@dc-qash/sdk 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.d.ts +8 -1
- package/dist/lib.js +36 -3
- package/package.json +1 -1
package/dist/lib.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export type IndividualAccountHolder = BaseAccountHolder & {
|
|
|
37
37
|
external_id: string | null;
|
|
38
38
|
};
|
|
39
39
|
export type AccountHolder = IndividualAccountHolder;
|
|
40
|
+
export type AccountListQuery = {
|
|
41
|
+
partner?: string | string[];
|
|
42
|
+
type?: string | string[];
|
|
43
|
+
holder?: string | string[];
|
|
44
|
+
currency?: string | string[];
|
|
45
|
+
};
|
|
40
46
|
export default class QashSDK {
|
|
41
47
|
apiKey: string;
|
|
42
48
|
environment: QashAPIEnv;
|
|
@@ -48,7 +54,8 @@ declare class QashCBS {
|
|
|
48
54
|
#private;
|
|
49
55
|
constructor(sdk: QashSDK);
|
|
50
56
|
getAccountHolders(): Promise<AccountHolder[]>;
|
|
51
|
-
getAccounts(): Promise<any[]>;
|
|
57
|
+
getAccounts(query?: AccountListQuery): Promise<any[]>;
|
|
58
|
+
getAccountHolder(account_holder_id: string): Promise<AccountHolder>;
|
|
52
59
|
createIndividualAccountHolder(data: IndividualAccountHolderCreationData): Promise<AccountHolder>;
|
|
53
60
|
}
|
|
54
61
|
export {};
|
package/dist/lib.js
CHANGED
|
@@ -18,6 +18,25 @@ export var QashAPIEnv;
|
|
|
18
18
|
QashAPIEnv["DEV"] = "https://api.dev.qash.cloud";
|
|
19
19
|
})(QashAPIEnv || (QashAPIEnv = {}));
|
|
20
20
|
;
|
|
21
|
+
// Util: build query value
|
|
22
|
+
function buildQueryValue(value) {
|
|
23
|
+
return Array.isArray(value) ? value.join(',') : value;
|
|
24
|
+
}
|
|
25
|
+
// Util: build query
|
|
26
|
+
function buildQuery(query) {
|
|
27
|
+
if (Object.keys(query).length == 0)
|
|
28
|
+
return "";
|
|
29
|
+
const kV = {};
|
|
30
|
+
for (let i in query) {
|
|
31
|
+
if (typeof query[i] !== "string" && !Array.isArray(query[i]))
|
|
32
|
+
continue;
|
|
33
|
+
if (Array.isArray(query[i]))
|
|
34
|
+
query[i] = query[i].filter((f) => typeof f === "string");
|
|
35
|
+
kV[i] = buildQueryValue(query[i]);
|
|
36
|
+
}
|
|
37
|
+
const built = Object.entries(kV).map(([k, v]) => `${k}=${v}`).join('&');
|
|
38
|
+
return '?' + built;
|
|
39
|
+
}
|
|
21
40
|
// SDK
|
|
22
41
|
export default class QashSDK {
|
|
23
42
|
constructor(apiKey, environment = QashAPIEnv.PRODUCTION) {
|
|
@@ -63,11 +82,25 @@ class QashCBS {
|
|
|
63
82
|
}
|
|
64
83
|
// Get accounts
|
|
65
84
|
// TODO: Account type
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
getAccounts(query = {}) {
|
|
86
|
+
return new Promise(async (resolve, reject) => {
|
|
87
|
+
const builtQuery = buildQuery(query);
|
|
88
|
+
try {
|
|
89
|
+
let _q = await fetch(`${__classPrivateFieldGet(this, _QashCBS_sdk, "f").environment}/v1/cbs/accounts${builtQuery}`, { headers: { Authorization: `Basic ${__classPrivateFieldGet(this, _QashCBS_sdk, "f").apiKey}` } }).then(r => r.json());
|
|
90
|
+
if (_q.error || _q.errors)
|
|
91
|
+
throw _q.errors || [_q.error];
|
|
92
|
+
return resolve(_q);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
reject(Array.isArray(e) ? e : ["unexpected_issue"]);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Get account holder
|
|
100
|
+
getAccountHolder(account_holder_id) {
|
|
68
101
|
return new Promise(async (resolve, reject) => {
|
|
69
102
|
try {
|
|
70
|
-
let _q = await fetch(`${__classPrivateFieldGet(this, _QashCBS_sdk, "f").environment}/v1/cbs/
|
|
103
|
+
let _q = await fetch(`${__classPrivateFieldGet(this, _QashCBS_sdk, "f").environment}/v1/cbs/account-holder/${account_holder_id}`, { headers: { Authorization: `Basic ${__classPrivateFieldGet(this, _QashCBS_sdk, "f").apiKey}` } }).then(r => r.json());
|
|
71
104
|
if (_q.error || _q.errors)
|
|
72
105
|
throw _q.errors || [_q.error];
|
|
73
106
|
return resolve(_q);
|