@compassdigital/sdk.typescript 4.121.0 → 4.123.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.
@@ -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
- printWidth: 100,
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 data = JSON.parse(res.body);
284
- if (data.code && (data.message || data.error)) {
285
- code = data.code;
286
- message = data.message || data.error;
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
@@ -1025,8 +1025,8 @@ import {
1025
1025
  import {
1026
1026
  PostVendorApplicationBody,
1027
1027
  PostVendorApplicationResponse,
1028
- GetVendorApplicationQuery,
1029
- GetVendorApplicationResponse,
1028
+ GetVendorApplicationsQuery,
1029
+ GetVendorApplicationsResponse,
1030
1030
  PatchVendorApplicationBody,
1031
1031
  PatchVendorApplicationResponse,
1032
1032
  PostVendorBody,
@@ -11019,11 +11019,11 @@ export class ServiceClient extends BaseServiceClient {
11019
11019
  *
11020
11020
  * @param options - additional request options
11021
11021
  */
11022
- get_vendor_application(
11022
+ get_vendor_applications(
11023
11023
  options?: {
11024
- query?: GetVendorApplicationQuery;
11024
+ query?: GetVendorApplicationsQuery;
11025
11025
  } & RequestOptions,
11026
- ): ResponsePromise<GetVendorApplicationResponse> {
11026
+ ): ResponsePromise<GetVendorApplicationsResponse> {
11027
11027
  return this.request(
11028
11028
  'vendor',
11029
11029
  '/vendor/application',
@@ -12,6 +12,7 @@ export interface SSOFlowRequestDTO {
12
12
  export interface OIDC {
13
13
  authorizationUrl: string;
14
14
  name: string;
15
+ clientId: string;
15
16
  }
16
17
 
17
18
  export interface SSOFlowResponseDTO {
@@ -26,7 +27,7 @@ export interface UnauthorizedErrorDTO {
26
27
  }
27
28
 
28
29
  export interface SSOMapping {
29
- id: string;
30
+ sub: string;
30
31
  given_name: string;
31
32
  family_name: string;
32
33
  email: string;
@@ -204,7 +204,7 @@ export interface PostVendorApplicationRequest extends BaseRequest {
204
204
 
205
205
  // GET /vendor/application - Get a list of all applications
206
206
 
207
- export interface GetVendorApplicationQuery {
207
+ export interface GetVendorApplicationsQuery {
208
208
  status?: 'pending' | 'approved' | 'rejected';
209
209
  // Pagination token to start query from
210
210
  last_evaluated_key?: string;
@@ -212,11 +212,11 @@ export interface GetVendorApplicationQuery {
212
212
  _query?: string;
213
213
  }
214
214
 
215
- export type GetVendorApplicationResponse = Applications;
215
+ export type GetVendorApplicationsResponse = Applications;
216
216
 
217
- export interface GetVendorApplicationRequest
217
+ export interface GetVendorApplicationsRequest
218
218
  extends BaseRequest,
219
- RequestQuery<GetVendorApplicationQuery> {}
219
+ RequestQuery<GetVendorApplicationsQuery> {}
220
220
 
221
221
  // PATCH /vendor/application/{id} - Update an application (or update status)
222
222
 
@@ -316,6 +316,8 @@ export interface GetVendorKeysPath {
316
316
  }
317
317
 
318
318
  export interface GetVendorKeysQuery {
319
+ // Pagination token to start query from
320
+ last_evaluated_key?: string;
319
321
  // Graphql query string
320
322
  _query?: string;
321
323
  }
@@ -352,8 +354,6 @@ export interface GetVendorKeyPath {
352
354
  }
353
355
 
354
356
  export interface GetVendorKeyQuery {
355
- // Pagination token to start query from
356
- last_evaluated_key?: string;
357
357
  // Graphql query string
358
358
  _query?: string;
359
359
  }
@@ -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
  });