Skip to content

Commit cedb78f

Browse files
committed
OBP-TypeScript scripts
1 parent 1b72938 commit cedb78f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6471
-0
lines changed

.eslintrc.cjs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
3+
parser: "@typescript-eslint/parser",
4+
plugins: ["@typescript-eslint", "eslint-plugin-tsdoc"],
5+
root: true,
6+
rules: {
7+
"@typescript-eslint/no-namespace": "off",
8+
"@typescript-eslint/no-explicit-any": "off",
9+
semi: [2, "always"],
10+
quotes: [2, "double", { avoidEscape: true }],
11+
},
12+
plugins: ["jest"],
13+
env: {
14+
"jest/globals": true,
15+
},
16+
};

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/config.json
2+
/node_modules
3+
/dist
4+
yarn-error.log

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
docs

.prettierrc.json

Whitespace-only changes.

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# obp-sdk-ts
2+
3+
## Usage
4+
5+
#### Symlink
6+
7+
Checkout the obp-sdk-ts library from https://github.com/mark-tesobe/OBP-SDK.
8+
Inside the obp-sdk repository folder, execute the **yarn link** command.
9+
10+
```
11+
yarn link
12+
```
13+
14+
To link the **obp-sdk-ts** library into your app, run the command inside your app.
15+
16+
```
17+
yarn link obp-sdk-ts
18+
```
19+
20+
#### Example
21+
22+
```typescript
23+
import {
24+
API,
25+
APIClientConfig,
26+
DirectLoginAuthentication,
27+
Version,
28+
get,
29+
create,
30+
Bank,
31+
Account,
32+
Transaction,
33+
GetTransactionsForAccountFull,
34+
TransactionRequestAccountBody,
35+
CreateTransactionRequestAccount,
36+
} from "obp-sdk-ts/src";
37+
38+
(async () => {
39+
const directLogin: DirectLoginAuthentication = {
40+
username: process.env.OBP_USERNAME || "",
41+
password: process.env.OBP_PASSWORD || "",
42+
consumerKey: process.env.OBP_CONSUMER_KEY || "",
43+
};
44+
const clientConfig: APIClientConfig = {
45+
baseUri: "https://apisandbox.openbankproject.com",
46+
version: Version.v500,
47+
authentication: directLogin,
48+
};
49+
const banks = await get<API.Bank>(clientConfig, Bank);
50+
const account = await get<API.Account>(clientConfig, Account);
51+
52+
const transactionFn = get<API.Transaction>(clientConfig, Transaction);
53+
// Get transaction for account full.
54+
const transactionsForAccountFull = await transactionFn(
55+
GetTransactionsForAccountFull
56+
)("bankId", "accountId", "viewId");
57+
58+
// New transaction body.
59+
const body: TransactionRequestAccountBody = {
60+
description: "Dummy transaction full data",
61+
to: {
62+
bank_id: "bankId",
63+
account_id: "accountId",
64+
},
65+
value: {
66+
currency: "EUR",
67+
amount: 1.0,
68+
},
69+
};
70+
// Create transaction request account.
71+
await create<API.Transaction>(
72+
clientConfig,
73+
Transaction
74+
)(CreateTransactionRequestAccount)(
75+
"bankId",
76+
"accountId",
77+
"viewId"
78+
)(body);
79+
})();
80+
```

__tests__/account.test.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
Version,
5+
APIClientConfig,
6+
DirectLoginAuthentication,
7+
get,
8+
Account,
9+
} from "../src";
10+
import { GetAccountsByBankId } from "../src/api/account";
11+
import { getRequest, apiCallWithCustomURIPath } from "../src/api/client";
12+
13+
const directLogin: DirectLoginAuthentication = {
14+
username: global.obpUsername,
15+
password: global.obpPassword,
16+
consumerKey: global.obpConsumerKey,
17+
};
18+
19+
const clientConfig: APIClientConfig = {
20+
baseUri: global.obpBaseUri,
21+
version: global.obpVersion as Version,
22+
authentication: directLogin,
23+
};
24+
25+
describe("Account", () => {
26+
test("get<API.Account> ByBankId should be able to get the OBP Accounts data.", async () => {
27+
const accounts = await get<API.Account>(
28+
clientConfig,
29+
Account
30+
)(GetAccountsByBankId)(global.obpTestBankId);
31+
32+
expect(accounts).toBeDefined();
33+
});
34+
35+
test("get<API.Account> should be able to get the OBP Accounts data.", async () => {
36+
const accounts = await get<API.Account>(
37+
clientConfig,
38+
Account
39+
)(`/banks/${global.obpTestBankId}/accounts`);
40+
41+
expect(accounts).toBeDefined();
42+
});
43+
44+
test("apiCallWithCustomURIPath should be able to get the OBP Accounts data.", async () => {
45+
const customPathCall = apiCallWithCustomURIPath<API.Account>(
46+
clientConfig,
47+
getRequest
48+
);
49+
const accounts = await customPathCall(
50+
`/banks/${global.obpTestBankId}/accounts`
51+
);
52+
53+
expect(accounts).toBeDefined();
54+
});
55+
});

__tests__/bank.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
APIClientConfig,
5+
DirectLoginAuthentication,
6+
Version,
7+
get,
8+
Bank,
9+
GetBanks,
10+
} from "../src/api";
11+
12+
describe("Bank", () => {
13+
test("get<API.Bank> should be able to get the OBP Bank 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 banks = await get<API.Bank>(clientConfig, Bank)(GetBanks);
25+
expect(banks).toBeDefined();
26+
});
27+
});

__tests__/customer.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
APIClientConfig,
5+
DirectLoginAuthentication,
6+
Version,
7+
get,
8+
Customer,
9+
GetCustomersAtBank,
10+
GetCustomersAtAnyBank,
11+
} from "../src/api";
12+
13+
const directLogin: DirectLoginAuthentication = {
14+
username: global.obpUsername,
15+
password: global.obpPassword,
16+
consumerKey: global.obpConsumerKey,
17+
};
18+
const clientConfig: APIClientConfig = {
19+
baseUri: global.obpBaseUri,
20+
version: global.obpVersion as Version,
21+
authentication: directLogin,
22+
};
23+
describe("Customer", () => {
24+
test("get<API.Customer> GetCustomersAtBank should be able to get the OBP Customer data.", async () => {
25+
const customers = await get<API.Customer>(
26+
clientConfig,
27+
Customer
28+
)(GetCustomersAtBank)(global.obpTestBankId);
29+
expect(customers).toBeDefined();
30+
});
31+
test("get<API.Customer> GetCustomersAtAnyBank should be able to get the OBP Customer data.", async () => {
32+
const customers = await get<API.Customer>(
33+
clientConfig,
34+
Customer
35+
)(GetCustomersAtAnyBank);
36+
expect(customers).toBeDefined();
37+
});
38+
});

__tests__/kyc.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+
KYC,
9+
GetKYCStatus,
10+
} from "../src/api";
11+
12+
describe("KYC", () => {
13+
test("get<API.KYC> GetKYCStatus should be able to get the OBP KYC Status 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 kycStatus = await get<API.KYC>(clientConfig, KYC)(GetKYCStatus)(
25+
"9e6b2f45-a449-4e87-b772-e74cc9d42448"
26+
);
27+
expect(kycStatus).toBeDefined();
28+
});
29+
});

__tests__/metadata.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
APIClientConfig,
5+
DirectLoginAuthentication,
6+
Version,
7+
get,
8+
Metadata,
9+
GetTagsOnAccount,
10+
} from "../src/api";
11+
12+
describe("Metadata", () => {
13+
test("get<API.Metadata> should be able to get the OBP Metadata 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 tagsOnAccount = await get<API.Metadata>(
25+
clientConfig,
26+
Metadata
27+
)(GetTagsOnAccount)(
28+
global.obpTestBankId,
29+
"9e6b2f45-a449-4e87-b772-e74cc9d42448",
30+
"owner"
31+
);
32+
console.log(tagsOnAccount);
33+
expect(tagsOnAccount).toBeDefined();
34+
});
35+
});

__tests__/transaction.test.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
Version,
5+
APIClientConfig,
6+
DirectLoginAuthentication,
7+
create,
8+
get,
9+
Transaction,
10+
} from "../src/api";
11+
import {
12+
GetTransactionsForAccountFull,
13+
CreateTransactionRequestAccount,
14+
TransactionRequestAccountBody,
15+
} from "../src/api/transaction";
16+
17+
const directLogin: DirectLoginAuthentication = {
18+
username: global.obpUsername,
19+
password: global.obpPassword,
20+
consumerKey: global.obpConsumerKey,
21+
};
22+
const clientConfig: APIClientConfig = {
23+
baseUri: global.obpBaseUri,
24+
version: global.obpVersion as Version,
25+
authentication: directLogin,
26+
};
27+
const bankId = global.obpTestBankId;
28+
const accountId = "9e6b2f45-a449-4e87-b772-e74cc9d42448";
29+
const viewId = "owner";
30+
31+
describe("Transaction", () => {
32+
test("get<API.Transaction> ByBankId should be able to get the OBP Transactions data.", async () => {
33+
const transactions = await get<API.Transaction>(
34+
clientConfig,
35+
Transaction
36+
)(GetTransactionsForAccountFull)(bankId, accountId, viewId);
37+
38+
expect(transactions).toBeDefined();
39+
});
40+
41+
test("get<API.Transaction> should be able to get the OBP Transactions data.", async () => {
42+
const transactions = await get<API.Transaction>(
43+
clientConfig,
44+
Transaction
45+
)(`/banks/${bankId}/accounts/${accountId}/${viewId}/transactions`);
46+
47+
expect(transactions).toBeDefined();
48+
});
49+
50+
test("create<API.Transaction, TransactionFullBody> should be able to createn an OBP Transaction Full data.", async () => {
51+
const body: TransactionRequestAccountBody = {
52+
description: "test transaction full data",
53+
to: {
54+
bank_id: bankId,
55+
account_id: accountId,
56+
},
57+
value: {
58+
currency: "EUR",
59+
amount: 1.0,
60+
},
61+
};
62+
const transactions = await create<API.Transaction>(
63+
clientConfig,
64+
Transaction
65+
)(CreateTransactionRequestAccount)(
66+
bankId,
67+
accountId,
68+
viewId,
69+
"SANDBOX_TAN"
70+
)(body);
71+
72+
expect(transactions).toBeDefined();
73+
});
74+
});

__tests__/user.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, test, expect } from "@jest/globals";
2+
import {
3+
API,
4+
APIClientConfig,
5+
DirectLoginAuthentication,
6+
Version,
7+
get,
8+
User,
9+
Current,
10+
} from "../src/api";
11+
12+
describe("User", () => {
13+
test("get<API.User> Current should be able to get the Current User.", 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 users = await get<API.User>(clientConfig, User)(Current);
25+
expect(users).toBeDefined();
26+
});
27+
});

0 commit comments

Comments
 (0)