Skip to content

Commit 71468c3

Browse files
committed
REFACTOR: format and add new module for custom API request
1 parent 65566d3 commit 71468c3

File tree

14 files changed

+155
-21
lines changed

14 files changed

+155
-21
lines changed

__tests__/any.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
APIClientConfig,
5+
DirectLoginAuthentication,
6+
Version,
7+
get,
8+
Any,
9+
GetAny,
10+
} from "../src/api";
11+
12+
describe("Any", () => {
13+
test("get<API.Any> should be able to get any OBP data.", async () => {
14+
const directLogin: DirectLoginAuthentication = {
15+
username: global.obpUsername,
16+
password: global.obpPassword,
17+
consumerKey: global.obpConsumerKey,
18+
};
19+
const clientConfig: APIClientConfig = {
20+
baseUri: global.obpBaseUri,
21+
version: global.obpVersion as Version,
22+
authentication: directLogin,
23+
};
24+
const resourceDocs = await get<API.Any>(clientConfig, Any)(GetAny)(
25+
"/resource-docs/v5.1.0/obp?tags=Account"
26+
);
27+
expect(resourceDocs).toBeDefined();
28+
});
29+
});

examples/any.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
API,
3+
APIClientConfig,
4+
DirectLoginAuthentication,
5+
Version,
6+
get,
7+
Any,
8+
GetAny,
9+
} from "../src/api";
10+
11+
const directLogin: DirectLoginAuthentication = {
12+
username: process.env.OBP_USERNAME,
13+
password: process.env.OBP_PASSWORD,
14+
consumerKey: process.env.OBP_CONSUMER_KEY,
15+
};
16+
const clientConfig: APIClientConfig = {
17+
baseUri: "https://obp-apisandbox.joinfincubator.com",
18+
version: Version.v510,
19+
authentication: directLogin,
20+
};
21+
22+
(async () => {
23+
// Get Resource Docs
24+
console.log(
25+
await get<API.Any>(clientConfig, Any)(GetAny)(
26+
"/resource-docs/v5.1.0/obp?tags=Account"
27+
)
28+
);
29+
})();

examples/bank.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Bank,
88
GetBanks,
99
GetBanksById,
10-
} from "../src/api";
10+
} from "obp-typescript/src";
1111

1212
const directLogin: DirectLoginAuthentication = {
1313
username: process.env.OBP_USERNAME,

src/api/account.ts

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

src/api/any.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Open Bank Project - OBP-TypeScript
3+
* Copyright (C) 2011-2023, TESOBE GmbH
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
18+
* TESOBE GmbH
19+
* Osloerstrasse 16/17
20+
* Berlin 13359, Germany
21+
*
22+
* This product includes software developed at
23+
* TESOBE (http://www.tesobe.com/)
24+
*/
25+
26+
import {
27+
API,
28+
APIRequest,
29+
APIClientConfig,
30+
apiCallWithCustomURIPath,
31+
} from "./client";
32+
33+
/**
34+
* Get any data.
35+
* Returns the response of the requested endpoint.
36+
*
37+
* @param config - The APIClientConfig object
38+
* @param methodCall - A higher order function
39+
* @returns A curried function
40+
*
41+
* @see {@link APIClientConfig}
42+
*
43+
* @public
44+
*/
45+
export const GetAny =
46+
(
47+
config: APIClientConfig,
48+
methodCall: (config: APIClientConfig, path: string) => Promise<any>
49+
) =>
50+
async (path: string) => {
51+
return await methodCall(config, path);
52+
};
53+
54+
/**
55+
* Returns an anonymous function for creating or getting Any data.
56+
*
57+
* @param config - The APIClientConfig object
58+
* @param methodCall - A higher order function
59+
* @returns A higher order function
60+
*
61+
* @see {@link APIClientConfig}
62+
* @see {@link APIRequest}
63+
*
64+
* @public
65+
*/
66+
export const Any: APIRequest<API.Any> = {
67+
get: (
68+
config: APIClientConfig,
69+
methodCall: (config: APIClientConfig, path: string) => Promise<any>
70+
) => {
71+
return apiCallWithCustomURIPath<API.Any>(config, methodCall);
72+
},
73+
};

src/api/bank.ts

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

src/api/client.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,6 +49,7 @@ export enum API {
4949
Customer,
5050
KYC,
5151
Metadata,
52+
Any,
5253
}
5354

5455
/**

src/api/customer.ts

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

src/api/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,6 +40,7 @@ export {
4040
CreateTransactionRequestAccount,
4141
} from "./transaction";
4242
export { User, Current } from "./user";
43+
export { Any, GetAny } from "./any";
4344
export {
4445
API,
4546
Version,

src/api/kyc.ts

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

src/api/metadata.ts

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

src/api/transaction.ts

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

src/api/user.ts

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

src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,6 +40,7 @@ export {
4040
CreateTransactionRequestAccount,
4141
} from "./api/transaction";
4242
export { User, Current } from "./api/user";
43+
export { Any, GetAny } from "./api/any";
4344
export {
4445
API,
4546
Version,

0 commit comments

Comments
 (0)