@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
|
@@ -6,12 +6,10 @@ var react$1 = require('@remix-run/react');
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var cookie = require('worktop/cookie');
|
|
8
8
|
var cspBuilder = require('content-security-policy-builder');
|
|
9
|
-
var invariant = require('tiny-invariant');
|
|
10
9
|
|
|
11
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
11
|
|
|
13
12
|
var cspBuilder__default = /*#__PURE__*/_interopDefault(cspBuilder);
|
|
14
|
-
var invariant__default = /*#__PURE__*/_interopDefault(invariant);
|
|
15
13
|
|
|
16
14
|
var __defProp = Object.defineProperty;
|
|
17
15
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -486,7 +484,7 @@ async function fetchWithServerCache(url, requestInit, {
|
|
|
486
484
|
}
|
|
487
485
|
|
|
488
486
|
// src/version.ts
|
|
489
|
-
var LIB_VERSION = "2024.4.
|
|
487
|
+
var LIB_VERSION = "2024.4.4";
|
|
490
488
|
|
|
491
489
|
// src/constants.ts
|
|
492
490
|
var STOREFRONT_REQUEST_GROUP_ID_HEADER = "Custom-Storefront-Request-Group-ID";
|
|
@@ -517,6 +515,13 @@ var warnOnce = (string) => {
|
|
|
517
515
|
warnings.add(string);
|
|
518
516
|
}
|
|
519
517
|
};
|
|
518
|
+
var errors = /* @__PURE__ */ new Set();
|
|
519
|
+
var errorOnce = (string) => {
|
|
520
|
+
if (!errors.has(string)) {
|
|
521
|
+
console.error(new Error(string));
|
|
522
|
+
errors.add(string);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
520
525
|
|
|
521
526
|
// src/utils/graphql.ts
|
|
522
527
|
function minifyQuery(string) {
|
|
@@ -633,19 +638,19 @@ var GraphQLError = class extends Error {
|
|
|
633
638
|
function throwErrorWithGqlLink({
|
|
634
639
|
url,
|
|
635
640
|
response,
|
|
636
|
-
errors,
|
|
641
|
+
errors: errors2,
|
|
637
642
|
type,
|
|
638
643
|
query,
|
|
639
644
|
queryVariables,
|
|
640
645
|
ErrorConstructor = Error,
|
|
641
646
|
client = "storefront"
|
|
642
647
|
}) {
|
|
643
|
-
const errorMessage = (typeof
|
|
648
|
+
const errorMessage = (typeof errors2 === "string" ? errors2 : errors2?.map?.((error) => error.message).join("\n")) || `URL: ${url}
|
|
644
649
|
API response error: ${response.status}`;
|
|
645
650
|
const gqlError = new GraphQLError(errorMessage, {
|
|
646
651
|
query,
|
|
647
652
|
queryVariables,
|
|
648
|
-
cause: { errors },
|
|
653
|
+
cause: { errors: errors2 },
|
|
649
654
|
clientOperation: `${client}.${type}`,
|
|
650
655
|
requestId: response.headers.get("x-request-id")
|
|
651
656
|
});
|
|
@@ -807,16 +812,16 @@ function createStorefrontClient(options) {
|
|
|
807
812
|
errors: void 0
|
|
808
813
|
};
|
|
809
814
|
if (!response.ok) {
|
|
810
|
-
let
|
|
815
|
+
let errors3;
|
|
811
816
|
try {
|
|
812
|
-
|
|
817
|
+
errors3 = parseJSON(body);
|
|
813
818
|
} catch (_e) {
|
|
814
|
-
|
|
819
|
+
errors3 = [{ message: body }];
|
|
815
820
|
}
|
|
816
|
-
throwErrorWithGqlLink({ ...errorOptions, errors:
|
|
821
|
+
throwErrorWithGqlLink({ ...errorOptions, errors: errors3 });
|
|
817
822
|
}
|
|
818
|
-
const { data, errors } = body;
|
|
819
|
-
const gqlErrors =
|
|
823
|
+
const { data, errors: errors2 } = body;
|
|
824
|
+
const gqlErrors = errors2?.map(
|
|
820
825
|
({ message, ...rest }) => new GraphQLError(message, {
|
|
821
826
|
...rest,
|
|
822
827
|
clientOperation: `storefront.${errorOptions.type}`,
|
|
@@ -903,10 +908,10 @@ var getStackOffset = (query) => {
|
|
|
903
908
|
}
|
|
904
909
|
return stackOffset;
|
|
905
910
|
} ;
|
|
906
|
-
function formatAPIResult(data,
|
|
911
|
+
function formatAPIResult(data, errors2) {
|
|
907
912
|
return {
|
|
908
913
|
...data,
|
|
909
|
-
...
|
|
914
|
+
...errors2 && { errors: errors2 }
|
|
910
915
|
};
|
|
911
916
|
}
|
|
912
917
|
|
|
@@ -2647,18 +2652,18 @@ function createCustomerAccountClient({
|
|
|
2647
2652
|
}
|
|
2648
2653
|
throw authFailResponse;
|
|
2649
2654
|
}
|
|
2650
|
-
let
|
|
2655
|
+
let errors2;
|
|
2651
2656
|
try {
|
|
2652
|
-
|
|
2657
|
+
errors2 = parseJSON(body);
|
|
2653
2658
|
} catch (_e) {
|
|
2654
|
-
|
|
2659
|
+
errors2 = [{ message: body }];
|
|
2655
2660
|
}
|
|
2656
|
-
throwErrorWithGqlLink({ ...errorOptions, errors });
|
|
2661
|
+
throwErrorWithGqlLink({ ...errorOptions, errors: errors2 });
|
|
2657
2662
|
}
|
|
2658
2663
|
try {
|
|
2659
2664
|
const APIresponse = parseJSON(body);
|
|
2660
|
-
const { errors } = APIresponse;
|
|
2661
|
-
const gqlErrors =
|
|
2665
|
+
const { errors: errors2 } = APIresponse;
|
|
2666
|
+
const gqlErrors = errors2?.map(
|
|
2662
2667
|
({ message, ...rest }) => new GraphQLError(message, {
|
|
2663
2668
|
...rest,
|
|
2664
2669
|
clientOperation: `customerAccount.${errorOptions.type}`,
|
|
@@ -2667,7 +2672,7 @@ function createCustomerAccountClient({
|
|
|
2667
2672
|
query: query2
|
|
2668
2673
|
})
|
|
2669
2674
|
);
|
|
2670
|
-
return { ...APIresponse, ...
|
|
2675
|
+
return { ...APIresponse, ...errors2 && { errors: gqlErrors } };
|
|
2671
2676
|
} catch (e) {
|
|
2672
2677
|
throwErrorWithGqlLink({ ...errorOptions, errors: [{ message: body }] });
|
|
2673
2678
|
}
|
|
@@ -3038,7 +3043,7 @@ function cartCreateDefault(options) {
|
|
|
3038
3043
|
const buyer = options.customerAccount ? await options.customerAccount.UNSTABLE_getBuyer() : void 0;
|
|
3039
3044
|
const { cartId, ...restOfOptionalParams } = optionalParams || {};
|
|
3040
3045
|
const { buyerIdentity, ...restOfInput } = input;
|
|
3041
|
-
const { cartCreate, errors } = await options.storefront.mutate(CART_CREATE_MUTATION(options.cartFragment), {
|
|
3046
|
+
const { cartCreate, errors: errors2 } = await options.storefront.mutate(CART_CREATE_MUTATION(options.cartFragment), {
|
|
3042
3047
|
variables: {
|
|
3043
3048
|
input: {
|
|
3044
3049
|
...restOfInput,
|
|
@@ -3050,7 +3055,7 @@ function cartCreateDefault(options) {
|
|
|
3050
3055
|
...restOfOptionalParams
|
|
3051
3056
|
}
|
|
3052
3057
|
});
|
|
3053
|
-
return formatAPIResult(cartCreate,
|
|
3058
|
+
return formatAPIResult(cartCreate, errors2);
|
|
3054
3059
|
};
|
|
3055
3060
|
}
|
|
3056
3061
|
var CART_CREATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3084,7 +3089,7 @@ function cartGetDefault({
|
|
|
3084
3089
|
const cartId = getCartId();
|
|
3085
3090
|
if (!cartId)
|
|
3086
3091
|
return null;
|
|
3087
|
-
const [isCustomerLoggedIn, { cart, errors }] = await Promise.all([
|
|
3092
|
+
const [isCustomerLoggedIn, { cart, errors: errors2 }] = await Promise.all([
|
|
3088
3093
|
customerAccount ? customerAccount.isLoggedIn() : false,
|
|
3089
3094
|
storefront.query(CART_QUERY(cartFragment), {
|
|
3090
3095
|
variables: {
|
|
@@ -3096,7 +3101,7 @@ function cartGetDefault({
|
|
|
3096
3101
|
]);
|
|
3097
3102
|
return formatAPIResult(
|
|
3098
3103
|
addCustomerLoggedInParam(isCustomerLoggedIn, cart),
|
|
3099
|
-
|
|
3104
|
+
errors2
|
|
3100
3105
|
);
|
|
3101
3106
|
};
|
|
3102
3107
|
}
|
|
@@ -3235,14 +3240,14 @@ var DEFAULT_CART_FRAGMENT = `#graphql
|
|
|
3235
3240
|
// src/cart/queries/cartLinesAddDefault.ts
|
|
3236
3241
|
function cartLinesAddDefault(options) {
|
|
3237
3242
|
return async (lines, optionalParams) => {
|
|
3238
|
-
const { cartLinesAdd, errors } = await options.storefront.mutate(CART_LINES_ADD_MUTATION(options.cartFragment), {
|
|
3243
|
+
const { cartLinesAdd, errors: errors2 } = await options.storefront.mutate(CART_LINES_ADD_MUTATION(options.cartFragment), {
|
|
3239
3244
|
variables: {
|
|
3240
3245
|
cartId: options.getCartId(),
|
|
3241
3246
|
lines,
|
|
3242
3247
|
...optionalParams
|
|
3243
3248
|
}
|
|
3244
3249
|
});
|
|
3245
|
-
return formatAPIResult(cartLinesAdd,
|
|
3250
|
+
return formatAPIResult(cartLinesAdd, errors2);
|
|
3246
3251
|
};
|
|
3247
3252
|
}
|
|
3248
3253
|
var CART_LINES_ADD_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3288,14 +3293,14 @@ function throwIfLinesAreOptimistic(type, lines) {
|
|
|
3288
3293
|
function cartLinesUpdateDefault(options) {
|
|
3289
3294
|
return async (lines, optionalParams) => {
|
|
3290
3295
|
throwIfLinesAreOptimistic("updateLines", lines);
|
|
3291
|
-
const { cartLinesUpdate, errors } = await options.storefront.mutate(CART_LINES_UPDATE_MUTATION(options.cartFragment), {
|
|
3296
|
+
const { cartLinesUpdate, errors: errors2 } = await options.storefront.mutate(CART_LINES_UPDATE_MUTATION(options.cartFragment), {
|
|
3292
3297
|
variables: {
|
|
3293
3298
|
cartId: options.getCartId(),
|
|
3294
3299
|
lines,
|
|
3295
3300
|
...optionalParams
|
|
3296
3301
|
}
|
|
3297
3302
|
});
|
|
3298
|
-
return formatAPIResult(cartLinesUpdate,
|
|
3303
|
+
return formatAPIResult(cartLinesUpdate, errors2);
|
|
3299
3304
|
};
|
|
3300
3305
|
}
|
|
3301
3306
|
var CART_LINES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3323,14 +3328,14 @@ var CART_LINES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#gra
|
|
|
3323
3328
|
function cartLinesRemoveDefault(options) {
|
|
3324
3329
|
return async (lineIds, optionalParams) => {
|
|
3325
3330
|
throwIfLinesAreOptimistic("removeLines", lineIds);
|
|
3326
|
-
const { cartLinesRemove, errors } = await options.storefront.mutate(CART_LINES_REMOVE_MUTATION(options.cartFragment), {
|
|
3331
|
+
const { cartLinesRemove, errors: errors2 } = await options.storefront.mutate(CART_LINES_REMOVE_MUTATION(options.cartFragment), {
|
|
3327
3332
|
variables: {
|
|
3328
3333
|
cartId: options.getCartId(),
|
|
3329
3334
|
lineIds,
|
|
3330
3335
|
...optionalParams
|
|
3331
3336
|
}
|
|
3332
3337
|
});
|
|
3333
|
-
return formatAPIResult(cartLinesRemove,
|
|
3338
|
+
return formatAPIResult(cartLinesRemove, errors2);
|
|
3334
3339
|
};
|
|
3335
3340
|
}
|
|
3336
3341
|
var CART_LINES_REMOVE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3360,14 +3365,14 @@ function cartDiscountCodesUpdateDefault(options) {
|
|
|
3360
3365
|
const uniqueCodes = discountCodes.filter((value, index, array) => {
|
|
3361
3366
|
return array.indexOf(value) === index;
|
|
3362
3367
|
});
|
|
3363
|
-
const { cartDiscountCodesUpdate, errors } = await options.storefront.mutate(CART_DISCOUNT_CODE_UPDATE_MUTATION(options.cartFragment), {
|
|
3368
|
+
const { cartDiscountCodesUpdate, errors: errors2 } = await options.storefront.mutate(CART_DISCOUNT_CODE_UPDATE_MUTATION(options.cartFragment), {
|
|
3364
3369
|
variables: {
|
|
3365
3370
|
cartId: options.getCartId(),
|
|
3366
3371
|
discountCodes: uniqueCodes,
|
|
3367
3372
|
...optionalParams
|
|
3368
3373
|
}
|
|
3369
3374
|
});
|
|
3370
|
-
return formatAPIResult(cartDiscountCodesUpdate,
|
|
3375
|
+
return formatAPIResult(cartDiscountCodesUpdate, errors2);
|
|
3371
3376
|
};
|
|
3372
3377
|
}
|
|
3373
3378
|
var CART_DISCOUNT_CODE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3399,7 +3404,7 @@ function cartBuyerIdentityUpdateDefault(options) {
|
|
|
3399
3404
|
});
|
|
3400
3405
|
}
|
|
3401
3406
|
const buyer = options.customerAccount ? await options.customerAccount.UNSTABLE_getBuyer() : void 0;
|
|
3402
|
-
const { cartBuyerIdentityUpdate, errors } = await options.storefront.mutate(CART_BUYER_IDENTITY_UPDATE_MUTATION(options.cartFragment), {
|
|
3407
|
+
const { cartBuyerIdentityUpdate, errors: errors2 } = await options.storefront.mutate(CART_BUYER_IDENTITY_UPDATE_MUTATION(options.cartFragment), {
|
|
3403
3408
|
variables: {
|
|
3404
3409
|
cartId: options.getCartId(),
|
|
3405
3410
|
buyerIdentity: {
|
|
@@ -3409,7 +3414,7 @@ function cartBuyerIdentityUpdateDefault(options) {
|
|
|
3409
3414
|
...optionalParams
|
|
3410
3415
|
}
|
|
3411
3416
|
});
|
|
3412
|
-
return formatAPIResult(cartBuyerIdentityUpdate,
|
|
3417
|
+
return formatAPIResult(cartBuyerIdentityUpdate, errors2);
|
|
3413
3418
|
};
|
|
3414
3419
|
}
|
|
3415
3420
|
var CART_BUYER_IDENTITY_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3435,14 +3440,14 @@ var CART_BUYER_IDENTITY_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT)
|
|
|
3435
3440
|
// src/cart/queries/cartNoteUpdateDefault.ts
|
|
3436
3441
|
function cartNoteUpdateDefault(options) {
|
|
3437
3442
|
return async (note, optionalParams) => {
|
|
3438
|
-
const { cartNoteUpdate, errors } = await options.storefront.mutate(CART_NOTE_UPDATE_MUTATION(options.cartFragment), {
|
|
3443
|
+
const { cartNoteUpdate, errors: errors2 } = await options.storefront.mutate(CART_NOTE_UPDATE_MUTATION(options.cartFragment), {
|
|
3439
3444
|
variables: {
|
|
3440
3445
|
cartId: options.getCartId(),
|
|
3441
3446
|
note,
|
|
3442
3447
|
...optionalParams
|
|
3443
3448
|
}
|
|
3444
3449
|
});
|
|
3445
|
-
return formatAPIResult(cartNoteUpdate,
|
|
3450
|
+
return formatAPIResult(cartNoteUpdate, errors2);
|
|
3446
3451
|
};
|
|
3447
3452
|
}
|
|
3448
3453
|
var CART_NOTE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3468,14 +3473,14 @@ var CART_NOTE_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#grap
|
|
|
3468
3473
|
// src/cart/queries/cartSelectedDeliveryOptionsUpdateDefault.ts
|
|
3469
3474
|
function cartSelectedDeliveryOptionsUpdateDefault(options) {
|
|
3470
3475
|
return async (selectedDeliveryOptions, optionalParams) => {
|
|
3471
|
-
const { cartSelectedDeliveryOptionsUpdate, errors } = await options.storefront.mutate(CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION(options.cartFragment), {
|
|
3476
|
+
const { cartSelectedDeliveryOptionsUpdate, errors: errors2 } = await options.storefront.mutate(CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION(options.cartFragment), {
|
|
3472
3477
|
variables: {
|
|
3473
3478
|
cartId: options.getCartId(),
|
|
3474
3479
|
selectedDeliveryOptions,
|
|
3475
3480
|
...optionalParams
|
|
3476
3481
|
}
|
|
3477
3482
|
});
|
|
3478
|
-
return formatAPIResult(cartSelectedDeliveryOptionsUpdate,
|
|
3483
|
+
return formatAPIResult(cartSelectedDeliveryOptionsUpdate, errors2);
|
|
3479
3484
|
};
|
|
3480
3485
|
}
|
|
3481
3486
|
var CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3501,13 +3506,13 @@ var CART_SELECTED_DELIVERY_OPTIONS_UPDATE_MUTATION = (cartFragment = MINIMAL_CAR
|
|
|
3501
3506
|
// src/cart/queries/cartAttributesUpdateDefault.ts
|
|
3502
3507
|
function cartAttributesUpdateDefault(options) {
|
|
3503
3508
|
return async (attributes, optionalParams) => {
|
|
3504
|
-
const { cartAttributesUpdate, errors } = await options.storefront.mutate(CART_ATTRIBUTES_UPDATE_MUTATION(options.cartFragment), {
|
|
3509
|
+
const { cartAttributesUpdate, errors: errors2 } = await options.storefront.mutate(CART_ATTRIBUTES_UPDATE_MUTATION(options.cartFragment), {
|
|
3505
3510
|
variables: {
|
|
3506
3511
|
cartId: optionalParams?.cartId || options.getCartId(),
|
|
3507
3512
|
attributes
|
|
3508
3513
|
}
|
|
3509
3514
|
});
|
|
3510
|
-
return formatAPIResult(cartAttributesUpdate,
|
|
3515
|
+
return formatAPIResult(cartAttributesUpdate, errors2);
|
|
3511
3516
|
};
|
|
3512
3517
|
}
|
|
3513
3518
|
var CART_ATTRIBUTES_UPDATE_MUTATION = (cartFragment = MINIMAL_CART_FRAGMENT) => `#graphql
|
|
@@ -3538,7 +3543,7 @@ function cartMetafieldsSetDefault(options) {
|
|
|
3538
3543
|
ownerId
|
|
3539
3544
|
})
|
|
3540
3545
|
);
|
|
3541
|
-
const { cartMetafieldsSet, errors } = await options.storefront.mutate(CART_METAFIELD_SET_MUTATION(), {
|
|
3546
|
+
const { cartMetafieldsSet, errors: errors2 } = await options.storefront.mutate(CART_METAFIELD_SET_MUTATION(), {
|
|
3542
3547
|
variables: { metafields: metafieldsWithOwnerId }
|
|
3543
3548
|
});
|
|
3544
3549
|
return formatAPIResult(
|
|
@@ -3548,7 +3553,7 @@ function cartMetafieldsSetDefault(options) {
|
|
|
3548
3553
|
},
|
|
3549
3554
|
...cartMetafieldsSet
|
|
3550
3555
|
},
|
|
3551
|
-
|
|
3556
|
+
errors2
|
|
3552
3557
|
);
|
|
3553
3558
|
};
|
|
3554
3559
|
}
|
|
@@ -3573,7 +3578,7 @@ var CART_METAFIELD_SET_MUTATION = () => `#graphql
|
|
|
3573
3578
|
function cartMetafieldDeleteDefault(options) {
|
|
3574
3579
|
return async (key, optionalParams) => {
|
|
3575
3580
|
const ownerId = optionalParams?.cartId || options.getCartId();
|
|
3576
|
-
const { cartMetafieldDelete, errors } = await options.storefront.mutate(CART_METAFIELD_DELETE_MUTATION(), {
|
|
3581
|
+
const { cartMetafieldDelete, errors: errors2 } = await options.storefront.mutate(CART_METAFIELD_DELETE_MUTATION(), {
|
|
3577
3582
|
variables: {
|
|
3578
3583
|
input: {
|
|
3579
3584
|
ownerId,
|
|
@@ -3588,7 +3593,7 @@ function cartMetafieldDeleteDefault(options) {
|
|
|
3588
3593
|
},
|
|
3589
3594
|
...cartMetafieldDelete
|
|
3590
3595
|
},
|
|
3591
|
-
|
|
3596
|
+
errors2
|
|
3592
3597
|
);
|
|
3593
3598
|
};
|
|
3594
3599
|
}
|
|
@@ -4010,11 +4015,20 @@ function ShopPayButton(props) {
|
|
|
4010
4015
|
function AnalyticsView(props) {
|
|
4011
4016
|
const { type, data = {}, customData } = props;
|
|
4012
4017
|
const location = react$1.useLocation();
|
|
4013
|
-
const {
|
|
4018
|
+
const {
|
|
4019
|
+
publish: publish2,
|
|
4020
|
+
cart,
|
|
4021
|
+
prevCart,
|
|
4022
|
+
shop,
|
|
4023
|
+
customData: analyticProviderCustomData
|
|
4024
|
+
} = useAnalytics();
|
|
4014
4025
|
const url = location.pathname + location.search;
|
|
4015
4026
|
let viewPayload2 = {
|
|
4016
4027
|
...data,
|
|
4017
|
-
customData
|
|
4028
|
+
customData: {
|
|
4029
|
+
...analyticProviderCustomData,
|
|
4030
|
+
...customData
|
|
4031
|
+
},
|
|
4018
4032
|
cart,
|
|
4019
4033
|
prevCart,
|
|
4020
4034
|
shop
|
|
@@ -4158,38 +4172,11 @@ function getCustomerPrivacyRequired() {
|
|
|
4158
4172
|
}
|
|
4159
4173
|
return customerPrivacy;
|
|
4160
4174
|
}
|
|
4161
|
-
function messageOnError(field) {
|
|
4162
|
-
return `[h2:error:Analytics.Provider] - ${field} is required`;
|
|
4163
|
-
}
|
|
4164
4175
|
function ShopifyAnalytics({
|
|
4165
4176
|
consent,
|
|
4166
4177
|
onReady,
|
|
4167
|
-
domain
|
|
4168
|
-
disableThrowOnError,
|
|
4169
|
-
isMockShop
|
|
4178
|
+
domain
|
|
4170
4179
|
}) {
|
|
4171
|
-
if (isMockShop) {
|
|
4172
|
-
warnOnce(
|
|
4173
|
-
"[h2:error:Analytics.Provider] - Mock shop is used. Analytics will not work properly."
|
|
4174
|
-
);
|
|
4175
|
-
} else {
|
|
4176
|
-
if (!consent.checkoutDomain) {
|
|
4177
|
-
const errorMsg = messageOnError("consent.checkoutDomain");
|
|
4178
|
-
if (disableThrowOnError) {
|
|
4179
|
-
console.error(errorMsg);
|
|
4180
|
-
} else {
|
|
4181
|
-
invariant__default.default(false, errorMsg);
|
|
4182
|
-
}
|
|
4183
|
-
}
|
|
4184
|
-
if (!consent.storefrontAccessToken) {
|
|
4185
|
-
const errorMsg = messageOnError("consent.storefrontAccessToken");
|
|
4186
|
-
if (disableThrowOnError) {
|
|
4187
|
-
console.error(errorMsg);
|
|
4188
|
-
} else {
|
|
4189
|
-
invariant__default.default(false, errorMsg);
|
|
4190
|
-
}
|
|
4191
|
-
}
|
|
4192
|
-
}
|
|
4193
4180
|
const { subscribe: subscribe2, register: register2, canTrack } = useAnalytics();
|
|
4194
4181
|
const [shopifyReady, setShopifyReady] = react.useState(false);
|
|
4195
4182
|
const [privacyReady, setPrivacyReady] = react.useState(false);
|
|
@@ -4207,9 +4194,9 @@ function ShopifyAnalytics({
|
|
|
4207
4194
|
};
|
|
4208
4195
|
const { checkoutDomain, storefrontAccessToken, withPrivacyBanner } = consent;
|
|
4209
4196
|
useCustomerPrivacy({
|
|
4210
|
-
checkoutDomain:
|
|
4211
|
-
storefrontAccessToken:
|
|
4212
|
-
withPrivacyBanner
|
|
4197
|
+
checkoutDomain: !checkoutDomain ? "mock.shop" : checkoutDomain,
|
|
4198
|
+
storefrontAccessToken: !storefrontAccessToken ? "abcdefghijklmnopqrstuvwxyz123456" : storefrontAccessToken,
|
|
4199
|
+
withPrivacyBanner,
|
|
4213
4200
|
onVisitorConsentCollected: setCustomerPrivacyReady,
|
|
4214
4201
|
onReady: () => {
|
|
4215
4202
|
setTimeout(setCustomerPrivacyReady, 3e3);
|
|
@@ -4646,6 +4633,9 @@ function shopifyCanTrack() {
|
|
|
4646
4633
|
}
|
|
4647
4634
|
return false;
|
|
4648
4635
|
}
|
|
4636
|
+
function messageOnError(field, envVar) {
|
|
4637
|
+
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.`;
|
|
4638
|
+
}
|
|
4649
4639
|
function AnalyticsProvider({
|
|
4650
4640
|
canTrack: customCanTrack,
|
|
4651
4641
|
cart: currentCart,
|
|
@@ -4665,6 +4655,28 @@ function AnalyticsProvider({
|
|
|
4665
4655
|
const [canTrack, setCanTrack] = react.useState(
|
|
4666
4656
|
customCanTrack ? () => customCanTrack : () => shopifyCanTrack
|
|
4667
4657
|
);
|
|
4658
|
+
if (!!shop) {
|
|
4659
|
+
if (/\/68817551382$/.test(shop.shopId)) {
|
|
4660
|
+
warnOnce(
|
|
4661
|
+
"[h2:error:Analytics.Provider] - Mock shop is used. Analytics will not work properly."
|
|
4662
|
+
);
|
|
4663
|
+
} else {
|
|
4664
|
+
if (!consent.checkoutDomain) {
|
|
4665
|
+
const errorMsg = messageOnError(
|
|
4666
|
+
"consent.checkoutDomain",
|
|
4667
|
+
"PUBLIC_CHECKOUT_DOMAIN"
|
|
4668
|
+
);
|
|
4669
|
+
errorOnce(errorMsg);
|
|
4670
|
+
}
|
|
4671
|
+
if (!consent.storefrontAccessToken) {
|
|
4672
|
+
const errorMsg = messageOnError(
|
|
4673
|
+
"consent.storefrontAccessToken",
|
|
4674
|
+
"PUBLIC_STOREFRONT_API_TOKEN"
|
|
4675
|
+
);
|
|
4676
|
+
errorOnce(errorMsg);
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4668
4680
|
const value = react.useMemo(() => {
|
|
4669
4681
|
return {
|
|
4670
4682
|
canTrack,
|
|
@@ -4695,7 +4707,7 @@ function AnalyticsProvider({
|
|
|
4695
4707
|
children,
|
|
4696
4708
|
!!shop && /* @__PURE__ */ jsxRuntime.jsx(AnalyticsPageView, {}),
|
|
4697
4709
|
!!shop && !!currentCart && /* @__PURE__ */ jsxRuntime.jsx(CartAnalytics, { cart: currentCart, setCarts }),
|
|
4698
|
-
!!shop && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4710
|
+
!!shop && consent.checkoutDomain && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4699
4711
|
ShopifyAnalytics,
|
|
4700
4712
|
{
|
|
4701
4713
|
consent,
|
|
@@ -4704,9 +4716,7 @@ function AnalyticsProvider({
|
|
|
4704
4716
|
setConsentLoaded(true);
|
|
4705
4717
|
setCanTrack(() => shopifyCanTrack);
|
|
4706
4718
|
},
|
|
4707
|
-
domain: cookieDomain
|
|
4708
|
-
disableThrowOnError,
|
|
4709
|
-
isMockShop: /\/68817551382$/.test(shop.shopId)
|
|
4719
|
+
domain: cookieDomain
|
|
4710
4720
|
}
|
|
4711
4721
|
)
|
|
4712
4722
|
] });
|