@paakd/api 0.0.3 → 0.0.5

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 (124) 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 +2 -2
  25. package/package.json +8 -10
  26. package/buf/validate/validate_pb.ts +0 -5001
  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
  66. package/gen/buf/validate/validate_pb.ts +0 -4799
  67. package/gen/src/proto/auth/v1/authv1connect/service.connect.go +0 -454
  68. package/gen/src/proto/auth/v1/entities/auth.pb.go +0 -818
  69. package/gen/src/proto/auth/v1/entities/auth_pb.ts +0 -348
  70. package/gen/src/proto/auth/v1/entities/policy.pb.go +0 -727
  71. package/gen/src/proto/auth/v1/entities/policy_pb.ts +0 -306
  72. package/gen/src/proto/auth/v1/service-AuthService_connectquery.ts +0 -70
  73. package/gen/src/proto/auth/v1/service.pb.go +0 -119
  74. package/gen/src/proto/auth/v1/service_pb.ts +0 -152
  75. package/gen/src/proto/customers/v1/customersv1connect/service.connect.go +0 -358
  76. package/gen/src/proto/customers/v1/entities/address.pb.go +0 -1073
  77. package/gen/src/proto/customers/v1/entities/address_pb.ts +0 -478
  78. package/gen/src/proto/customers/v1/entities/profile.pb.go +0 -633
  79. package/gen/src/proto/customers/v1/entities/profile_pb.ts +0 -252
  80. package/gen/src/proto/customers/v1/service-CustomerService_connectquery.ts +0 -50
  81. package/gen/src/proto/customers/v1/service.pb.go +0 -110
  82. package/gen/src/proto/customers/v1/service_pb.ts +0 -121
  83. package/gen/src/proto/files/v1/entities/file.pb.go +0 -669
  84. package/gen/src/proto/files/v1/entities/file_pb.ts +0 -265
  85. package/gen/src/proto/files/v1/filesv1connect/service.connect.go +0 -200
  86. package/gen/src/proto/files/v1/service-FileService_connectquery.ts +0 -25
  87. package/gen/src/proto/files/v1/service.pb.go +0 -85
  88. package/gen/src/proto/files/v1/service_pb.ts +0 -65
  89. package/gen/src/proto/products/v1/entities/category.pb.go +0 -744
  90. package/gen/src/proto/products/v1/entities/category_pb.ts +0 -318
  91. package/gen/src/proto/products/v1/entities/collection.pb.go +0 -528
  92. package/gen/src/proto/products/v1/entities/collection_pb.ts +0 -214
  93. package/gen/src/proto/products/v1/entities/product/create.pb.go +0 -453
  94. package/gen/src/proto/products/v1/entities/product/create_pb.ts +0 -199
  95. package/gen/src/proto/products/v1/entities/product/option.pb.go +0 -206
  96. package/gen/src/proto/products/v1/entities/product/option_pb.ts +0 -74
  97. package/gen/src/proto/products/v1/entities/product/shared.pb.go +0 -2890
  98. package/gen/src/proto/products/v1/entities/product/shared_pb.ts +0 -1317
  99. package/gen/src/proto/products/v1/entities/product/update.pb.go +0 -794
  100. package/gen/src/proto/products/v1/entities/product/update_pb.ts +0 -325
  101. package/gen/src/proto/products/v1/entities/tag.pb.go +0 -610
  102. package/gen/src/proto/products/v1/entities/tag_pb.ts +0 -233
  103. package/gen/src/proto/products/v1/entities/taxonomy.pb.go +0 -1352
  104. package/gen/src/proto/products/v1/entities/taxonomy_pb.ts +0 -606
  105. package/gen/src/proto/products/v1/entities/type.pb.go +0 -553
  106. package/gen/src/proto/products/v1/entities/type_pb.ts +0 -215
  107. package/gen/src/proto/products/v1/entities/variant.pb.go +0 -1474
  108. package/gen/src/proto/products/v1/entities/variant_pb.ts +0 -629
  109. package/gen/src/proto/products/v1/productsv1connect/service.connect.go +0 -1195
  110. package/gen/src/proto/products/v1/service-ProductsService_connectquery.ts +0 -199
  111. package/gen/src/proto/products/v1/service.pb.go +0 -250
  112. package/gen/src/proto/products/v1/service_pb.ts +0 -429
  113. package/gen/src/proto/promotions/v1/entities/campaign.pb.go +0 -1229
  114. package/gen/src/proto/promotions/v1/entities/campaign_pb.ts +0 -511
  115. package/gen/src/proto/promotions/v1/promotionsv1connect/service.connect.go +0 -289
  116. package/gen/src/proto/promotions/v1/service-CampaignService_connectquery.ts +0 -42
  117. package/gen/src/proto/promotions/v1/service.pb.go +0 -98
  118. package/gen/src/proto/promotions/v1/service_pb.ts +0 -95
  119. package/gen/src/proto/stocknodes/v1/entities/stocknode.pb.go +0 -1499
  120. package/gen/src/proto/stocknodes/v1/entities/stocknode_pb.ts +0 -655
  121. package/gen/src/proto/stocknodes/v1/service-StockNodesService_connectquery.ts +0 -41
  122. package/gen/src/proto/stocknodes/v1/service.pb.go +0 -98
  123. package/gen/src/proto/stocknodes/v1/service_pb.ts +0 -95
  124. package/gen/src/proto/stocknodes/v1/stocknodesv1connect/service.connect.go +0 -297
@@ -1,519 +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 products_1 = require("./products");
16
- const interceptors_1 = require("./interceptors");
17
- const test_utils_1 = require("./test-utils");
18
- // Mock dependencies
19
- vi.mock('@connectrpc/connect', () => __awaiter(void 0, void 0, void 0, function* () {
20
- const actual = yield vi.importActual('@connectrpc/connect');
21
- return Object.assign(Object.assign({}, actual), { createClient: vi.fn() });
22
- }));
23
- vi.mock('@connectrpc/connect-node', () => ({
24
- createGrpcTransport: vi.fn(),
25
- }));
26
- vi.mock('@paakd/config', () => ({
27
- getCheckoutConfig: vi.fn(),
28
- }));
29
- vi.mock('./interceptors', () => ({
30
- createAuthenticationInterceptor: vi.fn(),
31
- createHeadersInterceptor: vi.fn(),
32
- }));
33
- vi.mock('./compressor/brotli', () => ({
34
- brotliCompression: {
35
- name: 'brotli',
36
- compress: vi.fn(),
37
- decompress: vi.fn(),
38
- },
39
- }));
40
- vi.mock('../gen/src/proto/products/v1/service_pb', () => ({
41
- ProductsService: {},
42
- }));
43
- const mockGetCheckoutConfig = vi.mocked(config_1.getCheckoutConfig);
44
- const mockCreateGrpcTransport = vi.mocked(connect_node_1.createGrpcTransport);
45
- const mockCreateClient = vi.mocked(connect_1.createClient);
46
- const mockCreateAuthenticationInterceptor = vi.mocked(interceptors_1.createAuthenticationInterceptor);
47
- const mockCreateHeadersInterceptor = vi.mocked(interceptors_1.createHeadersInterceptor);
48
- /**
49
- * Setup function following @testing-library's render pattern
50
- */
51
- function setupProductsService() {
52
- (0, test_utils_1.clearAllMocks)();
53
- const { config, interceptors, transport } = (0, test_utils_1.setupCommonMocks)();
54
- const client = {
55
- getCollectionByID: vi.fn(),
56
- createCollection: vi.fn(),
57
- };
58
- mockGetCheckoutConfig.mockResolvedValue(config);
59
- mockCreateGrpcTransport.mockReturnValue(transport);
60
- mockCreateHeadersInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
61
- return yield next(req);
62
- }));
63
- mockCreateAuthenticationInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
64
- return yield next(req);
65
- }));
66
- mockCreateClient.mockReturnValue(client);
67
- return { client, config, interceptors, transport };
68
- }
69
- describe('Products Service', () => {
70
- let consoleSpy;
71
- beforeEach(() => {
72
- consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
73
- });
74
- afterEach(() => {
75
- consoleSpy.mockRestore();
76
- });
77
- describe('getCollectionByID', () => {
78
- it('should successfully retrieve a collection by ID', () => __awaiter(void 0, void 0, void 0, function* () {
79
- const { client } = setupProductsService();
80
- const mockCollection = {
81
- id: 'collection-1',
82
- name: 'Summer Collection',
83
- description: 'Summer 2024 collection',
84
- productCount: 25,
85
- };
86
- client.getCollectionByID.mockResolvedValue(mockCollection);
87
- const result = yield (0, products_1.getCollectionByID)({
88
- body: {
89
- collectionId: 'collection-1',
90
- },
91
- headers: {},
92
- });
93
- expect(result.status).toBe('success');
94
- expect(result.value).toEqual(mockCollection);
95
- expect(client.getCollectionByID).toHaveBeenCalledWith({
96
- id: 'collection-1',
97
- });
98
- }));
99
- it('should return not found when collection does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
100
- const { client } = setupProductsService();
101
- const error = (0, test_utils_1.createMockConnectError)(5, 'NOT_FOUND', 'Collection not found');
102
- client.getCollectionByID.mockRejectedValue(error);
103
- const result = yield (0, products_1.getCollectionByID)({
104
- body: {
105
- collectionId: 'invalid-collection',
106
- },
107
- headers: {},
108
- });
109
- expect(result.status).toBe('failed');
110
- expect(result.code).toBe(5);
111
- }));
112
- it('should handle service unavailability', () => __awaiter(void 0, void 0, void 0, function* () {
113
- const { client } = setupProductsService();
114
- const error = (0, test_utils_1.createMockConnectError)(14, 'UNAVAILABLE', 'Service temporarily unavailable');
115
- client.getCollectionByID.mockRejectedValue(error);
116
- const result = yield (0, products_1.getCollectionByID)({
117
- body: {
118
- collectionId: 'collection-1',
119
- },
120
- headers: {},
121
- });
122
- expect(result.status).toBe('failed');
123
- }));
124
- it('should include custom headers in request context', () => __awaiter(void 0, void 0, void 0, function* () {
125
- const { client } = setupProductsService();
126
- client.getCollectionByID.mockResolvedValue({
127
- id: 'collection-1',
128
- name: 'Summer Collection',
129
- });
130
- const customHeaders = {
131
- 'x-shop-id': '123',
132
- 'x-locale': 'en-US',
133
- };
134
- yield (0, products_1.getCollectionByID)({
135
- body: {
136
- collectionId: 'collection-1',
137
- },
138
- headers: customHeaders,
139
- });
140
- expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(customHeaders);
141
- }));
142
- it('should use checkout configuration for enterprise URL', () => __awaiter(void 0, void 0, void 0, function* () {
143
- const { client, config } = setupProductsService();
144
- client.getCollectionByID.mockResolvedValue({
145
- id: 'collection-1',
146
- name: 'Summer Collection',
147
- });
148
- yield (0, products_1.getCollectionByID)({
149
- body: {
150
- collectionId: 'collection-1',
151
- },
152
- headers: {},
153
- });
154
- expect(mockCreateGrpcTransport).toHaveBeenCalledWith(expect.objectContaining({
155
- baseUrl: config.enterpriseURL,
156
- }));
157
- }));
158
- it('should enable compression for data transfer', () => __awaiter(void 0, void 0, void 0, function* () {
159
- const { client } = setupProductsService();
160
- client.getCollectionByID.mockResolvedValue({
161
- id: 'collection-1',
162
- name: 'Summer Collection',
163
- });
164
- yield (0, products_1.getCollectionByID)({
165
- body: {
166
- collectionId: 'collection-1',
167
- },
168
- headers: {},
169
- });
170
- const transportConfig = mockCreateGrpcTransport.mock.calls[0][0];
171
- expect(transportConfig).toHaveProperty('acceptCompression');
172
- expect(transportConfig).toHaveProperty('sendCompression');
173
- }));
174
- it('should handle invalid collection ID format', () => __awaiter(void 0, void 0, void 0, function* () {
175
- const { client } = setupProductsService();
176
- const error = (0, test_utils_1.createMockConnectError)(3, 'INVALID_ARGUMENT', 'Invalid collection ID format');
177
- client.getCollectionByID.mockRejectedValue(error);
178
- const result = yield (0, products_1.getCollectionByID)({
179
- body: {
180
- collectionId: '',
181
- },
182
- headers: {},
183
- });
184
- expect(result.status).toBe('failed');
185
- }));
186
- it('should handle internal server errors gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
187
- const { client } = setupProductsService();
188
- const error = (0, test_utils_1.createMockConnectError)(13, 'INTERNAL', 'Internal server error');
189
- client.getCollectionByID.mockRejectedValue(error);
190
- const result = yield (0, products_1.getCollectionByID)({
191
- body: {
192
- collectionId: 'collection-1',
193
- },
194
- headers: {},
195
- });
196
- expect(result.status).toBe('failed');
197
- expect(result.code).toBe(connect_1.Code.Internal);
198
- }));
199
- it('should support concurrent collection retrievals', () => __awaiter(void 0, void 0, void 0, function* () {
200
- const { client } = setupProductsService();
201
- client.getCollectionByID.mockResolvedValue({
202
- id: 'collection-1',
203
- name: 'Collection',
204
- });
205
- const results = yield Promise.all([
206
- (0, products_1.getCollectionByID)({
207
- body: { collectionId: 'collection-1' },
208
- headers: {},
209
- }),
210
- (0, products_1.getCollectionByID)({
211
- body: { collectionId: 'collection-2' },
212
- headers: {},
213
- }),
214
- (0, products_1.getCollectionByID)({
215
- body: { collectionId: 'collection-3' },
216
- headers: {},
217
- }),
218
- ]);
219
- expect(results).toHaveLength(3);
220
- expect(results.every(r => r.status === 'success')).toBe(true);
221
- }));
222
- });
223
- describe('createCollection', () => {
224
- it('should successfully create a new collection', () => __awaiter(void 0, void 0, void 0, function* () {
225
- const { client } = setupProductsService();
226
- const newCollection = {
227
- name: 'Winter Collection',
228
- description: 'Winter 2024 collection',
229
- };
230
- const mockCollection = Object.assign({ id: 'new-collection-1' }, newCollection);
231
- const mockResponse = {
232
- collection: mockCollection,
233
- };
234
- client.createCollection.mockResolvedValue(mockResponse);
235
- const result = yield (0, products_1.createCollection)({
236
- body: newCollection,
237
- headers: {},
238
- });
239
- expect(result.status).toBe('success');
240
- expect(result.value).toEqual(mockResponse);
241
- expect(client.createCollection).toHaveBeenCalledWith(expect.objectContaining(newCollection));
242
- }));
243
- it('should reject collection creation with invalid data', () => __awaiter(void 0, void 0, void 0, function* () {
244
- const { client } = setupProductsService();
245
- const error = (0, test_utils_1.createMockConnectError)(3, 'INVALID_ARGUMENT', 'Invalid collection data');
246
- client.createCollection.mockRejectedValue(error);
247
- const result = yield (0, products_1.createCollection)({
248
- body: {
249
- name: '',
250
- },
251
- headers: {},
252
- });
253
- expect(result.status).toBe('failed');
254
- }));
255
- it('should handle duplicate collection names', () => __awaiter(void 0, void 0, void 0, function* () {
256
- const { client } = setupProductsService();
257
- const error = (0, test_utils_1.createMockConnectError)(6, 'ALREADY_EXISTS', 'Collection with this name already exists');
258
- client.createCollection.mockRejectedValue(error);
259
- const result = yield (0, products_1.createCollection)({
260
- body: {
261
- name: 'Existing Collection',
262
- description: 'New description',
263
- },
264
- headers: {},
265
- });
266
- expect(result.status).toBe('failed');
267
- }));
268
- it('should reject creation without authentication', () => __awaiter(void 0, void 0, void 0, function* () {
269
- const { client } = setupProductsService();
270
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Authentication required');
271
- client.createCollection.mockRejectedValue(error);
272
- const result = yield (0, products_1.createCollection)({
273
- body: {
274
- name: 'New Collection',
275
- description: 'Description',
276
- },
277
- headers: {},
278
- });
279
- expect(result.status).toBe('failed');
280
- }));
281
- it('should handle permission denied errors', () => __awaiter(void 0, void 0, void 0, function* () {
282
- const { client } = setupProductsService();
283
- const error = (0, test_utils_1.createMockConnectError)(7, 'PERMISSION_DENIED', 'User does not have permission to create collections');
284
- client.createCollection.mockRejectedValue(error);
285
- const result = yield (0, products_1.createCollection)({
286
- body: {
287
- name: 'New Collection',
288
- description: 'Description',
289
- },
290
- headers: {},
291
- });
292
- expect(result.status).toBe('failed');
293
- }));
294
- it('should include authentication interceptor', () => __awaiter(void 0, void 0, void 0, function* () {
295
- const { client } = setupProductsService();
296
- client.createCollection.mockResolvedValue({
297
- id: 'new-collection-1',
298
- name: 'New Collection',
299
- });
300
- yield (0, products_1.createCollection)({
301
- body: {
302
- name: 'New Collection',
303
- description: 'Description',
304
- },
305
- headers: {},
306
- });
307
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled();
308
- }));
309
- it('should handle service errors during creation', () => __awaiter(void 0, void 0, void 0, function* () {
310
- const { client } = setupProductsService();
311
- const error = (0, test_utils_1.createMockConnectError)(13, 'INTERNAL', 'Database error occurred');
312
- client.createCollection.mockRejectedValue(error);
313
- const result = yield (0, products_1.createCollection)({
314
- body: {
315
- name: 'New Collection',
316
- description: 'Description',
317
- },
318
- headers: {},
319
- });
320
- expect(result.status).toBe('failed');
321
- expect(result.code).toBe(connect_1.Code.Internal);
322
- }));
323
- it('should handle collection limit exceeded', () => __awaiter(void 0, void 0, void 0, function* () {
324
- const { client } = setupProductsService();
325
- const error = (0, test_utils_1.createMockConnectError)(8, 'RESOURCE_EXHAUSTED', 'Collection limit exceeded');
326
- client.createCollection.mockRejectedValue(error);
327
- const result = yield (0, products_1.createCollection)({
328
- body: {
329
- name: 'New Collection',
330
- description: 'Description',
331
- },
332
- headers: {},
333
- });
334
- expect(result.status).toBe('failed');
335
- }));
336
- it('should support multiple concurrent collection creations', () => __awaiter(void 0, void 0, void 0, function* () {
337
- const { client } = setupProductsService();
338
- client.createCollection.mockResolvedValue({
339
- id: 'collection-id',
340
- name: 'Collection',
341
- });
342
- const results = yield Promise.all([
343
- (0, products_1.createCollection)({
344
- body: {
345
- name: 'Collection 1',
346
- description: 'Desc 1',
347
- },
348
- headers: {},
349
- }),
350
- (0, products_1.createCollection)({
351
- body: {
352
- name: 'Collection 2',
353
- description: 'Desc 2',
354
- },
355
- headers: {},
356
- }),
357
- (0, products_1.createCollection)({
358
- body: {
359
- name: 'Collection 3',
360
- description: 'Desc 3',
361
- },
362
- headers: {},
363
- }),
364
- ]);
365
- expect(results).toHaveLength(3);
366
- expect(results.every(r => r.status === 'success')).toBe(true);
367
- }));
368
- });
369
- describe('Products Service - Common Behavior', () => {
370
- it('should apply authentication interceptor for all operations', () => __awaiter(void 0, void 0, void 0, function* () {
371
- const { client } = setupProductsService();
372
- client.getCollectionByID.mockResolvedValue({
373
- id: 'collection-1',
374
- name: 'Collection',
375
- });
376
- yield (0, products_1.getCollectionByID)({
377
- body: {
378
- collectionId: 'collection-1',
379
- },
380
- headers: {},
381
- });
382
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled();
383
- }));
384
- it('should load configuration for each request', () => __awaiter(void 0, void 0, void 0, function* () {
385
- const { client } = setupProductsService();
386
- client.getCollectionByID.mockResolvedValue({
387
- id: 'collection-1',
388
- name: 'Collection',
389
- });
390
- yield (0, products_1.getCollectionByID)({
391
- body: {
392
- collectionId: 'collection-1',
393
- },
394
- headers: {},
395
- });
396
- expect(mockGetCheckoutConfig).toHaveBeenCalled();
397
- }));
398
- it('should create transport with compression enabled', () => __awaiter(void 0, void 0, void 0, function* () {
399
- const { client } = setupProductsService();
400
- client.getCollectionByID.mockResolvedValue({
401
- id: 'collection-1',
402
- name: 'Collection',
403
- });
404
- yield (0, products_1.getCollectionByID)({
405
- body: {
406
- collectionId: 'collection-1',
407
- },
408
- headers: {},
409
- });
410
- expect(mockCreateGrpcTransport).toHaveBeenCalledWith(expect.objectContaining({
411
- acceptCompression: expect.any(Array),
412
- sendCompression: expect.any(Object),
413
- }));
414
- }));
415
- it('should handle concurrent mixed operations', () => __awaiter(void 0, void 0, void 0, function* () {
416
- const { client } = setupProductsService();
417
- client.getCollectionByID.mockResolvedValue({
418
- id: 'collection-1',
419
- name: 'Collection',
420
- });
421
- client.createCollection.mockResolvedValue({
422
- id: 'new-collection',
423
- name: 'New Collection',
424
- });
425
- const results = yield Promise.all([
426
- (0, products_1.getCollectionByID)({
427
- body: { collectionId: 'collection-1' },
428
- headers: {},
429
- }),
430
- (0, products_1.createCollection)({
431
- body: {
432
- name: 'New Collection',
433
- description: 'Desc',
434
- },
435
- headers: {},
436
- }),
437
- (0, products_1.getCollectionByID)({
438
- body: { collectionId: 'collection-2' },
439
- headers: {},
440
- }),
441
- ]);
442
- expect(results).toHaveLength(3);
443
- expect(results.every(r => r.status === 'success')).toBe(true);
444
- }));
445
- it('should handle edge cases with special characters in collection names', () => __awaiter(void 0, void 0, void 0, function* () {
446
- const { client } = setupProductsService();
447
- const mockCollection = {
448
- id: 'collection-special',
449
- name: "Summer's Special Collection 2024!",
450
- description: 'Special offer: 50% off - São Paulo exclusive',
451
- };
452
- client.createCollection.mockResolvedValue(mockCollection);
453
- const result = yield (0, products_1.createCollection)({
454
- body: {
455
- name: "Summer's Special Collection 2024!",
456
- description: 'Special offer: 50% off - São Paulo exclusive',
457
- },
458
- headers: {},
459
- });
460
- expect(result.status).toBe('success');
461
- expect(result.value).toEqual(mockCollection);
462
- }));
463
- it('should handle very long collection descriptions', () => __awaiter(void 0, void 0, void 0, function* () {
464
- const { client } = setupProductsService();
465
- const longDescription = 'A'.repeat(500);
466
- const mockCollection = {
467
- id: 'collection-long',
468
- name: 'Collection',
469
- description: longDescription,
470
- };
471
- client.createCollection.mockResolvedValue(mockCollection);
472
- const result = yield (0, products_1.createCollection)({
473
- body: {
474
- name: 'Collection',
475
- description: longDescription,
476
- },
477
- headers: {},
478
- });
479
- expect(result.status).toBe('success');
480
- }));
481
- it('should handle null or undefined headers gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
482
- const { client } = setupProductsService();
483
- client.getCollectionByID.mockResolvedValue({
484
- id: 'collection-1',
485
- name: 'Collection',
486
- });
487
- const result = yield (0, products_1.getCollectionByID)({
488
- body: {
489
- collectionId: 'collection-1',
490
- },
491
- headers: {
492
- 'x-header': null,
493
- },
494
- });
495
- expect(result.status).toBe('success');
496
- }));
497
- it('should consistent error handling across operations', () => __awaiter(void 0, void 0, void 0, function* () {
498
- const { client } = setupProductsService();
499
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Invalid authentication');
500
- client.getCollectionByID.mockRejectedValueOnce(error);
501
- client.createCollection.mockRejectedValueOnce(error);
502
- const results = yield Promise.all([
503
- (0, products_1.getCollectionByID)({
504
- body: { collectionId: 'collection-1' },
505
- headers: {},
506
- }),
507
- (0, products_1.createCollection)({
508
- body: {
509
- name: 'Collection',
510
- description: 'Desc',
511
- },
512
- headers: {},
513
- }),
514
- ]);
515
- expect(results.every(r => r.status === 'failed')).toBe(true);
516
- expect(results.every(r => r.code === 16)).toBe(true);
517
- }));
518
- });
519
- });
@@ -1,62 +0,0 @@
1
- import { Code, ConnectError } from '@connectrpc/connect';
2
- import type { UpdateProfileRequest } from '../gen/src/proto/customers/v1/entities/profile_pb';
3
- export interface GetBasicProfileProps {
4
- body: {
5
- customerId: string;
6
- jwt: string;
7
- };
8
- headers: Record<string, string | null>;
9
- }
10
- export interface GetProfileProps {
11
- body: {
12
- customerId: string;
13
- jwt: string;
14
- };
15
- headers: Record<string, string | null>;
16
- }
17
- export interface UpdateProfileProps {
18
- body: Omit<UpdateProfileRequest, '$typeName'> & {
19
- jwt: string;
20
- };
21
- headers: Record<string, string | null>;
22
- }
23
- export declare function getBasicProfile({ body: { customerId, jwt }, headers, }: GetBasicProfileProps): Promise<ConnectError | {
24
- value: import("../gen/src/proto/customers/v1/entities/profile_pb").BasicProfileResponse;
25
- status: string;
26
- code?: undefined;
27
- rawMessage?: undefined;
28
- message?: undefined;
29
- } | {
30
- code: Code;
31
- rawMessage: string;
32
- message: string;
33
- status: string;
34
- value?: undefined;
35
- }>;
36
- export declare function getProfile({ body: { customerId, jwt }, headers, }: GetProfileProps): Promise<ConnectError | {
37
- value: import("../gen/src/proto/customers/v1/entities/profile_pb").ProfileResponse;
38
- status: string;
39
- code?: undefined;
40
- rawMessage?: undefined;
41
- message?: undefined;
42
- } | {
43
- code: Code;
44
- rawMessage: string;
45
- message: string;
46
- status: string;
47
- value?: undefined;
48
- }>;
49
- export declare function updateProfile({ body: { jwt, ...prop }, headers, }: UpdateProfileProps): Promise<ConnectError | {
50
- value: import("@bufbuild/protobuf").Message<"UpdateProfileResponse">;
51
- status: string;
52
- code?: undefined;
53
- rawMessage?: undefined;
54
- message?: undefined;
55
- } | {
56
- code: Code;
57
- rawMessage: string;
58
- message: string;
59
- status: string;
60
- value?: undefined;
61
- }>;
62
- //# sourceMappingURL=profile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAA;AAItE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAA;AAQ7F,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,wBAAsB,eAAe,CAAC,EACpC,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EACzB,OAAO,GACR,EAAE,oBAAoB;;;;;;;;;;;;GA0CtB;AAED,wBAAsB,UAAU,CAAC,EAC/B,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EACzB,OAAO,GACR,EAAE,eAAe;;;;;;;;;;;;GA0CjB;AAED,wBAAsB,aAAa,CAAC,EAClC,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,EACtB,OAAO,GACR,EAAE,kBAAkB;;;;;;;;;;;;GAsCpB"}