@zappie/sdk 0.1.6 → 0.1.8
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 +13 -0
- package/README.md +47 -1
- package/dist/cart/branch.d.ts +2 -2
- package/dist/cart/item.d.ts +3 -3
- package/dist/cart/quote-response.js +6 -1
- package/dist/cart/quote-response.js.map +2 -2
- package/dist/cart/quote.d.ts +3 -3
- package/dist/{client-Bm2cCYea.d.ts → client-DzUauU-b.d.ts} +2 -2
- package/dist/debug.d.ts +3 -3
- package/dist/debug.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/integrations/index.d.ts +9 -6
- package/dist/integrations/index.js +1 -0
- package/dist/integrations/index.js.map +2 -2
- package/dist/internal.d.ts +3 -3
- package/dist/{models-Rg5kQUkv.d.ts → models-D__QbqEd.d.ts} +14 -1
- package/dist/persist/catalogue.d.ts +3 -3
- package/dist/places/index.d.ts +6 -2
- package/dist/pricing/index.d.ts +116 -0
- package/dist/pricing/index.js +30 -0
- package/dist/pricing/index.js.map +7 -0
- package/dist/react/index.d.ts +3 -3
- package/dist/server/index.d.ts +7 -4
- package/dist/server/storefront-url/build-v1.js +8 -17
- package/dist/server/storefront-url/build-v1.js.map +2 -2
- package/dist/server/storefront-url/build-v2.js +13 -41
- package/dist/server/storefront-url/build-v2.js.map +2 -2
- package/dist/server/storefront-url/canonical.js +36 -0
- package/dist/server/storefront-url/canonical.js.map +7 -0
- package/dist/server/storefront-url/contract.js +2 -2
- package/dist/server/storefront-url/contract.js.map +2 -2
- package/dist/server/storefront-url/params.js +35 -18
- package/dist/server/storefront-url/params.js.map +2 -2
- package/dist/server/storefront-url/parse-v1.js +15 -12
- package/dist/server/storefront-url/parse-v1.js.map +2 -2
- package/dist/server/storefront-url/parse-v2.js +17 -79
- package/dist/server/storefront-url/parse-v2.js.map +2 -2
- package/dist/server/storefront-url/public-id.js +8 -0
- package/dist/server/storefront-url/public-id.js.map +7 -0
- package/dist/server/storefront-url/redirect.js +20 -6
- package/dist/server/storefront-url/redirect.js.map +2 -2
- package/dist/server/storefront-url/sign-in.js +2 -1
- package/dist/server/storefront-url/sign-in.js.map +2 -2
- package/dist/server/storefront-url/types.js +1 -0
- package/dist/server/storefront-url/types.js.map +2 -2
- package/dist/server/storefront-url/url.js +34 -23
- package/dist/server/storefront-url/url.js.map +2 -2
- package/dist/testing/index.d.ts +3 -3
- package/dist/transport/category-page.d.ts +2 -2
- package/dist/transport/category-page.js +6 -2
- package/dist/transport/category-page.js.map +2 -2
- package/dist/transport/presentation.d.ts +7 -0
- package/dist/transport/presentation.js +68 -0
- package/dist/transport/presentation.js.map +7 -0
- package/dist/transport/rest.js +15 -3
- package/dist/transport/rest.js.map +2 -2
- package/dist/transport/search.d.ts +3 -3
- package/dist/transport/search.js +6 -1
- package/dist/transport/search.js.map +2 -2
- package/dist/transport/selected-menu.d.ts +3 -3
- package/dist/transport/selected-menu.js +7 -2
- package/dist/transport/selected-menu.js.map +2 -2
- package/dist/transport/store.d.ts +1 -2
- package/dist/transport/store.js.map +1 -1
- package/dist/{types-CuDvfW9g.d.ts → types-gQXU2gEA.d.ts} +3 -1
- package/dist/url/index.d.ts +4 -1
- package/package.json +6 -2
|
@@ -21,20 +21,12 @@ var routePathV1 = (route, options = {}) => {
|
|
|
21
21
|
return `/order/${encode(route.business)}${route.branch ? `/${encode(route.branch)}` : ""}/pages/${encode(route.slug)}`;
|
|
22
22
|
case "dine-in":
|
|
23
23
|
return `/dine-in/${encode(route.order)}`;
|
|
24
|
-
case "dine-in-menus":
|
|
25
|
-
return "/dine-in/menus";
|
|
26
|
-
case "self-service-menus":
|
|
27
|
-
return "/self-service/menus";
|
|
28
24
|
case "pay-point":
|
|
29
25
|
return `/pay-point/${encode(route.payPoint)}`;
|
|
30
26
|
case "beacon":
|
|
31
27
|
return `/beacons/${encode(route.beacon)}`;
|
|
32
28
|
case "link":
|
|
33
29
|
return `/links/${encode(route.link)}`;
|
|
34
|
-
case "collect-payment":
|
|
35
|
-
return "/collect-payment";
|
|
36
|
-
case "reservation":
|
|
37
|
-
return "/reservation";
|
|
38
30
|
case "pay-session":
|
|
39
31
|
return `/pay/${encode(route.session)}`;
|
|
40
32
|
case "payment-step":
|
|
@@ -47,6 +39,13 @@ var routePathV1 = (route, options = {}) => {
|
|
|
47
39
|
return route.home ? "/" : "/explore";
|
|
48
40
|
case "unknown":
|
|
49
41
|
return route.pathname || "/";
|
|
42
|
+
case "dine-in-menus":
|
|
43
|
+
return "/dine-in/menus";
|
|
44
|
+
case "self-service-menus":
|
|
45
|
+
return "/self-service/menus";
|
|
46
|
+
case "collect-payment":
|
|
47
|
+
case "reservation":
|
|
48
|
+
return `/${route.type}`;
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
51
|
var buildV1 = (route, options = {}) => {
|
|
@@ -58,15 +57,7 @@ var buildV1 = (route, options = {}) => {
|
|
|
58
57
|
options.installation
|
|
59
58
|
);
|
|
60
59
|
const query = v1Params(route).toString();
|
|
61
|
-
|
|
62
|
-
if (!options.origin) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
return new URL(value, options.origin).toString();
|
|
67
|
-
} catch {
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
60
|
+
return `${pathname}${query ? `?${query}` : ""}`;
|
|
70
61
|
};
|
|
71
62
|
export {
|
|
72
63
|
buildV1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/storefront-url/build-v1.ts"],
|
|
4
|
-
"sourcesContent": ["import { menuRoute } from \"./contract\";\nimport { publicInstallationPath } from \"./installation\";\nimport { v1Params } from \"./params\";\nimport { type StorefrontRoute, type StorefrontUrlOptions } from \"./types\";\nimport { encode } from \"./url\";\n\nexport const routePathV1 = (\n route: StorefrontRoute,\n options: StorefrontUrlOptions = {},\n): string => {\n switch (route.type) {\n case \"order-menu\":\n return `/order/${encode(route.business)}${route.branch ? `/${encode(route.branch)}` : \"\"}${route.cataloguePath ? \"/products\" : \"\"}`;\n case \"item\": {\n const branch = route.branch ?? options.installation?.defaultBranch;\n return branch\n ? `/order/${encode(route.business)}/${encode(branch)}/products/${encode(route.item)}`\n : `/order/${encode(route.business)}`;\n }\n case \"cart\":\n case \"checkout\":\n case \"checkout-return\":\n case \"sign-in\":\n return routePathV1(menuRoute(route), options);\n case \"content-page\":\n return `/order/${encode(route.business)}${route.branch ? `/${encode(route.branch)}` : \"\"}/pages/${encode(route.slug)}`;\n case \"dine-in\":\n return `/dine-in/${encode(route.order)}`;\n case \"
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AACvC,SAAS,gBAAgB;AACzB,OAAgE;AAChE,SAAS,cAAc;AAEhB,IAAM,cAAc,CACzB,OACA,UAAgC,CAAC,MACtB;AACX,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,aAAO,UAAU,OAAO,MAAM,QAAQ,CAAC,GAAG,MAAM,SAAS,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,GAAG,MAAM,gBAAgB,cAAc,EAAE;AAAA,IACnI,KAAK,QAAQ;AACX,YAAM,SAAS,MAAM,UAAU,QAAQ,cAAc;AACrD,aAAO,SACH,UAAU,OAAO,MAAM,QAAQ,CAAC,IAAI,OAAO,MAAM,CAAC,aAAa,OAAO,MAAM,IAAI,CAAC,KACjF,UAAU,OAAO,MAAM,QAAQ,CAAC;AAAA,IACtC;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,YAAY,UAAU,KAAK,GAAG,OAAO;AAAA,IAC9C,KAAK;AACH,aAAO,UAAU,OAAO,MAAM,QAAQ,CAAC,GAAG,MAAM,SAAS,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,UAAU,OAAO,MAAM,IAAI,CAAC;AAAA,IACtH,KAAK;AACH,aAAO,YAAY,OAAO,MAAM,KAAK,CAAC;AAAA,IACxC,KAAK;AACH,aAAO
|
|
4
|
+
"sourcesContent": ["import { menuRoute } from \"./contract\";\nimport { publicInstallationPath } from \"./installation\";\nimport { v1Params } from \"./params\";\nimport { type StorefrontRoute, type StorefrontUrlOptions } from \"./types\";\nimport { encode } from \"./url\";\n\nexport const routePathV1 = (\n route: StorefrontRoute,\n options: StorefrontUrlOptions = {},\n): string => {\n switch (route.type) {\n case \"order-menu\":\n return `/order/${encode(route.business)}${route.branch ? `/${encode(route.branch)}` : \"\"}${route.cataloguePath ? \"/products\" : \"\"}`;\n case \"item\": {\n const branch = route.branch ?? options.installation?.defaultBranch;\n return branch\n ? `/order/${encode(route.business)}/${encode(branch)}/products/${encode(route.item)}`\n : `/order/${encode(route.business)}`;\n }\n case \"cart\":\n case \"checkout\":\n case \"checkout-return\":\n case \"sign-in\":\n return routePathV1(menuRoute(route), options);\n case \"content-page\":\n return `/order/${encode(route.business)}${route.branch ? `/${encode(route.branch)}` : \"\"}/pages/${encode(route.slug)}`;\n case \"dine-in\":\n return `/dine-in/${encode(route.order)}`;\n case \"pay-point\":\n return `/pay-point/${encode(route.payPoint)}`;\n case \"beacon\":\n return `/beacons/${encode(route.beacon)}`;\n case \"link\":\n return `/links/${encode(route.link)}`;\n case \"pay-session\":\n return `/pay/${encode(route.session)}`;\n case \"payment-step\":\n return `/payment/${encode(route.payment)}${route.step === \"payment\" ? \"\" : `/${route.step}`}`;\n case \"payment-card\":\n return `/payment/card/${encode(route.transaction)}`;\n case \"profile\":\n return `/profile/${route.page}${route.order ? `/${encode(route.order)}` : \"\"}`;\n case \"explore\":\n return route.home ? \"/\" : \"/explore\";\n case \"unknown\":\n return route.pathname || \"/\";\n case \"dine-in-menus\":\n return \"/dine-in/menus\";\n case \"self-service-menus\":\n return \"/self-service/menus\";\n case \"collect-payment\":\n case \"reservation\":\n return `/${route.type}`;\n }\n};\n\nexport const buildV1 = (\n route: StorefrontRoute,\n options: StorefrontUrlOptions = {},\n) => {\n const internal = routePathV1(route, options);\n const publicRoute =\n route.type === \"item\" &&\n route.branch === undefined &&\n options.installation?.defaultBranch\n ? { ...route, branch: options.installation.defaultBranch }\n : route;\n const pathname = publicInstallationPath(\n internal,\n publicRoute,\n options.installation,\n );\n const query = v1Params(route).toString();\n return `${pathname}${query ? `?${query}` : \"\"}`;\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AACvC,SAAS,gBAAgB;AACzB,OAAgE;AAChE,SAAS,cAAc;AAEhB,IAAM,cAAc,CACzB,OACA,UAAgC,CAAC,MACtB;AACX,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,aAAO,UAAU,OAAO,MAAM,QAAQ,CAAC,GAAG,MAAM,SAAS,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,GAAG,MAAM,gBAAgB,cAAc,EAAE;AAAA,IACnI,KAAK,QAAQ;AACX,YAAM,SAAS,MAAM,UAAU,QAAQ,cAAc;AACrD,aAAO,SACH,UAAU,OAAO,MAAM,QAAQ,CAAC,IAAI,OAAO,MAAM,CAAC,aAAa,OAAO,MAAM,IAAI,CAAC,KACjF,UAAU,OAAO,MAAM,QAAQ,CAAC;AAAA,IACtC;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,YAAY,UAAU,KAAK,GAAG,OAAO;AAAA,IAC9C,KAAK;AACH,aAAO,UAAU,OAAO,MAAM,QAAQ,CAAC,GAAG,MAAM,SAAS,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,UAAU,OAAO,MAAM,IAAI,CAAC;AAAA,IACtH,KAAK;AACH,aAAO,YAAY,OAAO,MAAM,KAAK,CAAC;AAAA,IACxC,KAAK;AACH,aAAO,cAAc,OAAO,MAAM,QAAQ,CAAC;AAAA,IAC7C,KAAK;AACH,aAAO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Route } from "./canonical.js";
|
|
4
4
|
import { v2Params } from "./params.js";
|
|
5
|
-
import {
|
|
6
|
-
import { encode
|
|
7
|
-
var canonicalRoute = (route, installation) => {
|
|
8
|
-
if (route.type !== "order-menu") {
|
|
9
|
-
return route;
|
|
10
|
-
}
|
|
11
|
-
const common = {
|
|
12
|
-
business: route.business,
|
|
13
|
-
...route.branch !== void 0 ? { branch: route.branch } : {},
|
|
14
|
-
state: route.state
|
|
15
|
-
};
|
|
16
|
-
if (route.state.authModalId && SIGN_IN_MODALS.has(route.state.authModalId)) {
|
|
17
|
-
return signInFromOverlay(route, installation);
|
|
18
|
-
}
|
|
19
|
-
if (route.state.modalId?.startsWith(ITEM_MODAL_PREFIX)) {
|
|
20
|
-
return {
|
|
21
|
-
type: "item",
|
|
22
|
-
...common,
|
|
23
|
-
item: route.state.modalId.slice(ITEM_MODAL_PREFIX.length)
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (route.state.modalId === CART_MODAL) {
|
|
27
|
-
return { type: "cart", ...common };
|
|
28
|
-
}
|
|
29
|
-
if (route.state.modalId === CHECKOUT_MODAL) {
|
|
30
|
-
return { type: "checkout", ...common };
|
|
31
|
-
}
|
|
32
|
-
return route;
|
|
33
|
-
};
|
|
5
|
+
import { categoryHash, publicId } from "./public-id.js";
|
|
6
|
+
import { encode } from "./url.js";
|
|
34
7
|
var profilePath = (route) => {
|
|
35
8
|
if (route.page === "orders") {
|
|
36
|
-
return `/orders${route.order ? `/${encode(route.order)}` : ""}`;
|
|
9
|
+
return `/orders${route.order ? `/${encode(publicId(route.order, "ord"))}` : ""}`;
|
|
37
10
|
}
|
|
38
11
|
if (route.page === "edit") {
|
|
39
12
|
return "/account";
|
|
@@ -41,12 +14,12 @@ var profilePath = (route) => {
|
|
|
41
14
|
const page = route.page === "add-store-credit" ? "store-credit" : route.page;
|
|
42
15
|
return `/account/${page}`;
|
|
43
16
|
};
|
|
44
|
-
var routePathV2 = (route
|
|
17
|
+
var routePathV2 = (route) => {
|
|
45
18
|
switch (route.type) {
|
|
46
19
|
case "order-menu":
|
|
47
20
|
return "/";
|
|
48
21
|
case "item":
|
|
49
|
-
return `/item/${encode(route.item)}`;
|
|
22
|
+
return `/item/${encode(publicId(route.item, "item"))}`;
|
|
50
23
|
case "cart":
|
|
51
24
|
return "/cart";
|
|
52
25
|
case "checkout":
|
|
@@ -59,19 +32,18 @@ var routePathV2 = (route, options) => {
|
|
|
59
32
|
return `/pages/${encode(route.slug)}`;
|
|
60
33
|
case "profile":
|
|
61
34
|
return profilePath(route);
|
|
62
|
-
default:
|
|
63
|
-
return routePathV1(route, options);
|
|
64
35
|
}
|
|
65
36
|
};
|
|
66
37
|
var buildV2 = (route, options) => {
|
|
67
38
|
const installation = options.installation;
|
|
68
|
-
if (!installation) {
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
39
|
const canonical = canonicalRoute(route, installation);
|
|
72
|
-
|
|
40
|
+
if (!("business" in canonical) && canonical.type !== "profile") {
|
|
41
|
+
return buildV1(canonical, options);
|
|
42
|
+
}
|
|
43
|
+
const pathname = routePathV2(canonical);
|
|
73
44
|
const query = v2Params(canonical, installation).toString();
|
|
74
|
-
|
|
45
|
+
const hash = categoryHash(canonical.state.categoryId);
|
|
46
|
+
return `${pathname}${query ? `?${query}` : ""}${hash}`;
|
|
75
47
|
};
|
|
76
48
|
export {
|
|
77
49
|
buildV2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/storefront-url/build-v2.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { buildV1 } from \"./build-v1\";\nimport { canonicalRoute } from \"./canonical\";\nimport { v2Params } from \"./params\";\nimport { categoryHash, publicId } from \"./public-id\";\nimport type {\n StorefrontInstallation,\n StorefrontRoute,\n StorefrontUrlOptions,\n} from \"./types\";\nimport { encode } from \"./url\";\n\nconst profilePath = (route: Extract<StorefrontRoute, { type: \"profile\" }>) => {\n if (route.page === \"orders\") {\n return `/orders${route.order ? `/${encode(publicId(route.order, \"ord\"))}` : \"\"}`;\n }\n if (route.page === \"edit\") {\n return \"/account\";\n }\n const page = route.page === \"add-store-credit\" ? \"store-credit\" : route.page;\n return `/account/${page}`;\n};\n\nconst routePathV2 = (\n route: Extract<StorefrontRoute, { business: string } | { type: \"profile\" }>,\n) => {\n switch (route.type) {\n case \"order-menu\":\n return \"/\";\n case \"item\":\n return `/item/${encode(publicId(route.item, \"item\"))}`;\n case \"cart\":\n return \"/cart\";\n case \"checkout\":\n return \"/checkout\";\n case \"checkout-return\":\n return \"/checkout/return\";\n case \"sign-in\":\n return \"/sign-in\";\n case \"content-page\":\n return `/pages/${encode(route.slug)}`;\n case \"profile\":\n return profilePath(route);\n }\n};\n\nexport const buildV2 = (\n route: StorefrontRoute,\n options: StorefrontUrlOptions & { installation: StorefrontInstallation },\n) => {\n const installation = options.installation;\n const canonical = canonicalRoute(route, installation);\n if (!(\"business\" in canonical) && canonical.type !== \"profile\") {\n return buildV1(canonical, options);\n }\n const pathname = routePathV2(canonical);\n const query = v2Params(canonical, installation).toString();\n const hash = categoryHash(canonical.state.categoryId);\n return `${pathname}${query ? `?${query}` : \"\"}${hash}`;\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,cAAc,gBAAgB;AAMvC,SAAS,cAAc;AAEvB,IAAM,cAAc,CAAC,UAAyD;AAC5E,MAAI,MAAM,SAAS,UAAU;AAC3B,WAAO,UAAU,MAAM,QAAQ,IAAI,OAAO,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC,KAAK,EAAE;AAAA,EAChF;AACA,MAAI,MAAM,SAAS,QAAQ;AACzB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,MAAM,SAAS,qBAAqB,iBAAiB,MAAM;AACxE,SAAO,YAAY,IAAI;AACzB;AAEA,IAAM,cAAc,CAClB,UACG;AACH,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,SAAS,OAAO,SAAS,MAAM,MAAM,MAAM,CAAC,CAAC;AAAA,IACtD,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,UAAU,OAAO,MAAM,IAAI,CAAC;AAAA,IACrC,KAAK;AACH,aAAO,YAAY,KAAK;AAAA,EAC5B;AACF;AAEO,IAAM,UAAU,CACrB,OACA,YACG;AACH,QAAM,eAAe,QAAQ;AAC7B,QAAM,YAAY,eAAe,OAAO,YAAY;AACpD,MAAI,EAAE,cAAc,cAAc,UAAU,SAAS,WAAW;AAC9D,WAAO,QAAQ,WAAW,OAAO;AAAA,EACnC;AACA,QAAM,WAAW,YAAY,SAAS;AACtC,QAAM,QAAQ,SAAS,WAAW,YAAY,EAAE,SAAS;AACzD,QAAM,OAAO,aAAa,UAAU,MAAM,UAAU;AACpD,SAAO,GAAG,QAAQ,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE,GAAG,IAAI;AACtD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/server/storefront-url/canonical.ts
|
|
2
|
+
import { CART_MODAL, CHECKOUT_MODAL, SIGN_IN_MODALS } from "./contract.js";
|
|
3
|
+
import { signInFromOverlay } from "./sign-in.js";
|
|
4
|
+
import { ITEM_MODAL_PREFIX } from "./url.js";
|
|
5
|
+
var canonicalRoute = (route, installation) => {
|
|
6
|
+
if (route.type !== "order-menu") {
|
|
7
|
+
return route;
|
|
8
|
+
}
|
|
9
|
+
const { authModalId, modalId } = route.state;
|
|
10
|
+
if (authModalId && SIGN_IN_MODALS.includes(authModalId)) {
|
|
11
|
+
return signInFromOverlay(route, installation);
|
|
12
|
+
}
|
|
13
|
+
const common = {
|
|
14
|
+
business: route.business,
|
|
15
|
+
...route.branch !== void 0 ? { branch: route.branch } : {},
|
|
16
|
+
state: route.state
|
|
17
|
+
};
|
|
18
|
+
if (modalId?.startsWith(ITEM_MODAL_PREFIX)) {
|
|
19
|
+
return {
|
|
20
|
+
type: "item",
|
|
21
|
+
...common,
|
|
22
|
+
item: modalId.slice(ITEM_MODAL_PREFIX.length)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (modalId === CART_MODAL || modalId === CHECKOUT_MODAL) {
|
|
26
|
+
return {
|
|
27
|
+
type: modalId === CART_MODAL ? "cart" : "checkout",
|
|
28
|
+
...common
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return route;
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
canonicalRoute
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/server/storefront-url/canonical.ts"],
|
|
4
|
+
"sourcesContent": ["import { CART_MODAL, CHECKOUT_MODAL, SIGN_IN_MODALS } from \"./contract\";\nimport { signInFromOverlay } from \"./sign-in\";\nimport type { StorefrontRoute, StorefrontUrlOptions } from \"./types\";\nimport { ITEM_MODAL_PREFIX } from \"./url\";\n\nexport const canonicalRoute = (\n route: StorefrontRoute,\n installation: NonNullable<StorefrontUrlOptions[\"installation\"]>,\n): StorefrontRoute => {\n if (route.type !== \"order-menu\") {\n return route;\n }\n const { authModalId, modalId } = route.state;\n if (authModalId && SIGN_IN_MODALS.includes(authModalId)) {\n return signInFromOverlay(route, installation);\n }\n const common = {\n business: route.business,\n ...(route.branch !== undefined ? { branch: route.branch } : {}),\n state: route.state,\n };\n if (modalId?.startsWith(ITEM_MODAL_PREFIX)) {\n return {\n type: \"item\",\n ...common,\n item: modalId.slice(ITEM_MODAL_PREFIX.length),\n };\n }\n if (modalId === CART_MODAL || modalId === CHECKOUT_MODAL) {\n return {\n type: modalId === CART_MODAL ? \"cart\" : \"checkout\",\n ...common,\n };\n }\n return route;\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY,gBAAgB,sBAAsB;AAC3D,SAAS,yBAAyB;AAElC,SAAS,yBAAyB;AAE3B,IAAM,iBAAiB,CAC5B,OACA,iBACoB;AACpB,MAAI,MAAM,SAAS,cAAc;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,EAAE,aAAa,QAAQ,IAAI,MAAM;AACvC,MAAI,eAAe,eAAe,SAAS,WAAW,GAAG;AACvD,WAAO,kBAAkB,OAAO,YAAY;AAAA,EAC9C;AACA,QAAM,SAAS;AAAA,IACb,UAAU,MAAM;AAAA,IAChB,GAAI,MAAM,WAAW,SAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,IAC7D,OAAO,MAAM;AAAA,EACf;AACA,MAAI,SAAS,WAAW,iBAAiB,GAAG;AAC1C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,GAAG;AAAA,MACH,MAAM,QAAQ,MAAM,kBAAkB,MAAM;AAAA,IAC9C;AAAA,EACF;AACA,MAAI,YAAY,cAAc,YAAY,gBAAgB;AACxD,WAAO;AAAA,MACL,MAAM,YAAY,aAAa,SAAS;AAAA,MACxC,GAAG;AAAA,IACL;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
var CART_MODAL = "review-menu";
|
|
3
3
|
var CHECKOUT_MODAL = "payment";
|
|
4
4
|
var SIGN_IN_MODAL = "send-otp";
|
|
5
|
-
var SIGN_IN_MODALS =
|
|
5
|
+
var SIGN_IN_MODALS = [
|
|
6
6
|
SIGN_IN_MODAL,
|
|
7
7
|
"verify-otp",
|
|
8
8
|
"update-profile"
|
|
9
|
-
]
|
|
9
|
+
];
|
|
10
10
|
var usesV2 = (options) => options.contract !== "v1" && options.installation !== void 0;
|
|
11
11
|
var menuRoute = (route) => ({
|
|
12
12
|
type: "order-menu",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/storefront-url/contract.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type {\n StorefrontInstallation,\n StorefrontRoute,\n StorefrontUrlOptions,\n} from \"./types\";\n\nexport const CART_MODAL = \"review-menu\";\nexport const CHECKOUT_MODAL = \"payment\";\nexport const SIGN_IN_MODAL = \"send-otp\";\nexport const SIGN_IN_MODALS: readonly string[] = [\n SIGN_IN_MODAL,\n \"verify-otp\",\n \"update-profile\",\n];\n\nexport const usesV2 = (\n options: StorefrontUrlOptions,\n): options is StorefrontUrlOptions & { installation: StorefrontInstallation } =>\n options.contract !== \"v1\" && options.installation !== undefined;\n\nexport const menuRoute = (\n route: Extract<\n StorefrontRoute,\n { type: \"cart\" | \"checkout\" | \"checkout-return\" | \"sign-in\" }\n >,\n): Extract<StorefrontRoute, { type: \"order-menu\" }> => ({\n type: \"order-menu\",\n business: route.business,\n ...(route.branch !== undefined ? { branch: route.branch } : {}),\n state: route.state,\n});\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAM,aAAa;AACnB,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AACtB,IAAM,iBAAoC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,SAAS,CACpB,YAEA,QAAQ,aAAa,QAAQ,QAAQ,iBAAiB;AAEjD,IAAM,YAAY,CACvB,WAIsD;AAAA,EACtD,MAAM;AAAA,EACN,UAAU,MAAM;AAAA,EAChB,GAAI,MAAM,WAAW,SAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,EAC7D,OAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
// src/server/storefront-url/params.ts
|
|
2
2
|
import { CART_MODAL, CHECKOUT_MODAL, SIGN_IN_MODAL } from "./contract.js";
|
|
3
|
+
import { publicId } from "./public-id.js";
|
|
4
|
+
import { STATE_FIELDS } from "./url.js";
|
|
3
5
|
var stateParams = (route) => {
|
|
4
6
|
const params = new URLSearchParams(route.state.query);
|
|
5
7
|
const state = route.state;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
["category_id", state.categoryId],
|
|
9
|
-
["menu_layout", state.menuLayout],
|
|
10
|
-
["pickup", state.mode ? String(state.mode === "pickup") : void 0],
|
|
11
|
-
["modal_id", state.modalId],
|
|
12
|
-
["auth_modal_id", state.authModalId],
|
|
13
|
-
["payment_id", state.paymentId],
|
|
14
|
-
["lightbox", state.lightbox],
|
|
15
|
-
["catalogue_search", state.catalogueSearch],
|
|
16
|
-
["catalogue_categories", state.catalogueCategories]
|
|
17
|
-
];
|
|
18
|
-
values.forEach(([key, value]) => {
|
|
8
|
+
for (const [key, field] of Object.entries(STATE_FIELDS)) {
|
|
9
|
+
const value = state[field];
|
|
19
10
|
if (value !== void 0) {
|
|
20
11
|
params.set(key, value);
|
|
21
12
|
}
|
|
22
|
-
}
|
|
13
|
+
}
|
|
14
|
+
if (state.mode) {
|
|
15
|
+
params.set("pickup", String(state.mode === "pickup"));
|
|
16
|
+
}
|
|
23
17
|
return params;
|
|
24
18
|
};
|
|
25
19
|
var v1Params = (route) => {
|
|
@@ -43,16 +37,39 @@ var v1Params = (route) => {
|
|
|
43
37
|
};
|
|
44
38
|
var v2Params = (route, installation) => {
|
|
45
39
|
const params = stateParams(route);
|
|
46
|
-
|
|
40
|
+
const menu = params.get("menu_id");
|
|
41
|
+
if (menu) {
|
|
42
|
+
params.set("menu", publicId(menu, "menu"));
|
|
43
|
+
}
|
|
44
|
+
for (const key of [
|
|
45
|
+
"menu_id",
|
|
46
|
+
"category_id",
|
|
47
|
+
"pickup",
|
|
48
|
+
"menu_layout",
|
|
49
|
+
"catalogue_search",
|
|
50
|
+
"catalogue_categories",
|
|
51
|
+
"template",
|
|
52
|
+
"catalog_rendering",
|
|
53
|
+
"prefetch",
|
|
54
|
+
"ws",
|
|
55
|
+
"env",
|
|
56
|
+
"business",
|
|
57
|
+
"business_tag",
|
|
58
|
+
"switched_branch",
|
|
59
|
+
"success",
|
|
60
|
+
"auto_scroll",
|
|
61
|
+
"preview",
|
|
62
|
+
"modal_id"
|
|
63
|
+
]) {
|
|
64
|
+
params.delete(key);
|
|
65
|
+
}
|
|
66
|
+
if ("business" in route) {
|
|
47
67
|
if (route.branch && route.branch !== installation.defaultBranch) {
|
|
48
68
|
params.set("branch", route.branch);
|
|
49
69
|
} else {
|
|
50
70
|
params.delete("branch");
|
|
51
71
|
}
|
|
52
72
|
}
|
|
53
|
-
if (route.type === "item" || route.type === "cart" || route.type === "checkout" || route.type === "checkout-return") {
|
|
54
|
-
params.delete("modal_id");
|
|
55
|
-
}
|
|
56
73
|
if (route.type === "sign-in") {
|
|
57
74
|
params.delete("auth_modal_id");
|
|
58
75
|
if (route.returnTo !== void 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/storefront-url/params.ts"],
|
|
4
|
-
"sourcesContent": ["import { CART_MODAL, CHECKOUT_MODAL, SIGN_IN_MODAL } from \"./contract\";\nimport type { StorefrontInstallation, StorefrontRoute } from \"./types\";\n\nconst stateParams = (route: StorefrontRoute) => {\n const params = new URLSearchParams(route.state.query);\n const state = route.state;\n const
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY,gBAAgB,qBAAqB;
|
|
4
|
+
"sourcesContent": ["import { CART_MODAL, CHECKOUT_MODAL, SIGN_IN_MODAL } from \"./contract\";\nimport { publicId } from \"./public-id\";\nimport type { StorefrontInstallation, StorefrontRoute } from \"./types\";\nimport { STATE_FIELDS } from \"./url\";\n\nconst stateParams = (route: StorefrontRoute) => {\n const params = new URLSearchParams(route.state.query);\n const state = route.state;\n for (const [key, field] of Object.entries(STATE_FIELDS)) {\n const value = state[field];\n if (value !== undefined) {\n params.set(key, value);\n }\n }\n if (state.mode) {\n params.set(\"pickup\", String(state.mode === \"pickup\"));\n }\n return params;\n};\n\nexport const v1Params = (route: StorefrontRoute) => {\n const params = stateParams(route);\n if (route.type === \"item\") {\n params.delete(\"modal_id\");\n } else if (route.type === \"cart\") {\n params.set(\"modal_id\", CART_MODAL);\n } else if (route.type === \"checkout\") {\n params.set(\"modal_id\", CHECKOUT_MODAL);\n } else if (route.type === \"sign-in\") {\n params.set(\"auth_modal_id\", SIGN_IN_MODAL);\n if (route.returnTo !== undefined) {\n params.set(\"return\", route.returnTo);\n }\n } else if (route.type === \"checkout-return\" && route.session !== undefined) {\n params.set(\"session\", route.session);\n }\n params.sort();\n return params;\n};\n\nexport const v2Params = (\n route: StorefrontRoute,\n installation: StorefrontInstallation,\n) => {\n const params = stateParams(route);\n const menu = params.get(\"menu_id\");\n if (menu) {\n params.set(\"menu\", publicId(menu, \"menu\"));\n }\n for (const key of [\n \"menu_id\",\n \"category_id\",\n \"pickup\",\n \"menu_layout\",\n \"catalogue_search\",\n \"catalogue_categories\",\n \"template\",\n \"catalog_rendering\",\n \"prefetch\",\n \"ws\",\n \"env\",\n \"business\",\n \"business_tag\",\n \"switched_branch\",\n \"success\",\n \"auto_scroll\",\n \"preview\",\n \"modal_id\",\n ]) {\n params.delete(key);\n }\n\n if (\"business\" in route) {\n if (route.branch && route.branch !== installation.defaultBranch) {\n params.set(\"branch\", route.branch);\n } else {\n params.delete(\"branch\");\n }\n }\n if (route.type === \"sign-in\") {\n params.delete(\"auth_modal_id\");\n if (route.returnTo !== undefined) {\n params.set(\"return\", route.returnTo);\n }\n }\n if (route.type === \"checkout-return\" && route.session !== undefined) {\n params.set(\"session\", route.session);\n }\n params.sort();\n return params;\n};\n"],
|
|
5
|
+
"mappings": ";AA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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAG;AACD,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,MAAI,cAAc,OAAO;AACvB,QAAI,MAAM,UAAU,MAAM,WAAW,aAAa,eAAe;AAC/D,aAAO,IAAI,UAAU,MAAM,MAAM;AAAA,IACnC,OAAO;AACL,aAAO,OAAO,QAAQ;AAAA,IACxB;AAAA,EACF;AACA,MAAI,MAAM,SAAS,WAAW;AAC5B,WAAO,OAAO,eAAe;AAC7B,QAAI,MAAM,aAAa,QAAW;AAChC,aAAO,IAAI,UAAU,MAAM,QAAQ;AAAA,IACrC;AAAA,EACF;AACA,MAAI,MAAM,SAAS,qBAAqB,MAAM,YAAY,QAAW;AACnE,WAAO,IAAI,WAAW,MAAM,OAAO;AAAA,EACrC;AACA,SAAO,KAAK;AACZ,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,13 +9,12 @@ var FIXED_ROUTES = {
|
|
|
9
9
|
"/reservation": "reservation"
|
|
10
10
|
};
|
|
11
11
|
var ID_ROUTES = {
|
|
12
|
-
"dine-in":
|
|
13
|
-
"pay-point":
|
|
14
|
-
beacons:
|
|
15
|
-
links:
|
|
16
|
-
pay:
|
|
12
|
+
"dine-in": ["dine-in", "order"],
|
|
13
|
+
"pay-point": ["pay-point", "payPoint"],
|
|
14
|
+
beacons: ["beacon", "beacon"],
|
|
15
|
+
links: ["link", "link"],
|
|
16
|
+
pay: ["pay-session", "session"]
|
|
17
17
|
};
|
|
18
|
-
var isKeyOf = (table, key) => Object.hasOwn(table, key);
|
|
19
18
|
var parseV1 = (input, options = {}) => {
|
|
20
19
|
try {
|
|
21
20
|
const url = inputUrl(input);
|
|
@@ -74,23 +73,27 @@ var parseV1 = (input, options = {}) => {
|
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
if (
|
|
78
|
-
return {
|
|
76
|
+
if (Object.hasOwn(FIXED_ROUTES, pathname)) {
|
|
77
|
+
return {
|
|
78
|
+
type: FIXED_ROUTES[pathname],
|
|
79
|
+
state
|
|
80
|
+
};
|
|
79
81
|
}
|
|
80
82
|
const [prefix = "", id] = parts;
|
|
81
|
-
if (parts.length === 2 && id &&
|
|
82
|
-
|
|
83
|
+
if (parts.length === 2 && id && Object.hasOwn(ID_ROUTES, prefix)) {
|
|
84
|
+
const [type, field] = ID_ROUTES[prefix];
|
|
85
|
+
return { type, [field]: segment(parts, 1), state };
|
|
83
86
|
}
|
|
84
87
|
if (parts[0] === "payment" && parts[1] === "card" && parts[2] && parts.length === 3) {
|
|
85
88
|
return { type: "payment-card", transaction: segment(parts, 2), state };
|
|
86
89
|
}
|
|
87
90
|
if (parts[0] === "payment" && parts[1] && parts.length <= 3) {
|
|
88
91
|
const step = parts[2];
|
|
89
|
-
if (!step ||
|
|
92
|
+
if (!step || ["successful", "failed", "refunded"].includes(step)) {
|
|
90
93
|
return {
|
|
91
94
|
type: "payment-step",
|
|
92
95
|
payment: segment(parts, 1),
|
|
93
|
-
step: step
|
|
96
|
+
step: step || "payment",
|
|
94
97
|
state
|
|
95
98
|
};
|
|
96
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/storefront-url/parse-v1.ts"],
|
|
4
|
-
"sourcesContent": ["import { installationPath, normalizedPath, segment } from \"./installation\";\nimport {\n type
|
|
5
|
-
"mappings": ";AAAA,SAAS,kBAAkB,gBAAgB,eAAe;AAC1D,
|
|
4
|
+
"sourcesContent": ["import { installationPath, normalizedPath, segment } from \"./installation\";\nimport {\n type StorefrontRoute,\n type StorefrontUrlInput,\n type StorefrontUrlOptions,\n} from \"./types\";\nimport { ITEM_MODAL_PREFIX, inputUrl, pageState } from \"./url\";\n\n/** Paths with no variable segment. Checked before ID_ROUTES: `/dine-in/menus` is not a dine-in order. */\nconst FIXED_ROUTES = {\n \"/dine-in/menus\": \"dine-in-menus\",\n \"/self-service/menus\": \"self-service-menus\",\n \"/collect-payment\": \"collect-payment\",\n \"/reservation\": \"reservation\",\n} as const;\n\n/** `/<prefix>/<id>` routes, where the one segment after the prefix names the resource. */\nconst ID_ROUTES = {\n \"dine-in\": [\"dine-in\", \"order\"],\n \"pay-point\": [\"pay-point\", \"payPoint\"],\n beacons: [\"beacon\", \"beacon\"],\n links: [\"link\", \"link\"],\n pay: [\"pay-session\", \"session\"],\n} as const;\n\nexport const parseV1 = (\n input: StorefrontUrlInput,\n options: StorefrontUrlOptions = {},\n): StorefrontRoute => {\n try {\n const url = inputUrl(input);\n const state = pageState(url, \"v1\");\n const pathname = installationPath(\n normalizedPath(url.pathname),\n options.installation,\n );\n const parts = pathname.split(\"/\").filter(Boolean);\n\n if (parts[0] === \"order\" && parts[1]) {\n const business = segment(parts, 1);\n if (parts[2] === \"pages\" && parts.length === 4) {\n return {\n type: \"content-page\",\n business,\n slug: segment(parts, 3),\n state,\n };\n }\n const branch = parts[2] ? segment(parts, 2) : undefined;\n if (branch && parts[3] === \"pages\" && parts.length === 5) {\n return {\n type: \"content-page\",\n business,\n branch,\n slug: segment(parts, 4),\n state,\n };\n }\n if (branch && parts[3] === \"products\" && parts[4] && parts.length === 5) {\n return {\n type: \"item\",\n business,\n branch,\n item: segment(parts, 4),\n state,\n };\n }\n if (\n parts.length <= 3 ||\n (parts.length === 4 && parts[3] === \"products\")\n ) {\n const modalItem = state.modalId?.startsWith(ITEM_MODAL_PREFIX)\n ? state.modalId.slice(ITEM_MODAL_PREFIX.length)\n : \"\";\n if (branch && modalItem) {\n return {\n type: \"item\",\n business,\n branch,\n item: modalItem,\n state,\n };\n }\n return {\n type: \"order-menu\",\n business,\n ...(branch ? { branch } : {}),\n ...(parts[3] === \"products\" ? { cataloguePath: true } : {}),\n state,\n };\n }\n }\n\n if (Object.hasOwn(FIXED_ROUTES, pathname)) {\n return {\n type: FIXED_ROUTES[pathname as keyof typeof FIXED_ROUTES],\n state,\n };\n }\n const [prefix = \"\", id] = parts;\n if (parts.length === 2 && id && Object.hasOwn(ID_ROUTES, prefix)) {\n const [type, field] = ID_ROUTES[prefix as keyof typeof ID_ROUTES];\n return { type, [field]: segment(parts, 1), state } as StorefrontRoute;\n }\n if (\n parts[0] === \"payment\" &&\n parts[1] === \"card\" &&\n parts[2] &&\n parts.length === 3\n ) {\n return { type: \"payment-card\", transaction: segment(parts, 2), state };\n }\n if (parts[0] === \"payment\" && parts[1] && parts.length <= 3) {\n const step = parts[2];\n if (!step || [\"successful\", \"failed\", \"refunded\"].includes(step)) {\n return {\n type: \"payment-step\",\n payment: segment(parts, 1),\n step: (step || \"payment\") as Extract<\n StorefrontRoute,\n { type: \"payment-step\" }\n >[\"step\"],\n state,\n };\n }\n }\n if (parts[0] === \"orders\" && parts.length <= 2) {\n return {\n type: \"profile\",\n page: \"orders\",\n ...(parts[1] ? { order: segment(parts, 1) } : {}),\n state,\n };\n }\n if (parts[0] === \"profile\" && parts[1] && parts.length <= 3) {\n const page = parts[1];\n if (\n page === \"add-store-credit\" ||\n page === \"edit\" ||\n page === \"payment-methods\" ||\n page === \"transactions\"\n ) {\n return { type: \"profile\", page, state };\n }\n if (page === \"orders\") {\n return {\n type: \"profile\",\n page,\n ...(parts[2] ? { order: segment(parts, 2) } : {}),\n state,\n };\n }\n }\n if (pathname === \"/\" || pathname === \"/explore\") {\n return {\n type: \"explore\",\n ...(pathname === \"/\" ? { home: true } : {}),\n state,\n };\n }\n return { type: \"unknown\", pathname, state };\n } catch {\n return { type: \"unknown\", pathname: \"\", state: { query: {} } };\n }\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,kBAAkB,gBAAgB,eAAe;AAC1D,OAIO;AACP,SAAS,mBAAmB,UAAU,iBAAiB;AAGvD,IAAM,eAAe;AAA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UACL,MAAM;AAAA,UACN,SAAS,QAAQ,OAAO,CAAC;AAAA,UACzB,MAAO,QAAQ;AAAA,UAIf;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,CAAC,MAAM,YAAY,MAAM,UAAU,GAAG;AAC9C,aAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM;AAAA,QACN,GAAI,MAAM,CAAC,IAAI,EAAE,OAAO,QAAQ,OAAO,CAAC,EAAE,IAAI,CAAC;AAAA,QAC/C;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,CAAC,MAAM,aAAa,MAAM,CAAC,KAAK,MAAM,UAAU,GAAG;AAC3D,YAAM,OAAO,MAAM,CAAC;AACpB,UACE,SAAS,sBACT,SAAS,UACT,SAAS,qBACT,SAAS,gBACT;AACA,eAAO,EAAE,MAAM,WAAW,MAAM,MAAM;AAAA,MACxC;AACA,UAAI,SAAS,UAAU;AACrB,eAAO;AAAA,UACL,MAAM;AAAA,UACN;AAAA,UACA,GAAI,MAAM,CAAC,IAAI,EAAE,OAAO,QAAQ,OAAO,CAAC,EAAE,IAAI,CAAC;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,QAAI,aAAa,OAAO,aAAa,YAAY;AAC/C,aAAO;AAAA,QACL,MAAM;AAAA,QACN,GAAI,aAAa,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AACA,WAAO,EAAE,MAAM,WAAW,UAAU,MAAM;AAAA,EAC5C,QAAQ;AACN,WAAO,EAAE,MAAM,WAAW,UAAU,IAAI,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE;AAAA,EAC/D;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,69 +1,43 @@
|
|
|
1
1
|
// src/server/storefront-url/parse-v2.ts
|
|
2
|
-
import {
|
|
2
|
+
import { canonicalRoute } from "./canonical.js";
|
|
3
3
|
import { normalizedPath, segment } from "./installation.js";
|
|
4
4
|
import { parseV1 } from "./parse-v1.js";
|
|
5
|
-
import {
|
|
6
|
-
import { ITEM_MODAL_PREFIX, inputUrl, pageState } from "./url.js";
|
|
7
|
-
var branch = (url) => url.searchParams.has("branch") ? { branch: url.searchParams.get("branch") ?? "" } : {};
|
|
5
|
+
import { inputUrl, pageState } from "./url.js";
|
|
8
6
|
var canonical = (url, state, business) => {
|
|
9
7
|
const pathname = normalizedPath(url.pathname);
|
|
10
8
|
const parts = pathname.split("/").filter(Boolean);
|
|
11
|
-
const
|
|
9
|
+
const branch = url.searchParams.get("branch");
|
|
10
|
+
const common = { business, ...branch !== null ? { branch } : {}, state };
|
|
12
11
|
if (pathname === "/") {
|
|
13
|
-
return { type: "order-menu",
|
|
12
|
+
return { type: "order-menu", ...common };
|
|
14
13
|
}
|
|
15
14
|
if (parts[0] === "item" && parts[1] && parts.length === 2) {
|
|
16
15
|
return {
|
|
17
16
|
type: "item",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
item: segment(parts, 1),
|
|
21
|
-
state
|
|
17
|
+
...common,
|
|
18
|
+
item: segment(parts, 1)
|
|
22
19
|
};
|
|
23
20
|
}
|
|
24
21
|
if (pathname === "/cart" || pathname === "/checkout") {
|
|
25
22
|
return {
|
|
26
23
|
type: pathname === "/cart" ? "cart" : "checkout",
|
|
27
|
-
|
|
28
|
-
...scoped,
|
|
29
|
-
state
|
|
24
|
+
...common
|
|
30
25
|
};
|
|
31
26
|
}
|
|
32
|
-
if (pathname === "/checkout/return") {
|
|
33
|
-
const
|
|
27
|
+
if (pathname === "/checkout/return" || pathname === "/sign-in") {
|
|
28
|
+
const signIn = pathname === "/sign-in";
|
|
29
|
+
const value = url.searchParams.get(signIn ? "return" : "session");
|
|
34
30
|
return {
|
|
35
|
-
type: "checkout-return",
|
|
36
|
-
|
|
37
|
-
...
|
|
38
|
-
...session !== null ? { session } : {},
|
|
39
|
-
state
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (pathname === "/sign-in") {
|
|
43
|
-
const returnTo = url.searchParams.get("return");
|
|
44
|
-
return {
|
|
45
|
-
type: "sign-in",
|
|
46
|
-
business,
|
|
47
|
-
...scoped,
|
|
48
|
-
...returnTo !== null ? { returnTo } : {},
|
|
49
|
-
state
|
|
31
|
+
type: signIn ? "sign-in" : "checkout-return",
|
|
32
|
+
...common,
|
|
33
|
+
...value !== null ? { [signIn ? "returnTo" : "session"]: value } : {}
|
|
50
34
|
};
|
|
51
35
|
}
|
|
52
36
|
if (parts[0] === "pages" && parts[1] && parts.length === 2) {
|
|
53
37
|
return {
|
|
54
38
|
type: "content-page",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
slug: segment(parts, 1),
|
|
58
|
-
state
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (parts[0] === "orders" && parts.length <= 2) {
|
|
62
|
-
return {
|
|
63
|
-
type: "profile",
|
|
64
|
-
page: "orders",
|
|
65
|
-
...parts[1] ? { order: segment(parts, 1) } : {},
|
|
66
|
-
state
|
|
39
|
+
...common,
|
|
40
|
+
slug: segment(parts, 1)
|
|
67
41
|
};
|
|
68
42
|
}
|
|
69
43
|
if (parts[0] === "account" && parts.length <= 2) {
|
|
@@ -86,49 +60,13 @@ var canonical = (url, state, business) => {
|
|
|
86
60
|
}
|
|
87
61
|
return null;
|
|
88
62
|
};
|
|
89
|
-
var overlay = (route, installation) => {
|
|
90
|
-
if (route.type !== "order-menu") {
|
|
91
|
-
return route;
|
|
92
|
-
}
|
|
93
|
-
const { authModalId, modalId } = route.state;
|
|
94
|
-
if (authModalId && SIGN_IN_MODALS.has(authModalId)) {
|
|
95
|
-
return signInFromOverlay(route, installation);
|
|
96
|
-
}
|
|
97
|
-
if (modalId?.startsWith(ITEM_MODAL_PREFIX)) {
|
|
98
|
-
return {
|
|
99
|
-
type: "item",
|
|
100
|
-
business: route.business,
|
|
101
|
-
...route.branch !== void 0 ? { branch: route.branch } : {},
|
|
102
|
-
item: modalId.slice(ITEM_MODAL_PREFIX.length),
|
|
103
|
-
state: route.state
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (modalId === CART_MODAL || modalId === CHECKOUT_MODAL) {
|
|
107
|
-
return {
|
|
108
|
-
type: modalId === CART_MODAL ? "cart" : "checkout",
|
|
109
|
-
business: route.business,
|
|
110
|
-
...route.branch !== void 0 ? { branch: route.branch } : {},
|
|
111
|
-
state: route.state
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return route;
|
|
115
|
-
};
|
|
116
63
|
var parseV2 = (input, options) => {
|
|
117
64
|
try {
|
|
118
65
|
const url = inputUrl(input);
|
|
119
66
|
const state = pageState(url);
|
|
120
67
|
const installation = options.installation;
|
|
121
|
-
if (!installation) {
|
|
122
|
-
return parseV1(input, options);
|
|
123
|
-
}
|
|
124
68
|
const route = canonical(url, state, installation.business);
|
|
125
|
-
|
|
126
|
-
return route.type === "order-menu" ? overlay(route, installation) : route;
|
|
127
|
-
}
|
|
128
|
-
return overlay(
|
|
129
|
-
parseV1(input, { ...options, contract: "v1" }),
|
|
130
|
-
installation
|
|
131
|
-
);
|
|
69
|
+
return canonicalRoute(route ?? parseV1(input, options), installation);
|
|
132
70
|
} catch {
|
|
133
71
|
return { type: "unknown", pathname: "", state: { query: {} } };
|
|
134
72
|
}
|