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