@credenza3/partner-sdk 0.0.1 → 0.0.2-alpha.2
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/README.md +0 -3
- package/dist/accounts/client/index.d.ts +1 -0
- package/dist/accounts/client/index.js +1 -0
- package/dist/accounts/client/jwt-auth/index.d.ts +1 -0
- package/dist/accounts/{oauth-account → client/jwt-auth}/index.js +1 -1
- package/dist/accounts/client/jwt-auth/jwt-auth.d.ts +5 -0
- package/dist/accounts/client/jwt-auth/jwt-auth.js +59 -0
- package/dist/accounts/client/jwt-auth/jwt-auth.spec.d.ts +1 -0
- package/dist/accounts/client/jwt-auth/jwt-auth.spec.js +42 -0
- package/dist/accounts/client/jwt-auth/jwt-auth.types.d.ts +25 -0
- package/dist/accounts/client/jwt-auth/jwt-auth.types.js +2 -0
- package/dist/accounts/index.d.ts +2 -1
- package/dist/accounts/index.js +2 -1
- package/dist/accounts/oauth/index.d.ts +1 -0
- package/dist/accounts/oauth/index.js +17 -0
- package/dist/accounts/oauth/oauth.d.ts +3 -0
- package/dist/accounts/oauth/oauth.js +42 -0
- package/dist/accounts/oauth/oauth.spec.d.ts +1 -0
- package/dist/accounts/oauth/oauth.spec.js +77 -0
- package/dist/accounts/oauth/oauth.types.d.ts +10 -0
- package/dist/accounts/oauth/oauth.types.js +2 -0
- package/dist/accounts/user/index.d.ts +1 -0
- package/dist/accounts/user/index.js +17 -0
- package/dist/accounts/user/user.d.ts +2 -0
- package/dist/accounts/{oauth-account/oauth-account.js → user/user.js} +2 -1
- package/dist/accounts/{oauth-account/oauth-account.d.ts → user/user.types.d.ts} +3 -3
- package/dist/accounts/user/user.types.js +2 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/promo/index.d.ts +2 -0
- package/dist/api/promo/index.js +18 -0
- package/dist/api/promo/offers/index.d.ts +1 -0
- package/dist/api/promo/offers/index.js +17 -0
- package/dist/api/promo/offers/offers.d.ts +10 -0
- package/dist/api/promo/offers/offers.js +91 -0
- package/dist/api/promo/offers/offers.spec.d.ts +1 -0
- package/dist/api/promo/offers/offers.spec.js +49 -0
- package/dist/api/promo/offers/offers.types.d.ts +24 -0
- package/dist/api/promo/offers/offers.types.js +2 -0
- package/dist/api/promo/rules/index.d.ts +1 -0
- package/dist/api/promo/rules/index.js +17 -0
- package/dist/api/promo/rules/rules.d.ts +5 -0
- package/dist/api/promo/rules/rules.js +59 -0
- package/dist/api/promo/rules/rules.spec.d.ts +1 -0
- package/dist/api/promo/rules/rules.spec.js +38 -0
- package/dist/api/promo/rules/rules.types.d.ts +14 -0
- package/dist/api/promo/rules/rules.types.js +2 -0
- package/dist/lib/obj/index.d.ts +1 -0
- package/dist/lib/obj/index.js +17 -0
- package/dist/lib/obj/obj.d.ts +2 -0
- package/dist/lib/obj/obj.js +30 -0
- package/dist/lib/obj/obj.spec.d.ts +1 -0
- package/dist/lib/obj/obj.spec.js +30 -0
- package/package.json +115 -35
- package/dist/accounts/oauth-account/index.d.ts +0 -1
- package/dist/sui/zk/zk.d.ts +0 -3
- package/dist/sui/zk/zk.js +0 -15
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './jwt-auth';
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./jwt-auth"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TJwtAuthValidator, TJwtAuthValidatorParams, TJwtAuthUpdateValidatorParams } from './jwt-auth.types';
|
|
2
|
+
export declare function addJwtValidator(params: TJwtAuthValidatorParams): Promise<TJwtAuthValidator>;
|
|
3
|
+
export declare function updateJwtValidator(id: string, params: TJwtAuthUpdateValidatorParams): Promise<TJwtAuthValidator>;
|
|
4
|
+
export declare function removeJwtValidator(id: string): Promise<boolean>;
|
|
5
|
+
export declare function getJwtValidators(): Promise<TJwtAuthValidator[]>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addJwtValidator = addJwtValidator;
|
|
4
|
+
exports.updateJwtValidator = updateJwtValidator;
|
|
5
|
+
exports.removeJwtValidator = removeJwtValidator;
|
|
6
|
+
exports.getJwtValidators = getJwtValidators;
|
|
7
|
+
const logging_1 = require("../../../lib/logging");
|
|
8
|
+
const accounts_1 = require("../../../accounts");
|
|
9
|
+
const credentials_1 = require("../../../lib/credentials");
|
|
10
|
+
const obj_1 = require("../../../lib/obj");
|
|
11
|
+
async function addJwtValidator(params) {
|
|
12
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/clients/jwt-auth`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
19
|
+
});
|
|
20
|
+
const json = await response.json();
|
|
21
|
+
(0, logging_1.log)(addJwtValidator.name, json);
|
|
22
|
+
return (0, obj_1.toCamelCase)(json);
|
|
23
|
+
}
|
|
24
|
+
async function updateJwtValidator(id, params) {
|
|
25
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/clients/jwt-auth/${id}`, {
|
|
26
|
+
method: 'PATCH',
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
32
|
+
});
|
|
33
|
+
const json = await response.json();
|
|
34
|
+
(0, logging_1.log)(updateJwtValidator.name, json);
|
|
35
|
+
return (0, obj_1.toCamelCase)(json);
|
|
36
|
+
}
|
|
37
|
+
async function removeJwtValidator(id) {
|
|
38
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/clients/jwt-auth/${id}`, {
|
|
39
|
+
method: 'DELETE',
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const json = await response.json();
|
|
46
|
+
(0, logging_1.log)(removeJwtValidator.name, json);
|
|
47
|
+
return json;
|
|
48
|
+
}
|
|
49
|
+
async function getJwtValidators() {
|
|
50
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/clients/jwt-auth`, {
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const json = await response.json();
|
|
57
|
+
(0, logging_1.log)(getJwtValidators.name, json);
|
|
58
|
+
return (0, obj_1.toCamelCase)(json);
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require("./");
|
|
4
|
+
let validatorId;
|
|
5
|
+
test('Adds jwt Validator', async () => {
|
|
6
|
+
const result = await (0, _1.addJwtValidator)({
|
|
7
|
+
validationFields: ['id1', 'id2', 'id3'],
|
|
8
|
+
userinfoRequestConfig: {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
url: 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=AIzaSyDhJaZtjSw6EVvhr2Vr3dZ8QJJq-P27UkE',
|
|
11
|
+
contentType: 'application/json',
|
|
12
|
+
tokenParamName: 'idToken',
|
|
13
|
+
tokenParamKind: 'body',
|
|
14
|
+
tokenParamMask: '#####',
|
|
15
|
+
},
|
|
16
|
+
profileFieldsMapping: {
|
|
17
|
+
email: 'users.0.email',
|
|
18
|
+
name: ['users.0.localId', 'users.0.validSince'],
|
|
19
|
+
},
|
|
20
|
+
jwksUrl: 'https://test.com',
|
|
21
|
+
});
|
|
22
|
+
validatorId = result.id;
|
|
23
|
+
expect(result.id).toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
test('Updates jwt Validator', async () => {
|
|
26
|
+
const result = await (0, _1.updateJwtValidator)(validatorId, {
|
|
27
|
+
validationFields: ['sub', 'aud', 'iss'],
|
|
28
|
+
});
|
|
29
|
+
expect(result).toBeTruthy();
|
|
30
|
+
expect(result.validationFields).toEqual(['sub', 'aud', 'iss']);
|
|
31
|
+
});
|
|
32
|
+
test('Gets validators', async () => {
|
|
33
|
+
const result = await (0, _1.getJwtValidators)();
|
|
34
|
+
expect(result).toBeTruthy();
|
|
35
|
+
expect(result.length).toBeGreaterThan(0);
|
|
36
|
+
const validator = result.find((v) => v.id === validatorId);
|
|
37
|
+
expect(validator).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
test('Deletes jwt Validator', async () => {
|
|
40
|
+
const result = await (0, _1.removeJwtValidator)(validatorId);
|
|
41
|
+
expect(result).toBe(true);
|
|
42
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type TJwtAuthUpdateValidatorParams = {
|
|
2
|
+
validationFields?: string[];
|
|
3
|
+
jwksUrl?: string;
|
|
4
|
+
userinfoRequestConfig?: {
|
|
5
|
+
method?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
contentType?: string;
|
|
8
|
+
tokenParamName?: string;
|
|
9
|
+
tokenParamKind?: string;
|
|
10
|
+
tokenParamMask?: string;
|
|
11
|
+
};
|
|
12
|
+
profileFieldsMapping?: {
|
|
13
|
+
email?: string;
|
|
14
|
+
phone?: string;
|
|
15
|
+
picture?: string;
|
|
16
|
+
name?: string[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type TJwtAuthValidatorParams = TJwtAuthUpdateValidatorParams & {
|
|
20
|
+
validationFields: string[];
|
|
21
|
+
};
|
|
22
|
+
export type TJwtAuthValidator = TJwtAuthValidatorParams & {
|
|
23
|
+
id: string;
|
|
24
|
+
clientId: string;
|
|
25
|
+
};
|
package/dist/accounts/index.d.ts
CHANGED
package/dist/accounts/index.js
CHANGED
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./accounts"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./user"), exports);
|
|
19
|
+
__exportStar(require("./oauth"), exports);
|
|
19
20
|
__exportStar(require("./client"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './oauth';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./oauth"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exchangeCodeForToken = exchangeCodeForToken;
|
|
4
|
+
exports.refreshToken = refreshToken;
|
|
5
|
+
const credentials_1 = require("../../lib/credentials");
|
|
6
|
+
const accounts_1 = require("../../accounts");
|
|
7
|
+
const logging_1 = require("../../lib/logging");
|
|
8
|
+
const obj_1 = require("../../lib/obj");
|
|
9
|
+
async function exchangeCodeForToken(params) {
|
|
10
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/oauth2/token`, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
14
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
15
|
+
},
|
|
16
|
+
body: new URLSearchParams({
|
|
17
|
+
grant_type: 'authorization_code',
|
|
18
|
+
code: params.code,
|
|
19
|
+
code_verifier: params.codeVerifier,
|
|
20
|
+
redirect_uri: params.redirectUri || 'none',
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
const json = await response.json();
|
|
24
|
+
(0, logging_1.log)(exchangeCodeForToken.name, json);
|
|
25
|
+
return (0, obj_1.toCamelCase)(json);
|
|
26
|
+
}
|
|
27
|
+
async function refreshToken(refreshTokenValue) {
|
|
28
|
+
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/oauth2/token`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
32
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
33
|
+
},
|
|
34
|
+
body: new URLSearchParams({
|
|
35
|
+
grant_type: 'refresh_token',
|
|
36
|
+
refresh_token: refreshTokenValue,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const json = await response.json();
|
|
40
|
+
(0, logging_1.log)(refreshToken.name, json);
|
|
41
|
+
return (0, obj_1.toCamelCase)(json);
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto_1 = require("crypto");
|
|
4
|
+
const accounts_1 = require("../../accounts");
|
|
5
|
+
const credentials_1 = require("../../lib/credentials");
|
|
6
|
+
const jwt_auth_1 = require("../../accounts/client/jwt-auth");
|
|
7
|
+
const _1 = require("./");
|
|
8
|
+
const codeVerifier = 'crd-partner-sdk';
|
|
9
|
+
let authCode;
|
|
10
|
+
let refreshTokenValue;
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
const authResponse = await fetch(`https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyDhJaZtjSw6EVvhr2Vr3dZ8QJJq-P27UkE`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
email: 'test@test.com',
|
|
19
|
+
password: 'securepwd',
|
|
20
|
+
returnSecureToken: true,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
const idToken = (await authResponse.json()).idToken;
|
|
24
|
+
expect(idToken).toBeTruthy();
|
|
25
|
+
const validator = await (0, jwt_auth_1.addJwtValidator)({
|
|
26
|
+
validationFields: ['sub', 'aud', 'iss'],
|
|
27
|
+
jwksUrl: 'https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com',
|
|
28
|
+
});
|
|
29
|
+
expect(validator.id).toBeDefined();
|
|
30
|
+
const codeChallenge = (0, crypto_1.createHash)('sha256')
|
|
31
|
+
.update(codeVerifier)
|
|
32
|
+
.digest('base64')
|
|
33
|
+
.replace(/\+/g, '-')
|
|
34
|
+
.replace(/\//g, '_')
|
|
35
|
+
.replace(/=+$/, '');
|
|
36
|
+
const url = new URL(`${(0, accounts_1.getOAuthApiUrl)()}/oauth2/authorize/jwt`);
|
|
37
|
+
url.searchParams.append('client_id', process.env.CLIENT_ID);
|
|
38
|
+
url.searchParams.append('response_type', 'code');
|
|
39
|
+
url.searchParams.append('scope', 'openid profile offline.access');
|
|
40
|
+
url.searchParams.append('state', 'state');
|
|
41
|
+
url.searchParams.append('nonce', 'nonce');
|
|
42
|
+
url.searchParams.append('redirect_uri', 'none');
|
|
43
|
+
url.searchParams.append('code_challenge', codeChallenge);
|
|
44
|
+
url.searchParams.append('code_challenge_method', 'S256');
|
|
45
|
+
const response = await fetch(url.toString(), {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
49
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
50
|
+
},
|
|
51
|
+
body: new URLSearchParams({
|
|
52
|
+
validator_id: validator.id,
|
|
53
|
+
id_token: idToken,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
const json = await response.json();
|
|
57
|
+
authCode = json.code;
|
|
58
|
+
expect(json.code).toBeTruthy();
|
|
59
|
+
await (0, jwt_auth_1.removeJwtValidator)(validator.id);
|
|
60
|
+
});
|
|
61
|
+
test('Exchanges Auth code for token', async () => {
|
|
62
|
+
const result = await (0, _1.exchangeCodeForToken)({
|
|
63
|
+
code: authCode,
|
|
64
|
+
codeVerifier,
|
|
65
|
+
redirectUri: null,
|
|
66
|
+
});
|
|
67
|
+
expect(result.idToken).toBeTruthy();
|
|
68
|
+
expect(result.refreshToken).toBeTruthy();
|
|
69
|
+
expect(result.accessToken).toBeTruthy();
|
|
70
|
+
refreshTokenValue = result.refreshToken;
|
|
71
|
+
});
|
|
72
|
+
test('Exchanges Refresh token', async () => {
|
|
73
|
+
const result = await (0, _1.refreshToken)(refreshTokenValue);
|
|
74
|
+
expect(result.idToken).toBeTruthy();
|
|
75
|
+
expect(result.refreshToken).toBeTruthy();
|
|
76
|
+
expect(result.accessToken).toBeTruthy();
|
|
77
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './user';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./user"), exports);
|
|
@@ -4,6 +4,7 @@ exports.getAccountInfo = getAccountInfo;
|
|
|
4
4
|
const credentials_1 = require("../../lib/credentials");
|
|
5
5
|
const accounts_1 = require("../../accounts");
|
|
6
6
|
const logging_1 = require("../../lib/logging");
|
|
7
|
+
const obj_1 = require("../../lib/obj");
|
|
7
8
|
async function getAccountInfo(sub) {
|
|
8
9
|
const response = await fetch(`${(0, accounts_1.getOAuthApiUrl)()}/accounts/${sub}`, {
|
|
9
10
|
headers: {
|
|
@@ -13,5 +14,5 @@ async function getAccountInfo(sub) {
|
|
|
13
14
|
});
|
|
14
15
|
const json = await response.json();
|
|
15
16
|
(0, logging_1.log)(getAccountInfo.name, json);
|
|
16
|
-
return json;
|
|
17
|
+
return (0, obj_1.toCamelCase)(json);
|
|
17
18
|
}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rules"), exports);
|
|
18
|
+
__exportStar(require("./offers"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './offers';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./offers"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TCreateOfferParams, TUpdateOfferParams, TOffer, TOfferRss } from './offers.types';
|
|
2
|
+
export declare function addPromoOffer(params: TCreateOfferParams): Promise<TOffer>;
|
|
3
|
+
export declare function updatePromoOffer(id: string, params: TUpdateOfferParams): Promise<TOffer>;
|
|
4
|
+
export declare function removePromoOffer(id: string): Promise<boolean>;
|
|
5
|
+
export declare function getPromoOffers(): Promise<TOffer[]>;
|
|
6
|
+
export declare function checkPromoOffer(id: string, sub: string): Promise<boolean>;
|
|
7
|
+
export declare function getPromoOfferRss(params: {
|
|
8
|
+
suiAddress?: string;
|
|
9
|
+
evmAddress?: string;
|
|
10
|
+
}): Promise<TOfferRss[]>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPromoOffer = addPromoOffer;
|
|
4
|
+
exports.updatePromoOffer = updatePromoOffer;
|
|
5
|
+
exports.removePromoOffer = removePromoOffer;
|
|
6
|
+
exports.getPromoOffers = getPromoOffers;
|
|
7
|
+
exports.checkPromoOffer = checkPromoOffer;
|
|
8
|
+
exports.getPromoOfferRss = getPromoOfferRss;
|
|
9
|
+
const logging_1 = require("../../../lib/logging");
|
|
10
|
+
const api_1 = require("../../../api");
|
|
11
|
+
const credentials_1 = require("../../../lib/credentials");
|
|
12
|
+
const obj_1 = require("../../../lib/obj");
|
|
13
|
+
async function addPromoOffer(params) {
|
|
14
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/offers`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
21
|
+
});
|
|
22
|
+
const json = await response.json();
|
|
23
|
+
(0, logging_1.log)(addPromoOffer.name, json);
|
|
24
|
+
return (0, obj_1.toCamelCase)(json);
|
|
25
|
+
}
|
|
26
|
+
async function updatePromoOffer(id, params) {
|
|
27
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/offers/${id}`, {
|
|
28
|
+
method: 'PATCH',
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
34
|
+
});
|
|
35
|
+
const json = await response.json();
|
|
36
|
+
(0, logging_1.log)(updatePromoOffer.name, json);
|
|
37
|
+
return (0, obj_1.toCamelCase)(json);
|
|
38
|
+
}
|
|
39
|
+
async function removePromoOffer(id) {
|
|
40
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/offers/${id}`, {
|
|
41
|
+
method: 'DELETE',
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const json = await response.json();
|
|
48
|
+
(0, logging_1.log)(removePromoOffer.name, json);
|
|
49
|
+
return response.ok;
|
|
50
|
+
}
|
|
51
|
+
async function getPromoOffers() {
|
|
52
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/offers`, {
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const json = await response.json();
|
|
59
|
+
(0, logging_1.log)(getPromoOffers.name, json);
|
|
60
|
+
return (0, obj_1.toCamelCase)(json);
|
|
61
|
+
}
|
|
62
|
+
async function checkPromoOffer(id, sub) {
|
|
63
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/offers/${id}/check?sub=${sub}`, {
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const json = await response.json();
|
|
70
|
+
(0, logging_1.log)(checkPromoOffer.name, json);
|
|
71
|
+
return json;
|
|
72
|
+
}
|
|
73
|
+
async function getPromoOfferRss(params) {
|
|
74
|
+
const url = new URL(`${(0, api_1.getGeneralApiUrl)()}/promo/offers/rss`);
|
|
75
|
+
if (params?.suiAddress) {
|
|
76
|
+
url.searchParams.append('sui_address', params.suiAddress);
|
|
77
|
+
}
|
|
78
|
+
else if (params?.evmAddress) {
|
|
79
|
+
url.searchParams.append('evm_address', params.evmAddress);
|
|
80
|
+
throw new Error('Currently not supported for EVM'); // Remove when implemented
|
|
81
|
+
}
|
|
82
|
+
const response = await fetch(url.toString(), {
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const json = await response.json();
|
|
89
|
+
(0, logging_1.log)(getPromoOfferRss.name, json);
|
|
90
|
+
return (0, obj_1.toCamelCase)(json);
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
let offerId;
|
|
5
|
+
test('Adds promo offer', async () => {
|
|
6
|
+
const result = await (0, _1.addPromoOffer)({
|
|
7
|
+
title: 'test',
|
|
8
|
+
description: 'test',
|
|
9
|
+
includeRules: ['1'],
|
|
10
|
+
excludeRules: ['1'],
|
|
11
|
+
code: 'test',
|
|
12
|
+
});
|
|
13
|
+
offerId = result.id;
|
|
14
|
+
expect(result.id).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
test('Updates promo offer', async () => {
|
|
17
|
+
const result = await (0, _1.updatePromoOffer)(offerId, {
|
|
18
|
+
title: 'test1',
|
|
19
|
+
code: 'test1',
|
|
20
|
+
includeRules: ['1', '2'],
|
|
21
|
+
excludeRules: [],
|
|
22
|
+
});
|
|
23
|
+
expect(result).toBeTruthy();
|
|
24
|
+
expect(result.title).toEqual('test1');
|
|
25
|
+
expect(result.code).toEqual('test1');
|
|
26
|
+
expect(result.includeRules).toEqual(['1', '2']);
|
|
27
|
+
expect(result.excludeRules).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
test('Gets promo offers', async () => {
|
|
30
|
+
const result = await (0, _1.getPromoOffers)();
|
|
31
|
+
expect(result).toBeTruthy();
|
|
32
|
+
expect(result.length).toBeGreaterThan(0);
|
|
33
|
+
const item = result.find((v) => v.id === offerId);
|
|
34
|
+
expect(item).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
test('Checks promo offer', async () => {
|
|
37
|
+
const result = await (0, _1.checkPromoOffer)(offerId, '1');
|
|
38
|
+
expect(result).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
test('Gets promo offer RSS', async () => {
|
|
41
|
+
const result = await (0, _1.getPromoOfferRss)({
|
|
42
|
+
suiAddress: '0x1',
|
|
43
|
+
});
|
|
44
|
+
expect(result.length).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
test('Deletes promo offer', async () => {
|
|
47
|
+
const result = await (0, _1.removePromoOffer)(offerId);
|
|
48
|
+
expect(result).toBe(true);
|
|
49
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TUpdateOfferParams = {
|
|
2
|
+
title?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
includeRules?: string[];
|
|
5
|
+
excludeRules?: string[];
|
|
6
|
+
code?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TCreateOfferParams = Required<TUpdateOfferParams>;
|
|
9
|
+
export type TOffer = TCreateOfferParams & {
|
|
10
|
+
id: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
};
|
|
13
|
+
export type TOfferRss = {
|
|
14
|
+
code: string;
|
|
15
|
+
offerId: string;
|
|
16
|
+
rss: {
|
|
17
|
+
title: string;
|
|
18
|
+
description: string;
|
|
19
|
+
link: string;
|
|
20
|
+
imageLink: string;
|
|
21
|
+
pubDate: string;
|
|
22
|
+
offerId: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rules';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rules"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TCreateRuleParams, TUpdateRuleParams, TRule } from './rules.types';
|
|
2
|
+
export declare function addPromoRule(params: TCreateRuleParams): Promise<TRule>;
|
|
3
|
+
export declare function updatePromoRule(id: string, params: TUpdateRuleParams): Promise<TRule>;
|
|
4
|
+
export declare function removePromoRule(id: string): Promise<boolean>;
|
|
5
|
+
export declare function getPromoRules(): Promise<TRule[]>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPromoRule = addPromoRule;
|
|
4
|
+
exports.updatePromoRule = updatePromoRule;
|
|
5
|
+
exports.removePromoRule = removePromoRule;
|
|
6
|
+
exports.getPromoRules = getPromoRules;
|
|
7
|
+
const logging_1 = require("../../../lib/logging");
|
|
8
|
+
const api_1 = require("../../../api");
|
|
9
|
+
const credentials_1 = require("../../../lib/credentials");
|
|
10
|
+
const obj_1 = require("../../../lib/obj");
|
|
11
|
+
async function addPromoRule(params) {
|
|
12
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/rules`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
19
|
+
});
|
|
20
|
+
const json = await response.json();
|
|
21
|
+
(0, logging_1.log)(addPromoRule.name, json);
|
|
22
|
+
return (0, obj_1.toCamelCase)(json);
|
|
23
|
+
}
|
|
24
|
+
async function updatePromoRule(id, params) {
|
|
25
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/rules/${id}`, {
|
|
26
|
+
method: 'PATCH',
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify((0, obj_1.toSnakeCase)(params)),
|
|
32
|
+
});
|
|
33
|
+
const json = await response.json();
|
|
34
|
+
(0, logging_1.log)(updatePromoRule.name, json);
|
|
35
|
+
return (0, obj_1.toCamelCase)(json);
|
|
36
|
+
}
|
|
37
|
+
async function removePromoRule(id) {
|
|
38
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/rules/${id}`, {
|
|
39
|
+
method: 'DELETE',
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const json = await response.json();
|
|
46
|
+
(0, logging_1.log)(removePromoRule.name, json);
|
|
47
|
+
return response.ok;
|
|
48
|
+
}
|
|
49
|
+
async function getPromoRules() {
|
|
50
|
+
const response = await fetch(`${(0, api_1.getGeneralApiUrl)()}/promo/rules`, {
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const json = await response.json();
|
|
57
|
+
(0, logging_1.log)(getPromoRules.name, json);
|
|
58
|
+
return (0, obj_1.toCamelCase)(json);
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require("./");
|
|
4
|
+
let ruleId;
|
|
5
|
+
test('Adds promo rule', async () => {
|
|
6
|
+
const result = await (0, _1.addPromoRule)({
|
|
7
|
+
title: 'test',
|
|
8
|
+
description: 'test',
|
|
9
|
+
resourceId: 'test',
|
|
10
|
+
chainType: 'evm',
|
|
11
|
+
chainId: 80002,
|
|
12
|
+
type: 'erc20',
|
|
13
|
+
value: 'test',
|
|
14
|
+
});
|
|
15
|
+
ruleId = result.id;
|
|
16
|
+
expect(result.id).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
test('Updates promo rule', async () => {
|
|
19
|
+
const result = await (0, _1.updatePromoRule)(ruleId, {
|
|
20
|
+
title: 'test1',
|
|
21
|
+
value: 'test1',
|
|
22
|
+
});
|
|
23
|
+
expect(result).toBeTruthy();
|
|
24
|
+
expect(result.title).toEqual('test1');
|
|
25
|
+
expect(result.value).toEqual('test1');
|
|
26
|
+
expect(result.description).toEqual('test');
|
|
27
|
+
});
|
|
28
|
+
test('Gets promo rules', async () => {
|
|
29
|
+
const result = await (0, _1.getPromoRules)();
|
|
30
|
+
expect(result).toBeTruthy();
|
|
31
|
+
expect(result.length).toBeGreaterThan(0);
|
|
32
|
+
const item = result.find((v) => v.id === ruleId);
|
|
33
|
+
expect(item).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
test('Deletes promo rule', async () => {
|
|
36
|
+
const result = await (0, _1.removePromoRule)(ruleId);
|
|
37
|
+
expect(result).toBe(true);
|
|
38
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TUpdateRuleParams = {
|
|
2
|
+
title?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
resourceId?: string;
|
|
5
|
+
chainType?: string;
|
|
6
|
+
chainId?: number;
|
|
7
|
+
type?: string;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type TCreateRuleParams = Required<TUpdateRuleParams>;
|
|
11
|
+
export type TRule = TCreateRuleParams & {
|
|
12
|
+
id: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './obj';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./obj"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCamelCase = toCamelCase;
|
|
4
|
+
exports.toSnakeCase = toSnakeCase;
|
|
5
|
+
function toCamelCase(obj) {
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
return obj.map(toCamelCase);
|
|
8
|
+
}
|
|
9
|
+
else if (obj !== null && typeof obj === 'object') {
|
|
10
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
11
|
+
const camelKey = key.replace(/^_id$/, 'id').replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
12
|
+
acc[camelKey] = toCamelCase(obj[key]);
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
function toSnakeCase(obj) {
|
|
19
|
+
if (Array.isArray(obj)) {
|
|
20
|
+
return obj.map(toSnakeCase);
|
|
21
|
+
}
|
|
22
|
+
else if (obj !== null && typeof obj === 'object') {
|
|
23
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
24
|
+
const snakeKey = key.replace(/([A-Z])/g, (_, letter) => `_${letter.toLowerCase()}`);
|
|
25
|
+
acc[snakeKey] = toSnakeCase(obj[key]);
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
const camelCase = {
|
|
5
|
+
firstKey: [
|
|
6
|
+
{
|
|
7
|
+
secondKey: 'value',
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
const snakeCase = {
|
|
12
|
+
first_key: [
|
|
13
|
+
{
|
|
14
|
+
second_key: 'value',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
test('Updates obj to snake_case', () => {
|
|
19
|
+
const result = (0, _1.toSnakeCase)(camelCase);
|
|
20
|
+
expect(result).toEqual(snakeCase);
|
|
21
|
+
});
|
|
22
|
+
test('Updates obj to camelCase', () => {
|
|
23
|
+
const result = (0, _1.toCamelCase)(snakeCase);
|
|
24
|
+
expect(result).toEqual(camelCase);
|
|
25
|
+
});
|
|
26
|
+
test('Replaces "_id" field', () => {
|
|
27
|
+
const obj = { _id: 1 };
|
|
28
|
+
const result = (0, _1.toCamelCase)(obj);
|
|
29
|
+
expect(result).toEqual({ id: 1 });
|
|
30
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credenza3/partner-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha.2",
|
|
4
4
|
"description": "Credenza partner sdk",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,57 +9,137 @@
|
|
|
9
9
|
"url": "https://github.com/credenza-web3/credenza-partner-sdk.git"
|
|
10
10
|
},
|
|
11
11
|
"author": "Credenza (Dmytro Fokin)",
|
|
12
|
-
"exports": {
|
|
13
|
-
"./sui": {
|
|
14
|
-
"node": "./dist/sui/index.js",
|
|
15
|
-
"types": "./dist/sui/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./evm": {
|
|
18
|
-
"node": "./dist/evm/index.js",
|
|
19
|
-
"types": "./dist/evm/index.d.ts"
|
|
20
|
-
},
|
|
21
|
-
"./api": {
|
|
22
|
-
"node": "./dist/api/index.js",
|
|
23
|
-
"types": "./dist/api/index.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./accounts": {
|
|
26
|
-
"node": "./dist/accounts/index.js",
|
|
27
|
-
"types": "./dist/accounts/index.d.ts"
|
|
28
|
-
},
|
|
29
|
-
".": {
|
|
30
|
-
"node": "./dist/index.js",
|
|
31
|
-
"types": "./dist/index.d.ts"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
12
|
"files": [
|
|
35
13
|
"/dist"
|
|
36
14
|
],
|
|
37
15
|
"dependencies": {
|
|
38
16
|
"buffer": "^6.0.3",
|
|
39
|
-
"socket.io-client": "^4.
|
|
17
|
+
"socket.io-client": "^4.8.0"
|
|
40
18
|
},
|
|
41
19
|
"devDependencies": {
|
|
42
20
|
"@eslint/eslintrc": "^3.1.0",
|
|
43
|
-
"@eslint/js": "^9.
|
|
44
|
-
"@types/
|
|
45
|
-
"@
|
|
46
|
-
"@typescript-eslint/
|
|
47
|
-
"eslint": "9.
|
|
21
|
+
"@eslint/js": "^9.12.0",
|
|
22
|
+
"@types/jest": "^29.5.13",
|
|
23
|
+
"@types/node": "^22.7.6",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.9.0",
|
|
25
|
+
"@typescript-eslint/parser": "^8.9.0",
|
|
26
|
+
"dotenv": "^16.4.5",
|
|
27
|
+
"eslint": "9.12.0",
|
|
48
28
|
"eslint-config-prettier": "^9.1.0",
|
|
49
29
|
"eslint-plugin-prettier": "^5.2.1",
|
|
50
|
-
"globals": "^15.
|
|
30
|
+
"globals": "^15.11.0",
|
|
51
31
|
"husky": "^9.1.6",
|
|
32
|
+
"jest": "^29.7.0",
|
|
52
33
|
"lint-staged": "^15.2.10",
|
|
53
34
|
"prettier": "^3.3.3",
|
|
35
|
+
"ts-jest": "^29.2.5",
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
54
37
|
"tsc-alias": "^1.8.10",
|
|
55
|
-
"typescript": "^5.6.
|
|
38
|
+
"typescript": "^5.6.3"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
"./accounts/client": {
|
|
42
|
+
"import": "./dist/accounts/client/index.js",
|
|
43
|
+
"require": "./dist/accounts/client/index.js",
|
|
44
|
+
"types": "./dist/accounts/client/index.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./accounts/client/jwt-auth": {
|
|
47
|
+
"import": "./dist/accounts/client/jwt-auth/index.js",
|
|
48
|
+
"require": "./dist/accounts/client/jwt-auth/index.js",
|
|
49
|
+
"types": "./dist/accounts/client/jwt-auth/index.d.ts"
|
|
50
|
+
},
|
|
51
|
+
"./accounts": {
|
|
52
|
+
"import": "./dist/accounts/index.js",
|
|
53
|
+
"require": "./dist/accounts/index.js",
|
|
54
|
+
"types": "./dist/accounts/index.d.ts"
|
|
55
|
+
},
|
|
56
|
+
"./accounts/oauth": {
|
|
57
|
+
"import": "./dist/accounts/oauth/index.js",
|
|
58
|
+
"require": "./dist/accounts/oauth/index.js",
|
|
59
|
+
"types": "./dist/accounts/oauth/index.d.ts"
|
|
60
|
+
},
|
|
61
|
+
"./accounts/user": {
|
|
62
|
+
"import": "./dist/accounts/user/index.js",
|
|
63
|
+
"require": "./dist/accounts/user/index.js",
|
|
64
|
+
"types": "./dist/accounts/user/index.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./api": {
|
|
67
|
+
"import": "./dist/api/index.js",
|
|
68
|
+
"require": "./dist/api/index.js",
|
|
69
|
+
"types": "./dist/api/index.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./api/nfc-id": {
|
|
72
|
+
"import": "./dist/api/nfc-id/index.js",
|
|
73
|
+
"require": "./dist/api/nfc-id/index.js",
|
|
74
|
+
"types": "./dist/api/nfc-id/index.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./api/passport-id": {
|
|
77
|
+
"import": "./dist/api/passport-id/index.js",
|
|
78
|
+
"require": "./dist/api/passport-id/index.js",
|
|
79
|
+
"types": "./dist/api/passport-id/index.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./api/promo": {
|
|
82
|
+
"import": "./dist/api/promo/index.js",
|
|
83
|
+
"require": "./dist/api/promo/index.js",
|
|
84
|
+
"types": "./dist/api/promo/index.d.ts"
|
|
85
|
+
},
|
|
86
|
+
"./api/promo/offers": {
|
|
87
|
+
"import": "./dist/api/promo/offers/index.js",
|
|
88
|
+
"require": "./dist/api/promo/offers/index.js",
|
|
89
|
+
"types": "./dist/api/promo/offers/index.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./api/promo/rules": {
|
|
92
|
+
"import": "./dist/api/promo/rules/index.js",
|
|
93
|
+
"require": "./dist/api/promo/rules/index.js",
|
|
94
|
+
"types": "./dist/api/promo/rules/index.d.ts"
|
|
95
|
+
},
|
|
96
|
+
"./evm/account": {
|
|
97
|
+
"import": "./dist/evm/account/index.js",
|
|
98
|
+
"require": "./dist/evm/account/index.js",
|
|
99
|
+
"types": "./dist/evm/account/index.d.ts"
|
|
100
|
+
},
|
|
101
|
+
"./evm/contract": {
|
|
102
|
+
"import": "./dist/evm/contract/index.js",
|
|
103
|
+
"require": "./dist/evm/contract/index.js",
|
|
104
|
+
"types": "./dist/evm/contract/index.d.ts"
|
|
105
|
+
},
|
|
106
|
+
"./evm": {
|
|
107
|
+
"import": "./dist/evm/index.js",
|
|
108
|
+
"require": "./dist/evm/index.js",
|
|
109
|
+
"types": "./dist/evm/index.d.ts"
|
|
110
|
+
},
|
|
111
|
+
".": {
|
|
112
|
+
"import": "./dist/index.js",
|
|
113
|
+
"require": "./dist/index.js",
|
|
114
|
+
"types": "./dist/index.d.ts"
|
|
115
|
+
},
|
|
116
|
+
"./sui/account": {
|
|
117
|
+
"import": "./dist/sui/account/index.js",
|
|
118
|
+
"require": "./dist/sui/account/index.js",
|
|
119
|
+
"types": "./dist/sui/account/index.d.ts"
|
|
120
|
+
},
|
|
121
|
+
"./sui": {
|
|
122
|
+
"import": "./dist/sui/index.js",
|
|
123
|
+
"require": "./dist/sui/index.js",
|
|
124
|
+
"types": "./dist/sui/index.d.ts"
|
|
125
|
+
},
|
|
126
|
+
"./sui/zk/account": {
|
|
127
|
+
"import": "./dist/sui/zk/account/index.js",
|
|
128
|
+
"require": "./dist/sui/zk/account/index.js",
|
|
129
|
+
"types": "./dist/sui/zk/account/index.d.ts"
|
|
130
|
+
},
|
|
131
|
+
"./sui/zk": {
|
|
132
|
+
"import": "./dist/sui/zk/index.js",
|
|
133
|
+
"require": "./dist/sui/zk/index.js",
|
|
134
|
+
"types": "./dist/sui/zk/index.d.ts"
|
|
135
|
+
}
|
|
56
136
|
},
|
|
57
137
|
"scripts": {
|
|
58
138
|
"build": "tsc && tsc-alias",
|
|
139
|
+
"build:exports": "node ./package.setup.mjs",
|
|
59
140
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
60
|
-
"lint": "eslint \"src/**/*.ts\" --fix --max-warnings 0",
|
|
61
|
-
"test": "
|
|
62
|
-
"pre-commit-lint": "lint-staged"
|
|
63
|
-
"demo": "pnpm run build && cd ./demo && pnpm i && pnpm run start"
|
|
141
|
+
"lint": "eslint \"src/**/*.ts\" --fix --max-warnings 0 --no-warn-ignored",
|
|
142
|
+
"test": "jest",
|
|
143
|
+
"pre-commit-lint": "lint-staged"
|
|
64
144
|
}
|
|
65
145
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './oauth-account';
|
package/dist/sui/zk/zk.d.ts
DELETED
package/dist/sui/zk/zk.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuiZkAddress = getSuiZkAddress;
|
|
4
|
-
const credentials_1 = require("../../lib/credentials");
|
|
5
|
-
const sui_1 = require("../sui");
|
|
6
|
-
async function getSuiZkAddress(sub) {
|
|
7
|
-
const response = await fetch(`${(0, sui_1.getSuiApiUrl)()}/accounts/zk/${sub}/address`, {
|
|
8
|
-
headers: {
|
|
9
|
-
Authorization: (0, credentials_1.getBasicToken)(),
|
|
10
|
-
'Content-Type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
const json = await response.json();
|
|
14
|
-
return json;
|
|
15
|
-
}
|