@paakd/api 0.0.1 → 0.0.2

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 (201) hide show
  1. package/buf/validate/validate_pb.ts +5001 -0
  2. package/dist/gen/buf/validate/validate_pb.d.ts +4634 -0
  3. package/dist/gen/buf/validate/validate_pb.d.ts.map +1 -0
  4. package/dist/gen/buf/validate/validate_pb.js +414 -0
  5. package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts +268 -0
  6. package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts.map +1 -0
  7. package/dist/gen/src/proto/auth/v1/entities/auth_pb.js +120 -0
  8. package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts +235 -0
  9. package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts.map +1 -0
  10. package/dist/gen/src/proto/auth/v1/entities/policy_pb.js +98 -0
  11. package/dist/gen/src/proto/auth/v1/service_pb.d.ts +117 -0
  12. package/dist/gen/src/proto/auth/v1/service_pb.d.ts.map +1 -0
  13. package/dist/gen/src/proto/auth/v1/service_pb.js +22 -0
  14. package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts +371 -0
  15. package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts.map +1 -0
  16. package/dist/gen/src/proto/customers/v1/entities/address_pb.js +84 -0
  17. package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts +189 -0
  18. package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts.map +1 -0
  19. package/dist/gen/src/proto/customers/v1/entities/profile_pb.js +70 -0
  20. package/dist/gen/src/proto/customers/v1/service_pb.d.ts +85 -0
  21. package/dist/gen/src/proto/customers/v1/service_pb.d.ts.map +1 -0
  22. package/dist/gen/src/proto/customers/v1/service_pb.js +22 -0
  23. package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts +234 -0
  24. package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts.map +1 -0
  25. package/dist/gen/src/proto/products/v1/entities/category_pb.js +84 -0
  26. package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts +159 -0
  27. package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts.map +1 -0
  28. package/dist/gen/src/proto/products/v1/entities/collection_pb.js +70 -0
  29. package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts +146 -0
  30. package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts.map +1 -0
  31. package/dist/gen/src/proto/products/v1/entities/product/create_pb.js +32 -0
  32. package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts +50 -0
  33. package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts.map +1 -0
  34. package/dist/gen/src/proto/products/v1/entities/product/option_pb.js +32 -0
  35. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts +1042 -0
  36. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts.map +1 -0
  37. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.js +258 -0
  38. package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts +236 -0
  39. package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts.map +1 -0
  40. package/dist/gen/src/proto/products/v1/entities/product/update_pb.js +88 -0
  41. package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts +175 -0
  42. package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts.map +1 -0
  43. package/dist/gen/src/proto/products/v1/entities/tag_pb.js +84 -0
  44. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts +477 -0
  45. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts.map +1 -0
  46. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.js +235 -0
  47. package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts +158 -0
  48. package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts.map +1 -0
  49. package/dist/gen/src/proto/products/v1/entities/type_pb.js +70 -0
  50. package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts +489 -0
  51. package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts.map +1 -0
  52. package/dist/gen/src/proto/products/v1/entities/variant_pb.js +147 -0
  53. package/dist/gen/src/proto/products/v1/service_pb.d.ts +316 -0
  54. package/dist/gen/src/proto/products/v1/service_pb.d.ts.map +1 -0
  55. package/dist/gen/src/proto/products/v1/service_pb.js +36 -0
  56. package/dist/src/address.d.ts +53 -0
  57. package/dist/src/address.d.ts.map +1 -0
  58. package/dist/src/address.js +233 -0
  59. package/dist/src/address.spec.d.ts +2 -0
  60. package/dist/src/address.spec.d.ts.map +1 -0
  61. package/dist/src/address.spec.js +488 -0
  62. package/dist/src/auth.d.ts +27 -0
  63. package/dist/src/auth.d.ts.map +1 -0
  64. package/dist/src/auth.js +155 -0
  65. package/dist/src/auth.spec.d.ts +2 -0
  66. package/dist/src/auth.spec.d.ts.map +1 -0
  67. package/dist/src/auth.spec.js +582 -0
  68. package/dist/src/compressor/brotli.d.ts +3 -0
  69. package/dist/src/compressor/brotli.d.ts.map +1 -0
  70. package/dist/src/compressor/brotli.js +30 -0
  71. package/dist/src/index.d.ts +6 -0
  72. package/dist/src/index.d.ts.map +1 -0
  73. package/dist/src/interceptors.d.ts +16 -0
  74. package/dist/src/interceptors.d.ts.map +1 -0
  75. package/dist/src/interceptors.js +156 -0
  76. package/dist/src/interceptors.spec.d.ts +2 -0
  77. package/dist/src/interceptors.spec.d.ts.map +1 -0
  78. package/dist/src/interceptors.spec.js +1063 -0
  79. package/dist/src/policies.d.ts +217 -0
  80. package/dist/src/policies.d.ts.map +1 -0
  81. package/dist/src/policies.js +322 -0
  82. package/dist/src/policies.spec.d.ts +2 -0
  83. package/dist/src/policies.spec.d.ts.map +1 -0
  84. package/dist/src/policies.spec.js +463 -0
  85. package/dist/src/products.d.ts +39 -0
  86. package/dist/src/products.d.ts.map +1 -0
  87. package/dist/src/products.js +95 -0
  88. package/dist/src/products.spec.d.ts +2 -0
  89. package/dist/src/products.spec.d.ts.map +1 -0
  90. package/dist/src/products.spec.js +519 -0
  91. package/dist/src/profile.d.ts +62 -0
  92. package/dist/src/profile.d.ts.map +1 -0
  93. package/dist/src/profile.js +151 -0
  94. package/dist/src/profile.spec.d.ts +2 -0
  95. package/dist/src/profile.spec.d.ts.map +1 -0
  96. package/dist/src/profile.spec.js +475 -0
  97. package/dist/src/registration.d.ts +60 -0
  98. package/dist/src/registration.d.ts.map +1 -0
  99. package/dist/src/registration.js +147 -0
  100. package/dist/src/test-utils.d.ts +87 -0
  101. package/dist/src/test-utils.d.ts.map +1 -0
  102. package/dist/src/test-utils.js +132 -0
  103. package/gen/buf/validate/validate_pb.ts +4799 -0
  104. package/gen/src/proto/auth/v1/authv1connect/service.connect.go +454 -0
  105. package/gen/src/proto/auth/v1/entities/auth.pb.go +818 -0
  106. package/gen/src/proto/auth/v1/entities/auth_pb.ts +348 -0
  107. package/gen/src/proto/auth/v1/entities/policy.pb.go +727 -0
  108. package/gen/src/proto/auth/v1/entities/policy_pb.ts +306 -0
  109. package/gen/src/proto/auth/v1/service-AuthService_connectquery.ts +70 -0
  110. package/gen/src/proto/auth/v1/service.pb.go +119 -0
  111. package/gen/src/proto/auth/v1/service_pb.ts +152 -0
  112. package/gen/src/proto/customers/v1/customersv1connect/service.connect.go +358 -0
  113. package/gen/src/proto/customers/v1/entities/address.pb.go +1073 -0
  114. package/gen/src/proto/customers/v1/entities/address_pb.ts +478 -0
  115. package/gen/src/proto/customers/v1/entities/profile.pb.go +633 -0
  116. package/gen/src/proto/customers/v1/entities/profile_pb.ts +252 -0
  117. package/gen/src/proto/customers/v1/service-CustomerService_connectquery.ts +50 -0
  118. package/gen/src/proto/customers/v1/service.pb.go +110 -0
  119. package/gen/src/proto/customers/v1/service_pb.ts +121 -0
  120. package/gen/src/proto/files/v1/entities/file.pb.go +669 -0
  121. package/gen/src/proto/files/v1/entities/file_pb.ts +265 -0
  122. package/gen/src/proto/files/v1/filesv1connect/service.connect.go +200 -0
  123. package/gen/src/proto/files/v1/service-FileService_connectquery.ts +25 -0
  124. package/gen/src/proto/files/v1/service.pb.go +85 -0
  125. package/gen/src/proto/files/v1/service_pb.ts +65 -0
  126. package/gen/src/proto/products/v1/entities/category.pb.go +744 -0
  127. package/gen/src/proto/products/v1/entities/category_pb.ts +318 -0
  128. package/gen/src/proto/products/v1/entities/collection.pb.go +528 -0
  129. package/gen/src/proto/products/v1/entities/collection_pb.ts +214 -0
  130. package/gen/src/proto/products/v1/entities/product/create.pb.go +453 -0
  131. package/gen/src/proto/products/v1/entities/product/create_pb.ts +199 -0
  132. package/gen/src/proto/products/v1/entities/product/option.pb.go +206 -0
  133. package/gen/src/proto/products/v1/entities/product/option_pb.ts +74 -0
  134. package/gen/src/proto/products/v1/entities/product/shared.pb.go +2890 -0
  135. package/gen/src/proto/products/v1/entities/product/shared_pb.ts +1317 -0
  136. package/gen/src/proto/products/v1/entities/product/update.pb.go +794 -0
  137. package/gen/src/proto/products/v1/entities/product/update_pb.ts +325 -0
  138. package/gen/src/proto/products/v1/entities/tag.pb.go +610 -0
  139. package/gen/src/proto/products/v1/entities/tag_pb.ts +233 -0
  140. package/gen/src/proto/products/v1/entities/taxonomy.pb.go +1352 -0
  141. package/gen/src/proto/products/v1/entities/taxonomy_pb.ts +606 -0
  142. package/gen/src/proto/products/v1/entities/type.pb.go +553 -0
  143. package/gen/src/proto/products/v1/entities/type_pb.ts +215 -0
  144. package/gen/src/proto/products/v1/entities/variant.pb.go +1474 -0
  145. package/gen/src/proto/products/v1/entities/variant_pb.ts +629 -0
  146. package/gen/src/proto/products/v1/productsv1connect/service.connect.go +1195 -0
  147. package/gen/src/proto/products/v1/service-ProductsService_connectquery.ts +199 -0
  148. package/gen/src/proto/products/v1/service.pb.go +250 -0
  149. package/gen/src/proto/products/v1/service_pb.ts +429 -0
  150. package/gen/src/proto/promotions/v1/entities/campaign.pb.go +1229 -0
  151. package/gen/src/proto/promotions/v1/entities/campaign_pb.ts +511 -0
  152. package/gen/src/proto/promotions/v1/promotionsv1connect/service.connect.go +289 -0
  153. package/gen/src/proto/promotions/v1/service-CampaignService_connectquery.ts +42 -0
  154. package/gen/src/proto/promotions/v1/service.pb.go +98 -0
  155. package/gen/src/proto/promotions/v1/service_pb.ts +95 -0
  156. package/gen/src/proto/stocknodes/v1/entities/stocknode.pb.go +1499 -0
  157. package/gen/src/proto/stocknodes/v1/entities/stocknode_pb.ts +655 -0
  158. package/gen/src/proto/stocknodes/v1/service-StockNodesService_connectquery.ts +41 -0
  159. package/gen/src/proto/stocknodes/v1/service.pb.go +98 -0
  160. package/gen/src/proto/stocknodes/v1/service_pb.ts +95 -0
  161. package/gen/src/proto/stocknodes/v1/stocknodesv1connect/service.connect.go +297 -0
  162. package/package.json +5 -2
  163. package/src/address.spec.ts +0 -662
  164. package/src/address.ts +0 -300
  165. package/src/auth.spec.ts +0 -771
  166. package/src/auth.ts +0 -168
  167. package/src/compressor/brotli.ts +0 -26
  168. package/src/index.ts +0 -5
  169. package/src/interceptors.spec.ts +0 -1343
  170. package/src/interceptors.ts +0 -224
  171. package/src/policies.spec.ts +0 -595
  172. package/src/policies.ts +0 -431
  173. package/src/products.spec.ts +0 -710
  174. package/src/products.ts +0 -112
  175. package/src/profile.spec.ts +0 -626
  176. package/src/profile.ts +0 -169
  177. package/src/proto/auth/v1/entities/auth.proto +0 -140
  178. package/src/proto/auth/v1/entities/policy.proto +0 -57
  179. package/src/proto/auth/v1/service.proto +0 -26
  180. package/src/proto/customers/v1/entities/address.proto +0 -101
  181. package/src/proto/customers/v1/entities/profile.proto +0 -118
  182. package/src/proto/customers/v1/service.proto +0 -36
  183. package/src/proto/files/v1/entities/file.proto +0 -62
  184. package/src/proto/files/v1/service.proto +0 -19
  185. package/src/proto/products/v1/entities/category.proto +0 -98
  186. package/src/proto/products/v1/entities/collection.proto +0 -72
  187. package/src/proto/products/v1/entities/product/create.proto +0 -41
  188. package/src/proto/products/v1/entities/product/option.proto +0 -17
  189. package/src/proto/products/v1/entities/product/shared.proto +0 -255
  190. package/src/proto/products/v1/entities/product/update.proto +0 -66
  191. package/src/proto/products/v1/entities/tag.proto +0 -73
  192. package/src/proto/products/v1/entities/taxonomy.proto +0 -146
  193. package/src/proto/products/v1/entities/type.proto +0 -98
  194. package/src/proto/products/v1/entities/variant.proto +0 -127
  195. package/src/proto/products/v1/service.proto +0 -78
  196. package/src/proto/promotions/v1/entities/campaign.proto +0 -145
  197. package/src/proto/promotions/v1/service.proto +0 -17
  198. package/src/proto/stocknodes/v1/entities/stocknode.proto +0 -167
  199. package/src/proto/stocknodes/v1/service.proto +0 -21
  200. package/src/registration.ts +0 -170
  201. package/src/test-utils.ts +0 -176
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.spec.d.ts","sourceRoot":"","sources":["../../src/auth.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,582 @@
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
+ });
@@ -0,0 +1,3 @@
1
+ import { type Compression } from '@connectrpc/connect/protocol';
2
+ export declare const brotliCompression: Compression;
3
+ //# sourceMappingURL=brotli.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1,6 @@
1
+ export * from './address';
2
+ export * from './auth';
3
+ export * from './policies';
4
+ export * from './profile';
5
+ export * from './registration';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { Message } from '@bufbuild/protobuf';
2
+ import { type Interceptor, type StreamRequest, type UnaryRequest } from '@connectrpc/connect';
3
+ import type { Checkout } from '@paakd/config';
4
+ export interface RequestLogger {
5
+ onRequestHeader?: (header: Headers) => void;
6
+ onRequestMessage?: (message: Message) => void;
7
+ onResponseHeader?: (header: Headers) => void;
8
+ onResponseMessage?: (message: Message) => void;
9
+ onResponseTrailer?: (trailer: Headers) => void;
10
+ onError?: (error: unknown) => void;
11
+ }
12
+ export declare function createLoggingInterceptor(reqLogger?: (request: UnaryRequest | StreamRequest) => RequestLogger): Interceptor;
13
+ export declare function createAuthenticationInterceptor(checkoutConfig: Checkout): Interceptor;
14
+ export declare function createCustomerAuthenticationInterceptor(jwtKey: string): Interceptor;
15
+ export declare function createHeadersInterceptor(headers: Record<string, string | null>): Interceptor;
16
+ //# sourceMappingURL=interceptors.d.ts.map
@@ -0,0 +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,GACb,WAAW,CAYb;AAsFD,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GACrC,WAAW,CA0Cb"}