@shopify/hydrogen 2024.4.3 → 2024.4.4
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/development/index.cjs +92 -82
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +92 -81
- package/dist/development/index.js.map +1 -1
- package/dist/production/index.cjs +72 -74
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.d.cts +1 -1
- package/dist/production/index.d.ts +1 -1
- package/dist/production/index.js +31 -32
- package/dist/production/index.js.map +1 -1
- package/dist/vite/plugin.js +1 -5
- package/package.json +1 -2
|
@@ -5,7 +5,6 @@ import { useMatches, useLocation, useNavigation, Link, useNavigate, useFetcher,
|
|
|
5
5
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
6
6
|
import { parse, stringify } from 'worktop/cookie';
|
|
7
7
|
import cspBuilder from 'content-security-policy-builder';
|
|
8
|
-
import invariant from 'tiny-invariant';
|
|
9
8
|
|
|
10
9
|
// src/storefront.ts
|
|
11
10
|
|
|
@@ -391,7 +390,7 @@ async function fetchWithServerCache(url, requestInit, {
|
|
|
391
390
|
}
|
|
392
391
|
|
|
393
392
|
// src/version.ts
|
|
394
|
-
var LIB_VERSION = "2024.4.
|
|
393
|
+
var LIB_VERSION = "2024.4.4";
|
|
395
394
|
|
|
396
395
|
// src/constants.ts
|
|
397
396
|
var STOREFRONT_REQUEST_GROUP_ID_HEADER = "Custom-Storefront-Request-Group-ID";
|
|
@@ -422,6 +421,13 @@ var warnOnce = (string) => {
|
|
|
422
421
|
warnings.add(string);
|
|
423
422
|
}
|
|
424
423
|
};
|
|
424
|
+
var errors = /* @__PURE__ */ new Set();
|
|
425
|
+
var errorOnce = (string) => {
|
|
426
|
+
if (!errors.has(string)) {
|
|
427
|
+
console.error(new Error(string));
|
|
428
|
+
errors.add(string);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
425
431
|
|
|
426
432
|
// src/utils/graphql.ts
|
|
427
433
|
function minifyQuery(string) {
|
|
@@ -538,19 +544,19 @@ var GraphQLError = class extends Error {
|
|
|
538
544
|
function throwErrorWithGqlLink({
|
|
539
545
|
url,
|
|
540
546
|
response,
|
|
541
|
-
errors,
|
|
547
|
+
errors: errors2,
|
|
542
548
|
type,
|
|
543
549
|
query,
|
|
544
550
|
queryVariables,
|
|
545
551
|
ErrorConstructor = Error,
|
|
546
552
|
client = "storefront"
|
|
547
553
|
}) {
|
|
548
|
-
const errorMessage = (typeof
|
|
554
|
+
const errorMessage = (typeof errors2 === "string" ? errors2 : errors2?.map?.((error) => error.message).join("\n")) || `URL: ${url}
|
|
549
555
|
API response error: ${response.status}`;
|
|
550
556
|
const gqlError = new GraphQLError(errorMessage, {
|
|
551
557
|
query,
|
|
552
558
|
queryVariables,
|
|
553
|
-
cause: { errors },
|
|
559
|
+
cause: { errors: errors2 },
|
|
554
560
|
clientOperation: `${client}.${type}`,
|
|
555
561
|
requestId: response.headers.get("x-request-id")
|
|
556
562
|
});
|
|
@@ -712,16 +718,16 @@ function createStorefrontClient(options) {
|
|
|
712
718
|
errors: void 0
|
|
713
719
|
};
|
|
714
720
|
if (!response.ok) {
|
|
715
|
-
let
|
|
721
|
+
let errors3;
|
|
716
722
|
try {
|
|
717
|
-
|
|
723
|
+
errors3 = parseJSON(body);
|
|
718
724
|
} catch (_e) {
|
|
719
|
-
|
|
725
|
+
errors3 = [{ message: body }];
|
|
720
726
|
}
|
|
721
|
-
throwErrorWithGqlLink({ ...errorOptions, errors:
|
|
727
|
+
throwErrorWithGqlLink({ ...errorOptions, errors: errors3 });
|
|
722
728
|
}
|
|
723
|
-
const { data, errors } = body;
|
|
724
|
-
const gqlErrors =
|
|
729
|
+
const { data, errors: errors2 } = body;
|
|
730
|
+
const gqlErrors = errors2?.map(
|
|
725
731
|
({ message, ...rest }) => new GraphQLError(message, {
|
|
726
732
|
...rest,
|
|
727
733
|
clientOperation: `storefront.${errorOptions.type}`,
|
|
@@ -808,10 +814,10 @@ var getStackOffset = (query) => {
|
|
|
808
814
|
}
|
|
809
815
|
return stackOffset;
|
|
810
816
|
} ;
|
|
811
|
-
function formatAPIResult(data,
|
|
817
|
+
function formatAPIResult(data, errors2) {
|
|
812
818
|
return {
|
|
813
819
|
...data,
|
|
814
|
-
...
|
|
820
|
+
...errors2 && { errors: errors2 }
|
|
815
821
|
};
|
|
816
822
|
}
|
|
817
823
|
|
|
@@ -2552,18 +2558,18 @@ function createCustomerAccountClient({
|
|
|
2552
2558
|
}
|
|
2553
2559
|
throw authFailResponse;
|
|
2554
2560
|
}
|
|
2555
|
-
let
|
|
2561
|
+
let errors2;
|
|
2556
2562
|
try {
|
|
2557
|
-
|
|
2563
|
+
errors2 = parseJSON(body);
|
|
2558
2564
|
} catch (_e) {
|
|
2559
|
-
|
|
2565
|
+
errors2 = [{ message: body }];
|
|
2560
2566
|
}
|
|
2561
|
-
throwErrorWithGqlLink({ ...errorOptions, errors });
|
|
2567
|
+
throwErrorWithGqlLink({ ...errorOptions, errors: errors2 });
|
|
2562
2568
|
}
|
|
2563
2569
|
try {
|
|
2564
2570
|
const APIresponse = parseJSON(body);
|
|
2565
|
-
const { errors } = APIresponse;
|
|
2566
|
-
const gqlErrors =
|
|
2571
|
+
const { errors: errors2 } = APIresponse;
|
|
2572
|
+
const gqlErrors = errors2?.map(
|
|
2567
2573
|
({ message, ...rest }) => new GraphQLError(message, {
|
|
2568
2574
|
...rest,
|
|
2569
2575
|
clientOperation: `customerAccount.${errorOptions.type}`,
|
|
@@ -2572,7 +2578,7 @@ function createCustomerAccountClient({
|
|
|
2572
2578
|
query: query2
|
|
2573
2579
|
})
|
|
2574
2580
|
);
|
|
2575
|
-
return { ...APIresponse, ...
|
|
2581
|
+
return { ...APIresponse, ...errors2 && { errors: gqlErrors } };
|
|
2576
2582
|
} catch (e) {
|
|
2577
2583
|
throwErrorWithGqlLink({ ...errorOptions, errors: [{ message: body }] });
|
|
2578
2584
|
}
|
|
@@ -2943,7 +2949,7 @@ function cartCreateDefault(options) {
|
|
|
2943
2949
|
const buyer = options.customerAccount ? await options.customerAccount.UNSTABLE_getBuyer() : void 0;
|
|
2944
2950
|
const { cartId, ...restOfOptionalParams } = optionalParams || {};
|
|
2945
2951
|
const { buyerIdentity, ...restOfInput } = input;
|
|
2946
|
-
const { cartCreate, errors } = await options.storefront.mutate(CART_CREATE_MUTATION(options.cartFragment), {
|
|
2952
|
+
const { cartCreate, errors: errors2 } = await options.storefront.mutate(CART_CREATE_MUTATION(options.cartFragment), {
|
|
2947
2953
|
variables: {
|
|
2948
2954
|
input: {
|
|
2949
2955
|
...restOfInput,
|
|
@@ -2955,7 +2961,7 @@ function cartCreateDefault(options) {
|
|
|
2955
2961
|
...restOfOptionalParams
|
|
2956
2962
|
}
|
|
2957
2963
|
});
|
|
2958
|
-
return formatAPIResult(cartCreate,
|
|
2964
|
+
return formatAPIResult(cartCreate, errors2);
|
|
2959
2965
|
};
|
|
2960
2966
|
}
|
|
2961
2967
|
var CART_CREATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -2989,7 +2995,7 @@ function cartGetDefault({
|
|
|
2989
2995
|
const cartId = getCartId();
|
|
2990
2996
|
if (!cartId)
|
|
2991
2997
|
return null;
|
|
2992
|
-
const [isCustomerLoggedIn, { cart, errors }] = await Promise.all([
|
|
2998
|
+
const [isCustomerLoggedIn, { cart, errors: errors2 }] = await Promise.all([
|
|
2993
2999
|
customerAccount ? customerAccount.isLoggedIn() : false,
|
|
2994
3000
|
storefront.query(CART_QUERY(cartFragment), {
|
|
2995
3001
|
variables: {
|
|
@@ -3001,7 +3007,7 @@ function cartGetDefault({
|
|
|
3001
3007
|
]);
|
|
3002
3008
|
return formatAPIResult(
|
|
3003
3009
|
addCustomerLoggedInParam(isCustomerLoggedIn, cart),
|
|
3004
|
-
|
|
3010
|
+
errors2
|
|
3005
3011
|
);
|
|
3006
3012
|
};
|
|
3007
3013
|
}
|
|
@@ -3140,14 +3146,14 @@ var DEFAULT_CART_FRAGMENT = `#graphql
|
|
|
3140
3146
|
// src/cart/queries/cartLinesAddDefault.ts
|
|
3141
3147
|
function cartLinesAddDefault(options) {
|
|
3142
3148
|
return async (lines, optionalParams) => {
|
|
3143
|
-
const { cartLinesAdd, errors } = await options.storefront.mutate(CART_LINES_ADD_MUTATION(options.cartFragment), {
|
|
3149
|
+
const { cartLinesAdd, errors: errors2 } = await options.storefront.mutate(CART_LINES_ADD_MUTATION(options.cartFragment), {
|
|
3144
3150
|
variables: {
|
|
3145
3151
|
cartId: options.getCartId(),
|
|
3146
3152
|
lines,
|
|
3147
3153
|
...optionalParams
|
|
3148
3154
|
}
|
|
3149
3155
|
});
|
|
3150
|
-
return formatAPIResult(cartLinesAdd,
|
|
3156
|
+
return formatAPIResult(cartLinesAdd, errors2);
|
|
3151
3157
|
};
|
|
3152
3158
|
}
|
|
3153
3159
|
var CART_LINES_ADD_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3193,14 +3199,14 @@ function throwIfLinesAreOptimistic(type, lines) {
|
|
|
3193
3199
|
function cartLinesUpdateDefault(options) {
|
|
3194
3200
|
return async (lines, optionalParams) => {
|
|
3195
3201
|
throwIfLinesAreOptimistic("updateLines", lines);
|
|
3196
|
-
const { cartLinesUpdate, errors } = await options.storefront.mutate(CART_LINES_UPDATE_MUTATION(options.cartFragment), {
|
|
3202
|
+
const { cartLinesUpdate, errors: errors2 } = await options.storefront.mutate(CART_LINES_UPDATE_MUTATION(options.cartFragment), {
|
|
3197
3203
|
variables: {
|
|
3198
3204
|
cartId: options.getCartId(),
|
|
3199
3205
|
lines,
|
|
3200
3206
|
...optionalParams
|
|
3201
3207
|
}
|
|
3202
3208
|
});
|
|
3203
|
-
return formatAPIResult(cartLinesUpdate,
|
|
3209
|
+
return formatAPIResult(cartLinesUpdate, errors2);
|
|
3204
3210
|
};
|
|
3205
3211
|
}
|
|
3206
3212
|
var CART_LINES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3228,14 +3234,14 @@ var CART_LINES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#gra
|
|
|
3228
3234
|
function cartLinesRemoveDefault(options) {
|
|
3229
3235
|
return async (lineIds, optionalParams) => {
|
|
3230
3236
|
throwIfLinesAreOptimistic("removeLines", lineIds);
|
|
3231
|
-
const { cartLinesRemove, errors } = await options.storefront.mutate(CART_LINES_REMOVE_MUTATION(options.cartFragment), {
|
|
3237
|
+
const { cartLinesRemove, errors: errors2 } = await options.storefront.mutate(CART_LINES_REMOVE_MUTATION(options.cartFragment), {
|
|
3232
3238
|
variables: {
|
|
3233
3239
|
cartId: options.getCartId(),
|
|
3234
3240
|
lineIds,
|
|
3235
3241
|
...optionalParams
|
|
3236
3242
|
}
|
|
3237
3243
|
});
|
|
3238
|
-
return formatAPIResult(cartLinesRemove,
|
|
3244
|
+
return formatAPIResult(cartLinesRemove, errors2);
|
|
3239
3245
|
};
|
|
3240
3246
|
}
|
|
3241
3247
|
var CART_LINES_REMOVE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3265,14 +3271,14 @@ function cartDiscountCodesUpdateDefault(options) {
|
|
|
3265
3271
|
const uniqueCodes = discountCodes.filter((value, index, array) => {
|
|
3266
3272
|
return array.indexOf(value) === index;
|
|
3267
3273
|
});
|
|
3268
|
-
const { cartDiscountCodesUpdate, errors } = await options.storefront.mutate(CART_DISCOUNT_CODE_UPDATE_MUTATION(options.cartFragment), {
|
|
3274
|
+
const { cartDiscountCodesUpdate, errors: errors2 } = await options.storefront.mutate(CART_DISCOUNT_CODE_UPDATE_MUTATION(options.cartFragment), {
|
|
3269
3275
|
variables: {
|
|
3270
3276
|
cartId: options.getCartId(),
|
|
3271
3277
|
discountCodes: uniqueCodes,
|
|
3272
3278
|
...optionalParams
|
|
3273
3279
|
}
|
|
3274
3280
|
});
|
|
3275
|
-
return formatAPIResult(cartDiscountCodesUpdate,
|
|
3281
|
+
return formatAPIResult(cartDiscountCodesUpdate, errors2);
|
|
3276
3282
|
};
|
|
3277
3283
|
}
|
|
3278
3284
|
var CART_DISCOUNT_CODE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3304,7 +3310,7 @@ function cartBuyerIdentityUpdateDefault(options) {
|
|
|
3304
3310
|
});
|
|
3305
3311
|
}
|
|
3306
3312
|
const buyer = options.customerAccount ? await options.customerAccount.UNSTABLE_getBuyer() : void 0;
|
|
3307
|
-
const { cartBuyerIdentityUpdate, errors } = await options.storefront.mutate(CART_BUYER_IDENTITY_UPDATE_MUTATION(options.cartFragment), {
|
|
3313
|
+
const { cartBuyerIdentityUpdate, errors: errors2 } = await options.storefront.mutate(CART_BUYER_IDENTITY_UPDATE_MUTATION(options.cartFragment), {
|
|
3308
3314
|
variables: {
|
|
3309
3315
|
cartId: options.getCartId(),
|
|
3310
3316
|
buyerIdentity: {
|
|
@@ -3314,7 +3320,7 @@ function cartBuyerIdentityUpdateDefault(options) {
|
|
|
3314
3320
|
...optionalParams
|
|
3315
3321
|
}
|
|
3316
3322
|
});
|
|
3317
|
-
return formatAPIResult(cartBuyerIdentityUpdate,
|
|
3323
|
+
return formatAPIResult(cartBuyerIdentityUpdate, errors2);
|
|
3318
3324
|
};
|
|
3319
3325
|
}
|
|
3320
3326
|
var CART_BUYER_IDENTITY_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3340,14 +3346,14 @@ var CART_BUYER_IDENTITY_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT)
|
|
|
3340
3346
|
// src/cart/queries/cartNoteUpdateDefault.ts
|
|
3341
3347
|
function cartNoteUpdateDefault(options) {
|
|
3342
3348
|
return async (note, optionalParams) => {
|
|
3343
|
-
const { cartNoteUpdate, errors } = await options.storefront.mutate(CART_NOTE_UPDATE_MUTATION(options.cartFragment), {
|
|
3349
|
+
const { cartNoteUpdate, errors: errors2 } = await options.storefront.mutate(CART_NOTE_UPDATE_MUTATION(options.cartFragment), {
|
|
3344
3350
|
variables: {
|
|
3345
3351
|
cartId: options.getCartId(),
|
|
3346
3352
|
note,
|
|
3347
3353
|
...optionalParams
|
|
3348
3354
|
}
|
|
3349
3355
|
});
|
|
3350
|
-
return formatAPIResult(cartNoteUpdate,
|
|
3356
|
+
return formatAPIResult(cartNoteUpdate, errors2);
|
|
3351
3357
|
};
|
|
3352
3358
|
}
|
|
3353
3359
|
var CART_NOTE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3373,14 +3379,14 @@ var CART_NOTE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#grap
|
|
|
3373
3379
|
// src/cart/queries/cartSelectedDeliveryOptionsUpdateDefault.ts
|
|
3374
3380
|
function cartSelectedDeliveryOptionsUpdateDefault(options) {
|
|
3375
3381
|
return async (selectedDeliveryOptions, optionalParams) => {
|
|
3376
|
-
const { cartSelectedDeliveryOptionsUpdate, errors } = await options.storefront.mutate(CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION(options.cartFragment), {
|
|
3382
|
+
const { cartSelectedDeliveryOptionsUpdate, errors: errors2 } = await options.storefront.mutate(CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION(options.cartFragment), {
|
|
3377
3383
|
variables: {
|
|
3378
3384
|
cartId: options.getCartId(),
|
|
3379
3385
|
selectedDeliveryOptions,
|
|
3380
3386
|
...optionalParams
|
|
3381
3387
|
}
|
|
3382
3388
|
});
|
|
3383
|
-
return formatAPIResult(cartSelectedDeliveryOptionsUpdate,
|
|
3389
|
+
return formatAPIResult(cartSelectedDeliveryOptionsUpdate, errors2);
|
|
3384
3390
|
};
|
|
3385
3391
|
}
|
|
3386
3392
|
var CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3406,13 +3412,13 @@ var CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION = (cartFragment = MINIMAL_CAR
|
|
|
3406
3412
|
// src/cart/queries/cartAttributesUpdateDefault.ts
|
|
3407
3413
|
function cartAttributesUpdateDefault(options) {
|
|
3408
3414
|
return async (attributes, optionalParams) => {
|
|
3409
|
-
const { cartAttributesUpdate, errors } = await options.storefront.mutate(CART_ATTRIBUTES_UPDATE_MUTATION(options.cartFragment), {
|
|
3415
|
+
const { cartAttributesUpdate, errors: errors2 } = await options.storefront.mutate(CART_ATTRIBUTES_UPDATE_MUTATION(options.cartFragment), {
|
|
3410
3416
|
variables: {
|
|
3411
3417
|
cartId: optionalParams?.cartId || options.getCartId(),
|
|
3412
3418
|
attributes
|
|
3413
3419
|
}
|
|
3414
3420
|
});
|
|
3415
|
-
return formatAPIResult(cartAttributesUpdate,
|
|
3421
|
+
return formatAPIResult(cartAttributesUpdate, errors2);
|
|
3416
3422
|
};
|
|
3417
3423
|
}
|
|
3418
3424
|
var CART_ATTRIBUTES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3443,7 +3449,7 @@ function cartMetafieldsSetDefault(options) {
|
|
|
3443
3449
|
ownerId
|
|
3444
3450
|
})
|
|
3445
3451
|
);
|
|
3446
|
-
const { cartMetafieldsSet, errors } = await options.storefront.mutate(CART_METAFIELD_SET_MUTATION(), {
|
|
3452
|
+
const { cartMetafieldsSet, errors: errors2 } = await options.storefront.mutate(CART_METAFIELD_SET_MUTATION(), {
|
|
3447
3453
|
variables: { metafields: metafieldsWithOwnerId }
|
|
3448
3454
|
});
|
|
3449
3455
|
return formatAPIResult(
|
|
@@ -3453,7 +3459,7 @@ function cartMetafieldsSetDefault(options) {
|
|
|
3453
3459
|
},
|
|
3454
3460
|
...cartMetafieldsSet
|
|
3455
3461
|
},
|
|
3456
|
-
|
|
3462
|
+
errors2
|
|
3457
3463
|
);
|
|
3458
3464
|
};
|
|
3459
3465
|
}
|
|
@@ -3478,7 +3484,7 @@ var CART_METAFIELD_SET_MUTATION = () => `#graphql
|
|
|
3478
3484
|
function cartMetafieldDeleteDefault(options) {
|
|
3479
3485
|
return async (key, optionalParams) => {
|
|
3480
3486
|
const ownerId = optionalParams?.cartId || options.getCartId();
|
|
3481
|
-
const { cartMetafieldDelete, errors } = await options.storefront.mutate(CART_METAFIELD_DELETE_MUTATION(), {
|
|
3487
|
+
const { cartMetafieldDelete, errors: errors2 } = await options.storefront.mutate(CART_METAFIELD_DELETE_MUTATION(), {
|
|
3482
3488
|
variables: {
|
|
3483
3489
|
input: {
|
|
3484
3490
|
ownerId,
|
|
@@ -3493,7 +3499,7 @@ function cartMetafieldDeleteDefault(options) {
|
|
|
3493
3499
|
},
|
|
3494
3500
|
...cartMetafieldDelete
|
|
3495
3501
|
},
|
|
3496
|
-
|
|
3502
|
+
errors2
|
|
3497
3503
|
);
|
|
3498
3504
|
};
|
|
3499
3505
|
}
|
|
@@ -3915,11 +3921,20 @@ function ShopPayButton(props) {
|
|
|
3915
3921
|
function AnalyticsView(props) {
|
|
3916
3922
|
const { type, data = {}, customData } = props;
|
|
3917
3923
|
const location = useLocation();
|
|
3918
|
-
const {
|
|
3924
|
+
const {
|
|
3925
|
+
publish: publish2,
|
|
3926
|
+
cart,
|
|
3927
|
+
prevCart,
|
|
3928
|
+
shop,
|
|
3929
|
+
customData: analyticProviderCustomData
|
|
3930
|
+
} = useAnalytics();
|
|
3919
3931
|
const url = location.pathname + location.search;
|
|
3920
3932
|
let viewPayload2 = {
|
|
3921
3933
|
...data,
|
|
3922
|
-
customData
|
|
3934
|
+
customData: {
|
|
3935
|
+
...analyticProviderCustomData,
|
|
3936
|
+
...customData
|
|
3937
|
+
},
|
|
3923
3938
|
cart,
|
|
3924
3939
|
prevCart,
|
|
3925
3940
|
shop
|
|
@@ -4063,38 +4078,11 @@ function getCustomerPrivacyRequired() {
|
|
|
4063
4078
|
}
|
|
4064
4079
|
return customerPrivacy;
|
|
4065
4080
|
}
|
|
4066
|
-
function messageOnError(field) {
|
|
4067
|
-
return `[h2:error:Analytics.Provider] - ${field} is required`;
|
|
4068
|
-
}
|
|
4069
4081
|
function ShopifyAnalytics({
|
|
4070
4082
|
consent,
|
|
4071
4083
|
onReady,
|
|
4072
|
-
domain
|
|
4073
|
-
disableThrowOnError,
|
|
4074
|
-
isMockShop
|
|
4084
|
+
domain
|
|
4075
4085
|
}) {
|
|
4076
|
-
if (isMockShop) {
|
|
4077
|
-
warnOnce(
|
|
4078
|
-
"[h2:error:Analytics.Provider] - Mock shop is used. Analytics will not work properly."
|
|
4079
|
-
);
|
|
4080
|
-
} else {
|
|
4081
|
-
if (!consent.checkoutDomain) {
|
|
4082
|
-
const errorMsg = messageOnError("consent.checkoutDomain");
|
|
4083
|
-
if (disableThrowOnError) {
|
|
4084
|
-
console.error(errorMsg);
|
|
4085
|
-
} else {
|
|
4086
|
-
invariant(false, errorMsg);
|
|
4087
|
-
}
|
|
4088
|
-
}
|
|
4089
|
-
if (!consent.storefrontAccessToken) {
|
|
4090
|
-
const errorMsg = messageOnError("consent.storefrontAccessToken");
|
|
4091
|
-
if (disableThrowOnError) {
|
|
4092
|
-
console.error(errorMsg);
|
|
4093
|
-
} else {
|
|
4094
|
-
invariant(false, errorMsg);
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
}
|
|
4098
4086
|
const { subscribe: subscribe2, register: register2, canTrack } = useAnalytics();
|
|
4099
4087
|
const [shopifyReady, setShopifyReady] = useState(false);
|
|
4100
4088
|
const [privacyReady, setPrivacyReady] = useState(false);
|
|
@@ -4112,9 +4100,9 @@ function ShopifyAnalytics({
|
|
|
4112
4100
|
};
|
|
4113
4101
|
const { checkoutDomain, storefrontAccessToken, withPrivacyBanner } = consent;
|
|
4114
4102
|
useCustomerPrivacy({
|
|
4115
|
-
checkoutDomain:
|
|
4116
|
-
storefrontAccessToken:
|
|
4117
|
-
withPrivacyBanner
|
|
4103
|
+
checkoutDomain: !checkoutDomain ? "mock.shop" : checkoutDomain,
|
|
4104
|
+
storefrontAccessToken: !storefrontAccessToken ? "abcdefghijklmnopqrstuvwxyz123456" : storefrontAccessToken,
|
|
4105
|
+
withPrivacyBanner,
|
|
4118
4106
|
onVisitorConsentCollected: setCustomerPrivacyReady,
|
|
4119
4107
|
onReady: () => {
|
|
4120
4108
|
setTimeout(setCustomerPrivacyReady, 3e3);
|
|
@@ -4551,6 +4539,9 @@ function shopifyCanTrack() {
|
|
|
4551
4539
|
}
|
|
4552
4540
|
return false;
|
|
4553
4541
|
}
|
|
4542
|
+
function messageOnError(field, envVar) {
|
|
4543
|
+
return `[h2:error:Analytics.Provider] - ${field} is required. Make sure ${envVar} is defined in your environment variables. See https://h2o.fyi/analytics/consent to learn how to setup environment variables in the Shopify admin.`;
|
|
4544
|
+
}
|
|
4554
4545
|
function AnalyticsProvider({
|
|
4555
4546
|
canTrack: customCanTrack,
|
|
4556
4547
|
cart: currentCart,
|
|
@@ -4570,6 +4561,28 @@ function AnalyticsProvider({
|
|
|
4570
4561
|
const [canTrack, setCanTrack] = useState(
|
|
4571
4562
|
customCanTrack ? () => customCanTrack : () => shopifyCanTrack
|
|
4572
4563
|
);
|
|
4564
|
+
if (!!shop) {
|
|
4565
|
+
if (/\/68817551382$/.test(shop.shopId)) {
|
|
4566
|
+
warnOnce(
|
|
4567
|
+
"[h2:error:Analytics.Provider] - Mock shop is used. Analytics will not work properly."
|
|
4568
|
+
);
|
|
4569
|
+
} else {
|
|
4570
|
+
if (!consent.checkoutDomain) {
|
|
4571
|
+
const errorMsg = messageOnError(
|
|
4572
|
+
"consent.checkoutDomain",
|
|
4573
|
+
"PUBLIC_CHECKOUT_DOMAIN"
|
|
4574
|
+
);
|
|
4575
|
+
errorOnce(errorMsg);
|
|
4576
|
+
}
|
|
4577
|
+
if (!consent.storefrontAccessToken) {
|
|
4578
|
+
const errorMsg = messageOnError(
|
|
4579
|
+
"consent.storefrontAccessToken",
|
|
4580
|
+
"PUBLIC_STOREFRONT_API_TOKEN"
|
|
4581
|
+
);
|
|
4582
|
+
errorOnce(errorMsg);
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4573
4586
|
const value = useMemo(() => {
|
|
4574
4587
|
return {
|
|
4575
4588
|
canTrack,
|
|
@@ -4600,7 +4613,7 @@ function AnalyticsProvider({
|
|
|
4600
4613
|
children,
|
|
4601
4614
|
!!shop && /* @__PURE__ */ jsx(AnalyticsPageView, {}),
|
|
4602
4615
|
!!shop && !!currentCart && /* @__PURE__ */ jsx(CartAnalytics, { cart: currentCart, setCarts }),
|
|
4603
|
-
!!shop && /* @__PURE__ */ jsx(
|
|
4616
|
+
!!shop && consent.checkoutDomain && /* @__PURE__ */ jsx(
|
|
4604
4617
|
ShopifyAnalytics,
|
|
4605
4618
|
{
|
|
4606
4619
|
consent,
|
|
@@ -4609,9 +4622,7 @@ function AnalyticsProvider({
|
|
|
4609
4622
|
setConsentLoaded(true);
|
|
4610
4623
|
setCanTrack(() => shopifyCanTrack);
|
|
4611
4624
|
},
|
|
4612
|
-
domain: cookieDomain
|
|
4613
|
-
disableThrowOnError,
|
|
4614
|
-
isMockShop: /\/68817551382$/.test(shop.shopId)
|
|
4625
|
+
domain: cookieDomain
|
|
4615
4626
|
}
|
|
4616
4627
|
)
|
|
4617
4628
|
] });
|