@joy-loyalty/hydrogen 0.0.0-stage → 0.2.1
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/LICENSE +3 -0
- package/README.md +134 -2
- package/dist/cache-control.d.ts +8 -0
- package/dist/cache-control.js +6 -0
- package/dist/csp.d.ts +14 -0
- package/dist/csp.js +33 -0
- package/dist/headless-host-adapter.d.ts +5 -0
- package/dist/headless-host-adapter.js +198 -0
- package/dist/host-adapter/capabilities.d.ts +4 -0
- package/dist/host-adapter/capabilities.js +15 -0
- package/dist/host-adapter/data-source.d.ts +3 -0
- package/dist/host-adapter/data-source.js +49 -0
- package/dist/host-adapter/product-fetcher.d.ts +2 -0
- package/dist/host-adapter/product-fetcher.js +38 -0
- package/dist/host-adapter/promoted-collections.d.ts +2 -0
- package/dist/host-adapter/promoted-collections.js +44 -0
- package/dist/host-adapter/types.d.ts +212 -0
- package/dist/host-adapter/types.js +1 -0
- package/dist/hydrogen-cart-port.d.ts +134 -0
- package/dist/hydrogen-cart-port.js +245 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +15 -0
- package/dist/joy-widget.d.ts +29 -0
- package/dist/joy-widget.js +291 -0
- package/dist/lib/JoyProvider.d.ts +47 -0
- package/dist/lib/JoyProvider.js +95 -0
- package/dist/lib/account-links.d.ts +5 -0
- package/dist/lib/account-links.js +65 -0
- package/dist/lib/apply-behavior.d.ts +12 -0
- package/dist/lib/apply-behavior.js +26 -0
- package/dist/lib/core-loader.d.ts +63 -0
- package/dist/lib/core-loader.js +160 -0
- package/dist/lib/core-manifest.d.ts +7 -0
- package/dist/lib/core-manifest.js +54 -0
- package/dist/lib/core-preload-links.d.ts +8 -0
- package/dist/lib/core-preload-links.js +8 -0
- package/dist/lib/coupon-mapper.d.ts +95 -0
- package/dist/lib/coupon-mapper.js +167 -0
- package/dist/lib/custom-links.d.ts +22 -0
- package/dist/lib/custom-links.js +56 -0
- package/dist/lib/deeplink.d.ts +25 -0
- package/dist/lib/deeplink.js +92 -0
- package/dist/lib/earn-signup-gate.d.ts +3 -0
- package/dist/lib/earn-signup-gate.js +31 -0
- package/dist/lib/facebook-ref-link.d.ts +13 -0
- package/dist/lib/facebook-ref-link.js +31 -0
- package/dist/lib/headless-referral-origin.d.ts +2 -0
- package/dist/lib/headless-referral-origin.js +24 -0
- package/dist/lib/headless-source.d.ts +8 -0
- package/dist/lib/headless-source.js +71 -0
- package/dist/lib/image.d.ts +2 -0
- package/dist/lib/image.js +14 -0
- package/dist/lib/metafield-blob.d.ts +33 -0
- package/dist/lib/metafield-blob.js +76 -0
- package/dist/lib/money.d.ts +6 -0
- package/dist/lib/money.js +25 -0
- package/dist/lib/order-mapper.d.ts +44 -0
- package/dist/lib/order-mapper.js +141 -0
- package/dist/lib/place-order-scope.d.ts +6 -0
- package/dist/lib/place-order-scope.js +22 -0
- package/dist/lib/points.d.ts +5 -0
- package/dist/lib/points.js +10 -0
- package/dist/lib/recently-viewed-tracker.d.ts +1 -0
- package/dist/lib/recently-viewed-tracker.js +34 -0
- package/dist/lib/recommended-loader.d.ts +44 -0
- package/dist/lib/recommended-loader.js +113 -0
- package/dist/lib/referral-share.d.ts +4 -0
- package/dist/lib/referral-share.js +33 -0
- package/dist/lib/safe-navigation-url.d.ts +1 -0
- package/dist/lib/safe-navigation-url.js +9 -0
- package/dist/lib/server-token.d.ts +41 -0
- package/dist/lib/server-token.js +87 -0
- package/dist/lib/shop-locale.d.ts +1 -0
- package/dist/lib/shop-locale.js +21 -0
- package/dist/lib/social-earn.d.ts +11 -0
- package/dist/lib/social-earn.js +25 -0
- package/dist/lib/storefront-fonts.d.ts +5 -0
- package/dist/lib/storefront-fonts.js +52 -0
- package/dist/lib/token.d.ts +14 -0
- package/dist/lib/token.js +135 -0
- package/dist/lib/write-review.d.ts +2 -0
- package/dist/lib/write-review.js +44 -0
- package/dist/loyalty-page/JoyLoyaltyPage.d.ts +151 -0
- package/dist/loyalty-page/JoyLoyaltyPage.js +447 -0
- package/dist/loyalty-page/compose-home.d.ts +35 -0
- package/dist/loyalty-page/compose-home.js +177 -0
- package/dist/loyalty-page/skeleton.d.ts +11 -0
- package/dist/loyalty-page/skeleton.js +99 -0
- package/dist/orchestrator/context.d.ts +61 -0
- package/dist/orchestrator/context.js +64 -0
- package/dist/orchestrator/gated.d.ts +1 -0
- package/dist/orchestrator/gated.js +14 -0
- package/dist/orchestrator/handlers/account.d.ts +19 -0
- package/dist/orchestrator/handlers/account.js +266 -0
- package/dist/orchestrator/handlers/birthday.d.ts +6 -0
- package/dist/orchestrator/handlers/birthday.js +128 -0
- package/dist/orchestrator/handlers/earn.d.ts +5 -0
- package/dist/orchestrator/handlers/earn.js +267 -0
- package/dist/orchestrator/handlers/milestone-tier.d.ts +5 -0
- package/dist/orchestrator/handlers/milestone-tier.js +123 -0
- package/dist/orchestrator/handlers/profile.d.ts +5 -0
- package/dist/orchestrator/handlers/profile.js +262 -0
- package/dist/orchestrator/handlers/redeem.d.ts +6 -0
- package/dist/orchestrator/handlers/redeem.js +464 -0
- package/dist/orchestrator/handlers/referral.d.ts +5 -0
- package/dist/orchestrator/handlers/referral.js +218 -0
- package/dist/orchestrator/render.d.ts +2 -0
- package/dist/orchestrator/render.js +193 -0
- package/dist/render-adapter.d.ts +50 -0
- package/dist/render-adapter.js +422 -0
- package/dist/routes/joy-place-order-scope.d.ts +12 -0
- package/dist/routes/joy-place-order-scope.js +32 -0
- package/dist/routes/joy-products.d.ts +48 -0
- package/dist/routes/joy-products.js +338 -0
- package/dist/routes/joy-token.d.ts +16 -0
- package/dist/routes/joy-token.js +32 -0
- package/dist/server/get-joy-initial-data.d.ts +39 -0
- package/dist/server/get-joy-initial-data.js +65 -0
- package/dist/server/get-joy-loyalty-page-data.d.ts +28 -0
- package/dist/server/get-joy-loyalty-page-data.js +99 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +4 -0
- package/dist/widget-controller.d.ts +2 -0
- package/dist/widget-controller.js +1 -0
- package/dist/widget-orchestrator.d.ts +89 -0
- package/dist/widget-orchestrator.js +504 -0
- package/package.json +121 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getJoyMetafieldBlob } from '../lib/metafield-blob.js';
|
|
2
|
+
import { resolveShopLocale } from '../lib/shop-locale.js';
|
|
3
|
+
import { getWidgetCoreManifest } from '../lib/core-manifest.js';
|
|
4
|
+
const structureByStorefront = new WeakMap();
|
|
5
|
+
async function fetchStructureAndFaqs(options) {
|
|
6
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
7
|
+
const url = `${options.apiUrl.replace(/\/+$/, '')}/loyalty-page/structure?shop=${encodeURIComponent(options.shopDomain)}`;
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetchImpl(url, { headers: { Accept: 'application/json' } });
|
|
10
|
+
if (!response.ok)
|
|
11
|
+
return undefined;
|
|
12
|
+
const envelope = (await response.json());
|
|
13
|
+
if (!envelope || envelope.success !== true)
|
|
14
|
+
return undefined;
|
|
15
|
+
return envelope.data;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function sharedStructureAndFaqs(options) {
|
|
22
|
+
const cached = structureByStorefront.get(options.storefront);
|
|
23
|
+
if (cached)
|
|
24
|
+
return cached;
|
|
25
|
+
const pending = fetchStructureAndFaqs(options);
|
|
26
|
+
structureByStorefront.set(options.storefront, pending);
|
|
27
|
+
return pending;
|
|
28
|
+
}
|
|
29
|
+
function blobToHostFields(blob) {
|
|
30
|
+
const translations = blob?.translation;
|
|
31
|
+
const shop = blob?.shop;
|
|
32
|
+
return {
|
|
33
|
+
translations: isRecord(translations) ? translations : {},
|
|
34
|
+
shop: isRecord(shop) ? shop : {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function isRecord(value) {
|
|
38
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
export async function getJoyLoyaltyPageData(options) {
|
|
41
|
+
const [structureAndFaqs, blob, core] = await Promise.all([
|
|
42
|
+
sharedStructureAndFaqs(options),
|
|
43
|
+
getJoyMetafieldBlob(options.storefront),
|
|
44
|
+
getWidgetCoreManifest({
|
|
45
|
+
...(options.assetUrl ? { assetUrl: options.assetUrl } : {}),
|
|
46
|
+
...(options.fetch ? { fetch: options.fetch } : {})
|
|
47
|
+
})
|
|
48
|
+
]);
|
|
49
|
+
const locale = options.storefront.i18n?.language
|
|
50
|
+
? resolveShopLocale(toShopifyLocale(options.storefront.i18n.language), blob?.translation)
|
|
51
|
+
: undefined;
|
|
52
|
+
const hostFields = blobToHostFields(blob);
|
|
53
|
+
return {
|
|
54
|
+
...(structureAndFaqs?.structure != null ? { structure: structureAndFaqs.structure } : {}),
|
|
55
|
+
...(structureAndFaqs?.faqs !== undefined ? { faqs: structureAndFaqs.faqs } : {}),
|
|
56
|
+
...hostFields,
|
|
57
|
+
translations: locale ? projectTranslations(hostFields.translations, locale) : hostFields.translations,
|
|
58
|
+
...(blob ? { home: blobWithoutHostFields(blob) } : {}),
|
|
59
|
+
...(options.storefront.i18n?.country ? { country: options.storefront.i18n.country } : {}),
|
|
60
|
+
...(locale ? { locale } : {}),
|
|
61
|
+
...(core ? { core } : {})
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function projectTranslations(translations, locale) {
|
|
65
|
+
const dictKeys = Object.keys(translations).filter(key => isRecord(translations[key]));
|
|
66
|
+
if (dictKeys.length === 0)
|
|
67
|
+
return translations;
|
|
68
|
+
const primary = typeof translations.primaryLanguage === 'string' ? translations.primaryLanguage : undefined;
|
|
69
|
+
const keep = new Set();
|
|
70
|
+
for (const wanted of [locale, primary]) {
|
|
71
|
+
const hit = wanted ? matchLocaleKey(dictKeys, wanted) : undefined;
|
|
72
|
+
if (hit)
|
|
73
|
+
keep.add(hit);
|
|
74
|
+
}
|
|
75
|
+
if (keep.size === 0)
|
|
76
|
+
return translations;
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const [key, value] of Object.entries(translations)) {
|
|
79
|
+
if (!isRecord(value) || keep.has(key))
|
|
80
|
+
out[key] = value;
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
function matchLocaleKey(keys, wanted) {
|
|
85
|
+
const lower = wanted.toLowerCase();
|
|
86
|
+
const base = lower.split('-')[0];
|
|
87
|
+
return (keys.find(key => key === wanted) ??
|
|
88
|
+
keys.find(key => key.toLowerCase() === lower) ??
|
|
89
|
+
keys.find(key => key.toLowerCase() === base) ??
|
|
90
|
+
keys.find(key => key.toLowerCase().split('-')[0] === base));
|
|
91
|
+
}
|
|
92
|
+
function blobWithoutHostFields(blob) {
|
|
93
|
+
const { translation: _translation, shop: _shop, ...rest } = blob;
|
|
94
|
+
return rest;
|
|
95
|
+
}
|
|
96
|
+
export function toShopifyLocale(language) {
|
|
97
|
+
const [lang, region] = language.split('_');
|
|
98
|
+
return region ? `${lang.toLowerCase()}-${region.toUpperCase()}` : lang.toLowerCase();
|
|
99
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { getJoyInitialData } from './get-joy-initial-data.js';
|
|
2
|
+
export type { GetJoyInitialDataOptions, JoyInitialDataPage, JoyInitialDataResult, JoyMetafieldBlob, JoyStorefrontClient } from './get-joy-initial-data.js';
|
|
3
|
+
export { JOY_PERSONALIZED_CACHE_CONTROL, isJoyInitialDataPersonalized } from '../cache-control.js';
|
|
4
|
+
export { getJoyLoyaltyPageData } from './get-joy-loyalty-page-data.js';
|
|
5
|
+
export { getWidgetCoreManifest } from '../lib/core-manifest.js';
|
|
6
|
+
export type { GetWidgetCoreManifestOptions } from '../lib/core-manifest.js';
|
|
7
|
+
export type { WidgetCoreManifest } from '../lib/core-loader.js';
|
|
8
|
+
export type { GetJoyLoyaltyPageDataOptions, JoyLoyaltyPageData, JoyLoyaltyPageFaq } from './get-joy-loyalty-page-data.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { getJoyInitialData } from './get-joy-initial-data.js';
|
|
2
|
+
export { JOY_PERSONALIZED_CACHE_CONTROL, isJoyInitialDataPersonalized } from '../cache-control.js';
|
|
3
|
+
export { getJoyLoyaltyPageData } from './get-joy-loyalty-page-data.js';
|
|
4
|
+
export { getWidgetCoreManifest } from '../lib/core-manifest.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@joy-loyalty/sdk/host';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Program, Tier } from '@joy-loyalty/sdk/client';
|
|
2
|
+
import type { HeadlessHostAdapter, JoyInitialData } from './headless-host-adapter.js';
|
|
3
|
+
import type { HydrogenCartPort } from './hydrogen-cart-port.js';
|
|
4
|
+
import type { WidgetCoreExports } from './lib/core-loader.js';
|
|
5
|
+
import type { HeadlessRenderIdentity, JoyMetafieldBlob } from './render-adapter.js';
|
|
6
|
+
export interface WidgetOrchestratorHandle {
|
|
7
|
+
dispose(): void;
|
|
8
|
+
ready: Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface WidgetAppearance {
|
|
11
|
+
variant?: 'popup' | 'drawer' | 'floating-drawer';
|
|
12
|
+
position?: 'left' | 'right';
|
|
13
|
+
theme?: 'light' | 'dark';
|
|
14
|
+
primaryColor?: string;
|
|
15
|
+
fabLabel?: string;
|
|
16
|
+
collapsed?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface HeadlessInitialData extends JoyInitialData {
|
|
19
|
+
blob?: JoyMetafieldBlob;
|
|
20
|
+
shopifyCustomer?: HeadlessRenderIdentity;
|
|
21
|
+
login_url?: string;
|
|
22
|
+
register_url?: string;
|
|
23
|
+
account_url?: string;
|
|
24
|
+
page?: {
|
|
25
|
+
type: string;
|
|
26
|
+
resourceId: string;
|
|
27
|
+
handle: string;
|
|
28
|
+
};
|
|
29
|
+
locale?: string;
|
|
30
|
+
country?: string;
|
|
31
|
+
token?: string;
|
|
32
|
+
}
|
|
33
|
+
export type BlobCustomer = JoyInitialData['customer'] | Record<string, unknown>;
|
|
34
|
+
export declare function buildAppearanceProps(appearance?: WidgetAppearance): {
|
|
35
|
+
variant: "popup" | "drawer" | "floating-drawer";
|
|
36
|
+
position: "left" | "right";
|
|
37
|
+
theme: "light" | "dark";
|
|
38
|
+
'primary-color': string | undefined;
|
|
39
|
+
'fab-label': string | undefined;
|
|
40
|
+
collapsed: boolean;
|
|
41
|
+
};
|
|
42
|
+
export declare function buildAppearanceOverrides(appearance?: WidgetAppearance): Record<string, unknown>;
|
|
43
|
+
export declare function buildProps(customer: JoyInitialData['customer'], programs: readonly Program[], tiers?: readonly Tier[]): {
|
|
44
|
+
'logged-in': boolean;
|
|
45
|
+
'customer-id': string;
|
|
46
|
+
points: number;
|
|
47
|
+
'current-tier': string;
|
|
48
|
+
'tier-id': string | null;
|
|
49
|
+
'next-tier': string;
|
|
50
|
+
'tier-progress': number | undefined;
|
|
51
|
+
'tier-required': number | undefined;
|
|
52
|
+
'progress-type': "points" | undefined;
|
|
53
|
+
earnPrograms: {
|
|
54
|
+
id: string;
|
|
55
|
+
icon: string;
|
|
56
|
+
title: string;
|
|
57
|
+
description: string;
|
|
58
|
+
points: number | undefined;
|
|
59
|
+
value: string;
|
|
60
|
+
}[];
|
|
61
|
+
redeemPrograms: {
|
|
62
|
+
id: string;
|
|
63
|
+
icon: string;
|
|
64
|
+
title: string;
|
|
65
|
+
description: string;
|
|
66
|
+
points: number;
|
|
67
|
+
value: string;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
70
|
+
export declare function writeProps(element: HTMLElement, props: Record<string, unknown>): void;
|
|
71
|
+
export declare function detail<T>(event: Event): T;
|
|
72
|
+
export declare function openGuideModal(guide: string): Promise<void>;
|
|
73
|
+
export declare function createWidgetOrchestrator(container: HTMLElement, hostAdapter: HeadlessHostAdapter, initialData?: HeadlessInitialData | null, appearance?: WidgetAppearance, cart?: HydrogenCartPort, coreExports?: WidgetCoreExports, hostHooks?: {
|
|
74
|
+
openCartDrawer?: () => boolean | void;
|
|
75
|
+
}): WidgetOrchestratorHandle;
|
|
76
|
+
export declare const JOY_POINTS_UPDATED_EVENT = "joy:points-updated";
|
|
77
|
+
export declare function readEarningProgramByEvent(blob: JoyMetafieldBlob | undefined, event: string): Record<string, unknown> | undefined;
|
|
78
|
+
export declare function openInNewTab(url: string): void;
|
|
79
|
+
export declare function readCachedReferralLink(): boolean;
|
|
80
|
+
export declare function writeCachedReferralLink(showInvite: boolean): void;
|
|
81
|
+
export interface StoreCreditAccount {
|
|
82
|
+
id?: string;
|
|
83
|
+
amount: number;
|
|
84
|
+
currencyCode: string;
|
|
85
|
+
}
|
|
86
|
+
export declare function pickActiveMarketStoreCredit(accounts: StoreCreditAccount[] | undefined, activeCurrency?: string): {
|
|
87
|
+
balance: number;
|
|
88
|
+
currency: string;
|
|
89
|
+
};
|