@pack/hydrogen 3.2.4 → 3.2.6
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 +73 -90
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5811,71 +5811,62 @@ async function getTestInfo({
|
|
|
5811
5811
|
);
|
|
5812
5812
|
if (testSessionData?.id && testSessionData?.testVariant) {
|
|
5813
5813
|
debug3("[Pack Test] Found existing test data in session");
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5814
|
+
try {
|
|
5815
|
+
const validationResult = await packClientFetchTestByRules(
|
|
5816
|
+
packClient,
|
|
5817
|
+
testTargetAudienceAttributes,
|
|
5818
|
+
testSession,
|
|
5819
|
+
request,
|
|
5820
|
+
withCache,
|
|
5821
|
+
token,
|
|
5822
|
+
null,
|
|
5823
|
+
true
|
|
5824
|
+
// validateOnly - but will assign new test if current is inactive
|
|
5817
5825
|
);
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
if (validationResult) {
|
|
5831
|
-
if (validationResult.id === testSessionData.id) {
|
|
5832
|
-
debug3(
|
|
5833
|
-
"[Pack Test] Test is still active, using refreshed data",
|
|
5834
|
-
JSON.stringify({
|
|
5835
|
-
testId: validationResult.id,
|
|
5836
|
-
testHandle: validationResult.handle,
|
|
5837
|
-
variantId: validationResult.testVariant.id,
|
|
5838
|
-
variantHandle: validationResult.testVariant.handle
|
|
5839
|
-
})
|
|
5840
|
-
);
|
|
5841
|
-
return validationResult;
|
|
5842
|
-
} else {
|
|
5843
|
-
debug3(
|
|
5844
|
-
"[Pack Test] Original test no longer active, new test assigned",
|
|
5845
|
-
JSON.stringify({
|
|
5846
|
-
oldTestId: testSessionData.id,
|
|
5847
|
-
newTestId: validationResult.id,
|
|
5848
|
-
newTestHandle: validationResult.handle,
|
|
5849
|
-
newVariantId: validationResult.testVariant.id,
|
|
5850
|
-
newVariantHandle: validationResult.testVariant.handle
|
|
5851
|
-
})
|
|
5852
|
-
);
|
|
5853
|
-
return {
|
|
5854
|
-
...validationResult,
|
|
5855
|
-
isFirstExposure: true
|
|
5856
|
-
};
|
|
5857
|
-
}
|
|
5826
|
+
if (validationResult) {
|
|
5827
|
+
if (validationResult.id === testSessionData.id) {
|
|
5828
|
+
debug3(
|
|
5829
|
+
"[Pack Test] Test is still active, using refreshed data",
|
|
5830
|
+
JSON.stringify({
|
|
5831
|
+
testId: validationResult.id,
|
|
5832
|
+
testHandle: validationResult.handle,
|
|
5833
|
+
variantId: validationResult.testVariant.id,
|
|
5834
|
+
variantHandle: validationResult.testVariant.handle
|
|
5835
|
+
})
|
|
5836
|
+
);
|
|
5837
|
+
return validationResult;
|
|
5858
5838
|
} else {
|
|
5859
5839
|
debug3(
|
|
5860
|
-
"[Pack Test]
|
|
5840
|
+
"[Pack Test] Original test no longer active, new test assigned",
|
|
5841
|
+
JSON.stringify({
|
|
5842
|
+
oldTestId: testSessionData.id,
|
|
5843
|
+
newTestId: validationResult.id,
|
|
5844
|
+
newTestHandle: validationResult.handle,
|
|
5845
|
+
newVariantId: validationResult.testVariant.id,
|
|
5846
|
+
newVariantHandle: validationResult.testVariant.handle
|
|
5847
|
+
})
|
|
5861
5848
|
);
|
|
5862
|
-
return
|
|
5849
|
+
return {
|
|
5850
|
+
...validationResult,
|
|
5851
|
+
isFirstExposure: true
|
|
5852
|
+
};
|
|
5863
5853
|
}
|
|
5864
|
-
}
|
|
5854
|
+
} else {
|
|
5865
5855
|
debug3(
|
|
5866
|
-
"[Pack Test]
|
|
5867
|
-
JSON.stringify(error)
|
|
5868
|
-
);
|
|
5869
|
-
console.error(
|
|
5870
|
-
"[Pack Test] Error validating test, using cached data:",
|
|
5871
|
-
error
|
|
5856
|
+
"[Pack Test] Test is no longer active and no new test was assigned"
|
|
5872
5857
|
);
|
|
5873
|
-
return
|
|
5858
|
+
return void 0;
|
|
5874
5859
|
}
|
|
5875
|
-
}
|
|
5876
|
-
debug3(
|
|
5877
|
-
|
|
5878
|
-
|
|
5860
|
+
} catch (error) {
|
|
5861
|
+
debug3(
|
|
5862
|
+
"[Pack Test] Error validating test, using cached data:",
|
|
5863
|
+
JSON.stringify(error)
|
|
5864
|
+
);
|
|
5865
|
+
console.error(
|
|
5866
|
+
"[Pack Test] Error validating test, using cached data:",
|
|
5867
|
+
error
|
|
5868
|
+
);
|
|
5869
|
+
return { ...testSessionData, isFirstExposure: void 0 };
|
|
5879
5870
|
}
|
|
5880
5871
|
}
|
|
5881
5872
|
if (exposedTestCookieString) {
|
|
@@ -6009,28 +6000,33 @@ async function getTestInfo({
|
|
|
6009
6000
|
);
|
|
6010
6001
|
return testInfo;
|
|
6011
6002
|
}
|
|
6012
|
-
function
|
|
6003
|
+
function hasCompleteTestInput(testInput) {
|
|
6004
|
+
if (!testInput) return false;
|
|
6005
|
+
const hasTest = Boolean(testInput.testId || testInput.testHandle);
|
|
6006
|
+
const hasVariant = Boolean(
|
|
6007
|
+
testInput.testVariantId || testInput.testVariantHandle
|
|
6008
|
+
);
|
|
6009
|
+
return hasTest && hasVariant;
|
|
6010
|
+
}
|
|
6011
|
+
function getTestSession(testSession, explicitTest = null, previewEnabled = false) {
|
|
6013
6012
|
debug3(
|
|
6014
6013
|
"[Pack Test] Getting test session:",
|
|
6015
6014
|
JSON.stringify({
|
|
6016
6015
|
hasTestSession: !!testSession,
|
|
6017
|
-
|
|
6016
|
+
hasExplicitTest: hasCompleteTestInput(explicitTest),
|
|
6018
6017
|
previewEnabled
|
|
6019
6018
|
})
|
|
6020
6019
|
);
|
|
6021
|
-
if (
|
|
6020
|
+
if (hasCompleteTestInput(explicitTest)) {
|
|
6022
6021
|
const result = {
|
|
6023
|
-
id:
|
|
6024
|
-
handle:
|
|
6022
|
+
id: explicitTest.testId || "",
|
|
6023
|
+
handle: explicitTest.testHandle || "",
|
|
6025
6024
|
testVariant: {
|
|
6026
|
-
id:
|
|
6027
|
-
handle:
|
|
6025
|
+
id: explicitTest.testVariantId || "",
|
|
6026
|
+
handle: explicitTest.testVariantHandle || ""
|
|
6028
6027
|
}
|
|
6029
6028
|
};
|
|
6030
|
-
debug3(
|
|
6031
|
-
"[Pack Test] Using test from query parameters:",
|
|
6032
|
-
JSON.stringify(result)
|
|
6033
|
-
);
|
|
6029
|
+
debug3("[Pack Test] Using explicit test input:", JSON.stringify(result));
|
|
6034
6030
|
return result;
|
|
6035
6031
|
}
|
|
6036
6032
|
if (previewEnabled) {
|
|
@@ -6232,6 +6228,9 @@ function createPackClient(options) {
|
|
|
6232
6228
|
let testInfoPromise = void 0;
|
|
6233
6229
|
let currentRequest = request;
|
|
6234
6230
|
let testFromQueryParams = request ? getTestFromQueryParams(request) : null;
|
|
6231
|
+
const testFromPreviewSession = previewEnabled && testHandle && testVariantHandle ? { testId: "", testHandle, testVariantId: "", testVariantHandle } : null;
|
|
6232
|
+
const getExplicitTestForSession = () => hasCompleteTestInput(testFromQueryParams) ? testFromQueryParams : testFromPreviewSession;
|
|
6233
|
+
const getCurrentAbTest = () => getTestSession(testSession, getExplicitTestForSession(), previewEnabled);
|
|
6235
6234
|
if (!token && !defaultThemeData) {
|
|
6236
6235
|
throw new Error(
|
|
6237
6236
|
"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 +6263,14 @@ function createPackClient(options) {
|
|
|
6264
6263
|
if (!token) {
|
|
6265
6264
|
return {
|
|
6266
6265
|
get abTest() {
|
|
6267
|
-
return
|
|
6266
|
+
return getCurrentAbTest();
|
|
6268
6267
|
},
|
|
6269
6268
|
handleRequest: handleRequest2,
|
|
6270
6269
|
getPackSessionData: () => {
|
|
6271
6270
|
return {
|
|
6272
6271
|
storeId,
|
|
6273
6272
|
sessionId: session.id,
|
|
6274
|
-
abTest:
|
|
6275
|
-
testSession,
|
|
6276
|
-
testFromQueryParams,
|
|
6277
|
-
previewEnabled
|
|
6278
|
-
),
|
|
6273
|
+
abTest: getCurrentAbTest(),
|
|
6279
6274
|
isPreviewModeEnabled: previewEnabled,
|
|
6280
6275
|
customizerMeta: session.get("customizerMeta")
|
|
6281
6276
|
};
|
|
@@ -6284,11 +6279,7 @@ function createPackClient(options) {
|
|
|
6284
6279
|
return {
|
|
6285
6280
|
packStoreId: storeId,
|
|
6286
6281
|
packSessionId: session.id,
|
|
6287
|
-
packAbTest:
|
|
6288
|
-
testSession,
|
|
6289
|
-
testFromQueryParams,
|
|
6290
|
-
previewEnabled
|
|
6291
|
-
),
|
|
6282
|
+
packAbTest: getCurrentAbTest(),
|
|
6292
6283
|
packIsPreviewMode: previewEnabled,
|
|
6293
6284
|
packCustomizerMeta: session.get("customizerMeta"),
|
|
6294
6285
|
packErrorTracking: errorTracking
|
|
@@ -6331,17 +6322,13 @@ function createPackClient(options) {
|
|
|
6331
6322
|
});
|
|
6332
6323
|
return {
|
|
6333
6324
|
get abTest() {
|
|
6334
|
-
return
|
|
6325
|
+
return getCurrentAbTest();
|
|
6335
6326
|
},
|
|
6336
6327
|
getPackSessionData: () => {
|
|
6337
6328
|
return {
|
|
6338
6329
|
storeId,
|
|
6339
6330
|
sessionId: session.id,
|
|
6340
|
-
abTest:
|
|
6341
|
-
testSession,
|
|
6342
|
-
testFromQueryParams,
|
|
6343
|
-
previewEnabled
|
|
6344
|
-
),
|
|
6331
|
+
abTest: getCurrentAbTest(),
|
|
6345
6332
|
isPreviewModeEnabled: previewEnabled,
|
|
6346
6333
|
customizerMeta: session.get("customizerMeta")
|
|
6347
6334
|
};
|
|
@@ -6350,11 +6337,7 @@ function createPackClient(options) {
|
|
|
6350
6337
|
return {
|
|
6351
6338
|
packStoreId: storeId,
|
|
6352
6339
|
packSessionId: session.id,
|
|
6353
|
-
packAbTest:
|
|
6354
|
-
testSession,
|
|
6355
|
-
testFromQueryParams,
|
|
6356
|
-
previewEnabled
|
|
6357
|
-
),
|
|
6340
|
+
packAbTest: getCurrentAbTest(),
|
|
6358
6341
|
packIsPreviewMode: previewEnabled,
|
|
6359
6342
|
packCustomizerMeta: session.get("customizerMeta"),
|
|
6360
6343
|
packErrorTracking: errorTracking
|