@pack/hydrogen 3.2.0 → 3.2.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/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5046,11 +5046,26 @@ var cookie2 = __toESM(require_cookie(), 1);
|
|
|
5046
5046
|
// src/tests/local-test-resolver.ts
|
|
5047
5047
|
var import_json_rules_engine = __toESM(require_dist(), 1);
|
|
5048
5048
|
var import_debug2 = __toESM(require_browser(), 1);
|
|
5049
|
-
|
|
5050
|
-
|
|
5049
|
+
|
|
5050
|
+
// src/tests/impression.ts
|
|
5051
|
+
function getVariantImpressionSectionIds(testVariant) {
|
|
5051
5052
|
const sectionIds = testVariant?.sectionTestVariants?.map((variant) => variant?.section?.id).filter((id) => Boolean(id)) || [];
|
|
5052
5053
|
return [...new Set(sectionIds)];
|
|
5053
5054
|
}
|
|
5055
|
+
function getImpressionSectionIdsForVariant(test, testVariant) {
|
|
5056
|
+
const selectedVariantSectionIds = getVariantImpressionSectionIds(testVariant);
|
|
5057
|
+
if (selectedVariantSectionIds.length > 0) {
|
|
5058
|
+
return selectedVariantSectionIds;
|
|
5059
|
+
}
|
|
5060
|
+
if (testVariant?.handle !== "control") {
|
|
5061
|
+
return [];
|
|
5062
|
+
}
|
|
5063
|
+
const fallbackSectionIds = test?.testVariants?.filter((variant) => variant.handle !== "control").flatMap((variant) => getVariantImpressionSectionIds(variant)) || [];
|
|
5064
|
+
return [...new Set(fallbackSectionIds)];
|
|
5065
|
+
}
|
|
5066
|
+
|
|
5067
|
+
// src/tests/local-test-resolver.ts
|
|
5068
|
+
var debug2 = (0, import_debug2.default)("pack:ab-testing:local-resolver");
|
|
5054
5069
|
var LocalTestResolver = class {
|
|
5055
5070
|
testRules = [];
|
|
5056
5071
|
constructor() {
|
|
@@ -5154,7 +5169,10 @@ var LocalTestResolver = class {
|
|
|
5154
5169
|
})
|
|
5155
5170
|
);
|
|
5156
5171
|
if (accumulatedPercentage >= randomPercentage) {
|
|
5157
|
-
const impressionSectionIds =
|
|
5172
|
+
const impressionSectionIds = getImpressionSectionIdsForVariant(
|
|
5173
|
+
selectedTest,
|
|
5174
|
+
variant
|
|
5175
|
+
);
|
|
5158
5176
|
const result = {
|
|
5159
5177
|
id: selectedTest.id,
|
|
5160
5178
|
handle: selectedTest.handle,
|
|
@@ -5366,10 +5384,6 @@ var QUERY_TESTS_BY_RULES = `#graphql
|
|
|
5366
5384
|
}
|
|
5367
5385
|
}
|
|
5368
5386
|
`;
|
|
5369
|
-
function getImpressionSectionIds2(testVariant) {
|
|
5370
|
-
const sectionIds = testVariant?.sectionTestVariants?.map((variant) => variant?.section?.id).filter((id) => Boolean(id)) || [];
|
|
5371
|
-
return [...new Set(sectionIds)];
|
|
5372
|
-
}
|
|
5373
5387
|
var localTestResolver = new LocalTestResolver();
|
|
5374
5388
|
function generateTestRulesCacheKey(storeId, contentEnvironment) {
|
|
5375
5389
|
return `pack-tests:${storeId}:${contentEnvironment || "default"}`;
|
|
@@ -5583,7 +5597,10 @@ async function packClientFetchTestByRules(packClient, testTargetAudienceAttribut
|
|
|
5583
5597
|
(v) => v.id === currentTestData.testVariant.id
|
|
5584
5598
|
);
|
|
5585
5599
|
if (currentVariant) {
|
|
5586
|
-
const impressionSectionIds =
|
|
5600
|
+
const impressionSectionIds = getImpressionSectionIdsForVariant(
|
|
5601
|
+
freshTestData,
|
|
5602
|
+
currentVariant
|
|
5603
|
+
);
|
|
5587
5604
|
const refreshedTest = {
|
|
5588
5605
|
id: freshTestData.id,
|
|
5589
5606
|
handle: freshTestData.handle,
|
|
@@ -5595,7 +5612,10 @@ async function packClientFetchTestByRules(packClient, testTargetAudienceAttribut
|
|
|
5595
5612
|
impression: impressionSectionIds.length > 0 ? { sectionIds: impressionSectionIds } : void 0,
|
|
5596
5613
|
isFirstExposure: void 0
|
|
5597
5614
|
};
|
|
5598
|
-
const {
|
|
5615
|
+
const {
|
|
5616
|
+
isFirstExposure: _isFirstExposure2,
|
|
5617
|
+
...testDataWithoutFlag2
|
|
5618
|
+
} = refreshedTest;
|
|
5599
5619
|
testSession.setTestData(testDataWithoutFlag2);
|
|
5600
5620
|
testSession.setExpireAt(getExpireAtDate().toISOString());
|
|
5601
5621
|
return refreshedTest;
|
|
@@ -5640,7 +5660,10 @@ async function packClientFetchTestByRules(packClient, testTargetAudienceAttribut
|
|
|
5640
5660
|
(v) => v.id === exposedTest.testVariant?.id
|
|
5641
5661
|
);
|
|
5642
5662
|
if (exposedVariant) {
|
|
5643
|
-
const impressionSectionIds =
|
|
5663
|
+
const impressionSectionIds = getImpressionSectionIdsForVariant(
|
|
5664
|
+
freshTestData,
|
|
5665
|
+
exposedVariant
|
|
5666
|
+
);
|
|
5644
5667
|
const result2 = {
|
|
5645
5668
|
id: freshTestData.id,
|
|
5646
5669
|
handle: freshTestData.handle,
|
|
@@ -5652,7 +5675,7 @@ async function packClientFetchTestByRules(packClient, testTargetAudienceAttribut
|
|
|
5652
5675
|
impression: impressionSectionIds.length > 0 ? { sectionIds: impressionSectionIds } : void 0,
|
|
5653
5676
|
isFirstExposure: void 0
|
|
5654
5677
|
};
|
|
5655
|
-
const { isFirstExposure:
|
|
5678
|
+
const { isFirstExposure: _isFirstExposure2, ...testDataWithoutFlag2 } = result2;
|
|
5656
5679
|
testSession.setTestData(testDataWithoutFlag2);
|
|
5657
5680
|
testSession.setExpireAt(getExpireAtDate().toISOString());
|
|
5658
5681
|
return result2;
|
|
@@ -5707,7 +5730,7 @@ async function packClientFetchTestByRules(packClient, testTargetAudienceAttribut
|
|
|
5707
5730
|
variantHandle: result.testVariant.handle
|
|
5708
5731
|
})
|
|
5709
5732
|
);
|
|
5710
|
-
const { isFirstExposure, ...testDataWithoutFlag } = result;
|
|
5733
|
+
const { isFirstExposure: _isFirstExposure, ...testDataWithoutFlag } = result;
|
|
5711
5734
|
testSession.setTestData(testDataWithoutFlag);
|
|
5712
5735
|
testSession.setExpireAt(getExpireAtDate().toISOString());
|
|
5713
5736
|
debug3("[Pack Test] Returning test info with first exposure flag");
|