@compassdigital/sdk.typescript 3.0.0-beta.13 → 3.0.0-beta.14
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/README.md +10 -5
- package/gen.ts +13 -5
- package/lib/announcement.d.ts.map +1 -1
- package/lib/announcement.js +1 -0
- package/lib/announcement.js.map +1 -1
- package/lib/base.d.ts.map +1 -1
- package/lib/base.js.map +1 -1
- package/lib/brand.d.ts.map +1 -1
- package/lib/brand.js +1 -0
- package/lib/brand.js.map +1 -1
- package/lib/calendar.d.ts.map +1 -1
- package/lib/calendar.js +1 -0
- package/lib/calendar.js.map +1 -1
- package/lib/client/base.d.ts +157 -0
- package/lib/client/base.d.ts.map +1 -0
- package/lib/client/base.js +392 -0
- package/lib/client/base.js.map +1 -0
- package/lib/client/index.d.ts +1877 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +2208 -0
- package/lib/client/index.js.map +1 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -0
- package/lib/config.js.map +1 -1
- package/lib/datalake.d.ts.map +1 -1
- package/lib/datalake.js +1 -0
- package/lib/datalake.js.map +1 -1
- package/lib/delivery.d.ts.map +1 -1
- package/lib/delivery.js +1 -0
- package/lib/delivery.js.map +1 -1
- package/lib/dh.d.ts.map +1 -1
- package/lib/dh.js +1 -0
- package/lib/dh.js.map +1 -1
- package/lib/email.d.ts.map +1 -1
- package/lib/email.js +1 -0
- package/lib/email.js.map +1 -1
- package/lib/file.d.ts.map +1 -1
- package/lib/file.js +1 -0
- package/lib/file.js.map +1 -1
- package/lib/index.d.ts +8 -19
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -2
- package/lib/index.js.map +1 -1
- package/lib/interface/announcement.d.ts +76 -0
- package/lib/interface/announcement.d.ts.map +1 -0
- package/lib/interface/announcement.js +4 -0
- package/lib/interface/announcement.js.map +1 -0
- package/lib/interface/brand.d.ts +16 -0
- package/lib/interface/brand.d.ts.map +1 -0
- package/lib/interface/brand.js +4 -0
- package/lib/interface/brand.js.map +1 -0
- package/lib/interface/calendar.d.ts +85 -0
- package/lib/interface/calendar.d.ts.map +1 -0
- package/lib/interface/calendar.js +4 -0
- package/lib/interface/calendar.js.map +1 -0
- package/lib/interface/config.d.ts +68 -0
- package/lib/interface/config.d.ts.map +1 -0
- package/lib/interface/config.js +4 -0
- package/lib/interface/config.js.map +1 -0
- package/lib/interface/datalake.d.ts +19 -0
- package/lib/interface/datalake.d.ts.map +1 -0
- package/lib/interface/datalake.js +4 -0
- package/lib/interface/datalake.js.map +1 -0
- package/lib/interface/delivery.d.ts +34 -0
- package/lib/interface/delivery.d.ts.map +1 -0
- package/lib/interface/delivery.js +4 -0
- package/lib/interface/delivery.js.map +1 -0
- package/lib/interface/dh.d.ts +9 -0
- package/lib/interface/dh.d.ts.map +1 -0
- package/lib/interface/dh.js +4 -0
- package/lib/interface/dh.js.map +1 -0
- package/lib/interface/email.d.ts +5 -0
- package/lib/interface/email.d.ts.map +1 -0
- package/lib/interface/email.js +4 -0
- package/lib/interface/email.js.map +1 -0
- package/lib/interface/file.d.ts +17 -0
- package/lib/interface/file.d.ts.map +1 -0
- package/lib/interface/file.js +4 -0
- package/lib/interface/file.js.map +1 -0
- package/lib/interface/kds.d.ts +58 -0
- package/lib/interface/kds.d.ts.map +1 -0
- package/lib/interface/kds.js +4 -0
- package/lib/interface/kds.js.map +1 -0
- package/lib/interface/location.d.ts +747 -0
- package/lib/interface/location.d.ts.map +1 -0
- package/lib/interface/location.js +4 -0
- package/lib/interface/location.js.map +1 -0
- package/lib/interface/logger.d.ts +29 -0
- package/lib/interface/logger.d.ts.map +1 -0
- package/lib/interface/logger.js +4 -0
- package/lib/interface/logger.js.map +1 -0
- package/lib/interface/loyalty.d.ts +350 -0
- package/lib/interface/loyalty.d.ts.map +1 -0
- package/lib/interface/loyalty.js +4 -0
- package/lib/interface/loyalty.js.map +1 -0
- package/lib/interface/mealplan.d.ts +177 -0
- package/lib/interface/mealplan.d.ts.map +1 -0
- package/lib/interface/mealplan.js +4 -0
- package/lib/interface/mealplan.js.map +1 -0
- package/lib/interface/message.d.ts +38 -0
- package/lib/interface/message.d.ts.map +1 -0
- package/lib/interface/message.js +4 -0
- package/lib/interface/message.js.map +1 -0
- package/lib/interface/order.d.ts +303 -0
- package/lib/interface/order.d.ts.map +1 -0
- package/lib/interface/order.js +4 -0
- package/lib/interface/order.js.map +1 -0
- package/lib/interface/partner.d.ts +402 -0
- package/lib/interface/partner.d.ts.map +1 -0
- package/lib/interface/partner.js +4 -0
- package/lib/interface/partner.js.map +1 -0
- package/lib/interface/payment.d.ts +250 -0
- package/lib/interface/payment.d.ts.map +1 -0
- package/lib/interface/payment.js +4 -0
- package/lib/interface/payment.js.map +1 -0
- package/lib/interface/promo.d.ts +312 -0
- package/lib/interface/promo.d.ts.map +1 -0
- package/lib/interface/promo.js +4 -0
- package/lib/interface/promo.js.map +1 -0
- package/lib/interface/report.d.ts +376 -0
- package/lib/interface/report.d.ts.map +1 -0
- package/lib/interface/report.js +4 -0
- package/lib/interface/report.js.map +1 -0
- package/lib/interface/schedule.d.ts +95 -0
- package/lib/interface/schedule.d.ts.map +1 -0
- package/lib/interface/schedule.js +4 -0
- package/lib/interface/schedule.js.map +1 -0
- package/lib/interface/shoppingcart.d.ts +279 -0
- package/lib/interface/shoppingcart.d.ts.map +1 -0
- package/lib/interface/shoppingcart.js +4 -0
- package/lib/interface/shoppingcart.js.map +1 -0
- package/lib/interface/task.d.ts +171 -0
- package/lib/interface/task.d.ts.map +1 -0
- package/lib/interface/task.js +4 -0
- package/lib/interface/task.js.map +1 -0
- package/lib/interface/user.d.ts +359 -0
- package/lib/interface/user.d.ts.map +1 -0
- package/lib/interface/user.js +4 -0
- package/lib/interface/user.js.map +1 -0
- package/lib/interface/vote.d.ts +52 -0
- package/lib/interface/vote.d.ts.map +1 -0
- package/lib/interface/vote.js +4 -0
- package/lib/interface/vote.js.map +1 -0
- package/lib/kds.d.ts.map +1 -1
- package/lib/kds.js +1 -0
- package/lib/kds.js.map +1 -1
- package/lib/location.d.ts +4 -4
- package/lib/location.d.ts.map +1 -1
- package/lib/location.js +1 -0
- package/lib/location.js.map +1 -1
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +1 -0
- package/lib/logger.js.map +1 -1
- package/lib/loyalty.d.ts.map +1 -1
- package/lib/loyalty.js +1 -0
- package/lib/loyalty.js.map +1 -1
- package/lib/mealplan.d.ts.map +1 -1
- package/lib/mealplan.js +1 -0
- package/lib/mealplan.js.map +1 -1
- package/lib/message.d.ts.map +1 -1
- package/lib/message.js +1 -0
- package/lib/message.js.map +1 -1
- package/lib/order.d.ts.map +1 -1
- package/lib/order.js +1 -0
- package/lib/order.js.map +1 -1
- package/lib/partner.d.ts +13 -0
- package/lib/partner.d.ts.map +1 -1
- package/lib/partner.js +1 -0
- package/lib/partner.js.map +1 -1
- package/lib/payment.d.ts.map +1 -1
- package/lib/payment.js +1 -0
- package/lib/payment.js.map +1 -1
- package/lib/promo.d.ts.map +1 -1
- package/lib/promo.js +1 -0
- package/lib/promo.js.map +1 -1
- package/lib/report.d.ts.map +1 -1
- package/lib/report.js +1 -0
- package/lib/report.js.map +1 -1
- package/lib/schedule.d.ts.map +1 -1
- package/lib/schedule.js +1 -0
- package/lib/schedule.js.map +1 -1
- package/lib/shoppingcart.d.ts.map +1 -1
- package/lib/shoppingcart.js +1 -0
- package/lib/shoppingcart.js.map +1 -1
- package/lib/task.d.ts.map +1 -1
- package/lib/task.js +1 -0
- package/lib/task.js.map +1 -1
- package/lib/user.d.ts.map +1 -1
- package/lib/user.js +1 -0
- package/lib/user.js.map +1 -1
- package/lib/vote.d.ts.map +1 -1
- package/lib/vote.js +1 -0
- package/lib/vote.js.map +1 -1
- package/package.json +1 -1
- package/src/{index.ts → client/index.ts} +54 -24
- package/src/{announcement.ts → interface/announcement.ts} +2 -0
- package/src/{brand.ts → interface/brand.ts} +2 -0
- package/src/{calendar.ts → interface/calendar.ts} +2 -0
- package/src/{config.ts → interface/config.ts} +2 -0
- package/src/{datalake.ts → interface/datalake.ts} +2 -0
- package/src/{delivery.ts → interface/delivery.ts} +2 -0
- package/src/{dh.ts → interface/dh.ts} +2 -0
- package/src/{email.ts → interface/email.ts} +2 -0
- package/src/{file.ts → interface/file.ts} +2 -0
- package/src/{kds.ts → interface/kds.ts} +2 -0
- package/src/{location.ts → interface/location.ts} +2 -0
- package/src/{logger.ts → interface/logger.ts} +2 -0
- package/src/{loyalty.ts → interface/loyalty.ts} +2 -0
- package/src/{mealplan.ts → interface/mealplan.ts} +2 -0
- package/src/{message.ts → interface/message.ts} +2 -0
- package/src/{order.ts → interface/order.ts} +2 -0
- package/src/{partner.ts → interface/partner.ts} +25 -0
- package/src/{payment.ts → interface/payment.ts} +2 -0
- package/src/{promo.ts → interface/promo.ts} +2 -0
- package/src/{report.ts → interface/report.ts} +2 -0
- package/src/{schedule.ts → interface/schedule.ts} +2 -0
- package/src/{shoppingcart.ts → interface/shoppingcart.ts} +2 -0
- package/src/{task.ts → interface/task.ts} +2 -0
- package/src/{user.ts → interface/user.ts} +2 -0
- package/src/{vote.ts → interface/vote.ts} +2 -0
- package/test/client.test.ts +57 -73
- /package/src/{base.ts → client/base.ts} +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
PostPaymentTransactionBody,
|
|
3
5
|
PostPaymentTransactionResponse,
|
|
@@ -26,7 +28,7 @@ import {
|
|
|
26
28
|
GetPaymentMethodsResponse,
|
|
27
29
|
GetPaymentHpcQuery,
|
|
28
30
|
GetPaymentHpcResponse,
|
|
29
|
-
} from "
|
|
31
|
+
} from "../interface/payment";
|
|
30
32
|
|
|
31
33
|
import {
|
|
32
34
|
PostOrderQuery,
|
|
@@ -49,7 +51,7 @@ import {
|
|
|
49
51
|
GetOrderLocationOrdersResponse,
|
|
50
52
|
GetOrderGroupOrdersQuery,
|
|
51
53
|
GetOrderGroupOrdersResponse,
|
|
52
|
-
} from "
|
|
54
|
+
} from "../interface/order";
|
|
53
55
|
|
|
54
56
|
import {
|
|
55
57
|
PostLocationBody,
|
|
@@ -146,7 +148,7 @@ import {
|
|
|
146
148
|
GetLocationCompanyResponse,
|
|
147
149
|
PatchLocationCompanyBody,
|
|
148
150
|
PatchLocationCompanyResponse,
|
|
149
|
-
} from "
|
|
151
|
+
} from "../interface/location";
|
|
150
152
|
|
|
151
153
|
import {
|
|
152
154
|
PostShoppingcartCartBody,
|
|
@@ -171,16 +173,17 @@ import {
|
|
|
171
173
|
PostShoppingcartCloneCartResponse,
|
|
172
174
|
PostShoppingcartBulkBody,
|
|
173
175
|
PostShoppingcartBulkResponse,
|
|
174
|
-
} from "
|
|
176
|
+
} from "../interface/shoppingcart";
|
|
175
177
|
|
|
176
178
|
import {
|
|
177
179
|
PostPartnerStandardcognitionShoppingcartBody,
|
|
178
180
|
PostPartnerStandardcognitionShoppingcartResponse,
|
|
179
181
|
GetPartnerStandardcognitionLocationsResponse,
|
|
182
|
+
GetPartnerStandardcognitionStoresResponse,
|
|
180
183
|
GetPartnerCoolrLocationsResponse,
|
|
181
184
|
GetPartnerCoolrImagesResponse,
|
|
182
185
|
GetPartnerSwaggerResponse,
|
|
183
|
-
} from "
|
|
186
|
+
} from "../interface/partner";
|
|
184
187
|
|
|
185
188
|
import {
|
|
186
189
|
PostTaskBody,
|
|
@@ -199,7 +202,7 @@ import {
|
|
|
199
202
|
GetTaskLocationBrandResponse,
|
|
200
203
|
GetTaskLocationGroupQuery,
|
|
201
204
|
GetTaskLocationGroupResponse,
|
|
202
|
-
} from "
|
|
205
|
+
} from "../interface/task";
|
|
203
206
|
|
|
204
207
|
import {
|
|
205
208
|
GetKdsDevicesQuery,
|
|
@@ -208,7 +211,7 @@ import {
|
|
|
208
211
|
PostKdsDeviceAuthResponse,
|
|
209
212
|
DeleteKdsDeviceAuthResponse,
|
|
210
213
|
GetKdsSwaggerResponse,
|
|
211
|
-
} from "
|
|
214
|
+
} from "../interface/kds";
|
|
212
215
|
|
|
213
216
|
import {
|
|
214
217
|
PostMealplanBody,
|
|
@@ -230,9 +233,13 @@ import {
|
|
|
230
233
|
PutMealplanVerifyResponse,
|
|
231
234
|
PostMealplanAuthorizeBody,
|
|
232
235
|
PostMealplanAuthorizeResponse,
|
|
233
|
-
} from "
|
|
236
|
+
} from "../interface/mealplan";
|
|
234
237
|
|
|
235
|
-
import {
|
|
238
|
+
import {
|
|
239
|
+
PostDatalakeSqlBody,
|
|
240
|
+
PostDatalakeSqlResponse,
|
|
241
|
+
GetSwaggerResponse,
|
|
242
|
+
} from "../interface/datalake";
|
|
236
243
|
|
|
237
244
|
import {
|
|
238
245
|
PostPromoBody,
|
|
@@ -265,9 +272,9 @@ import {
|
|
|
265
272
|
PostPromoVoucherifyActivityExecuteBody,
|
|
266
273
|
PostPromoVoucherifyActivityExecuteResponse,
|
|
267
274
|
GetPromoVoucherifyActivityConfigResponse,
|
|
268
|
-
} from "
|
|
275
|
+
} from "../interface/promo";
|
|
269
276
|
|
|
270
|
-
import { PostDhSqlResponse } from "
|
|
277
|
+
import { PostDhSqlResponse } from "../interface/dh";
|
|
271
278
|
|
|
272
279
|
import {
|
|
273
280
|
GetConfigResponse,
|
|
@@ -282,7 +289,7 @@ import {
|
|
|
282
289
|
PutConfigPublicBody,
|
|
283
290
|
PutConfigPublicResponse,
|
|
284
291
|
DeleteConfigPublicResponse,
|
|
285
|
-
} from "
|
|
292
|
+
} from "../interface/config";
|
|
286
293
|
|
|
287
294
|
import {
|
|
288
295
|
PostAnnouncementBody,
|
|
@@ -295,7 +302,7 @@ import {
|
|
|
295
302
|
PutAnnouncementBody,
|
|
296
303
|
PutAnnouncementResponse,
|
|
297
304
|
DeleteAnnouncementResponse,
|
|
298
|
-
} from "
|
|
305
|
+
} from "../interface/announcement";
|
|
299
306
|
|
|
300
307
|
import {
|
|
301
308
|
GetReportAnalyticsGroupQuery,
|
|
@@ -323,7 +330,7 @@ import {
|
|
|
323
330
|
DeleteReportDiscrepancySubscribersResponse,
|
|
324
331
|
PostReportDiscrepancySubscribersBody,
|
|
325
332
|
PostReportDiscrepancySubscribersResponse,
|
|
326
|
-
} from "
|
|
333
|
+
} from "../interface/report";
|
|
327
334
|
|
|
328
335
|
import {
|
|
329
336
|
GetUserAuthQuery,
|
|
@@ -378,7 +385,7 @@ import {
|
|
|
378
385
|
PostUserSendEmailVerificationResponse,
|
|
379
386
|
PutUserVerifyUserEmailBody,
|
|
380
387
|
PutUserVerifyUserEmailResponse,
|
|
381
|
-
} from "
|
|
388
|
+
} from "../interface/user";
|
|
382
389
|
|
|
383
390
|
import {
|
|
384
391
|
PostLoyaltyEnrollQuery,
|
|
@@ -415,9 +422,9 @@ import {
|
|
|
415
422
|
GetLoyaltyUsersResponse,
|
|
416
423
|
GetLoyaltyEventsQuery,
|
|
417
424
|
GetLoyaltyEventsResponse,
|
|
418
|
-
} from "
|
|
425
|
+
} from "../interface/loyalty";
|
|
419
426
|
|
|
420
|
-
import { GetBrandResponse, GetBrandsResponse } from "
|
|
427
|
+
import { GetBrandResponse, GetBrandsResponse } from "../interface/brand";
|
|
421
428
|
|
|
422
429
|
import {
|
|
423
430
|
GetCalendarResponse,
|
|
@@ -427,14 +434,14 @@ import {
|
|
|
427
434
|
GetCalendarCdlResponse,
|
|
428
435
|
GetCalendarSwaggerResponse,
|
|
429
436
|
PostCalendarSyncResponse,
|
|
430
|
-
} from "
|
|
437
|
+
} from "../interface/calendar";
|
|
431
438
|
|
|
432
439
|
import {
|
|
433
440
|
PostDeliveryOrderBody,
|
|
434
441
|
PostDeliveryOrderResponse,
|
|
435
442
|
PatchDeliveryOrderResponse,
|
|
436
443
|
GetDeliveryOrderResponse,
|
|
437
|
-
} from "
|
|
444
|
+
} from "../interface/delivery";
|
|
438
445
|
|
|
439
446
|
import {
|
|
440
447
|
PostScheduleBody,
|
|
@@ -445,15 +452,20 @@ import {
|
|
|
445
452
|
PutScheduleBody,
|
|
446
453
|
PutScheduleResponse,
|
|
447
454
|
DeleteScheduleResponse,
|
|
448
|
-
} from "
|
|
455
|
+
} from "../interface/schedule";
|
|
449
456
|
|
|
450
|
-
import {
|
|
457
|
+
import {
|
|
458
|
+
PostVoteBody,
|
|
459
|
+
PostVoteResponse,
|
|
460
|
+
GetVoteIdfaQuery,
|
|
461
|
+
GetVoteIdfaResponse,
|
|
462
|
+
} from "../interface/vote";
|
|
451
463
|
|
|
452
|
-
import { PostFileBody, PostFileResponse } from "
|
|
464
|
+
import { PostFileBody, PostFileResponse } from "../interface/file";
|
|
453
465
|
|
|
454
|
-
import { PostMessageBody, PostMessageResponse, GetMessageResponse } from "
|
|
466
|
+
import { PostMessageBody, PostMessageResponse, GetMessageResponse } from "../interface/message";
|
|
455
467
|
|
|
456
|
-
import { GetLoggerBrandStatusQuery, GetLoggerBrandStatusResponse } from "
|
|
468
|
+
import { GetLoggerBrandStatusQuery, GetLoggerBrandStatusResponse } from "../interface/logger";
|
|
457
469
|
|
|
458
470
|
import { BaseServiceClient, RequestOptions, ResponsePromise } from "./base";
|
|
459
471
|
export * from "./base";
|
|
@@ -2267,6 +2279,24 @@ export class ServiceClient extends BaseServiceClient {
|
|
|
2267
2279
|
);
|
|
2268
2280
|
}
|
|
2269
2281
|
|
|
2282
|
+
/**
|
|
2283
|
+
* GET /partner/standardcognition/stores - Gets the UUID for all the Standard Cognition external locations
|
|
2284
|
+
*
|
|
2285
|
+
* @param options - additional request options
|
|
2286
|
+
*/
|
|
2287
|
+
get_partner_standardcognition_stores(
|
|
2288
|
+
options?: RequestOptions
|
|
2289
|
+
): ResponsePromise<GetPartnerStandardcognitionStoresResponse> {
|
|
2290
|
+
return this.request(
|
|
2291
|
+
"partner",
|
|
2292
|
+
"get_partner_standardcognition_stores",
|
|
2293
|
+
"get",
|
|
2294
|
+
`/partner/standardcognition/stores`,
|
|
2295
|
+
null,
|
|
2296
|
+
options
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2270
2300
|
/**
|
|
2271
2301
|
* GET /partner/coolr/locations - Gets the locations where Coolr is available
|
|
2272
2302
|
*
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY
|
|
2
|
+
|
|
1
3
|
export interface Error {
|
|
2
4
|
message?: string;
|
|
3
5
|
code?: number;
|
|
@@ -395,6 +397,23 @@ export type Hours = any;
|
|
|
395
397
|
|
|
396
398
|
export type DeliveryHours = any;
|
|
397
399
|
|
|
400
|
+
export interface CognitionStore {
|
|
401
|
+
// UUID for external store
|
|
402
|
+
uuid?: string;
|
|
403
|
+
// Store name
|
|
404
|
+
name?: string;
|
|
405
|
+
// Full address
|
|
406
|
+
address?: string;
|
|
407
|
+
city?: string;
|
|
408
|
+
state?: string;
|
|
409
|
+
// Abbreviated address
|
|
410
|
+
street_address?: string;
|
|
411
|
+
// ISO code for currency
|
|
412
|
+
currency_code?: string;
|
|
413
|
+
latitude?: number;
|
|
414
|
+
longitude?: number;
|
|
415
|
+
}
|
|
416
|
+
|
|
398
417
|
export interface CoolrLocations {
|
|
399
418
|
// location
|
|
400
419
|
id?: string;
|
|
@@ -438,6 +457,12 @@ export interface GetPartnerStandardcognitionLocationsResponse {
|
|
|
438
457
|
|
|
439
458
|
export type GetPartnerStandardcognitionLocationsRequest = {};
|
|
440
459
|
|
|
460
|
+
// GET /partner/standardcognition/stores - Gets the UUID for all the Standard Cognition external locations
|
|
461
|
+
|
|
462
|
+
export type GetPartnerStandardcognitionStoresResponse = CognitionStore;
|
|
463
|
+
|
|
464
|
+
export type GetPartnerStandardcognitionStoresRequest = {};
|
|
465
|
+
|
|
441
466
|
// GET /partner/coolr/locations - Gets the locations where Coolr is available
|
|
442
467
|
|
|
443
468
|
export interface GetPartnerCoolrLocationsResponse {
|
package/test/client.test.ts
CHANGED
|
@@ -1,92 +1,90 @@
|
|
|
1
1
|
|
|
2
|
-
import { ServiceClient, ResponseData, ServiceError } from "../src";
|
|
3
|
-
import { Task } from "../src/task";
|
|
2
|
+
import { ServiceClient, ResponseData, ServiceError, RequestData, InterceptFn } from "../src/client";
|
|
3
|
+
import { Task } from "../src/interface/task";
|
|
4
4
|
|
|
5
5
|
describe("ServiceClient", () => {
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function response(status: number, body?: any): ResponseData {
|
|
8
|
+
const res = { ok: status === 200, status: status, body: "" };
|
|
9
|
+
if (body) {
|
|
10
|
+
res.body = JSON.stringify(body);
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function interceptor(status: number, body?: any): InterceptFn {
|
|
16
|
+
return (req: RequestData) => Promise.resolve(response(status, body));
|
|
17
|
+
}
|
|
8
18
|
|
|
9
19
|
test("makes basic request", async () => {
|
|
10
20
|
const fake: Task = { id: "some_id" };
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
expect(req.name).toBe("get_task");
|
|
14
|
-
expect(req.service).toBe("task");
|
|
15
|
-
expect(req.url).toBe("https://api.compassdigital.org/dev/task/some_id");
|
|
16
|
-
return {
|
|
17
|
-
ok: true,
|
|
18
|
-
status: 200,
|
|
19
|
-
body: JSON.stringify(fake)
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
});
|
|
21
|
+
const intercept = jest.fn(interceptor(200, fake));
|
|
22
|
+
const api = new ServiceClient({ intercept });
|
|
23
23
|
const task = await api.get_task("some_id");
|
|
24
24
|
expect(task).toEqual(fake);
|
|
25
|
+
const req = intercept.mock.calls[0][0];
|
|
26
|
+
expect(req).toEqual({
|
|
27
|
+
name: "get_task",
|
|
28
|
+
service: "task",
|
|
29
|
+
url: "https://api.compassdigital.org/dev/task/some_id",
|
|
30
|
+
method: "get",
|
|
31
|
+
headers: {
|
|
32
|
+
"User-Agent": "CDL/ServiceClient",
|
|
33
|
+
},
|
|
34
|
+
})
|
|
25
35
|
});
|
|
26
36
|
|
|
27
37
|
test("token gets passed", async () => {
|
|
28
38
|
const token = "this is a token";
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
expect(req.headers).toHaveProperty("Authorization", `Bearer ${token}`);
|
|
32
|
-
return empty;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
39
|
+
const intercept = jest.fn(interceptor(200));
|
|
40
|
+
const api = new ServiceClient({ intercept });
|
|
35
41
|
await api.get_task("", { token });
|
|
42
|
+
const req = intercept.mock.calls[0][0];
|
|
43
|
+
expect(req.headers).toHaveProperty("Authorization", `Bearer ${token}`);
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
test("headers get merged", async () => {
|
|
47
|
+
const intercept = jest.fn(interceptor(200));
|
|
39
48
|
const api = new ServiceClient({
|
|
49
|
+
intercept,
|
|
40
50
|
headers: {
|
|
41
51
|
"a": "a from constructor",
|
|
42
52
|
"b": "b from constructor",
|
|
43
53
|
},
|
|
44
|
-
intercept: async (req) => {
|
|
45
|
-
expect(req.headers).toEqual({
|
|
46
|
-
"User-Agent": "CDL/ServiceClient",
|
|
47
|
-
"a": "a from constructor",
|
|
48
|
-
"b": "b from method",
|
|
49
|
-
"c": "c from method",
|
|
50
|
-
})
|
|
51
|
-
return empty;
|
|
52
|
-
}
|
|
53
54
|
});
|
|
54
55
|
await api.get_task("", {
|
|
55
56
|
headers: {
|
|
56
57
|
"b": "b from method",
|
|
57
58
|
"c": "c from method",
|
|
58
59
|
},
|
|
59
|
-
})
|
|
60
|
+
});
|
|
61
|
+
const req = intercept.mock.calls[0][0];
|
|
62
|
+
expect(req.headers).toEqual({
|
|
63
|
+
"User-Agent": "CDL/ServiceClient",
|
|
64
|
+
"a": "a from constructor",
|
|
65
|
+
"b": "b from method",
|
|
66
|
+
"c": "c from method",
|
|
67
|
+
});
|
|
60
68
|
});
|
|
61
69
|
|
|
62
70
|
test("client retries on failure", async () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
attempts++;
|
|
67
|
-
if (attempts === 3) {
|
|
68
|
-
return { ok: true, status: 200, body: "{}" };
|
|
69
|
-
}
|
|
70
|
-
return { ok: false, status: 500, body: "something went wrong"};
|
|
71
|
+
const intercept = jest.fn(async (req: RequestData) => {
|
|
72
|
+
if (intercept.mock.calls.length === 3) {
|
|
73
|
+
return response(200, "{}");
|
|
71
74
|
}
|
|
75
|
+
return response(500, "something went wrong");
|
|
72
76
|
});
|
|
77
|
+
const api = new ServiceClient({ intercept });
|
|
73
78
|
const task = await api.get_task("", { retry: 2 });
|
|
79
|
+
expect(intercept.mock.calls.length).toBe(3);
|
|
74
80
|
});
|
|
75
81
|
|
|
76
82
|
test("client gives up after retry limit", async () => {
|
|
77
|
-
|
|
78
|
-
const api = new ServiceClient({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
try {
|
|
85
|
-
const task = await api.get_task("", { retry: 5 });
|
|
86
|
-
throw new Error("request should not have succeeded");
|
|
87
|
-
} catch (_) {
|
|
88
|
-
expect(attempts).toEqual(6);
|
|
89
|
-
}
|
|
83
|
+
const intercept = jest.fn(interceptor(500));
|
|
84
|
+
const api = new ServiceClient({ intercept });
|
|
85
|
+
const promise = api.get_task("", { retry: 5 });
|
|
86
|
+
await expect(promise).rejects.toBeInstanceOf(ServiceError);
|
|
87
|
+
expect(intercept.mock.calls.length).toEqual(6);
|
|
90
88
|
});
|
|
91
89
|
|
|
92
90
|
describe("ServiceError", () => {
|
|
@@ -99,9 +97,7 @@ describe("ServiceClient", () => {
|
|
|
99
97
|
|
|
100
98
|
test("returns null for ignored http status", async () => {
|
|
101
99
|
const api = new ServiceClient({
|
|
102
|
-
intercept:
|
|
103
|
-
return { ok: false, status: 501, body: "" };
|
|
104
|
-
}
|
|
100
|
+
intercept: interceptor(501),
|
|
105
101
|
});
|
|
106
102
|
const task = await api.get_task("").ignore(501);
|
|
107
103
|
expect(task).toBeNull();
|
|
@@ -109,9 +105,7 @@ describe("ServiceClient", () => {
|
|
|
109
105
|
|
|
110
106
|
test("returns null for ignored service error code", async () => {
|
|
111
107
|
const api = new ServiceClient({
|
|
112
|
-
intercept:
|
|
113
|
-
return { ok: false, status: 500, body: JSON.stringify({ code: 500.4, message: "uh oh" }) };
|
|
114
|
-
}
|
|
108
|
+
intercept: interceptor(500, { code: 500.4, message: "uh oh" }),
|
|
115
109
|
});
|
|
116
110
|
const task = await api.get_task("").ignore(500.4);
|
|
117
111
|
expect(task).toBeNull();
|
|
@@ -119,9 +113,7 @@ describe("ServiceClient", () => {
|
|
|
119
113
|
|
|
120
114
|
test("throws ServiceError for non-ignored errors", async () => {
|
|
121
115
|
const api = new ServiceClient({
|
|
122
|
-
intercept:
|
|
123
|
-
return { ok: false, status: 500, body: JSON.stringify({ code: 500.4, message: "hello world" }) };
|
|
124
|
-
}
|
|
116
|
+
intercept: interceptor(500, { code: 500.4, message: "hello world"}),
|
|
125
117
|
});
|
|
126
118
|
try {
|
|
127
119
|
await api.get_task("");
|
|
@@ -134,9 +126,7 @@ describe("ServiceClient", () => {
|
|
|
134
126
|
|
|
135
127
|
test("either should be true with 200 response", async () => {
|
|
136
128
|
const api = new ServiceClient({
|
|
137
|
-
intercept:
|
|
138
|
-
return { ok: true, status: 200, body: "{}" };
|
|
139
|
-
}
|
|
129
|
+
intercept: interceptor(200, "{}"),
|
|
140
130
|
});
|
|
141
131
|
const res = await api.get_task("{}").combine();
|
|
142
132
|
expect(res.ok).toBe(true);
|
|
@@ -146,9 +136,7 @@ describe("ServiceClient", () => {
|
|
|
146
136
|
|
|
147
137
|
test("either should be false with non-200 response", async () => {
|
|
148
138
|
const api = new ServiceClient({
|
|
149
|
-
intercept:
|
|
150
|
-
return { ok: false, status: 400, body: "{}" };
|
|
151
|
-
}
|
|
139
|
+
intercept: interceptor(400, "{}"),
|
|
152
140
|
});
|
|
153
141
|
const res = await api.get_task("{}").combine();
|
|
154
142
|
expect(res.ok).toBe(false);
|
|
@@ -158,9 +146,7 @@ describe("ServiceClient", () => {
|
|
|
158
146
|
|
|
159
147
|
test("either should be false with matching code", async () => {
|
|
160
148
|
const api = new ServiceClient({
|
|
161
|
-
intercept:
|
|
162
|
-
return { ok: false, status: 400, body: "{}" };
|
|
163
|
-
}
|
|
149
|
+
intercept: interceptor(400, "{}"),
|
|
164
150
|
});
|
|
165
151
|
const res = await api.get_task("{}").combine(400);
|
|
166
152
|
expect(res.ok).toBe(false);
|
|
@@ -169,9 +155,7 @@ describe("ServiceClient", () => {
|
|
|
169
155
|
|
|
170
156
|
test("method should throw if code is not specified", async () => {
|
|
171
157
|
const api = new ServiceClient({
|
|
172
|
-
intercept:
|
|
173
|
-
return { ok: false, status: 400, body: "{}" };
|
|
174
|
-
}
|
|
158
|
+
intercept: interceptor(400, "{}"),
|
|
175
159
|
});
|
|
176
160
|
const promise = api.get_task("").combine(500);
|
|
177
161
|
expect(promise).rejects.toThrow();
|
|
File without changes
|