REFACTOR: format and add new module for custom API request

This commit is contained in:
Mark Silva 2023-03-31 15:55:50 +08:00
parent 65566d3cfd
commit 71468c3756
14 changed files with 155 additions and 21 deletions

29
__tests__/any.test.ts Normal file
View File

@ -0,0 +1,29 @@
import { describe, test, expect } from "@jest/globals";
import {
API,
APIClientConfig,
DirectLoginAuthentication,
Version,
get,
Any,
GetAny,
} from "../src/api";
describe("Any", () => {
test("get<API.Any> should be able to get any OBP data.", async () => {
const directLogin: DirectLoginAuthentication = {
username: global.obpUsername,
password: global.obpPassword,
consumerKey: global.obpConsumerKey,
};
const clientConfig: APIClientConfig = {
baseUri: global.obpBaseUri,
version: global.obpVersion as Version,
authentication: directLogin,
};
const resourceDocs = await get<API.Any>(clientConfig, Any)(GetAny)(
"/resource-docs/v5.1.0/obp?tags=Account"
);
expect(resourceDocs).toBeDefined();
});
});

29
examples/any.ts Normal file
View File

@ -0,0 +1,29 @@
import {
API,
APIClientConfig,
DirectLoginAuthentication,
Version,
get,
Any,
GetAny,
} from "../src/api";
const directLogin: DirectLoginAuthentication = {
username: process.env.OBP_USERNAME,
password: process.env.OBP_PASSWORD,
consumerKey: process.env.OBP_CONSUMER_KEY,
};
const clientConfig: APIClientConfig = {
baseUri: "https://obp-apisandbox.joinfincubator.com",
version: Version.v510,
authentication: directLogin,
};
(async () => {
// Get Resource Docs
console.log(
await get<API.Any>(clientConfig, Any)(GetAny)(
"/resource-docs/v5.1.0/obp?tags=Account"
)
);
})();

View File

@ -7,7 +7,7 @@ import {
Bank,
GetBanks,
GetBanksById,
} from "../src/api";
} from "obp-typescript/src";
const directLogin: DirectLoginAuthentication = {
username: process.env.OBP_USERNAME,

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

73
src/api/any.ts Normal file
View File

@ -0,0 +1,73 @@
/**
* Open Bank Project - OBP-TypeScript
* Copyright (C) 2011-2023, TESOBE GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Email: contact@tesobe.com
* TESOBE GmbH
* Osloerstrasse 16/17
* Berlin 13359, Germany
*
* This product includes software developed at
* TESOBE (http://www.tesobe.com/)
*/
import {
API,
APIRequest,
APIClientConfig,
apiCallWithCustomURIPath,
} from "./client";
/**
* Get any data.
* Returns the response of the requested endpoint.
*
* @param config - The APIClientConfig object
* @param methodCall - A higher order function
* @returns A curried function
*
* @see {@link APIClientConfig}
*
* @public
*/
export const GetAny =
(
config: APIClientConfig,
methodCall: (config: APIClientConfig, path: string) => Promise<any>
) =>
async (path: string) => {
return await methodCall(config, path);
};
/**
* Returns an anonymous function for creating or getting Any data.
*
* @param config - The APIClientConfig object
* @param methodCall - A higher order function
* @returns A higher order function
*
* @see {@link APIClientConfig}
* @see {@link APIRequest}
*
* @public
*/
export const Any: APIRequest<API.Any> = {
get: (
config: APIClientConfig,
methodCall: (config: APIClientConfig, path: string) => Promise<any>
) => {
return apiCallWithCustomURIPath<API.Any>(config, methodCall);
},
};

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,6 +49,7 @@ export enum API {
Customer,
KYC,
Metadata,
Any,
}
/**

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -40,6 +40,7 @@ export {
CreateTransactionRequestAccount,
} from "./transaction";
export { User, Current } from "./user";
export { Any, GetAny } from "./any";
export {
API,
Version,

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -5,9 +5,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -40,6 +40,7 @@ export {
CreateTransactionRequestAccount,
} from "./api/transaction";
export { User, Current } from "./api/user";
export { Any, GetAny } from "./api/any";
export {
API,
Version,