@zappie/sdk 0.18.0 → 0.19.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/CHANGELOG.md +14 -0
- package/dist/account/index.js +1 -5
- package/dist/account/index.js.map +1 -1
- package/dist/account/url.js +1 -23
- package/dist/account/url.js.map +1 -1
- package/dist/branches/index.js +1 -43
- package/dist/branches/index.js.map +1 -1
- package/dist/cart/branch.js +1 -82
- package/dist/cart/branch.js.map +1 -1
- package/dist/cart/errors.js +1 -12
- package/dist/cart/errors.js.map +1 -1
- package/dist/cart/held.js +1 -17
- package/dist/cart/held.js.map +1 -1
- package/dist/cart/index.js +1 -782
- package/dist/cart/index.js.map +1 -1
- package/dist/cart/item.js +1 -11
- package/dist/cart/item.js.map +1 -1
- package/dist/cart/preview.js +1 -31
- package/dist/cart/preview.js.map +1 -1
- package/dist/cart/price.js +1 -24
- package/dist/cart/price.js.map +1 -1
- package/dist/cart/quote-client.js +1 -107
- package/dist/cart/quote-client.js.map +1 -1
- package/dist/cart/quote-response.js +1 -214
- package/dist/cart/quote-response.js.map +1 -1
- package/dist/cart/reconcile.js +1 -107
- package/dist/cart/reconcile.js.map +1 -1
- package/dist/cart/source-menu.js +1 -20
- package/dist/cart/source-menu.js.map +1 -1
- package/dist/cart/storage.js +1 -175
- package/dist/cart/storage.js.map +1 -1
- package/dist/cart/validate.js +1 -270
- package/dist/cart/validate.js.map +1 -1
- package/dist/cart/wire.js +1 -42
- package/dist/cart/wire.js.map +1 -1
- package/dist/cart/working-set.js +1 -79
- package/dist/cart/working-set.js.map +1 -1
- package/dist/checkout/client.js +1 -116
- package/dist/checkout/client.js.map +1 -1
- package/dist/checkout/embed.js +1 -247
- package/dist/checkout/embed.js.map +1 -1
- package/dist/checkout/error.js +1 -19
- package/dist/checkout/error.js.map +1 -1
- package/dist/checkout/index.js +1 -12
- package/dist/checkout/index.js.map +1 -1
- package/dist/checkout/react.js +1 -45
- package/dist/checkout/react.js.map +1 -1
- package/dist/checkout/readiness.js +1 -35
- package/dist/checkout/readiness.js.map +1 -1
- package/dist/checkout/sdk.js +1 -8
- package/dist/checkout/sdk.js.map +1 -1
- package/dist/checkout/session.js +1 -57
- package/dist/checkout/session.js.map +1 -1
- package/dist/checkout-defaults/index.js +1 -205
- package/dist/checkout-defaults/index.js.map +1 -1
- package/dist/client.js +1 -255
- package/dist/client.js.map +1 -1
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +1 -12
- package/dist/config/index.js.map +1 -1
- package/dist/config.js +1 -27
- package/dist/config.js.map +1 -1
- package/dist/customer/client.js +1 -180
- package/dist/customer/client.js.map +1 -1
- package/dist/customer/error.js +1 -18
- package/dist/customer/error.js.map +1 -1
- package/dist/customer/index.js +1 -7
- package/dist/customer/index.js.map +1 -1
- package/dist/customer/navigation.js +1 -39
- package/dist/customer/navigation.js.map +1 -1
- package/dist/customer/react.js +1 -69
- package/dist/customer/react.js.map +1 -1
- package/dist/customer/reorder.js +1 -60
- package/dist/customer/reorder.js.map +1 -1
- package/dist/customer/request.js +1 -37
- package/dist/customer/request.js.map +1 -1
- package/dist/customer/watch-order.js +1 -79
- package/dist/customer/watch-order.js.map +1 -1
- package/dist/debug.js +1 -77
- package/dist/debug.js.map +1 -1
- package/dist/display/index.js +1 -30
- package/dist/display/index.js.map +1 -1
- package/dist/error-pages/art.js +1 -10
- package/dist/error-pages/art.js.map +1 -1
- package/dist/error-pages/index.js +2 -103
- package/dist/error-pages/index.js.map +1 -1
- package/dist/error-pages/react.js +1 -65
- package/dist/error-pages/react.js.map +1 -1
- package/dist/errors.js +1 -70
- package/dist/errors.js.map +1 -1
- package/dist/in-venue/bill.js +1 -69
- package/dist/in-venue/bill.js.map +1 -1
- package/dist/in-venue/client.js +1 -119
- package/dist/in-venue/client.js.map +1 -1
- package/dist/in-venue/error.js +1 -18
- package/dist/in-venue/error.js.map +1 -1
- package/dist/in-venue/index.js +1 -23
- package/dist/in-venue/index.js.map +1 -1
- package/dist/in-venue/react/bill-page.js +1 -350
- package/dist/in-venue/react/bill-page.js.map +1 -1
- package/dist/in-venue/react/in-venue-page.js +1 -102
- package/dist/in-venue/react/in-venue-page.js.map +1 -1
- package/dist/in-venue/react/order-panel.js +1 -283
- package/dist/in-venue/react/order-panel.js.map +1 -1
- package/dist/in-venue/react/pay-point-page.js +1 -50
- package/dist/in-venue/react/pay-point-page.js.map +1 -1
- package/dist/in-venue/react/shared.js +2 -171
- package/dist/in-venue/react/shared.js.map +1 -1
- package/dist/in-venue/react/table-menus-page.js +1 -151
- package/dist/in-venue/react/table-menus-page.js.map +1 -1
- package/dist/in-venue/react.js +1 -14
- package/dist/in-venue/react.js.map +1 -1
- package/dist/in-venue/table.js +1 -62
- package/dist/in-venue/table.js.map +1 -1
- package/dist/in-venue/watch.js +1 -82
- package/dist/in-venue/watch.js.map +1 -1
- package/dist/index.js +1 -31
- package/dist/index.js.map +1 -1
- package/dist/integrations/index.js +1 -78
- package/dist/integrations/index.js.map +1 -1
- package/dist/internal/abort.js +1 -28
- package/dist/internal/abort.js.map +1 -1
- package/dist/internal/cache.js +1 -141
- package/dist/internal/cache.js.map +1 -1
- package/dist/internal/customer-http.js +1 -75
- package/dist/internal/customer-http.js.map +1 -1
- package/dist/internal/emitter.js +1 -26
- package/dist/internal/emitter.js.map +1 -1
- package/dist/internal/image-widths.js +1 -5
- package/dist/internal/image-widths.js.map +1 -1
- package/dist/internal/money-math.js +1 -29
- package/dist/internal/money-math.js.map +1 -1
- package/dist/internal/perk-hold.js +1 -34
- package/dist/internal/perk-hold.js.map +1 -1
- package/dist/internal/remembered-address.js +1 -68
- package/dist/internal/remembered-address.js.map +1 -1
- package/dist/internal/return-path.js +1 -16
- package/dist/internal/return-path.js.map +1 -1
- package/dist/internal/service-url.js +1 -10
- package/dist/internal/service-url.js.map +1 -1
- package/dist/internal.js +1 -8
- package/dist/internal.js.map +1 -1
- package/dist/loyalty/cart.js +1 -55
- package/dist/loyalty/cart.js.map +1 -1
- package/dist/loyalty/client.js +1 -88
- package/dist/loyalty/client.js.map +1 -1
- package/dist/loyalty/index.js +1 -12
- package/dist/loyalty/index.js.map +1 -1
- package/dist/loyalty/react.js +1 -199
- package/dist/loyalty/react.js.map +1 -1
- package/dist/loyalty/release.js +1 -42
- package/dist/loyalty/release.js.map +1 -1
- package/dist/money.js +1 -46
- package/dist/money.js.map +1 -1
- package/dist/navigation/index.js +1 -55
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/react.js +1 -17
- package/dist/navigation/react.js.map +1 -1
- package/dist/navigation-progress/index.js +1 -41
- package/dist/navigation-progress/index.js.map +1 -1
- package/dist/options/index.js +1 -103
- package/dist/options/index.js.map +1 -1
- package/dist/persist/catalogue.js +1 -205
- package/dist/persist/catalogue.js.map +1 -1
- package/dist/places/client.js +1 -96
- package/dist/places/client.js.map +1 -1
- package/dist/places/error.js +1 -18
- package/dist/places/error.js.map +1 -1
- package/dist/places/index.js +1 -7
- package/dist/places/index.js.map +1 -1
- package/dist/places/request.js +1 -39
- package/dist/places/request.js.map +1 -1
- package/dist/places/sdk.js +1 -9
- package/dist/places/sdk.js.map +1 -1
- package/dist/places/search.js +1 -79
- package/dist/places/search.js.map +1 -1
- package/dist/pricing/index.js +1 -80
- package/dist/pricing/index.js.map +1 -1
- package/dist/react/cart.js +1 -40
- package/dist/react/cart.js.map +1 -1
- package/dist/react/changes.js +1 -93
- package/dist/react/changes.js.map +1 -1
- package/dist/react/hooks.js +1 -90
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/index.js +1 -19
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.js +1 -33
- package/dist/react/provider.js.map +1 -1
- package/dist/react/rollback.js +1 -89
- package/dist/react/rollback.js.map +1 -1
- package/dist/receipts/index.js +1 -48
- package/dist/receipts/index.js.map +1 -1
- package/dist/redirect/index.js +1 -30
- package/dist/redirect/index.js.map +1 -1
- package/dist/server/auth/crypto.js +1 -105
- package/dist/server/auth/crypto.js.map +1 -1
- package/dist/server/auth/jwt.js +1 -203
- package/dist/server/auth/jwt.js.map +1 -1
- package/dist/server/auth/session-store.js +1 -45
- package/dist/server/auth/session-store.js.map +1 -1
- package/dist/server/chosen-branch.js +1 -69
- package/dist/server/chosen-branch.js.map +1 -1
- package/dist/server/edge-cache.js +1 -394
- package/dist/server/edge-cache.js.map +1 -1
- package/dist/server/edge-snapshot.js +1 -199
- package/dist/server/edge-snapshot.js.map +1 -1
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +1 -113
- package/dist/server/index.js.map +1 -1
- package/dist/server/security.js +1 -135
- package/dist/server/security.js.map +1 -1
- package/dist/server/sign-in.js +1 -17
- package/dist/server/sign-in.js.map +1 -1
- package/dist/server/storefront-url/build-v1.js +1 -65
- package/dist/server/storefront-url/build-v1.js.map +1 -1
- package/dist/server/storefront-url/build-v2.js +1 -50
- package/dist/server/storefront-url/build-v2.js.map +1 -1
- package/dist/server/storefront-url/build.js +1 -18
- package/dist/server/storefront-url/build.js.map +1 -1
- package/dist/server/storefront-url/canonical.js +1 -35
- package/dist/server/storefront-url/canonical.js.map +1 -1
- package/dist/server/storefront-url/contract.js +1 -24
- package/dist/server/storefront-url/contract.js.map +1 -1
- package/dist/server/storefront-url/index.js +1 -15
- package/dist/server/storefront-url/index.js.map +1 -1
- package/dist/server/storefront-url/installation.js +1 -57
- package/dist/server/storefront-url/installation.js.map +1 -1
- package/dist/server/storefront-url/params.js +1 -88
- package/dist/server/storefront-url/params.js.map +1 -1
- package/dist/server/storefront-url/parse-v1.js +1 -137
- package/dist/server/storefront-url/parse-v1.js.map +1 -1
- package/dist/server/storefront-url/parse-v2.js +1 -84
- package/dist/server/storefront-url/parse-v2.js.map +1 -1
- package/dist/server/storefront-url/parse.js +1 -8
- package/dist/server/storefront-url/parse.js.map +1 -1
- package/dist/server/storefront-url/public-id.js +1 -7
- package/dist/server/storefront-url/public-id.js.map +1 -1
- package/dist/server/storefront-url/redirect.js +1 -43
- package/dist/server/storefront-url/redirect.js.map +1 -1
- package/dist/server/storefront-url/sign-in.js +1 -17
- package/dist/server/storefront-url/sign-in.js.map +1 -1
- package/dist/server/storefront-url/types.js +1 -55
- package/dist/server/storefront-url/types.js.map +1 -1
- package/dist/server/storefront-url/url.js +1 -73
- package/dist/server/storefront-url/url.js.map +1 -1
- package/dist/server/webhook.js +1 -95
- package/dist/server/webhook.js.map +1 -1
- package/dist/services/index.js +1 -18
- package/dist/services/index.js.map +1 -1
- package/dist/site-closed/index.js +1 -38
- package/dist/site-closed/index.js.map +1 -1
- package/dist/site-config/helpers.js +1 -58
- package/dist/site-config/helpers.js.map +1 -1
- package/dist/site-config/sections.js +1 -114
- package/dist/site-config/sections.js.map +1 -1
- package/dist/site-config/types.js +1 -31
- package/dist/site-config/types.js.map +1 -1
- package/dist/site-config/validate.js +1 -215
- package/dist/site-config/validate.js.map +1 -1
- package/dist/site-error/index.js +1 -32
- package/dist/site-error/index.js.map +1 -1
- package/dist/site-error/react.js +1 -14
- package/dist/site-error/react.js.map +1 -1
- package/dist/studio/index.js +1 -315
- package/dist/template/index.js +1 -88
- package/dist/template/index.js.map +1 -1
- package/dist/template/react.js +1 -111
- package/dist/template/react.js.map +1 -1
- package/dist/testing/index.js +1 -459
- package/dist/testing/loyalty.js +1 -109
- package/dist/testing/loyalty.js.map +1 -1
- package/dist/transport/category-page.js +1 -24
- package/dist/transport/category-page.js.map +1 -1
- package/dist/transport/mappers.js +1 -356
- package/dist/transport/mappers.js.map +1 -1
- package/dist/transport/presentation.js +1 -67
- package/dist/transport/presentation.js.map +1 -1
- package/dist/transport/quote-body.js +1 -23
- package/dist/transport/quote-body.js.map +1 -1
- package/dist/transport/rest.js +1 -327
- package/dist/transport/rest.js.map +1 -1
- package/dist/transport/search.js +1 -36
- package/dist/transport/search.js.map +1 -1
- package/dist/transport/selected-menu.js +1 -83
- package/dist/transport/selected-menu.js.map +1 -1
- package/dist/transport/store.js +1 -132
- package/dist/transport/store.js.map +1 -1
- package/dist/uploads/index.js +1 -36
- package/dist/uploads/index.js.map +1 -1
- package/dist/url/index.js +1 -15
- package/dist/url/index.js.map +1 -1
- package/dist/visits/index.js +1 -61
- package/dist/visits/index.js.map +1 -1
- package/dist/visits/page-views.js +1 -102
- package/dist/visits/page-views.js.map +1 -1
- package/dist/vite/index.js +3 -373
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -1,459 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { estimateUnitPrice } from "../cart/price.js";
|
|
3
|
-
import { validateLine } from "../cart/validate.js";
|
|
4
|
-
import { createZappie } from "../client.js";
|
|
5
|
-
import { ZappieError } from "../errors.js";
|
|
6
|
-
import { delay, throwIfAborted } from "../internal/abort.js";
|
|
7
|
-
import { multiplyMoney } from "../internal/money-math.js";
|
|
8
|
-
import { money } from "../money.js";
|
|
9
|
-
import { VERSION } from "../index.js";
|
|
10
|
-
import { createMockLoyalty } from "./loyalty.js";
|
|
11
|
-
function createMockZappie(input, opts = {}) {
|
|
12
|
-
const fixtures2 = structuredClone(input);
|
|
13
|
-
const before = async (method, ctx) => {
|
|
14
|
-
throwIfAborted(ctx.signal);
|
|
15
|
-
if (opts.latencyMs) {
|
|
16
|
-
await delay(opts.latencyMs, ctx.signal);
|
|
17
|
-
}
|
|
18
|
-
const code = opts.failWith?.[method];
|
|
19
|
-
if (code) {
|
|
20
|
-
throw new ZappieError(code, `Mock ${method} failure`);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const menu2 = (id) => {
|
|
24
|
-
const value = fixtures2.menus[id];
|
|
25
|
-
if (!value) {
|
|
26
|
-
throw new ZappieError("branch_not_found", "No fixture for this branch");
|
|
27
|
-
}
|
|
28
|
-
return structuredClone(value);
|
|
29
|
-
};
|
|
30
|
-
const transport = {
|
|
31
|
-
async quote(ctx, body) {
|
|
32
|
-
await before("quote", ctx);
|
|
33
|
-
const value = menu2(body.branch_id);
|
|
34
|
-
const branch = fixtures2.store.branches.find(
|
|
35
|
-
(b) => b.id === body.branch_id
|
|
36
|
-
);
|
|
37
|
-
const issues = [];
|
|
38
|
-
const lines = body.lines.map((line) => {
|
|
39
|
-
const item = value.items[line.item_id];
|
|
40
|
-
const input2 = {
|
|
41
|
-
itemId: line.item_id,
|
|
42
|
-
...line.menu_id !== void 0 ? { menuId: line.menu_id } : {},
|
|
43
|
-
quantity: line.quantity,
|
|
44
|
-
choices: line.options.map((c) => ({
|
|
45
|
-
groupId: c.group_id,
|
|
46
|
-
choiceId: c.choice_id,
|
|
47
|
-
quantity: c.quantity
|
|
48
|
-
})),
|
|
49
|
-
inputs: line.inputs,
|
|
50
|
-
...line.variant_id ? { variantId: line.variant_id } : {}
|
|
51
|
-
};
|
|
52
|
-
const invalid = validateLine(item, input2, { menu: value, branch });
|
|
53
|
-
issues.push(
|
|
54
|
-
...invalid.map((i) => ({
|
|
55
|
-
code: i.code,
|
|
56
|
-
severity: i.severity,
|
|
57
|
-
message: i.message,
|
|
58
|
-
line_id: line.line_id,
|
|
59
|
-
...i.groupId ? { group_id: i.groupId } : {},
|
|
60
|
-
fixes: []
|
|
61
|
-
}))
|
|
62
|
-
);
|
|
63
|
-
const price = item && !invalid.length ? estimateUnitPrice(item, input2) : money(0, fixtures2.store.currency);
|
|
64
|
-
return {
|
|
65
|
-
line_id: line.line_id,
|
|
66
|
-
unit_price: {
|
|
67
|
-
amount_minor: price.amountMinor,
|
|
68
|
-
currency: price.currency
|
|
69
|
-
},
|
|
70
|
-
line_total: {
|
|
71
|
-
amount_minor: multiplyMoney(price, line.quantity).amountMinor,
|
|
72
|
-
currency: price.currency
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
const subtotal = {
|
|
77
|
-
amount_minor: lines.reduce((n, l) => n + l.line_total.amount_minor, 0),
|
|
78
|
-
currency: fixtures2.store.currency
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
branch_id: body.branch_id,
|
|
82
|
-
lines,
|
|
83
|
-
subtotal,
|
|
84
|
-
total: subtotal,
|
|
85
|
-
charges: [],
|
|
86
|
-
discounts: [],
|
|
87
|
-
issues,
|
|
88
|
-
can_checkout: !issues.some((issue) => issue.severity === "blocking"),
|
|
89
|
-
checkout: issues.some((issue) => issue.severity === "blocking") ? { ready: false, reason: "issues" } : { ready: true },
|
|
90
|
-
menu_version: value.version,
|
|
91
|
-
expires_at: new Date(Date.now() + 3e5).toISOString()
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
async getStore(ctx) {
|
|
95
|
-
await before("getStore", ctx);
|
|
96
|
-
return structuredClone(fixtures2.store);
|
|
97
|
-
},
|
|
98
|
-
async getMenu(ctx) {
|
|
99
|
-
await before("getMenu", ctx);
|
|
100
|
-
const value = menu2(ctx.branchId);
|
|
101
|
-
return ctx.ifNoneMatch === value.version ? { notModified: true } : { menu: value, etag: value.version };
|
|
102
|
-
},
|
|
103
|
-
async getMenuVersion(ctx) {
|
|
104
|
-
await before("getMenuVersion", ctx);
|
|
105
|
-
const value = menu2(ctx.branchId);
|
|
106
|
-
return { version: value.version, availabilityHash: value.version };
|
|
107
|
-
},
|
|
108
|
-
async getItem(ctx) {
|
|
109
|
-
await before("getItem", ctx);
|
|
110
|
-
const value = menu2(ctx.branchId).items[ctx.itemId];
|
|
111
|
-
if (!value) {
|
|
112
|
-
throw new ZappieError("item_not_found", "Item not found");
|
|
113
|
-
}
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return createZappie({
|
|
118
|
-
store: fixtures2.store.slug,
|
|
119
|
-
key: "pk_test_fixture",
|
|
120
|
-
transport
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
var fulfilment = {
|
|
124
|
-
pickup: true,
|
|
125
|
-
delivery: true,
|
|
126
|
-
dineIn: false,
|
|
127
|
-
scheduling: false
|
|
128
|
-
};
|
|
129
|
-
var store = {
|
|
130
|
-
id: "biz_fixture",
|
|
131
|
-
slug: "default-store",
|
|
132
|
-
name: "Default storefront",
|
|
133
|
-
currency: "NGN",
|
|
134
|
-
timezone: "Africa/Lagos",
|
|
135
|
-
brand: {},
|
|
136
|
-
fulfilment,
|
|
137
|
-
paymentMethods: ["card"],
|
|
138
|
-
branches: [
|
|
139
|
-
{
|
|
140
|
-
id: "br_fixture",
|
|
141
|
-
slug: "main",
|
|
142
|
-
name: "Main",
|
|
143
|
-
openingTimes: [{ day: 1, opens: "08:00", closes: "22:00" }],
|
|
144
|
-
isOpen: true,
|
|
145
|
-
fulfilment
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
};
|
|
149
|
-
var menu = {
|
|
150
|
-
id: "menu_fixture",
|
|
151
|
-
branchId: "br_fixture",
|
|
152
|
-
name: "Menu",
|
|
153
|
-
version: "fixture-v1",
|
|
154
|
-
categories: [{ id: "cat_fixture", name: "Food", itemIds: ["item_fixture"] }],
|
|
155
|
-
items: {
|
|
156
|
-
item_fixture: {
|
|
157
|
-
id: "item_fixture",
|
|
158
|
-
name: "Lunch",
|
|
159
|
-
images: [],
|
|
160
|
-
price: money(65e4, "NGN"),
|
|
161
|
-
isAvailable: true,
|
|
162
|
-
quantity: { min: 1, step: 1 },
|
|
163
|
-
variants: [
|
|
164
|
-
{
|
|
165
|
-
id: "variant_fixture",
|
|
166
|
-
attributeChoices: {},
|
|
167
|
-
images: [],
|
|
168
|
-
price: money(65e4, "NGN"),
|
|
169
|
-
isAvailable: true
|
|
170
|
-
}
|
|
171
|
-
],
|
|
172
|
-
optionGroups: [],
|
|
173
|
-
tags: []
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var ngn = (amountMinor) => money(amountMinor, "NGN");
|
|
178
|
-
var templateStore = {
|
|
179
|
-
id: "biz_template",
|
|
180
|
-
slug: "default-template",
|
|
181
|
-
name: "Default template",
|
|
182
|
-
description: "A public storefront fixture for template authors.",
|
|
183
|
-
templateSettings: {
|
|
184
|
-
accent: "#175c3a",
|
|
185
|
-
headerPhoto: "https://example.com/default-template-cover.png"
|
|
186
|
-
},
|
|
187
|
-
currency: "NGN",
|
|
188
|
-
timezone: "Africa/Lagos",
|
|
189
|
-
brand: {
|
|
190
|
-
logoUrl: "https://example.com/default-template-logo.png",
|
|
191
|
-
coverImageUrl: "https://example.com/default-template-cover.png"
|
|
192
|
-
},
|
|
193
|
-
fulfilment: { pickup: true, delivery: true, dineIn: true, scheduling: true },
|
|
194
|
-
paymentMethods: ["card", "bank_transfer", "wallet"],
|
|
195
|
-
branches: [
|
|
196
|
-
{
|
|
197
|
-
id: "br_template_main",
|
|
198
|
-
slug: "main",
|
|
199
|
-
name: "Main",
|
|
200
|
-
timezone: "Africa/Lagos",
|
|
201
|
-
address: "1 Example Street, Lagos",
|
|
202
|
-
phone: "+234 800 000 0000",
|
|
203
|
-
pickupAddress: {
|
|
204
|
-
placeId: "place_template_main",
|
|
205
|
-
coordinates: { lat: 6.5244, lng: 3.3792 }
|
|
206
|
-
},
|
|
207
|
-
socialLinks: [
|
|
208
|
-
{ type: "INSTAGRAM", url: "https://instagram.com/default-template" },
|
|
209
|
-
{ type: "WEBSITE", url: "https://example.com" }
|
|
210
|
-
],
|
|
211
|
-
openingTimes: [1, 2, 3, 4, 5].map((day) => ({
|
|
212
|
-
day,
|
|
213
|
-
opens: "08:00",
|
|
214
|
-
closes: "22:00"
|
|
215
|
-
})),
|
|
216
|
-
isOpen: true,
|
|
217
|
-
isDefault: true,
|
|
218
|
-
orderAheadDays: 7,
|
|
219
|
-
fulfilment: {
|
|
220
|
-
pickup: true,
|
|
221
|
-
delivery: true,
|
|
222
|
-
dineIn: true,
|
|
223
|
-
scheduling: true
|
|
224
|
-
},
|
|
225
|
-
minimumOrder: ngn(2e5)
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
id: "br_template_island",
|
|
229
|
-
slug: "island",
|
|
230
|
-
name: "Island",
|
|
231
|
-
timezone: "Africa/Lagos",
|
|
232
|
-
openingTimes: [{ day: 6, opens: "10:00", closes: "18:00" }],
|
|
233
|
-
specialHours: [{ date: "2026-12-25", closed: true }],
|
|
234
|
-
isOpen: false,
|
|
235
|
-
closedUntil: "2026-12-26T10:00:00+01:00",
|
|
236
|
-
orderAheadDays: 0,
|
|
237
|
-
fulfilment: {
|
|
238
|
-
pickup: false,
|
|
239
|
-
delivery: true,
|
|
240
|
-
dineIn: false,
|
|
241
|
-
scheduling: false
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
]
|
|
245
|
-
};
|
|
246
|
-
var templateMenu = {
|
|
247
|
-
id: "menu_template",
|
|
248
|
-
branchId: "br_template_main",
|
|
249
|
-
name: "All day",
|
|
250
|
-
version: "template-v1",
|
|
251
|
-
categories: [
|
|
252
|
-
{
|
|
253
|
-
id: "cat_popular",
|
|
254
|
-
name: "Popular",
|
|
255
|
-
itemIds: ["item_jollof", "item_zobo"]
|
|
256
|
-
},
|
|
257
|
-
{ id: "cat_mains", name: "Mains", itemIds: ["item_jollof"] },
|
|
258
|
-
{
|
|
259
|
-
id: "cat_drinks",
|
|
260
|
-
name: "Drinks and desserts",
|
|
261
|
-
itemIds: ["item_zobo", "item_cake"]
|
|
262
|
-
}
|
|
263
|
-
],
|
|
264
|
-
items: {
|
|
265
|
-
item_jollof: {
|
|
266
|
-
id: "item_jollof",
|
|
267
|
-
name: "Jollof rice",
|
|
268
|
-
description: "Smoky party jollof.",
|
|
269
|
-
images: [],
|
|
270
|
-
price: ngn(45e4),
|
|
271
|
-
isAvailable: true,
|
|
272
|
-
quantity: { min: 1, max: 10, step: 1 },
|
|
273
|
-
variants: [
|
|
274
|
-
{
|
|
275
|
-
id: "variant_jollof",
|
|
276
|
-
attributeChoices: {},
|
|
277
|
-
images: [],
|
|
278
|
-
price: ngn(45e4),
|
|
279
|
-
isAvailable: true
|
|
280
|
-
}
|
|
281
|
-
],
|
|
282
|
-
optionGroups: [
|
|
283
|
-
{
|
|
284
|
-
id: "grp_protein",
|
|
285
|
-
name: "Protein",
|
|
286
|
-
kind: "select",
|
|
287
|
-
required: true,
|
|
288
|
-
selection: { min: 1, max: 1 },
|
|
289
|
-
isAttribute: false,
|
|
290
|
-
choices: [
|
|
291
|
-
{
|
|
292
|
-
id: "opt_chicken",
|
|
293
|
-
name: "Chicken",
|
|
294
|
-
price: ngn(0),
|
|
295
|
-
isAvailable: true
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
id: "opt_beef",
|
|
299
|
-
name: "Beef",
|
|
300
|
-
price: ngn(5e4),
|
|
301
|
-
isAvailable: true
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
id: "opt_fish",
|
|
305
|
-
name: "Fish",
|
|
306
|
-
price: ngn(8e4),
|
|
307
|
-
isAvailable: false
|
|
308
|
-
}
|
|
309
|
-
]
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
id: "grp_sauce",
|
|
313
|
-
name: "Sauce",
|
|
314
|
-
helpText: "Required with chicken.",
|
|
315
|
-
kind: "select",
|
|
316
|
-
required: false,
|
|
317
|
-
selection: { min: 0, max: 1 },
|
|
318
|
-
isAttribute: false,
|
|
319
|
-
choices: [
|
|
320
|
-
{
|
|
321
|
-
id: "opt_pepper",
|
|
322
|
-
name: "Pepper sauce",
|
|
323
|
-
price: ngn(0),
|
|
324
|
-
isAvailable: true
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
id: "opt_stew",
|
|
328
|
-
name: "Stew",
|
|
329
|
-
price: ngn(2e4),
|
|
330
|
-
isAvailable: true
|
|
331
|
-
}
|
|
332
|
-
],
|
|
333
|
-
conditions: [
|
|
334
|
-
{
|
|
335
|
-
groupId: "grp_protein",
|
|
336
|
-
choiceIds: ["opt_chicken"],
|
|
337
|
-
match: "any",
|
|
338
|
-
setRequired: true,
|
|
339
|
-
setMin: 1
|
|
340
|
-
}
|
|
341
|
-
]
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
id: "grp_extras",
|
|
345
|
-
name: "Extras",
|
|
346
|
-
kind: "select",
|
|
347
|
-
required: false,
|
|
348
|
-
selection: { min: 0, max: 3 },
|
|
349
|
-
isAttribute: false,
|
|
350
|
-
choices: [
|
|
351
|
-
{
|
|
352
|
-
id: "opt_plantain",
|
|
353
|
-
name: "Plantain",
|
|
354
|
-
price: ngn(3e4),
|
|
355
|
-
isAvailable: true,
|
|
356
|
-
quantity: { min: 1, max: 3 }
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
id: "opt_egg",
|
|
360
|
-
name: "Boiled egg",
|
|
361
|
-
price: ngn(15e3),
|
|
362
|
-
isAvailable: true
|
|
363
|
-
}
|
|
364
|
-
]
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
id: "grp_note",
|
|
368
|
-
name: "Note for the kitchen",
|
|
369
|
-
kind: "text",
|
|
370
|
-
required: false,
|
|
371
|
-
selection: { min: 0 },
|
|
372
|
-
isAttribute: false,
|
|
373
|
-
choices: [],
|
|
374
|
-
input: { maxLength: 140, placeholder: "No onions, please" }
|
|
375
|
-
}
|
|
376
|
-
],
|
|
377
|
-
tags: ["popular"]
|
|
378
|
-
},
|
|
379
|
-
item_zobo: {
|
|
380
|
-
id: "item_zobo",
|
|
381
|
-
name: "Zobo",
|
|
382
|
-
images: [],
|
|
383
|
-
price: ngn(12e4),
|
|
384
|
-
isAvailable: true,
|
|
385
|
-
quantity: { min: 1, step: 1 },
|
|
386
|
-
variants: [
|
|
387
|
-
{
|
|
388
|
-
id: "variant_zobo_small",
|
|
389
|
-
attributeChoices: { grp_size: "opt_small" },
|
|
390
|
-
images: [],
|
|
391
|
-
price: ngn(12e4),
|
|
392
|
-
isAvailable: true
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
id: "variant_zobo_large",
|
|
396
|
-
attributeChoices: { grp_size: "opt_large" },
|
|
397
|
-
images: [],
|
|
398
|
-
price: ngn(2e5),
|
|
399
|
-
isAvailable: false
|
|
400
|
-
}
|
|
401
|
-
],
|
|
402
|
-
optionGroups: [
|
|
403
|
-
{
|
|
404
|
-
id: "grp_size",
|
|
405
|
-
name: "Size",
|
|
406
|
-
kind: "select",
|
|
407
|
-
required: true,
|
|
408
|
-
selection: { min: 1, max: 1 },
|
|
409
|
-
isAttribute: true,
|
|
410
|
-
choices: [
|
|
411
|
-
{
|
|
412
|
-
id: "opt_small",
|
|
413
|
-
name: "Small",
|
|
414
|
-
price: ngn(0),
|
|
415
|
-
isAvailable: true
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
id: "opt_large",
|
|
419
|
-
name: "Large",
|
|
420
|
-
price: ngn(0),
|
|
421
|
-
isAvailable: false
|
|
422
|
-
}
|
|
423
|
-
]
|
|
424
|
-
}
|
|
425
|
-
],
|
|
426
|
-
tags: []
|
|
427
|
-
},
|
|
428
|
-
item_cake: {
|
|
429
|
-
id: "item_cake",
|
|
430
|
-
name: "Chocolate cake",
|
|
431
|
-
images: [],
|
|
432
|
-
price: ngn(35e4),
|
|
433
|
-
compareAtPrice: ngn(4e5),
|
|
434
|
-
isAvailable: false,
|
|
435
|
-
quantity: { min: 1, step: 1 },
|
|
436
|
-
variants: [
|
|
437
|
-
{
|
|
438
|
-
id: "variant_cake",
|
|
439
|
-
attributeChoices: {},
|
|
440
|
-
images: [],
|
|
441
|
-
price: ngn(35e4),
|
|
442
|
-
isAvailable: false
|
|
443
|
-
}
|
|
444
|
-
],
|
|
445
|
-
optionGroups: [],
|
|
446
|
-
tags: []
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
var fixtures = {
|
|
451
|
-
minimal: { store, menu },
|
|
452
|
-
defaultTemplate: { store: templateStore, menu: templateMenu }
|
|
453
|
-
};
|
|
454
|
-
export {
|
|
455
|
-
VERSION,
|
|
456
|
-
createMockLoyalty,
|
|
457
|
-
createMockZappie,
|
|
458
|
-
fixtures
|
|
459
|
-
};
|
|
1
|
+
import{estimateUnitPrice}from"../cart/price.js";import{validateLine}from"../cart/validate.js";import{createZappie}from"../client.js";import{ZappieError}from"../errors.js";import{delay,throwIfAborted}from"../internal/abort.js";import{multiplyMoney}from"../internal/money-math.js";import{money}from"../money.js";import{VERSION}from"../index.js";import{createMockLoyalty}from"./loyalty.js";function createMockZappie(input,opts={}){const fixtures2=structuredClone(input);const before=async(method,ctx)=>{throwIfAborted(ctx.signal);if(opts.latencyMs){await delay(opts.latencyMs,ctx.signal)}const code=opts.failWith?.[method];if(code){throw new ZappieError(code,`Mock ${method} failure`)}};const menu2=id=>{const value=fixtures2.menus[id];if(!value){throw new ZappieError("branch_not_found","No fixture for this branch")}return structuredClone(value)};const transport={async quote(ctx,body){await before("quote",ctx);const value=menu2(body.branch_id);const branch=fixtures2.store.branches.find(b=>b.id===body.branch_id);const issues=[];const lines=body.lines.map(line=>{const item=value.items[line.item_id];const input2={itemId:line.item_id,...line.menu_id!==void 0?{menuId:line.menu_id}:{},quantity:line.quantity,choices:line.options.map(c=>({groupId:c.group_id,choiceId:c.choice_id,quantity:c.quantity})),inputs:line.inputs,...line.variant_id?{variantId:line.variant_id}:{}};const invalid=validateLine(item,input2,{menu:value,branch});issues.push(...invalid.map(i=>({code:i.code,severity:i.severity,message:i.message,line_id:line.line_id,...i.groupId?{group_id:i.groupId}:{},fixes:[]})));const price=item&&!invalid.length?estimateUnitPrice(item,input2):money(0,fixtures2.store.currency);return{line_id:line.line_id,unit_price:{amount_minor:price.amountMinor,currency:price.currency},line_total:{amount_minor:multiplyMoney(price,line.quantity).amountMinor,currency:price.currency}}});const subtotal={amount_minor:lines.reduce((n,l)=>n+l.line_total.amount_minor,0),currency:fixtures2.store.currency};return{branch_id:body.branch_id,lines,subtotal,total:subtotal,charges:[],discounts:[],issues,can_checkout:!issues.some(issue=>issue.severity==="blocking"),checkout:issues.some(issue=>issue.severity==="blocking")?{ready:false,reason:"issues"}:{ready:true},menu_version:value.version,expires_at:new Date(Date.now()+3e5).toISOString()}},async getStore(ctx){await before("getStore",ctx);return structuredClone(fixtures2.store)},async getMenu(ctx){await before("getMenu",ctx);const value=menu2(ctx.branchId);return ctx.ifNoneMatch===value.version?{notModified:true}:{menu:value,etag:value.version}},async getMenuVersion(ctx){await before("getMenuVersion",ctx);const value=menu2(ctx.branchId);return{version:value.version,availabilityHash:value.version}},async getItem(ctx){await before("getItem",ctx);const value=menu2(ctx.branchId).items[ctx.itemId];if(!value){throw new ZappieError("item_not_found","Item not found")}return value}};return createZappie({store:fixtures2.store.slug,key:"pk_test_fixture",transport})}var fulfilment={pickup:true,delivery:true,dineIn:false,scheduling:false};var store={id:"biz_fixture",slug:"default-store",name:"Default storefront",currency:"NGN",timezone:"Africa/Lagos",brand:{},fulfilment,paymentMethods:["card"],branches:[{id:"br_fixture",slug:"main",name:"Main",openingTimes:[{day:1,opens:"08:00",closes:"22:00"}],isOpen:true,fulfilment}]};var menu={id:"menu_fixture",branchId:"br_fixture",name:"Menu",version:"fixture-v1",categories:[{id:"cat_fixture",name:"Food",itemIds:["item_fixture"]}],items:{item_fixture:{id:"item_fixture",name:"Lunch",images:[],price:money(65e4,"NGN"),isAvailable:true,quantity:{min:1,step:1},variants:[{id:"variant_fixture",attributeChoices:{},images:[],price:money(65e4,"NGN"),isAvailable:true}],optionGroups:[],tags:[]}}};var ngn=amountMinor=>money(amountMinor,"NGN");var templateStore={id:"biz_template",slug:"default-template",name:"Default template",description:"A public storefront fixture for template authors.",templateSettings:{accent:"#175c3a",headerPhoto:"https://example.com/default-template-cover.png"},currency:"NGN",timezone:"Africa/Lagos",brand:{logoUrl:"https://example.com/default-template-logo.png",coverImageUrl:"https://example.com/default-template-cover.png"},fulfilment:{pickup:true,delivery:true,dineIn:true,scheduling:true},paymentMethods:["card","bank_transfer","wallet"],branches:[{id:"br_template_main",slug:"main",name:"Main",timezone:"Africa/Lagos",address:"1 Example Street, Lagos",phone:"+234 800 000 0000",pickupAddress:{placeId:"place_template_main",coordinates:{lat:6.5244,lng:3.3792}},socialLinks:[{type:"INSTAGRAM",url:"https://instagram.com/default-template"},{type:"WEBSITE",url:"https://example.com"}],openingTimes:[1,2,3,4,5].map(day=>({day,opens:"08:00",closes:"22:00"})),isOpen:true,isDefault:true,orderAheadDays:7,fulfilment:{pickup:true,delivery:true,dineIn:true,scheduling:true},minimumOrder:ngn(2e5)},{id:"br_template_island",slug:"island",name:"Island",timezone:"Africa/Lagos",openingTimes:[{day:6,opens:"10:00",closes:"18:00"}],specialHours:[{date:"2026-12-25",closed:true}],isOpen:false,closedUntil:"2026-12-26T10:00:00+01:00",orderAheadDays:0,fulfilment:{pickup:false,delivery:true,dineIn:false,scheduling:false}}]};var templateMenu={id:"menu_template",branchId:"br_template_main",name:"All day",version:"template-v1",categories:[{id:"cat_popular",name:"Popular",itemIds:["item_jollof","item_zobo"]},{id:"cat_mains",name:"Mains",itemIds:["item_jollof"]},{id:"cat_drinks",name:"Drinks and desserts",itemIds:["item_zobo","item_cake"]}],items:{item_jollof:{id:"item_jollof",name:"Jollof rice",description:"Smoky party jollof.",images:[],price:ngn(45e4),isAvailable:true,quantity:{min:1,max:10,step:1},variants:[{id:"variant_jollof",attributeChoices:{},images:[],price:ngn(45e4),isAvailable:true}],optionGroups:[{id:"grp_protein",name:"Protein",kind:"select",required:true,selection:{min:1,max:1},isAttribute:false,choices:[{id:"opt_chicken",name:"Chicken",price:ngn(0),isAvailable:true},{id:"opt_beef",name:"Beef",price:ngn(5e4),isAvailable:true},{id:"opt_fish",name:"Fish",price:ngn(8e4),isAvailable:false}]},{id:"grp_sauce",name:"Sauce",helpText:"Required with chicken.",kind:"select",required:false,selection:{min:0,max:1},isAttribute:false,choices:[{id:"opt_pepper",name:"Pepper sauce",price:ngn(0),isAvailable:true},{id:"opt_stew",name:"Stew",price:ngn(2e4),isAvailable:true}],conditions:[{groupId:"grp_protein",choiceIds:["opt_chicken"],match:"any",setRequired:true,setMin:1}]},{id:"grp_extras",name:"Extras",kind:"select",required:false,selection:{min:0,max:3},isAttribute:false,choices:[{id:"opt_plantain",name:"Plantain",price:ngn(3e4),isAvailable:true,quantity:{min:1,max:3}},{id:"opt_egg",name:"Boiled egg",price:ngn(15e3),isAvailable:true}]},{id:"grp_note",name:"Note for the kitchen",kind:"text",required:false,selection:{min:0},isAttribute:false,choices:[],input:{maxLength:140,placeholder:"No onions, please"}}],tags:["popular"]},item_zobo:{id:"item_zobo",name:"Zobo",images:[],price:ngn(12e4),isAvailable:true,quantity:{min:1,step:1},variants:[{id:"variant_zobo_small",attributeChoices:{grp_size:"opt_small"},images:[],price:ngn(12e4),isAvailable:true},{id:"variant_zobo_large",attributeChoices:{grp_size:"opt_large"},images:[],price:ngn(2e5),isAvailable:false}],optionGroups:[{id:"grp_size",name:"Size",kind:"select",required:true,selection:{min:1,max:1},isAttribute:true,choices:[{id:"opt_small",name:"Small",price:ngn(0),isAvailable:true},{id:"opt_large",name:"Large",price:ngn(0),isAvailable:false}]}],tags:[]},item_cake:{id:"item_cake",name:"Chocolate cake",images:[],price:ngn(35e4),compareAtPrice:ngn(4e5),isAvailable:false,quantity:{min:1,step:1},variants:[{id:"variant_cake",attributeChoices:{},images:[],price:ngn(35e4),isAvailable:false}],optionGroups:[],tags:[]}}};var fixtures={minimal:{store,menu},defaultTemplate:{store:templateStore,menu:templateMenu}};export{VERSION,createMockLoyalty,createMockZappie,fixtures};
|
package/dist/testing/loyalty.js
CHANGED
|
@@ -1,110 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { ZappieError } from "../errors.js";
|
|
3
|
-
var MockLoyaltyError = class extends ZappieError {
|
|
4
|
-
constructor(status, apiCode, message) {
|
|
5
|
-
super(
|
|
6
|
-
status === 401 ? "unauthorized" : status === 404 ? "not_found" : apiCode === "scope_required" ? apiCode : status === 403 ? "forbidden" : "server_error",
|
|
7
|
-
message,
|
|
8
|
-
{ status }
|
|
9
|
-
);
|
|
10
|
-
this.apiCode = apiCode;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
function createMockLoyalty(options = {}) {
|
|
14
|
-
let points = options.points ?? 0;
|
|
15
|
-
let sequence = 0;
|
|
16
|
-
const reserved = /* @__PURE__ */ new Map();
|
|
17
|
-
const claimed = /* @__PURE__ */ new Set();
|
|
18
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
19
|
-
const changed = () => listeners.forEach((listener) => listener());
|
|
20
|
-
const check = async () => {
|
|
21
|
-
await Promise.resolve();
|
|
22
|
-
if (options.failWith) {
|
|
23
|
-
const status = options.failWith === "customer_required" ? 401 : options.failWith.endsWith("_required") || options.failWith === "feature_off" ? 403 : 409;
|
|
24
|
-
throw new MockLoyaltyError(
|
|
25
|
-
status,
|
|
26
|
-
options.failWith,
|
|
27
|
-
`Mock ${options.failWith}`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const client = {
|
|
32
|
-
base: "/_zappie/api",
|
|
33
|
-
async points() {
|
|
34
|
-
await check();
|
|
35
|
-
return {
|
|
36
|
-
object: "loyalty",
|
|
37
|
-
enabled: options.enabled ?? true,
|
|
38
|
-
points
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
async perks() {
|
|
42
|
-
await check();
|
|
43
|
-
return options.enabled === false ? [] : structuredClone(options.perks ?? []);
|
|
44
|
-
},
|
|
45
|
-
async redeem(perkId) {
|
|
46
|
-
await check();
|
|
47
|
-
const perk = options.perks?.find((candidate) => candidate.id === perkId);
|
|
48
|
-
if (!perk) {
|
|
49
|
-
throw new MockLoyaltyError(404, "perk_not_found", "No such perk");
|
|
50
|
-
}
|
|
51
|
-
if (points < perk.points_cost) {
|
|
52
|
-
throw new MockLoyaltyError(
|
|
53
|
-
409,
|
|
54
|
-
"insufficient_points",
|
|
55
|
-
"You don't have enough points for this perk."
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
points -= perk.points_cost;
|
|
59
|
-
const id = `rdm_mock${++sequence}`;
|
|
60
|
-
reserved.set(id, perk.points_cost);
|
|
61
|
-
changed();
|
|
62
|
-
return {
|
|
63
|
-
id,
|
|
64
|
-
object: "perk_redemption",
|
|
65
|
-
status: "reserved",
|
|
66
|
-
points_spent: perk.points_cost,
|
|
67
|
-
perk: { id: perk.id, name: perk.name },
|
|
68
|
-
expires_at: new Date(Date.now() + 864e5).toISOString()
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
async cancel(redemptionId) {
|
|
72
|
-
await check();
|
|
73
|
-
points += reserved.get(redemptionId) ?? 0;
|
|
74
|
-
reserved.delete(redemptionId);
|
|
75
|
-
changed();
|
|
76
|
-
},
|
|
77
|
-
async claim(orderId) {
|
|
78
|
-
await check();
|
|
79
|
-
const earned = claimed.has(orderId) ? 0 : options.claims?.[orderId] ?? 0;
|
|
80
|
-
claimed.add(orderId);
|
|
81
|
-
points += earned;
|
|
82
|
-
changed();
|
|
83
|
-
return {
|
|
84
|
-
object: "loyalty_claim",
|
|
85
|
-
order_id: orderId,
|
|
86
|
-
points_earned: earned,
|
|
87
|
-
points
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
async storeCredit() {
|
|
91
|
-
await check();
|
|
92
|
-
return options.storeCredit ?? {
|
|
93
|
-
object: "store_credit",
|
|
94
|
-
enabled: false,
|
|
95
|
-
balance: { amount_minor: 0, currency: "NGN" }
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
onChange(listener) {
|
|
99
|
-
listeners.add(listener);
|
|
100
|
-
return () => {
|
|
101
|
-
listeners.delete(listener);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
return client;
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
createMockLoyalty
|
|
109
|
-
};
|
|
1
|
+
import{ZappieError}from"../errors.js";var MockLoyaltyError=class extends ZappieError{constructor(status,apiCode,message){super(status===401?"unauthorized":status===404?"not_found":apiCode==="scope_required"?apiCode:status===403?"forbidden":"server_error",message,{status});this.apiCode=apiCode}};function createMockLoyalty(options={}){let points=options.points??0;let sequence=0;const reserved=new Map;const claimed=new Set;const listeners=new Set;const changed=()=>listeners.forEach(listener=>listener());const check=async()=>{await Promise.resolve();if(options.failWith){const status=options.failWith==="customer_required"?401:options.failWith.endsWith("_required")||options.failWith==="feature_off"?403:409;throw new MockLoyaltyError(status,options.failWith,`Mock ${options.failWith}`)}};const client={base:"/_zappie/api",async points(){await check();return{object:"loyalty",enabled:options.enabled??true,points}},async perks(){await check();return options.enabled===false?[]:structuredClone(options.perks??[])},async redeem(perkId){await check();const perk=options.perks?.find(candidate=>candidate.id===perkId);if(!perk){throw new MockLoyaltyError(404,"perk_not_found","No such perk")}if(points<perk.points_cost){throw new MockLoyaltyError(409,"insufficient_points","You don't have enough points for this perk.")}points-=perk.points_cost;const id=`rdm_mock${++sequence}`;reserved.set(id,perk.points_cost);changed();return{id,object:"perk_redemption",status:"reserved",points_spent:perk.points_cost,perk:{id:perk.id,name:perk.name},expires_at:new Date(Date.now()+864e5).toISOString()}},async cancel(redemptionId){await check();points+=reserved.get(redemptionId)??0;reserved.delete(redemptionId);changed()},async claim(orderId){await check();const earned=claimed.has(orderId)?0:options.claims?.[orderId]??0;claimed.add(orderId);points+=earned;changed();return{object:"loyalty_claim",order_id:orderId,points_earned:earned,points}},async storeCredit(){await check();return options.storeCredit??{object:"store_credit",enabled:false,balance:{amount_minor:0,currency:"NGN"}}},onChange(listener){listeners.add(listener);return()=>{listeners.delete(listener)}}};return client}export{createMockLoyalty};
|
|
110
2
|
//# sourceMappingURL=loyalty.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/testing/loyalty.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,OAAS,gBAAmB,eAW5B,IAAM,iBAAN,cAA+B,WAAY,CACzC,YACE,OACS,QACT,QACA,CACA,MACE,SAAW,IACP,eACA,SAAW,IACT,YACA,UAAY,iBACV,QACA,SAAW,IACT,YACA,eACV,QACA,CAAE,MAAO,CACX,EAfS,oBAgBX,CACF,EAmBO,SAAS,kBAAkB,QAA8B,CAAC,EAAG,CAClE,IAAI,OAAS,QAAQ,QAAU,EAC/B,IAAI,SAAW,EACf,MAAM,SAAW,IAAI,IACrB,MAAM,QAAU,IAAI,IACpB,MAAM,UAAY,IAAI,IACtB,MAAM,QAAU,IAAM,UAAU,QAAS,UAAa,SAAS,CAAC,EAChE,MAAM,MAAQ,SAAY,CACxB,MAAM,QAAQ,QAAQ,EACtB,GAAI,QAAQ,SAAU,CACpB,MAAM,OACJ,QAAQ,WAAa,oBACjB,IACA,QAAQ,SAAS,SAAS,WAAW,GACnC,QAAQ,WAAa,cACrB,IACA,IACR,MAAM,IAAI,iBACR,OACA,QAAQ,SACR,QAAQ,QAAQ,QAAQ,EAC1B,CACF,CACF,EACA,MAAM,OAAwB,CAC5B,KAAM,eACN,MAAM,QAAS,CACb,MAAM,MAAM,EACZ,MAAO,CACL,OAAQ,UACR,QAAS,QAAQ,SAAW,KAC5B,MACF,CACF,EACA,MAAM,OAAQ,CACZ,MAAM,MAAM,EACZ,OAAO,QAAQ,UAAY,MACvB,CAAC,EACD,gBAAgB,QAAQ,OAAS,CAAC,CAAC,CACzC,EACA,MAAM,OAAO,OAAiC,CAC5C,MAAM,MAAM,EACZ,MAAM,KAAO,QAAQ,OAAO,KAAM,WAAc,UAAU,KAAO,MAAM,EACvE,GAAI,CAAC,KAAM,CACT,MAAM,IAAI,iBAAiB,IAAK,iBAAkB,cAAc,CAClE,CACA,GAAI,OAAS,KAAK,YAAa,CAC7B,MAAM,IAAI,iBACR,IACA,sBACA,6CACF,CACF,CACA,QAAU,KAAK,YACf,MAAM,GAAK,WAAW,EAAE,QAAQ,GAChC,SAAS,IAAI,GAAI,KAAK,WAAW,EACjC,QAAQ,EACR,MAAO,CACL,GACA,OAAQ,kBACR,OAAQ,WACR,aAAc,KAAK,YACnB,KAAM,CAAE,GAAI,KAAK,GAAI,KAAM,KAAK,IAAK,EACrC,WAAY,IAAI,KAAK,KAAK,IAAI,EAAI,KAAU,EAAE,YAAY,CAC5D,CACF,EACA,MAAM,OAAO,aAAc,CACzB,MAAM,MAAM,EACZ,QAAU,SAAS,IAAI,YAAY,GAAK,EACxC,SAAS,OAAO,YAAY,EAC5B,QAAQ,CACV,EACA,MAAM,MAAM,QAAgC,CAC1C,MAAM,MAAM,EACZ,MAAM,OAAS,QAAQ,IAAI,OAAO,EAC9B,EACC,QAAQ,SAAS,OAAO,GAAK,EAClC,QAAQ,IAAI,OAAO,EACnB,QAAU,OACV,QAAQ,EACR,MAAO,CACL,OAAQ,gBACR,SAAU,QACV,cAAe,OACf,MACF,CACF,EACA,MAAM,aAAc,CAClB,MAAM,MAAM,EACZ,OACE,QAAQ,aAAe,CACrB,OAAQ,eACR,QAAS,MACT,QAAS,CAAE,aAAc,EAAG,SAAU,KAAM,CAC9C,CAEJ,EACA,SAAS,SAAU,CACjB,UAAU,IAAI,QAAQ,EACtB,MAAO,IAAM,CACX,UAAU,OAAO,QAAQ,CAC3B,CACF,CACF,EACA,OAAO,MACT",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
async function categoryPage(raw, ctx, mapMenu, invalid) {
|
|
3
|
-
const menu = (await import("./presentation.js")).presentMenu(
|
|
4
|
-
mapMenu(raw, ctx.branchId),
|
|
5
|
-
raw,
|
|
6
|
-
invalid
|
|
7
|
-
);
|
|
8
|
-
if (raw.next_cursor != null && (typeof raw.next_cursor !== "string" || !raw.next_cursor || raw.next_cursor === ctx.cursor) || menu.categories.some((c) => c.id !== ctx.categoryId) || Object.keys(menu.items).some(
|
|
9
|
-
(id) => !menu.categories.some((c) => c.itemIds.includes(id))
|
|
10
|
-
) || !menu.menus?.some(
|
|
11
|
-
(m) => m.id === ctx.menuId && m.categoryIds.includes(ctx.categoryId)
|
|
12
|
-
)) {
|
|
13
|
-
throw invalid();
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
menu: { ...menu, completeness: "partial" },
|
|
17
|
-
menuId: ctx.menuId,
|
|
18
|
-
categoryId: ctx.categoryId,
|
|
19
|
-
...typeof raw.next_cursor === "string" && raw.next_cursor ? { nextCursor: raw.next_cursor } : {}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
categoryPage
|
|
24
|
-
};
|
|
1
|
+
async function categoryPage(raw,ctx,mapMenu,invalid){const menu=(await import("./presentation.js")).presentMenu(mapMenu(raw,ctx.branchId),raw,invalid);if(raw.next_cursor!=null&&(typeof raw.next_cursor!=="string"||!raw.next_cursor||raw.next_cursor===ctx.cursor)||menu.categories.some(c=>c.id!==ctx.categoryId)||Object.keys(menu.items).some(id=>!menu.categories.some(c=>c.itemIds.includes(id)))||!menu.menus?.some(m=>m.id===ctx.menuId&&m.categoryIds.includes(ctx.categoryId))){throw invalid()}return{menu:{...menu,completeness:"partial"},menuId:ctx.menuId,categoryId:ctx.categoryId,...typeof raw.next_cursor==="string"&&raw.next_cursor?{nextCursor:raw.next_cursor}:{}}}export{categoryPage};
|
|
25
2
|
//# sourceMappingURL=category-page.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/transport/category-page.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AASA,eAAsB,aACpB,IACA,IAMA,QACA,QACuB,CACvB,MAAM,MAAQ,KAAM,QAAO,mBAAgB,GAAG,YAC5C,QAAQ,IAAK,IAAI,QAAQ,EACzB,IACA,OACF,EACA,GACG,IAAI,aAAe,OACjB,OAAO,IAAI,cAAgB,UAC1B,CAAC,IAAI,aACL,IAAI,cAAgB,IAAI,SAC5B,KAAK,WAAW,KAAM,GAAM,EAAE,KAAO,IAAI,UAAU,GACnD,OAAO,KAAK,KAAK,KAAK,EAAE,KACrB,IAAO,CAAC,KAAK,WAAW,KAAM,GAAM,EAAE,QAAQ,SAAS,EAAE,CAAC,CAC7D,GACA,CAAC,KAAK,OAAO,KACV,GAAM,EAAE,KAAO,IAAI,QAAU,EAAE,YAAY,SAAS,IAAI,UAAU,CACrE,EACA,CACA,MAAM,QAAQ,CAChB,CACA,MAAO,CACL,KAAM,CAAE,GAAG,KAAM,aAAc,SAAU,EACzC,OAAQ,IAAI,OACZ,WAAY,IAAI,WAChB,GAAI,OAAO,IAAI,cAAgB,UAAY,IAAI,YAC3C,CAAE,WAAY,IAAI,WAAY,EAC9B,CAAC,CACP,CACF",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|