@paakd/api 0.0.4 → 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 (64) 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 +6 -6
  26. package/dist/src/address.d.ts +0 -53
  27. package/dist/src/address.d.ts.map +0 -1
  28. package/dist/src/address.js +0 -233
  29. package/dist/src/address.spec.d.ts +0 -2
  30. package/dist/src/address.spec.d.ts.map +0 -1
  31. package/dist/src/address.spec.js +0 -488
  32. package/dist/src/auth.d.ts +0 -27
  33. package/dist/src/auth.d.ts.map +0 -1
  34. package/dist/src/auth.js +0 -155
  35. package/dist/src/auth.spec.d.ts +0 -2
  36. package/dist/src/auth.spec.d.ts.map +0 -1
  37. package/dist/src/auth.spec.js +0 -582
  38. package/dist/src/compressor/brotli.d.ts +0 -3
  39. package/dist/src/compressor/brotli.d.ts.map +0 -1
  40. package/dist/src/compressor/brotli.js +0 -30
  41. package/dist/src/policies.d.ts +0 -217
  42. package/dist/src/policies.d.ts.map +0 -1
  43. package/dist/src/policies.js +0 -322
  44. package/dist/src/policies.spec.d.ts +0 -2
  45. package/dist/src/policies.spec.d.ts.map +0 -1
  46. package/dist/src/policies.spec.js +0 -463
  47. package/dist/src/products.d.ts +0 -39
  48. package/dist/src/products.d.ts.map +0 -1
  49. package/dist/src/products.js +0 -95
  50. package/dist/src/products.spec.d.ts +0 -2
  51. package/dist/src/products.spec.d.ts.map +0 -1
  52. package/dist/src/products.spec.js +0 -519
  53. package/dist/src/profile.d.ts +0 -62
  54. package/dist/src/profile.d.ts.map +0 -1
  55. package/dist/src/profile.js +0 -151
  56. package/dist/src/profile.spec.d.ts +0 -2
  57. package/dist/src/profile.spec.d.ts.map +0 -1
  58. package/dist/src/profile.spec.js +0 -475
  59. package/dist/src/registration.d.ts +0 -60
  60. package/dist/src/registration.d.ts.map +0 -1
  61. package/dist/src/registration.js +0 -147
  62. package/dist/src/test-utils.d.ts +0 -87
  63. package/dist/src/test-utils.d.ts.map +0 -1
  64. package/dist/src/test-utils.js +0 -132
@@ -1,582 +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 auth_1 = require("./auth");
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('./compressor/brotli', () => ({
24
- brotliCompression: {
25
- name: 'brotli',
26
- compress: vi.fn(),
27
- decompress: vi.fn(),
28
- },
29
- }));
30
- vi.mock('@connectrpc/connect-node', () => ({
31
- createGrpcTransport: vi.fn(),
32
- }));
33
- vi.mock('@paakd/config', () => ({
34
- getCheckoutConfig: vi.fn(),
35
- }));
36
- vi.mock('./interceptors', () => ({
37
- createAuthenticationInterceptor: vi.fn(),
38
- createCustomerAuthenticationInterceptor: vi.fn(),
39
- createHeadersInterceptor: vi.fn(),
40
- }));
41
- vi.mock('../gen/src/proto/auth/v1/service_pb', () => ({
42
- AuthService: {},
43
- }));
44
- vi.mock('../gen/src/proto/customers/v1/service_pb', () => ({
45
- CustomerService: {},
46
- }));
47
- const mockGetCheckoutConfig = vi.mocked(config_1.getCheckoutConfig);
48
- const mockCreateGrpcTransport = vi.mocked(connect_node_1.createGrpcTransport);
49
- const mockCreateClient = vi.mocked(connect_1.createClient);
50
- const mockCreateAuthenticationInterceptor = vi.mocked(interceptors_1.createAuthenticationInterceptor);
51
- const mockCreateCustomerAuthenticationInterceptor = vi.mocked(interceptors_1.createCustomerAuthenticationInterceptor);
52
- const mockCreateHeadersInterceptor = vi.mocked(interceptors_1.createHeadersInterceptor);
53
- /**
54
- * Setup function similar to testing-library's render.
55
- * Initializes the testing environment with proper mocks
56
- */
57
- function setupAuthService() {
58
- (0, test_utils_1.clearAllMocks)();
59
- const { config, interceptors, transport } = (0, test_utils_1.setupCommonMocks)();
60
- const clients = {
61
- auth: {
62
- login: vi.fn(),
63
- refreshToken: vi.fn(),
64
- },
65
- customer: {
66
- changePassword: vi.fn(),
67
- },
68
- };
69
- // Setup mock implementations
70
- mockGetCheckoutConfig.mockResolvedValue(config);
71
- mockCreateGrpcTransport.mockReturnValue(transport);
72
- mockCreateHeadersInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
73
- return yield next(req);
74
- }));
75
- mockCreateAuthenticationInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
76
- return yield next(req);
77
- }));
78
- mockCreateCustomerAuthenticationInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
79
- return yield next(req);
80
- }));
81
- // mockCreateClient should intelligently return the right client
82
- // The tests will set up their own expectations, but provide a smart default
83
- mockCreateClient.mockImplementation(() => {
84
- // Default to returning auth client, but tests can override as needed
85
- return clients.auth;
86
- });
87
- return {
88
- client: clients.auth,
89
- clients,
90
- config,
91
- interceptors,
92
- transport,
93
- };
94
- }
95
- describe('Authentication Service', () => {
96
- let consoleSpySpy;
97
- beforeEach(() => {
98
- consoleSpySpy = vi.spyOn(console, 'log').mockImplementation(() => { });
99
- });
100
- afterEach(() => {
101
- consoleSpySpy.mockRestore();
102
- });
103
- describe('login', () => {
104
- it('should successfully authenticate user with valid credentials', () => __awaiter(void 0, void 0, void 0, function* () {
105
- const { clients } = setupAuthService();
106
- const credentials = {
107
- body: {
108
- email: 'user@example.com',
109
- password: 'password123',
110
- },
111
- headers: {
112
- 'x-shop-id': '123',
113
- },
114
- };
115
- const expectedResponse = {
116
- jwt: 'token123',
117
- refreshToken: 'refresh123',
118
- expiresIn: 3600,
119
- };
120
- clients.auth.login.mockResolvedValue(expectedResponse);
121
- const result = yield (0, auth_1.login)(credentials);
122
- expect(result.status).toBe('success');
123
- expect(result).toHaveProperty('value');
124
- expect(clients.auth.login).toHaveBeenCalledWith({
125
- email: credentials.body.email,
126
- password: credentials.body.password,
127
- });
128
- }));
129
- it('should reject user when credentials are invalid', () => __awaiter(void 0, void 0, void 0, function* () {
130
- const { clients } = setupAuthService();
131
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Invalid credentials');
132
- clients.auth.login.mockRejectedValue(error);
133
- const result = yield (0, auth_1.login)({
134
- body: {
135
- email: 'user@example.com',
136
- password: 'wrongpassword',
137
- },
138
- headers: {},
139
- });
140
- expect(result.status).toBe('failed');
141
- expect(result).toHaveProperty('code');
142
- }));
143
- it('should handle network failures gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
144
- const { clients } = setupAuthService();
145
- const networkError = (0, test_utils_1.createMockConnectError)(14, 'UNAVAILABLE', 'Service unavailable');
146
- clients.auth.login.mockRejectedValue(networkError);
147
- const result = yield (0, auth_1.login)({
148
- body: {
149
- email: 'user@example.com',
150
- password: 'password123',
151
- },
152
- headers: {},
153
- });
154
- expect(result.status).toBe('failed');
155
- }));
156
- it('should include custom headers in request context', () => __awaiter(void 0, void 0, void 0, function* () {
157
- const { clients } = setupAuthService();
158
- const customHeaders = {
159
- 'x-original-host': 'example.com',
160
- 'x-shop-id': '456',
161
- 'x-locale': 'en-US',
162
- };
163
- clients.auth.login.mockResolvedValue({
164
- jwt: 'new-token',
165
- refreshToken: 'refresh-token',
166
- });
167
- yield (0, auth_1.login)({
168
- body: {
169
- email: 'user@example.com',
170
- password: 'password123',
171
- },
172
- headers: customHeaders,
173
- });
174
- expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(customHeaders);
175
- }));
176
- it('should use checkout configuration for enterprise URL', () => __awaiter(void 0, void 0, void 0, function* () {
177
- const { clients, config } = setupAuthService();
178
- const jwt = 'token-xyz';
179
- clients.auth.login.mockResolvedValue({ jwt });
180
- yield (0, auth_1.login)({
181
- body: {
182
- email: 'user@example.com',
183
- password: 'password123',
184
- },
185
- headers: {},
186
- });
187
- expect(mockCreateGrpcTransport).toHaveBeenCalledWith(expect.objectContaining({
188
- baseUrl: config.enterpriseURL,
189
- }));
190
- }));
191
- it('should enable compression for optimized data transfer', () => __awaiter(void 0, void 0, void 0, function* () {
192
- const { clients } = setupAuthService();
193
- const jwt = 'token-for-compression-test';
194
- clients.auth.login.mockResolvedValue({ jwt });
195
- yield (0, auth_1.login)({
196
- body: {
197
- email: 'user@example.com',
198
- password: 'password123',
199
- },
200
- headers: {},
201
- });
202
- const transportConfig = mockCreateGrpcTransport.mock.calls[0][0];
203
- expect(transportConfig).toHaveProperty('acceptCompression');
204
- expect(transportConfig).toHaveProperty('sendCompression');
205
- }));
206
- it('should handle service unavailability', () => __awaiter(void 0, void 0, void 0, function* () {
207
- const { clients } = setupAuthService();
208
- const error = (0, test_utils_1.createMockConnectError)(14, 'UNAVAILABLE', 'Service temporarily unavailable');
209
- clients.auth.login.mockRejectedValue(error);
210
- const result = yield (0, auth_1.login)({
211
- body: {
212
- email: 'user@example.com',
213
- password: 'password123',
214
- },
215
- headers: {},
216
- });
217
- expect(result.status).toBe('failed');
218
- }));
219
- it('should support multiple concurrent login attempts', () => __awaiter(void 0, void 0, void 0, function* () {
220
- const { clients } = setupAuthService();
221
- const mockResponse = {
222
- jwt: 'concurrent-token',
223
- refreshToken: 'concurrent-refresh',
224
- };
225
- clients.auth.login.mockResolvedValue(mockResponse);
226
- const results = yield Promise.all([
227
- (0, auth_1.login)({
228
- body: {
229
- email: 'user1@example.com',
230
- password: 'password123',
231
- },
232
- headers: {},
233
- }),
234
- (0, auth_1.login)({
235
- body: {
236
- email: 'user2@example.com',
237
- password: 'password456',
238
- },
239
- headers: {},
240
- }),
241
- (0, auth_1.login)({
242
- body: {
243
- email: 'user3@example.com',
244
- password: 'password789',
245
- },
246
- headers: {},
247
- }),
248
- ]);
249
- expect(results).toHaveLength(3);
250
- expect(results.every(r => r.status === 'success')).toBe(true);
251
- }));
252
- });
253
- describe('refreshToken', () => {
254
- it('should refresh authentication token with valid refresh token', () => __awaiter(void 0, void 0, void 0, function* () {
255
- const { clients } = setupAuthService();
256
- const refreshTokenValue = 'refresh-token-123';
257
- const expectedResponse = {
258
- jwt: 'new-jwt-token',
259
- refreshToken: 'new-refresh-token',
260
- expiresIn: 3600,
261
- };
262
- clients.auth.refreshToken.mockResolvedValue(expectedResponse);
263
- const result = yield (0, auth_1.refreshToken)({
264
- body: {
265
- refreshToken: refreshTokenValue,
266
- },
267
- headers: {},
268
- });
269
- expect(result.status).toBe('success');
270
- expect(clients.auth.refreshToken).toHaveBeenCalledWith({
271
- refreshToken: refreshTokenValue,
272
- });
273
- }));
274
- it('should reject expired refresh tokens', () => __awaiter(void 0, void 0, void 0, function* () {
275
- const { clients } = setupAuthService();
276
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Refresh token expired');
277
- clients.auth.refreshToken.mockRejectedValue(error);
278
- const result = yield (0, auth_1.refreshToken)({
279
- body: {
280
- refreshToken: 'expired-refresh-token',
281
- },
282
- headers: {},
283
- });
284
- expect(result.status).toBe('failed');
285
- }));
286
- it('should handle missing or malformed refresh tokens', () => __awaiter(void 0, void 0, void 0, function* () {
287
- const { clients } = setupAuthService();
288
- const error = (0, test_utils_1.createMockConnectError)(3, 'INVALID_ARGUMENT', 'Invalid refresh token format');
289
- clients.auth.refreshToken.mockRejectedValue(error);
290
- const result = yield (0, auth_1.refreshToken)({
291
- body: {
292
- refreshToken: '',
293
- },
294
- headers: {},
295
- });
296
- expect(result.status).toBe('failed');
297
- }));
298
- it('should recover gracefully from service errors', () => __awaiter(void 0, void 0, void 0, function* () {
299
- const { clients } = setupAuthService();
300
- const serviceError = (0, test_utils_1.createMockConnectError)(13, 'INTERNAL', 'Internal server error');
301
- clients.auth.refreshToken.mockRejectedValue(serviceError);
302
- const result = yield (0, auth_1.refreshToken)({
303
- body: {
304
- refreshToken: 'valid-refresh-token',
305
- },
306
- headers: {},
307
- });
308
- expect(result.status).toBe('failed');
309
- }));
310
- it('should use authentication interceptor for token refresh', () => __awaiter(void 0, void 0, void 0, function* () {
311
- const { clients } = setupAuthService();
312
- const refreshTokenValue = 'refresh-token-abc';
313
- clients.auth.refreshToken.mockResolvedValue({
314
- jwt: 'new-jwt-token',
315
- refreshToken: 'new-refresh-token',
316
- });
317
- yield (0, auth_1.refreshToken)({
318
- body: {
319
- refreshToken: refreshTokenValue,
320
- },
321
- headers: {},
322
- });
323
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled();
324
- }));
325
- });
326
- describe('changePassword', () => {
327
- it('should successfully change user password with correct current password', () => __awaiter(void 0, void 0, void 0, function* () {
328
- const { clients } = setupAuthService();
329
- const passwordChange = {
330
- body: {
331
- jwt: 'user-jwt-token',
332
- customerId: 'cust-1',
333
- oldPassword: 'oldpassword123',
334
- newPassword: 'newpassword456',
335
- },
336
- headers: {},
337
- };
338
- const success = { jwt: 'updated-jwt-token' };
339
- clients.customer.changePassword.mockResolvedValue(success);
340
- // For changePassword test, we need mockCreateClient to return customer client
341
- mockCreateClient.mockReturnValue(clients.customer);
342
- const result = yield (0, auth_1.changePassword)(passwordChange);
343
- expect(result.status).toBe('success');
344
- expect(result).toHaveProperty('value');
345
- }));
346
- it('should reject when current password is incorrect', () => __awaiter(void 0, void 0, void 0, function* () {
347
- const { clients } = setupAuthService();
348
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Current password is incorrect');
349
- clients.customer.changePassword.mockRejectedValue(error);
350
- mockCreateClient.mockReturnValue(clients.customer);
351
- const result = yield (0, auth_1.changePassword)({
352
- body: {
353
- jwt: 'user-jwt-token',
354
- customerId: 'cust-1',
355
- oldPassword: 'wrongpassword',
356
- newPassword: 'newpassword456',
357
- },
358
- headers: {},
359
- });
360
- expect(result.status).toBe('failed');
361
- }));
362
- it('should enforce password complexity requirements', () => __awaiter(void 0, void 0, void 0, function* () {
363
- const { clients } = setupAuthService();
364
- const error = (0, test_utils_1.createMockConnectError)(3, 'INVALID_ARGUMENT', 'Password does not meet complexity requirements');
365
- clients.customer.changePassword.mockRejectedValue(error);
366
- mockCreateClient.mockReturnValue(clients.customer);
367
- const result = yield (0, auth_1.changePassword)({
368
- body: {
369
- jwt: 'user-jwt-token',
370
- customerId: 'cust-1',
371
- oldPassword: 'oldpassword123',
372
- newPassword: 'weak',
373
- },
374
- headers: {},
375
- });
376
- expect(result.status).toBe('failed');
377
- }));
378
- it('should reject requests with invalid or expired JWT', () => __awaiter(void 0, void 0, void 0, function* () {
379
- const { clients } = setupAuthService();
380
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Invalid or expired JWT');
381
- clients.customer.changePassword.mockRejectedValue(error);
382
- mockCreateClient.mockReturnValue(clients.customer);
383
- const result = yield (0, auth_1.changePassword)({
384
- body: {
385
- jwt: 'expired-jwt-token',
386
- customerId: 'cust-1',
387
- oldPassword: 'oldpassword123',
388
- newPassword: 'newpassword456',
389
- },
390
- headers: {},
391
- });
392
- expect(result.status).toBe('failed');
393
- }));
394
- it('should not include JWT in service request', () => __awaiter(void 0, void 0, void 0, function* () {
395
- const { clients } = setupAuthService();
396
- const success = { jwt: 'updated-jwt-token' };
397
- clients.customer.changePassword.mockResolvedValue(success);
398
- mockCreateClient.mockReturnValue(clients.customer);
399
- const jwtToken = 'user-jwt-token';
400
- const passwordData = {
401
- body: {
402
- jwt: jwtToken,
403
- customerId: 'cust-1',
404
- oldPassword: 'oldpassword123',
405
- newPassword: 'newpassword456',
406
- },
407
- headers: {},
408
- };
409
- yield (0, auth_1.changePassword)(passwordData);
410
- // Verify that JWT is not passed directly to the service
411
- const callArgs = clients.customer.changePassword.mock.calls[0][0];
412
- expect(callArgs).not.toHaveProperty('jwt');
413
- }));
414
- it('should apply three interceptors in correct order', () => __awaiter(void 0, void 0, void 0, function* () {
415
- const { clients, interceptors } = setupAuthService();
416
- const success = { jwt: 'updated-jwt-token' };
417
- clients.customer.changePassword.mockResolvedValue(success);
418
- mockCreateClient.mockReturnValue(clients.customer);
419
- const headers = {
420
- 'x-shop-id': '123',
421
- };
422
- const jwt = 'user-jwt-token';
423
- yield (0, auth_1.changePassword)({
424
- body: {
425
- customerId: 'cust-1',
426
- oldPassword: 'oldpassword123',
427
- newPassword: 'newpassword456',
428
- jwt,
429
- },
430
- headers,
431
- });
432
- expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(headers);
433
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled();
434
- expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(jwt);
435
- }));
436
- it('should handle database errors gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
437
- const { clients } = setupAuthService();
438
- const dbError = (0, test_utils_1.createMockConnectError)(13, 'INTERNAL', 'Database error occurred');
439
- clients.customer.changePassword.mockRejectedValue(dbError);
440
- mockCreateClient.mockReturnValue(clients.customer);
441
- const result = yield (0, auth_1.changePassword)({
442
- body: {
443
- jwt: 'user-jwt-token',
444
- customerId: 'cust-1',
445
- oldPassword: 'oldpassword123',
446
- newPassword: 'newpassword456',
447
- },
448
- headers: {},
449
- });
450
- expect(result.status).toBe('failed');
451
- }));
452
- it('should handle permission errors when user cannot change password', () => __awaiter(void 0, void 0, void 0, function* () {
453
- const { clients } = setupAuthService();
454
- const error = (0, test_utils_1.createMockConnectError)(7, 'PERMISSION_DENIED', 'User does not have permission to change password');
455
- clients.customer.changePassword.mockRejectedValue(error);
456
- mockCreateClient.mockReturnValue(clients.customer);
457
- const result = yield (0, auth_1.changePassword)({
458
- body: {
459
- jwt: 'restricted-jwt-token',
460
- customerId: 'cust-1',
461
- oldPassword: 'oldpassword123',
462
- newPassword: 'newpassword456',
463
- },
464
- headers: {},
465
- });
466
- expect(result.status).toBe('failed');
467
- }));
468
- });
469
- describe('Common Authentication Behavior', () => {
470
- it('should load configuration once per request', () => __awaiter(void 0, void 0, void 0, function* () {
471
- const { clients } = setupAuthService();
472
- clients.auth.login.mockResolvedValue({
473
- jwt: 'token123',
474
- refreshToken: 'refresh123',
475
- });
476
- yield (0, auth_1.login)({
477
- body: {
478
- email: 'user@example.com',
479
- password: 'password123',
480
- },
481
- headers: {},
482
- });
483
- yield (0, auth_1.login)({
484
- body: {
485
- email: 'user2@example.com',
486
- password: 'password456',
487
- },
488
- headers: {},
489
- });
490
- expect(mockGetCheckoutConfig).toHaveBeenCalledTimes(2);
491
- }));
492
- it('should support different error scenarios across functions', () => __awaiter(void 0, void 0, void 0, function* () {
493
- const { clients } = setupAuthService();
494
- const errorScenarios = [
495
- {
496
- code: 16,
497
- message: 'UNAUTHENTICATED',
498
- fn: auth_1.login,
499
- args: {
500
- body: {
501
- email: 'user@example.com',
502
- password: 'invalid',
503
- },
504
- headers: {},
505
- },
506
- },
507
- {
508
- code: 16,
509
- message: 'UNAUTHENTICATED',
510
- fn: auth_1.refreshToken,
511
- args: {
512
- body: {
513
- refreshToken: 'expired-token',
514
- },
515
- headers: {},
516
- },
517
- },
518
- {
519
- code: 16,
520
- message: 'UNAUTHENTICATED',
521
- fn: auth_1.changePassword,
522
- args: {
523
- body: {
524
- jwt: 'invalid-jwt',
525
- customerId: 'cust-1',
526
- oldPassword: 'old',
527
- newPassword: 'new',
528
- },
529
- headers: {},
530
- },
531
- },
532
- ];
533
- for (const scenario of errorScenarios) {
534
- const error = (0, test_utils_1.createMockConnectError)(scenario.code, scenario.message, scenario.message);
535
- if (scenario.fn === auth_1.login) {
536
- clients.auth.login.mockRejectedValueOnce(error);
537
- }
538
- else if (scenario.fn === auth_1.refreshToken) {
539
- clients.auth.refreshToken.mockRejectedValueOnce(error);
540
- }
541
- else {
542
- clients.customer.changePassword.mockRejectedValueOnce(error);
543
- }
544
- const result = yield scenario.fn(scenario.args);
545
- expect(result.status).toBe('failed');
546
- }
547
- }));
548
- it('should handle edge cases with special characters and long inputs', () => __awaiter(void 0, void 0, void 0, function* () {
549
- const { clients } = setupAuthService();
550
- const jwt = 'special-chars-token-!@#$%^&*()';
551
- clients.auth.login.mockResolvedValue({
552
- jwt: 'new-token',
553
- });
554
- const result = yield (0, auth_1.login)({
555
- body: {
556
- email: 'user+tag@example.com',
557
- password: 'P@ssw0rd!@#$%^&*()',
558
- },
559
- headers: {},
560
- });
561
- expect(result.status).toBe('success');
562
- }));
563
- it('should handle null or undefined headers gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
564
- const { clients } = setupAuthService();
565
- const jwt = 'test-jwt-token';
566
- clients.auth.login.mockResolvedValue({
567
- jwt: 'token123',
568
- refreshToken: 'refresh123',
569
- });
570
- const result = yield (0, auth_1.login)({
571
- body: {
572
- email: 'user@example.com',
573
- password: 'password123',
574
- },
575
- headers: {
576
- 'x-header': null,
577
- },
578
- });
579
- expect(result.status).toBe('success');
580
- }));
581
- });
582
- });
@@ -1,3 +0,0 @@
1
- import { type Compression } from '@connectrpc/connect/protocol';
2
- export declare const brotliCompression: Compression;
3
- //# sourceMappingURL=brotli.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../src/compressor/brotli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAI/D,eAAO,MAAM,iBAAiB,EAAE,WAqB/B,CAAA"}
@@ -1,30 +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.brotliCompression = void 0;
13
- const brotli = require('brotli');
14
- exports.brotliCompression = {
15
- name: 'br',
16
- compress: (bytes) => __awaiter(void 0, void 0, void 0, function* () {
17
- return new Uint8Array(brotli.compress(bytes, {
18
- mode: 0, // 0 = generic, 1 = text, 2 = font (WOFF2)
19
- quality: 9, // 0 - 11
20
- lgwin: 22, // window size
21
- }));
22
- }),
23
- decompress: (bytes, readMaxBytes) => __awaiter(void 0, void 0, void 0, function* () {
24
- const decompressed = brotli.decompress(bytes);
25
- if (decompressed.length > readMaxBytes) {
26
- throw new Error('Decompressed size exceeds readMaxBytes limit');
27
- }
28
- return new Uint8Array(decompressed);
29
- }),
30
- };