@dc-qash/sdk 1.0.0

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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "useTabs": true,
5
+ "singleQuote": true,
6
+ "printWidth": 3000,
7
+ "bracketSpacing": true
8
+ }
9
+
package/dist/lib.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export declare enum QashAPIEnv {
2
+ PRODUCTION = "https://api.qash.cloud",
3
+ STAGING = "https://api.staging.qash.cloud",
4
+ DEV = "https://api.dev.qash.cloud"
5
+ }
6
+ export default class QashSDK {
7
+ apiKey: string;
8
+ environment: QashAPIEnv;
9
+ constructor(apiKey: string, environment?: QashAPIEnv);
10
+ getAuthorizedPartner(): Promise<any>;
11
+ CBS: QashCBS;
12
+ }
13
+ declare class QashCBS {
14
+ #private;
15
+ constructor(sdk: QashSDK);
16
+ getAccountHolders(): Promise<any[]>;
17
+ getAccounts(): Promise<any[]>;
18
+ }
19
+ export {};
package/dist/lib.js ADDED
@@ -0,0 +1,83 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _QashCBS_sdk;
13
+ // Types
14
+ export var QashAPIEnv;
15
+ (function (QashAPIEnv) {
16
+ QashAPIEnv["PRODUCTION"] = "https://api.qash.cloud";
17
+ QashAPIEnv["STAGING"] = "https://api.staging.qash.cloud";
18
+ QashAPIEnv["DEV"] = "https://api.dev.qash.cloud";
19
+ })(QashAPIEnv || (QashAPIEnv = {}));
20
+ ;
21
+ // SDK
22
+ export default class QashSDK {
23
+ constructor(apiKey, environment = QashAPIEnv.PRODUCTION) {
24
+ this.apiKey = apiKey;
25
+ this.environment = environment;
26
+ this.CBS = new QashCBS(this);
27
+ }
28
+ // Get authorized partner
29
+ // TODO: Partner type
30
+ getAuthorizedPartner() {
31
+ return new Promise(async (resolve, reject) => {
32
+ try {
33
+ let _q = await fetch(`${this.environment}/v1/partner/@self`, { headers: { Authorization: `Basic ${this.apiKey}` } }).then(r => r.json());
34
+ if (_q.error || _q.errors)
35
+ throw _q.errors || [_q.error];
36
+ return resolve(_q);
37
+ }
38
+ catch (e) {
39
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
40
+ }
41
+ });
42
+ }
43
+ }
44
+ // CBS
45
+ class QashCBS {
46
+ constructor(sdk) {
47
+ _QashCBS_sdk.set(this, void 0);
48
+ __classPrivateFieldSet(this, _QashCBS_sdk, sdk, "f");
49
+ }
50
+ // Get account holders
51
+ // TODO: AccountHolder type
52
+ // TODO: search query
53
+ getAccountHolders() {
54
+ return new Promise(async (resolve, reject) => {
55
+ try {
56
+ let _q = await fetch(`${__classPrivateFieldGet(this, _QashCBS_sdk, "f").environment}/v1/cbs/account-holders`, { headers: { Authorization: `Basic ${__classPrivateFieldGet(this, _QashCBS_sdk, "f").apiKey}` } }).then(r => r.json());
57
+ if (_q.error || _q.errors)
58
+ throw _q.errors || [_q.error];
59
+ return resolve(_q);
60
+ }
61
+ catch (e) {
62
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
63
+ }
64
+ });
65
+ }
66
+ // Get accounts
67
+ // TODO: Account type
68
+ // TODO: search query
69
+ getAccounts() {
70
+ return new Promise(async (resolve, reject) => {
71
+ try {
72
+ let _q = await fetch(`${__classPrivateFieldGet(this, _QashCBS_sdk, "f").environment}/v1/cbs/accounts`, { headers: { Authorization: `Basic ${__classPrivateFieldGet(this, _QashCBS_sdk, "f").apiKey}` } }).then(r => r.json());
73
+ if (_q.error || _q.errors)
74
+ throw _q.errors || [_q.error];
75
+ return resolve(_q);
76
+ }
77
+ catch (e) {
78
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
79
+ }
80
+ });
81
+ }
82
+ }
83
+ _QashCBS_sdk = new WeakMap();
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@dc-qash/sdk",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "SDK for Qash, a DemocracyCraft clearing house",
6
+ "main": "dist/lib.js",
7
+ "repository": "https://github.com/luzzardik/qash-js-sdk",
8
+ "author": "Kacy Luzzardi",
9
+ "private": false
10
+ }
package/src/lib.ts ADDED
@@ -0,0 +1,114 @@
1
+ // Types
2
+ export enum QashAPIEnv { PRODUCTION = "https://api.qash.cloud", STAGING = "https://api.staging.qash.cloud", DEV = "https://api.dev.qash.cloud" };
3
+ export type Partner = {
4
+ _id: string;
5
+ name: string;
6
+ juridisctions: string[];
7
+ currencies: string[];
8
+ routing: {
9
+ identifier: string;
10
+ } | null;
11
+ is_cbs_partner: boolean;
12
+ joined_at: number;
13
+ revoked_at: number | null;
14
+ logo_url: string | null;
15
+ }
16
+ export type IndividualAccountHolderCreationData = {
17
+ name: string;
18
+ discord_id: string | null;
19
+ minecraft_id: string | null;
20
+ external_id: string | null;
21
+ }
22
+ export type BaseAccountHolder = {
23
+ _id: string;
24
+ type: "individual" | "business" | "institution";
25
+ responsible_partner: string;
26
+ name: string;
27
+ created_at: number;
28
+ updated_at: number | null;
29
+ revoked_at: number | null;
30
+ }
31
+ export type IndividualAccountHolder = BaseAccountHolder & {
32
+ discord_id: string | null;
33
+ minecraft_id: string | null;
34
+ external_id: string | null;
35
+ }
36
+ export type AccountHolder = IndividualAccountHolder;
37
+ // SDK
38
+ export default class QashSDK {
39
+ // Identification
40
+ apiKey : string;
41
+ environment : QashAPIEnv;
42
+ constructor (apiKey : string, environment : QashAPIEnv = QashAPIEnv.PRODUCTION) {
43
+ this.apiKey = apiKey;
44
+ this.environment = environment;
45
+ this.CBS = new QashCBS(this);
46
+ }
47
+
48
+ // Get authorized partner
49
+ getAuthorizedPartner () : Promise<Partner> {
50
+ return new Promise(async (resolve, reject) => {
51
+ try {
52
+ let _q = await fetch(`${this.environment}/v1/partner/@self`, { headers: { Authorization: `Basic ${this.apiKey}` } }).then(r => r.json());
53
+ if (_q.error || _q.errors) throw _q.errors || [_q.error];
54
+ return resolve(_q);
55
+ } catch (e) {
56
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
57
+ }
58
+ });
59
+ }
60
+
61
+ // CBS
62
+ public CBS;
63
+ }
64
+
65
+ // CBS
66
+ class QashCBS {
67
+ #sdk: QashSDK;
68
+
69
+ constructor (sdk: QashSDK) {
70
+ this.#sdk = sdk;
71
+ }
72
+
73
+ // Get account holders
74
+ // TODO: search query
75
+ getAccountHolders () : Promise<AccountHolder[]> {
76
+ return new Promise(async (resolve, reject) => {
77
+ try {
78
+ let _q = await fetch(`${this.#sdk.environment}/v1/cbs/account-holders`, { headers: { Authorization: `Basic ${this.#sdk.apiKey}` } }).then(r => r.json());
79
+ if (_q.error || _q.errors) throw _q.errors || [_q.error];
80
+ return resolve(_q);
81
+ } catch (e) {
82
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
83
+ }
84
+ });
85
+ }
86
+
87
+ // Get accounts
88
+ // TODO: Account type
89
+ // TODO: search query
90
+ getAccounts () : Promise<any[]> {
91
+ return new Promise(async (resolve, reject) => {
92
+ try {
93
+ let _q = await fetch(`${this.#sdk.environment}/v1/cbs/accounts`, { headers: { Authorization: `Basic ${this.#sdk.apiKey}` } }).then(r => r.json());
94
+ if (_q.error || _q.errors) throw _q.errors || [_q.error];
95
+ return resolve(_q);
96
+ } catch (e) {
97
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
98
+ }
99
+ });
100
+ }
101
+
102
+ // Create account holder - Individual
103
+ createIndividualAccountHolder (data: IndividualAccountHolderCreationData) : Promise<AccountHolder> {
104
+ return new Promise(async (resolve, reject) => {
105
+ try {
106
+ let _q = await fetch(`${this.#sdk.environment}/v1/cbs/account-holders`, { method: "POST", body: JSON.stringify(Object.assign({ type: "individual" }, data)), headers: { Authorization: `Basic ${this.#sdk.apiKey}` } }).then(r => r.json());
107
+ if (_q.error || _q.errors) throw _q.errors || [_q.error];
108
+ return resolve(_q);
109
+ } catch (e) {
110
+ reject(Array.isArray(e) ? e : ["unexpected_issue"]);
111
+ }
112
+ });
113
+ }
114
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2021",
4
+ "module": "es2022",
5
+ "moduleResolution": "node",
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "allowJs": true,
10
+ "declaration": true,
11
+ "experimentalDecorators": true,
12
+ "emitDecoratorMetadata": true,
13
+ "outDir": "./dist",
14
+ "rootDir": "./src",
15
+ "resolveJsonModule": true,
16
+ "skipLibCheck": true
17
+ },
18
+ "include": ["./src/**/*.ts", "./src/**/*.js", "./src/lib.ts"],
19
+ "exclude": []
20
+ }