@personizely/shopify-hydrogen 1.0.1 → 1.0.3
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/README.md +36 -4
- package/dist/index.cjs +21 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +342 -0
- package/dist/index.mjs +21 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","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,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EAWvC,gBAAA,CAAA,KAAe,CAAA,EAAA,OAAA,CAAA,EAhBK,OAgBL,CAAA,GAAA,CAAA;EAIQ,WAAA,CAAA,IAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAfS,OAeT,CAAA,IAAA,CAAA;EAAR,SAAA,EAAA,EAAA,MAAA,GAAA,IAAA;;AAY+C,UAhB9D,eAAA,CAgB8D;EAApB,YAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAZ3B,OAY2B,CAZnB,WAYmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.cts","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,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EAWvC,gBAAA,CAAA,KAAe,CAAA,EAAA,OAAA,CAAA,EAhBK,OAgBL,CAAA,GAAA,CAAA;EAIQ,WAAA,CAAA,IAAA,EAAA,MAAA,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.d.mts
CHANGED
|
@@ -30,7 +30,7 @@ interface IShopifyAdapter {
|
|
|
30
30
|
convertToBaseCurrency(amount: number): number;
|
|
31
31
|
convertFromBaseCurrency(amount: number): number;
|
|
32
32
|
formatMoney(amount: number, includeDecimals: boolean): string;
|
|
33
|
-
getCustomer():
|
|
33
|
+
getCustomer(): Customer | null;
|
|
34
34
|
getPageContext(): PageContext;
|
|
35
35
|
getVisitorId(): string | null;
|
|
36
36
|
getMarket(): string | null;
|
|
@@ -258,9 +258,9 @@ declare class Adapter implements IShopifyAdapter {
|
|
|
258
258
|
private locale;
|
|
259
259
|
private pageContext;
|
|
260
260
|
private methods?;
|
|
261
|
-
private
|
|
261
|
+
private customer;
|
|
262
262
|
constructor(config: PersonizelyConfig, storefrontClient: StorefrontClient);
|
|
263
|
-
|
|
263
|
+
setCustomer(customer: Customer | null): void;
|
|
264
264
|
fetchProduct(handle: string): Promise<ProductData>;
|
|
265
265
|
fetchProductCollections(handle: string, productId: number): Promise<number[]>;
|
|
266
266
|
fetchRecommendations(productId: number, intent: string): Promise<{
|
|
@@ -273,7 +273,7 @@ declare class Adapter implements IShopifyAdapter {
|
|
|
273
273
|
convertToBaseCurrency(amount: number): number;
|
|
274
274
|
convertFromBaseCurrency(amount: number): number;
|
|
275
275
|
formatMoney(amount: number, includeDecimals?: boolean): string;
|
|
276
|
-
getCustomer():
|
|
276
|
+
getCustomer(): Customer | null;
|
|
277
277
|
getPageContext(): PageContext;
|
|
278
278
|
setPageContext(context: Partial<PageContext>): void;
|
|
279
279
|
getVisitorId(): string | null;
|
|
@@ -310,7 +310,7 @@ type PersonizelyProviderProps = {
|
|
|
310
310
|
market?: string;
|
|
311
311
|
methods?: PersonizelyConfigMethods;
|
|
312
312
|
children: ReactNode;
|
|
313
|
-
|
|
313
|
+
customer?: Customer | null;
|
|
314
314
|
};
|
|
315
315
|
declare function PersonizelyProvider({
|
|
316
316
|
websiteApiKey,
|
|
@@ -323,7 +323,7 @@ declare function PersonizelyProvider({
|
|
|
323
323
|
scriptBaseUrl,
|
|
324
324
|
methods,
|
|
325
325
|
children,
|
|
326
|
-
|
|
326
|
+
customer
|
|
327
327
|
}: PersonizelyProviderProps): React.JSX.Element;
|
|
328
328
|
//#endregion
|
|
329
329
|
//#region src/hooks/usePersonizely.d.ts
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +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,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EAWvC,gBAAA,CAAA,KAAe,CAAA,EAAA,OAAA,CAAA,EAhBK,OAgBL,CAAA,GAAA,CAAA;EAIQ,WAAA,CAAA,IAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAfS,OAeT,CAAA,IAAA,CAAA;EAAR,SAAA,EAAA,EAAA,MAAA,GAAA,IAAA;;AAY+C,UAhB9D,eAAA,CAgB8D;EAApB,YAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAZ3B,OAY2B,CAZnB,WAYmB,CAAA;
|
|
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,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EAWvC,gBAAA,CAAA,KAAe,CAAA,EAAA,OAAA,CAAA,EAhBK,OAgBL,CAAA,GAAA,CAAA;EAIQ,WAAA,CAAA,IAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAfS,OAeT,CAAA,IAAA,CAAA;EAAR,SAAA,EAAA,EAAA,MAAA,GAAA,IAAA;;AAY+C,UAhB9D,eAAA,CAgB8D;EAApB,YAAA,CAAA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
+
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(): 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 customer;
|
|
262
|
+
constructor(config: PersonizelyConfig, storefrontClient: StorefrontClient);
|
|
263
|
+
setCustomer(customer: Customer | 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(): 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
|
+
customer?: Customer | 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
|
+
customer
|
|
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
CHANGED
|
@@ -126,7 +126,20 @@ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,use
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
${d}
|
|
129
|
-
|
|
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=`
|
|
130
143
|
fragment ProductFragment on Product {
|
|
131
144
|
id
|
|
132
145
|
handle
|
|
@@ -214,51 +227,26 @@ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,use
|
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
229
|
}
|
|
217
|
-
`,
|
|
230
|
+
`,S=`
|
|
218
231
|
query getProductByHandle($handle: String!) {
|
|
219
232
|
product(handle: $handle) {
|
|
220
233
|
...ProductFragment
|
|
221
234
|
}
|
|
222
235
|
}
|
|
223
|
-
${
|
|
224
|
-
`,
|
|
236
|
+
${x}
|
|
237
|
+
`,C=`
|
|
225
238
|
query getProductById($id: ID!) {
|
|
226
239
|
product(id: $id) {
|
|
227
240
|
...ProductFragment
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
|
-
${
|
|
231
|
-
`,
|
|
243
|
+
${x}
|
|
244
|
+
`,w=`
|
|
232
245
|
query getProductRecommendations($productId: ID!) {
|
|
233
246
|
productRecommendations(productId: $productId) {
|
|
234
247
|
...ProductFragment
|
|
235
248
|
}
|
|
236
249
|
}
|
|
237
|
-
${
|
|
238
|
-
`;var
|
|
239
|
-
query getCustomer($customerAccessToken: String!) {
|
|
240
|
-
customer(customerAccessToken: $customerAccessToken) {
|
|
241
|
-
...CustomerFragment
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
fragment CustomerFragment on Customer {
|
|
246
|
-
id
|
|
247
|
-
email
|
|
248
|
-
phone
|
|
249
|
-
firstName
|
|
250
|
-
lastName
|
|
251
|
-
displayName
|
|
252
|
-
defaultAddress {
|
|
253
|
-
id
|
|
254
|
-
address1
|
|
255
|
-
address2
|
|
256
|
-
city
|
|
257
|
-
province
|
|
258
|
-
country
|
|
259
|
-
zip
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
`,{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=_(String(e.product.id))),e.collection&&(e.collection.id=_(String(e.collection.id))),this.pageContext=e}getVisitorId(){return null}getMarket(){return this.market}getCurrencyRate(){return this.currency.rate}toProductData(e){return{id:_(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:_(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}))||[]}))}}},T=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 E=t(null);function D({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(),b=a(()=>new T({storefrontAccessToken:n,shopDomain:r,apiVersion:f}),[n,r,f]),x=a(()=>{let e=new w({locale:l,currency:u,market:d,methods:m},b);return g&&e.setCustomerAccessToken(g),e},[]),S=a(()=>new y(_,b,v.revalidate),[]),C=o(null);i(()=>{_.then(e=>{e&&e!==C.current&&(S.updateCartData(e),S.notifyListeners(),C.current=e)})},[_,S]);let D=o([]),O=o([]);i(()=>{if(typeof window>`u`)return;window.__PLY_HYDROGEN_CONFIG__={cart:S,adapter:x,onCartAdd:e=>(D.current.push(e),()=>{let t=D.current.indexOf(e);t>-1&&D.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 D.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(E.Provider,{value:k},h)}function O(){let e=r(E);if(!e)throw Error(`usePersonizely must be used within a PersonizelyProvider. Make sure your component is wrapped with <PersonizelyProvider>.`);return e}function k(){let e=O();return n(async t=>typeof window>`u`?!1:await e.triggerCartAdd({...t,id:_(String(t.id)),variantId:_(String(t.variantId)),price:Number(t.price)*100}),[e])}function A(){let e=O();return n(async()=>typeof window>`u`?!1:await e.triggerCheckout(),[e])}function j(e){O().adapter.setPageContext(e)}export{w as Adapter,y as Cart,D as PersonizelyProvider,k as useCartAdd,A as useCheckout,j as usePageContext,O as usePersonizely};
|
|
250
|
+
${x}
|
|
251
|
+
`;var T=class{constructor(e,t){this.customer=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}}setCustomer(e){this.customer=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)}getCustomer(){return this.customer}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,customer: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(()=>new T({locale:l,currency:u,market:d,methods:m},y),[]);i(()=>{g&&x.setCustomer(g)},[g,x]);let 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};
|
|
264
252
|
//# sourceMappingURL=index.mjs.map
|