opticedge-cloud-utils 1.0.45 → 1.1.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.
Files changed (82) hide show
  1. package/dist/db/mongo.js +1 -1
  2. package/dist/db/mongo2.js +1 -1
  3. package/dist/db/mongo3.js +1 -1
  4. package/dist/index.d.ts +7 -14
  5. package/dist/index.js +7 -14
  6. package/dist/{utils → tw}/tw-wallet.js +1 -1
  7. package/package.json +5 -4
  8. package/src/db/mongo.ts +1 -1
  9. package/src/db/mongo2.ts +1 -1
  10. package/src/db/mongo3.ts +1 -1
  11. package/src/index.ts +7 -14
  12. package/src/{utils → tw}/tw-wallet.ts +1 -1
  13. package/{src/auth/verify.test.ts → tests/auth.test.ts} +1 -1
  14. package/{src → tests}/db/mongo.test.ts +4 -4
  15. package/{src → tests}/db/mongo2.test.ts +5 -5
  16. package/{src → tests}/db/mongo3.test.ts +5 -5
  17. package/{src/utils → tests}/env.test.ts +1 -1
  18. package/{src/utils → tests}/regex.test.ts +1 -1
  19. package/{src/utils → tests}/secrets.test.ts +1 -1
  20. package/{src/utils → tests}/task.test.ts +1 -1
  21. package/{src/utils → tests/tw}/tw-utils.test.ts +1 -1
  22. package/{src/utils → tests/tw}/tw-wallet.test.ts +3 -4
  23. package/dist/auth/verify.test.d.ts +0 -1
  24. package/dist/auth/verify.test.js +0 -79
  25. package/dist/constants.d.ts +0 -2
  26. package/dist/constants.js +0 -7
  27. package/dist/db/mongo.test.d.ts +0 -1
  28. package/dist/db/mongo.test.js +0 -73
  29. package/dist/db/mongo2.test.d.ts +0 -1
  30. package/dist/db/mongo2.test.js +0 -86
  31. package/dist/db/mongo3.test.d.ts +0 -1
  32. package/dist/db/mongo3.test.js +0 -108
  33. package/dist/types/card.d.ts +0 -79
  34. package/dist/types/card.js +0 -19
  35. package/dist/types/notify.d.ts +0 -4
  36. package/dist/types/notify.js +0 -2
  37. package/dist/types/payment.d.ts +0 -1
  38. package/dist/types/payment.js +0 -2
  39. package/dist/types/pokemontcg.d.ts +0 -158
  40. package/dist/types/pokemontcg.js +0 -2
  41. package/dist/types/pricecharting.d.ts +0 -40
  42. package/dist/types/pricecharting.js +0 -2
  43. package/dist/types/user.d.ts +0 -37
  44. package/dist/types/user.js +0 -10
  45. package/dist/utils/env.test.d.ts +0 -1
  46. package/dist/utils/env.test.js +0 -17
  47. package/dist/utils/regex.test.d.ts +0 -1
  48. package/dist/utils/regex.test.js +0 -22
  49. package/dist/utils/secrets.test.d.ts +0 -1
  50. package/dist/utils/secrets.test.js +0 -38
  51. package/dist/utils/task.test.d.ts +0 -1
  52. package/dist/utils/task.test.js +0 -67
  53. package/dist/utils/tw-utils.test.d.ts +0 -1
  54. package/dist/utils/tw-utils.test.js +0 -26
  55. package/dist/utils/tw-wallet.test.d.ts +0 -1
  56. package/dist/utils/tw-wallet.test.js +0 -94
  57. package/src/constants.ts +0 -6
  58. package/src/types/card.ts +0 -82
  59. package/src/types/notify.ts +0 -4
  60. package/src/types/payment.ts +0 -1
  61. package/src/types/pokemontcg.ts +0 -162
  62. package/src/types/pricecharting.ts +0 -42
  63. package/src/types/user.ts +0 -38
  64. /package/dist/{auth/verify.d.ts → auth.d.ts} +0 -0
  65. /package/dist/{auth/verify.js → auth.js} +0 -0
  66. /package/dist/{utils/env.d.ts → env.d.ts} +0 -0
  67. /package/dist/{utils/env.js → env.js} +0 -0
  68. /package/dist/{utils/regex.d.ts → regex.d.ts} +0 -0
  69. /package/dist/{utils/regex.js → regex.js} +0 -0
  70. /package/dist/{utils/secrets.d.ts → secrets.d.ts} +0 -0
  71. /package/dist/{utils/secrets.js → secrets.js} +0 -0
  72. /package/dist/{utils/task.d.ts → task.d.ts} +0 -0
  73. /package/dist/{utils/task.js → task.js} +0 -0
  74. /package/dist/{utils → tw}/tw-utils.d.ts +0 -0
  75. /package/dist/{utils → tw}/tw-utils.js +0 -0
  76. /package/dist/{utils → tw}/tw-wallet.d.ts +0 -0
  77. /package/src/{auth/verify.ts → auth.ts} +0 -0
  78. /package/src/{utils/env.ts → env.ts} +0 -0
  79. /package/src/{utils/regex.ts → regex.ts} +0 -0
  80. /package/src/{utils/secrets.ts → secrets.ts} +0 -0
  81. /package/src/{utils/task.ts → task.ts} +0 -0
  82. /package/src/{utils → tw}/tw-utils.ts +0 -0
@@ -1,108 +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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const mongo3_1 = require("./mongo3");
37
- const mongodb_1 = require("mongodb");
38
- const secretsModule = __importStar(require("../utils/secrets"));
39
- jest.mock('mongodb');
40
- jest.mock('../utils/secrets');
41
- const mockDb = {
42
- collection: jest.fn()
43
- };
44
- const mockConnect = jest.fn();
45
- const mockClient = {
46
- connect: mockConnect,
47
- db: jest.fn().mockReturnValue(mockDb)
48
- };
49
- beforeEach(() => {
50
- jest.clearAllMocks();
51
- mongo3_1.__mongoClients.clear();
52
- mongo3_1.__connectPromises.clear();
53
- secretsModule.getSecret.mockResolvedValue('mongodb://mock-uri');
54
- mongodb_1.MongoClient.mockImplementation(() => mockClient);
55
- });
56
- describe('MongoClientManager (multi-cluster)', () => {
57
- const clusterASecret = 'clusterA-uri-secret';
58
- const clusterBSecret = 'clusterB-uri-secret';
59
- it('should connect and cache client for a single cluster', async () => {
60
- await (0, mongo3_1.connectToMongo3)('test-project', clusterASecret);
61
- expect(secretsModule.getSecret).toHaveBeenCalledWith('test-project', clusterASecret);
62
- expect(mockConnect).toHaveBeenCalled();
63
- const db = (0, mongo3_1.getDb3)(clusterASecret, 'test-db');
64
- expect(mockClient.db).toHaveBeenCalledWith('test-db');
65
- expect(db).toBe(mockDb);
66
- });
67
- it('should reuse client if already connected', async () => {
68
- await (0, mongo3_1.connectToMongo3)('test-project', clusterASecret);
69
- await (0, mongo3_1.connectToMongo3)('test-project', clusterASecret);
70
- // getSecret and connect should only happen once
71
- expect(secretsModule.getSecret).toHaveBeenCalledTimes(1);
72
- expect(mockConnect).toHaveBeenCalledTimes(1);
73
- });
74
- it('should connect and cache separate clients for multiple clusters', async () => {
75
- // Mock different URIs for 2 clusters
76
- ;
77
- secretsModule.getSecret
78
- .mockResolvedValueOnce('mongodb://mock-uri-A')
79
- .mockResolvedValueOnce('mongodb://mock-uri-B');
80
- await (0, mongo3_1.connectToMongo3)('test-project', clusterASecret);
81
- await (0, mongo3_1.connectToMongo3)('test-project', clusterBSecret);
82
- // Should call getSecret + connect twice (for 2 clusters)
83
- expect(secretsModule.getSecret).toHaveBeenCalledTimes(2);
84
- expect(secretsModule.getSecret).toHaveBeenCalledWith('test-project', clusterASecret);
85
- expect(secretsModule.getSecret).toHaveBeenCalledWith('test-project', clusterBSecret);
86
- expect(mockConnect).toHaveBeenCalledTimes(2);
87
- });
88
- it('should return a collection when client is initialized', async () => {
89
- await (0, mongo3_1.connectToMongo3)('test-project', clusterASecret);
90
- (0, mongo3_1.getCollection3)(clusterASecret, 'test-db', 'users');
91
- expect(mockClient.db).toHaveBeenCalledWith('test-db');
92
- expect(mockDb.collection).toHaveBeenCalledWith('users');
93
- });
94
- it('should throw error if client not initialized (getDb)', () => {
95
- jest.isolateModules(() => {
96
- // eslint-disable-next-line @typescript-eslint/no-require-imports
97
- const { getDb3 } = require('./mongo3');
98
- expect(() => getDb3('unknown-uri-secret', 'some-db')).toThrow('Mongo client for secret "unknown-uri-secret" not initialized');
99
- });
100
- });
101
- it('should throw error if client not initialized (getCollection)', () => {
102
- jest.isolateModules(() => {
103
- // eslint-disable-next-line @typescript-eslint/no-require-imports
104
- const { getCollection3 } = require('./mongo3');
105
- expect(() => getCollection3('unknown-uri-secret', 'some-db', 'users')).toThrow('Mongo client for secret "unknown-uri-secret" not initialized');
106
- });
107
- });
108
- });
@@ -1,79 +0,0 @@
1
- export declare enum CardApprovalStatus {
2
- Rescan = -2,
3
- Pending = -1,
4
- Failed = 0,
5
- Approved = 1,
6
- Approving = 999
7
- }
8
- export declare enum CardGradingType {
9
- UNKNOWN = 0,
10
- COLLECTION = 1,
11
- ADDED = 2,
12
- SOLD = 3,
13
- CARD_CENTERING = 6
14
- }
15
- export type MarketReport = {
16
- data: string;
17
- title: string;
18
- price: {
19
- currency: string;
20
- range: {
21
- min: number;
22
- max: number;
23
- };
24
- max: number;
25
- };
26
- };
27
- export type Card = {
28
- _createdAt: number;
29
- _updatedAt: number;
30
- amountToReinvest: number;
31
- approved?: CardApprovalStatus;
32
- appraisalReport?: string;
33
- assetID: string;
34
- backImage: string;
35
- backImageUncropped: string;
36
- card_structure: number;
37
- countryLanguage?: string;
38
- cardType: string;
39
- category: string;
40
- centering_grading: number;
41
- corner_grading: number;
42
- edge_grading: number;
43
- frontImage: string;
44
- frontImageUncropped: string;
45
- gifUrl?: string;
46
- gradeDate: number;
47
- grading: number;
48
- grading_confidence: number;
49
- grading_environment: number;
50
- hp: number;
51
- identifier: string;
52
- isPulledFromPack: boolean;
53
- isRead: boolean;
54
- isSetCostOfCard: boolean;
55
- isSold: boolean;
56
- latitude: number;
57
- longitude: number;
58
- moneyEarn: number;
59
- marketLink?: string;
60
- marketReport?: MarketReport;
61
- name: string;
62
- note: string;
63
- number: string;
64
- priceHigh: number;
65
- priceLow: number;
66
- priceMarket: number;
67
- priceValue: number;
68
- releaseDate?: number;
69
- resultInvisible: boolean;
70
- saleNote: string;
71
- series: string;
72
- setName?: string;
73
- surface_grading: number;
74
- tcgLargeImageUrl: string;
75
- tcgSmallImageUrl: string;
76
- type: number;
77
- typeOfGrading: CardGradingType;
78
- userId: string;
79
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CardGradingType = exports.CardApprovalStatus = void 0;
4
- var CardApprovalStatus;
5
- (function (CardApprovalStatus) {
6
- CardApprovalStatus[CardApprovalStatus["Rescan"] = -2] = "Rescan";
7
- CardApprovalStatus[CardApprovalStatus["Pending"] = -1] = "Pending";
8
- CardApprovalStatus[CardApprovalStatus["Failed"] = 0] = "Failed";
9
- CardApprovalStatus[CardApprovalStatus["Approved"] = 1] = "Approved";
10
- CardApprovalStatus[CardApprovalStatus["Approving"] = 999] = "Approving";
11
- })(CardApprovalStatus || (exports.CardApprovalStatus = CardApprovalStatus = {}));
12
- var CardGradingType;
13
- (function (CardGradingType) {
14
- CardGradingType[CardGradingType["UNKNOWN"] = 0] = "UNKNOWN";
15
- CardGradingType[CardGradingType["COLLECTION"] = 1] = "COLLECTION";
16
- CardGradingType[CardGradingType["ADDED"] = 2] = "ADDED";
17
- CardGradingType[CardGradingType["SOLD"] = 3] = "SOLD";
18
- CardGradingType[CardGradingType["CARD_CENTERING"] = 6] = "CARD_CENTERING";
19
- })(CardGradingType || (exports.CardGradingType = CardGradingType = {}));
@@ -1,4 +0,0 @@
1
- export type Message = {
2
- title: string;
3
- body: string;
4
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export type PaymentEnvironment = 'SANDBOX' | 'PRODUCTION';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,158 +0,0 @@
1
- import { PriceChartingPrice } from './pricecharting';
2
- export type TCGPlayerPrices = {
3
- low: number;
4
- mid: number;
5
- high: number;
6
- market: number;
7
- directLow: number;
8
- };
9
- export type CardMarketPrices = {
10
- averageSellPrice: number;
11
- lowPrice: number;
12
- trendPrice: number;
13
- germanProLow: number;
14
- suggestedPrice: number;
15
- reverseHoloSell: number;
16
- reverseHoloLow: number;
17
- reverseHoloTrend: number;
18
- lowPriceExPlus: number;
19
- avg1: number;
20
- avg7: number;
21
- avg30: number;
22
- reverseHoloAvg1: number;
23
- reverseHoloAvg7: number;
24
- reverseHoloAvg30: number;
25
- };
26
- export type PokemonTCGCard = {
27
- id: string;
28
- name: string;
29
- supertype: string;
30
- subtypes: string[];
31
- level: string;
32
- hp: string;
33
- evolvesFrom: string;
34
- evolvesTo: string[];
35
- rules: string[];
36
- ancientTrait: {
37
- name: string;
38
- text: string;
39
- };
40
- abilities: [
41
- {
42
- name: string;
43
- text: string;
44
- type: string;
45
- }
46
- ];
47
- attacks: [
48
- {
49
- cost: string[];
50
- name: string;
51
- text: string;
52
- damage: string;
53
- convertedEnergyCost: number;
54
- }
55
- ];
56
- weaknesses: [
57
- {
58
- type: string;
59
- value: string;
60
- }
61
- ];
62
- resistances: [
63
- {
64
- type: string;
65
- value: string;
66
- }
67
- ];
68
- retreatCost: string[];
69
- convertedRetreatCost: number;
70
- set: {
71
- id: string;
72
- name: string;
73
- series: string;
74
- printedTotal: number;
75
- total: number;
76
- legalities: {
77
- unlimited: string;
78
- standard: string;
79
- expanded: string;
80
- };
81
- ptcgoCode: string;
82
- releaseDate: string;
83
- updatedAt: string;
84
- images: {
85
- symbol: string;
86
- logo: string;
87
- };
88
- };
89
- number: string;
90
- artist: string;
91
- rarity: string;
92
- flavorText: string;
93
- nationalPokedexNumbers: number[];
94
- legalities: [
95
- {
96
- standard: string;
97
- expanded: string;
98
- unlimited: string;
99
- }
100
- ];
101
- regulationMark: string;
102
- images: {
103
- small: string;
104
- large: string;
105
- };
106
- tcgplayer: {
107
- url: string;
108
- updatedAt: string;
109
- prices: {
110
- normal?: TCGPlayerPrices;
111
- holofoil?: TCGPlayerPrices;
112
- reverseHolofoil?: TCGPlayerPrices;
113
- '1stEditionHolofoil'?: TCGPlayerPrices;
114
- '1stEditionNormal'?: TCGPlayerPrices;
115
- };
116
- };
117
- cardmarket: {
118
- url: string;
119
- updatedAt: string;
120
- prices: CardMarketPrices;
121
- };
122
- pricecharting?: {
123
- id: number;
124
- prices: PriceChartingPrice;
125
- updatedAt: string;
126
- deleted?: boolean;
127
- };
128
- };
129
- export type PokemonCard = {
130
- _id: string;
131
- card_id: string;
132
- card_data: {
133
- name: string;
134
- number: string;
135
- setName: string;
136
- setSeries: string;
137
- };
138
- card: PokemonTCGCard;
139
- pricehistory: [
140
- {
141
- date: string;
142
- tcgplayer: {
143
- normal: TCGPlayerPrices | null;
144
- holofoil: TCGPlayerPrices | null;
145
- reverseHolofoil: TCGPlayerPrices | null;
146
- firstEditionHolofoil: TCGPlayerPrices | null;
147
- firstEditionNormal: TCGPlayerPrices | null;
148
- };
149
- cardmarket: CardMarketPrices;
150
- }
151
- ];
152
- pricecharting_id: number;
153
- pricecharting_data: {
154
- consoleName: string;
155
- productName: string;
156
- releaseDate: string;
157
- };
158
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,40 +0,0 @@
1
- export type PriceChartingPrice = {
2
- loose: number | null;
3
- cib: number | null;
4
- new: number | null;
5
- graded: number | null;
6
- boxOnly: number | null;
7
- manualOnly: number | null;
8
- bgs10: number | null;
9
- condition17: number | null;
10
- condition18: number | null;
11
- gamestop: number | null;
12
- gamestopTrade: number | null;
13
- retailLooseBuy: number | null;
14
- retailLooseSell: number | null;
15
- retailCibBuy: number | null;
16
- retailCibSell: number | null;
17
- retailNewBuy: number | null;
18
- retailNewSell: number | null;
19
- };
20
- export type PriceChartingPriceEntry = {
21
- date: string;
22
- price: PriceChartingPrice;
23
- };
24
- export type PriceChartingCard = {
25
- id: number;
26
- consoleName: string;
27
- productName: string;
28
- upc: string;
29
- genre: string;
30
- tcgId: string;
31
- asin: string;
32
- epid: string;
33
- releaseDate: string;
34
- price: PriceChartingPrice;
35
- priceHistory: PriceChartingPriceEntry[];
36
- salesVolume: number | null;
37
- salesVolumeHistory: (number | null)[];
38
- updatedAt: string;
39
- deleted?: boolean;
40
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,37 +0,0 @@
1
- export declare enum UserCollectorType {
2
- 'Non-member' = -1,
3
- Elite = 0,
4
- Rookie = 1,
5
- Free = 2
6
- }
7
- export type User = {
8
- cards: {
9
- count: number;
10
- };
11
- collections: {
12
- count: number;
13
- };
14
- email: string;
15
- fcmTokens: Record<string, boolean>;
16
- firstName: string;
17
- fundAmount: number;
18
- fundalert: number;
19
- id: string;
20
- insights: {
21
- count: number;
22
- };
23
- isAppleUser: boolean;
24
- isFacebookUser: boolean;
25
- lastCardIndex: number;
26
- lastGradingTime: number;
27
- lastName: string;
28
- soldCards: {
29
- count: number;
30
- };
31
- thumbnail: string | undefined;
32
- _collectorType: UserCollectorType;
33
- _createdAt: number;
34
- _currency: string;
35
- _id: string;
36
- _updatedAt: number;
37
- };
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserCollectorType = void 0;
4
- var UserCollectorType;
5
- (function (UserCollectorType) {
6
- UserCollectorType[UserCollectorType["Non-member"] = -1] = "Non-member";
7
- UserCollectorType[UserCollectorType["Elite"] = 0] = "Elite";
8
- UserCollectorType[UserCollectorType["Rookie"] = 1] = "Rookie";
9
- UserCollectorType[UserCollectorType["Free"] = 2] = "Free";
10
- })(UserCollectorType || (exports.UserCollectorType = UserCollectorType = {}));
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const env_1 = require("./env");
4
- describe('getEnv', () => {
5
- it('returns the value of an existing env var', () => {
6
- process.env.TEST_KEY = 'test-value';
7
- expect((0, env_1.getEnv)('TEST_KEY')).toBe('test-value');
8
- });
9
- it('returns fallback if env var is not set', () => {
10
- delete process.env.OPTIONAL_KEY;
11
- expect((0, env_1.getEnv)('OPTIONAL_KEY', 'default')).toBe('default');
12
- });
13
- it('throws error if env var is not set and no fallback provided', () => {
14
- delete process.env.MISSING_KEY;
15
- expect(() => (0, env_1.getEnv)('MISSING_KEY')).toThrow('Missing env var MISSING_KEY');
16
- });
17
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const regex_1 = require("./regex");
4
- describe('escapeRegex', () => {
5
- it('escapes regex special characters', () => {
6
- const input = 'Pikachu.$^*+?()[]{}|\\';
7
- const expected = 'Pikachu\\.\\$\\^\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\';
8
- expect((0, regex_1.escapeRegex)(input)).toBe(expected);
9
- });
10
- it('returns same string if no special characters', () => {
11
- const input = 'Charmander123';
12
- expect((0, regex_1.escapeRegex)(input)).toBe('Charmander123');
13
- });
14
- it('works with empty string', () => {
15
- expect((0, regex_1.escapeRegex)('')).toBe('');
16
- });
17
- it('does not escape regular alphanumerics or spaces', () => {
18
- const input = 'Lt. Surge Pikachu';
19
- const expected = 'Lt\\. Surge Pikachu';
20
- expect((0, regex_1.escapeRegex)(input)).toBe(expected);
21
- });
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -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
- });
@@ -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 {};