@paakd/api 0.0.4 → 0.0.6

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 (65) hide show
  1. package/dist/gen/src/proto/files/v1/entities/file_pb.d.ts +199 -0
  2. package/dist/gen/src/proto/files/v1/entities/file_pb.d.ts.map +1 -0
  3. package/dist/gen/src/proto/files/v1/entities/file_pb.js +77 -0
  4. package/dist/gen/src/proto/files/v1/service_pb.d.ts +44 -0
  5. package/dist/gen/src/proto/files/v1/service_pb.d.ts.map +1 -0
  6. package/dist/gen/src/proto/files/v1/service_pb.js +18 -0
  7. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.d.ts +391 -0
  8. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.d.ts.map +1 -0
  9. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.js +140 -0
  10. package/dist/gen/src/proto/promotions/v1/service_pb.d.ts +68 -0
  11. package/dist/gen/src/proto/promotions/v1/service_pb.d.ts.map +1 -0
  12. package/dist/gen/src/proto/promotions/v1/service_pb.js +18 -0
  13. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.d.ts +508 -0
  14. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.d.ts.map +1 -0
  15. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.js +150 -0
  16. package/dist/gen/src/proto/stocknodes/v1/service_pb.d.ts +68 -0
  17. package/dist/gen/src/proto/stocknodes/v1/service_pb.d.ts.map +1 -0
  18. package/dist/gen/src/proto/stocknodes/v1/service_pb.js +18 -0
  19. package/dist/src/index.d.ts +828 -5
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/index.js +48 -5
  22. package/dist/src/interceptors.d.ts +1 -1
  23. package/dist/src/interceptors.d.ts.map +1 -1
  24. package/dist/src/interceptors.js +1 -4
  25. package/dist/src/interceptors.spec.js +0 -94
  26. package/package.json +6 -6
  27. package/dist/src/address.d.ts +0 -53
  28. package/dist/src/address.d.ts.map +0 -1
  29. package/dist/src/address.js +0 -233
  30. package/dist/src/address.spec.d.ts +0 -2
  31. package/dist/src/address.spec.d.ts.map +0 -1
  32. package/dist/src/address.spec.js +0 -488
  33. package/dist/src/auth.d.ts +0 -27
  34. package/dist/src/auth.d.ts.map +0 -1
  35. package/dist/src/auth.js +0 -155
  36. package/dist/src/auth.spec.d.ts +0 -2
  37. package/dist/src/auth.spec.d.ts.map +0 -1
  38. package/dist/src/auth.spec.js +0 -582
  39. package/dist/src/compressor/brotli.d.ts +0 -3
  40. package/dist/src/compressor/brotli.d.ts.map +0 -1
  41. package/dist/src/compressor/brotli.js +0 -30
  42. package/dist/src/policies.d.ts +0 -217
  43. package/dist/src/policies.d.ts.map +0 -1
  44. package/dist/src/policies.js +0 -322
  45. package/dist/src/policies.spec.d.ts +0 -2
  46. package/dist/src/policies.spec.d.ts.map +0 -1
  47. package/dist/src/policies.spec.js +0 -463
  48. package/dist/src/products.d.ts +0 -39
  49. package/dist/src/products.d.ts.map +0 -1
  50. package/dist/src/products.js +0 -95
  51. package/dist/src/products.spec.d.ts +0 -2
  52. package/dist/src/products.spec.d.ts.map +0 -1
  53. package/dist/src/products.spec.js +0 -519
  54. package/dist/src/profile.d.ts +0 -62
  55. package/dist/src/profile.d.ts.map +0 -1
  56. package/dist/src/profile.js +0 -151
  57. package/dist/src/profile.spec.d.ts +0 -2
  58. package/dist/src/profile.spec.d.ts.map +0 -1
  59. package/dist/src/profile.spec.js +0 -475
  60. package/dist/src/registration.d.ts +0 -60
  61. package/dist/src/registration.d.ts.map +0 -1
  62. package/dist/src/registration.js +0 -147
  63. package/dist/src/test-utils.d.ts +0 -87
  64. package/dist/src/test-utils.d.ts.map +0 -1
  65. package/dist/src/test-utils.js +0 -132
@@ -1,463 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const connect_1 = require("@connectrpc/connect");
13
- const connect_node_1 = require("@connectrpc/connect-node");
14
- const config_1 = require("@paakd/config");
15
- const interceptors_1 = require("./interceptors");
16
- const policies_1 = require("./policies");
17
- // Mock dependencies
18
- vi.mock('@connectrpc/connect', () => __awaiter(void 0, void 0, void 0, function* () {
19
- const actual = yield vi.importActual('@connectrpc/connect');
20
- return Object.assign(Object.assign({}, actual), { createClient: vi.fn() });
21
- }));
22
- vi.mock('./compressor/brotli', () => ({
23
- brotliCompression: {
24
- name: 'brotli',
25
- compress: vi.fn(),
26
- decompress: vi.fn(),
27
- },
28
- }));
29
- vi.mock('@connectrpc/connect-node', () => ({
30
- createGrpcTransport: vi.fn(),
31
- }));
32
- vi.mock('@paakd/config', () => ({
33
- getCheckoutConfig: vi.fn(),
34
- }));
35
- vi.mock('./interceptors', () => ({
36
- createAuthenticationInterceptor: vi.fn(),
37
- createHeadersInterceptor: vi.fn().mockReturnValue(() => { }),
38
- }));
39
- vi.mock('../gen/src/proto/auth/v1/service_pb', () => ({
40
- AuthService: {},
41
- }));
42
- const mockGetCheckoutConfig = vi.mocked(config_1.getCheckoutConfig);
43
- const mockCreateGrpcTransport = vi.mocked(connect_node_1.createGrpcTransport);
44
- const mockCreateClient = vi.mocked(connect_1.createClient);
45
- const mockCreateAuthenticationInterceptor = vi.mocked(interceptors_1.createAuthenticationInterceptor);
46
- const mockCreateHeadersInterceptor = vi.mocked(interceptors_1.createHeadersInterceptor);
47
- describe('policies', () => {
48
- let mockAuthClient;
49
- let mockTransport;
50
- let mockCheckoutConfig;
51
- let mockInterceptor;
52
- beforeEach(() => {
53
- // Reset all mocks
54
- vi.clearAllMocks();
55
- // Setup mock objects
56
- mockAuthClient = {
57
- getPolicies: vi.fn(),
58
- savePolicies: vi.fn(),
59
- addPolicy: vi.fn(),
60
- addPolicies: vi.fn(),
61
- removePolicy: vi.fn(),
62
- removePolicies: vi.fn(),
63
- removeFilteredPolicy: vi.fn(),
64
- getFilteredPolicy: vi.fn(),
65
- };
66
- mockTransport = {};
67
- mockCheckoutConfig = {
68
- enterpriseURL: 'https://enterprise.example.com',
69
- };
70
- mockInterceptor = {};
71
- // Setup mock implementations
72
- mockGetCheckoutConfig.mockResolvedValue(mockCheckoutConfig);
73
- mockCreateGrpcTransport.mockReturnValue(mockTransport);
74
- mockCreateAuthenticationInterceptor.mockReturnValue(mockInterceptor);
75
- mockCreateHeadersInterceptor.mockReturnValue(mockInterceptor);
76
- mockCreateClient.mockReturnValue(mockAuthClient);
77
- });
78
- describe('getPolicies', () => {
79
- it('should return policies on success', () => __awaiter(void 0, void 0, void 0, function* () {
80
- const mockPolicies = [
81
- { pType: 'p', v0: 'alice', v1: 'data1', v2: 'read' },
82
- { pType: 'p', v0: 'bob', v1: 'data2', v2: 'write' },
83
- ];
84
- mockAuthClient.getPolicies.mockResolvedValue({
85
- policies: mockPolicies,
86
- });
87
- const result = yield (0, policies_1.getPolicies)({
88
- headers: {},
89
- });
90
- expect(config_1.getCheckoutConfig).toHaveBeenCalled();
91
- expect(connect_node_1.createGrpcTransport).toHaveBeenCalledWith({
92
- baseUrl: mockCheckoutConfig.enterpriseURL,
93
- interceptors: [mockInterceptor, mockInterceptor],
94
- acceptCompression: expect.any(Array), // Accept gzip and Brotli compression
95
- sendCompression: expect.any(Object), // Send Brotli compression
96
- });
97
- expect(connect_1.createClient).toHaveBeenCalledWith({}, mockTransport);
98
- expect(mockAuthClient.getPolicies).toHaveBeenCalledWith({});
99
- expect(result).toEqual({
100
- value: mockPolicies,
101
- status: 'success',
102
- });
103
- }));
104
- it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
105
- const connectError = {
106
- code: connect_1.Code.Unauthenticated,
107
- rawMessage: 'Invalid credentials',
108
- message: 'Authentication failed',
109
- name: 'ConnectError',
110
- };
111
- // Make it pass instanceof check
112
- Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
113
- mockAuthClient.getPolicies.mockRejectedValue(connectError);
114
- const result = yield (0, policies_1.getPolicies)({
115
- headers: {},
116
- });
117
- expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid credentials', status: 'failed' }));
118
- }));
119
- it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
120
- const unexpectedError = new Error('Network error');
121
- mockAuthClient.getPolicies.mockRejectedValue(unexpectedError);
122
- const result = yield (0, policies_1.getPolicies)({
123
- headers: {},
124
- });
125
- expect(result).toEqual({
126
- code: connect_1.Code.Internal,
127
- rawMessage: 'An unexpected error occurred during login.',
128
- message: 'An unexpected error occurred during login.',
129
- status: 'failed',
130
- });
131
- }));
132
- });
133
- describe('savePolicies', () => {
134
- it('should save policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
135
- const inputPolicies = [
136
- ['p', 'alice', 'data1', 'read'],
137
- ['p', 'bob', 'data2', 'write'],
138
- ];
139
- mockAuthClient.savePolicies.mockResolvedValue({});
140
- const result = yield (0, policies_1.savePolicies)({
141
- headers: {},
142
- body: { inPolicies: inputPolicies },
143
- });
144
- expect(mockAuthClient.savePolicies).toHaveBeenCalledWith({
145
- policies: [
146
- {
147
- pType: 'p',
148
- v0: 'alice',
149
- v1: 'data1',
150
- v2: 'read',
151
- v3: '',
152
- v4: '',
153
- v5: '',
154
- },
155
- {
156
- pType: 'p',
157
- v0: 'bob',
158
- v1: 'data2',
159
- v2: 'write',
160
- v3: '',
161
- v4: '',
162
- v5: '',
163
- },
164
- ],
165
- });
166
- expect(result).toEqual({ status: 'success' });
167
- }));
168
- it('should handle policies with different lengths', () => __awaiter(void 0, void 0, void 0, function* () {
169
- const inputPolicies = [
170
- ['p', 'alice'],
171
- ['p', 'bob', 'data2', 'write', 'extra1', 'extra2', 'extra3', 'extra4'],
172
- ];
173
- mockAuthClient.savePolicies.mockResolvedValue({});
174
- const result = yield (0, policies_1.savePolicies)({
175
- headers: {},
176
- body: { inPolicies: inputPolicies },
177
- });
178
- expect(mockAuthClient.savePolicies).toHaveBeenCalledWith({
179
- policies: [
180
- { pType: 'p', v0: 'alice', v1: '', v2: '', v3: '', v4: '', v5: '' },
181
- {
182
- pType: 'p',
183
- v0: 'bob',
184
- v1: 'data2',
185
- v2: 'write',
186
- v3: 'extra1',
187
- v4: 'extra2',
188
- v5: 'extra3',
189
- },
190
- ],
191
- });
192
- expect(result).toEqual({ status: 'success' });
193
- }));
194
- it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
195
- const connectError = {
196
- code: connect_1.Code.Internal,
197
- rawMessage: 'Database error',
198
- message: 'Save failed',
199
- name: 'ConnectError',
200
- };
201
- // Make it pass instanceof check
202
- Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
203
- mockAuthClient.savePolicies.mockRejectedValue(connectError);
204
- const result = yield (0, policies_1.savePolicies)({
205
- headers: {},
206
- body: { inPolicies: [['p', 'alice']] },
207
- });
208
- expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Database error', status: 'failed' }));
209
- }));
210
- });
211
- describe('addPolicy', () => {
212
- it('should add policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
213
- const rule = ['alice', 'data1', 'read'];
214
- const pType = 'p';
215
- mockAuthClient.addPolicy.mockResolvedValue({});
216
- const result = yield (0, policies_1.addPolicy)({
217
- headers: {},
218
- body: { rule, pType },
219
- });
220
- expect(mockAuthClient.addPolicy).toHaveBeenCalledWith({ rule, pType });
221
- expect(result).toEqual({ status: 'success' });
222
- }));
223
- it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
224
- const connectError = {
225
- code: connect_1.Code.InvalidArgument,
226
- rawMessage: 'Invalid policy format',
227
- message: 'Add failed',
228
- name: 'ConnectError',
229
- };
230
- // Make it pass instanceof check
231
- Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
232
- mockAuthClient.addPolicy.mockRejectedValue(connectError);
233
- const result = yield (0, policies_1.addPolicy)({
234
- headers: {},
235
- body: { rule: ['alice'], pType: 'p' },
236
- });
237
- expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid policy format', status: 'failed' }));
238
- }));
239
- });
240
- describe('addPolicies', () => {
241
- it('should add multiple policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
242
- const rules = [
243
- ['alice', 'data1', 'read'],
244
- ['bob', 'data2', 'write'],
245
- ];
246
- const pType = 'p';
247
- mockAuthClient.addPolicies.mockResolvedValue({});
248
- const result = yield (0, policies_1.addPolicies)({
249
- headers: {},
250
- body: { inRules: rules, pType },
251
- });
252
- expect(mockAuthClient.addPolicies).toHaveBeenCalledWith({
253
- rules: [
254
- { rules: ['alice', 'data1', 'read'] },
255
- { rules: ['bob', 'data2', 'write'] },
256
- ],
257
- pType,
258
- });
259
- expect(result).toEqual({ status: 'success' });
260
- }));
261
- it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
262
- const unexpectedError = new Error('Network timeout');
263
- mockAuthClient.addPolicies.mockRejectedValue(unexpectedError);
264
- const result = yield (0, policies_1.addPolicies)({
265
- headers: {},
266
- body: { inRules: [['alice']], pType: 'p' },
267
- });
268
- expect(result).toEqual({
269
- code: connect_1.Code.Internal,
270
- rawMessage: 'An unexpected error occurred while adding policies.',
271
- message: 'An unexpected error occurred while adding policies.',
272
- status: 'failed',
273
- });
274
- }));
275
- });
276
- describe('removePolicy', () => {
277
- it('should remove policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
278
- const rule = ['alice', 'data1', 'read'];
279
- const pType = 'p';
280
- mockAuthClient.removePolicy.mockResolvedValue({});
281
- const result = yield (0, policies_1.removePolicy)({
282
- headers: {},
283
- body: { rule, pType },
284
- });
285
- expect(mockAuthClient.removePolicy).toHaveBeenCalledWith({ rule, pType });
286
- expect(result).toEqual({ status: 'success' });
287
- }));
288
- it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
289
- const connectError = {
290
- code: connect_1.Code.NotFound,
291
- rawMessage: 'Policy not found',
292
- message: 'Remove failed',
293
- name: 'ConnectError',
294
- };
295
- // Make it pass instanceof check
296
- Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
297
- mockAuthClient.removePolicy.mockRejectedValue(connectError);
298
- const result = yield (0, policies_1.removePolicy)({
299
- headers: {},
300
- body: { rule: ['alice'], pType: 'p' },
301
- });
302
- expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Policy not found', status: 'failed' }));
303
- }));
304
- });
305
- describe('removePolicies', () => {
306
- it('should remove multiple policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
307
- const rules = [
308
- ['alice', 'data1', 'read'],
309
- ['bob', 'data2', 'write'],
310
- ];
311
- const pType = 'p';
312
- mockAuthClient.removePolicies.mockResolvedValue({});
313
- const result = yield (0, policies_1.removePolicies)({
314
- headers: {},
315
- body: { inRules: rules, pType },
316
- });
317
- expect(mockAuthClient.removePolicies).toHaveBeenCalledWith({
318
- rules: [
319
- { rules: ['alice', 'data1', 'read'] },
320
- { rules: ['bob', 'data2', 'write'] },
321
- ],
322
- pType,
323
- });
324
- expect(result).toEqual({ status: 'success' });
325
- }));
326
- });
327
- describe('removeFilteredPolicy', () => {
328
- it('should remove filtered policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
329
- const pType = 'p';
330
- const fieldIndex = 0;
331
- const fieldValues = ['alice'];
332
- mockAuthClient.removeFilteredPolicy.mockResolvedValue({});
333
- const result = yield (0, policies_1.removeFilteredPolicy)({
334
- headers: {},
335
- body: { pType, fieldIndex, fieldValues },
336
- });
337
- expect(mockAuthClient.removeFilteredPolicy).toHaveBeenCalledWith({
338
- pType,
339
- fieldIndex,
340
- fieldValues,
341
- });
342
- expect(result).toEqual({ status: 'success' });
343
- }));
344
- it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
345
- const connectError = {
346
- code: connect_1.Code.InvalidArgument,
347
- rawMessage: 'Invalid filter criteria',
348
- message: 'Filter failed',
349
- name: 'ConnectError',
350
- };
351
- // Make it pass instanceof check
352
- Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
353
- mockAuthClient.removeFilteredPolicy.mockRejectedValue(connectError);
354
- const result = yield (0, policies_1.removeFilteredPolicy)({
355
- headers: {},
356
- body: { pType: 'p', fieldIndex: 0, fieldValues: ['alice'] },
357
- });
358
- expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid filter criteria', status: 'failed' }));
359
- }));
360
- });
361
- describe('getFilteredPolicy', () => {
362
- it('should get filtered policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
363
- const filter = {
364
- v0: [['alice'], ['bob']],
365
- v1: [['data1']],
366
- };
367
- const mockPolicies = [
368
- { pType: 'p', v0: 'alice', v1: 'data1', v2: 'read' },
369
- ];
370
- mockAuthClient.getFilteredPolicy.mockResolvedValue({
371
- policies: mockPolicies,
372
- });
373
- const result = yield (0, policies_1.getFilteredPolicy)({
374
- headers: {},
375
- body: { inFilter: filter },
376
- });
377
- expect(mockAuthClient.getFilteredPolicy).toHaveBeenCalledWith({
378
- filter: [
379
- {
380
- key: 'v0',
381
- values: [{ items: ['alice'] }, { items: ['bob'] }],
382
- },
383
- {
384
- key: 'v1',
385
- values: [{ items: ['data1'] }],
386
- },
387
- ],
388
- });
389
- expect(result).toEqual({
390
- value: mockPolicies,
391
- status: 'success',
392
- });
393
- }));
394
- it('should handle empty filter', () => __awaiter(void 0, void 0, void 0, function* () {
395
- const filter = {};
396
- mockAuthClient.getFilteredPolicy.mockResolvedValue({
397
- policies: [],
398
- });
399
- const result = yield (0, policies_1.getFilteredPolicy)({
400
- headers: {},
401
- body: { inFilter: filter },
402
- });
403
- expect(mockAuthClient.getFilteredPolicy).toHaveBeenCalledWith({
404
- filter: [],
405
- });
406
- expect(result).toEqual({
407
- value: [],
408
- status: 'success',
409
- });
410
- }));
411
- it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
412
- const unexpectedError = new Error('Database connection failed');
413
- mockAuthClient.getFilteredPolicy.mockRejectedValue(unexpectedError);
414
- const result = yield (0, policies_1.getFilteredPolicy)({
415
- headers: {},
416
- body: { inFilter: {} },
417
- });
418
- expect(result).toEqual({
419
- code: connect_1.Code.Internal,
420
- rawMessage: 'An unexpected error occurred while fetching policies.',
421
- message: 'An unexpected error occurred while fetching policies.',
422
- status: 'failed',
423
- });
424
- }));
425
- });
426
- describe('common functionality', () => {
427
- it('should setup transport and client consistently across all functions', () => __awaiter(void 0, void 0, void 0, function* () {
428
- // Test one function to verify the setup pattern
429
- yield (0, policies_1.getPolicies)({
430
- headers: {},
431
- });
432
- expect(config_1.getCheckoutConfig).toHaveBeenCalled();
433
- expect(interceptors_1.createAuthenticationInterceptor).toHaveBeenCalledWith(mockCheckoutConfig);
434
- expect(connect_node_1.createGrpcTransport).toHaveBeenCalledWith({
435
- baseUrl: mockCheckoutConfig.enterpriseURL,
436
- interceptors: [mockInterceptor, mockInterceptor],
437
- acceptCompression: expect.any(Array), // Accept gzip and Brotli compression
438
- sendCompression: expect.any(Object), // Send Brotli compression
439
- });
440
- expect(connect_1.createClient).toHaveBeenCalledWith({}, mockTransport);
441
- }));
442
- it('should use consistent timeout across all functions', () => __awaiter(void 0, void 0, void 0, function* () {
443
- mockAuthClient.getPolicies.mockResolvedValue({ policies: [] });
444
- mockAuthClient.addPolicy.mockResolvedValue({});
445
- mockAuthClient.removePolicy.mockResolvedValue({});
446
- yield (0, policies_1.getPolicies)({
447
- headers: {},
448
- });
449
- yield (0, policies_1.addPolicy)({
450
- headers: {},
451
- body: { rule: ['alice'], pType: 'p' },
452
- });
453
- yield (0, policies_1.removePolicy)({
454
- headers: {},
455
- body: { rule: ['bob'], pType: 'p' },
456
- });
457
- // Verify all calls use the same timeout
458
- expect(mockAuthClient.getPolicies).toHaveBeenCalledWith({});
459
- expect(mockAuthClient.addPolicy).toHaveBeenCalledWith(expect.any(Object));
460
- expect(mockAuthClient.removePolicy).toHaveBeenCalledWith(expect.any(Object));
461
- }));
462
- });
463
- });
@@ -1,39 +0,0 @@
1
- import { Code, ConnectError } from '@connectrpc/connect';
2
- import type { CreateCollectionRequest } from '../gen/src/proto/products/v1/entities/collection_pb';
3
- export interface GetCollectionByIDProps {
4
- body: {
5
- collectionId: string;
6
- };
7
- headers: Record<string, string | null>;
8
- }
9
- export interface CreateCollectionProps {
10
- body: Omit<CreateCollectionRequest, '$typeName'>;
11
- headers: Record<string, string | null>;
12
- }
13
- export declare function getCollectionByID({ body: { collectionId }, headers, }: GetCollectionByIDProps): Promise<ConnectError | {
14
- value: import("../gen/src/proto/products/v1/entities/collection_pb").GetCollectionByIDResponse;
15
- status: string;
16
- code?: undefined;
17
- rawMessage?: undefined;
18
- message?: undefined;
19
- } | {
20
- code: Code;
21
- rawMessage: string;
22
- message: string;
23
- status: string;
24
- value?: undefined;
25
- }>;
26
- export declare function createCollection({ body, headers, }: CreateCollectionProps): Promise<ConnectError | {
27
- value: import("../gen/src/proto/products/v1/entities/collection_pb").CreateCollectionResponse;
28
- status: string;
29
- code?: undefined;
30
- rawMessage?: undefined;
31
- message?: undefined;
32
- } | {
33
- code: Code;
34
- rawMessage: string;
35
- message: string;
36
- status: string;
37
- value?: undefined;
38
- }>;
39
- //# sourceMappingURL=products.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"products.d.ts","sourceRoot":"","sources":["../../src/products.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAA;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qDAAqD,CAAA;AAOlG,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAA;IAChD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,wBAAsB,iBAAiB,CAAC,EACtC,IAAI,EAAE,EAAE,YAAY,EAAE,EACtB,OAAO,GACR,EAAE,sBAAsB;;;;;;;;;;;;GAyCxB;AAED,wBAAsB,gBAAgB,CAAC,EACrC,IAAI,EACJ,OAAO,GACR,EAAE,qBAAqB;;;;;;;;;;;;GAuCvB"}
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getCollectionByID = getCollectionByID;
13
- exports.createCollection = createCollection;
14
- const connect_1 = require("@connectrpc/connect");
15
- const connect_node_1 = require("@connectrpc/connect-node");
16
- const config_1 = require("@paakd/config");
17
- const service_pb_1 = require("../gen/src/proto/products/v1/service_pb");
18
- const brotli_1 = require("./compressor/brotli");
19
- const interceptors_1 = require("./interceptors");
20
- function getCollectionByID(_a) {
21
- return __awaiter(this, arguments, void 0, function* ({ body: { collectionId }, headers, }) {
22
- try {
23
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
24
- const productClient = (0, connect_1.createClient)(service_pb_1.ProductsService, (0, connect_node_1.createGrpcTransport)({
25
- baseUrl: checkoutConfig.enterpriseURL,
26
- interceptors: [
27
- (0, interceptors_1.createHeadersInterceptor)(headers),
28
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
29
- ],
30
- acceptCompression: [brotli_1.brotliCompression],
31
- sendCompression: brotli_1.brotliCompression,
32
- }));
33
- const value = yield productClient.getCollectionByID({
34
- id: collectionId,
35
- });
36
- return {
37
- value,
38
- status: 'success',
39
- };
40
- }
41
- catch (err) {
42
- if (err instanceof connect_1.ConnectError) {
43
- return {
44
- code: err.code,
45
- rawMessage: err.rawMessage,
46
- message: err.rawMessage,
47
- status: 'failed',
48
- };
49
- }
50
- return {
51
- code: connect_1.Code.Internal,
52
- rawMessage: 'An unexpected error occurred while fetching the collection.',
53
- message: 'An unexpected error occurred while fetching the collection.',
54
- status: 'failed',
55
- };
56
- }
57
- });
58
- }
59
- function createCollection(_a) {
60
- return __awaiter(this, arguments, void 0, function* ({ body, headers, }) {
61
- try {
62
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
63
- const productClient = (0, connect_1.createClient)(service_pb_1.ProductsService, (0, connect_node_1.createGrpcTransport)({
64
- baseUrl: checkoutConfig.enterpriseURL,
65
- interceptors: [
66
- (0, interceptors_1.createHeadersInterceptor)(headers),
67
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
68
- ],
69
- acceptCompression: [brotli_1.brotliCompression],
70
- sendCompression: brotli_1.brotliCompression,
71
- }));
72
- const value = yield productClient.createCollection(body);
73
- return {
74
- value,
75
- status: 'success',
76
- };
77
- }
78
- catch (err) {
79
- if (err instanceof connect_1.ConnectError) {
80
- return {
81
- code: err.code,
82
- rawMessage: err.rawMessage,
83
- message: err.rawMessage,
84
- status: 'failed',
85
- };
86
- }
87
- return {
88
- code: connect_1.Code.Internal,
89
- rawMessage: 'An unexpected error occurred while creating the collection.',
90
- message: 'An unexpected error occurred while creating the collection.',
91
- status: 'failed',
92
- };
93
- }
94
- });
95
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=products.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"products.spec.d.ts","sourceRoot":"","sources":["../../src/products.spec.ts"],"names":[],"mappings":""}