@compassdigital/sdk.typescript 4.122.0 → 4.124.0
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/.eslintrc.js +1 -69
- package/lib/base.d.ts +3 -1
- package/lib/base.d.ts.map +1 -1
- package/lib/base.js +13 -7
- package/lib/base.js.map +1 -1
- package/lib/index.d.ts +9 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/interface/discount.d.ts +19 -0
- package/lib/interface/discount.d.ts.map +1 -1
- package/manifest.json +30 -30
- package/package.json +9 -7
- package/prettier.config.js +4 -8
- package/src/base.ts +14 -6
- package/src/index.ts +15 -0
- package/src/interface/discount.ts +29 -0
- package/test/client.test.ts +15 -0
package/manifest.json
CHANGED
|
@@ -2,147 +2,147 @@
|
|
|
2
2
|
"services": [
|
|
3
3
|
{
|
|
4
4
|
"name": "payment",
|
|
5
|
-
"swagger": "../../platform2/payment/swagger.json"
|
|
5
|
+
"swagger": "../../api/platform2/payment/swagger.json"
|
|
6
6
|
},
|
|
7
7
|
{
|
|
8
8
|
"name": "order",
|
|
9
|
-
"swagger": "../../platform2/order/swagger.json"
|
|
9
|
+
"swagger": "../../api/platform2/order/swagger.json"
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"name": "location",
|
|
13
|
-
"swagger": "../../platform2/location/swagger.json"
|
|
13
|
+
"swagger": "../../api/platform2/location/swagger.json"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"name": "shoppingcart",
|
|
17
|
-
"swagger": "../../platform2/shoppingcart/swagger.json"
|
|
17
|
+
"swagger": "../../api/platform2/shoppingcart/swagger.json"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"name": "partner",
|
|
21
|
-
"swagger": "../../platform2/partner/swagger.json"
|
|
21
|
+
"swagger": "../../api/platform2/partner/swagger.json"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"name": "email",
|
|
25
|
-
"swagger": "../../platform2/email/swagger.json"
|
|
25
|
+
"swagger": "../../api/platform2/email/swagger.json"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"name": "task",
|
|
29
|
-
"swagger": "../../platform2/task/swagger.json"
|
|
29
|
+
"swagger": "../../api/platform2/task/swagger.json"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"name": "kds",
|
|
33
|
-
"swagger": "../../platform2/kds/swagger.json"
|
|
33
|
+
"swagger": "../../api/platform2/kds/swagger.json"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
"name": "mealplan",
|
|
37
|
-
"swagger": "../../platform2/mealplan/swagger.json"
|
|
37
|
+
"swagger": "../../api/platform2/mealplan/swagger.json"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"name": "datalake",
|
|
41
|
-
"swagger": "../../platform2/datalake/swagger.json"
|
|
41
|
+
"swagger": "../../api/platform2/datalake/swagger.json"
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
"name": "promo",
|
|
45
|
-
"swagger": "../../platform2/promo/swagger.json"
|
|
45
|
+
"swagger": "../../api/platform2/promo/swagger.json"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
"name": "config",
|
|
49
|
-
"swagger": "../../platform2/config/swagger.json"
|
|
49
|
+
"swagger": "../../api/platform2/config/swagger.json"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"name": "announcement",
|
|
53
|
-
"swagger": "../../platform2/announcement/swagger.json"
|
|
53
|
+
"swagger": "../../api/platform2/announcement/swagger.json"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"name": "report",
|
|
57
|
-
"swagger": "../../platform2/report/swagger.json"
|
|
57
|
+
"swagger": "../../api/platform2/report/swagger.json"
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"name": "user",
|
|
61
|
-
"swagger": "../../platform2/user/swagger.json"
|
|
61
|
+
"swagger": "../../api/platform2/user/swagger.json"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
"name": "calendar",
|
|
65
|
-
"swagger": "../../platform2/calendar/swagger.json"
|
|
65
|
+
"swagger": "../../api/platform2/calendar/swagger.json"
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
"name": "file",
|
|
69
|
-
"swagger": "../../platform2/file/swagger.json"
|
|
69
|
+
"swagger": "../../api/platform2/file/swagger.json"
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
"name": "menu",
|
|
73
|
-
"swagger": "../../platform2/menu/swagger.json"
|
|
73
|
+
"swagger": "../../api/platform2/menu/swagger.json"
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"name": "notification",
|
|
77
|
-
"swagger": "../../platform2/notification/swagger.json"
|
|
77
|
+
"swagger": "../../api/platform2/notification/swagger.json"
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
80
|
"name": "compassconnect",
|
|
81
|
-
"swagger": "../../platform2/compassconnect/swagger.json"
|
|
81
|
+
"swagger": "../../api/platform2/compassconnect/swagger.json"
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"name": "vendor",
|
|
85
|
-
"swagger": "../../platform2/vendor/swagger.json"
|
|
85
|
+
"swagger": "../../api/platform2/vendor/swagger.json"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
"name": "frictionless",
|
|
89
|
-
"swagger": "../../platform2/frictionless/swagger.json",
|
|
89
|
+
"swagger": "../../api/platform2/frictionless/swagger.json",
|
|
90
90
|
"options": {
|
|
91
91
|
"request": false
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
"name": "consumer",
|
|
96
|
-
"swagger": "../../platform2/edges/consumer/swagger.json",
|
|
96
|
+
"swagger": "../../api/platform2/edges/consumer/swagger.json",
|
|
97
97
|
"options": {
|
|
98
98
|
"request": false
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
"name": "ai",
|
|
103
|
-
"swagger": "../../platform2/ai/swagger.json",
|
|
103
|
+
"swagger": "../../api/platform2/ai/swagger.json",
|
|
104
104
|
"options": {
|
|
105
105
|
"request": false
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
109
|
"name": "centricos",
|
|
110
|
-
"swagger": "../../platform2/edges/centricos/swagger.json",
|
|
110
|
+
"swagger": "../../api/platform2/edges/centricos/swagger.json",
|
|
111
111
|
"options": {
|
|
112
112
|
"request": false
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
116
|
"name": "tax",
|
|
117
|
-
"swagger": "../../platform2/external-integrations/tax/swagger.json",
|
|
117
|
+
"swagger": "../../api/platform2/external-integrations/tax/swagger.json",
|
|
118
118
|
"options": {
|
|
119
119
|
"request": false
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
{
|
|
123
123
|
"name": "search",
|
|
124
|
-
"swagger": "../../platform2/search/swagger.json",
|
|
124
|
+
"swagger": "../../api/platform2/search/swagger.json",
|
|
125
125
|
"options": {
|
|
126
126
|
"request": false
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
"name": "auth",
|
|
131
|
-
"swagger": "../../platform2/auth/service/swagger.json",
|
|
131
|
+
"swagger": "../../api/platform2/auth/service/swagger.json",
|
|
132
132
|
"options": {
|
|
133
133
|
"request": false
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
137
|
"name": "review",
|
|
138
|
-
"swagger": "../../platform2/review/swagger.json",
|
|
138
|
+
"swagger": "../../api/platform2/review/swagger.json",
|
|
139
139
|
"options": {
|
|
140
140
|
"request": false
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
144
|
"name": "discount",
|
|
145
|
-
"swagger": "../../platform2/discount/swagger.json",
|
|
145
|
+
"swagger": "../../api/platform2/discount/swagger.json",
|
|
146
146
|
"options": {
|
|
147
147
|
"request": false
|
|
148
148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compassdigital/sdk.typescript",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.124.0",
|
|
4
4
|
"description": "Compass Digital Labs TypeScript SDK",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -31,30 +31,32 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test": "jest",
|
|
33
33
|
"build": "rimraf ./lib && tsc",
|
|
34
|
-
"gen": "npm ci && rimraf ./src && sdk.typescript --events ../../events --manifest ./manifest.json && npm run build",
|
|
34
|
+
"gen": "npm ci && rimraf ./src && sdk.typescript --events ../../api/events --manifest ./manifest.json && npm run build",
|
|
35
35
|
"prepare": "npm run build",
|
|
36
36
|
"pretest": "eslint --quiet . --ext .js,.ts",
|
|
37
37
|
"pre-commit": "lint-staged",
|
|
38
|
-
"format": "prettier --write '**/*.{ts,js,yml}'"
|
|
38
|
+
"format": "prettier --write '**/*.{ts,js,yml}'",
|
|
39
|
+
"lint": "eslint --quiet . --ext .js,.ts",
|
|
40
|
+
"lint:fix": "npm run lint -- --fix"
|
|
39
41
|
},
|
|
40
42
|
"author": "",
|
|
41
43
|
"license": "ISC",
|
|
42
44
|
"repository": {
|
|
43
45
|
"type": "git",
|
|
44
46
|
"url": "git+https://github.com/compassdigital/cdl.git",
|
|
45
|
-
"directory": "
|
|
47
|
+
"directory": "npm/sdk.typescript"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"cross-fetch": "^4.0.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@compassdigital/review": "^7.3
|
|
52
|
-
"@compassdigital/sdk.typescript.cli": "^4.
|
|
53
|
+
"@compassdigital/review": "^7.6.3",
|
|
54
|
+
"@compassdigital/sdk.typescript.cli": "^4.43.0",
|
|
53
55
|
"@swc/core": "^1.4.1",
|
|
54
56
|
"@swc/jest": "^0.2.36",
|
|
55
57
|
"@types/jest": "^29.2.4",
|
|
56
58
|
"@types/node": "^22.0.0",
|
|
57
|
-
"esbuild": "^0.
|
|
59
|
+
"esbuild": "^0.25.2",
|
|
58
60
|
"jest": "^29.7.0",
|
|
59
61
|
"rimraf": "^6.0.1",
|
|
60
62
|
"typescript": "^5.0.2"
|
package/prettier.config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
const baseConfig = require('@compassdigital/review/prettier.config');
|
|
3
|
+
|
|
1
4
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
tabWidth: 4,
|
|
4
|
-
useTabs: true,
|
|
5
|
-
semi: true,
|
|
6
|
-
singleQuote: true,
|
|
7
|
-
trailingComma: 'all',
|
|
8
|
-
bracketSpacing: true,
|
|
9
|
-
arrowParens: 'always',
|
|
5
|
+
...baseConfig,
|
|
10
6
|
};
|
package/src/base.ts
CHANGED
|
@@ -161,13 +161,17 @@ export interface ServiceErrorIsOptions {
|
|
|
161
161
|
* An error returned from an api service.
|
|
162
162
|
*/
|
|
163
163
|
export class ServiceError extends Error {
|
|
164
|
+
data: Record<string, any>;
|
|
165
|
+
|
|
164
166
|
constructor(
|
|
165
167
|
public status: number, // http status
|
|
166
168
|
public code: number, // service error code
|
|
167
169
|
message: string, // service error message
|
|
170
|
+
data?: Record<string, any>, // arbitrary error data
|
|
168
171
|
) {
|
|
169
172
|
super(message);
|
|
170
173
|
this.name = `ServiceError(${code})`;
|
|
174
|
+
this.data = data ?? {};
|
|
171
175
|
|
|
172
176
|
// TODO: remove this if we change compilation target > es5
|
|
173
177
|
Object.setPrototypeOf(this, ServiceError.prototype);
|
|
@@ -270,6 +274,7 @@ export class ServiceError extends Error {
|
|
|
270
274
|
static from_res(res: ResponseData): ServiceError {
|
|
271
275
|
let message = res.body;
|
|
272
276
|
let code = res.status;
|
|
277
|
+
let data: Record<string, any> | undefined;
|
|
273
278
|
if (res.err) {
|
|
274
279
|
// network error
|
|
275
280
|
if (res.err instanceof Error) {
|
|
@@ -280,14 +285,17 @@ export class ServiceError extends Error {
|
|
|
280
285
|
code = 0;
|
|
281
286
|
} else {
|
|
282
287
|
try {
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
code =
|
|
286
|
-
message =
|
|
288
|
+
const body = JSON.parse(res.body);
|
|
289
|
+
if (body.code && (body.message || body.error)) {
|
|
290
|
+
code = body.code;
|
|
291
|
+
message = body.message || body.error;
|
|
292
|
+
data = body.data;
|
|
287
293
|
}
|
|
288
|
-
} catch
|
|
294
|
+
} catch {
|
|
295
|
+
// ignore
|
|
296
|
+
}
|
|
289
297
|
}
|
|
290
|
-
const err = new ServiceError(res.status, code, message);
|
|
298
|
+
const err = new ServiceError(res.status, code, message, data);
|
|
291
299
|
// override the stack trace so that it doesn't include the from_res helper.
|
|
292
300
|
if (Error.captureStackTrace) {
|
|
293
301
|
Error.captureStackTrace(err, ServiceError.from_res);
|
package/src/index.ts
CHANGED
|
@@ -1225,6 +1225,8 @@ import {
|
|
|
1225
1225
|
GetDiscountsResponse,
|
|
1226
1226
|
PostDiscountBody,
|
|
1227
1227
|
PostDiscountResponse,
|
|
1228
|
+
GetDiscountsAllQuery,
|
|
1229
|
+
GetDiscountsAllResponse,
|
|
1228
1230
|
PutDiscountPublishBody,
|
|
1229
1231
|
PutDiscountPublishResponse,
|
|
1230
1232
|
} from './interface/discount';
|
|
@@ -12702,6 +12704,19 @@ export class ServiceClient extends BaseServiceClient {
|
|
|
12702
12704
|
return this.request('discount', '/discount', 'post', `/discount`, body, options);
|
|
12703
12705
|
}
|
|
12704
12706
|
|
|
12707
|
+
/**
|
|
12708
|
+
* GET /discount/all - Get all discount
|
|
12709
|
+
*
|
|
12710
|
+
* @param options - additional request options
|
|
12711
|
+
*/
|
|
12712
|
+
get_discounts_all(
|
|
12713
|
+
options?: {
|
|
12714
|
+
query?: GetDiscountsAllQuery;
|
|
12715
|
+
} & RequestOptions,
|
|
12716
|
+
): ResponsePromise<GetDiscountsAllResponse> {
|
|
12717
|
+
return this.request('discount', '/discount/all', 'get', `/discount/all`, null, options);
|
|
12718
|
+
}
|
|
12719
|
+
|
|
12705
12720
|
/**
|
|
12706
12721
|
* PUT /discount/{id}/publish - update and publish a discount
|
|
12707
12722
|
*
|
|
@@ -91,6 +91,26 @@ export interface GetDiscountsResponseDTO {
|
|
|
91
91
|
discounts: DiscountDTO[];
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
export interface DiscountWithSites {
|
|
95
|
+
// discount id
|
|
96
|
+
id: string;
|
|
97
|
+
// user id of discount creator
|
|
98
|
+
createdBy: string;
|
|
99
|
+
// user id of most recent update
|
|
100
|
+
updatedBy: string;
|
|
101
|
+
sites: string[];
|
|
102
|
+
createdAt: string;
|
|
103
|
+
updatedAt: string;
|
|
104
|
+
name: string;
|
|
105
|
+
status?: DiscountStatus;
|
|
106
|
+
is?: DiscountIs;
|
|
107
|
+
meta?: DiscountMeta;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface GetAllDiscountsResponseDTO {
|
|
111
|
+
discounts: DiscountWithSites[];
|
|
112
|
+
}
|
|
113
|
+
|
|
94
114
|
export interface DiscountTaxonomy {
|
|
95
115
|
site?: string[];
|
|
96
116
|
brand?: string[];
|
|
@@ -218,6 +238,15 @@ export type PostDiscountBody = PostDiscountRequestDTO;
|
|
|
218
238
|
|
|
219
239
|
export type PostDiscountResponse = PostDiscountResponseDTO;
|
|
220
240
|
|
|
241
|
+
// GET /discount/all - Get all discount
|
|
242
|
+
|
|
243
|
+
export interface GetDiscountsAllQuery {
|
|
244
|
+
// Graphql query string
|
|
245
|
+
_query?: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type GetDiscountsAllResponse = GetAllDiscountsResponseDTO;
|
|
249
|
+
|
|
221
250
|
// PUT /discount/{id}/publish - update and publish a discount
|
|
222
251
|
|
|
223
252
|
export interface PutDiscountPublishPath {
|
package/test/client.test.ts
CHANGED
|
@@ -224,5 +224,20 @@ describe('ServiceClient', () => {
|
|
|
224
224
|
const promise = api.get_task('').combine(500);
|
|
225
225
|
expect(promise).rejects.toThrow();
|
|
226
226
|
});
|
|
227
|
+
|
|
228
|
+
test('error data should be included', async () => {
|
|
229
|
+
const api = new ServiceClient({
|
|
230
|
+
stage: 'dev',
|
|
231
|
+
intercept: interceptor(500, {
|
|
232
|
+
code: 500,
|
|
233
|
+
error: 'message',
|
|
234
|
+
data: { foo: 'bar' },
|
|
235
|
+
}),
|
|
236
|
+
});
|
|
237
|
+
const promise = api.get_task('');
|
|
238
|
+
expect(promise).rejects.toMatchObject({
|
|
239
|
+
data: { foo: 'bar' },
|
|
240
|
+
});
|
|
241
|
+
});
|
|
227
242
|
});
|
|
228
243
|
});
|