@wocart/storefront 0.0.0-stage → 1.1.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 +95 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +144 -2
- package/USAGE.md +1470 -0
- package/dist/abandoned-checkout.d.ts +22 -0
- package/dist/abandoned-checkout.js +89 -0
- package/dist/actions.d.ts +117 -0
- package/dist/actions.js +196 -0
- package/dist/astro.d.ts +6 -0
- package/dist/astro.js +3 -0
- package/dist/basket.d.ts +87 -0
- package/dist/basket.js +258 -0
- package/dist/client/cart.d.ts +30 -0
- package/dist/client/cart.js +26 -0
- package/dist/client/categories.d.ts +25 -0
- package/dist/client/categories.js +37 -0
- package/dist/client/config.d.ts +29 -0
- package/dist/client/config.js +41 -0
- package/dist/client/core.d.ts +88 -0
- package/dist/client/core.js +566 -0
- package/dist/client/errors.d.ts +19 -0
- package/dist/client/errors.js +31 -0
- package/dist/client/geo.d.ts +31 -0
- package/dist/client/geo.js +39 -0
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +81 -0
- package/dist/client/orders.d.ts +68 -0
- package/dist/client/orders.js +76 -0
- package/dist/client/page-data.d.ts +30 -0
- package/dist/client/page-data.js +36 -0
- package/dist/client/pages.d.ts +33 -0
- package/dist/client/pages.js +44 -0
- package/dist/client/paths.d.ts +8 -0
- package/dist/client/paths.js +10 -0
- package/dist/client/products.d.ts +56 -0
- package/dist/client/products.js +78 -0
- package/dist/client/shipping.d.ts +36 -0
- package/dist/client/shipping.js +47 -0
- package/dist/data/communes.d.ts +25 -0
- package/dist/data/communes.js +1690 -0
- package/dist/data/wilayas.d.ts +6 -0
- package/dist/data/wilayas.js +64 -0
- package/dist/domain.d.ts +341 -0
- package/dist/domain.js +214 -0
- package/dist/endpoints/proxy.d.ts +111 -0
- package/dist/endpoints/proxy.js +161 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +30 -0
- package/dist/locale-routing.d.ts +59 -0
- package/dist/locale-routing.js +62 -0
- package/dist/locales.d.ts +15 -0
- package/dist/locales.js +8 -0
- package/dist/meta-tracking.d.ts +34 -0
- package/dist/meta-tracking.js +72 -0
- package/dist/middleware.d.ts +100 -0
- package/dist/middleware.js +72 -0
- package/dist/offer-view.d.ts +10 -0
- package/dist/offer-view.js +13 -0
- package/dist/otp.d.ts +80 -0
- package/dist/otp.js +295 -0
- package/dist/phone.d.ts +2 -0
- package/dist/phone.js +34 -0
- package/dist/product-view.d.ts +12 -0
- package/dist/product-view.js +42 -0
- package/dist/routes.d.ts +45 -0
- package/dist/routes.js +59 -0
- package/dist/schemas.d.ts +753 -0
- package/dist/schemas.js +377 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +2 -0
- package/dist/types.d.ts +418 -0
- package/dist/types.js +1 -0
- package/dist/utils/image.d.ts +140 -0
- package/dist/utils/image.js +131 -0
- package/dist/utils/money.d.ts +39 -0
- package/dist/utils/money.js +43 -0
- package/dist/utils/product-image.d.ts +37 -0
- package/dist/utils/product-image.js +38 -0
- package/dist/whatsapp.d.ts +55 -0
- package/dist/whatsapp.js +89 -0
- package/package.json +76 -4
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical storefront route contract.
|
|
3
|
+
*
|
|
4
|
+
* One deployment serves one store, and three parts of the platform meet on the
|
|
5
|
+
* same public URLs: the theme renders them, the server writes them into a conversion's
|
|
6
|
+
* landing URL (`/lp/:slug` for an attributed sale, `/thank-you` otherwise), and
|
|
7
|
+
* the dashboard shows them as the store's public links (`/pages/:slug`). These
|
|
8
|
+
* patterns are what all three already assume, so they are written down here: a
|
|
9
|
+
* theme may restyle everything else, but these paths are a platform contract,
|
|
10
|
+
* not a theme decision.
|
|
11
|
+
*
|
|
12
|
+
* Two further paths carry no parameter and no pattern: the root (`/`, the home
|
|
13
|
+
* surface) and the catalog index (`/products`, the catalog surface). The
|
|
14
|
+
* surface gate below handles them alongside the six frozen patterns.
|
|
15
|
+
*/
|
|
16
|
+
import type { WidgetSurfaces } from "./types.js";
|
|
17
|
+
/** One route in the contract: the pattern and the surface that renders it. */
|
|
18
|
+
export interface StorefrontRoute {
|
|
19
|
+
/** Path pattern; `:handle` and `:slug` mark the single path parameter. */
|
|
20
|
+
readonly path: string;
|
|
21
|
+
/** The `surfaces` key this route belongs to. */
|
|
22
|
+
readonly surface: keyof WidgetSurfaces;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The frozen contract. Adding a route is a deliberate platform change: a path
|
|
26
|
+
* that renders a surface but is missing here is a surface the merchant cannot
|
|
27
|
+
* switch on with any confidence.
|
|
28
|
+
*/
|
|
29
|
+
export declare const STOREFRONT_ROUTES: readonly StorefrontRoute[];
|
|
30
|
+
/**
|
|
31
|
+
* Whether the widget belongs on a pathname.
|
|
32
|
+
*
|
|
33
|
+
* The merchant answers "which surfaces" (`surfaces[surface]`); this function
|
|
34
|
+
* answers the platform half — which surface a pathname *is* — and it reads the
|
|
35
|
+
* contract above:
|
|
36
|
+
*
|
|
37
|
+
* - `/` → the home surface;
|
|
38
|
+
* - `/products` (the catalog index) and `/category/:slug` → the catalog surface;
|
|
39
|
+
* - `/products/:handle` → the product surface;
|
|
40
|
+
* - `/pages/:slug`, `/lp/:slug`, `/checkout`, `/thank-you` → their own surfaces;
|
|
41
|
+
* - anything else — a 404, `/productsomething`, `/checkout-success` — → no
|
|
42
|
+
* surface at all, never a prefix match that leaks a widget onto a page the
|
|
43
|
+
* merchant switched off.
|
|
44
|
+
*/
|
|
45
|
+
export declare function showsWidgetOn(surfaces: WidgetSurfaces | null | undefined, rawPathname: string): boolean;
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frozen contract. Adding a route is a deliberate platform change: a path
|
|
3
|
+
* that renders a surface but is missing here is a surface the merchant cannot
|
|
4
|
+
* switch on with any confidence.
|
|
5
|
+
*/
|
|
6
|
+
export const STOREFRONT_ROUTES = [
|
|
7
|
+
{ path: "/products/:handle", surface: "product" },
|
|
8
|
+
{ path: "/category/:slug", surface: "catalog" },
|
|
9
|
+
{ path: "/pages/:slug", surface: "pages" },
|
|
10
|
+
{ path: "/lp/:slug", surface: "landing" },
|
|
11
|
+
{ path: "/checkout", surface: "checkout" },
|
|
12
|
+
{ path: "/thank-you", surface: "thankYou" },
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Whether the widget belongs on a pathname.
|
|
16
|
+
*
|
|
17
|
+
* The merchant answers "which surfaces" (`surfaces[surface]`); this function
|
|
18
|
+
* answers the platform half — which surface a pathname *is* — and it reads the
|
|
19
|
+
* contract above:
|
|
20
|
+
*
|
|
21
|
+
* - `/` → the home surface;
|
|
22
|
+
* - `/products` (the catalog index) and `/category/:slug` → the catalog surface;
|
|
23
|
+
* - `/products/:handle` → the product surface;
|
|
24
|
+
* - `/pages/:slug`, `/lp/:slug`, `/checkout`, `/thank-you` → their own surfaces;
|
|
25
|
+
* - anything else — a 404, `/productsomething`, `/checkout-success` — → no
|
|
26
|
+
* surface at all, never a prefix match that leaks a widget onto a page the
|
|
27
|
+
* merchant switched off.
|
|
28
|
+
*/
|
|
29
|
+
export function showsWidgetOn(surfaces, rawPathname) {
|
|
30
|
+
if (!surfaces)
|
|
31
|
+
return false;
|
|
32
|
+
// Normalise: strip query/hash, strip trailing slashes (except root "/")
|
|
33
|
+
const pathname = rawPathname.split("?")[0].split("#")[0].replace(/\/+$/, "") || "/";
|
|
34
|
+
if (pathname === "/") {
|
|
35
|
+
return Boolean(surfaces.home);
|
|
36
|
+
}
|
|
37
|
+
if (pathname === "/products" || pathname.startsWith("/category/")) {
|
|
38
|
+
return Boolean(surfaces.catalog);
|
|
39
|
+
}
|
|
40
|
+
if (pathname.startsWith("/products/")) {
|
|
41
|
+
const slug = pathname.slice("/products/".length);
|
|
42
|
+
return slug.length > 0 ? Boolean(surfaces.product) : Boolean(surfaces.catalog);
|
|
43
|
+
}
|
|
44
|
+
if (pathname === "/checkout") {
|
|
45
|
+
return Boolean(surfaces.checkout);
|
|
46
|
+
}
|
|
47
|
+
if (pathname === "/thank-you") {
|
|
48
|
+
return Boolean(surfaces.thankYou);
|
|
49
|
+
}
|
|
50
|
+
if (pathname.startsWith("/pages/")) {
|
|
51
|
+
const slug = pathname.slice("/pages/".length);
|
|
52
|
+
return slug.length > 0 ? Boolean(surfaces.pages) : false;
|
|
53
|
+
}
|
|
54
|
+
if (pathname.startsWith("/lp/")) {
|
|
55
|
+
const slug = pathname.slice("/lp/".length);
|
|
56
|
+
return slug.length > 0 ? Boolean(surfaces.landing) : false;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|