@joy-loyalty/hydrogen 0.0.0-stage → 0.2.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/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 +197 -0
- package/dist/host-adapter/capabilities.d.ts +3 -0
- package/dist/host-adapter/capabilities.js +12 -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 +37 -0
- package/dist/host-adapter/promoted-collections.d.ts +2 -0
- package/dist/host-adapter/promoted-collections.js +43 -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 +43 -0
- package/dist/lib/recommended-loader.js +111 -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 +258 -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 +326 -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 +38 -0
- package/dist/server/get-joy-initial-data.js +61 -0
- package/dist/server/get-joy-loyalty-page-data.d.ts +27 -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 +88 -0
- package/dist/widget-orchestrator.js +499 -0
- package/package.json +121 -4
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Activity, ActivityPage, Address, AddressDeleteResult, AddressInput, BirthdayClaimResult, BirthdayRewardsMap, BirthdayRewardsResult, BirthdaySaveResult, Customer, CustomerRewards, CustomerRewardsPage, EarnContext, EarnImageUpload, EarnResult, EarnUploadResult, FacebookDisconnectResult, FreeGiftStock, GenerateReferralLinkResult, GetImpactHistoryParams, GetStoreCreditTransactionsParams, ImpactHistory, InstagramLinkResult, JoinFrom, JoyInfo, LineAuthUrlResult, MilestoneClaimInput, MilestoneClaimResult, MilestoneProgress, Order, Pagination, PendingRewardClaimResult, PendingTierRewardClaim, ProfileResult, Program, QrCodeResult, ReceivedReward, ReceivedRewardsPage, RedeemResult, Referral, ReferralEmailResult, SegmentEligibility, SegmentProgramQuery, SendRewardInput, SendRewardResult, ShopConfig, SocialEarnResult, StoreCreditTransactionPage, Tier, TierPerkSaveInput, TierPerkSaveResult, UpdateProfileOptions } from '@joy-loyalty/sdk/client';
|
|
2
|
+
import type { AppleWalletPassCache, AuthPort, AuthState, ActivityQuery, CoreDataPort, CurrentProduct, EarnRequest, NavTarget, PromotedCollection, PromotedCollectionSelection, RecentlyViewedProduct, RedeemOptions as CoreRedeemOptions, RedeemRecipient, ReferralHistoryItem, ReferralHistoryPage, RewardQuery as CoreRewardQuery } from '@joy-loyalty/sdk/ports';
|
|
3
|
+
export type { ActivityQuery, AppleWalletPassCache, AuthPort, AuthState, CurrentProduct, EarnRequest, NavTarget, PromotedCollection, PromotedCollectionSelection, RecentlyViewedProduct, RedeemRecipient, ReferralHistoryItem, ReferralHistoryPage };
|
|
4
|
+
export interface RedeemOptions extends CoreRedeemOptions {
|
|
5
|
+
idempotencyKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface RewardQuery extends CoreRewardQuery {
|
|
8
|
+
couponStatus?: 'available' | 'unavailable';
|
|
9
|
+
}
|
|
10
|
+
export interface GetInfoOptions {
|
|
11
|
+
includeStoreCredit?: boolean;
|
|
12
|
+
earnSignup?: boolean;
|
|
13
|
+
allowGuest?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface DataCapabilities {
|
|
16
|
+
freeGiftStock: boolean;
|
|
17
|
+
receivedRewards: boolean;
|
|
18
|
+
referralInvite: boolean;
|
|
19
|
+
referralHistory: boolean;
|
|
20
|
+
joinProgram: boolean;
|
|
21
|
+
socialConnect: boolean;
|
|
22
|
+
profileEdit: boolean;
|
|
23
|
+
appleWalletPass: boolean;
|
|
24
|
+
googleWalletPass: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface HeadlessDataPort extends CoreDataPort {
|
|
27
|
+
redeem(programId: string, opts?: RedeemOptions): Promise<RedeemResult>;
|
|
28
|
+
getActivities(query?: ActivityQuery): Promise<ActivityPage>;
|
|
29
|
+
getRewards(params?: RewardQuery): Promise<CustomerRewards & {
|
|
30
|
+
pagination?: Pagination;
|
|
31
|
+
received?: ReceivedReward[];
|
|
32
|
+
}>;
|
|
33
|
+
getReceivedRewards(params?: {
|
|
34
|
+
before?: string;
|
|
35
|
+
after?: string;
|
|
36
|
+
limit?: number;
|
|
37
|
+
}): Promise<ReceivedRewardsPage>;
|
|
38
|
+
getAddresses(): Promise<Address[]>;
|
|
39
|
+
saveAddress(address: AddressInput): Promise<Address>;
|
|
40
|
+
deleteAddress(addressId: string | number): Promise<AddressDeleteResult>;
|
|
41
|
+
updateProfile(options: UpdateProfileOptions): Promise<ProfileResult>;
|
|
42
|
+
saveBirthday(birthday: string, dateOfBirth?: string): Promise<BirthdaySaveResult>;
|
|
43
|
+
sendReferralEmail(refereeEmail: string): Promise<ReferralEmailResult>;
|
|
44
|
+
generateReferralLink(email: string): Promise<GenerateReferralLinkResult>;
|
|
45
|
+
getTierRewards(): Promise<Tier[]>;
|
|
46
|
+
getPendingTierRewardClaims(): Promise<PendingTierRewardClaim[]>;
|
|
47
|
+
getMilestoneProgress(): Promise<MilestoneProgress>;
|
|
48
|
+
claimMilestone(input: MilestoneClaimInput): Promise<MilestoneClaimResult>;
|
|
49
|
+
saveTierPerkVariantSelection(input: TierPerkSaveInput): Promise<TierPerkSaveResult>;
|
|
50
|
+
claimPendingReward(pendingId: string, input?: {
|
|
51
|
+
variantIds?: string[];
|
|
52
|
+
}): Promise<PendingRewardClaimResult>;
|
|
53
|
+
getImpactHistory(params?: GetImpactHistoryParams): Promise<ImpactHistory>;
|
|
54
|
+
joinProgram(joinFrom?: JoinFrom): Promise<Customer>;
|
|
55
|
+
checkSegmentPrograms(segmentPrograms: SegmentProgramQuery[]): Promise<SegmentEligibility>;
|
|
56
|
+
linkInstagram(instagramUsername: string): Promise<InstagramLinkResult>;
|
|
57
|
+
disconnectFacebook(): Promise<FacebookDisconnectResult>;
|
|
58
|
+
getLineAuthUrl(): Promise<LineAuthUrlResult>;
|
|
59
|
+
getAppleWalletLink(): Promise<string>;
|
|
60
|
+
getGoogleWalletLink(): Promise<string>;
|
|
61
|
+
verifyApplePass(): Promise<boolean>;
|
|
62
|
+
getAppleWalletPassCache(): AppleWalletPassCache;
|
|
63
|
+
setAppleWalletPassCache(qrUrl: string): void;
|
|
64
|
+
getOrders(): Promise<Order[]>;
|
|
65
|
+
getOrderById(orderId: string): Promise<Order | null>;
|
|
66
|
+
getOrderActivities(orderId: string): Promise<Activity[]>;
|
|
67
|
+
getStoreCreditTransactions(params?: GetStoreCreditTransactionsParams): Promise<StoreCreditTransactionPage>;
|
|
68
|
+
sendRewardToFriend(input: SendRewardInput): Promise<SendRewardResult>;
|
|
69
|
+
setBirthdayRewards(birthdayRewards: BirthdayRewardsMap): Promise<BirthdayRewardsResult>;
|
|
70
|
+
claimBirthdayReward(birthdayRewards?: BirthdayRewardsMap): Promise<BirthdayClaimResult>;
|
|
71
|
+
generateQrCode(): Promise<QrCodeResult>;
|
|
72
|
+
getFreeGiftStock(programId: string): Promise<FreeGiftStock>;
|
|
73
|
+
getInfo(params?: GetInfoOptions): Promise<JoyInfo>;
|
|
74
|
+
getProductByHandle(handle: string): Promise<CurrentProduct | null>;
|
|
75
|
+
getPromotedCollections(selections: PromotedCollectionSelection[]): Promise<PromotedCollection[]>;
|
|
76
|
+
getRecentlyViewedProducts(): Promise<RecentlyViewedProduct[]>;
|
|
77
|
+
capabilities: DataCapabilities;
|
|
78
|
+
}
|
|
79
|
+
export interface JoyDataSource {
|
|
80
|
+
getShopConfig?: () => Promise<ShopConfig>;
|
|
81
|
+
getTiers?: () => Promise<Tier[]>;
|
|
82
|
+
getCustomer(): Promise<Customer>;
|
|
83
|
+
getPrograms(): Promise<Program[]>;
|
|
84
|
+
getActivities(query?: {
|
|
85
|
+
before?: string;
|
|
86
|
+
after?: string;
|
|
87
|
+
limit?: number;
|
|
88
|
+
}): Promise<ActivityPage>;
|
|
89
|
+
getRewards(params?: {
|
|
90
|
+
before?: string;
|
|
91
|
+
after?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
couponStatus?: 'available' | 'unavailable';
|
|
94
|
+
}): Promise<CustomerRewardsPage>;
|
|
95
|
+
getReceivedRewards(params?: {
|
|
96
|
+
before?: string;
|
|
97
|
+
after?: string;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}): Promise<ReceivedRewardsPage>;
|
|
100
|
+
getAddresses?: () => Promise<Address[]>;
|
|
101
|
+
saveAddress(address: AddressInput): Promise<Address>;
|
|
102
|
+
deleteAddress(addressId: string | number): Promise<AddressDeleteResult>;
|
|
103
|
+
updateProfile(options: UpdateProfileOptions): Promise<ProfileResult>;
|
|
104
|
+
saveBirthday(birthday: string, dateOfBirth?: string): Promise<BirthdaySaveResult>;
|
|
105
|
+
getReferral(): Promise<Referral>;
|
|
106
|
+
getTierRewards(): Promise<Tier[]>;
|
|
107
|
+
getPendingTierRewardClaims(): Promise<PendingTierRewardClaim[]>;
|
|
108
|
+
getMilestoneProgress(): Promise<MilestoneProgress>;
|
|
109
|
+
claimMilestone(input: MilestoneClaimInput): Promise<MilestoneClaimResult>;
|
|
110
|
+
saveTierPerkVariantSelection(input: TierPerkSaveInput): Promise<TierPerkSaveResult>;
|
|
111
|
+
claimPendingReward(pendingId: string, input?: {
|
|
112
|
+
variantIds?: string[];
|
|
113
|
+
}): Promise<PendingRewardClaimResult>;
|
|
114
|
+
getImpactHistory(params?: GetImpactHistoryParams): Promise<ImpactHistory>;
|
|
115
|
+
getReferralHistory(params?: {
|
|
116
|
+
before?: string;
|
|
117
|
+
after?: string;
|
|
118
|
+
}): Promise<ReferralHistoryPage>;
|
|
119
|
+
sendReferralEmail(refereeEmail: string): Promise<ReferralEmailResult>;
|
|
120
|
+
generateReferralLink(email: string): Promise<GenerateReferralLinkResult>;
|
|
121
|
+
getOrders(): Promise<Order[]>;
|
|
122
|
+
getOrderById(orderId: string): Promise<Order | null>;
|
|
123
|
+
getOrderActivities(orderId: string): Promise<Activity[]>;
|
|
124
|
+
getStoreCreditTransactions(params?: GetStoreCreditTransactionsParams): Promise<StoreCreditTransactionPage>;
|
|
125
|
+
sendRewardToFriend(input: SendRewardInput): Promise<SendRewardResult>;
|
|
126
|
+
setBirthdayRewards(birthdayRewards: BirthdayRewardsMap): Promise<BirthdayRewardsResult>;
|
|
127
|
+
claimBirthdayReward(birthdayRewards?: BirthdayRewardsMap): Promise<BirthdayClaimResult>;
|
|
128
|
+
generateQrCode(): Promise<QrCodeResult>;
|
|
129
|
+
joinProgram(joinFrom?: JoinFrom): Promise<Customer>;
|
|
130
|
+
checkSegmentPrograms(segmentPrograms: SegmentProgramQuery[]): Promise<SegmentEligibility>;
|
|
131
|
+
linkInstagram(instagramUsername: string): Promise<InstagramLinkResult>;
|
|
132
|
+
disconnectFacebook(): Promise<FacebookDisconnectResult>;
|
|
133
|
+
getLineAuthUrl(): Promise<LineAuthUrlResult>;
|
|
134
|
+
getAppleWalletLink(): Promise<string>;
|
|
135
|
+
getGoogleWalletLink(): Promise<string>;
|
|
136
|
+
verifyApplePass(): Promise<boolean>;
|
|
137
|
+
getFreeGiftStock(programId: string, country?: string): Promise<FreeGiftStock>;
|
|
138
|
+
getInfo?: (params?: GetInfoOptions) => Promise<JoyInfo>;
|
|
139
|
+
redeem(programId: string, opts?: RedeemOptions): Promise<RedeemResult>;
|
|
140
|
+
earn(programId: string, context?: EarnContext): Promise<EarnResult>;
|
|
141
|
+
earnUpload(input: {
|
|
142
|
+
images: EarnImageUpload[];
|
|
143
|
+
}): Promise<EarnUploadResult>;
|
|
144
|
+
earnSocial(programId: string): Promise<SocialEarnResult>;
|
|
145
|
+
}
|
|
146
|
+
export interface HeadlessHostContext {
|
|
147
|
+
shopDomain: string;
|
|
148
|
+
apiUrl: string;
|
|
149
|
+
currency: string;
|
|
150
|
+
activeMarketCurrency?: string;
|
|
151
|
+
moneyFormat?: string;
|
|
152
|
+
locale?: string;
|
|
153
|
+
contentLocale?: string;
|
|
154
|
+
customerTierId?: string;
|
|
155
|
+
translation: Record<string, string>;
|
|
156
|
+
page: {
|
|
157
|
+
type: string;
|
|
158
|
+
resourceId: string;
|
|
159
|
+
handle: string;
|
|
160
|
+
};
|
|
161
|
+
routesRoot: string;
|
|
162
|
+
loginUrl: string;
|
|
163
|
+
registerUrl: string;
|
|
164
|
+
loyaltyPageUrl: string;
|
|
165
|
+
accountUrl: string;
|
|
166
|
+
country: string;
|
|
167
|
+
preview?: boolean;
|
|
168
|
+
demoMode?: boolean;
|
|
169
|
+
viewport: {
|
|
170
|
+
width: number;
|
|
171
|
+
};
|
|
172
|
+
currencyRate?: number;
|
|
173
|
+
debug?: boolean;
|
|
174
|
+
customerProfile?: {
|
|
175
|
+
first_name?: string;
|
|
176
|
+
last_name?: string;
|
|
177
|
+
orders_count?: number;
|
|
178
|
+
orders?: unknown[];
|
|
179
|
+
phone?: string;
|
|
180
|
+
avatarUrl?: string;
|
|
181
|
+
addresses?: unknown[];
|
|
182
|
+
};
|
|
183
|
+
shopId?: string;
|
|
184
|
+
shopifyCustomerId?: string;
|
|
185
|
+
ordersCustomerId?: string;
|
|
186
|
+
currentProduct?: CurrentProduct;
|
|
187
|
+
}
|
|
188
|
+
export type HeadlessHostContextInput = Omit<HeadlessHostContext, 'translation'> & {
|
|
189
|
+
translation?: Record<string, string>;
|
|
190
|
+
};
|
|
191
|
+
export interface JoyInitialData {
|
|
192
|
+
shopConfig?: ShopConfig;
|
|
193
|
+
programs?: Program[];
|
|
194
|
+
tiers?: Tier[];
|
|
195
|
+
customer?: Customer;
|
|
196
|
+
}
|
|
197
|
+
export interface HeadlessHostAdapterOptions {
|
|
198
|
+
context: HeadlessHostContextInput;
|
|
199
|
+
initialData?: JoyInitialData | null;
|
|
200
|
+
source?: JoyDataSource;
|
|
201
|
+
getToken?: () => Promise<string | null>;
|
|
202
|
+
productsRoute?: string;
|
|
203
|
+
}
|
|
204
|
+
export interface HeadlessHostAdapter {
|
|
205
|
+
context(): HeadlessHostContext;
|
|
206
|
+
readonly initialData: JoyInitialData | null;
|
|
207
|
+
getToken(): Promise<string | null>;
|
|
208
|
+
data: HeadlessDataPort;
|
|
209
|
+
auth: AuthPort;
|
|
210
|
+
navigate(target: NavTarget): void;
|
|
211
|
+
notifyAuth(state: AuthState): void;
|
|
212
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
type CartLine = {
|
|
2
|
+
id?: string | null;
|
|
3
|
+
merchandise?: {
|
|
4
|
+
id?: string | null;
|
|
5
|
+
availableForSale?: boolean | null;
|
|
6
|
+
} | null;
|
|
7
|
+
quantity?: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type StorefrontCart = {
|
|
10
|
+
updatedAt?: string | null;
|
|
11
|
+
lines?: {
|
|
12
|
+
nodes?: CartLine[] | null;
|
|
13
|
+
} | null;
|
|
14
|
+
discountCodes?: Array<{
|
|
15
|
+
code?: string | null;
|
|
16
|
+
applicable?: boolean | null;
|
|
17
|
+
}> | null;
|
|
18
|
+
cost?: {
|
|
19
|
+
totalAmount?: {
|
|
20
|
+
amount?: string | null;
|
|
21
|
+
currencyCode?: string | null;
|
|
22
|
+
} | null;
|
|
23
|
+
subtotalAmount?: {
|
|
24
|
+
amount?: string | null;
|
|
25
|
+
currencyCode?: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
} | null;
|
|
28
|
+
};
|
|
29
|
+
export interface HydrogenCartFetcher {
|
|
30
|
+
state: string;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
submit(data: Record<string, string>, options: {
|
|
33
|
+
method: 'POST';
|
|
34
|
+
action: string;
|
|
35
|
+
}): void;
|
|
36
|
+
}
|
|
37
|
+
export interface HydrogenCartPortOptions {
|
|
38
|
+
fetcher: HydrogenCartFetcher;
|
|
39
|
+
getCart: () => StorefrontCart | null | undefined;
|
|
40
|
+
revalidate: () => void;
|
|
41
|
+
cartRoute?: string;
|
|
42
|
+
onCartUpdated?: (cart: StorefrontCart) => void;
|
|
43
|
+
}
|
|
44
|
+
export declare function normalizeHydrogenCart(cart: StorefrontCart | null | undefined): {
|
|
45
|
+
lines: {
|
|
46
|
+
variantId: string;
|
|
47
|
+
quantity: number;
|
|
48
|
+
}[];
|
|
49
|
+
cost: {
|
|
50
|
+
totalAmount: {
|
|
51
|
+
amount: string;
|
|
52
|
+
currencyCode: string;
|
|
53
|
+
};
|
|
54
|
+
subtotalAmount: {
|
|
55
|
+
amount: string;
|
|
56
|
+
currencyCode: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
discountCodes: {
|
|
60
|
+
code: string;
|
|
61
|
+
applicable: boolean;
|
|
62
|
+
}[];
|
|
63
|
+
} | null;
|
|
64
|
+
export declare class HydrogenCartPort {
|
|
65
|
+
readonly capabilities: {
|
|
66
|
+
discountCodes: boolean;
|
|
67
|
+
freeGift: boolean;
|
|
68
|
+
mergeCodes: boolean;
|
|
69
|
+
revalidate: boolean;
|
|
70
|
+
};
|
|
71
|
+
private readonly fetcher;
|
|
72
|
+
private readonly getStorefrontCart;
|
|
73
|
+
private readonly revalidateCart;
|
|
74
|
+
private readonly cartRoute;
|
|
75
|
+
private readonly onCartUpdated?;
|
|
76
|
+
private pending;
|
|
77
|
+
private pendingAdds;
|
|
78
|
+
private queue;
|
|
79
|
+
private lastCart;
|
|
80
|
+
constructor({ fetcher, getCart, revalidate, cartRoute, onCartUpdated }: HydrogenCartPortOptions);
|
|
81
|
+
getCart(): {
|
|
82
|
+
lines: {
|
|
83
|
+
variantId: string;
|
|
84
|
+
quantity: number;
|
|
85
|
+
}[];
|
|
86
|
+
cost: {
|
|
87
|
+
totalAmount: {
|
|
88
|
+
amount: string;
|
|
89
|
+
currencyCode: string;
|
|
90
|
+
};
|
|
91
|
+
subtotalAmount: {
|
|
92
|
+
amount: string;
|
|
93
|
+
currencyCode: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
discountCodes: {
|
|
97
|
+
code: string;
|
|
98
|
+
applicable: boolean;
|
|
99
|
+
}[];
|
|
100
|
+
} | null;
|
|
101
|
+
private currentStorefrontCart;
|
|
102
|
+
settle(): void;
|
|
103
|
+
applyDiscount(code: string, { alwaysOverrideDiscount }?: {
|
|
104
|
+
alwaysOverrideDiscount?: boolean;
|
|
105
|
+
}): Promise<{
|
|
106
|
+
droppedCodes?: string[] | undefined;
|
|
107
|
+
ok: boolean;
|
|
108
|
+
applied: boolean;
|
|
109
|
+
reason?: undefined;
|
|
110
|
+
} | {
|
|
111
|
+
ok: boolean;
|
|
112
|
+
applied: boolean;
|
|
113
|
+
reason: string;
|
|
114
|
+
}>;
|
|
115
|
+
removeDiscount(code: string): Promise<void>;
|
|
116
|
+
addLines(lines: Array<{
|
|
117
|
+
id: string;
|
|
118
|
+
quantity?: number;
|
|
119
|
+
}>): Promise<void>;
|
|
120
|
+
addGiftLines(lines: Array<{
|
|
121
|
+
id: string;
|
|
122
|
+
quantity?: number;
|
|
123
|
+
}>): Promise<number>;
|
|
124
|
+
redeemGift({ code, variantId }: {
|
|
125
|
+
code: string;
|
|
126
|
+
variantId: string;
|
|
127
|
+
}): Promise<void>;
|
|
128
|
+
revalidate(): void;
|
|
129
|
+
private serialize;
|
|
130
|
+
private submit;
|
|
131
|
+
private publishCart;
|
|
132
|
+
}
|
|
133
|
+
export declare function settleHydrogenCartPort(port: HydrogenCartPort): void;
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { CartForm } from '@shopify/hydrogen';
|
|
2
|
+
const SETTLE_TIMEOUT_MS = 15_000;
|
|
3
|
+
function isVariantGid(id) {
|
|
4
|
+
return /^gid:\/\/shopify\/ProductVariant\/[^/]+$/.test(id);
|
|
5
|
+
}
|
|
6
|
+
function cartFromResult(result) {
|
|
7
|
+
return result.cart || null;
|
|
8
|
+
}
|
|
9
|
+
function mutationError(result) {
|
|
10
|
+
const warnings = (result.warnings || []).filter(warning => String(warning.code || '').startsWith('MERCHANDISE_'));
|
|
11
|
+
return ([...(result.errors || []), ...(result.userErrors || []), ...warnings].find(error => error.message)?.message || null);
|
|
12
|
+
}
|
|
13
|
+
function updatedAtMs(cart) {
|
|
14
|
+
const ms = Date.parse(cart?.updatedAt || '');
|
|
15
|
+
return Number.isFinite(ms) ? ms : null;
|
|
16
|
+
}
|
|
17
|
+
export function normalizeHydrogenCart(cart) {
|
|
18
|
+
if (!cart?.cost?.totalAmount || !cart.cost.subtotalAmount)
|
|
19
|
+
return null;
|
|
20
|
+
return {
|
|
21
|
+
lines: (cart.lines?.nodes || []).flatMap(line => {
|
|
22
|
+
const variantId = line.merchandise?.id;
|
|
23
|
+
return variantId ? [{ variantId, quantity: line.quantity || 0 }] : [];
|
|
24
|
+
}),
|
|
25
|
+
cost: {
|
|
26
|
+
totalAmount: {
|
|
27
|
+
amount: cart.cost.totalAmount.amount || '0',
|
|
28
|
+
currencyCode: cart.cost.totalAmount.currencyCode || ''
|
|
29
|
+
},
|
|
30
|
+
subtotalAmount: {
|
|
31
|
+
amount: cart.cost.subtotalAmount.amount || '0',
|
|
32
|
+
currencyCode: cart.cost.subtotalAmount.currencyCode || ''
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
discountCodes: (cart.discountCodes || []).flatMap(discount => discount.code ? [{ code: discount.code, applicable: !!discount.applicable }] : [])
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export class HydrogenCartPort {
|
|
39
|
+
capabilities = {
|
|
40
|
+
discountCodes: true,
|
|
41
|
+
freeGift: true,
|
|
42
|
+
mergeCodes: true,
|
|
43
|
+
revalidate: true
|
|
44
|
+
};
|
|
45
|
+
fetcher;
|
|
46
|
+
getStorefrontCart;
|
|
47
|
+
revalidateCart;
|
|
48
|
+
cartRoute;
|
|
49
|
+
onCartUpdated;
|
|
50
|
+
pending = null;
|
|
51
|
+
pendingAdds = new Map();
|
|
52
|
+
queue = null;
|
|
53
|
+
lastCart = null;
|
|
54
|
+
constructor({ fetcher, getCart, revalidate, cartRoute = '/cart', onCartUpdated }) {
|
|
55
|
+
this.fetcher = fetcher;
|
|
56
|
+
this.getStorefrontCart = getCart;
|
|
57
|
+
this.revalidateCart = revalidate;
|
|
58
|
+
this.cartRoute = cartRoute;
|
|
59
|
+
this.onCartUpdated = onCartUpdated;
|
|
60
|
+
}
|
|
61
|
+
getCart() {
|
|
62
|
+
return normalizeHydrogenCart(this.currentStorefrontCart());
|
|
63
|
+
}
|
|
64
|
+
currentStorefrontCart() {
|
|
65
|
+
const hostCart = this.getStorefrontCart();
|
|
66
|
+
if (!this.lastCart)
|
|
67
|
+
return hostCart;
|
|
68
|
+
if (!hostCart)
|
|
69
|
+
return this.lastCart;
|
|
70
|
+
const hostMs = updatedAtMs(hostCart);
|
|
71
|
+
const lastMs = updatedAtMs(this.lastCart);
|
|
72
|
+
return hostMs != null && lastMs != null && lastMs > hostMs ? this.lastCart : hostCart;
|
|
73
|
+
}
|
|
74
|
+
settle() {
|
|
75
|
+
const pending = this.pending;
|
|
76
|
+
if (!pending)
|
|
77
|
+
return;
|
|
78
|
+
if (this.fetcher.state !== 'idle') {
|
|
79
|
+
pending.sawBusy = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!pending.sawBusy && this.fetcher.data === pending.dataAtSubmit)
|
|
83
|
+
return;
|
|
84
|
+
this.pending = null;
|
|
85
|
+
const result = (this.fetcher.data || {});
|
|
86
|
+
const error = mutationError(result);
|
|
87
|
+
if (error)
|
|
88
|
+
return pending.reject(new Error(error));
|
|
89
|
+
pending.resolve(result);
|
|
90
|
+
}
|
|
91
|
+
applyDiscount(code, { alwaysOverrideDiscount = false } = {}) {
|
|
92
|
+
return this.serialize(async () => {
|
|
93
|
+
const cart = this.getCart();
|
|
94
|
+
const existingCodes = cart ? cart.discountCodes.map(discount => discount.code) : [];
|
|
95
|
+
const replace = alwaysOverrideDiscount || !cart?.discountCodes.some(discount => discount.applicable);
|
|
96
|
+
const discountCodes = replace ? [code] : [...new Set([...existingCodes, code])];
|
|
97
|
+
if (cart &&
|
|
98
|
+
discountCodes.length === existingCodes.length &&
|
|
99
|
+
discountCodes.every(existingCode => existingCodes.includes(existingCode))) {
|
|
100
|
+
return { ok: true, applied: true };
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const result = await this.submit(CartForm.ACTIONS.DiscountCodesUpdate, { discountCodes });
|
|
104
|
+
const updated = normalizeHydrogenCart(cartFromResult(result));
|
|
105
|
+
const droppedCodes = updated
|
|
106
|
+
? existingCodes.filter(existingCode => !updated.discountCodes.some(discount => discount.code === existingCode))
|
|
107
|
+
: [];
|
|
108
|
+
const applied = updated?.discountCodes.find(discount => discount.code === code)?.applicable === true;
|
|
109
|
+
return { ok: true, applied, ...(droppedCodes.length ? { droppedCodes } : {}) };
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return { ok: false, applied: false, reason: error.message };
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
removeDiscount(code) {
|
|
117
|
+
return this.serialize(async () => {
|
|
118
|
+
const cart = this.getCart();
|
|
119
|
+
if (!cart)
|
|
120
|
+
return;
|
|
121
|
+
await this.submit(CartForm.ACTIONS.DiscountCodesUpdate, {
|
|
122
|
+
discountCodes: cart.discountCodes.map(discount => discount.code).filter(existingCode => existingCode !== code)
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
addLines(lines) {
|
|
127
|
+
for (const line of lines) {
|
|
128
|
+
if (!isVariantGid(line.id))
|
|
129
|
+
return Promise.reject(new Error('variantId must be a Shopify ProductVariant GID'));
|
|
130
|
+
}
|
|
131
|
+
const key = lines
|
|
132
|
+
.map(line => `${line.id}:${line.quantity || 1}`)
|
|
133
|
+
.sort()
|
|
134
|
+
.join('|');
|
|
135
|
+
const existing = this.pendingAdds.get(key);
|
|
136
|
+
if (existing)
|
|
137
|
+
return existing;
|
|
138
|
+
const mutation = this.serialize(async () => {
|
|
139
|
+
await this.submit(CartForm.ACTIONS.LinesAdd, {
|
|
140
|
+
lines: lines.map(line => ({ merchandiseId: line.id, quantity: line.quantity || 1 }))
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
this.pendingAdds.set(key, mutation);
|
|
144
|
+
mutation.then(() => this.pendingAdds.delete(key), () => this.pendingAdds.delete(key));
|
|
145
|
+
return mutation;
|
|
146
|
+
}
|
|
147
|
+
addGiftLines(lines) {
|
|
148
|
+
for (const line of lines) {
|
|
149
|
+
if (!isVariantGid(line.id))
|
|
150
|
+
return Promise.reject(new Error('variantId must be a Shopify ProductVariant GID'));
|
|
151
|
+
}
|
|
152
|
+
return this.serialize(async () => {
|
|
153
|
+
const requested = new Set(lines.map(line => line.id));
|
|
154
|
+
const beforeLines = (this.currentStorefrontCart()?.lines?.nodes || []).filter(line => requested.has(line.merchandise?.id || ''));
|
|
155
|
+
const beforeQtyByLineId = new Map(beforeLines.filter((line) => !!line.id).map(line => [line.id, line.quantity || 0]));
|
|
156
|
+
const result = await this.submit(CartForm.ACTIONS.LinesAdd, {
|
|
157
|
+
lines: lines.map(line => ({ merchandiseId: line.id, quantity: line.quantity || 1 }))
|
|
158
|
+
});
|
|
159
|
+
const cart = cartFromResult(result);
|
|
160
|
+
if (!cart)
|
|
161
|
+
return lines.length;
|
|
162
|
+
const afterLines = (cart.lines?.nodes || []).filter(line => requested.has(line.merchandise?.id || ''));
|
|
163
|
+
const landedVariants = new Set();
|
|
164
|
+
const lineIdsToRemove = [];
|
|
165
|
+
for (const line of afterLines) {
|
|
166
|
+
const variantId = line.merchandise?.id;
|
|
167
|
+
if (!variantId)
|
|
168
|
+
continue;
|
|
169
|
+
const isNewLine = !line.id || !beforeQtyByLineId.has(line.id);
|
|
170
|
+
const addedQty = (line.quantity || 0) - (isNewLine ? 0 : beforeQtyByLineId.get(line.id) || 0);
|
|
171
|
+
const sellable = !!line.quantity && line.merchandise?.availableForSale !== false;
|
|
172
|
+
if (addedQty > 0 && sellable) {
|
|
173
|
+
landedVariants.add(variantId);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (isNewLine && !sellable && line.id)
|
|
177
|
+
lineIdsToRemove.push(line.id);
|
|
178
|
+
}
|
|
179
|
+
if (lineIdsToRemove.length)
|
|
180
|
+
await this.submit(CartForm.ACTIONS.LinesRemove, { lineIds: lineIdsToRemove });
|
|
181
|
+
return landedVariants.size;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async redeemGift({ code, variantId }) {
|
|
185
|
+
await this.addLines([{ id: variantId, quantity: 1 }]);
|
|
186
|
+
const result = await this.applyDiscount(code);
|
|
187
|
+
if (!result.ok)
|
|
188
|
+
throw new Error(result.reason || 'Could not apply gift discount');
|
|
189
|
+
}
|
|
190
|
+
revalidate() {
|
|
191
|
+
this.revalidateCart();
|
|
192
|
+
}
|
|
193
|
+
serialize(task) {
|
|
194
|
+
const run = this.queue ? this.queue.then(task) : task();
|
|
195
|
+
const tail = run.then(() => { }, () => { });
|
|
196
|
+
this.queue = tail;
|
|
197
|
+
tail.then(() => {
|
|
198
|
+
if (this.queue === tail)
|
|
199
|
+
this.queue = null;
|
|
200
|
+
});
|
|
201
|
+
return run;
|
|
202
|
+
}
|
|
203
|
+
submit(action, inputs) {
|
|
204
|
+
return new Promise((resolve, reject) => {
|
|
205
|
+
const timer = setTimeout(() => {
|
|
206
|
+
if (this.pending?.resolve !== settleResolve)
|
|
207
|
+
return;
|
|
208
|
+
this.pending = null;
|
|
209
|
+
reject(new Error('The cart did not respond in time'));
|
|
210
|
+
}, SETTLE_TIMEOUT_MS);
|
|
211
|
+
const settleResolve = (value) => {
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
resolve(value);
|
|
214
|
+
};
|
|
215
|
+
const settleReject = (reason) => {
|
|
216
|
+
clearTimeout(timer);
|
|
217
|
+
reject(reason);
|
|
218
|
+
};
|
|
219
|
+
this.pending = { resolve: settleResolve, reject: settleReject, dataAtSubmit: this.fetcher.data, sawBusy: false };
|
|
220
|
+
try {
|
|
221
|
+
this.fetcher.submit({ [CartForm.INPUT_NAME]: JSON.stringify({ action, inputs }) }, { method: 'POST', action: this.cartRoute });
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
this.pending = null;
|
|
225
|
+
settleReject(error);
|
|
226
|
+
}
|
|
227
|
+
}).then(result => {
|
|
228
|
+
this.publishCart(cartFromResult(result));
|
|
229
|
+
this.revalidate();
|
|
230
|
+
return result;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
publishCart(cart) {
|
|
234
|
+
if (!cart)
|
|
235
|
+
return;
|
|
236
|
+
this.lastCart = cart;
|
|
237
|
+
this.onCartUpdated?.(cart);
|
|
238
|
+
if (typeof window !== 'undefined') {
|
|
239
|
+
window.dispatchEvent(new CustomEvent('joy:cart-updated', { detail: { cart } }));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export function settleHydrogenCartPort(port) {
|
|
244
|
+
port.settle();
|
|
245
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { JoyWidget } from './joy-widget.js';
|
|
2
|
+
export type { JoyWidgetProps } from './joy-widget.js';
|
|
3
|
+
export { JoyLoyaltyPage, isLoyaltyPageV2Enabled } from './loyalty-page/JoyLoyaltyPage.js';
|
|
4
|
+
export type { JoyLoyaltyPageInitialData, JoyLoyaltyPageProps } from './loyalty-page/JoyLoyaltyPage.js';
|
|
5
|
+
export { createHeadlessHostAdapter, createJoyDataSource } from './headless-host-adapter.js';
|
|
6
|
+
export type { ActivityQuery, DataCapabilities, EarnRequest, HeadlessHostAdapter, HeadlessHostAdapterOptions, HeadlessHostContext, HeadlessDataPort, JoyDataSource, JoyInitialData, RedeemOptions, RedeemRecipient, ReferralHistoryItem, ReferralHistoryPage, RewardQuery } from './headless-host-adapter.js';
|
|
7
|
+
export { JOY_API_ORIGIN, JOY_CDN_ORIGIN, JOY_CSP_DIRECTIVES, joyCspDirectives } from './csp.js';
|
|
8
|
+
export type { JoyCspDirectives } from './csp.js';
|
|
9
|
+
export { JOY_PERSONALIZED_CACHE_CONTROL, isJoyInitialDataPersonalized } from './cache-control.js';
|
|
10
|
+
export { loadWidgetCore, preconnectWidgetCore, preloadWidgetCore, resolveWidgetCoreAssetUrls } from './lib/core-loader.js';
|
|
11
|
+
export type { LoadWidgetCoreOptions, WidgetCoreManifest } from './lib/core-loader.js';
|
|
12
|
+
export { WidgetCorePreloadLinks } from './lib/core-preload-links.js';
|
|
13
|
+
export type { WidgetCorePreloadLinksProps } from './lib/core-preload-links.js';
|
|
14
|
+
export { ensureClient, JoyProvider, useJoyConfig, useJoyCustomer, useJoyProviderCart, useJoyProviderCartHandlers } from './lib/JoyProvider.js';
|
|
15
|
+
export type { JoyConfig, JoyCustomerState, JoyProviderCartHandlers } from './lib/JoyProvider.js';
|
|
16
|
+
export { createHeadlessSource } from './lib/headless-source.js';
|
|
17
|
+
export type { CreateHeadlessSourceOptions } from './lib/headless-source.js';
|
|
18
|
+
export { clearJoyToken, DEFAULT_TOKEN_ROUTE, getJoyToken } from './lib/token.js';
|
|
19
|
+
export type { GetJoyTokenOptions } from './lib/token.js';
|
|
20
|
+
export { DEFAULT_POINTS_LABEL, formatPointsNumber, POINTS_LABEL_HELP, resolvePointsLabel } from './lib/points.js';
|
|
21
|
+
export { formatMoney } from './lib/money.js';
|
|
22
|
+
export type { JoyMoney } from './lib/money.js';
|
|
23
|
+
export { ICON_IMAGE_SIZE, sizeShopifyImage } from './lib/image.js';
|
|
24
|
+
export { DEFAULT_PLACE_ORDER_SCOPE_ROUTE, getPlaceOrderScope } from './lib/place-order-scope.js';
|
|
25
|
+
export type { GetPlaceOrderScopeOptions } from './lib/place-order-scope.js';
|
|
26
|
+
export { isLineFollowOaProgram, isRepeatableSocialProgram, isSocialEarnProgram, SOCIAL_EARN_EVENT_KEYS } from './lib/social-earn.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { JoyWidget } from './joy-widget.js';
|
|
2
|
+
export { JoyLoyaltyPage, isLoyaltyPageV2Enabled } from './loyalty-page/JoyLoyaltyPage.js';
|
|
3
|
+
export { createHeadlessHostAdapter, createJoyDataSource } from './headless-host-adapter.js';
|
|
4
|
+
export { JOY_API_ORIGIN, JOY_CDN_ORIGIN, JOY_CSP_DIRECTIVES, joyCspDirectives } from './csp.js';
|
|
5
|
+
export { JOY_PERSONALIZED_CACHE_CONTROL, isJoyInitialDataPersonalized } from './cache-control.js';
|
|
6
|
+
export { loadWidgetCore, preconnectWidgetCore, preloadWidgetCore, resolveWidgetCoreAssetUrls } from './lib/core-loader.js';
|
|
7
|
+
export { WidgetCorePreloadLinks } from './lib/core-preload-links.js';
|
|
8
|
+
export { ensureClient, JoyProvider, useJoyConfig, useJoyCustomer, useJoyProviderCart, useJoyProviderCartHandlers } from './lib/JoyProvider.js';
|
|
9
|
+
export { createHeadlessSource } from './lib/headless-source.js';
|
|
10
|
+
export { clearJoyToken, DEFAULT_TOKEN_ROUTE, getJoyToken } from './lib/token.js';
|
|
11
|
+
export { DEFAULT_POINTS_LABEL, formatPointsNumber, POINTS_LABEL_HELP, resolvePointsLabel } from './lib/points.js';
|
|
12
|
+
export { formatMoney } from './lib/money.js';
|
|
13
|
+
export { ICON_IMAGE_SIZE, sizeShopifyImage } from './lib/image.js';
|
|
14
|
+
export { DEFAULT_PLACE_ORDER_SCOPE_ROUTE, getPlaceOrderScope } from './lib/place-order-scope.js';
|
|
15
|
+
export { isLineFollowOaProgram, isRepeatableSocialProgram, isSocialEarnProgram, SOCIAL_EARN_EVENT_KEYS } from './lib/social-earn.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HeadlessInitialData } from './widget-orchestrator.js';
|
|
2
|
+
import type { HydrogenCartFetcher, StorefrontCart } from './hydrogen-cart-port.js';
|
|
3
|
+
export interface JoyWidgetProps {
|
|
4
|
+
apiUrl?: string | null;
|
|
5
|
+
tokenRoute?: string;
|
|
6
|
+
loginUrl?: string;
|
|
7
|
+
loyaltyPageUrl?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
pathname?: string;
|
|
10
|
+
shopDomain?: string;
|
|
11
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
12
|
+
accentColor?: string;
|
|
13
|
+
launcherLabel?: string;
|
|
14
|
+
panelHeading?: string;
|
|
15
|
+
pointsLabel?: string;
|
|
16
|
+
viewRewardsLabel?: string;
|
|
17
|
+
loginLabel?: string;
|
|
18
|
+
initialData?: HeadlessInitialData | null;
|
|
19
|
+
assetUrl?: string;
|
|
20
|
+
preload?: 'idle' | 'interaction' | 'eager';
|
|
21
|
+
cart?: StorefrontCart | (() => StorefrontCart | null | undefined);
|
|
22
|
+
cartFetcher?: HydrogenCartFetcher;
|
|
23
|
+
cartRevalidate?: () => void;
|
|
24
|
+
cartRoute?: string;
|
|
25
|
+
onOpenCartDrawer?: () => void;
|
|
26
|
+
currency?: string;
|
|
27
|
+
country?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function JoyWidget({ apiUrl, tokenRoute, loginUrl, loyaltyPageUrl, locale, pathname: pathnameProp, shopDomain: shopDomainProp, position, accentColor, launcherLabel, panelHeading, pointsLabel, viewRewardsLabel, loginLabel, initialData, assetUrl, preload, cart, cartFetcher, cartRevalidate, cartRoute, onOpenCartDrawer, currency, country }: JoyWidgetProps): import("react").JSX.Element;
|