opticedge-cloud-utils 1.0.45 → 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/package.json +47 -6
- package/src/db/mongo.ts +1 -1
- package/src/db/mongo2.ts +1 -1
- package/src/db/mongo3.ts +1 -1
- package/src/{utils/tw-wallet.ts → tw/wallet.ts} +1 -1
- package/{src/auth/verify.test.ts → tests/auth.test.ts} +1 -1
- package/{src → tests}/db/mongo.test.ts +4 -4
- package/{src → tests}/db/mongo2.test.ts +5 -5
- package/{src → tests}/db/mongo3.test.ts +5 -5
- package/{src/utils → tests}/env.test.ts +1 -1
- package/{src/utils → tests}/regex.test.ts +1 -1
- package/{src/utils → tests}/secrets.test.ts +1 -1
- package/{src/utils → tests}/task.test.ts +1 -1
- package/{src/utils/tw-utils.test.ts → tests/tw/utils.test.ts} +1 -1
- package/{src/utils/tw-wallet.test.ts → tests/tw/wallet.test.ts} +3 -4
- package/dist/auth/verify.d.ts +0 -7
- package/dist/auth/verify.js +0 -23
- package/dist/auth/verify.test.d.ts +0 -1
- package/dist/auth/verify.test.js +0 -79
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -7
- package/dist/db/mongo.d.ts +0 -3
- package/dist/db/mongo.js +0 -27
- package/dist/db/mongo.test.d.ts +0 -1
- package/dist/db/mongo.test.js +0 -73
- package/dist/db/mongo2.d.ts +0 -4
- package/dist/db/mongo2.js +0 -30
- package/dist/db/mongo2.test.d.ts +0 -1
- package/dist/db/mongo2.test.js +0 -86
- package/dist/db/mongo3.d.ts +0 -6
- package/dist/db/mongo3.js +0 -39
- package/dist/db/mongo3.test.d.ts +0 -1
- package/dist/db/mongo3.test.js +0 -108
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -33
- package/dist/types/card.d.ts +0 -79
- package/dist/types/card.js +0 -19
- package/dist/types/notify.d.ts +0 -4
- package/dist/types/notify.js +0 -2
- package/dist/types/payment.d.ts +0 -1
- package/dist/types/payment.js +0 -2
- package/dist/types/pokemontcg.d.ts +0 -158
- package/dist/types/pokemontcg.js +0 -2
- package/dist/types/pricecharting.d.ts +0 -40
- package/dist/types/pricecharting.js +0 -2
- package/dist/types/user.d.ts +0 -37
- package/dist/types/user.js +0 -10
- package/dist/utils/env.d.ts +0 -1
- package/dist/utils/env.js +0 -12
- package/dist/utils/env.test.d.ts +0 -1
- package/dist/utils/env.test.js +0 -17
- package/dist/utils/regex.d.ts +0 -1
- package/dist/utils/regex.js +0 -6
- package/dist/utils/regex.test.d.ts +0 -1
- package/dist/utils/regex.test.js +0 -22
- package/dist/utils/secrets.d.ts +0 -8
- package/dist/utils/secrets.js +0 -22
- package/dist/utils/secrets.test.d.ts +0 -1
- package/dist/utils/secrets.test.js +0 -38
- package/dist/utils/task.d.ts +0 -1
- package/dist/utils/task.js +0 -38
- package/dist/utils/task.test.d.ts +0 -1
- package/dist/utils/task.test.js +0 -67
- package/dist/utils/tw-utils.d.ts +0 -1
- package/dist/utils/tw-utils.js +0 -19
- package/dist/utils/tw-utils.test.d.ts +0 -1
- package/dist/utils/tw-utils.test.js +0 -26
- package/dist/utils/tw-wallet.d.ts +0 -1
- package/dist/utils/tw-wallet.js +0 -32
- package/dist/utils/tw-wallet.test.d.ts +0 -1
- package/dist/utils/tw-wallet.test.js +0 -94
- package/src/constants.ts +0 -6
- package/src/index.ts +0 -17
- package/src/types/card.ts +0 -82
- package/src/types/notify.ts +0 -4
- package/src/types/payment.ts +0 -1
- package/src/types/pokemontcg.ts +0 -162
- package/src/types/pricecharting.ts +0 -42
- package/src/types/user.ts +0 -38
- /package/src/{auth/verify.ts → auth.ts} +0 -0
- /package/src/{utils/env.ts → env.ts} +0 -0
- /package/src/{utils/regex.ts → regex.ts} +0 -0
- /package/src/{utils/secrets.ts → secrets.ts} +0 -0
- /package/src/{utils/task.ts → task.ts} +0 -0
- /package/src/{utils/tw-utils.ts → tw/utils.ts} +0 -0
package/dist/utils/secrets.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSecret = getSecret;
|
|
4
|
-
const secret_manager_1 = require("@google-cloud/secret-manager");
|
|
5
|
-
/**
|
|
6
|
-
* Returns the latest value of a Secret Manager secret.
|
|
7
|
-
*
|
|
8
|
-
* @param projectId – GCP project that owns the secret.
|
|
9
|
-
* @param secretName – Secret name (without version).
|
|
10
|
-
* @returns – UTF-8 string value.
|
|
11
|
-
*/
|
|
12
|
-
async function getSecret(projectId, secretName) {
|
|
13
|
-
if (!projectId)
|
|
14
|
-
throw new Error('projectId is required');
|
|
15
|
-
if (!secretName)
|
|
16
|
-
throw new Error('secretName is required');
|
|
17
|
-
const secretClient = new secret_manager_1.SecretManagerServiceClient();
|
|
18
|
-
const [version] = await secretClient.accessSecretVersion({
|
|
19
|
-
name: `projects/${projectId}/secrets/${secretName}/versions/latest`
|
|
20
|
-
});
|
|
21
|
-
return version.payload?.data?.toString('utf-8') ?? '';
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const secrets_1 = require("./secrets");
|
|
4
|
-
const secret_manager_1 = require("@google-cloud/secret-manager");
|
|
5
|
-
jest.mock('@google-cloud/secret-manager');
|
|
6
|
-
// Mock implementation
|
|
7
|
-
const mockAccessSecretVersion = jest.fn();
|
|
8
|
-
secret_manager_1.SecretManagerServiceClient.mockImplementation(() => ({
|
|
9
|
-
accessSecretVersion: mockAccessSecretVersion
|
|
10
|
-
}));
|
|
11
|
-
describe('getSecret', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.clearAllMocks();
|
|
14
|
-
});
|
|
15
|
-
it('returns secret value as string', async () => {
|
|
16
|
-
mockAccessSecretVersion.mockResolvedValue([
|
|
17
|
-
{
|
|
18
|
-
payload: { data: Buffer.from('super-secret-value') }
|
|
19
|
-
}
|
|
20
|
-
]);
|
|
21
|
-
const result = await (0, secrets_1.getSecret)('test-project', 'test-secret');
|
|
22
|
-
expect(result).toBe('super-secret-value');
|
|
23
|
-
expect(mockAccessSecretVersion).toHaveBeenCalledWith({
|
|
24
|
-
name: 'projects/test-project/secrets/test-secret/versions/latest'
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
it('throws if projectId is missing', async () => {
|
|
28
|
-
await expect((0, secrets_1.getSecret)('', 'secret')).rejects.toThrow('projectId is required');
|
|
29
|
-
});
|
|
30
|
-
it('throws if secretName is missing', async () => {
|
|
31
|
-
await expect((0, secrets_1.getSecret)('project', '')).rejects.toThrow('secretName is required');
|
|
32
|
-
});
|
|
33
|
-
it('returns empty string if payload or data is missing', async () => {
|
|
34
|
-
mockAccessSecretVersion.mockResolvedValue([{}]); // no payload
|
|
35
|
-
const result = await (0, secrets_1.getSecret)('project', 'secret');
|
|
36
|
-
expect(result).toBe('');
|
|
37
|
-
});
|
|
38
|
-
});
|
package/dist/utils/task.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createTask(projectId: string, region: string, queueId: string, data: unknown, serviceAccount: string, audience: string, delaySeconds?: number): Promise<string>;
|
package/dist/utils/task.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTask = createTask;
|
|
4
|
-
const tasks_1 = require("@google-cloud/tasks");
|
|
5
|
-
const tasksClient = new tasks_1.CloudTasksClient();
|
|
6
|
-
async function createTask(projectId, region, queueId, data, serviceAccount, audience, delaySeconds = 0) {
|
|
7
|
-
if (!projectId || !region || !queueId || !serviceAccount || !audience) {
|
|
8
|
-
throw new Error('Missing required parameters for Cloud Tasks setup');
|
|
9
|
-
}
|
|
10
|
-
const parent = tasksClient.queuePath(projectId, region, queueId);
|
|
11
|
-
const now = Date.now() / 1000;
|
|
12
|
-
const scheduledTime = delaySeconds > 0
|
|
13
|
-
? {
|
|
14
|
-
seconds: Math.floor(now + delaySeconds)
|
|
15
|
-
}
|
|
16
|
-
: undefined;
|
|
17
|
-
const task = {
|
|
18
|
-
httpRequest: {
|
|
19
|
-
httpMethod: tasks_1.protos.google.cloud.tasks.v2.HttpMethod.POST,
|
|
20
|
-
url: audience,
|
|
21
|
-
headers: {
|
|
22
|
-
'Content-Type': 'application/json'
|
|
23
|
-
},
|
|
24
|
-
body: Buffer.from(JSON.stringify(data)).toString('base64'),
|
|
25
|
-
oidcToken: {
|
|
26
|
-
serviceAccountEmail: serviceAccount,
|
|
27
|
-
audience
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
scheduleTime: scheduledTime
|
|
31
|
-
};
|
|
32
|
-
const [response] = await tasksClient.createTask({ parent, task });
|
|
33
|
-
if (!response.name) {
|
|
34
|
-
throw new Error('Failed to create task: no name returned');
|
|
35
|
-
}
|
|
36
|
-
console.log(`✅ Created Cloud Task: ${response.name}`);
|
|
37
|
-
return response.name;
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/task.test.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mockCreateTask = jest.fn();
|
|
4
|
-
const mockQueuePath = jest.fn((projectId, region, queueId) => `projects/${projectId}/locations/${region}/queues/${queueId}`);
|
|
5
|
-
jest.mock('@google-cloud/tasks', () => {
|
|
6
|
-
return {
|
|
7
|
-
CloudTasksClient: jest.fn(() => ({
|
|
8
|
-
createTask: mockCreateTask,
|
|
9
|
-
queuePath: mockQueuePath
|
|
10
|
-
})),
|
|
11
|
-
protos: {
|
|
12
|
-
google: {
|
|
13
|
-
cloud: {
|
|
14
|
-
tasks: {
|
|
15
|
-
v2: {
|
|
16
|
-
HttpMethod: {
|
|
17
|
-
POST: 'POST'
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
const task_1 = require("./task");
|
|
27
|
-
describe('createTask', () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
mockCreateTask.mockReset();
|
|
30
|
-
});
|
|
31
|
-
it('throws error if any required parameter is missing', async () => {
|
|
32
|
-
// Missing projectId
|
|
33
|
-
await expect((0, task_1.createTask)('', 'region', 'queue', {}, 'serviceAccount', 'audience')).rejects.toThrow('Missing required parameters for Cloud Tasks setup');
|
|
34
|
-
// Missing region
|
|
35
|
-
await expect((0, task_1.createTask)('project', '', 'queue', {}, 'serviceAccount', 'audience')).rejects.toThrow('Missing required parameters for Cloud Tasks setup');
|
|
36
|
-
// Missing queueId
|
|
37
|
-
await expect((0, task_1.createTask)('project', 'region', '', {}, 'serviceAccount', 'audience')).rejects.toThrow('Missing required parameters for Cloud Tasks setup');
|
|
38
|
-
// Missing serviceAccount
|
|
39
|
-
await expect((0, task_1.createTask)('project', 'region', 'queue', {}, '', 'audience')).rejects.toThrow('Missing required parameters for Cloud Tasks setup');
|
|
40
|
-
// Missing audience
|
|
41
|
-
await expect((0, task_1.createTask)('project', 'region', 'queue', {}, 'serviceAccount', '')).rejects.toThrow('Missing required parameters for Cloud Tasks setup');
|
|
42
|
-
});
|
|
43
|
-
it('should create a task and return task name', async () => {
|
|
44
|
-
const mockTaskName = 'projects/test-project/locations/us-central1/queues/test-queue/tasks/task-123';
|
|
45
|
-
mockCreateTask.mockResolvedValue([{ name: mockTaskName }]);
|
|
46
|
-
const result = await (0, task_1.createTask)('test-project', 'us-central1', 'test-queue', { test: 'data' }, 'test-sa@test.iam.gserviceaccount.com', 'https://run-url');
|
|
47
|
-
expect(result).toBe(mockTaskName);
|
|
48
|
-
expect(mockCreateTask).toHaveBeenCalledTimes(1);
|
|
49
|
-
});
|
|
50
|
-
it('should throw error if task name is missing', async () => {
|
|
51
|
-
mockCreateTask.mockResolvedValue([{}]); // Simulate missing name
|
|
52
|
-
await expect((0, task_1.createTask)('test-project', 'us-central1', 'test-queue', { foo: 'bar' }, 'test@project.iam.gserviceaccount.com', 'https://example.com')).rejects.toThrow('Failed to create task: no name returned');
|
|
53
|
-
});
|
|
54
|
-
it('should include scheduleTime if delaySeconds is set', async () => {
|
|
55
|
-
const mockTaskName = 'projects/test/locations/us-central1/queues/test/tasks/task-456';
|
|
56
|
-
mockCreateTask.mockResolvedValue([{ name: mockTaskName }]);
|
|
57
|
-
const delaySeconds = 120;
|
|
58
|
-
const before = Math.floor(Date.now() / 1000) + delaySeconds;
|
|
59
|
-
await (0, task_1.createTask)('test', 'us-central1', 'test', { message: 'delayed' }, 'sa@test.iam.gserviceaccount.com', 'https://run-url', delaySeconds);
|
|
60
|
-
const taskArg = mockCreateTask.mock.calls[0][0].task;
|
|
61
|
-
const scheduleTime = taskArg.scheduleTime?.seconds;
|
|
62
|
-
const after = Math.floor(Date.now() / 1000) + delaySeconds;
|
|
63
|
-
expect(typeof scheduleTime).toBe('number');
|
|
64
|
-
expect(scheduleTime).toBeGreaterThanOrEqual(before);
|
|
65
|
-
expect(scheduleTime).toBeLessThanOrEqual(after);
|
|
66
|
-
});
|
|
67
|
-
});
|
package/dist/utils/tw-utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValidWebhookSignature(secret: string, body: string, signature: string): boolean;
|
package/dist/utils/tw-utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isValidWebhookSignature = isValidWebhookSignature;
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
const generateSignature = (body, secret) => {
|
|
9
|
-
return crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
10
|
-
};
|
|
11
|
-
function isValidWebhookSignature(secret, body, signature) {
|
|
12
|
-
const expectedSignature = generateSignature(body, secret);
|
|
13
|
-
const expectedBuffer = Buffer.from(expectedSignature);
|
|
14
|
-
const signatureBuffer = Buffer.from(signature);
|
|
15
|
-
if (expectedBuffer.length !== signatureBuffer.length) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return crypto_1.default.timingSafeEqual(expectedBuffer, signatureBuffer);
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const tw_utils_1 = require("./tw-utils");
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
describe('isValidWebhookSignature', () => {
|
|
9
|
-
const secret = 'test_secret';
|
|
10
|
-
const body = '{"message":"hello"}';
|
|
11
|
-
it('returns true for a valid signature', () => {
|
|
12
|
-
const validSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
13
|
-
expect((0, tw_utils_1.isValidWebhookSignature)(secret, body, validSignature)).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it('returns false for an invalid signature', () => {
|
|
16
|
-
const invalidSignature = 'invalidsignature123';
|
|
17
|
-
expect((0, tw_utils_1.isValidWebhookSignature)(secret, body, invalidSignature)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
it('returns false if body or secret is tampered', () => {
|
|
20
|
-
const originalSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
21
|
-
// wrong body
|
|
22
|
-
expect((0, tw_utils_1.isValidWebhookSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
|
|
23
|
-
// wrong secret
|
|
24
|
-
expect((0, tw_utils_1.isValidWebhookSignature)('wrong_secret', body, originalSignature)).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function pregenerateInAppWallet(projectId: string, twClientId: string, twSecretKeyName: string, email: string): Promise<string | null>;
|
package/dist/utils/tw-wallet.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.pregenerateInAppWallet = pregenerateInAppWallet;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const secrets_1 = require("./secrets");
|
|
9
|
-
async function pregenerateInAppWallet(projectId, twClientId, twSecretKeyName, email) {
|
|
10
|
-
const TW_SECRET_KEY = await (0, secrets_1.getSecret)(projectId, twSecretKeyName);
|
|
11
|
-
try {
|
|
12
|
-
const response = await axios_1.default.post('https://in-app-wallet.thirdweb.com/api/v1/pregenerate', { strategy: 'email', email }, {
|
|
13
|
-
headers: {
|
|
14
|
-
'x-secret-key': TW_SECRET_KEY,
|
|
15
|
-
'x-client-id': twClientId,
|
|
16
|
-
'Content-Type': 'application/json'
|
|
17
|
-
},
|
|
18
|
-
timeout: 5000
|
|
19
|
-
});
|
|
20
|
-
const wallet = response.data.wallet;
|
|
21
|
-
if (!wallet || !wallet.address) {
|
|
22
|
-
console.error('Invalid wallet response:', response.data);
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
console.log('Wallet pregeneration response:', wallet.address);
|
|
26
|
-
return wallet.address;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Error pregenerating wallet:', error);
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const axios_1 = __importDefault(require("axios"));
|
|
40
|
-
const tw_wallet_1 = require("./tw-wallet");
|
|
41
|
-
const secrets = __importStar(require("./secrets"));
|
|
42
|
-
jest.mock('axios');
|
|
43
|
-
jest.mock('opticedge-cloud-utils');
|
|
44
|
-
jest.mock('./secrets');
|
|
45
|
-
const mockedAxios = axios_1.default;
|
|
46
|
-
const mockedGetSecret = secrets.getSecret;
|
|
47
|
-
describe('pregenerateInAppWallet', () => {
|
|
48
|
-
const mockProjectId = 'test-project';
|
|
49
|
-
const mockClientId = 'test-client-id';
|
|
50
|
-
const mockSecretKeyName = 'test-key';
|
|
51
|
-
const mockEmail = 'user@example.com';
|
|
52
|
-
const mockWalletAddress = '0xabc123';
|
|
53
|
-
const mockSecretValue = 'mock-secret-key';
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
jest.clearAllMocks();
|
|
56
|
-
});
|
|
57
|
-
it('returns wallet address on success', async () => {
|
|
58
|
-
mockedGetSecret.mockResolvedValue(mockSecretValue);
|
|
59
|
-
mockedAxios.post.mockResolvedValue({
|
|
60
|
-
data: {
|
|
61
|
-
wallet: {
|
|
62
|
-
address: mockWalletAddress
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const result = await (0, tw_wallet_1.pregenerateInAppWallet)(mockProjectId, mockClientId, mockSecretKeyName, mockEmail);
|
|
67
|
-
expect(mockedGetSecret).toHaveBeenCalledWith(mockProjectId, mockSecretKeyName);
|
|
68
|
-
expect(mockedAxios.post).toHaveBeenCalledWith('https://in-app-wallet.thirdweb.com/api/v1/pregenerate', { strategy: 'email', email: mockEmail }, {
|
|
69
|
-
headers: {
|
|
70
|
-
'x-secret-key': mockSecretValue,
|
|
71
|
-
'x-client-id': mockClientId,
|
|
72
|
-
'Content-Type': 'application/json'
|
|
73
|
-
},
|
|
74
|
-
timeout: 5000
|
|
75
|
-
});
|
|
76
|
-
expect(result).toBe(mockWalletAddress);
|
|
77
|
-
});
|
|
78
|
-
it('returns null if wallet.address is missing', async () => {
|
|
79
|
-
mockedGetSecret.mockResolvedValue(mockSecretValue);
|
|
80
|
-
mockedAxios.post.mockResolvedValue({
|
|
81
|
-
data: {
|
|
82
|
-
wallet: {} // Missing address
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
const result = await (0, tw_wallet_1.pregenerateInAppWallet)(mockProjectId, mockClientId, mockSecretKeyName, mockEmail);
|
|
86
|
-
expect(result).toBeNull();
|
|
87
|
-
});
|
|
88
|
-
it('returns null on axios error', async () => {
|
|
89
|
-
mockedGetSecret.mockResolvedValue(mockSecretValue);
|
|
90
|
-
mockedAxios.post.mockRejectedValue(new Error('Network error'));
|
|
91
|
-
const result = await (0, tw_wallet_1.pregenerateInAppWallet)(mockProjectId, mockClientId, mockSecretKeyName, mockEmail);
|
|
92
|
-
expect(result).toBeNull();
|
|
93
|
-
});
|
|
94
|
-
});
|
package/src/constants.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './auth/verify'
|
|
2
|
-
export * from './db/mongo'
|
|
3
|
-
export * from './db/mongo2'
|
|
4
|
-
export * from './db/mongo3'
|
|
5
|
-
export * from './types/card'
|
|
6
|
-
export * from './types/notify'
|
|
7
|
-
export * from './types/payment'
|
|
8
|
-
export * from './types/pokemontcg'
|
|
9
|
-
export * from './types/pricecharting'
|
|
10
|
-
export * from './types/user'
|
|
11
|
-
export * from './utils/env'
|
|
12
|
-
export * from './utils/regex'
|
|
13
|
-
export * from './utils/secrets'
|
|
14
|
-
export * from './utils/task'
|
|
15
|
-
export * from './utils/tw-utils'
|
|
16
|
-
export * from './utils/tw-wallet'
|
|
17
|
-
export * from './constants'
|
package/src/types/card.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export enum CardApprovalStatus {
|
|
2
|
-
Rescan = -2,
|
|
3
|
-
Pending,
|
|
4
|
-
Failed,
|
|
5
|
-
Approved,
|
|
6
|
-
Approving = 999
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export enum CardGradingType {
|
|
10
|
-
UNKNOWN = 0,
|
|
11
|
-
COLLECTION = 1,
|
|
12
|
-
ADDED = 2,
|
|
13
|
-
SOLD = 3,
|
|
14
|
-
CARD_CENTERING = 6
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type MarketReport = {
|
|
18
|
-
data: string
|
|
19
|
-
title: string
|
|
20
|
-
price: {
|
|
21
|
-
currency: string
|
|
22
|
-
range: {
|
|
23
|
-
min: number
|
|
24
|
-
max: number
|
|
25
|
-
}
|
|
26
|
-
max: number
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type Card = {
|
|
31
|
-
_createdAt: number
|
|
32
|
-
_updatedAt: number
|
|
33
|
-
amountToReinvest: number
|
|
34
|
-
approved?: CardApprovalStatus
|
|
35
|
-
appraisalReport?: string
|
|
36
|
-
assetID: string
|
|
37
|
-
backImage: string
|
|
38
|
-
backImageUncropped: string
|
|
39
|
-
card_structure: number
|
|
40
|
-
countryLanguage?: string
|
|
41
|
-
cardType: string
|
|
42
|
-
category: string
|
|
43
|
-
centering_grading: number
|
|
44
|
-
corner_grading: number
|
|
45
|
-
edge_grading: number
|
|
46
|
-
frontImage: string
|
|
47
|
-
frontImageUncropped: string
|
|
48
|
-
gifUrl?: string
|
|
49
|
-
gradeDate: number
|
|
50
|
-
grading: number
|
|
51
|
-
grading_confidence: number
|
|
52
|
-
grading_environment: number
|
|
53
|
-
hp: number
|
|
54
|
-
identifier: string
|
|
55
|
-
isPulledFromPack: boolean
|
|
56
|
-
isRead: boolean
|
|
57
|
-
isSetCostOfCard: boolean
|
|
58
|
-
isSold: boolean
|
|
59
|
-
latitude: number
|
|
60
|
-
longitude: number
|
|
61
|
-
moneyEarn: number
|
|
62
|
-
marketLink?: string
|
|
63
|
-
marketReport?: MarketReport
|
|
64
|
-
name: string
|
|
65
|
-
note: string
|
|
66
|
-
number: string
|
|
67
|
-
priceHigh: number
|
|
68
|
-
priceLow: number
|
|
69
|
-
priceMarket: number
|
|
70
|
-
priceValue: number
|
|
71
|
-
releaseDate?: number
|
|
72
|
-
resultInvisible: boolean
|
|
73
|
-
saleNote: string
|
|
74
|
-
series: string
|
|
75
|
-
setName?: string
|
|
76
|
-
surface_grading: number
|
|
77
|
-
tcgLargeImageUrl: string
|
|
78
|
-
tcgSmallImageUrl: string
|
|
79
|
-
type: number
|
|
80
|
-
typeOfGrading: CardGradingType
|
|
81
|
-
userId: string
|
|
82
|
-
}
|
package/src/types/notify.ts
DELETED
package/src/types/payment.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type PaymentEnvironment = 'SANDBOX' | 'PRODUCTION'
|
package/src/types/pokemontcg.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { PriceChartingPrice } from './pricecharting'
|
|
2
|
-
|
|
3
|
-
export type TCGPlayerPrices = {
|
|
4
|
-
low: number
|
|
5
|
-
mid: number
|
|
6
|
-
high: number
|
|
7
|
-
market: number
|
|
8
|
-
directLow: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type CardMarketPrices = {
|
|
12
|
-
averageSellPrice: number
|
|
13
|
-
lowPrice: number
|
|
14
|
-
trendPrice: number
|
|
15
|
-
germanProLow: number
|
|
16
|
-
suggestedPrice: number
|
|
17
|
-
reverseHoloSell: number
|
|
18
|
-
reverseHoloLow: number
|
|
19
|
-
reverseHoloTrend: number
|
|
20
|
-
lowPriceExPlus: number
|
|
21
|
-
avg1: number
|
|
22
|
-
avg7: number
|
|
23
|
-
avg30: number
|
|
24
|
-
reverseHoloAvg1: number
|
|
25
|
-
reverseHoloAvg7: number
|
|
26
|
-
reverseHoloAvg30: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type PokemonTCGCard = {
|
|
30
|
-
id: string
|
|
31
|
-
name: string
|
|
32
|
-
supertype: string
|
|
33
|
-
subtypes: string[]
|
|
34
|
-
level: string
|
|
35
|
-
hp: string
|
|
36
|
-
evolvesFrom: string
|
|
37
|
-
evolvesTo: string[]
|
|
38
|
-
rules: string[]
|
|
39
|
-
ancientTrait: {
|
|
40
|
-
name: string
|
|
41
|
-
text: string
|
|
42
|
-
}
|
|
43
|
-
abilities: [
|
|
44
|
-
{
|
|
45
|
-
name: string
|
|
46
|
-
text: string
|
|
47
|
-
type: string
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
attacks: [
|
|
51
|
-
{
|
|
52
|
-
cost: string[]
|
|
53
|
-
name: string
|
|
54
|
-
text: string
|
|
55
|
-
damage: string
|
|
56
|
-
convertedEnergyCost: number
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
weaknesses: [
|
|
60
|
-
{
|
|
61
|
-
type: string
|
|
62
|
-
value: string
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
resistances: [
|
|
66
|
-
{
|
|
67
|
-
type: string
|
|
68
|
-
value: string
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
retreatCost: string[]
|
|
72
|
-
convertedRetreatCost: number
|
|
73
|
-
set: {
|
|
74
|
-
id: string
|
|
75
|
-
name: string
|
|
76
|
-
series: string
|
|
77
|
-
printedTotal: number
|
|
78
|
-
total: number
|
|
79
|
-
legalities: {
|
|
80
|
-
unlimited: string
|
|
81
|
-
standard: string
|
|
82
|
-
expanded: string
|
|
83
|
-
}
|
|
84
|
-
ptcgoCode: string
|
|
85
|
-
releaseDate: string
|
|
86
|
-
updatedAt: string
|
|
87
|
-
images: {
|
|
88
|
-
symbol: string
|
|
89
|
-
logo: string
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
number: string
|
|
93
|
-
artist: string
|
|
94
|
-
rarity: string
|
|
95
|
-
flavorText: string
|
|
96
|
-
nationalPokedexNumbers: number[]
|
|
97
|
-
legalities: [
|
|
98
|
-
{
|
|
99
|
-
standard: string
|
|
100
|
-
expanded: string
|
|
101
|
-
unlimited: string
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
regulationMark: string
|
|
105
|
-
images: {
|
|
106
|
-
small: string
|
|
107
|
-
large: string
|
|
108
|
-
}
|
|
109
|
-
tcgplayer: {
|
|
110
|
-
url: string
|
|
111
|
-
updatedAt: string
|
|
112
|
-
prices: {
|
|
113
|
-
normal?: TCGPlayerPrices
|
|
114
|
-
holofoil?: TCGPlayerPrices
|
|
115
|
-
reverseHolofoil?: TCGPlayerPrices
|
|
116
|
-
'1stEditionHolofoil'?: TCGPlayerPrices
|
|
117
|
-
'1stEditionNormal'?: TCGPlayerPrices
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
cardmarket: {
|
|
121
|
-
url: string
|
|
122
|
-
updatedAt: string
|
|
123
|
-
prices: CardMarketPrices
|
|
124
|
-
}
|
|
125
|
-
pricecharting?: {
|
|
126
|
-
id: number
|
|
127
|
-
prices: PriceChartingPrice
|
|
128
|
-
updatedAt: string
|
|
129
|
-
deleted?: boolean
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export type PokemonCard = {
|
|
134
|
-
_id: string
|
|
135
|
-
card_id: string
|
|
136
|
-
card_data: {
|
|
137
|
-
name: string
|
|
138
|
-
number: string
|
|
139
|
-
setName: string
|
|
140
|
-
setSeries: string
|
|
141
|
-
}
|
|
142
|
-
card: PokemonTCGCard
|
|
143
|
-
pricehistory: [
|
|
144
|
-
{
|
|
145
|
-
date: string
|
|
146
|
-
tcgplayer: {
|
|
147
|
-
normal: TCGPlayerPrices | null
|
|
148
|
-
holofoil: TCGPlayerPrices | null
|
|
149
|
-
reverseHolofoil: TCGPlayerPrices | null
|
|
150
|
-
firstEditionHolofoil: TCGPlayerPrices | null
|
|
151
|
-
firstEditionNormal: TCGPlayerPrices | null
|
|
152
|
-
}
|
|
153
|
-
cardmarket: CardMarketPrices
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
pricecharting_id: number
|
|
157
|
-
pricecharting_data: {
|
|
158
|
-
consoleName: string
|
|
159
|
-
productName: string
|
|
160
|
-
releaseDate: string
|
|
161
|
-
}
|
|
162
|
-
}
|