@rebuy/rebuy 1.6.0-alpha.2 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +131 -0
- package/dist/api.js.map +7 -0
- package/dist/api.mjs +111 -0
- package/dist/api.mjs.map +7 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +145 -0
- package/dist/client.js.map +7 -0
- package/dist/client.mjs +115 -0
- package/dist/client.mjs.map +7 -0
- package/dist/cookie.js +139 -0
- package/dist/cookie.js.map +7 -0
- package/dist/cookie.mjs +119 -0
- package/dist/cookie.mjs.map +7 -0
- package/dist/geolocation.d.ts +2 -0
- package/dist/geolocation.d.ts.map +1 -1
- package/dist/geolocation.js +79 -0
- package/dist/geolocation.js.map +7 -0
- package/dist/geolocation.mjs +49 -0
- package/dist/geolocation.mjs.map +7 -0
- package/dist/identity.d.ts +4 -3
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +86 -0
- package/dist/identity.js.map +7 -0
- package/dist/identity.mjs +56 -0
- package/dist/identity.mjs.map +7 -0
- package/dist/index.js +8 -773
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +7 -766
- package/dist/index.mjs.map +4 -4
- package/dist/session.js +72 -0
- package/dist/session.js.map +7 -0
- package/dist/session.mjs +42 -0
- package/dist/session.mjs.map +7 -0
- package/dist/utilities.js +321 -0
- package/dist/utilities.js.map +7 -0
- package/dist/utilities.mjs +301 -0
- package/dist/utilities.mjs.map +7 -0
- package/package.json +14 -1
package/dist/index.js
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,776 +11,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
11
|
}
|
|
16
12
|
return to;
|
|
17
13
|
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
16
|
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Api: () => Api,
|
|
24
|
-
Geolocation: () => Geolocation,
|
|
25
|
-
Identity: () => Identity,
|
|
26
|
-
RebuyClient: () => RebuyClient,
|
|
27
|
-
Session: () => Session,
|
|
28
|
-
amountToCents: () => amountToCents,
|
|
29
|
-
convertProductToStorefrontFormat: () => convertProductToStorefrontFormat,
|
|
30
|
-
convertToNodes: () => convertToNodes,
|
|
31
|
-
convertVariantToStorefrontFormat: () => convertVariantToStorefrontFormat,
|
|
32
|
-
dataToString: () => dataToString,
|
|
33
|
-
destroy: () => destroy,
|
|
34
|
-
enabled: () => enabled,
|
|
35
|
-
find: () => find,
|
|
36
|
-
firstAvailableVariant: () => firstAvailableVariant,
|
|
37
|
-
get: () => get,
|
|
38
|
-
getAll: () => getAll,
|
|
39
|
-
getIdFromGraphUrl: () => getIdFromGraphUrl,
|
|
40
|
-
isBase64Encoded: () => isBase64Encoded,
|
|
41
|
-
productImageObject: () => productImageObject,
|
|
42
|
-
queryStringToObject: () => queryStringToObject,
|
|
43
|
-
selectedVariantOptions: () => selectedVariantOptions,
|
|
44
|
-
serialize: () => serialize,
|
|
45
|
-
sessionId: () => sessionId,
|
|
46
|
-
set: () => set,
|
|
47
|
-
stringToData: () => stringToData,
|
|
48
|
-
stripHtml: () => stripHtml,
|
|
49
|
-
utmObjectFromString: () => utmObjectFromString,
|
|
50
|
-
uuid: () => uuid,
|
|
51
|
-
variantAvailable: () => variantAvailable,
|
|
52
|
-
variantMinMaxPriceObject: () => variantMinMaxPriceObject,
|
|
53
|
-
variantPriceObject: () => variantPriceObject
|
|
54
|
-
});
|
|
55
17
|
module.exports = __toCommonJS(index_exports);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let response = data;
|
|
64
|
-
if (decode === true) {
|
|
65
|
-
response = atob(response);
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
response = JSON.parse(response);
|
|
69
|
-
} catch (e) {
|
|
70
|
-
response = data;
|
|
71
|
-
}
|
|
72
|
-
return response;
|
|
73
|
-
}
|
|
74
|
-
function dataToString(data, encode) {
|
|
75
|
-
let response = data;
|
|
76
|
-
if (typeof response != "string") {
|
|
77
|
-
response = JSON.stringify(response);
|
|
78
|
-
}
|
|
79
|
-
if (encode === true) {
|
|
80
|
-
response = btoa(response);
|
|
81
|
-
}
|
|
82
|
-
return response;
|
|
83
|
-
}
|
|
84
|
-
function stripHtml(str) {
|
|
85
|
-
return str?.replace(/<(.|\n)*?>/g, "") ?? "";
|
|
86
|
-
}
|
|
87
|
-
function getIdFromGraphUrl(graphId, objectType) {
|
|
88
|
-
let id = null;
|
|
89
|
-
const regex = new RegExp(`gid://shopify/${objectType}/(.*)`);
|
|
90
|
-
const matches = graphId.match(regex);
|
|
91
|
-
if (matches != null) {
|
|
92
|
-
const matchedId = matches[1];
|
|
93
|
-
if (!isNaN(Number(matchedId))) {
|
|
94
|
-
id = Number(matchedId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return id;
|
|
98
|
-
}
|
|
99
|
-
function variantAvailable(variant) {
|
|
100
|
-
return !(variant.inventory_management && variant.inventory_policy === "deny" && variant.inventory_quantity <= 0);
|
|
101
|
-
}
|
|
102
|
-
function firstAvailableVariant(product) {
|
|
103
|
-
let selectedVariant = product.variants[0];
|
|
104
|
-
for (let i = 0; i < product.variants.length; i++) {
|
|
105
|
-
if (variantAvailable(product.variants[i])) {
|
|
106
|
-
selectedVariant = product.variants[i];
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return selectedVariant;
|
|
111
|
-
}
|
|
112
|
-
function uuid() {
|
|
113
|
-
let d = (/* @__PURE__ */ new Date()).getTime();
|
|
114
|
-
let d2 = performance && performance.now && performance.now() * 1e3 || 0;
|
|
115
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
116
|
-
let r = Math.random() * 16;
|
|
117
|
-
if (d > 0) {
|
|
118
|
-
r = (d + r) % 16 | 0;
|
|
119
|
-
d = Math.floor(d / 16);
|
|
120
|
-
} else {
|
|
121
|
-
r = (d2 + r) % 16 | 0;
|
|
122
|
-
d2 = Math.floor(d2 / 16);
|
|
123
|
-
}
|
|
124
|
-
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
function sessionId() {
|
|
128
|
-
const config6 = {
|
|
129
|
-
chars: "0123456789",
|
|
130
|
-
length: 12
|
|
131
|
-
};
|
|
132
|
-
let sessionId2 = "";
|
|
133
|
-
const sessionStart = (/* @__PURE__ */ new Date()).getTime();
|
|
134
|
-
for (let i = config6.length; i > 0; i--) {
|
|
135
|
-
sessionId2 += config6.chars[Math.floor(Math.random() * config6.chars.length)];
|
|
136
|
-
}
|
|
137
|
-
return `REBUY.${sessionStart}.${sessionId2}`;
|
|
138
|
-
}
|
|
139
|
-
function convertProductToStorefrontFormat(product) {
|
|
140
|
-
const defaultVariant = firstAvailableVariant(product);
|
|
141
|
-
const minVariantPrice = variantMinMaxPriceObject(product, "price", "min");
|
|
142
|
-
const maxVariantPrice = variantMinMaxPriceObject(product, "price", "max");
|
|
143
|
-
const minVariantCompareAtPrice = variantMinMaxPriceObject(product, "compare_at_price", "min");
|
|
144
|
-
const maxVariantCompareAtPrice = variantMinMaxPriceObject(product, "compare_at_price", "max");
|
|
145
|
-
const selectedOptions = selectedVariantOptions(product, defaultVariant);
|
|
146
|
-
const variants = product.variants.map((variant) => convertVariantToStorefrontFormat(product, variant));
|
|
147
|
-
return {
|
|
148
|
-
collections: null,
|
|
149
|
-
compareAtPriceRange: {
|
|
150
|
-
maxVariantCompareAtPrice,
|
|
151
|
-
minVariantCompareAtPrice
|
|
152
|
-
},
|
|
153
|
-
description: stripHtml(product.body_html),
|
|
154
|
-
descriptionHtml: product.body_html,
|
|
155
|
-
featuredImage: productImageObject(product, null),
|
|
156
|
-
handle: product.handle,
|
|
157
|
-
id: `gid://shopify/Product/${product.id}`,
|
|
158
|
-
images: null,
|
|
159
|
-
media: [],
|
|
160
|
-
metafields: [],
|
|
161
|
-
options: [
|
|
162
|
-
...product.options.map((option) => {
|
|
163
|
-
return { name: option.name, values: option.values };
|
|
164
|
-
})
|
|
165
|
-
],
|
|
166
|
-
priceRange: {
|
|
167
|
-
maxVariantPrice,
|
|
168
|
-
minVariantPrice
|
|
169
|
-
},
|
|
170
|
-
selectedOptions,
|
|
171
|
-
selectedSellingPlan: null,
|
|
172
|
-
selectedSellingPlanAllocation: null,
|
|
173
|
-
sellingPlanGroups: [],
|
|
174
|
-
seo: { description: null, title: null },
|
|
175
|
-
title: product.title,
|
|
176
|
-
variants: convertToNodes(variants),
|
|
177
|
-
vendor: product.vendor
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function convertToNodes(arr) {
|
|
181
|
-
return {
|
|
182
|
-
edges: [
|
|
183
|
-
...arr.map((node) => {
|
|
184
|
-
return { node };
|
|
185
|
-
})
|
|
186
|
-
]
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function convertVariantToStorefrontFormat(product, variant) {
|
|
190
|
-
const selectedOptions = selectedVariantOptions(product, variant);
|
|
191
|
-
const image = productImageObject(product, variant.image_id);
|
|
192
|
-
return {
|
|
193
|
-
availableForSale: variantAvailable(variant),
|
|
194
|
-
compareAtPriceV2: variantPriceObject(variant, "compare_at_price"),
|
|
195
|
-
id: `gid://shopify/ProductVariant/${variant.id}`,
|
|
196
|
-
image,
|
|
197
|
-
priceV2: variantPriceObject(variant, "price"),
|
|
198
|
-
product: {
|
|
199
|
-
handle: product.handle,
|
|
200
|
-
id: product.id,
|
|
201
|
-
title: product.title,
|
|
202
|
-
vendor: product.vendor
|
|
203
|
-
},
|
|
204
|
-
selectedOptions: [selectedOptions],
|
|
205
|
-
sku: variant.sku,
|
|
206
|
-
title: variant.title
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function variantMinMaxPriceObject(product, key = "price", operator = "min") {
|
|
210
|
-
let priceObject = variantPriceObject(product.variants[0], key);
|
|
211
|
-
for (let i = 0; i < product.variants.length; i++) {
|
|
212
|
-
const variantPrice = variantPriceObject(product.variants[i], key);
|
|
213
|
-
if (variantPrice != null) {
|
|
214
|
-
const variantPriceAmount = Number(variantPrice.amount);
|
|
215
|
-
const currentPriceAmount = priceObject != null ? Number(priceObject.amount) : null;
|
|
216
|
-
if (currentPriceAmount == null || operator === "min" && variantPriceAmount < currentPriceAmount || operator === "max" && variantPriceAmount > currentPriceAmount) {
|
|
217
|
-
priceObject = variantPrice;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return priceObject;
|
|
222
|
-
}
|
|
223
|
-
function variantPriceObject(variant, key = "price") {
|
|
224
|
-
if (variant[key] != null) {
|
|
225
|
-
return {
|
|
226
|
-
amount: variant[key],
|
|
227
|
-
currencyCode: "USD"
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
function selectedVariantOptions(product, variant) {
|
|
233
|
-
const selectedOptions = {};
|
|
234
|
-
if (variant.option1 != null) {
|
|
235
|
-
selectedOptions[product.options[0].name] = variant.option1;
|
|
236
|
-
}
|
|
237
|
-
if (variant.option2 != null) {
|
|
238
|
-
selectedOptions[product.options[1].name] = variant.option2;
|
|
239
|
-
}
|
|
240
|
-
if (variant.option3 != null) {
|
|
241
|
-
selectedOptions[product.options[2].name] = variant.option3;
|
|
242
|
-
}
|
|
243
|
-
return selectedOptions;
|
|
244
|
-
}
|
|
245
|
-
function productImageObject(product, id) {
|
|
246
|
-
let image = null;
|
|
247
|
-
if (product.image) {
|
|
248
|
-
image = {
|
|
249
|
-
altText: product.image.alt,
|
|
250
|
-
height: product.image.height,
|
|
251
|
-
id: `gid://shopify/ProductImage/${product.image.id}`,
|
|
252
|
-
url: product.image.src,
|
|
253
|
-
width: product.image.width
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
if (product.images && product.images.length > 0 && id != null) {
|
|
257
|
-
const matchingImage = product.images.find((i) => i.id === id);
|
|
258
|
-
if (matchingImage) {
|
|
259
|
-
image = {
|
|
260
|
-
altText: matchingImage.alt,
|
|
261
|
-
height: matchingImage.height,
|
|
262
|
-
id: `gid://shopify/ProductImage/${matchingImage.id}`,
|
|
263
|
-
url: matchingImage.src,
|
|
264
|
-
width: matchingImage.width
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return image;
|
|
269
|
-
}
|
|
270
|
-
function queryStringToObject(str) {
|
|
271
|
-
const params = new URLSearchParams(str);
|
|
272
|
-
return Object.fromEntries(params.entries());
|
|
273
|
-
}
|
|
274
|
-
function utmObjectFromString(str) {
|
|
275
|
-
const utmKeys = ["utm_campaign", "utm_medium", "utm_source", "utm_term", "utm_content"];
|
|
276
|
-
const matches = {};
|
|
277
|
-
const url = new URL(str);
|
|
278
|
-
const queryObject = queryStringToObject(url.search);
|
|
279
|
-
for (const [key, value] of Object.entries(queryObject)) {
|
|
280
|
-
if (utmKeys.includes(key)) {
|
|
281
|
-
matches[key] = value;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return Object.keys(matches).length > 0 ? matches : null;
|
|
285
|
-
}
|
|
286
|
-
function amountToCents(amount) {
|
|
287
|
-
let normalizedAmount = 0;
|
|
288
|
-
if (typeof amount === "string") {
|
|
289
|
-
if (amount.indexOf(".") !== -1) {
|
|
290
|
-
normalizedAmount = Math.round(parseFloat(amount) * 100);
|
|
291
|
-
} else {
|
|
292
|
-
normalizedAmount = parseInt(amount, 10);
|
|
293
|
-
}
|
|
294
|
-
} else if (typeof amount === "number") {
|
|
295
|
-
normalizedAmount = Math.round(amount * 100);
|
|
296
|
-
}
|
|
297
|
-
if (isNaN(normalizedAmount)) {
|
|
298
|
-
normalizedAmount = 0;
|
|
299
|
-
}
|
|
300
|
-
return normalizedAmount;
|
|
301
|
-
}
|
|
302
|
-
function serialize(obj) {
|
|
303
|
-
const serialized = [];
|
|
304
|
-
const add = (key, value) => {
|
|
305
|
-
value = typeof value === "function" ? value() : value;
|
|
306
|
-
value = value === null ? "" : value === void 0 ? "" : value;
|
|
307
|
-
serialized[serialized.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
|
308
|
-
};
|
|
309
|
-
const buildParameters = (prefix, obj2) => {
|
|
310
|
-
let i, key, len;
|
|
311
|
-
if (prefix) {
|
|
312
|
-
if (Array.isArray(obj2)) {
|
|
313
|
-
for (i = 0, len = obj2.length; i < len; i++) {
|
|
314
|
-
buildParameters(prefix + "[" + (typeof obj2[i] === "object" && obj2[i] ? i : "") + "]", obj2[i]);
|
|
315
|
-
}
|
|
316
|
-
} else if (Object.prototype.toString.call(obj2) === "[object Object]") {
|
|
317
|
-
for (key in obj2) {
|
|
318
|
-
buildParameters(prefix + "[" + key + "]", obj2[key]);
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
add(prefix, obj2);
|
|
322
|
-
}
|
|
323
|
-
} else if (Array.isArray(obj2)) {
|
|
324
|
-
for (i = 0, len = obj2.length; i < len; i++) {
|
|
325
|
-
add(obj2[i].name, obj2[i].value);
|
|
326
|
-
}
|
|
327
|
-
} else {
|
|
328
|
-
for (key in obj2) {
|
|
329
|
-
buildParameters(key, obj2[key]);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return serialized;
|
|
333
|
-
};
|
|
334
|
-
return buildParameters("", obj).join("&");
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// src/api.ts
|
|
338
|
-
var config = {
|
|
339
|
-
/**
|
|
340
|
-
* @deprecated
|
|
341
|
-
*/
|
|
342
|
-
cdnDomain: "https://cdn.rebuyengine.com",
|
|
343
|
-
domain: "https://rebuyengine.com",
|
|
344
|
-
eventDomain: "https://rebuyengine.com",
|
|
345
|
-
geoDomain: "https://geo.rebuyengine.com",
|
|
346
|
-
key: null,
|
|
347
|
-
shieldDomain: "https://cached.rebuyengine.com",
|
|
348
|
-
shop: null,
|
|
349
|
-
staticDomain: "https://cdn.rebuyengine.com"
|
|
350
|
-
};
|
|
351
|
-
var staging = {
|
|
352
|
-
/**
|
|
353
|
-
* @deprecated
|
|
354
|
-
*/
|
|
355
|
-
cdnDomain: "https://cdn.enigneyuber.com",
|
|
356
|
-
domain: "https://enigneyuber.com",
|
|
357
|
-
eventDomain: "https://enigneyuber.com",
|
|
358
|
-
geoDomain: "https://geo.enigneyuber.com",
|
|
359
|
-
shieldDomain: "https://cached.enigneyuber.com",
|
|
360
|
-
staticDomain: "https://cdn.enigneyuber.com"
|
|
361
|
-
};
|
|
362
|
-
var stagingDomains = [
|
|
363
|
-
"enigneyuber.com",
|
|
364
|
-
"rebuy-engine-regression.myshopify.com",
|
|
365
|
-
"rebuy-stage-currency-test.myshopify.com",
|
|
366
|
-
"rebuy-staging-automation.myshopify.com",
|
|
367
|
-
"rebuy-staging-regression.myshopify.com",
|
|
368
|
-
"rebuy-uat.myshopify.com",
|
|
369
|
-
"rebuy-regression-qa.myshopify.com",
|
|
370
|
-
"senator-staging.myshopify.com",
|
|
371
|
-
"mike-reids-test-store.myshopify.com",
|
|
372
|
-
"dash-ext-hoke.myshopify.com"
|
|
373
|
-
];
|
|
374
|
-
var makeCall = async (method, path, data, origin, options = {}) => {
|
|
375
|
-
const url = `${origin}${path}`;
|
|
376
|
-
const requestUrl = new URL(url);
|
|
377
|
-
const fetchOptions = options?.fetch ?? {};
|
|
378
|
-
const requestData = {};
|
|
379
|
-
if (typeof data == "object" && data != null) {
|
|
380
|
-
Object.assign(requestData, data);
|
|
381
|
-
}
|
|
382
|
-
if (typeof config.key == "string" && config.key.length > 0) {
|
|
383
|
-
Object.assign(requestData, { key: config.key });
|
|
384
|
-
}
|
|
385
|
-
const requestObject = {
|
|
386
|
-
method,
|
|
387
|
-
...fetchOptions
|
|
388
|
-
};
|
|
389
|
-
if (method === "GET") {
|
|
390
|
-
requestUrl.search = serialize(requestData);
|
|
391
|
-
} else if (method === "POST") {
|
|
392
|
-
requestObject.headers = {
|
|
393
|
-
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
|
|
394
|
-
};
|
|
395
|
-
requestObject.body = new URLSearchParams(requestData);
|
|
396
|
-
}
|
|
397
|
-
const request = await fetch(requestUrl.toString(), requestObject);
|
|
398
|
-
const response = await request.json();
|
|
399
|
-
if (!request.ok && fetchOptions.strictErrors === true) {
|
|
400
|
-
const message = `An error has occurred: ${request.status}`;
|
|
401
|
-
throw new Error(message, { cause: response });
|
|
402
|
-
}
|
|
403
|
-
return response;
|
|
404
|
-
};
|
|
405
|
-
var Api = class {
|
|
406
|
-
constructor(options) {
|
|
407
|
-
if (typeof options == "string") {
|
|
408
|
-
config.key = options;
|
|
409
|
-
} else if (typeof options == "object" && options != null) {
|
|
410
|
-
Object.assign(config, options);
|
|
411
|
-
}
|
|
412
|
-
for (const domain of stagingDomains) {
|
|
413
|
-
if (typeof location === "object" && location?.host?.includes(domain)) {
|
|
414
|
-
Object.assign(config, staging);
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
if (typeof config.shop === "string" && config.shop.includes(domain)) {
|
|
418
|
-
Object.assign(config, staging);
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
async callEvent(method, path, data, options) {
|
|
424
|
-
return await makeCall(method, path, data, config.eventDomain, options);
|
|
425
|
-
}
|
|
426
|
-
async callShield(method, path, data, options) {
|
|
427
|
-
return await makeCall(method, path, data, config.shieldDomain, options);
|
|
428
|
-
}
|
|
429
|
-
async callStatic(method, path, data, options) {
|
|
430
|
-
return await makeCall(method, path, data, config.staticDomain, options);
|
|
431
|
-
}
|
|
432
|
-
async callGeo(method, path, data, options) {
|
|
433
|
-
return await makeCall(method, path, data, config.geoDomain, options);
|
|
434
|
-
}
|
|
435
|
-
async callCdn(method, path, data, options) {
|
|
436
|
-
return await makeCall(method, path, data, config.cdnDomain, options);
|
|
437
|
-
}
|
|
438
|
-
async callApi(method, path, data, options) {
|
|
439
|
-
return await makeCall(method, path, data, config.domain, options);
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
var api_default = Api;
|
|
443
|
-
|
|
444
|
-
// src/cookie.ts
|
|
445
|
-
function get(name) {
|
|
446
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
const cookie = document.cookie.match("(^|;) ?" + decodeURIComponent(name) + "=([^;]*)(;|$)");
|
|
450
|
-
let value = null;
|
|
451
|
-
if (cookie != null) {
|
|
452
|
-
const data = decodeURIComponent(cookie[2]);
|
|
453
|
-
const decode = isBase64Encoded(data) ? true : false;
|
|
454
|
-
value = stringToData(data, decode);
|
|
455
|
-
}
|
|
456
|
-
return value;
|
|
457
|
-
}
|
|
458
|
-
function getAll() {
|
|
459
|
-
const cookies = {};
|
|
460
|
-
if (document && document.cookie && document.cookie !== "") {
|
|
461
|
-
const split = document.cookie.split(";");
|
|
462
|
-
for (let i = 0; i < split.length; i++) {
|
|
463
|
-
const pairs = split[i].split("=");
|
|
464
|
-
pairs[0] = pairs[0].replace(/^ /, "");
|
|
465
|
-
const key = decodeURIComponent(pairs[0]);
|
|
466
|
-
const value = decodeURIComponent(pairs[1]);
|
|
467
|
-
const decode = isBase64Encoded(value) ? true : false;
|
|
468
|
-
cookies[key] = stringToData(value, decode);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return cookies;
|
|
472
|
-
}
|
|
473
|
-
function set(name, value, config6) {
|
|
474
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
const attributes = ["path", "domain", "maxAge", "expires", "secure", "sameSite"];
|
|
478
|
-
const convenienceTimes = ["seconds", "minutes", "hours", "days", "weeks", "months", "years"];
|
|
479
|
-
const cookieAttributes = {
|
|
480
|
-
path: "/"
|
|
481
|
-
};
|
|
482
|
-
if (typeof config6 != "undefined" && Number.isInteger(config6)) {
|
|
483
|
-
cookieAttributes["max-age"] = config6;
|
|
484
|
-
} else if (typeof config6 === "object" && config6 !== null) {
|
|
485
|
-
for (const key in config6) {
|
|
486
|
-
if (attributes.includes(key)) {
|
|
487
|
-
if (key === "maxAge") {
|
|
488
|
-
cookieAttributes["max-age"] = config6[key];
|
|
489
|
-
} else if (key === "sameSite") {
|
|
490
|
-
cookieAttributes["samesite"] = config6[key];
|
|
491
|
-
} else if (key === "expires") {
|
|
492
|
-
cookieAttributes[key] = new Date(config6[key]).toUTCString();
|
|
493
|
-
} else {
|
|
494
|
-
cookieAttributes[key] = config6[key];
|
|
495
|
-
}
|
|
496
|
-
} else if (convenienceTimes.includes(key)) {
|
|
497
|
-
let duration = config6[key];
|
|
498
|
-
if (key === "seconds") {
|
|
499
|
-
duration = duration * 1;
|
|
500
|
-
} else if (key === "minutes") {
|
|
501
|
-
duration = duration * 60;
|
|
502
|
-
} else if (key === "hours") {
|
|
503
|
-
duration = duration * 60 * 60;
|
|
504
|
-
} else if (key === "days") {
|
|
505
|
-
duration = duration * 60 * 60 * 24;
|
|
506
|
-
} else if (key === "weeks") {
|
|
507
|
-
duration = duration * 60 * 60 * 24 * 7;
|
|
508
|
-
} else if (key === "months") {
|
|
509
|
-
duration = duration * 60 * 60 * 24 * 30;
|
|
510
|
-
} else if (key === "years") {
|
|
511
|
-
duration = duration * 60 * 60 * 24 * 365;
|
|
512
|
-
}
|
|
513
|
-
cookieAttributes["max-age"] = duration;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
value = dataToString(value, config6?.encode);
|
|
518
|
-
let cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
|
|
519
|
-
for (const key in cookieAttributes) {
|
|
520
|
-
cookie += ";" + key + "=" + cookieAttributes[key];
|
|
521
|
-
}
|
|
522
|
-
document.cookie = cookie;
|
|
523
|
-
}
|
|
524
|
-
function find(name) {
|
|
525
|
-
const matches = [];
|
|
526
|
-
const cookies = getAll();
|
|
527
|
-
for (const key in cookies) {
|
|
528
|
-
if (key.includes(name)) {
|
|
529
|
-
matches.push({
|
|
530
|
-
name: key,
|
|
531
|
-
value: cookies[key]
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return matches;
|
|
536
|
-
}
|
|
537
|
-
function destroy(name) {
|
|
538
|
-
set(name, "", { encode: false, seconds: 0 });
|
|
539
|
-
}
|
|
540
|
-
function enabled() {
|
|
541
|
-
const test = {
|
|
542
|
-
key: "__cookie_test",
|
|
543
|
-
value: 1
|
|
544
|
-
};
|
|
545
|
-
set(test.key, test.value, { encode: false });
|
|
546
|
-
const enabled2 = get(test.key) === test.value ? true : false;
|
|
547
|
-
if (enabled2) {
|
|
548
|
-
destroy(test.key);
|
|
549
|
-
}
|
|
550
|
-
return enabled2;
|
|
551
|
-
}
|
|
552
|
-
var cookie_default = { destroy, enabled, find, get, getAll, set };
|
|
553
|
-
|
|
554
|
-
// src/geolocation.ts
|
|
555
|
-
var config2 = {
|
|
556
|
-
geolocation: null,
|
|
557
|
-
geolocationCookie: "_rebuyGeolocation",
|
|
558
|
-
geolocationDuration: {
|
|
559
|
-
minutes: 30
|
|
560
|
-
},
|
|
561
|
-
key: null
|
|
562
|
-
};
|
|
563
|
-
var getGeolocation = async () => {
|
|
564
|
-
const api = new api_default(config2.key);
|
|
565
|
-
const response = await api.callGeo("GET", "/", null);
|
|
566
|
-
if (response.data) {
|
|
567
|
-
config2.geolocation = response.data;
|
|
568
|
-
const cookieOptions = {
|
|
569
|
-
secure: true
|
|
570
|
-
};
|
|
571
|
-
Object.assign(cookieOptions, config2.geolocationDuration);
|
|
572
|
-
cookie_default.set(config2.geolocationCookie, config2.geolocation, { ...cookieOptions, encode: false });
|
|
573
|
-
}
|
|
574
|
-
return config2.geolocation;
|
|
575
|
-
};
|
|
576
|
-
var Geolocation = class {
|
|
577
|
-
constructor(key) {
|
|
578
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
if (typeof key == "string") {
|
|
582
|
-
config2.key = key;
|
|
583
|
-
}
|
|
584
|
-
config2.geolocation = cookie_default.get(config2.geolocationCookie);
|
|
585
|
-
if (config2.geolocation === null) {
|
|
586
|
-
getGeolocation();
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
async geolocation() {
|
|
590
|
-
if (config2.geolocation == null) {
|
|
591
|
-
await getGeolocation();
|
|
592
|
-
}
|
|
593
|
-
return config2.geolocation;
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
var geolocation_default = Geolocation;
|
|
597
|
-
|
|
598
|
-
// src/session.ts
|
|
599
|
-
var config3 = {
|
|
600
|
-
now: null,
|
|
601
|
-
sessionDuration: {
|
|
602
|
-
minutes: 30
|
|
603
|
-
},
|
|
604
|
-
sessionId: null,
|
|
605
|
-
sessionIdCookie: "_rebuySessionId"
|
|
606
|
-
};
|
|
607
|
-
var Session = class {
|
|
608
|
-
constructor() {
|
|
609
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
config3.now = (/* @__PURE__ */ new Date()).getTime();
|
|
613
|
-
config3.sessionId = cookie_default.get(config3.sessionIdCookie);
|
|
614
|
-
if (config3.sessionId === null) {
|
|
615
|
-
config3.sessionId = sessionId();
|
|
616
|
-
}
|
|
617
|
-
const cookieOptions = {
|
|
618
|
-
secure: true
|
|
619
|
-
};
|
|
620
|
-
Object.assign(cookieOptions, config3.sessionDuration);
|
|
621
|
-
cookie_default.set(config3.sessionIdCookie, config3.sessionId, cookieOptions);
|
|
622
|
-
}
|
|
623
|
-
sessionId() {
|
|
624
|
-
return config3.sessionId;
|
|
625
|
-
}
|
|
626
|
-
sessionStart() {
|
|
627
|
-
return config3.sessionId ? Number(config3.sessionId.split(".")[1]) : 0;
|
|
628
|
-
}
|
|
629
|
-
sessionDuration() {
|
|
630
|
-
return config3.now !== null ? parseInt(((config3.now - this.sessionStart()) / 1e3 / 60).toString()) : 0;
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
var session_default = Session;
|
|
634
|
-
|
|
635
|
-
// src/identity.ts
|
|
636
|
-
var config4 = {
|
|
637
|
-
key: null,
|
|
638
|
-
session: null,
|
|
639
|
-
visitorDuration: {
|
|
640
|
-
years: 1
|
|
641
|
-
},
|
|
642
|
-
visitorId: null,
|
|
643
|
-
visitorIdCookie: "_rebuyVisitorId"
|
|
644
|
-
};
|
|
645
|
-
var Identity = class {
|
|
646
|
-
constructor(key) {
|
|
647
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
if (typeof key == "string") {
|
|
651
|
-
config4.key = key;
|
|
652
|
-
}
|
|
653
|
-
config4.visitorId = cookie_default.get(config4.visitorIdCookie);
|
|
654
|
-
if (config4.visitorId === null) {
|
|
655
|
-
config4.visitorId = uuid();
|
|
656
|
-
}
|
|
657
|
-
const cookieOptions = {
|
|
658
|
-
secure: true
|
|
659
|
-
};
|
|
660
|
-
Object.assign(cookieOptions, config4.visitorDuration);
|
|
661
|
-
cookie_default.set(config4.visitorIdCookie, config4.visitorId, cookieOptions);
|
|
662
|
-
config4.session = new session_default();
|
|
663
|
-
config4.geolocation = new geolocation_default(config4.key);
|
|
664
|
-
}
|
|
665
|
-
visitorId() {
|
|
666
|
-
return config4.visitorId;
|
|
667
|
-
}
|
|
668
|
-
sessionId() {
|
|
669
|
-
return config4.session.sessionId();
|
|
670
|
-
}
|
|
671
|
-
sessionStart() {
|
|
672
|
-
return config4.session.sessionStart();
|
|
673
|
-
}
|
|
674
|
-
sessionDuration() {
|
|
675
|
-
return config4.session.sessionDuration();
|
|
676
|
-
}
|
|
677
|
-
async geolocation() {
|
|
678
|
-
return await config4.geolocation.geolocation();
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
var identity_default = Identity;
|
|
682
|
-
|
|
683
|
-
// src/client.ts
|
|
684
|
-
var config5 = {
|
|
685
|
-
api: null,
|
|
686
|
-
contextParameters: null,
|
|
687
|
-
defaultParameters: null,
|
|
688
|
-
identity: null,
|
|
689
|
-
key: null,
|
|
690
|
-
shop: null
|
|
691
|
-
};
|
|
692
|
-
var trackEvent = async (eventData) => {
|
|
693
|
-
if (config5.identity && config5.identity.visitorId()) {
|
|
694
|
-
eventData.uuid = config5.identity.visitorId();
|
|
695
|
-
}
|
|
696
|
-
return await config5.api.callEvent("POST", "/api/v1/analytics/event", eventData);
|
|
697
|
-
};
|
|
698
|
-
var makeShieldCall = async (endpoint, params, format, options = {}) => {
|
|
699
|
-
return await makeCall2(endpoint, params, format, { ...options, shield: true });
|
|
700
|
-
};
|
|
701
|
-
var makeStaticCall = async (endpoint, params, format, options = {}) => {
|
|
702
|
-
return await makeCall2(endpoint, params, format, { ...options, static: true });
|
|
703
|
-
};
|
|
704
|
-
var makeCDNCall = async (endpoint, params, format, options = {}) => {
|
|
705
|
-
return await makeCall2(endpoint, params, format, { ...options, cdn: true });
|
|
706
|
-
};
|
|
707
|
-
var makeCall2 = async (endpoint, params, format, options = {}) => {
|
|
708
|
-
const query = {};
|
|
709
|
-
if (config5.defaultParameters != null) {
|
|
710
|
-
Object.assign(query, config5.defaultParameters);
|
|
711
|
-
}
|
|
712
|
-
if (config5.contextParameters != null) {
|
|
713
|
-
Object.assign(query, config5.contextParameters);
|
|
714
|
-
}
|
|
715
|
-
if (typeof params == "object" && params != null) {
|
|
716
|
-
Object.assign(query, params);
|
|
717
|
-
}
|
|
718
|
-
if (typeof options != "object" || options == null) {
|
|
719
|
-
console.warn("Unsupported fetch options provided.", options);
|
|
720
|
-
options = {};
|
|
721
|
-
}
|
|
722
|
-
if (config5.identity && config5.identity.visitorId()) {
|
|
723
|
-
query.uuid = config5.identity.visitorId();
|
|
724
|
-
}
|
|
725
|
-
const source = options.cdn ? "callCdn" : options.shield ? "callShield" : options.static ? "callStatic" : "callApi";
|
|
726
|
-
const response = await config5.api[source]("GET", endpoint, query, options);
|
|
727
|
-
if (response.data && format === "storefront") {
|
|
728
|
-
for (let i = 0; i < response.data.length; i++) {
|
|
729
|
-
response.data[i] = convertProductToStorefrontFormat(response.data[i]);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
return response;
|
|
733
|
-
};
|
|
734
|
-
var RebuyClient = class {
|
|
735
|
-
constructor(key, defaultParameters, shop) {
|
|
736
|
-
if (typeof key == "string") {
|
|
737
|
-
config5.key = key;
|
|
738
|
-
}
|
|
739
|
-
if (typeof defaultParameters == "object" && defaultParameters != null) {
|
|
740
|
-
config5.defaultParameters = defaultParameters;
|
|
741
|
-
}
|
|
742
|
-
if (typeof shop == "string" && shop.endsWith(".myshopify.com")) {
|
|
743
|
-
config5.shop = shop;
|
|
744
|
-
}
|
|
745
|
-
config5.api = new api_default({ key: config5.key, shop: config5.shop });
|
|
746
|
-
config5.identity = new identity_default(config5.key);
|
|
747
|
-
}
|
|
748
|
-
setDefaultParameters(defaultParameters) {
|
|
749
|
-
if (typeof defaultParameters == "object" && defaultParameters != null) {
|
|
750
|
-
config5.defaultParameters = defaultParameters;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
setContextParameters(contextParameters) {
|
|
754
|
-
if (typeof contextParameters == "object" && contextParameters != null) {
|
|
755
|
-
config5.contextParameters = contextParameters;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
async getData(endpoint, params, options = {}) {
|
|
759
|
-
return await makeCall2(endpoint, params, null, options);
|
|
760
|
-
}
|
|
761
|
-
async getDataFromCDN(endpoint, params, options = {}) {
|
|
762
|
-
return await makeCDNCall(endpoint, params, null, options);
|
|
763
|
-
}
|
|
764
|
-
async getShieldedAsset(endpoint, params, options = {}) {
|
|
765
|
-
return await makeShieldCall(endpoint, params, null, options);
|
|
766
|
-
}
|
|
767
|
-
async getStaticAsset(endpoint, params, options = {}) {
|
|
768
|
-
return await makeStaticCall(endpoint, params, null, options);
|
|
769
|
-
}
|
|
770
|
-
async getStorefrontData(endpoint, params, options = {}) {
|
|
771
|
-
return await makeCall2(endpoint, params, "storefront", options);
|
|
772
|
-
}
|
|
773
|
-
async trackProductViewed(data) {
|
|
774
|
-
const requiredKeys = ["shopify_product_id", "shopify_product_handle"];
|
|
775
|
-
const defaultData = {
|
|
776
|
-
noun: "product",
|
|
777
|
-
subject: "user",
|
|
778
|
-
verb: "viewed"
|
|
779
|
-
};
|
|
780
|
-
if (typeof data != "undefined" && data != null) {
|
|
781
|
-
const dataKeys = Object.keys(data);
|
|
782
|
-
if (dataKeys.some((key) => requiredKeys.includes(key))) {
|
|
783
|
-
const payload = Object.assign(data, defaultData);
|
|
784
|
-
return await trackEvent(payload);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return null;
|
|
788
|
-
}
|
|
789
|
-
};
|
|
18
|
+
__reExport(index_exports, require("./api"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./client"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./cookie"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./geolocation"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./identity"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./session"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./utilities"), module.exports);
|
|
790
25
|
//# sourceMappingURL=index.js.map
|