@compassdigital/sdk.typescript 4.119.0 → 4.121.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compassdigital/sdk.typescript",
3
- "version": "4.119.0",
3
+ "version": "4.121.0",
4
4
  "description": "Compass Digital Labs TypeScript SDK",
5
5
  "type": "commonjs",
6
6
  "main": "./lib/index.js",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@compassdigital/review": "^7.3.0",
52
- "@compassdigital/sdk.typescript.cli": "^4.40.1",
52
+ "@compassdigital/sdk.typescript.cli": "^4.42.0",
53
53
  "@swc/core": "^1.4.1",
54
54
  "@swc/jest": "^0.2.36",
55
55
  "@types/jest": "^29.2.4",
package/src/base.ts CHANGED
@@ -149,6 +149,14 @@ interface ErrorConstructor {
149
149
  captureStackTrace?(target: object, constructorOpt?: Function): void;
150
150
  }
151
151
 
152
+ /**
153
+ * A set of constraints that are used to validate service errors.
154
+ */
155
+ export interface ServiceErrorIsOptions {
156
+ status?: number;
157
+ code?: number;
158
+ }
159
+
152
160
  /**
153
161
  * An error returned from an api service.
154
162
  */
@@ -187,6 +195,22 @@ export class ServiceError extends Error {
187
195
  return -1;
188
196
  }
189
197
 
198
+ /**
199
+ * Returns true if err is an instance of ServiceError and matches the specified options.
200
+ */
201
+ static is(err: any, options?: ServiceErrorIsOptions): err is ServiceError {
202
+ if (!(err instanceof ServiceError)) {
203
+ return false;
204
+ }
205
+ if (options?.status !== undefined && err.status !== options.status) {
206
+ return false;
207
+ }
208
+ if (options?.code !== undefined && err.code !== options.code) {
209
+ return false;
210
+ }
211
+ return true;
212
+ }
213
+
190
214
  /**
191
215
  * Returns a promise that resolves to null if http status code
192
216
  * or service error code matches one of the provided codes.
@@ -490,9 +514,11 @@ export abstract class BaseServiceClient {
490
514
  if (url.startsWith('https://')) options.agent ??= this.agent();
491
515
  const headers: Record<string, string> = {
492
516
  'User-Agent': 'CDL/ServiceClient',
493
- 'Content-Type': 'application/json',
494
517
  ...options.headers,
495
518
  };
519
+ if (body) {
520
+ headers['Content-Type'] = 'application/json';
521
+ }
496
522
  if (options.internal) {
497
523
  headers['X-Request-Type'] = 'internal';
498
524
  }
package/src/index.ts CHANGED
@@ -948,6 +948,8 @@ import {
948
948
  PostMenuV4ItemDuplicateResponse,
949
949
  DeleteMenuV4ItemModifierGroupsDetachBody,
950
950
  DeleteMenuV4ItemModifierGroupsDetachResponse,
951
+ PostMenuV4ItemAttachModifierGroupsBody,
952
+ PostMenuV4ItemAttachModifierGroupsResponse,
951
953
  PostMenuV4ModifierBody,
952
954
  PostMenuV4ModifierResponse,
953
955
  GetMenuV4ModifierQuery,
@@ -1187,6 +1189,8 @@ import {
1187
1189
  import {
1188
1190
  PostAuthFlowBody,
1189
1191
  PostAuthFlowResponse,
1192
+ GetAuthSsoConfigQuery,
1193
+ GetAuthSsoConfigResponse,
1190
1194
  GetAuthSsoConfigsQuery,
1191
1195
  GetAuthSsoConfigsResponse,
1192
1196
  PostAuthSsoConfigBody,
@@ -10291,6 +10295,28 @@ export class ServiceClient extends BaseServiceClient {
10291
10295
  );
10292
10296
  }
10293
10297
 
10298
+ /**
10299
+ * POST /menu/v4/item/{id}/attach-modifier-groups
10300
+ *
10301
+ * @param id
10302
+ * @param body
10303
+ * @param options - additional request options
10304
+ */
10305
+ post_menu_v4_item_attach_modifier_groups(
10306
+ id: string,
10307
+ body: PostMenuV4ItemAttachModifierGroupsBody,
10308
+ options?: RequestOptions,
10309
+ ): ResponsePromise<PostMenuV4ItemAttachModifierGroupsResponse> {
10310
+ return this.request(
10311
+ 'menu',
10312
+ '/menu/v4/item/{id}/attach-modifier-groups',
10313
+ 'post',
10314
+ `/menu/v4/item/${id}/attach-modifier-groups`,
10315
+ body,
10316
+ options,
10317
+ );
10318
+ }
10319
+
10294
10320
  /**
10295
10321
  * POST /menu/v4/modifier
10296
10322
  *
@@ -12449,6 +12475,28 @@ export class ServiceClient extends BaseServiceClient {
12449
12475
  return this.request('auth', '/auth/flow', 'post', `/auth/flow`, body, options);
12450
12476
  }
12451
12477
 
12478
+ /**
12479
+ * GET /auth/sso-config/{name} - Return sso client-id based on lookup values
12480
+ *
12481
+ * @param name
12482
+ * @param options - additional request options
12483
+ */
12484
+ get_auth_sso_config(
12485
+ name: string,
12486
+ options: {
12487
+ query: GetAuthSsoConfigQuery;
12488
+ } & RequestOptions,
12489
+ ): ResponsePromise<GetAuthSsoConfigResponse> {
12490
+ return this.request(
12491
+ 'auth',
12492
+ '/auth/sso-config/{name}',
12493
+ 'get',
12494
+ `/auth/sso-config/${name}`,
12495
+ null,
12496
+ options,
12497
+ );
12498
+ }
12499
+
12452
12500
  /**
12453
12501
  * GET /auth/sso-configs - Returns all available SSO configurations
12454
12502
  *
@@ -126,6 +126,20 @@ export type PostAuthFlowBody = SSOFlowRequestDTO;
126
126
 
127
127
  export type PostAuthFlowResponse = SSOFlowResponseDTO;
128
128
 
129
+ // GET /auth/sso-config/{name} - Return sso client-id based on lookup values
130
+
131
+ export interface GetAuthSsoConfigPath {
132
+ name: string;
133
+ }
134
+
135
+ export interface GetAuthSsoConfigQuery {
136
+ realm: string;
137
+ // Graphql query string
138
+ _query?: string;
139
+ }
140
+
141
+ export type GetAuthSsoConfigResponse = string;
142
+
129
143
  // GET /auth/sso-configs - Returns all available SSO configurations
130
144
 
131
145
  export interface GetAuthSsoConfigsQuery {
@@ -222,7 +222,7 @@ export interface CentricDiscountStatus {
222
222
 
223
223
  export interface CentricVoucherifyMetaData {
224
224
  // The type of the voucherify discount
225
- type: Record<string, any>;
225
+ type: 'AMOUNT_OFF' | 'PERCENT_OFF';
226
226
  // The numeric value of discount for amount off
227
227
  amountOff?: number;
228
228
  // The percentage value of discount for percent off
@@ -8628,6 +8628,40 @@ export interface DeleteMenuV4ItemModifierGroupsDetachRequest
8628
8628
  body: DeleteMenuV4ItemModifierGroupsDetachBody;
8629
8629
  }
8630
8630
 
8631
+ // POST /menu/v4/item/{id}/attach-modifier-groups
8632
+
8633
+ export interface PostMenuV4ItemAttachModifierGroupsPath {
8634
+ id: string;
8635
+ }
8636
+
8637
+ export type PostMenuV4ItemAttachModifierGroupsBody = {
8638
+ parent?: DraftItemToModifierGroupRelationshipDTO;
8639
+ children?: DraftItemToModifierGroupRelationshipDTO[];
8640
+ parent_id?: string;
8641
+ modifier_group_id: string;
8642
+ item_id: string;
8643
+ brand_id: string;
8644
+ sequence?: number;
8645
+ applied_diff_snapshot?: Record<string, any>;
8646
+ item?: DraftItemDTO;
8647
+ modifier_group?: DraftModifierGroupDTO;
8648
+ brand?: DraftBrandDTO;
8649
+ changes?: ItemToModifierGroupRelationshipChangeDTO[];
8650
+ vendor_metadata?: VendorMetadataDTO[];
8651
+ permissions?: Record<string, any>;
8652
+ [index: string]: any;
8653
+ }[];
8654
+
8655
+ export interface PostMenuV4ItemAttachModifierGroupsResponse {
8656
+ status?: string;
8657
+ }
8658
+
8659
+ export interface PostMenuV4ItemAttachModifierGroupsRequest
8660
+ extends BaseRequest,
8661
+ PostMenuV4ItemAttachModifierGroupsPath {
8662
+ body: PostMenuV4ItemAttachModifierGroupsBody;
8663
+ }
8664
+
8631
8665
  // POST /menu/v4/modifier
8632
8666
 
8633
8667
  export interface PostMenuV4ModifierBody {
@@ -32,7 +32,6 @@ describe('ServiceClient', () => {
32
32
  method: 'get',
33
33
  headers: {
34
34
  'User-Agent': 'CDL/ServiceClient',
35
- 'Content-Type': 'application/json',
36
35
  },
37
36
  });
38
37
  });
@@ -65,13 +64,26 @@ describe('ServiceClient', () => {
65
64
  const req = intercept.mock.calls[0][0];
66
65
  expect(req.headers).toEqual({
67
66
  'User-Agent': 'CDL/ServiceClient',
68
- 'Content-Type': 'application/json',
69
67
  a: 'a from constructor',
70
68
  b: 'b from method',
71
69
  c: 'c from method',
72
70
  });
73
71
  });
74
72
 
73
+ test('Content-Type header is added to headers if body exists', async () => {
74
+ const intercept = jest.fn(interceptor(200));
75
+ const api = new ServiceClient({
76
+ stage: 'dev',
77
+ intercept,
78
+ });
79
+ await api.post_discount({ name: 'test', createdBy: 'test' }, {});
80
+ const req = intercept.mock.calls[0][0];
81
+ expect(req.headers).toEqual({
82
+ 'User-Agent': 'CDL/ServiceClient',
83
+ 'Content-Type': 'application/json',
84
+ });
85
+ });
86
+
75
87
  test('client retries on bad status codes', async () => {
76
88
  const intercept = jest.fn(async () => {
77
89
  if (intercept.mock.calls.length === 3) {