@paakd/api 0.0.5 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,aAAa,EAElB,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC7C,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9C,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC;AA4BD,wBAAgB,wBAAwB,CACtC,SAAS,GAAE,CACT,OAAO,EAAE,YAAY,GAAG,aAAa,KAClC,aAAoC,GACxC,WAAW,CAab;AAED,wBAAgB,+BAA+B,CAC7C,cAAc,EAAE,QAAQ,GACvB,WAAW,CASb;AAED,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,OAAO,GACd,WAAW,CASb;AAsFD,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GACrC,WAAW,CA0Cb"}
1
+ {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,aAAa,EAElB,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC7C,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9C,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC;AA4BD,wBAAgB,wBAAwB,CACtC,SAAS,GAAE,CACT,OAAO,EAAE,YAAY,GAAG,aAAa,KAClC,aAAoC,GACxC,WAAW,CAab;AAED,wBAAgB,+BAA+B,CAC7C,cAAc,EAAE,QAAQ,GACvB,WAAW,CASb;AAED,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,OAAO,GACd,WAAW,CAKb;AAsFD,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GACrC,WAAW,CA0Cb"}
@@ -64,9 +64,6 @@ function createAuthenticationInterceptor(checkoutConfig) {
64
64
  }
65
65
  function createCustomerAuthenticationInterceptor(jwtKey, debug) {
66
66
  return next => (req) => __awaiter(this, void 0, void 0, function* () {
67
- if (!jwtKey) {
68
- throw new connect_1.ConnectError('JWT token is not provided', connect_1.Code.Unauthenticated);
69
- }
70
67
  req.header.set('Authorization', `Bearer ${jwtKey}`);
71
68
  return yield next(req);
72
69
  });
@@ -515,46 +515,6 @@ describe('interceptors', () => {
515
515
  expect(streamRequest.header.get('Authorization')).toBe(`Bearer ${jwtToken}`);
516
516
  expect(result).toBe(mockResponse);
517
517
  }));
518
- it('should throw error for empty JWT token', () => __awaiter(void 0, void 0, void 0, function* () {
519
- const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)('');
520
- const interceptorFn = interceptor(mockNext);
521
- try {
522
- yield interceptorFn(mockRequest);
523
- expect.fail('Should have thrown error');
524
- }
525
- catch (error) {
526
- expect(error).toBeInstanceOf(connect_1.ConnectError);
527
- }
528
- }));
529
- it('should throw Unauthenticated error code for empty JWT', () => __awaiter(void 0, void 0, void 0, function* () {
530
- const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)('');
531
- const interceptorFn = interceptor(mockNext);
532
- try {
533
- yield interceptorFn(mockRequest);
534
- expect.fail('Should have thrown error');
535
- }
536
- catch (error) {
537
- expect(error).toBeInstanceOf(connect_1.ConnectError);
538
- expect(error.code).toBe(connect_1.Code.Unauthenticated);
539
- }
540
- }));
541
- it('should throw error for null JWT token', () => __awaiter(void 0, void 0, void 0, function* () {
542
- const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)(null);
543
- const interceptorFn = interceptor(mockNext);
544
- yield expect(interceptorFn(mockRequest)).rejects.toThrow();
545
- }));
546
- it('should throw error for undefined JWT token', () => __awaiter(void 0, void 0, void 0, function* () {
547
- const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)(undefined);
548
- const interceptorFn = interceptor(mockNext);
549
- yield expect(interceptorFn(mockRequest)).rejects.toThrow();
550
- }));
551
- it('should not call next when JWT validation fails', () => __awaiter(void 0, void 0, void 0, function* () {
552
- const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)('');
553
- const interceptorFn = interceptor(mockNext);
554
- yield expect(interceptorFn(mockRequest)).rejects.toThrow();
555
- // next should never be called if validation fails
556
- expect(mockNext).not.toHaveBeenCalled();
557
- }));
558
518
  it('should propagate response from next interceptor', () => __awaiter(void 0, void 0, void 0, function* () {
559
519
  const jwtToken = 'test-jwt-token';
560
520
  const interceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwtToken);
@@ -889,60 +849,6 @@ describe('interceptors', () => {
889
849
  expect(mockRequest.header.get('Authorization')).toBe(`Bearer ${jwtToken}`);
890
850
  expect(mockNext).toHaveBeenCalled();
891
851
  }));
892
- it('should handle errors in chained interceptors', () => __awaiter(void 0, void 0, void 0, function* () {
893
- const jwtToken = '';
894
- const mockNext = vi.fn();
895
- mockNext.mockResolvedValue({
896
- header: new Headers(),
897
- message: { $typeName: 'test.Message' },
898
- trailer: new Headers(),
899
- });
900
- const mockCheckoutConfig = {
901
- hostname: 'example.com',
902
- cmsRemoteURL: 'https://cms.example.com',
903
- enterpriseRemoteURL: 'https://enterprise.example.com',
904
- cmsURL: 'https://cms-local.example.com',
905
- enterpriseURL: 'https://enterprise.example.com',
906
- secureCookiePassword: 'secure-cookie-password',
907
- forestAPIKey: 'forest-api-key',
908
- saleChannelAccessKey: 'test-sales-channel-access',
909
- salesChannelAPISecret: 'test-sales-channel-secret',
910
- storeAccessKey: 'test-store-access',
911
- storeAPISecret: 'test-store-secret',
912
- isProduction: false,
913
- posthogKey: 'posthog-key',
914
- posthogDomain: 'posthog.example.com',
915
- posthogHost: 'posthog.example.com',
916
- assetsPath: '/assets',
917
- assetsDomain: 'assets.example.com',
918
- turnstileKey: 'turnstile-key',
919
- turnstileSecret: 'turnstile-secret',
920
- redis: {
921
- user: 'redis-user',
922
- host: 'localhost',
923
- password: 'redis-password',
924
- port: 6379,
925
- },
926
- };
927
- // Chain: auth -> customer auth (will fail) -> logging
928
- const authInterceptor = (0, interceptors_1.createAuthenticationInterceptor)(mockCheckoutConfig);
929
- const customerAuthInterceptor = (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwtToken);
930
- const loggingInterceptor = (0, interceptors_1.createLoggingInterceptor)();
931
- const chainedInterceptor = authInterceptor(customerAuthInterceptor(loggingInterceptor(mockNext)));
932
- const mockRequest = {
933
- header: new Headers(),
934
- method: {
935
- toString: () => 'TestService/TestMethod',
936
- },
937
- message: { $typeName: 'test.Message' },
938
- };
939
- // Should fail at customer auth interceptor
940
- yield expect(chainedInterceptor(mockRequest)).rejects.toThrow();
941
- // Auth headers should still be set before error
942
- expect(mockRequest.header.get('X-Store-Key')).toBe('test-store-secret');
943
- // But next should not be called
944
- expect(mockNext).not.toHaveBeenCalled();
945
- }));
946
852
  it('should work with all interceptors including headers', () => __awaiter(void 0, void 0, void 0, function* () {
947
853
  const jwtToken = 'test-jwt';
948
854
  const mockNext = vi.fn();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paakd/api",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "repository": {
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "main": "./dist/src/index.js",
18
18
  "dependencies": {
19
- "@paakd/core": "0.0.5",
20
- "@paakd/entities": "0.0.5"
19
+ "@paakd/entities": "0.0.6",
20
+ "@paakd/core": "0.0.6"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@bufbuild/buf": "^1.60.0",
@@ -43,9 +43,9 @@
43
43
  "prettier": "^3.5.3",
44
44
  "typescript": "^5.8.3",
45
45
  "vitest": "4.0.16",
46
- "@paakd/config": "0.0.5",
47
- "@paakd/eslint-config": "0.0.5",
48
- "@paakd/typescript-config": "0.0.5"
46
+ "@paakd/config": "0.0.6",
47
+ "@paakd/eslint-config": "0.0.6",
48
+ "@paakd/typescript-config": "0.0.6"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"