@pack/hydrogen 3.2.3 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6009,28 +6009,33 @@ async function getTestInfo({
|
|
|
6009
6009
|
);
|
|
6010
6010
|
return testInfo;
|
|
6011
6011
|
}
|
|
6012
|
-
function
|
|
6012
|
+
function hasCompleteTestInput(testInput) {
|
|
6013
|
+
if (!testInput) return false;
|
|
6014
|
+
const hasTest = Boolean(testInput.testId || testInput.testHandle);
|
|
6015
|
+
const hasVariant = Boolean(
|
|
6016
|
+
testInput.testVariantId || testInput.testVariantHandle
|
|
6017
|
+
);
|
|
6018
|
+
return hasTest && hasVariant;
|
|
6019
|
+
}
|
|
6020
|
+
function getTestSession(testSession, explicitTest = null, previewEnabled = false) {
|
|
6013
6021
|
debug3(
|
|
6014
6022
|
"[Pack Test] Getting test session:",
|
|
6015
6023
|
JSON.stringify({
|
|
6016
6024
|
hasTestSession: !!testSession,
|
|
6017
|
-
|
|
6025
|
+
hasExplicitTest: hasCompleteTestInput(explicitTest),
|
|
6018
6026
|
previewEnabled
|
|
6019
6027
|
})
|
|
6020
6028
|
);
|
|
6021
|
-
if (
|
|
6029
|
+
if (hasCompleteTestInput(explicitTest)) {
|
|
6022
6030
|
const result = {
|
|
6023
|
-
id:
|
|
6024
|
-
handle:
|
|
6031
|
+
id: explicitTest.testId || "",
|
|
6032
|
+
handle: explicitTest.testHandle || "",
|
|
6025
6033
|
testVariant: {
|
|
6026
|
-
id:
|
|
6027
|
-
handle:
|
|
6034
|
+
id: explicitTest.testVariantId || "",
|
|
6035
|
+
handle: explicitTest.testVariantHandle || ""
|
|
6028
6036
|
}
|
|
6029
6037
|
};
|
|
6030
|
-
debug3(
|
|
6031
|
-
"[Pack Test] Using test from query parameters:",
|
|
6032
|
-
JSON.stringify(result)
|
|
6033
|
-
);
|
|
6038
|
+
debug3("[Pack Test] Using explicit test input:", JSON.stringify(result));
|
|
6034
6039
|
return result;
|
|
6035
6040
|
}
|
|
6036
6041
|
if (previewEnabled) {
|
|
@@ -6232,6 +6237,9 @@ function createPackClient(options) {
|
|
|
6232
6237
|
let testInfoPromise = void 0;
|
|
6233
6238
|
let currentRequest = request;
|
|
6234
6239
|
let testFromQueryParams = request ? getTestFromQueryParams(request) : null;
|
|
6240
|
+
const testFromPreviewSession = previewEnabled && testHandle && testVariantHandle ? { testId: "", testHandle, testVariantId: "", testVariantHandle } : null;
|
|
6241
|
+
const getExplicitTestForSession = () => hasCompleteTestInput(testFromQueryParams) ? testFromQueryParams : testFromPreviewSession;
|
|
6242
|
+
const getCurrentAbTest = () => getTestSession(testSession, getExplicitTestForSession(), previewEnabled);
|
|
6235
6243
|
if (!token && !defaultThemeData) {
|
|
6236
6244
|
throw new Error(
|
|
6237
6245
|
"ERR_HY_MISSING_TOKEN: The Pack client token is missing or empty. Please provide a valid token or default theme data. Doc: https://docs.packdigital.com/err/ERR_HY_MISSING_TOKEN"
|
|
@@ -6264,18 +6272,14 @@ function createPackClient(options) {
|
|
|
6264
6272
|
if (!token) {
|
|
6265
6273
|
return {
|
|
6266
6274
|
get abTest() {
|
|
6267
|
-
return
|
|
6275
|
+
return getCurrentAbTest();
|
|
6268
6276
|
},
|
|
6269
6277
|
handleRequest: handleRequest2,
|
|
6270
6278
|
getPackSessionData: () => {
|
|
6271
6279
|
return {
|
|
6272
6280
|
storeId,
|
|
6273
6281
|
sessionId: session.id,
|
|
6274
|
-
abTest:
|
|
6275
|
-
testSession,
|
|
6276
|
-
testFromQueryParams,
|
|
6277
|
-
previewEnabled
|
|
6278
|
-
),
|
|
6282
|
+
abTest: getCurrentAbTest(),
|
|
6279
6283
|
isPreviewModeEnabled: previewEnabled,
|
|
6280
6284
|
customizerMeta: session.get("customizerMeta")
|
|
6281
6285
|
};
|
|
@@ -6284,11 +6288,7 @@ function createPackClient(options) {
|
|
|
6284
6288
|
return {
|
|
6285
6289
|
packStoreId: storeId,
|
|
6286
6290
|
packSessionId: session.id,
|
|
6287
|
-
packAbTest:
|
|
6288
|
-
testSession,
|
|
6289
|
-
testFromQueryParams,
|
|
6290
|
-
previewEnabled
|
|
6291
|
-
),
|
|
6291
|
+
packAbTest: getCurrentAbTest(),
|
|
6292
6292
|
packIsPreviewMode: previewEnabled,
|
|
6293
6293
|
packCustomizerMeta: session.get("customizerMeta"),
|
|
6294
6294
|
packErrorTracking: errorTracking
|
|
@@ -6331,17 +6331,13 @@ function createPackClient(options) {
|
|
|
6331
6331
|
});
|
|
6332
6332
|
return {
|
|
6333
6333
|
get abTest() {
|
|
6334
|
-
return
|
|
6334
|
+
return getCurrentAbTest();
|
|
6335
6335
|
},
|
|
6336
6336
|
getPackSessionData: () => {
|
|
6337
6337
|
return {
|
|
6338
6338
|
storeId,
|
|
6339
6339
|
sessionId: session.id,
|
|
6340
|
-
abTest:
|
|
6341
|
-
testSession,
|
|
6342
|
-
testFromQueryParams,
|
|
6343
|
-
previewEnabled
|
|
6344
|
-
),
|
|
6340
|
+
abTest: getCurrentAbTest(),
|
|
6345
6341
|
isPreviewModeEnabled: previewEnabled,
|
|
6346
6342
|
customizerMeta: session.get("customizerMeta")
|
|
6347
6343
|
};
|
|
@@ -6350,11 +6346,7 @@ function createPackClient(options) {
|
|
|
6350
6346
|
return {
|
|
6351
6347
|
packStoreId: storeId,
|
|
6352
6348
|
packSessionId: session.id,
|
|
6353
|
-
packAbTest:
|
|
6354
|
-
testSession,
|
|
6355
|
-
testFromQueryParams,
|
|
6356
|
-
previewEnabled
|
|
6357
|
-
),
|
|
6349
|
+
packAbTest: getCurrentAbTest(),
|
|
6358
6350
|
packIsPreviewMode: previewEnabled,
|
|
6359
6351
|
packCustomizerMeta: session.get("customizerMeta"),
|
|
6360
6352
|
packErrorTracking: errorTracking
|
|
@@ -6382,7 +6374,9 @@ function createPackClient(options) {
|
|
|
6382
6374
|
queryVariables.language = i18n.language;
|
|
6383
6375
|
queryVariables.country = i18n.country;
|
|
6384
6376
|
}
|
|
6385
|
-
|
|
6377
|
+
const explicitTest = testFromQueryParams || test;
|
|
6378
|
+
const resolveTestInfo = !previewEnabled && !explicitTest;
|
|
6379
|
+
if (resolveTestInfo && packClient && token && !testInfoForRequest && currentRequest) {
|
|
6386
6380
|
try {
|
|
6387
6381
|
if (!testInfoPromise) {
|
|
6388
6382
|
debug4(
|
|
@@ -6415,20 +6409,19 @@ function createPackClient(options) {
|
|
|
6415
6409
|
testInfoForRequest = void 0;
|
|
6416
6410
|
testInfoPromise = void 0;
|
|
6417
6411
|
}
|
|
6418
|
-
} else if (packClient && token && testInfoForRequest) {
|
|
6412
|
+
} else if (resolveTestInfo && packClient && token && testInfoForRequest) {
|
|
6419
6413
|
debug4("[Pack Test] Using cached testInfo - subsequent query");
|
|
6420
6414
|
if (process.env.NODE_ENV === "development") {
|
|
6421
6415
|
console.log("[Pack Test] Using cached testInfo - subsequent query");
|
|
6422
6416
|
}
|
|
6423
6417
|
}
|
|
6424
|
-
if (testInfoForRequest?.isFirstExposure) {
|
|
6418
|
+
if (resolveTestInfo && testInfoForRequest?.isFirstExposure) {
|
|
6425
6419
|
const { isFirstExposure: _isFirstExposure, ...testInfo } = testInfoForRequest;
|
|
6426
6420
|
testInfoForLoader = testInfo;
|
|
6427
6421
|
}
|
|
6428
6422
|
headers = setTestHeaders(headers, {
|
|
6429
|
-
previewEnabled,
|
|
6430
6423
|
testInfoForRequest,
|
|
6431
|
-
testFromQueryParams:
|
|
6424
|
+
testFromQueryParams: explicitTest
|
|
6432
6425
|
});
|
|
6433
6426
|
if (previewEnabled) {
|
|
6434
6427
|
try {
|