@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.
- package/buf/validate/validate_pb.ts +5001 -0
- package/dist/gen/buf/validate/validate_pb.d.ts +4634 -0
- package/dist/gen/buf/validate/validate_pb.d.ts.map +1 -0
- package/dist/gen/buf/validate/validate_pb.js +414 -0
- package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts +268 -0
- package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/auth/v1/entities/auth_pb.js +120 -0
- package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts +235 -0
- package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/auth/v1/entities/policy_pb.js +98 -0
- package/dist/gen/src/proto/auth/v1/service_pb.d.ts +117 -0
- package/dist/gen/src/proto/auth/v1/service_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/auth/v1/service_pb.js +22 -0
- package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts +371 -0
- package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/customers/v1/entities/address_pb.js +84 -0
- package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts +189 -0
- package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/customers/v1/entities/profile_pb.js +70 -0
- package/dist/gen/src/proto/customers/v1/service_pb.d.ts +85 -0
- package/dist/gen/src/proto/customers/v1/service_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/customers/v1/service_pb.js +22 -0
- package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts +234 -0
- package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/category_pb.js +84 -0
- package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts +159 -0
- package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/collection_pb.js +70 -0
- package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts +146 -0
- package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/product/create_pb.js +32 -0
- package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts +50 -0
- package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/product/option_pb.js +32 -0
- package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts +1042 -0
- package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/product/shared_pb.js +258 -0
- package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts +236 -0
- package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/product/update_pb.js +88 -0
- package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts +175 -0
- package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/tag_pb.js +84 -0
- package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts +477 -0
- package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.js +235 -0
- package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts +158 -0
- package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/type_pb.js +70 -0
- package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts +489 -0
- package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/entities/variant_pb.js +147 -0
- package/dist/gen/src/proto/products/v1/service_pb.d.ts +316 -0
- package/dist/gen/src/proto/products/v1/service_pb.d.ts.map +1 -0
- package/dist/gen/src/proto/products/v1/service_pb.js +36 -0
- package/dist/src/address.d.ts +53 -0
- package/dist/src/address.d.ts.map +1 -0
- package/dist/src/address.js +233 -0
- package/dist/src/address.spec.d.ts +2 -0
- package/dist/src/address.spec.d.ts.map +1 -0
- package/dist/src/address.spec.js +488 -0
- package/dist/src/auth.d.ts +27 -0
- package/dist/src/auth.d.ts.map +1 -0
- package/dist/src/auth.js +155 -0
- package/dist/src/auth.spec.d.ts +2 -0
- package/dist/src/auth.spec.d.ts.map +1 -0
- package/dist/src/auth.spec.js +582 -0
- package/dist/src/compressor/brotli.d.ts +3 -0
- package/dist/src/compressor/brotli.d.ts.map +1 -0
- package/dist/src/compressor/brotli.js +30 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/interceptors.d.ts +16 -0
- package/dist/src/interceptors.d.ts.map +1 -0
- package/dist/src/interceptors.js +156 -0
- package/dist/src/interceptors.spec.d.ts +2 -0
- package/dist/src/interceptors.spec.d.ts.map +1 -0
- package/dist/src/interceptors.spec.js +1063 -0
- package/dist/src/policies.d.ts +217 -0
- package/dist/src/policies.d.ts.map +1 -0
- package/dist/src/policies.js +322 -0
- package/dist/src/policies.spec.d.ts +2 -0
- package/dist/src/policies.spec.d.ts.map +1 -0
- package/dist/src/policies.spec.js +463 -0
- package/dist/src/products.d.ts +39 -0
- package/dist/src/products.d.ts.map +1 -0
- package/dist/src/products.js +95 -0
- package/dist/src/products.spec.d.ts +2 -0
- package/dist/src/products.spec.d.ts.map +1 -0
- package/dist/src/products.spec.js +519 -0
- package/dist/src/profile.d.ts +62 -0
- package/dist/src/profile.d.ts.map +1 -0
- package/dist/src/profile.js +151 -0
- package/dist/src/profile.spec.d.ts +2 -0
- package/dist/src/profile.spec.d.ts.map +1 -0
- package/dist/src/profile.spec.js +475 -0
- package/dist/src/registration.d.ts +60 -0
- package/dist/src/registration.d.ts.map +1 -0
- package/dist/src/registration.js +147 -0
- package/dist/src/test-utils.d.ts +87 -0
- package/dist/src/test-utils.d.ts.map +1 -0
- package/dist/src/test-utils.js +132 -0
- package/gen/buf/validate/validate_pb.ts +4799 -0
- package/gen/src/proto/auth/v1/authv1connect/service.connect.go +454 -0
- package/gen/src/proto/auth/v1/entities/auth.pb.go +818 -0
- package/gen/src/proto/auth/v1/entities/auth_pb.ts +348 -0
- package/gen/src/proto/auth/v1/entities/policy.pb.go +727 -0
- package/gen/src/proto/auth/v1/entities/policy_pb.ts +306 -0
- package/gen/src/proto/auth/v1/service-AuthService_connectquery.ts +70 -0
- package/gen/src/proto/auth/v1/service.pb.go +119 -0
- package/gen/src/proto/auth/v1/service_pb.ts +152 -0
- package/gen/src/proto/customers/v1/customersv1connect/service.connect.go +358 -0
- package/gen/src/proto/customers/v1/entities/address.pb.go +1073 -0
- package/gen/src/proto/customers/v1/entities/address_pb.ts +478 -0
- package/gen/src/proto/customers/v1/entities/profile.pb.go +633 -0
- package/gen/src/proto/customers/v1/entities/profile_pb.ts +252 -0
- package/gen/src/proto/customers/v1/service-CustomerService_connectquery.ts +50 -0
- package/gen/src/proto/customers/v1/service.pb.go +110 -0
- package/gen/src/proto/customers/v1/service_pb.ts +121 -0
- package/gen/src/proto/files/v1/entities/file.pb.go +669 -0
- package/gen/src/proto/files/v1/entities/file_pb.ts +265 -0
- package/gen/src/proto/files/v1/filesv1connect/service.connect.go +200 -0
- package/gen/src/proto/files/v1/service-FileService_connectquery.ts +25 -0
- package/gen/src/proto/files/v1/service.pb.go +85 -0
- package/gen/src/proto/files/v1/service_pb.ts +65 -0
- package/gen/src/proto/products/v1/entities/category.pb.go +744 -0
- package/gen/src/proto/products/v1/entities/category_pb.ts +318 -0
- package/gen/src/proto/products/v1/entities/collection.pb.go +528 -0
- package/gen/src/proto/products/v1/entities/collection_pb.ts +214 -0
- package/gen/src/proto/products/v1/entities/product/create.pb.go +453 -0
- package/gen/src/proto/products/v1/entities/product/create_pb.ts +199 -0
- package/gen/src/proto/products/v1/entities/product/option.pb.go +206 -0
- package/gen/src/proto/products/v1/entities/product/option_pb.ts +74 -0
- package/gen/src/proto/products/v1/entities/product/shared.pb.go +2890 -0
- package/gen/src/proto/products/v1/entities/product/shared_pb.ts +1317 -0
- package/gen/src/proto/products/v1/entities/product/update.pb.go +794 -0
- package/gen/src/proto/products/v1/entities/product/update_pb.ts +325 -0
- package/gen/src/proto/products/v1/entities/tag.pb.go +610 -0
- package/gen/src/proto/products/v1/entities/tag_pb.ts +233 -0
- package/gen/src/proto/products/v1/entities/taxonomy.pb.go +1352 -0
- package/gen/src/proto/products/v1/entities/taxonomy_pb.ts +606 -0
- package/gen/src/proto/products/v1/entities/type.pb.go +553 -0
- package/gen/src/proto/products/v1/entities/type_pb.ts +215 -0
- package/gen/src/proto/products/v1/entities/variant.pb.go +1474 -0
- package/gen/src/proto/products/v1/entities/variant_pb.ts +629 -0
- package/gen/src/proto/products/v1/productsv1connect/service.connect.go +1195 -0
- package/gen/src/proto/products/v1/service-ProductsService_connectquery.ts +199 -0
- package/gen/src/proto/products/v1/service.pb.go +250 -0
- package/gen/src/proto/products/v1/service_pb.ts +429 -0
- package/gen/src/proto/promotions/v1/entities/campaign.pb.go +1229 -0
- package/gen/src/proto/promotions/v1/entities/campaign_pb.ts +511 -0
- package/gen/src/proto/promotions/v1/promotionsv1connect/service.connect.go +289 -0
- package/gen/src/proto/promotions/v1/service-CampaignService_connectquery.ts +42 -0
- package/gen/src/proto/promotions/v1/service.pb.go +98 -0
- package/gen/src/proto/promotions/v1/service_pb.ts +95 -0
- package/gen/src/proto/stocknodes/v1/entities/stocknode.pb.go +1499 -0
- package/gen/src/proto/stocknodes/v1/entities/stocknode_pb.ts +655 -0
- package/gen/src/proto/stocknodes/v1/service-StockNodesService_connectquery.ts +41 -0
- package/gen/src/proto/stocknodes/v1/service.pb.go +98 -0
- package/gen/src/proto/stocknodes/v1/service_pb.ts +95 -0
- package/gen/src/proto/stocknodes/v1/stocknodesv1connect/service.connect.go +297 -0
- package/package.json +5 -2
- package/src/address.spec.ts +0 -662
- package/src/address.ts +0 -300
- package/src/auth.spec.ts +0 -771
- package/src/auth.ts +0 -168
- package/src/compressor/brotli.ts +0 -26
- package/src/index.ts +0 -5
- package/src/interceptors.spec.ts +0 -1343
- package/src/interceptors.ts +0 -224
- package/src/policies.spec.ts +0 -595
- package/src/policies.ts +0 -431
- package/src/products.spec.ts +0 -710
- package/src/products.ts +0 -112
- package/src/profile.spec.ts +0 -626
- package/src/profile.ts +0 -169
- package/src/proto/auth/v1/entities/auth.proto +0 -140
- package/src/proto/auth/v1/entities/policy.proto +0 -57
- package/src/proto/auth/v1/service.proto +0 -26
- package/src/proto/customers/v1/entities/address.proto +0 -101
- package/src/proto/customers/v1/entities/profile.proto +0 -118
- package/src/proto/customers/v1/service.proto +0 -36
- package/src/proto/files/v1/entities/file.proto +0 -62
- package/src/proto/files/v1/service.proto +0 -19
- package/src/proto/products/v1/entities/category.proto +0 -98
- package/src/proto/products/v1/entities/collection.proto +0 -72
- package/src/proto/products/v1/entities/product/create.proto +0 -41
- package/src/proto/products/v1/entities/product/option.proto +0 -17
- package/src/proto/products/v1/entities/product/shared.proto +0 -255
- package/src/proto/products/v1/entities/product/update.proto +0 -66
- package/src/proto/products/v1/entities/tag.proto +0 -73
- package/src/proto/products/v1/entities/taxonomy.proto +0 -146
- package/src/proto/products/v1/entities/type.proto +0 -98
- package/src/proto/products/v1/entities/variant.proto +0 -127
- package/src/proto/products/v1/service.proto +0 -78
- package/src/proto/promotions/v1/entities/campaign.proto +0 -145
- package/src/proto/promotions/v1/service.proto +0 -17
- package/src/proto/stocknodes/v1/entities/stocknode.proto +0 -167
- package/src/proto/stocknodes/v1/service.proto +0 -21
- package/src/registration.ts +0 -170
- package/src/test-utils.ts +0 -176
|
@@ -0,0 +1,463 @@
|
|
|
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 interceptors_1 = require("./interceptors");
|
|
16
|
+
const policies_1 = require("./policies");
|
|
17
|
+
// Mock dependencies
|
|
18
|
+
vi.mock('@connectrpc/connect', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const actual = yield vi.importActual('@connectrpc/connect');
|
|
20
|
+
return Object.assign(Object.assign({}, actual), { createClient: vi.fn() });
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('./compressor/brotli', () => ({
|
|
23
|
+
brotliCompression: {
|
|
24
|
+
name: 'brotli',
|
|
25
|
+
compress: vi.fn(),
|
|
26
|
+
decompress: vi.fn(),
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
vi.mock('@connectrpc/connect-node', () => ({
|
|
30
|
+
createGrpcTransport: vi.fn(),
|
|
31
|
+
}));
|
|
32
|
+
vi.mock('@paakd/config', () => ({
|
|
33
|
+
getCheckoutConfig: vi.fn(),
|
|
34
|
+
}));
|
|
35
|
+
vi.mock('./interceptors', () => ({
|
|
36
|
+
createAuthenticationInterceptor: vi.fn(),
|
|
37
|
+
createHeadersInterceptor: vi.fn().mockReturnValue(() => { }),
|
|
38
|
+
}));
|
|
39
|
+
vi.mock('../gen/src/proto/auth/v1/service_pb', () => ({
|
|
40
|
+
AuthService: {},
|
|
41
|
+
}));
|
|
42
|
+
const mockGetCheckoutConfig = vi.mocked(config_1.getCheckoutConfig);
|
|
43
|
+
const mockCreateGrpcTransport = vi.mocked(connect_node_1.createGrpcTransport);
|
|
44
|
+
const mockCreateClient = vi.mocked(connect_1.createClient);
|
|
45
|
+
const mockCreateAuthenticationInterceptor = vi.mocked(interceptors_1.createAuthenticationInterceptor);
|
|
46
|
+
const mockCreateHeadersInterceptor = vi.mocked(interceptors_1.createHeadersInterceptor);
|
|
47
|
+
describe('policies', () => {
|
|
48
|
+
let mockAuthClient;
|
|
49
|
+
let mockTransport;
|
|
50
|
+
let mockCheckoutConfig;
|
|
51
|
+
let mockInterceptor;
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
// Reset all mocks
|
|
54
|
+
vi.clearAllMocks();
|
|
55
|
+
// Setup mock objects
|
|
56
|
+
mockAuthClient = {
|
|
57
|
+
getPolicies: vi.fn(),
|
|
58
|
+
savePolicies: vi.fn(),
|
|
59
|
+
addPolicy: vi.fn(),
|
|
60
|
+
addPolicies: vi.fn(),
|
|
61
|
+
removePolicy: vi.fn(),
|
|
62
|
+
removePolicies: vi.fn(),
|
|
63
|
+
removeFilteredPolicy: vi.fn(),
|
|
64
|
+
getFilteredPolicy: vi.fn(),
|
|
65
|
+
};
|
|
66
|
+
mockTransport = {};
|
|
67
|
+
mockCheckoutConfig = {
|
|
68
|
+
enterpriseURL: 'https://enterprise.example.com',
|
|
69
|
+
};
|
|
70
|
+
mockInterceptor = {};
|
|
71
|
+
// Setup mock implementations
|
|
72
|
+
mockGetCheckoutConfig.mockResolvedValue(mockCheckoutConfig);
|
|
73
|
+
mockCreateGrpcTransport.mockReturnValue(mockTransport);
|
|
74
|
+
mockCreateAuthenticationInterceptor.mockReturnValue(mockInterceptor);
|
|
75
|
+
mockCreateHeadersInterceptor.mockReturnValue(mockInterceptor);
|
|
76
|
+
mockCreateClient.mockReturnValue(mockAuthClient);
|
|
77
|
+
});
|
|
78
|
+
describe('getPolicies', () => {
|
|
79
|
+
it('should return policies on success', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const mockPolicies = [
|
|
81
|
+
{ pType: 'p', v0: 'alice', v1: 'data1', v2: 'read' },
|
|
82
|
+
{ pType: 'p', v0: 'bob', v1: 'data2', v2: 'write' },
|
|
83
|
+
];
|
|
84
|
+
mockAuthClient.getPolicies.mockResolvedValue({
|
|
85
|
+
policies: mockPolicies,
|
|
86
|
+
});
|
|
87
|
+
const result = yield (0, policies_1.getPolicies)({
|
|
88
|
+
headers: {},
|
|
89
|
+
});
|
|
90
|
+
expect(config_1.getCheckoutConfig).toHaveBeenCalled();
|
|
91
|
+
expect(connect_node_1.createGrpcTransport).toHaveBeenCalledWith({
|
|
92
|
+
baseUrl: mockCheckoutConfig.enterpriseURL,
|
|
93
|
+
interceptors: [mockInterceptor, mockInterceptor],
|
|
94
|
+
acceptCompression: expect.any(Array), // Accept gzip and Brotli compression
|
|
95
|
+
sendCompression: expect.any(Object), // Send Brotli compression
|
|
96
|
+
});
|
|
97
|
+
expect(connect_1.createClient).toHaveBeenCalledWith({}, mockTransport);
|
|
98
|
+
expect(mockAuthClient.getPolicies).toHaveBeenCalledWith({});
|
|
99
|
+
expect(result).toEqual({
|
|
100
|
+
value: mockPolicies,
|
|
101
|
+
status: 'success',
|
|
102
|
+
});
|
|
103
|
+
}));
|
|
104
|
+
it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const connectError = {
|
|
106
|
+
code: connect_1.Code.Unauthenticated,
|
|
107
|
+
rawMessage: 'Invalid credentials',
|
|
108
|
+
message: 'Authentication failed',
|
|
109
|
+
name: 'ConnectError',
|
|
110
|
+
};
|
|
111
|
+
// Make it pass instanceof check
|
|
112
|
+
Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
|
|
113
|
+
mockAuthClient.getPolicies.mockRejectedValue(connectError);
|
|
114
|
+
const result = yield (0, policies_1.getPolicies)({
|
|
115
|
+
headers: {},
|
|
116
|
+
});
|
|
117
|
+
expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid credentials', status: 'failed' }));
|
|
118
|
+
}));
|
|
119
|
+
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
const unexpectedError = new Error('Network error');
|
|
121
|
+
mockAuthClient.getPolicies.mockRejectedValue(unexpectedError);
|
|
122
|
+
const result = yield (0, policies_1.getPolicies)({
|
|
123
|
+
headers: {},
|
|
124
|
+
});
|
|
125
|
+
expect(result).toEqual({
|
|
126
|
+
code: connect_1.Code.Internal,
|
|
127
|
+
rawMessage: 'An unexpected error occurred during login.',
|
|
128
|
+
message: 'An unexpected error occurred during login.',
|
|
129
|
+
status: 'failed',
|
|
130
|
+
});
|
|
131
|
+
}));
|
|
132
|
+
});
|
|
133
|
+
describe('savePolicies', () => {
|
|
134
|
+
it('should save policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const inputPolicies = [
|
|
136
|
+
['p', 'alice', 'data1', 'read'],
|
|
137
|
+
['p', 'bob', 'data2', 'write'],
|
|
138
|
+
];
|
|
139
|
+
mockAuthClient.savePolicies.mockResolvedValue({});
|
|
140
|
+
const result = yield (0, policies_1.savePolicies)({
|
|
141
|
+
headers: {},
|
|
142
|
+
body: { inPolicies: inputPolicies },
|
|
143
|
+
});
|
|
144
|
+
expect(mockAuthClient.savePolicies).toHaveBeenCalledWith({
|
|
145
|
+
policies: [
|
|
146
|
+
{
|
|
147
|
+
pType: 'p',
|
|
148
|
+
v0: 'alice',
|
|
149
|
+
v1: 'data1',
|
|
150
|
+
v2: 'read',
|
|
151
|
+
v3: '',
|
|
152
|
+
v4: '',
|
|
153
|
+
v5: '',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
pType: 'p',
|
|
157
|
+
v0: 'bob',
|
|
158
|
+
v1: 'data2',
|
|
159
|
+
v2: 'write',
|
|
160
|
+
v3: '',
|
|
161
|
+
v4: '',
|
|
162
|
+
v5: '',
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
expect(result).toEqual({ status: 'success' });
|
|
167
|
+
}));
|
|
168
|
+
it('should handle policies with different lengths', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
const inputPolicies = [
|
|
170
|
+
['p', 'alice'],
|
|
171
|
+
['p', 'bob', 'data2', 'write', 'extra1', 'extra2', 'extra3', 'extra4'],
|
|
172
|
+
];
|
|
173
|
+
mockAuthClient.savePolicies.mockResolvedValue({});
|
|
174
|
+
const result = yield (0, policies_1.savePolicies)({
|
|
175
|
+
headers: {},
|
|
176
|
+
body: { inPolicies: inputPolicies },
|
|
177
|
+
});
|
|
178
|
+
expect(mockAuthClient.savePolicies).toHaveBeenCalledWith({
|
|
179
|
+
policies: [
|
|
180
|
+
{ pType: 'p', v0: 'alice', v1: '', v2: '', v3: '', v4: '', v5: '' },
|
|
181
|
+
{
|
|
182
|
+
pType: 'p',
|
|
183
|
+
v0: 'bob',
|
|
184
|
+
v1: 'data2',
|
|
185
|
+
v2: 'write',
|
|
186
|
+
v3: 'extra1',
|
|
187
|
+
v4: 'extra2',
|
|
188
|
+
v5: 'extra3',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
expect(result).toEqual({ status: 'success' });
|
|
193
|
+
}));
|
|
194
|
+
it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
|
+
const connectError = {
|
|
196
|
+
code: connect_1.Code.Internal,
|
|
197
|
+
rawMessage: 'Database error',
|
|
198
|
+
message: 'Save failed',
|
|
199
|
+
name: 'ConnectError',
|
|
200
|
+
};
|
|
201
|
+
// Make it pass instanceof check
|
|
202
|
+
Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
|
|
203
|
+
mockAuthClient.savePolicies.mockRejectedValue(connectError);
|
|
204
|
+
const result = yield (0, policies_1.savePolicies)({
|
|
205
|
+
headers: {},
|
|
206
|
+
body: { inPolicies: [['p', 'alice']] },
|
|
207
|
+
});
|
|
208
|
+
expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Database error', status: 'failed' }));
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
describe('addPolicy', () => {
|
|
212
|
+
it('should add policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
|
+
const rule = ['alice', 'data1', 'read'];
|
|
214
|
+
const pType = 'p';
|
|
215
|
+
mockAuthClient.addPolicy.mockResolvedValue({});
|
|
216
|
+
const result = yield (0, policies_1.addPolicy)({
|
|
217
|
+
headers: {},
|
|
218
|
+
body: { rule, pType },
|
|
219
|
+
});
|
|
220
|
+
expect(mockAuthClient.addPolicy).toHaveBeenCalledWith({ rule, pType });
|
|
221
|
+
expect(result).toEqual({ status: 'success' });
|
|
222
|
+
}));
|
|
223
|
+
it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
const connectError = {
|
|
225
|
+
code: connect_1.Code.InvalidArgument,
|
|
226
|
+
rawMessage: 'Invalid policy format',
|
|
227
|
+
message: 'Add failed',
|
|
228
|
+
name: 'ConnectError',
|
|
229
|
+
};
|
|
230
|
+
// Make it pass instanceof check
|
|
231
|
+
Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
|
|
232
|
+
mockAuthClient.addPolicy.mockRejectedValue(connectError);
|
|
233
|
+
const result = yield (0, policies_1.addPolicy)({
|
|
234
|
+
headers: {},
|
|
235
|
+
body: { rule: ['alice'], pType: 'p' },
|
|
236
|
+
});
|
|
237
|
+
expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid policy format', status: 'failed' }));
|
|
238
|
+
}));
|
|
239
|
+
});
|
|
240
|
+
describe('addPolicies', () => {
|
|
241
|
+
it('should add multiple policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
+
const rules = [
|
|
243
|
+
['alice', 'data1', 'read'],
|
|
244
|
+
['bob', 'data2', 'write'],
|
|
245
|
+
];
|
|
246
|
+
const pType = 'p';
|
|
247
|
+
mockAuthClient.addPolicies.mockResolvedValue({});
|
|
248
|
+
const result = yield (0, policies_1.addPolicies)({
|
|
249
|
+
headers: {},
|
|
250
|
+
body: { inRules: rules, pType },
|
|
251
|
+
});
|
|
252
|
+
expect(mockAuthClient.addPolicies).toHaveBeenCalledWith({
|
|
253
|
+
rules: [
|
|
254
|
+
{ rules: ['alice', 'data1', 'read'] },
|
|
255
|
+
{ rules: ['bob', 'data2', 'write'] },
|
|
256
|
+
],
|
|
257
|
+
pType,
|
|
258
|
+
});
|
|
259
|
+
expect(result).toEqual({ status: 'success' });
|
|
260
|
+
}));
|
|
261
|
+
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
const unexpectedError = new Error('Network timeout');
|
|
263
|
+
mockAuthClient.addPolicies.mockRejectedValue(unexpectedError);
|
|
264
|
+
const result = yield (0, policies_1.addPolicies)({
|
|
265
|
+
headers: {},
|
|
266
|
+
body: { inRules: [['alice']], pType: 'p' },
|
|
267
|
+
});
|
|
268
|
+
expect(result).toEqual({
|
|
269
|
+
code: connect_1.Code.Internal,
|
|
270
|
+
rawMessage: 'An unexpected error occurred while adding policies.',
|
|
271
|
+
message: 'An unexpected error occurred while adding policies.',
|
|
272
|
+
status: 'failed',
|
|
273
|
+
});
|
|
274
|
+
}));
|
|
275
|
+
});
|
|
276
|
+
describe('removePolicy', () => {
|
|
277
|
+
it('should remove policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
+
const rule = ['alice', 'data1', 'read'];
|
|
279
|
+
const pType = 'p';
|
|
280
|
+
mockAuthClient.removePolicy.mockResolvedValue({});
|
|
281
|
+
const result = yield (0, policies_1.removePolicy)({
|
|
282
|
+
headers: {},
|
|
283
|
+
body: { rule, pType },
|
|
284
|
+
});
|
|
285
|
+
expect(mockAuthClient.removePolicy).toHaveBeenCalledWith({ rule, pType });
|
|
286
|
+
expect(result).toEqual({ status: 'success' });
|
|
287
|
+
}));
|
|
288
|
+
it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
289
|
+
const connectError = {
|
|
290
|
+
code: connect_1.Code.NotFound,
|
|
291
|
+
rawMessage: 'Policy not found',
|
|
292
|
+
message: 'Remove failed',
|
|
293
|
+
name: 'ConnectError',
|
|
294
|
+
};
|
|
295
|
+
// Make it pass instanceof check
|
|
296
|
+
Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
|
|
297
|
+
mockAuthClient.removePolicy.mockRejectedValue(connectError);
|
|
298
|
+
const result = yield (0, policies_1.removePolicy)({
|
|
299
|
+
headers: {},
|
|
300
|
+
body: { rule: ['alice'], pType: 'p' },
|
|
301
|
+
});
|
|
302
|
+
expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Policy not found', status: 'failed' }));
|
|
303
|
+
}));
|
|
304
|
+
});
|
|
305
|
+
describe('removePolicies', () => {
|
|
306
|
+
it('should remove multiple policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
const rules = [
|
|
308
|
+
['alice', 'data1', 'read'],
|
|
309
|
+
['bob', 'data2', 'write'],
|
|
310
|
+
];
|
|
311
|
+
const pType = 'p';
|
|
312
|
+
mockAuthClient.removePolicies.mockResolvedValue({});
|
|
313
|
+
const result = yield (0, policies_1.removePolicies)({
|
|
314
|
+
headers: {},
|
|
315
|
+
body: { inRules: rules, pType },
|
|
316
|
+
});
|
|
317
|
+
expect(mockAuthClient.removePolicies).toHaveBeenCalledWith({
|
|
318
|
+
rules: [
|
|
319
|
+
{ rules: ['alice', 'data1', 'read'] },
|
|
320
|
+
{ rules: ['bob', 'data2', 'write'] },
|
|
321
|
+
],
|
|
322
|
+
pType,
|
|
323
|
+
});
|
|
324
|
+
expect(result).toEqual({ status: 'success' });
|
|
325
|
+
}));
|
|
326
|
+
});
|
|
327
|
+
describe('removeFilteredPolicy', () => {
|
|
328
|
+
it('should remove filtered policy successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
|
+
const pType = 'p';
|
|
330
|
+
const fieldIndex = 0;
|
|
331
|
+
const fieldValues = ['alice'];
|
|
332
|
+
mockAuthClient.removeFilteredPolicy.mockResolvedValue({});
|
|
333
|
+
const result = yield (0, policies_1.removeFilteredPolicy)({
|
|
334
|
+
headers: {},
|
|
335
|
+
body: { pType, fieldIndex, fieldValues },
|
|
336
|
+
});
|
|
337
|
+
expect(mockAuthClient.removeFilteredPolicy).toHaveBeenCalledWith({
|
|
338
|
+
pType,
|
|
339
|
+
fieldIndex,
|
|
340
|
+
fieldValues,
|
|
341
|
+
});
|
|
342
|
+
expect(result).toEqual({ status: 'success' });
|
|
343
|
+
}));
|
|
344
|
+
it('should handle ConnectError', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
345
|
+
const connectError = {
|
|
346
|
+
code: connect_1.Code.InvalidArgument,
|
|
347
|
+
rawMessage: 'Invalid filter criteria',
|
|
348
|
+
message: 'Filter failed',
|
|
349
|
+
name: 'ConnectError',
|
|
350
|
+
};
|
|
351
|
+
// Make it pass instanceof check
|
|
352
|
+
Object.setPrototypeOf(connectError, connect_1.ConnectError.prototype);
|
|
353
|
+
mockAuthClient.removeFilteredPolicy.mockRejectedValue(connectError);
|
|
354
|
+
const result = yield (0, policies_1.removeFilteredPolicy)({
|
|
355
|
+
headers: {},
|
|
356
|
+
body: { pType: 'p', fieldIndex: 0, fieldValues: ['alice'] },
|
|
357
|
+
});
|
|
358
|
+
expect(result).toEqual(Object.assign(Object.assign({}, connectError), { message: 'Invalid filter criteria', status: 'failed' }));
|
|
359
|
+
}));
|
|
360
|
+
});
|
|
361
|
+
describe('getFilteredPolicy', () => {
|
|
362
|
+
it('should get filtered policies successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
363
|
+
const filter = {
|
|
364
|
+
v0: [['alice'], ['bob']],
|
|
365
|
+
v1: [['data1']],
|
|
366
|
+
};
|
|
367
|
+
const mockPolicies = [
|
|
368
|
+
{ pType: 'p', v0: 'alice', v1: 'data1', v2: 'read' },
|
|
369
|
+
];
|
|
370
|
+
mockAuthClient.getFilteredPolicy.mockResolvedValue({
|
|
371
|
+
policies: mockPolicies,
|
|
372
|
+
});
|
|
373
|
+
const result = yield (0, policies_1.getFilteredPolicy)({
|
|
374
|
+
headers: {},
|
|
375
|
+
body: { inFilter: filter },
|
|
376
|
+
});
|
|
377
|
+
expect(mockAuthClient.getFilteredPolicy).toHaveBeenCalledWith({
|
|
378
|
+
filter: [
|
|
379
|
+
{
|
|
380
|
+
key: 'v0',
|
|
381
|
+
values: [{ items: ['alice'] }, { items: ['bob'] }],
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
key: 'v1',
|
|
385
|
+
values: [{ items: ['data1'] }],
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
});
|
|
389
|
+
expect(result).toEqual({
|
|
390
|
+
value: mockPolicies,
|
|
391
|
+
status: 'success',
|
|
392
|
+
});
|
|
393
|
+
}));
|
|
394
|
+
it('should handle empty filter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
395
|
+
const filter = {};
|
|
396
|
+
mockAuthClient.getFilteredPolicy.mockResolvedValue({
|
|
397
|
+
policies: [],
|
|
398
|
+
});
|
|
399
|
+
const result = yield (0, policies_1.getFilteredPolicy)({
|
|
400
|
+
headers: {},
|
|
401
|
+
body: { inFilter: filter },
|
|
402
|
+
});
|
|
403
|
+
expect(mockAuthClient.getFilteredPolicy).toHaveBeenCalledWith({
|
|
404
|
+
filter: [],
|
|
405
|
+
});
|
|
406
|
+
expect(result).toEqual({
|
|
407
|
+
value: [],
|
|
408
|
+
status: 'success',
|
|
409
|
+
});
|
|
410
|
+
}));
|
|
411
|
+
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
412
|
+
const unexpectedError = new Error('Database connection failed');
|
|
413
|
+
mockAuthClient.getFilteredPolicy.mockRejectedValue(unexpectedError);
|
|
414
|
+
const result = yield (0, policies_1.getFilteredPolicy)({
|
|
415
|
+
headers: {},
|
|
416
|
+
body: { inFilter: {} },
|
|
417
|
+
});
|
|
418
|
+
expect(result).toEqual({
|
|
419
|
+
code: connect_1.Code.Internal,
|
|
420
|
+
rawMessage: 'An unexpected error occurred while fetching policies.',
|
|
421
|
+
message: 'An unexpected error occurred while fetching policies.',
|
|
422
|
+
status: 'failed',
|
|
423
|
+
});
|
|
424
|
+
}));
|
|
425
|
+
});
|
|
426
|
+
describe('common functionality', () => {
|
|
427
|
+
it('should setup transport and client consistently across all functions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
428
|
+
// Test one function to verify the setup pattern
|
|
429
|
+
yield (0, policies_1.getPolicies)({
|
|
430
|
+
headers: {},
|
|
431
|
+
});
|
|
432
|
+
expect(config_1.getCheckoutConfig).toHaveBeenCalled();
|
|
433
|
+
expect(interceptors_1.createAuthenticationInterceptor).toHaveBeenCalledWith(mockCheckoutConfig);
|
|
434
|
+
expect(connect_node_1.createGrpcTransport).toHaveBeenCalledWith({
|
|
435
|
+
baseUrl: mockCheckoutConfig.enterpriseURL,
|
|
436
|
+
interceptors: [mockInterceptor, mockInterceptor],
|
|
437
|
+
acceptCompression: expect.any(Array), // Accept gzip and Brotli compression
|
|
438
|
+
sendCompression: expect.any(Object), // Send Brotli compression
|
|
439
|
+
});
|
|
440
|
+
expect(connect_1.createClient).toHaveBeenCalledWith({}, mockTransport);
|
|
441
|
+
}));
|
|
442
|
+
it('should use consistent timeout across all functions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
443
|
+
mockAuthClient.getPolicies.mockResolvedValue({ policies: [] });
|
|
444
|
+
mockAuthClient.addPolicy.mockResolvedValue({});
|
|
445
|
+
mockAuthClient.removePolicy.mockResolvedValue({});
|
|
446
|
+
yield (0, policies_1.getPolicies)({
|
|
447
|
+
headers: {},
|
|
448
|
+
});
|
|
449
|
+
yield (0, policies_1.addPolicy)({
|
|
450
|
+
headers: {},
|
|
451
|
+
body: { rule: ['alice'], pType: 'p' },
|
|
452
|
+
});
|
|
453
|
+
yield (0, policies_1.removePolicy)({
|
|
454
|
+
headers: {},
|
|
455
|
+
body: { rule: ['bob'], pType: 'p' },
|
|
456
|
+
});
|
|
457
|
+
// Verify all calls use the same timeout
|
|
458
|
+
expect(mockAuthClient.getPolicies).toHaveBeenCalledWith({});
|
|
459
|
+
expect(mockAuthClient.addPolicy).toHaveBeenCalledWith(expect.any(Object));
|
|
460
|
+
expect(mockAuthClient.removePolicy).toHaveBeenCalledWith(expect.any(Object));
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Code, ConnectError } from '@connectrpc/connect';
|
|
2
|
+
import type { CreateCollectionRequest } from '../gen/src/proto/products/v1/entities/collection_pb';
|
|
3
|
+
export interface GetCollectionByIDProps {
|
|
4
|
+
body: {
|
|
5
|
+
collectionId: string;
|
|
6
|
+
};
|
|
7
|
+
headers: Record<string, string | null>;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateCollectionProps {
|
|
10
|
+
body: Omit<CreateCollectionRequest, '$typeName'>;
|
|
11
|
+
headers: Record<string, string | null>;
|
|
12
|
+
}
|
|
13
|
+
export declare function getCollectionByID({ body: { collectionId }, headers, }: GetCollectionByIDProps): Promise<ConnectError | {
|
|
14
|
+
value: import("../gen/src/proto/products/v1/entities/collection_pb").GetCollectionByIDResponse;
|
|
15
|
+
status: string;
|
|
16
|
+
code?: undefined;
|
|
17
|
+
rawMessage?: undefined;
|
|
18
|
+
message?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
code: Code;
|
|
21
|
+
rawMessage: string;
|
|
22
|
+
message: string;
|
|
23
|
+
status: string;
|
|
24
|
+
value?: undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function createCollection({ body, headers, }: CreateCollectionProps): Promise<ConnectError | {
|
|
27
|
+
value: import("../gen/src/proto/products/v1/entities/collection_pb").CreateCollectionResponse;
|
|
28
|
+
status: string;
|
|
29
|
+
code?: undefined;
|
|
30
|
+
rawMessage?: undefined;
|
|
31
|
+
message?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
code: Code;
|
|
34
|
+
rawMessage: string;
|
|
35
|
+
message: string;
|
|
36
|
+
status: string;
|
|
37
|
+
value?: undefined;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=products.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"products.d.ts","sourceRoot":"","sources":["../../src/products.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAA;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qDAAqD,CAAA;AAOlG,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAA;IAChD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,wBAAsB,iBAAiB,CAAC,EACtC,IAAI,EAAE,EAAE,YAAY,EAAE,EACtB,OAAO,GACR,EAAE,sBAAsB;;;;;;;;;;;;GAyCxB;AAED,wBAAsB,gBAAgB,CAAC,EACrC,IAAI,EACJ,OAAO,GACR,EAAE,qBAAqB;;;;;;;;;;;;GAuCvB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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.getCollectionByID = getCollectionByID;
|
|
13
|
+
exports.createCollection = createCollection;
|
|
14
|
+
const connect_1 = require("@connectrpc/connect");
|
|
15
|
+
const connect_node_1 = require("@connectrpc/connect-node");
|
|
16
|
+
const config_1 = require("@paakd/config");
|
|
17
|
+
const service_pb_1 = require("../gen/src/proto/products/v1/service_pb");
|
|
18
|
+
const brotli_1 = require("./compressor/brotli");
|
|
19
|
+
const interceptors_1 = require("./interceptors");
|
|
20
|
+
function getCollectionByID(_a) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* ({ body: { collectionId }, headers, }) {
|
|
22
|
+
try {
|
|
23
|
+
const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
|
|
24
|
+
const productClient = (0, connect_1.createClient)(service_pb_1.ProductsService, (0, connect_node_1.createGrpcTransport)({
|
|
25
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
26
|
+
interceptors: [
|
|
27
|
+
(0, interceptors_1.createHeadersInterceptor)(headers),
|
|
28
|
+
(0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
|
|
29
|
+
],
|
|
30
|
+
acceptCompression: [brotli_1.brotliCompression],
|
|
31
|
+
sendCompression: brotli_1.brotliCompression,
|
|
32
|
+
}));
|
|
33
|
+
const value = yield productClient.getCollectionByID({
|
|
34
|
+
id: collectionId,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
value,
|
|
38
|
+
status: 'success',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof connect_1.ConnectError) {
|
|
43
|
+
return {
|
|
44
|
+
code: err.code,
|
|
45
|
+
rawMessage: err.rawMessage,
|
|
46
|
+
message: err.rawMessage,
|
|
47
|
+
status: 'failed',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
code: connect_1.Code.Internal,
|
|
52
|
+
rawMessage: 'An unexpected error occurred while fetching the collection.',
|
|
53
|
+
message: 'An unexpected error occurred while fetching the collection.',
|
|
54
|
+
status: 'failed',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function createCollection(_a) {
|
|
60
|
+
return __awaiter(this, arguments, void 0, function* ({ body, headers, }) {
|
|
61
|
+
try {
|
|
62
|
+
const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
|
|
63
|
+
const productClient = (0, connect_1.createClient)(service_pb_1.ProductsService, (0, connect_node_1.createGrpcTransport)({
|
|
64
|
+
baseUrl: checkoutConfig.enterpriseURL,
|
|
65
|
+
interceptors: [
|
|
66
|
+
(0, interceptors_1.createHeadersInterceptor)(headers),
|
|
67
|
+
(0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
|
|
68
|
+
],
|
|
69
|
+
acceptCompression: [brotli_1.brotliCompression],
|
|
70
|
+
sendCompression: brotli_1.brotliCompression,
|
|
71
|
+
}));
|
|
72
|
+
const value = yield productClient.createCollection(body);
|
|
73
|
+
return {
|
|
74
|
+
value,
|
|
75
|
+
status: 'success',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof connect_1.ConnectError) {
|
|
80
|
+
return {
|
|
81
|
+
code: err.code,
|
|
82
|
+
rawMessage: err.rawMessage,
|
|
83
|
+
message: err.rawMessage,
|
|
84
|
+
status: 'failed',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
code: connect_1.Code.Internal,
|
|
89
|
+
rawMessage: 'An unexpected error occurred while creating the collection.',
|
|
90
|
+
message: 'An unexpected error occurred while creating the collection.',
|
|
91
|
+
status: 'failed',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"products.spec.d.ts","sourceRoot":"","sources":["../../src/products.spec.ts"],"names":[],"mappings":""}
|