@wocart/storefront 0.0.0-stage → 1.0.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 +66 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +143 -2
- package/USAGE.md +1465 -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 +86 -0
- package/dist/client/core.js +582 -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 +39 -0
- package/dist/client/index.js +80 -0
- package/dist/client/orders.d.ts +68 -0
- package/dist/client/orders.js +76 -0
- package/dist/client/page-data.d.ts +31 -0
- package/dist/client/page-data.js +37 -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 +37 -0
- package/dist/client/shipping.js +48 -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 +332 -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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shipping Namespace - Delivery Pricing
|
|
3
|
+
*
|
|
4
|
+
* Deep module: hides URL construction and the per-wilaya lookup behind two
|
|
5
|
+
* calls. The server always returns the full per-wilaya map; `rate()` extracts
|
|
6
|
+
* a single wilaya's pair when the caller only needs one.
|
|
7
|
+
*
|
|
8
|
+
* Fetched fresh every request (merchants adjust delivery pricing and expect
|
|
9
|
+
* the next render to show it); parallel identical calls coalesce into one
|
|
10
|
+
* request.
|
|
11
|
+
*
|
|
12
|
+
* Failure contract: resolves to `{}` /
|
|
13
|
+
* `null` on any failure — never throws. Absent wilayas have no rule and are
|
|
14
|
+
* treated as unsupported.
|
|
15
|
+
*/
|
|
16
|
+
import { ShippingRatesSchema } from "../schemas.js";
|
|
17
|
+
import { STOREFRONT_OPERATIONS } from "../domain.js";
|
|
18
|
+
import { reportDegradedRead } from "./core.js";
|
|
19
|
+
/**
|
|
20
|
+
* Create shipping namespace
|
|
21
|
+
*/
|
|
22
|
+
export function createShippingNamespace(core) {
|
|
23
|
+
return {
|
|
24
|
+
async rates() {
|
|
25
|
+
try {
|
|
26
|
+
return ((await core.get("/store/shipping-rates", ShippingRatesSchema.nullable(), {
|
|
27
|
+
operation: STOREFRONT_OPERATIONS.shippingRates,
|
|
28
|
+
})) ?? {});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
reportDegradedRead(core.config, error, "shipping.rates");
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async rate(wilayaId) {
|
|
36
|
+
try {
|
|
37
|
+
const rates = (await core.get("/store/shipping-rates", ShippingRatesSchema.nullable(), {
|
|
38
|
+
operation: STOREFRONT_OPERATIONS.shippingRate,
|
|
39
|
+
})) ?? {};
|
|
40
|
+
return rates[String(wilayaId)] ?? null;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
reportDegradedRead(core.config, error, "shipping.rate");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algeria's 1,551 communes across all 58 wilayas — the reference dataset the
|
|
3
|
+
* checkout's locality field resolves against.
|
|
4
|
+
*
|
|
5
|
+
* Bundled, not fetched: a shopper picking a wilaya gets its communes in the
|
|
6
|
+
* same tick, with no round-trip to fail on a bad mobile connection. The
|
|
7
|
+
* server's rows stay reachable through `geo.communes()`; the two are checked
|
|
8
|
+
* against each other before every release (count, id, wilaya, name, Arabic
|
|
9
|
+
* name).
|
|
10
|
+
*
|
|
11
|
+
* Compact tuple structure: [id, nameFr, nameAr]. Ids are `c-<wilaya>-<n>`, so
|
|
12
|
+
* the wilaya is part of the identity the server returns.
|
|
13
|
+
*/
|
|
14
|
+
import type { Commune } from "../types.js";
|
|
15
|
+
export type CommuneTuple = readonly [id: string, name: string, nameAr: string];
|
|
16
|
+
export declare const ALGERIA_COMMUNES: Readonly<Record<number, readonly CommuneTuple[]>>;
|
|
17
|
+
/**
|
|
18
|
+
* The communes of one wilaya, shaped as the wire model: `Commune[]`.
|
|
19
|
+
*
|
|
20
|
+
* Answers `[]` for a wilaya the bundle does not know — the caller then decides
|
|
21
|
+
* whether that is "no localities to show" or "ask the server" (`geo.communes()`
|
|
22
|
+
* asks). Accepts the string form an `<input>`/`<select>` hands over, so a
|
|
23
|
+
* browser caller never has to parse first.
|
|
24
|
+
*/
|
|
25
|
+
export declare function communesForWilaya(wilayaId: number | string): Commune[];
|