@personizely/shopify-hydrogen 1.0.0 → 1.0.2
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/index.cjs +399 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +342 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +342 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +342 -10
- package/dist/index.mjs +277 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -4
- package/dist/classes/Adapter.d.ts +0 -33
- package/dist/classes/Adapter.d.ts.map +0 -1
- package/dist/classes/Adapter.js +0 -126
- package/dist/classes/Adapter.js.map +0 -1
- package/dist/classes/Cart.d.ts +0 -29
- package/dist/classes/Cart.d.ts.map +0 -1
- package/dist/classes/Cart.js +0 -272
- package/dist/classes/Cart.js.map +0 -1
- package/dist/components/PersonizelyProvider.d.ts +0 -36
- package/dist/components/PersonizelyProvider.d.ts.map +0 -1
- package/dist/components/PersonizelyProvider.js +0 -118
- package/dist/components/PersonizelyProvider.js.map +0 -1
- package/dist/graphql/queries/cart.d.ts +0 -7
- package/dist/graphql/queries/cart.d.ts.map +0 -1
- package/dist/graphql/queries/cart.js +0 -142
- package/dist/graphql/queries/cart.js.map +0 -1
- package/dist/graphql/queries/customer.d.ts +0 -5
- package/dist/graphql/queries/customer.d.ts.map +0 -1
- package/dist/graphql/queries/customer.js +0 -72
- package/dist/graphql/queries/customer.js.map +0 -1
- package/dist/graphql/queries/product.d.ts +0 -5
- package/dist/graphql/queries/product.d.ts.map +0 -1
- package/dist/graphql/queries/product.js +0 -114
- package/dist/graphql/queries/product.js.map +0 -1
- package/dist/hooks/useCartAdd.d.ts +0 -3
- package/dist/hooks/useCartAdd.d.ts.map +0 -1
- package/dist/hooks/useCartAdd.js +0 -18
- package/dist/hooks/useCartAdd.js.map +0 -1
- package/dist/hooks/useCheckout.d.ts +0 -2
- package/dist/hooks/useCheckout.d.ts.map +0 -1
- package/dist/hooks/useCheckout.js +0 -12
- package/dist/hooks/useCheckout.js.map +0 -1
- package/dist/hooks/usePageContext.d.ts +0 -3
- package/dist/hooks/usePageContext.d.ts.map +0 -1
- package/dist/hooks/usePageContext.js +0 -6
- package/dist/hooks/usePageContext.js.map +0 -1
- package/dist/hooks/usePersonizely.d.ts +0 -3
- package/dist/hooks/usePersonizely.d.ts.map +0 -1
- package/dist/hooks/usePersonizely.js +0 -11
- package/dist/hooks/usePersonizely.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -170
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/interfaces.d.ts +0 -35
- package/dist/types/interfaces.d.ts.map +0 -1
- package/dist/types/interfaces.js +0 -2
- package/dist/types/interfaces.js.map +0 -1
- package/dist/utils/cookies.d.ts +0 -4
- package/dist/utils/cookies.d.ts.map +0 -1
- package/dist/utils/cookies.js +0 -33
- package/dist/utils/cookies.js.map +0 -1
- package/dist/utils/id.d.ts +0 -3
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -7
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/storefront-client.d.ts +0 -15
- package/dist/utils/storefront-client.d.ts.map +0 -1
- package/dist/utils/storefront-client.js +0 -39
- package/dist/utils/storefront-client.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/interfaces.ts","../src/types/index.ts","../src/utils/storefront-client.ts","../src/classes/Cart.ts","../src/classes/Adapter.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":[],"mappings":";;;;UAWiB,KAAA;;4BAUW;EAVX,KAAA,CAAA,KAAK,CAAA,EAA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AAA,IAAA;CAIA;AAAa,iBIJR,mBAAA,CJIQ;EAAA,aAAA;EAAA,qBAAA;EAAA,UAAA;EAAA,MAAA;EAAA,QAAA;EAAA,MAAA;EAAA,UAAA;EAAA,aAAA;EAAA,OAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EIQrB,wBJRqB,CAAA,EIQG,KAAA,CAAA,GAAA,CAAA,OJRH;;;iBK/BR,cAAA,CAAA,GAAmB;;;iBCmBnB,UAAA,CAAA,aAGqB,mBAAiB;;;iBCdtC,WAAA,CAAA,SAGe;;;iBC9Bf,cAAA,UAAyB,QAAQ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,342 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { CartReturn } from "@shopify/hydrogen";
|
|
3
|
+
|
|
4
|
+
//#region src/types/interfaces.d.ts
|
|
5
|
+
interface ICart {
|
|
6
|
+
isSynced(): boolean;
|
|
7
|
+
onChange(callback: (cart: CartData) => void): () => void;
|
|
8
|
+
fetch(force?: boolean): Promise<CartData | null>;
|
|
9
|
+
update(action: string, data: any): Promise<void>;
|
|
10
|
+
buy(variantId: string, quantity?: number): void;
|
|
11
|
+
get(property?: string): any;
|
|
12
|
+
getToken(): string | null;
|
|
13
|
+
getItemsIds(): string[];
|
|
14
|
+
getValue(currency?: string): number;
|
|
15
|
+
getSize(distinct?: boolean): number;
|
|
16
|
+
fetchCollections(force?: boolean): Promise<any>;
|
|
17
|
+
applyCoupon(code: string, expiresIn?: number): Promise<void>;
|
|
18
|
+
getCoupon(): string | null;
|
|
19
|
+
}
|
|
20
|
+
interface IShopifyAdapter {
|
|
21
|
+
fetchProduct(handle: string): Promise<ProductData>;
|
|
22
|
+
fetchProductCollections(handle: string, productId: number): Promise<any>;
|
|
23
|
+
fetchRecommendations(productId: number, intent: string): Promise<{
|
|
24
|
+
products: ProductData[];
|
|
25
|
+
intent: string;
|
|
26
|
+
}>;
|
|
27
|
+
buildProductPath(params: {
|
|
28
|
+
handle: string;
|
|
29
|
+
}): string;
|
|
30
|
+
convertToBaseCurrency(amount: number): number;
|
|
31
|
+
convertFromBaseCurrency(amount: number): number;
|
|
32
|
+
formatMoney(amount: number, includeDecimals: boolean): string;
|
|
33
|
+
getCustomer(): Promise<Customer | null>;
|
|
34
|
+
getPageContext(): PageContext;
|
|
35
|
+
getVisitorId(): string | null;
|
|
36
|
+
getMarket(): string | null;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/types/index.d.ts
|
|
40
|
+
type ProductData = {
|
|
41
|
+
id: number;
|
|
42
|
+
handle: string;
|
|
43
|
+
title: string;
|
|
44
|
+
available: boolean;
|
|
45
|
+
requires_selling_plan: boolean;
|
|
46
|
+
images: string[];
|
|
47
|
+
variants: ProductDataVariant[];
|
|
48
|
+
};
|
|
49
|
+
type ProductDataVariant = {
|
|
50
|
+
id: number;
|
|
51
|
+
title: string;
|
|
52
|
+
available: boolean;
|
|
53
|
+
price: number;
|
|
54
|
+
compare_at_price: number | null;
|
|
55
|
+
featured_image: {
|
|
56
|
+
src: string;
|
|
57
|
+
} | null;
|
|
58
|
+
selling_plan_allocations: Array<{
|
|
59
|
+
selling_plan_id: string;
|
|
60
|
+
}>;
|
|
61
|
+
};
|
|
62
|
+
type Product = {
|
|
63
|
+
id: string;
|
|
64
|
+
handle: string;
|
|
65
|
+
title: string;
|
|
66
|
+
description: string;
|
|
67
|
+
descriptionHtml: string;
|
|
68
|
+
variants: {
|
|
69
|
+
nodes: Variant[];
|
|
70
|
+
};
|
|
71
|
+
images: {
|
|
72
|
+
nodes: Image[];
|
|
73
|
+
};
|
|
74
|
+
featuredImage?: Image | null;
|
|
75
|
+
priceRange: PriceRange;
|
|
76
|
+
tags: string[];
|
|
77
|
+
productType: string;
|
|
78
|
+
vendor: string;
|
|
79
|
+
collections: {
|
|
80
|
+
nodes: Collection[];
|
|
81
|
+
};
|
|
82
|
+
requiresSellingPlan: boolean;
|
|
83
|
+
availableForSale: boolean;
|
|
84
|
+
options: ProductOption[];
|
|
85
|
+
};
|
|
86
|
+
type Variant = {
|
|
87
|
+
id: string;
|
|
88
|
+
title: string;
|
|
89
|
+
price: Money;
|
|
90
|
+
compareAtPrice?: Money | null;
|
|
91
|
+
availableForSale: boolean;
|
|
92
|
+
sellingPlanAllocations: {
|
|
93
|
+
edges: Array<{
|
|
94
|
+
node: {
|
|
95
|
+
sellingPlan: {
|
|
96
|
+
id: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
100
|
+
};
|
|
101
|
+
selectedOptions: SelectedOption[];
|
|
102
|
+
image?: Image | null;
|
|
103
|
+
sku?: string | null;
|
|
104
|
+
quantityAvailable?: number;
|
|
105
|
+
};
|
|
106
|
+
type Image = {
|
|
107
|
+
id?: string;
|
|
108
|
+
url: string;
|
|
109
|
+
altText?: string | null;
|
|
110
|
+
width?: number;
|
|
111
|
+
height?: number;
|
|
112
|
+
};
|
|
113
|
+
type Money = {
|
|
114
|
+
amount: string;
|
|
115
|
+
currencyCode: string;
|
|
116
|
+
};
|
|
117
|
+
type PriceRange = {
|
|
118
|
+
minVariantPrice: Money;
|
|
119
|
+
maxVariantPrice: Money;
|
|
120
|
+
};
|
|
121
|
+
type ProductOption = {
|
|
122
|
+
id?: string;
|
|
123
|
+
name: string;
|
|
124
|
+
values: string[];
|
|
125
|
+
};
|
|
126
|
+
type SelectedOption = {
|
|
127
|
+
name: string;
|
|
128
|
+
value: string;
|
|
129
|
+
};
|
|
130
|
+
type Collection = {
|
|
131
|
+
id: string;
|
|
132
|
+
handle: string;
|
|
133
|
+
title: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
};
|
|
136
|
+
type CartData = {
|
|
137
|
+
token: string;
|
|
138
|
+
item_count: number;
|
|
139
|
+
items: CartDataItem[];
|
|
140
|
+
total_price: number;
|
|
141
|
+
discount_codes?: DiscountCode[];
|
|
142
|
+
attributes?: Record<string, any>;
|
|
143
|
+
note?: string | null;
|
|
144
|
+
};
|
|
145
|
+
type CartDataItem = {
|
|
146
|
+
id: number;
|
|
147
|
+
quantity: number;
|
|
148
|
+
product_id: number;
|
|
149
|
+
variant_id: number;
|
|
150
|
+
price: number;
|
|
151
|
+
};
|
|
152
|
+
type DiscountCode = {
|
|
153
|
+
code: string;
|
|
154
|
+
applicable: boolean;
|
|
155
|
+
};
|
|
156
|
+
type Customer = {
|
|
157
|
+
id: string;
|
|
158
|
+
email?: string | null;
|
|
159
|
+
phone?: string | null;
|
|
160
|
+
firstName?: string | null;
|
|
161
|
+
lastName?: string | null;
|
|
162
|
+
displayName: string;
|
|
163
|
+
hasAccount: boolean;
|
|
164
|
+
tags: string[];
|
|
165
|
+
};
|
|
166
|
+
type PageContext = {
|
|
167
|
+
pageType?: string | number;
|
|
168
|
+
product?: {
|
|
169
|
+
handle: string;
|
|
170
|
+
id: number;
|
|
171
|
+
tags?: string[];
|
|
172
|
+
} | null;
|
|
173
|
+
collection?: {
|
|
174
|
+
id: number;
|
|
175
|
+
} | null;
|
|
176
|
+
};
|
|
177
|
+
type CartAddProduct = {
|
|
178
|
+
id: string | number;
|
|
179
|
+
variantId: string | number;
|
|
180
|
+
price?: string | number;
|
|
181
|
+
quantity?: number;
|
|
182
|
+
handle?: string;
|
|
183
|
+
properties?: Record<string, string>;
|
|
184
|
+
};
|
|
185
|
+
type PersonizelyConfigMethods = {
|
|
186
|
+
formatMoney: (amount: number, includeDecimals: boolean) => string;
|
|
187
|
+
builtProductPath?: ({
|
|
188
|
+
handle
|
|
189
|
+
}: {
|
|
190
|
+
handle: string;
|
|
191
|
+
}) => string;
|
|
192
|
+
};
|
|
193
|
+
type PersonizelyConfig = {
|
|
194
|
+
locale?: string;
|
|
195
|
+
currency?: {
|
|
196
|
+
rate?: number;
|
|
197
|
+
active?: string;
|
|
198
|
+
base?: string;
|
|
199
|
+
};
|
|
200
|
+
market?: string;
|
|
201
|
+
methods?: PersonizelyConfigMethods;
|
|
202
|
+
};
|
|
203
|
+
type HydrogenConfig = {
|
|
204
|
+
cart: ICart;
|
|
205
|
+
adapter: IShopifyAdapter;
|
|
206
|
+
onCartAdd: (callback: (product: CartAddProduct) => Promise<boolean>) => () => void;
|
|
207
|
+
onCheckout: (callback: () => Promise<boolean>) => () => void;
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/utils/storefront-client.d.ts
|
|
211
|
+
type StorefrontClientConfig = {
|
|
212
|
+
storefrontAccessToken: string;
|
|
213
|
+
shopDomain: string;
|
|
214
|
+
apiVersion?: string;
|
|
215
|
+
};
|
|
216
|
+
declare class StorefrontClient {
|
|
217
|
+
private storefrontAccessToken;
|
|
218
|
+
private shopDomain;
|
|
219
|
+
private apiVersion;
|
|
220
|
+
private endpoint;
|
|
221
|
+
constructor(config: StorefrontClientConfig);
|
|
222
|
+
query<T = any>(query: string, variables?: Record<string, any>): Promise<T>;
|
|
223
|
+
mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T>;
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/classes/Cart.d.ts
|
|
227
|
+
declare class Cart implements ICart {
|
|
228
|
+
private storefrontClient;
|
|
229
|
+
private listeners;
|
|
230
|
+
private cart;
|
|
231
|
+
private cartPromise;
|
|
232
|
+
private revalidate?;
|
|
233
|
+
constructor(cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void);
|
|
234
|
+
updateCartData(cart: CartReturn): void;
|
|
235
|
+
notifyListeners(): void;
|
|
236
|
+
isSynced(): boolean;
|
|
237
|
+
onChange(callback: (cart: CartData) => void): () => void;
|
|
238
|
+
fetch(force?: boolean): Promise<CartData | null>;
|
|
239
|
+
update(action: string, data: any): Promise<void>;
|
|
240
|
+
buy(_variantId: string, _quantity?: number): Promise<void>;
|
|
241
|
+
get(property?: string): any;
|
|
242
|
+
getToken(): string | null;
|
|
243
|
+
getItemsIds(): string[];
|
|
244
|
+
getCurrency(): string;
|
|
245
|
+
getValue(_currency?: string): number;
|
|
246
|
+
getSize(distinct?: boolean): number;
|
|
247
|
+
fetchCollections(_force?: boolean): Promise<any>;
|
|
248
|
+
applyCoupon(code: string, expiresIn?: number): Promise<void>;
|
|
249
|
+
getCoupon(): string | null;
|
|
250
|
+
private toCartData;
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/classes/Adapter.d.ts
|
|
254
|
+
declare class Adapter implements IShopifyAdapter {
|
|
255
|
+
private client;
|
|
256
|
+
private currency;
|
|
257
|
+
private market;
|
|
258
|
+
private locale;
|
|
259
|
+
private pageContext;
|
|
260
|
+
private methods?;
|
|
261
|
+
private customerAccessToken;
|
|
262
|
+
constructor(config: PersonizelyConfig, storefrontClient: StorefrontClient);
|
|
263
|
+
setCustomerAccessToken(token: string | null): void;
|
|
264
|
+
fetchProduct(handle: string): Promise<ProductData>;
|
|
265
|
+
fetchProductCollections(handle: string, productId: number): Promise<number[]>;
|
|
266
|
+
fetchRecommendations(productId: number, intent: string): Promise<{
|
|
267
|
+
products: ProductData[];
|
|
268
|
+
intent: string;
|
|
269
|
+
}>;
|
|
270
|
+
buildProductPath(product: {
|
|
271
|
+
handle: string;
|
|
272
|
+
}): string;
|
|
273
|
+
convertToBaseCurrency(amount: number): number;
|
|
274
|
+
convertFromBaseCurrency(amount: number): number;
|
|
275
|
+
formatMoney(amount: number, includeDecimals?: boolean): string;
|
|
276
|
+
getCustomer(): Promise<Customer | null>;
|
|
277
|
+
getPageContext(): PageContext;
|
|
278
|
+
setPageContext(context: Partial<PageContext>): void;
|
|
279
|
+
getVisitorId(): string | null;
|
|
280
|
+
getMarket(): string | null;
|
|
281
|
+
getCurrencyRate(): number;
|
|
282
|
+
toProductData(product: Product): ProductData;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/components/PersonizelyProvider.d.ts
|
|
286
|
+
declare global {
|
|
287
|
+
interface Window {
|
|
288
|
+
__PLY_HYDROGEN_CONFIG__?: HydrogenConfig;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
type PersonizelyContextType = {
|
|
292
|
+
cart: Cart;
|
|
293
|
+
adapter: Adapter;
|
|
294
|
+
websiteApiKey: string;
|
|
295
|
+
triggerCartAdd: (product: CartAddProduct) => Promise<boolean>;
|
|
296
|
+
triggerCheckout: () => Promise<boolean>;
|
|
297
|
+
};
|
|
298
|
+
type PersonizelyProviderProps = {
|
|
299
|
+
websiteApiKey: string;
|
|
300
|
+
storefrontAccessToken: string;
|
|
301
|
+
shopDomain: string;
|
|
302
|
+
apiVersion?: string;
|
|
303
|
+
scriptBaseUrl?: string;
|
|
304
|
+
locale?: string;
|
|
305
|
+
currency?: {
|
|
306
|
+
rate: number;
|
|
307
|
+
active: string;
|
|
308
|
+
base: string;
|
|
309
|
+
};
|
|
310
|
+
market?: string;
|
|
311
|
+
methods?: PersonizelyConfigMethods;
|
|
312
|
+
children: ReactNode;
|
|
313
|
+
customerAccessToken?: string | null;
|
|
314
|
+
};
|
|
315
|
+
declare function PersonizelyProvider({
|
|
316
|
+
websiteApiKey,
|
|
317
|
+
storefrontAccessToken,
|
|
318
|
+
shopDomain,
|
|
319
|
+
locale,
|
|
320
|
+
currency,
|
|
321
|
+
market,
|
|
322
|
+
apiVersion,
|
|
323
|
+
scriptBaseUrl,
|
|
324
|
+
methods,
|
|
325
|
+
children,
|
|
326
|
+
customerAccessToken
|
|
327
|
+
}: PersonizelyProviderProps): React.JSX.Element;
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/hooks/usePersonizely.d.ts
|
|
330
|
+
declare function usePersonizely(): PersonizelyContextType;
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/hooks/useCartAdd.d.ts
|
|
333
|
+
declare function useCartAdd(): (product: CartAddProduct) => Promise<boolean>;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/hooks/useCheckout.d.ts
|
|
336
|
+
declare function useCheckout(): () => Promise<boolean>;
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/hooks/usePageContext.d.ts
|
|
339
|
+
declare function usePageContext(context: Partial<PageContext>): void;
|
|
340
|
+
//#endregion
|
|
341
|
+
export { Adapter, Cart, type CartAddProduct, type HydrogenConfig, type ICart, type IShopifyAdapter, type PageContext, type PersonizelyConfig, type PersonizelyContextType, PersonizelyProvider, type PersonizelyProviderProps, useCartAdd, useCheckout, usePageContext, usePersonizely };
|
|
342
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,useMemo as a,useRef as o}from"react";import{useMatches as s,useRevalidator as c}from"react-router";function l(e){if(typeof document>`u`)return null;let t=e+`=`,n=document.cookie.split(`;`);for(let e=0;e<n.length;e++){let r=n[e];for(;r.charAt(0)===` `;)r=r.substring(1,r.length);if(r.indexOf(t)===0)return r.substring(t.length,r.length)}return null}function u(e,t,n,r=`/`){if(typeof document>`u`)return;let i=``;if(n){let e=new Date;e.setTime(e.getTime()+n*24*60*60*1e3),i=`; expires=`+e.toUTCString()}document.cookie=e+`=`+t+i+`; path=`+r}const d=`
|
|
2
|
+
fragment CartFragment on Cart {
|
|
3
|
+
id
|
|
4
|
+
checkoutUrl
|
|
5
|
+
totalQuantity
|
|
6
|
+
cost {
|
|
7
|
+
subtotalAmount {
|
|
8
|
+
amount
|
|
9
|
+
currencyCode
|
|
10
|
+
}
|
|
11
|
+
totalAmount {
|
|
12
|
+
amount
|
|
13
|
+
currencyCode
|
|
14
|
+
}
|
|
15
|
+
totalTaxAmount {
|
|
16
|
+
amount
|
|
17
|
+
currencyCode
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
lines(first: 100) {
|
|
21
|
+
nodes {
|
|
22
|
+
id
|
|
23
|
+
quantity
|
|
24
|
+
cost {
|
|
25
|
+
totalAmount {
|
|
26
|
+
amount
|
|
27
|
+
currencyCode
|
|
28
|
+
}
|
|
29
|
+
amountPerQuantity {
|
|
30
|
+
amount
|
|
31
|
+
currencyCode
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
merchandise {
|
|
35
|
+
... on ProductVariant {
|
|
36
|
+
id
|
|
37
|
+
title
|
|
38
|
+
price {
|
|
39
|
+
amount
|
|
40
|
+
currencyCode
|
|
41
|
+
}
|
|
42
|
+
image {
|
|
43
|
+
url
|
|
44
|
+
altText
|
|
45
|
+
}
|
|
46
|
+
selectedOptions {
|
|
47
|
+
name
|
|
48
|
+
value
|
|
49
|
+
}
|
|
50
|
+
product {
|
|
51
|
+
id
|
|
52
|
+
handle
|
|
53
|
+
title
|
|
54
|
+
featuredImage {
|
|
55
|
+
url
|
|
56
|
+
altText
|
|
57
|
+
}
|
|
58
|
+
tags
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
attributes {
|
|
63
|
+
key
|
|
64
|
+
value
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
discountCodes {
|
|
69
|
+
code
|
|
70
|
+
applicable
|
|
71
|
+
}
|
|
72
|
+
attributes {
|
|
73
|
+
key
|
|
74
|
+
value
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`;`${d}`;const f=`
|
|
78
|
+
mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
|
|
79
|
+
cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
80
|
+
cart {
|
|
81
|
+
...CartFragment
|
|
82
|
+
}
|
|
83
|
+
userErrors {
|
|
84
|
+
field
|
|
85
|
+
message
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
${d}
|
|
90
|
+
`,p=`
|
|
91
|
+
mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
|
|
92
|
+
cartLinesUpdate(cartId: $cartId, lines: $lines) {
|
|
93
|
+
cart {
|
|
94
|
+
...CartFragment
|
|
95
|
+
}
|
|
96
|
+
userErrors {
|
|
97
|
+
field
|
|
98
|
+
message
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
${d}
|
|
103
|
+
`,m=`
|
|
104
|
+
mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {
|
|
105
|
+
cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
|
|
106
|
+
cart {
|
|
107
|
+
...CartFragment
|
|
108
|
+
}
|
|
109
|
+
userErrors {
|
|
110
|
+
field
|
|
111
|
+
message
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
${d}
|
|
116
|
+
`,h=`
|
|
117
|
+
mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {
|
|
118
|
+
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
|
|
119
|
+
cart {
|
|
120
|
+
...CartFragment
|
|
121
|
+
}
|
|
122
|
+
userErrors {
|
|
123
|
+
field
|
|
124
|
+
message
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
${d}
|
|
129
|
+
`,g=`
|
|
130
|
+
mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {
|
|
131
|
+
cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
|
|
132
|
+
cart {
|
|
133
|
+
...CartFragment
|
|
134
|
+
}
|
|
135
|
+
userErrors {
|
|
136
|
+
field
|
|
137
|
+
message
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
${d}
|
|
142
|
+
`;function _(e,t){return`gid://shopify/${t}/${e}`}function v(e){return Number(e.split(`/`).pop())}const y=`_ply_coupon`;var b=class{constructor(e,t,n){this.listeners=[],this.cart=null,this.storefrontClient=t,this.cartPromise=e,this.revalidate=n}updateCartData(e){this.cart=e,this.cartPromise=null}notifyListeners(){this.cart&&this.listeners.forEach(e=>{try{this.cart&&e(this.toCartData(this.cart))}catch(e){console.error(`Cart listener error:`,e)}})}isSynced(){return!!this.cart}onChange(e){return this.listeners.push(e),()=>{let t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}}async fetch(e=!0){return this.cart&&!e?this.toCartData(this.cart):this.cartPromise?(this.cart=await this.cartPromise,this.toCartData(this.cart)):this.cart?this.toCartData(this.cart):null}async update(e,t){if(!this.cart)throw Error(`Cart not initialized`);let n=this.cart.lines.nodes.map(e=>e.id);try{let r;switch(e){case`add`:r=await this.storefrontClient.mutate(f,{cartId:this.cart.id,lines:[{merchandiseId:_(t.id,`ProductVariant`),quantity:t.quantity||1,attributes:t.properties?Object.entries(t.properties).map(([e,t])=>({key:e,value:String(t)})):void 0}]}),r?.cartLinesAdd?.cart&&(this.cart=r.cartLinesAdd.cart,this.notifyListeners());break;case`update`:case`change`:if(t.updates){let e=[],n=[];Object.entries(t.updates).forEach(([t,r])=>{let i=this.cart.lines.nodes.find(e=>v(e.merchandise.id)===Number(t));i?e.push({id:i.id,quantity:Number(r)}):Number(r)>0&&n.push({merchandiseId:_(Number(t),`ProductVariant`),quantity:Number(r)})});let r=[];if(e.length>0&&r.push(this.storefrontClient.mutate(p,{cartId:this.cart.id,lines:e})),n.length>0&&r.push(this.storefrontClient.mutate(f,{cartId:this.cart.id,lines:n})),r.length>0){let e=await Promise.all(r),t=e[e.length-1];(t?.cartLinesUpdate?.cart||t?.cartLinesAdd?.cart)&&(this.cart=t.cartLinesUpdate?.cart||t.cartLinesAdd?.cart,this.notifyListeners())}}else t.id&&(r=await this.storefrontClient.mutate(p,{cartId:this.cart.id,lines:[{id:`gid://shopify/CartLine/${t.id}`,quantity:t.quantity}]}),r?.cartLinesUpdate?.cart&&(this.cart=r.cartLinesUpdate.cart,this.notifyListeners()));t.attributes&&this.cart&&(r=await this.storefrontClient.mutate(g,{cartId:this.cart.id,attributes:Object.entries(t.attributes).map(([e,t])=>({key:e,value:String(t)}))}),r?.cartAttributesUpdate?.cart&&(this.cart=r.cartAttributesUpdate.cart,this.notifyListeners())),t.discount&&this.cart&&(r=await this.storefrontClient.mutate(h,{cartId:this.cart.id,discountCodes:[t.discount]}),r?.cartDiscountCodesUpdate?.cart&&(this.cart=r.cartDiscountCodesUpdate.cart,this.notifyListeners()));break;case`clear`:r=await this.storefrontClient.mutate(m,{cartId:this.cart.id,lineIds:n}),r?.cartLinesRemove?.cart&&(this.cart=r.cartLinesRemove.cart,this.notifyListeners());break;default:console.warn(`Unknown cart action: ${e}`)}this.revalidate&&this.revalidate()}catch(e){throw console.error(`Cart update error:`,e),e}}async buy(e,t=1){if(!this.cart)return;let n=this.getCoupon(),r=this.cart.checkoutUrl||`/checkout`,i=n?`${r}?discount=${n}`:r;typeof window<`u`&&(window.location.href=i)}get(e){return this.cart?e?this.toCartData(this.cart)[e]:this.toCartData(this.cart):e?void 0:null}getToken(){return this.cart&&this.cart.id||null}getItemsIds(){return this.cart?this.cart.lines.nodes.map(e=>e.merchandise.product.id):[]}getCurrency(){return this.cart?this.cart.cost.totalAmount.currencyCode:`USD`}getValue(e){return this.cart?parseFloat(this.cart.cost.totalAmount.amount)*100:0}getSize(e=!1){return this.cart?e?new Set(this.cart.lines.nodes.map(e=>e.merchandise.product.id)).size:this.cart.totalQuantity:0}async fetchCollections(e=!1){return console.warn(`fetchCollections: Not implemented for Hydrogen. Use custom metafield query.`),{}}async applyCoupon(e,t){if(!this.cart)throw Error(`Cart not initialized`);u(y,e,t);try{let t=await this.storefrontClient.mutate(h,{cartId:this.cart.id,discountCodes:[e]});t?.cartDiscountCodesUpdate?.cart&&(this.cart=t.cartDiscountCodesUpdate.cart,this.notifyListeners()),this.revalidate&&this.revalidate()}catch(e){throw console.error(`Error applying coupon:`,e),e}}getCoupon(){return this.cart?this.cart.discountCodes&&this.cart.discountCodes.length>0?this.cart.discountCodes[0].code:l(y):null}toCartData(e){return{token:e.id,item_count:e.totalQuantity||0,items:(e.lines?.nodes||[]).map(e=>({id:v(e.id),product_id:v(e.merchandise.product.id),variant_id:v(e.merchandise.id),price:Number(e.merchandise.price.amount)*100,quantity:e.quantity})),total_price:Number(e.cost.totalAmount.amount)*100,discount_codes:e.discountCodes,attributes:e.attributes,note:e.note}}};const x=`
|
|
143
|
+
fragment ProductFragment on Product {
|
|
144
|
+
id
|
|
145
|
+
handle
|
|
146
|
+
title
|
|
147
|
+
description
|
|
148
|
+
descriptionHtml
|
|
149
|
+
productType
|
|
150
|
+
vendor
|
|
151
|
+
tags
|
|
152
|
+
availableForSale
|
|
153
|
+
requiresSellingPlan
|
|
154
|
+
priceRange {
|
|
155
|
+
minVariantPrice {
|
|
156
|
+
amount
|
|
157
|
+
currencyCode
|
|
158
|
+
}
|
|
159
|
+
maxVariantPrice {
|
|
160
|
+
amount
|
|
161
|
+
currencyCode
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
featuredImage {
|
|
165
|
+
id
|
|
166
|
+
url
|
|
167
|
+
altText
|
|
168
|
+
width
|
|
169
|
+
height
|
|
170
|
+
}
|
|
171
|
+
images(first: 10) {
|
|
172
|
+
nodes {
|
|
173
|
+
id
|
|
174
|
+
url
|
|
175
|
+
altText
|
|
176
|
+
width
|
|
177
|
+
height
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
variants(first: 100) {
|
|
181
|
+
nodes {
|
|
182
|
+
id
|
|
183
|
+
title
|
|
184
|
+
availableForSale
|
|
185
|
+
quantityAvailable
|
|
186
|
+
sellingPlanAllocations(first: 10) {
|
|
187
|
+
edges {
|
|
188
|
+
node {
|
|
189
|
+
sellingPlan {
|
|
190
|
+
id
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
sku
|
|
196
|
+
price {
|
|
197
|
+
amount
|
|
198
|
+
currencyCode
|
|
199
|
+
}
|
|
200
|
+
compareAtPrice {
|
|
201
|
+
amount
|
|
202
|
+
currencyCode
|
|
203
|
+
}
|
|
204
|
+
selectedOptions {
|
|
205
|
+
name
|
|
206
|
+
value
|
|
207
|
+
}
|
|
208
|
+
image {
|
|
209
|
+
id
|
|
210
|
+
url
|
|
211
|
+
altText
|
|
212
|
+
width
|
|
213
|
+
height
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
options {
|
|
218
|
+
id
|
|
219
|
+
name
|
|
220
|
+
values
|
|
221
|
+
}
|
|
222
|
+
collections(first: 10) {
|
|
223
|
+
nodes {
|
|
224
|
+
id
|
|
225
|
+
handle
|
|
226
|
+
title
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`,S=`
|
|
231
|
+
query getProductByHandle($handle: String!) {
|
|
232
|
+
product(handle: $handle) {
|
|
233
|
+
...ProductFragment
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
${x}
|
|
237
|
+
`,C=`
|
|
238
|
+
query getProductById($id: ID!) {
|
|
239
|
+
product(id: $id) {
|
|
240
|
+
...ProductFragment
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
${x}
|
|
244
|
+
`,w=`
|
|
245
|
+
query getProductRecommendations($productId: ID!) {
|
|
246
|
+
productRecommendations(productId: $productId) {
|
|
247
|
+
...ProductFragment
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
${x}
|
|
251
|
+
`;var T=class{constructor(e,t){this.customerAccessToken=null,this.client=t,this.methods=e.methods,this.currency={active:`USD`,base:`USD`,rate:1,...e.currency},this.locale=e.locale||`en-US`,this.market=e.market||null,this.pageContext={pageType:void 0,product:null,collection:null}}setCustomerAccessToken(e){this.customerAccessToken=e}async fetchProduct(e){let t=await this.client.query(S,{handle:e});if(!t.product)throw Error(`Product not found: ${e}`);return this.toProductData(t.product)}async fetchProductCollections(e,t){let n;if(t?n=await this.client.query(C,{id:`gid://shopify/Product/${t}`}):e&&(n=await this.client.query(S,{handle:e})),!n||!n.product)throw Error(`Product not found: ${t}`);return n.product.collections.nodes.map(e=>v(e.id))}async fetchRecommendations(e,t){return{intent:t,products:(await this.client.query(w,{productId:`gid://shopify/Product/${e}`,intent:t})).productRecommendations.map(e=>this.toProductData(e))||[]}}buildProductPath(e){return typeof this.methods?.builtProductPath==`function`?this.methods.builtProductPath(e):`/products/${e.handle}`}convertToBaseCurrency(e){return this.currency.rate/e}convertFromBaseCurrency(e){return this.currency.rate*e}formatMoney(e,t=!0){return typeof this.methods?.formatMoney==`function`?this.methods.formatMoney(e,t):new Intl.NumberFormat(this.locale,{style:`currency`,currency:this.currency.active,maximumFractionDigits:t?void 0:0}).format(e/100)}async getCustomer(){if(!this.customerAccessToken)return null;try{return(await this.client.query(`
|
|
252
|
+
query getCustomer($customerAccessToken: String!) {
|
|
253
|
+
customer(customerAccessToken: $customerAccessToken) {
|
|
254
|
+
...CustomerFragment
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fragment CustomerFragment on Customer {
|
|
259
|
+
id
|
|
260
|
+
email
|
|
261
|
+
phone
|
|
262
|
+
firstName
|
|
263
|
+
lastName
|
|
264
|
+
displayName
|
|
265
|
+
defaultAddress {
|
|
266
|
+
id
|
|
267
|
+
address1
|
|
268
|
+
address2
|
|
269
|
+
city
|
|
270
|
+
province
|
|
271
|
+
country
|
|
272
|
+
zip
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
`,{customerAccessToken:this.customerAccessToken})).customer||null}catch(e){return console.error(`Error fetching customer:`,e),null}}getPageContext(){return this.pageContext}setPageContext(e){e.product&&(e.product.id=v(String(e.product.id))),e.collection&&(e.collection.id=v(String(e.collection.id))),this.pageContext=e}getVisitorId(){return null}getMarket(){return this.market}getCurrencyRate(){return this.currency.rate}toProductData(e){return{id:v(e.id),handle:e.handle,title:e.title,available:e.availableForSale,requires_selling_plan:e.requiresSellingPlan,images:e.images.nodes.map(e=>e.url),variants:e.variants.nodes.map(e=>({id:v(e.id),title:e.title,available:e.availableForSale,price:Math.round(parseFloat(e.price.amount)*100),compare_at_price:e.compareAtPrice?Math.round(parseFloat(e.compareAtPrice.amount)*100):null,featured_image:e.image?{src:e.image.url}:null,selling_plan_allocations:e.sellingPlanAllocations?.edges?.map(e=>({selling_plan_id:e.node.sellingPlan.id}))||[]}))}}},E=class{constructor(e){this.storefrontAccessToken=e.storefrontAccessToken,this.shopDomain=e.shopDomain,this.apiVersion=e.apiVersion||`2024-01`,this.endpoint=`https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`}async query(e,t){try{let n=await fetch(this.endpoint,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:t})});if(!n.ok)throw Error(`Storefront API request failed: ${n.statusText}`);let r=await n.json();if(r.errors)throw Error(`GraphQL errors: ${JSON.stringify(r.errors)}`);return r.data}catch(e){throw console.error(`Storefront API error:`,e),e}}async mutate(e,t){return this.query(e,t)}};const D=t(null);function O({websiteApiKey:t,storefrontAccessToken:n,shopDomain:r,locale:l,currency:u,market:d,apiVersion:f,scriptBaseUrl:p,methods:m,children:h,customerAccessToken:g}){let _=s().find(e=>e.id===`root`)?.loaderData?.cart,v=c(),y=a(()=>new E({storefrontAccessToken:n,shopDomain:r,apiVersion:f}),[n,r,f]),x=a(()=>{let e=new T({locale:l,currency:u,market:d,methods:m},y);return g&&e.setCustomerAccessToken(g),e},[]),S=a(()=>new b(_,y,v.revalidate),[]),C=o(null);i(()=>{_.then(e=>{e&&e!==C.current&&(S.updateCartData(e),S.notifyListeners(),C.current=e)})},[_,S]);let w=o([]),O=o([]);i(()=>{if(typeof window>`u`)return;window.__PLY_HYDROGEN_CONFIG__={cart:S,adapter:x,onCartAdd:e=>(w.current.push(e),()=>{let t=w.current.indexOf(e);t>-1&&w.current.splice(t,1)}),onCheckout:e=>(O.current.push(e),()=>{let t=O.current.indexOf(e);t>-1&&O.current.splice(t,1)})};let e=document.createElement(`script`);return e.src=`${p||`https://static.personizely.net`}/${t}.js`,document.head.appendChild(e),()=>{delete window.__PLY_HYDROGEN_CONFIG__,e&&e.remove()}},[]);let k=a(()=>({cart:S,adapter:x,websiteApiKey:t,triggerCartAdd:async e=>{let t=!1;for(let n of w.current)try{await n(e)&&(t=!0)}catch(e){console.error(`Cart add callback error:`,e)}return t},triggerCheckout:async()=>{let e=!1;for(let t of O.current)try{await t()&&(e=!0)}catch(e){console.error(`Checkout callback error:`,e)}return e}}),[S,x,t]);return e.createElement(D.Provider,{value:k},h)}function k(){let e=r(D);if(!e)throw Error(`usePersonizely must be used within a PersonizelyProvider. Make sure your component is wrapped with <PersonizelyProvider>.`);return e}function A(){let e=k();return n(async t=>typeof window>`u`?!1:await e.triggerCartAdd({...t,id:v(String(t.id)),variantId:v(String(t.variantId)),price:Number(t.price)*100}),[e])}function j(){let e=k();return n(async()=>typeof window>`u`?!1:await e.triggerCheckout(),[e])}function M(e){k().adapter.setPageContext(e)}export{T as Adapter,b as Cart,O as PersonizelyProvider,A as useCartAdd,j as useCheckout,M as usePageContext,k as usePersonizely};
|
|
277
|
+
//# sourceMappingURL=index.mjs.map
|