@wocart/storefront 2.1.0 → 3.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/dist/whatsapp.js CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * WhatsApp prefill messages — the storefront's message rule.
3
- *
4
- * A storefront's WhatsApp launcher hands the shopper to WhatsApp with the
5
- * message already written. The template belongs to the merchant (the dashboard
6
- * authors it within the limits below), and the page
7
- * resolves it: `{store}`, `{product}`, `{url}`, `{order}`.
8
- *
9
- * Three rules live here so no theme re-invents them:
10
- *
11
- * 1. **Ad-click parameters are stripped from `{url}`.** A shopper arriving from
12
- * a paid ad should not hand the merchant's WhatsApp a `fbclid`-laden link.
13
- * 2. **The resolved message is capped at `MAX_RESOLVED_PREFILL_LENGTH`, cut at
14
- * a word boundary.** Browsers and WhatsApp both truncate silently past a
15
- * point; a cut mid-word reads as a broken store.
16
- * 3. **The encoded text is appended the same way everywhere**, so a base href
17
- * that already carries a query string keeps it.
18
- */
19
1
  /**
20
2
  * The hard cap on a resolved prefill message, in characters.
21
3
  *
@@ -87,3 +69,35 @@ export function buildWhatsAppHref(baseHref, text) {
87
69
  const separator = baseHref.includes("?") ? "&" : "?";
88
70
  return `${baseHref}${separator}text=${encodeURIComponent(text)}`;
89
71
  }
72
+ /**
73
+ * The store's WhatsApp for one page, or null when it has none: every link a
74
+ * theme draws to it — the launcher, a footer or menu link, a contact card,
75
+ * the order confirmation's button — comes from here, so each carries the
76
+ * page's message and every text is in the page's language.
77
+ *
78
+ * Each text is the merchant's when they wrote one, else the theme's `words`.
79
+ * The message is the page's own template (a product's, an order's), else the
80
+ * merchant's general one, else the theme's for that kind of page.
81
+ */
82
+ export function whatsAppContact(config, page, words) {
83
+ const widget = config.whatsapp;
84
+ if (!widget)
85
+ return null;
86
+ const own = page.kind === "product" ? widget.prefillProduct : page.kind === "order" ? widget.prefillThankYou : null;
87
+ const template = own ?? widget.prefillGeneral ?? words.messages[page.kind];
88
+ const message = resolvePrefillText({ template, storeName: config.name, productName: page.product ?? null, url: page.url, orderNumber: page.order ?? null });
89
+ return {
90
+ href: buildWhatsAppHref(widget.href, message),
91
+ launcherLabel: widget.launcherLabel ?? words.launcher,
92
+ caption: widget.caption ?? words.caption,
93
+ welcomeMessage: widget.welcomeMessage ?? words.welcome,
94
+ ctaLabel: widget.ctaLabel ?? words.cta,
95
+ orderButtonLabel: widget.thankYouButtonLabel ?? words.orderButton,
96
+ agentName: widget.agentName ?? config.name,
97
+ avatarUrl: widget.avatarUrl,
98
+ accent: widget.accent,
99
+ position: widget.position,
100
+ attention: widget.attention,
101
+ surfaces: widget.surfaces,
102
+ };
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocart/storefront",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Typed, validated SDK for Wocart cash-on-delivery storefronts: catalog reads, basket, checkout, OTP and order tracking, with Astro adapters.",
5
5
  "keywords": [
6
6
  "wocart",