opticedge-cloud-utils 1.1.21 → 1.1.22

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.
Files changed (68) hide show
  1. package/package.json +1 -1
  2. package/tsconfig.json +1 -1
  3. package/dist/tests/auth.test.d.ts +0 -1
  4. package/dist/tests/auth.test.js +0 -79
  5. package/dist/tests/chunk.test.d.ts +0 -1
  6. package/dist/tests/chunk.test.js +0 -45
  7. package/dist/tests/db/mongo.test.d.ts +0 -1
  8. package/dist/tests/db/mongo.test.js +0 -43
  9. package/dist/tests/db/mongo2.test.d.ts +0 -1
  10. package/dist/tests/db/mongo2.test.js +0 -49
  11. package/dist/tests/db/mongo3.test.d.ts +0 -1
  12. package/dist/tests/db/mongo3.test.js +0 -60
  13. package/dist/tests/env.test.d.ts +0 -1
  14. package/dist/tests/env.test.js +0 -17
  15. package/dist/tests/number.test.d.ts +0 -1
  16. package/dist/tests/number.test.js +0 -30
  17. package/dist/tests/parser.test.d.ts +0 -1
  18. package/dist/tests/parser.test.js +0 -24
  19. package/dist/tests/pub.test.d.ts +0 -1
  20. package/dist/tests/pub.test.js +0 -102
  21. package/dist/tests/regex.test.d.ts +0 -1
  22. package/dist/tests/regex.test.js +0 -60
  23. package/dist/tests/retry.test.d.ts +0 -1
  24. package/dist/tests/retry.test.js +0 -339
  25. package/dist/tests/secrets.test.d.ts +0 -1
  26. package/dist/tests/secrets.test.js +0 -38
  27. package/dist/tests/task.test.d.ts +0 -1
  28. package/dist/tests/task.test.js +0 -262
  29. package/dist/tests/tw/utils.test.d.ts +0 -1
  30. package/dist/tests/tw/utils.test.js +0 -26
  31. package/dist/tests/tw/wallet.test.d.ts +0 -1
  32. package/dist/tests/tw/wallet.test.js +0 -108
  33. package/dist/tests/validator.d.ts +0 -1
  34. package/dist/tests/validator.js +0 -34
  35. /package/dist/{src/auth.d.ts → auth.d.ts} +0 -0
  36. /package/dist/{src/auth.js → auth.js} +0 -0
  37. /package/dist/{src/chunk.d.ts → chunk.d.ts} +0 -0
  38. /package/dist/{src/chunk.js → chunk.js} +0 -0
  39. /package/dist/{src/db → db}/mongo.d.ts +0 -0
  40. /package/dist/{src/db → db}/mongo.js +0 -0
  41. /package/dist/{src/db → db}/mongo2.d.ts +0 -0
  42. /package/dist/{src/db → db}/mongo2.js +0 -0
  43. /package/dist/{src/db → db}/mongo3.d.ts +0 -0
  44. /package/dist/{src/db → db}/mongo3.js +0 -0
  45. /package/dist/{src/env.d.ts → env.d.ts} +0 -0
  46. /package/dist/{src/env.js → env.js} +0 -0
  47. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  48. /package/dist/{src/index.js → index.js} +0 -0
  49. /package/dist/{src/number.d.ts → number.d.ts} +0 -0
  50. /package/dist/{src/number.js → number.js} +0 -0
  51. /package/dist/{src/parser.d.ts → parser.d.ts} +0 -0
  52. /package/dist/{src/parser.js → parser.js} +0 -0
  53. /package/dist/{src/pub.d.ts → pub.d.ts} +0 -0
  54. /package/dist/{src/pub.js → pub.js} +0 -0
  55. /package/dist/{src/regex.d.ts → regex.d.ts} +0 -0
  56. /package/dist/{src/regex.js → regex.js} +0 -0
  57. /package/dist/{src/retry.d.ts → retry.d.ts} +0 -0
  58. /package/dist/{src/retry.js → retry.js} +0 -0
  59. /package/dist/{src/secrets.d.ts → secrets.d.ts} +0 -0
  60. /package/dist/{src/secrets.js → secrets.js} +0 -0
  61. /package/dist/{src/task.d.ts → task.d.ts} +0 -0
  62. /package/dist/{src/task.js → task.js} +0 -0
  63. /package/dist/{src/tw → tw}/utils.d.ts +0 -0
  64. /package/dist/{src/tw → tw}/utils.js +0 -0
  65. /package/dist/{src/tw → tw}/wallet.d.ts +0 -0
  66. /package/dist/{src/tw → tw}/wallet.js +0 -0
  67. /package/dist/{src/validator.d.ts → validator.d.ts} +0 -0
  68. /package/dist/{src/validator.js → validator.js} +0 -0
@@ -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 utils_1 = require("../../src/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, utils_1.isValidWebhookSignature)(secret, body, validSignature)).toBe(true);
14
- });
15
- it('returns false for an invalid signature', () => {
16
- const invalidSignature = 'invalidsignature123';
17
- expect((0, 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, utils_1.isValidWebhookSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
23
- // wrong secret
24
- expect((0, utils_1.isValidWebhookSignature)('wrong_secret', body, originalSignature)).toBe(false);
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,108 +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
- // tests/tw/wallet.test.ts
7
- /* eslint-disable @typescript-eslint/no-explicit-any */
8
- const axios_1 = __importDefault(require("axios"));
9
- const wallet_1 = require("../../src/tw/wallet");
10
- jest.mock('axios');
11
- const mockedAxios = axios_1.default;
12
- function makeAxiosError(message, status, noResponse = false) {
13
- const err = new Error(message);
14
- err.isAxiosError = true;
15
- if (!noResponse) {
16
- err.response = {
17
- status: typeof status === 'number' ? status : 500,
18
- data: { message: `mocked ${status ?? 500}` }
19
- };
20
- }
21
- else {
22
- // simulate network error (no response)
23
- delete err.response;
24
- }
25
- return err;
26
- }
27
- function makeSuccessResponse(data) {
28
- return { data, status: 200 };
29
- }
30
- describe('pregenerateInAppWallet (current signature)', () => {
31
- const mockClientId = 'test-client-id';
32
- const mockSecretKey = 'test-secret-key';
33
- const mockEmail = 'user@example.com';
34
- const mockWalletAddress = '0xabc123';
35
- const realMathRandom = Math.random;
36
- const realWarn = console.warn;
37
- const realError = console.error;
38
- beforeEach(() => {
39
- jest.clearAllMocks();
40
- // make retry jitter deterministic (so delays don't interfere)
41
- Math.random = jest.fn(() => 0);
42
- // axios.isAxiosError helper
43
- jest
44
- .spyOn(axios_1.default, 'isAxiosError')
45
- .mockImplementation((e) => Boolean(e && e.isAxiosError));
46
- // silence logs during tests but keep spies
47
- console.warn = jest.fn();
48
- console.error = jest.fn();
49
- });
50
- afterEach(() => {
51
- Math.random = realMathRandom;
52
- console.warn = realWarn;
53
- console.error = realError;
54
- });
55
- it('returns null and logs if params missing', async () => {
56
- const res = await (0, wallet_1.pregenerateInAppWallet)('', mockSecretKey, mockEmail);
57
- expect(mockedAxios.post).not.toHaveBeenCalled();
58
- expect(res).toBeNull();
59
- expect(console.error.mock.calls.length).toBeGreaterThanOrEqual(1);
60
- expect(console.error.mock.calls[0][0]).toEqual('Missing client id or secret or email');
61
- });
62
- it('retries on 500 then succeeds and returns address', async () => {
63
- // first: 500, then success
64
- mockedAxios.post
65
- .mockRejectedValueOnce(makeAxiosError('server error', 500))
66
- .mockResolvedValueOnce({ data: { wallet: { address: mockWalletAddress } } });
67
- const result = await (0, wallet_1.pregenerateInAppWallet)(mockClientId, mockSecretKey, mockEmail);
68
- expect(mockedAxios.post).toHaveBeenCalledTimes(2);
69
- expect(result).toBe(mockWalletAddress);
70
- expect(console.warn.mock.calls.length).toBeGreaterThanOrEqual(1);
71
- });
72
- it('does NOT retry on 400 and returns null immediately', async () => {
73
- mockedAxios.post.mockRejectedValue(makeAxiosError('bad request', 400));
74
- const result = await (0, wallet_1.pregenerateInAppWallet)(mockClientId, mockSecretKey, mockEmail);
75
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
76
- expect(result).toBeNull();
77
- // no retry log
78
- expect(console.warn.mock.calls.length).toBe(0);
79
- });
80
- it('retries on network/no-response errors and then succeeds', async () => {
81
- mockedAxios.post
82
- .mockRejectedValueOnce(makeAxiosError('network down', undefined, true))
83
- .mockResolvedValueOnce({ data: { wallet: { address: mockWalletAddress } } });
84
- const result = await (0, wallet_1.pregenerateInAppWallet)(mockClientId, mockSecretKey, mockEmail);
85
- expect(mockedAxios.post).toHaveBeenCalledTimes(2);
86
- expect(result).toBe(mockWalletAddress);
87
- });
88
- it('exhausts retries on repeated 500s and returns null', async () => {
89
- mockedAxios.post.mockRejectedValue(makeAxiosError('server error', 500));
90
- const result = await (0, wallet_1.pregenerateInAppWallet)(mockClientId, mockSecretKey, mockEmail);
91
- // retry behavior is implementation-dependent; assert at least one call and final null
92
- expect(mockedAxios.post.mock.calls.length).toBeGreaterThanOrEqual(1);
93
- expect(result).toBeNull();
94
- expect(console.error.mock.calls.length).toBeGreaterThanOrEqual(1);
95
- });
96
- it('logs invalid wallet shape and returns null when wallet.address missing (2xx response)', async () => {
97
- mockedAxios.post.mockResolvedValueOnce(makeSuccessResponse({ wallet: {} }));
98
- const result = await (0, wallet_1.pregenerateInAppWallet)(mockClientId, mockSecretKey, mockEmail);
99
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
100
- expect(result).toBeNull();
101
- // ensure we logged the invalid shape (the implementation logs then throws)
102
- expect(console.error.mock.calls.length).toBeGreaterThanOrEqual(1);
103
- const firstArg = console.error.mock.calls[0][0];
104
- expect(firstArg).toEqual('Invalid wallet response shape');
105
- const secondArg = console.error.mock.calls[0][1];
106
- expect(secondArg).toEqual(expect.objectContaining({ status: 200, data: { wallet: {} } }));
107
- });
108
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // isValidEmail.test.ts
4
- const globals_1 = require("@jest/globals");
5
- const src_1 = require("../src");
6
- (0, globals_1.describe)('isValidEmail', () => {
7
- (0, globals_1.it)('returns true for simple valid emails', () => {
8
- (0, globals_1.expect)((0, src_1.isValidEmail)('test@example.com')).toBe(true);
9
- (0, globals_1.expect)((0, src_1.isValidEmail)('user.name@domain.co')).toBe(true);
10
- (0, globals_1.expect)((0, src_1.isValidEmail)('user_name+tag@sub.domain.org')).toBe(true);
11
- });
12
- (0, globals_1.it)('returns false for missing parts', () => {
13
- (0, globals_1.expect)((0, src_1.isValidEmail)('')).toBe(false);
14
- (0, globals_1.expect)((0, src_1.isValidEmail)('plainaddress')).toBe(false);
15
- (0, globals_1.expect)((0, src_1.isValidEmail)('@no-local-part.com')).toBe(false);
16
- (0, globals_1.expect)((0, src_1.isValidEmail)('username@')).toBe(false);
17
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@domain')).toBe(false);
18
- (0, globals_1.expect)((0, src_1.isValidEmail)('username@.com')).toBe(false);
19
- });
20
- (0, globals_1.it)('handles whitespace correctly', () => {
21
- (0, globals_1.expect)((0, src_1.isValidEmail)(' test@example.com ')).toBe(true); // trims input
22
- (0, globals_1.expect)((0, src_1.isValidEmail)('\nuser@domain.com\t')).toBe(true);
23
- });
24
- (0, globals_1.it)('rejects invalid characters or formats', () => {
25
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@@domain.com')).toBe(false);
26
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@domain,com')).toBe(false);
27
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@domain..com')).toBe(false);
28
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@.domain.com')).toBe(false);
29
- (0, globals_1.expect)((0, src_1.isValidEmail)('user@domain com')).toBe(false);
30
- });
31
- (0, globals_1.it)('accepts minimal valid domain structures', () => {
32
- (0, globals_1.expect)((0, src_1.isValidEmail)('x@y.z')).toBe(true); // still valid
33
- });
34
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes