@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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBrB,CAAA;AAED,cAAc,2CAA2C,CAAA;AACzD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,mDAAmD,CAAA;AACjE,cAAc,mDAAmD,CAAA;AACjE,cAAc,4CAA4C,CAAA;AAC1D,cAAc,mDAAmD,CAAA;AACjE,cAAc,qDAAqD,CAAA;AACnE,cAAc,8CAA8C,CAAA;AAC5D,cAAc,mDAAmD,CAAA;AACjE,cAAc,+CAA+C,CAAA;AAC7D,cAAc,kDAAkD,CAAA;AAChE,cAAc,qDAAqD,CAAA;AACnE,cAAc,sDAAsD,CAAA"}
package/dist/src/index.js CHANGED
@@ -13,9 +13,52 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
16
25
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./address"), exports);
18
- __exportStar(require("./auth"), exports);
19
- __exportStar(require("./policies"), exports);
20
- __exportStar(require("./profile"), exports);
21
- __exportStar(require("./registration"), exports);
26
+ exports.createAPIClient = void 0;
27
+ const config_1 = require("@paakd/config");
28
+ const connect_1 = require("@connectrpc/connect");
29
+ const service_pb_1 = require("../gen/src/proto/products/v1/service_pb");
30
+ const connect_node_1 = require("@connectrpc/connect-node");
31
+ const core_1 = require("@paakd/core");
32
+ const interceptors_1 = require("./interceptors");
33
+ const service_pb_2 = require("../gen/src/proto/customers/v1/service_pb");
34
+ const service_pb_3 = require("../gen/src/proto/auth/v1/service_pb");
35
+ const service_pb_4 = require("../gen/src/proto/stocknodes/v1/service_pb");
36
+ const service_pb_5 = require("../gen/src/proto/files/v1/service_pb");
37
+ const service_pb_6 = require("../gen/src/proto/promotions/v1/service_pb");
38
+ const createAPIClient = (_a) => __awaiter(void 0, [_a], void 0, function* ({ conf, headers = {}, jwt = '', debug = false, }) {
39
+ const checkoutConfig = yield (0, config_1.getCheckoutConfig)(conf);
40
+ const reqHeaders = yield (0, core_1.getRequestHeaders)(conf);
41
+ const transport = (0, connect_node_1.createGrpcTransport)({
42
+ baseUrl: checkoutConfig.enterpriseURL,
43
+ interceptors: [
44
+ (0, interceptors_1.createHeadersInterceptor)(Object.assign(Object.assign({}, reqHeaders), headers)),
45
+ (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
46
+ (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt, debug),
47
+ ],
48
+ });
49
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, connect_1.createClient)(service_pb_2.CustomerService, transport)), (0, connect_1.createClient)(service_pb_3.AuthService, transport)), (0, connect_1.createClient)(service_pb_1.ProductsService, transport)), (0, connect_1.createClient)(service_pb_5.FileService, transport)), (0, connect_1.createClient)(service_pb_6.CampaignService, transport)), (0, connect_1.createClient)(service_pb_4.StockNodesService, transport));
50
+ });
51
+ exports.createAPIClient = createAPIClient;
52
+ __exportStar(require("../gen/src/proto/auth/v1/entities/auth_pb"), exports);
53
+ __exportStar(require("../gen/src/proto/auth/v1/entities/policy_pb"), exports);
54
+ __exportStar(require("../gen/src/proto/customers/v1/entities/address_pb"), exports);
55
+ __exportStar(require("../gen/src/proto/customers/v1/entities/profile_pb"), exports);
56
+ __exportStar(require("../gen/src/proto/files/v1/entities/file_pb"), exports);
57
+ __exportStar(require("../gen/src/proto/products/v1/entities/category_pb"), exports);
58
+ __exportStar(require("../gen/src/proto/products/v1/entities/collection_pb"), exports);
59
+ __exportStar(require("../gen/src/proto/products/v1/entities/tag_pb"), exports);
60
+ __exportStar(require("../gen/src/proto/products/v1/entities/taxonomy_pb"), exports);
61
+ __exportStar(require("../gen/src/proto/products/v1/entities/type_pb"), exports);
62
+ __exportStar(require("../gen/src/proto/products/v1/entities/variant_pb"), exports);
63
+ __exportStar(require("../gen/src/proto/promotions/v1/entities/campaign_pb"), exports);
64
+ __exportStar(require("../gen/src/proto/stocknodes/v1/entities/stocknode_pb"), exports);
@@ -11,6 +11,6 @@ export interface RequestLogger {
11
11
  }
12
12
  export declare function createLoggingInterceptor(reqLogger?: (request: UnaryRequest | StreamRequest) => RequestLogger): Interceptor;
13
13
  export declare function createAuthenticationInterceptor(checkoutConfig: Checkout): Interceptor;
14
- export declare function createCustomerAuthenticationInterceptor(jwtKey: string): Interceptor;
14
+ export declare function createCustomerAuthenticationInterceptor(jwtKey: string, debug?: boolean): Interceptor;
15
15
  export declare function createHeadersInterceptor(headers: Record<string, string | null>): Interceptor;
16
16
  //# sourceMappingURL=interceptors.d.ts.map
@@ -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,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AC,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"}
@@ -62,11 +62,8 @@ function createAuthenticationInterceptor(checkoutConfig) {
62
62
  return yield next(req);
63
63
  });
64
64
  }
65
- function createCustomerAuthenticationInterceptor(jwtKey) {
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 key is required for customer authentication', 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.4",
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
- "brotli": "1.3.3",
20
- "@paakd/entities": "0.0.4"
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/eslint-config": "0.0.4",
47
- "@paakd/config": "0.0.4",
48
- "@paakd/typescript-config": "0.0.4"
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"
@@ -1,53 +0,0 @@
1
- import type { AddAddressRequest, UpdateAddressRequest, GetAddressResponse, DeleteAddressResponse } from '../gen/src/proto/customers/v1/entities/address_pb';
2
- export interface GetAddressProps {
3
- body: {
4
- customerId: string;
5
- addressId: string;
6
- jwt: string;
7
- };
8
- headers: Record<string, string | null>;
9
- }
10
- export interface GetAddressesProps {
11
- body: {
12
- customerId: string;
13
- jwt: string;
14
- };
15
- headers: Record<string, string | null>;
16
- }
17
- export interface AddAddressProps {
18
- body: Omit<AddAddressRequest, '$typeName'> & {
19
- jwt: string;
20
- };
21
- headers: Record<string, string | null>;
22
- }
23
- export interface UpdateAddressProps {
24
- body: Omit<UpdateAddressRequest, '$typeName'> & {
25
- jwt: string;
26
- };
27
- headers: Record<string, string | null>;
28
- }
29
- export interface DeleteAddressProps {
30
- body: {
31
- customerId: string;
32
- addressId: string;
33
- jwt: string;
34
- };
35
- headers: Record<string, string | null>;
36
- }
37
- export type SuccessResponse<T> = {
38
- value: T;
39
- status: 'success';
40
- };
41
- export type ErrorResponse = {
42
- code: number;
43
- rawMessage: string;
44
- message: string;
45
- status: 'failed';
46
- };
47
- export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse;
48
- export declare function getAddresses({ body: { customerId, jwt }, headers, }: GetAddressesProps): Promise<ApiResponse<GetAddressResponse[]>>;
49
- export declare function getAddress({ body: { customerId, addressId, jwt }, headers, }: GetAddressProps): Promise<ApiResponse<GetAddressResponse>>;
50
- export declare function addAddress({ body: { jwt, ...val }, headers, }: AddAddressProps): Promise<ApiResponse<GetAddressResponse | undefined>>;
51
- export declare function deleteAddress({ body: { customerId, addressId, jwt }, headers, }: DeleteAddressProps): Promise<ApiResponse<DeleteAddressResponse>>;
52
- export declare function updateAddress({ body: { jwt, ...val }, headers, }: UpdateAddressProps): Promise<ApiResponse<GetAddressResponse | undefined>>;
53
- //# sourceMappingURL=address.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,mDAAmD,CAAA;AAQ1D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;QACjB,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;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C,CAAC,CA0ChE;AAED,wBAAsB,UAAU,CAAC,EAC/B,IAAI,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,EACpC,OAAO,GACR,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CA2C5D;AAED,wBAAsB,UAAU,CAAC,EAC/B,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,EACrB,OAAO,GACR,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC,CAwCxE;AAED,wBAAsB,aAAa,CAAC,EAClC,IAAI,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,EACpC,OAAO,GACR,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,CA2ClE;AAED,wBAAsB,aAAa,CAAC,EAClC,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,EACrB,OAAO,GACR,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC,CAwC3E"}
@@ -1,233 +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
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.getAddresses = getAddresses;
24
- exports.getAddress = getAddress;
25
- exports.addAddress = addAddress;
26
- exports.deleteAddress = deleteAddress;
27
- exports.updateAddress = updateAddress;
28
- const connect_1 = require("@connectrpc/connect");
29
- const connect_node_1 = require("@connectrpc/connect-node");
30
- const config_1 = require("@paakd/config");
31
- const service_pb_1 = require("../gen/src/proto/customers/v1/service_pb");
32
- const brotli_1 = require("./compressor/brotli");
33
- const interceptors_1 = require("./interceptors");
34
- function getAddresses(_a) {
35
- return __awaiter(this, arguments, void 0, function* ({ body: { customerId, jwt }, headers, }) {
36
- try {
37
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
38
- const addressClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
39
- baseUrl: checkoutConfig.enterpriseURL,
40
- interceptors: [
41
- (0, interceptors_1.createHeadersInterceptor)(headers),
42
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
43
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
44
- ],
45
- acceptCompression: [brotli_1.brotliCompression],
46
- sendCompression: brotli_1.brotliCompression,
47
- }));
48
- const { addresses } = yield addressClient.getAddresses({
49
- customerId,
50
- });
51
- return {
52
- value: addresses,
53
- status: 'success',
54
- };
55
- }
56
- catch (err) {
57
- if (err instanceof connect_1.ConnectError) {
58
- return {
59
- code: err.code,
60
- rawMessage: err.rawMessage,
61
- message: err.rawMessage,
62
- status: 'failed',
63
- };
64
- }
65
- return {
66
- code: connect_1.Code.Internal,
67
- rawMessage: 'error fetching addresses.',
68
- message: 'error fetching addresses.',
69
- status: 'failed',
70
- };
71
- }
72
- });
73
- }
74
- function getAddress(_a) {
75
- return __awaiter(this, arguments, void 0, function* ({ body: { customerId, addressId, jwt }, headers, }) {
76
- try {
77
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
78
- const addressClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
79
- baseUrl: checkoutConfig.enterpriseURL,
80
- interceptors: [
81
- (0, interceptors_1.createHeadersInterceptor)(headers),
82
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
83
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
84
- ],
85
- acceptCompression: [brotli_1.brotliCompression],
86
- sendCompression: brotli_1.brotliCompression,
87
- }));
88
- const value = yield addressClient.getAddress({
89
- customerId,
90
- addressId,
91
- });
92
- return {
93
- value,
94
- status: 'success',
95
- };
96
- }
97
- catch (err) {
98
- if (err instanceof connect_1.ConnectError) {
99
- return {
100
- code: err.code,
101
- rawMessage: err.rawMessage,
102
- message: err.rawMessage,
103
- status: 'failed',
104
- };
105
- }
106
- return {
107
- code: connect_1.Code.Internal,
108
- rawMessage: 'error fetching address.',
109
- message: 'error fetching address.',
110
- status: 'failed',
111
- };
112
- }
113
- });
114
- }
115
- function addAddress(_a) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- var _b = _a.body, { jwt } = _b, val = __rest(_b, ["jwt"]), { headers } = _a;
118
- try {
119
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
120
- const addressClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
121
- baseUrl: checkoutConfig.enterpriseURL,
122
- interceptors: [
123
- (0, interceptors_1.createHeadersInterceptor)(headers),
124
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
125
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
126
- ],
127
- acceptCompression: [brotli_1.brotliCompression],
128
- sendCompression: brotli_1.brotliCompression,
129
- }));
130
- const { address } = yield addressClient.addAddress(val);
131
- return {
132
- value: address,
133
- status: 'success',
134
- };
135
- }
136
- catch (err) {
137
- if (err instanceof connect_1.ConnectError) {
138
- return {
139
- code: err.code,
140
- rawMessage: err.rawMessage,
141
- message: err.rawMessage,
142
- status: 'failed',
143
- };
144
- }
145
- return {
146
- code: connect_1.Code.Internal,
147
- rawMessage: 'error adding address.',
148
- message: 'error adding address.',
149
- status: 'failed',
150
- };
151
- }
152
- });
153
- }
154
- function deleteAddress(_a) {
155
- return __awaiter(this, arguments, void 0, function* ({ body: { customerId, addressId, jwt }, headers, }) {
156
- try {
157
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
158
- const addressClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
159
- baseUrl: checkoutConfig.enterpriseURL,
160
- interceptors: [
161
- (0, interceptors_1.createHeadersInterceptor)(headers),
162
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
163
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
164
- ],
165
- acceptCompression: [brotli_1.brotliCompression],
166
- sendCompression: brotli_1.brotliCompression,
167
- }));
168
- const value = yield addressClient.deleteAddress({
169
- customerId,
170
- addressId,
171
- });
172
- return {
173
- value,
174
- status: 'success',
175
- };
176
- }
177
- catch (err) {
178
- if (err instanceof connect_1.ConnectError) {
179
- return {
180
- code: err.code,
181
- rawMessage: err.rawMessage,
182
- message: err.rawMessage,
183
- status: 'failed',
184
- };
185
- }
186
- return {
187
- code: connect_1.Code.Internal,
188
- rawMessage: 'error deleting address.',
189
- message: 'error deleting address.',
190
- status: 'failed',
191
- };
192
- }
193
- });
194
- }
195
- function updateAddress(_a) {
196
- return __awaiter(this, void 0, void 0, function* () {
197
- var _b = _a.body, { jwt } = _b, val = __rest(_b, ["jwt"]), { headers } = _a;
198
- try {
199
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
200
- const addressClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
201
- baseUrl: checkoutConfig.enterpriseURL,
202
- interceptors: [
203
- (0, interceptors_1.createHeadersInterceptor)(headers),
204
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
205
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
206
- ],
207
- acceptCompression: [brotli_1.brotliCompression],
208
- sendCompression: brotli_1.brotliCompression,
209
- }));
210
- const { address } = yield addressClient.updateAddress(val);
211
- return {
212
- value: address,
213
- status: 'success',
214
- };
215
- }
216
- catch (err) {
217
- if (err instanceof connect_1.ConnectError) {
218
- return {
219
- code: err.code,
220
- rawMessage: err.rawMessage,
221
- message: err.rawMessage,
222
- status: 'failed',
223
- };
224
- }
225
- return {
226
- code: connect_1.Code.Internal,
227
- rawMessage: 'error updating address.',
228
- message: 'error updating address.',
229
- status: 'failed',
230
- };
231
- }
232
- });
233
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=address.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address.spec.d.ts","sourceRoot":"","sources":["../../src/address.spec.ts"],"names":[],"mappings":""}