@compassdigital/sdk.typescript 3.0.0-beta.18 → 3.0.0-beta.20
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/lib/base.d.ts +5 -4
- package/lib/base.d.ts.map +1 -1
- package/lib/base.js +53 -13
- package/lib/base.js.map +1 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -1
- package/lib/interface/location.d.ts +1 -0
- package/lib/interface/location.d.ts.map +1 -1
- package/lib/interface/menu.d.ts +17 -3
- package/lib/interface/menu.d.ts.map +1 -1
- package/lib/interface/order.d.ts +1 -0
- package/lib/interface/order.d.ts.map +1 -1
- package/lib/interface/partner.d.ts +220 -3
- package/lib/interface/partner.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/base.ts +57 -21
- package/src/index.ts +22 -0
- package/src/interface/location.ts +2 -0
- package/src/interface/menu.ts +25 -3
- package/src/interface/order.ts +2 -0
- package/src/interface/partner.ts +254 -4
- package/test/client.test.ts +33 -5
package/src/interface/partner.ts
CHANGED
|
@@ -291,6 +291,8 @@ export interface LocationGroup {
|
|
|
291
291
|
brand?: string;
|
|
292
292
|
// location
|
|
293
293
|
location?: string;
|
|
294
|
+
// location group
|
|
295
|
+
group?: string;
|
|
294
296
|
// payment
|
|
295
297
|
payment_provider?: string;
|
|
296
298
|
location_description?: string;
|
|
@@ -397,6 +399,235 @@ export type Hours = any;
|
|
|
397
399
|
|
|
398
400
|
export type DeliveryHours = any;
|
|
399
401
|
|
|
402
|
+
export interface Menu {
|
|
403
|
+
// menu
|
|
404
|
+
id?: string;
|
|
405
|
+
date?: {
|
|
406
|
+
created?: string;
|
|
407
|
+
modified?: string;
|
|
408
|
+
published?: string;
|
|
409
|
+
};
|
|
410
|
+
label?: {
|
|
411
|
+
en?: string;
|
|
412
|
+
};
|
|
413
|
+
groups?: {
|
|
414
|
+
// group
|
|
415
|
+
id?: string;
|
|
416
|
+
label?: {
|
|
417
|
+
en?: string;
|
|
418
|
+
fr?: string;
|
|
419
|
+
};
|
|
420
|
+
items?: {
|
|
421
|
+
// item
|
|
422
|
+
id?: string;
|
|
423
|
+
label?: {
|
|
424
|
+
en?: string;
|
|
425
|
+
};
|
|
426
|
+
description?: {
|
|
427
|
+
en?: string;
|
|
428
|
+
};
|
|
429
|
+
price?: {
|
|
430
|
+
amount?: number;
|
|
431
|
+
currency?: string;
|
|
432
|
+
};
|
|
433
|
+
// Meal exchange value of the item
|
|
434
|
+
meal_value?: number;
|
|
435
|
+
sale_price?: {
|
|
436
|
+
amount?: number;
|
|
437
|
+
currency?: string;
|
|
438
|
+
};
|
|
439
|
+
// The number of units that belong to this item. For example, a dozen doughnuts should have a unit value of 12
|
|
440
|
+
unit?: number;
|
|
441
|
+
ingredients?: any[];
|
|
442
|
+
amount_off_exclusions?: string[];
|
|
443
|
+
nutrition?: {
|
|
444
|
+
kcal?: number;
|
|
445
|
+
calories?: any;
|
|
446
|
+
serving_size?: any;
|
|
447
|
+
total_fat?: any;
|
|
448
|
+
saturated_fat?: any;
|
|
449
|
+
trans_fat?: any;
|
|
450
|
+
cholesterol?: any;
|
|
451
|
+
sodium?: {
|
|
452
|
+
amount?: number;
|
|
453
|
+
unit?: string;
|
|
454
|
+
};
|
|
455
|
+
total_carbohydrate?: any;
|
|
456
|
+
dietary_fiber?: any;
|
|
457
|
+
sugars?: any;
|
|
458
|
+
protein?: any;
|
|
459
|
+
well_being?: any;
|
|
460
|
+
[index: string]: any;
|
|
461
|
+
};
|
|
462
|
+
certified?: {
|
|
463
|
+
vegan?: boolean;
|
|
464
|
+
vegetarian?: boolean;
|
|
465
|
+
seafood_watch?: boolean;
|
|
466
|
+
wellbeing?: boolean;
|
|
467
|
+
farm_to_fork?: boolean;
|
|
468
|
+
in_balance?: boolean;
|
|
469
|
+
organic?: boolean;
|
|
470
|
+
no_gluten_ingredients?: boolean;
|
|
471
|
+
halal?: boolean;
|
|
472
|
+
kosher?: boolean;
|
|
473
|
+
humane?: boolean;
|
|
474
|
+
locally_crafted?: boolean;
|
|
475
|
+
nuts?: boolean;
|
|
476
|
+
oracle_garden_grown?: boolean;
|
|
477
|
+
oracle_oyes?: boolean;
|
|
478
|
+
peanut_free?: boolean;
|
|
479
|
+
tree_nut_free?: boolean;
|
|
480
|
+
wheat_free?: boolean;
|
|
481
|
+
non_gmo?: boolean;
|
|
482
|
+
milk_free?: boolean;
|
|
483
|
+
egg_free?: boolean;
|
|
484
|
+
soy_free?: boolean;
|
|
485
|
+
fair_trade?: boolean;
|
|
486
|
+
rainforest_alliance?: boolean;
|
|
487
|
+
salt_free?: boolean;
|
|
488
|
+
};
|
|
489
|
+
options?: {
|
|
490
|
+
// modifier_group
|
|
491
|
+
id?: string;
|
|
492
|
+
label?: {
|
|
493
|
+
en?: string;
|
|
494
|
+
};
|
|
495
|
+
unique_name?: string;
|
|
496
|
+
items?: {
|
|
497
|
+
// option
|
|
498
|
+
id?: string;
|
|
499
|
+
label?: {
|
|
500
|
+
en?: string;
|
|
501
|
+
};
|
|
502
|
+
price?: {
|
|
503
|
+
amount?: number;
|
|
504
|
+
currency?: string;
|
|
505
|
+
};
|
|
506
|
+
sku?: number;
|
|
507
|
+
nutrition?: {
|
|
508
|
+
kcal?: number;
|
|
509
|
+
calories?: any;
|
|
510
|
+
};
|
|
511
|
+
certified?: {
|
|
512
|
+
vegan?: boolean;
|
|
513
|
+
};
|
|
514
|
+
modifier_sets?: {
|
|
515
|
+
category?: string;
|
|
516
|
+
list?: string[];
|
|
517
|
+
}[];
|
|
518
|
+
meta?: {
|
|
519
|
+
// chit sort order
|
|
520
|
+
sort_number?: number;
|
|
521
|
+
// menu sort order
|
|
522
|
+
menu_sort_number?: number;
|
|
523
|
+
[index: string]: any;
|
|
524
|
+
};
|
|
525
|
+
is?: {
|
|
526
|
+
disabled?: boolean;
|
|
527
|
+
hidden?: boolean;
|
|
528
|
+
out_of_stock?: boolean;
|
|
529
|
+
};
|
|
530
|
+
amount_off_exclusions?: any[];
|
|
531
|
+
}[];
|
|
532
|
+
min?: number;
|
|
533
|
+
max?: number;
|
|
534
|
+
is?: {
|
|
535
|
+
disabled?: boolean;
|
|
536
|
+
hidden?: boolean;
|
|
537
|
+
out_of_stock?: boolean;
|
|
538
|
+
};
|
|
539
|
+
meta?: {
|
|
540
|
+
// chit sort order
|
|
541
|
+
sort_number?: number;
|
|
542
|
+
// menu sort order
|
|
543
|
+
menu_sort_number?: number;
|
|
544
|
+
[index: string]: any;
|
|
545
|
+
};
|
|
546
|
+
[index: string]: any;
|
|
547
|
+
}[];
|
|
548
|
+
required?: boolean;
|
|
549
|
+
special?: boolean;
|
|
550
|
+
meta?: {
|
|
551
|
+
superplate?: {
|
|
552
|
+
type_id?: number;
|
|
553
|
+
type?: string;
|
|
554
|
+
};
|
|
555
|
+
featured?: {
|
|
556
|
+
sort_number?: number;
|
|
557
|
+
dates?: {
|
|
558
|
+
start?: string;
|
|
559
|
+
end?: string;
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
// chit sort order
|
|
563
|
+
sort_number?: number;
|
|
564
|
+
// menu sort order
|
|
565
|
+
menu_sort_number?: number;
|
|
566
|
+
};
|
|
567
|
+
category?: {
|
|
568
|
+
en?: string;
|
|
569
|
+
};
|
|
570
|
+
location?: string;
|
|
571
|
+
sku?: number;
|
|
572
|
+
item_number?: number;
|
|
573
|
+
image?: {
|
|
574
|
+
src?: string;
|
|
575
|
+
};
|
|
576
|
+
is_deleted?: boolean;
|
|
577
|
+
is?: {
|
|
578
|
+
disabled?: boolean;
|
|
579
|
+
hidden?: boolean;
|
|
580
|
+
meq_eligible?: boolean;
|
|
581
|
+
out_of_stock?: boolean;
|
|
582
|
+
deleted?: boolean;
|
|
583
|
+
featured?: boolean;
|
|
584
|
+
};
|
|
585
|
+
}[];
|
|
586
|
+
is_disabled?: boolean;
|
|
587
|
+
name?: string;
|
|
588
|
+
is?: {
|
|
589
|
+
disabled?: boolean;
|
|
590
|
+
hidden?: boolean;
|
|
591
|
+
};
|
|
592
|
+
meta?: {
|
|
593
|
+
// chit sort order
|
|
594
|
+
sort_number?: number;
|
|
595
|
+
// menu sort order
|
|
596
|
+
menu_sort_number?: number;
|
|
597
|
+
[index: string]: any;
|
|
598
|
+
};
|
|
599
|
+
}[];
|
|
600
|
+
// menu
|
|
601
|
+
parent_id?: string;
|
|
602
|
+
// brand
|
|
603
|
+
location_brand?: string;
|
|
604
|
+
// company
|
|
605
|
+
company?: string;
|
|
606
|
+
// sector
|
|
607
|
+
sector?: string;
|
|
608
|
+
is?: {
|
|
609
|
+
disabled?: boolean;
|
|
610
|
+
hidden?: boolean;
|
|
611
|
+
linked?: boolean;
|
|
612
|
+
promo_exemptions_enabled?: boolean;
|
|
613
|
+
plu_enabled?: boolean;
|
|
614
|
+
item_images_enabled?: boolean;
|
|
615
|
+
item_showcase_enabled?: boolean;
|
|
616
|
+
item_desc_edit_enabled?: boolean;
|
|
617
|
+
calories_edit_enabled?: boolean;
|
|
618
|
+
item_label_edit_enabled?: boolean;
|
|
619
|
+
};
|
|
620
|
+
meta?: {
|
|
621
|
+
// User ID
|
|
622
|
+
locked_by_user?: string;
|
|
623
|
+
// User ID
|
|
624
|
+
last_modified_user?: string;
|
|
625
|
+
[index: string]: any;
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export type Group = any;
|
|
630
|
+
|
|
400
631
|
export interface CognitionStore {
|
|
401
632
|
// UUID for external store
|
|
402
633
|
uuid?: string;
|
|
@@ -433,14 +664,14 @@ export type CoolrImages = any[];
|
|
|
433
664
|
// POST /partner/standardcognition/shoppingcart - Calculates a shoppingcart
|
|
434
665
|
|
|
435
666
|
export interface PostPartnerStandardcognitionShoppingcartBody {
|
|
436
|
-
items
|
|
667
|
+
items: {
|
|
437
668
|
sku?: string;
|
|
438
669
|
quantity?: number;
|
|
439
670
|
}[];
|
|
440
671
|
// brand
|
|
441
|
-
location_brand
|
|
442
|
-
// shoppingcart
|
|
443
|
-
shoppingcart
|
|
672
|
+
location_brand: string;
|
|
673
|
+
// CDL shoppingcart id. If provided, items will be added to this shoppingcart
|
|
674
|
+
shoppingcart: string;
|
|
444
675
|
}
|
|
445
676
|
|
|
446
677
|
export type PostPartnerStandardcognitionShoppingcartResponse = ShoppingCart;
|
|
@@ -463,6 +694,25 @@ export type GetPartnerStandardcognitionStoresResponse = CognitionStore;
|
|
|
463
694
|
|
|
464
695
|
export type GetPartnerStandardcognitionStoresRequest = {};
|
|
465
696
|
|
|
697
|
+
// POST /partner/standardcognition/menu - Create new Standard Cognition menu from JSON files
|
|
698
|
+
|
|
699
|
+
export interface PostPartnerStandardcognitionMenuBody {
|
|
700
|
+
// CDL company ID
|
|
701
|
+
company: string;
|
|
702
|
+
// CDL sector ID
|
|
703
|
+
sector: string;
|
|
704
|
+
// CDL location brand ID
|
|
705
|
+
location_brand: string;
|
|
706
|
+
// Link for S3 menu file provided by Standard Cognition
|
|
707
|
+
s3_link: string;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export type PostPartnerStandardcognitionMenuResponse = Menu;
|
|
711
|
+
|
|
712
|
+
export interface PostPartnerStandardcognitionMenuRequest {
|
|
713
|
+
body: PostPartnerStandardcognitionMenuBody;
|
|
714
|
+
}
|
|
715
|
+
|
|
466
716
|
// GET /partner/coolr/locations - Gets the locations where Coolr is available
|
|
467
717
|
|
|
468
718
|
export interface GetPartnerCoolrLocationsResponse {
|
package/test/client.test.ts
CHANGED
|
@@ -4,16 +4,19 @@ import { Task } from "../src/interface/task";
|
|
|
4
4
|
|
|
5
5
|
describe("ServiceClient", () => {
|
|
6
6
|
|
|
7
|
-
function response(status: number, body?: any): ResponseData {
|
|
8
|
-
const res = { ok: status === 200, status: status, body: "" };
|
|
7
|
+
function response(status: number, body?: any, err?: any): ResponseData {
|
|
8
|
+
const res = { ok: status === 200, status: status, body: "", err: undefined };
|
|
9
9
|
if (body) {
|
|
10
10
|
res.body = JSON.stringify(body);
|
|
11
11
|
}
|
|
12
|
+
if (err) {
|
|
13
|
+
res.err = err;
|
|
14
|
+
}
|
|
12
15
|
return res;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
function interceptor(status: number, body?: any): InterceptFn {
|
|
16
|
-
return (req: RequestData) => Promise.resolve(response(status, body));
|
|
18
|
+
function interceptor(status: number, body?: any, err?: any): InterceptFn {
|
|
19
|
+
return (req: RequestData) => Promise.resolve(response(status, body, err));
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
test("makes basic request", async () => {
|
|
@@ -67,7 +70,7 @@ describe("ServiceClient", () => {
|
|
|
67
70
|
});
|
|
68
71
|
});
|
|
69
72
|
|
|
70
|
-
test("client retries on
|
|
73
|
+
test("client retries on bad status codes", async () => {
|
|
71
74
|
const intercept = jest.fn(async (req: RequestData) => {
|
|
72
75
|
if (intercept.mock.calls.length === 3) {
|
|
73
76
|
return response(200, "{}");
|
|
@@ -79,6 +82,18 @@ describe("ServiceClient", () => {
|
|
|
79
82
|
expect(intercept.mock.calls.length).toBe(3);
|
|
80
83
|
});
|
|
81
84
|
|
|
85
|
+
test("client retries on network error", async () => {
|
|
86
|
+
const intercept = jest.fn(async (req: RequestData) => {
|
|
87
|
+
if (intercept.mock.calls.length === 3) {
|
|
88
|
+
return response(200, "{}");
|
|
89
|
+
}
|
|
90
|
+
return response(0, "", new Error("network error"));
|
|
91
|
+
});
|
|
92
|
+
const api = new ServiceClient({ intercept });
|
|
93
|
+
const task = await api.get_task("", { retry: 2 });
|
|
94
|
+
expect(intercept.mock.calls.length).toBe(3);
|
|
95
|
+
});
|
|
96
|
+
|
|
82
97
|
test("client gives up after retry limit", async () => {
|
|
83
98
|
const intercept = jest.fn(interceptor(500));
|
|
84
99
|
const api = new ServiceClient({ intercept });
|
|
@@ -124,6 +139,19 @@ describe("ServiceClient", () => {
|
|
|
124
139
|
}
|
|
125
140
|
});
|
|
126
141
|
|
|
142
|
+
test("throws ServiceError for network errors", async () => {
|
|
143
|
+
const api = new ServiceClient({
|
|
144
|
+
intercept: interceptor(0, null, new Error("Network Error")),
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
await api.get_task("");
|
|
148
|
+
} catch (err) {
|
|
149
|
+
expect(err).toBeInstanceOf(ServiceError);
|
|
150
|
+
expect(ServiceError.status(err)).toBe(0);
|
|
151
|
+
expect(ServiceError.code(err)).toBe(0);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
127
155
|
test("either should be true with 200 response", async () => {
|
|
128
156
|
const api = new ServiceClient({
|
|
129
157
|
intercept: interceptor(200, "{}"),
|