@joy-loyalty/hydrogen 0.2.0 → 0.3.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.
Files changed (33) hide show
  1. package/README.md +118 -4
  2. package/dist/csp.d.ts +1 -1
  3. package/dist/csp.js +2 -2
  4. package/dist/headless-host-adapter.js +3 -2
  5. package/dist/host-adapter/capabilities.d.ts +1 -0
  6. package/dist/host-adapter/capabilities.js +3 -0
  7. package/dist/host-adapter/product-fetcher.d.ts +1 -1
  8. package/dist/host-adapter/product-fetcher.js +3 -2
  9. package/dist/host-adapter/promoted-collections.d.ts +1 -1
  10. package/dist/host-adapter/promoted-collections.js +3 -2
  11. package/dist/hydrogen-cart-port.d.ts +49 -1
  12. package/dist/hydrogen-cart-port.js +24 -1
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.js +1 -0
  15. package/dist/joy-widget.js +2 -2
  16. package/dist/lib/core-loader.d.ts +23 -0
  17. package/dist/lib/recommended-loader.d.ts +2 -1
  18. package/dist/lib/recommended-loader.js +5 -3
  19. package/dist/lib/redeem-cart-snapshot.d.ts +51 -0
  20. package/dist/lib/redeem-cart-snapshot.js +173 -0
  21. package/dist/orchestrator/handlers/account.js +1 -1
  22. package/dist/orchestrator/handlers/earn.js +9 -0
  23. package/dist/orchestrator/handlers/milestone-tier.js +1 -1
  24. package/dist/redeem-cart/JoyRedeemCart.d.ts +19 -0
  25. package/dist/redeem-cart/JoyRedeemCart.js +321 -0
  26. package/dist/routes/joy-products.js +22 -10
  27. package/dist/server/get-joy-initial-data.d.ts +1 -0
  28. package/dist/server/get-joy-initial-data.js +5 -1
  29. package/dist/server/get-joy-loyalty-page-data.d.ts +1 -0
  30. package/dist/server/get-joy-loyalty-page-data.js +1 -1
  31. package/dist/widget-orchestrator.d.ts +1 -0
  32. package/dist/widget-orchestrator.js +8 -2
  33. package/package.json +2 -2
@@ -2,12 +2,15 @@ import { createJoyClient } from '@joy-loyalty/sdk/client';
2
2
  import { getJoyMetafieldBlob } from '../lib/metafield-blob.js';
3
3
  import { mintJoyToken } from '../lib/server-token.js';
4
4
  import { resolveShopLocale } from '../lib/shop-locale.js';
5
+ import { toShopifyLocale } from './get-joy-loyalty-page-data.js';
5
6
  import { getWidgetCoreManifest } from '../lib/core-manifest.js';
6
7
  const DEFAULT_LOGIN_URL = '/account/login';
7
8
  const DEFAULT_REGISTER_URL = '/account/register';
8
9
  const DEFAULT_ACCOUNT_URL = '/account';
9
10
  export async function getJoyInitialData(options) {
10
- const { storefront, customerAccount, apiUrl, shopDomain, secret, locale, loginUrl = DEFAULT_LOGIN_URL, registerUrl = DEFAULT_REGISTER_URL, accountUrl = DEFAULT_ACCOUNT_URL, request, exposeToken = false, assetUrl, deferCustomerBalance = false } = options;
11
+ const { storefront, customerAccount, apiUrl, shopDomain, secret, loginUrl = DEFAULT_LOGIN_URL, registerUrl = DEFAULT_REGISTER_URL, accountUrl = DEFAULT_ACCOUNT_URL, request, exposeToken = false, assetUrl, deferCustomerBalance = false } = options;
12
+ const i18n = storefront.i18n;
13
+ const locale = options.locale ?? (i18n?.language ? toShopifyLocale(i18n.language) : undefined);
11
14
  const [blob, customerHalf, core] = await Promise.all([
12
15
  getJoyMetafieldBlob(storefront),
13
16
  fetchCustomerHalf({ customerAccount, apiUrl, shopDomain, secret, locale, deferCustomerBalance }),
@@ -20,6 +23,7 @@ export async function getJoyInitialData(options) {
20
23
  ...(customerHalf.shopifyCustomer !== undefined ? { shopifyCustomer: customerHalf.shopifyCustomer } : {}),
21
24
  ...(exposeToken && customerHalf.token !== undefined ? { token: customerHalf.token } : {}),
22
25
  ...(locale !== undefined ? { locale: resolveShopLocale(locale, blob?.translation) } : {}),
26
+ ...(i18n?.country ? { country: i18n.country } : {}),
23
27
  login_url: loginUrl,
24
28
  register_url: registerUrl,
25
29
  account_url: accountUrl,
@@ -25,3 +25,4 @@ export interface GetJoyLoyaltyPageDataOptions {
25
25
  }
26
26
  export declare function getJoyLoyaltyPageData(options: GetJoyLoyaltyPageDataOptions): Promise<JoyLoyaltyPageData>;
27
27
  export declare function projectTranslations(translations: Record<string, unknown>, locale: string): Record<string, unknown>;
28
+ export declare function toShopifyLocale(language: string): string;
@@ -93,7 +93,7 @@ function blobWithoutHostFields(blob) {
93
93
  const { translation: _translation, shop: _shop, ...rest } = blob;
94
94
  return rest;
95
95
  }
96
- function toShopifyLocale(language) {
96
+ export function toShopifyLocale(language) {
97
97
  const [lang, region] = language.split('_');
98
98
  return region ? `${lang.toLowerCase()}-${region.toUpperCase()}` : lang.toLowerCase();
99
99
  }
@@ -27,6 +27,7 @@ export interface HeadlessInitialData extends JoyInitialData {
27
27
  handle: string;
28
28
  };
29
29
  locale?: string;
30
+ country?: string;
30
31
  token?: string;
31
32
  }
32
33
  export type BlobCustomer = JoyInitialData['customer'] | Record<string, unknown>;
@@ -109,6 +109,10 @@ export function writeProps(element, props) {
109
109
  if (value === undefined || value === null)
110
110
  continue;
111
111
  const property = key.replace(/-([a-z])/g, (_, character) => character.toUpperCase());
112
+ if (/[A-Z]/.test(key)) {
113
+ element[property] = value;
114
+ continue;
115
+ }
112
116
  if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {
113
117
  element[property] = value;
114
118
  }
@@ -386,9 +390,10 @@ export function createWidgetOrchestrator(container, hostAdapter, initialData, ap
386
390
  });
387
391
  if (!built)
388
392
  return null;
389
- const { facade } = built;
393
+ const { facade, renderInput } = built;
390
394
  facade.hostAdapter.data = hostAdapter.data;
391
395
  facade.widgetEl = element;
396
+ facade._renderInput = renderInput;
392
397
  return facade;
393
398
  }
394
399
  function loadRecentlyViewed() {
@@ -414,7 +419,8 @@ export function createWidgetOrchestrator(container, hostAdapter, initialData, ap
414
419
  widgetEl: element,
415
420
  sections: Array.isArray(settings?.sections) ? settings.sections : [],
416
421
  productCard: coreExports?.productCard,
417
- currency: renderContext?.currency
422
+ currency: renderContext?.currency,
423
+ country: hostAdapter.context().country || undefined
418
424
  });
419
425
  }
420
426
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joy-loyalty/hydrogen",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Joy Loyalty Widget V4 for any Hydrogen / headless Shopify storefront — host-neutral core embedded through HeadlessHostAdapter. No Weaverse dependency.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -95,7 +95,7 @@
95
95
  }
96
96
  },
97
97
  "dependencies": {
98
- "@joy-loyalty/sdk": "^0.2.0",
98
+ "@joy-loyalty/sdk": "^0.3.0",
99
99
  "dompurify": "^3.1.7"
100
100
  },
101
101
  "devDependencies": {