@lime-bundles/widget 3.3.0 → 3.4.0
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.cjs +31 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.js +32 -19
- package/dist/index.js.map +1 -1
- package/dist/lime-bundle.global.js +16 -16
- package/dist/lime-bundle.global.js.map +1 -1
- package/docs/react-nextjs.md +14 -5
- package/docs/web-component.md +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4294,7 +4294,7 @@ var LimeBundleElement = class extends HTMLElement {
|
|
|
4294
4294
|
const sanitized = (0, import_core8.sanitizeCustomCss)(css.shop.metafield.value);
|
|
4295
4295
|
if (sanitized.ok) this.shopCustomCss = sanitized.css;
|
|
4296
4296
|
}
|
|
4297
|
-
await this.
|
|
4297
|
+
await this.applyLinkGroupVariants();
|
|
4298
4298
|
this.renderBundles();
|
|
4299
4299
|
} catch (err) {
|
|
4300
4300
|
if (controller.signal.aborted) return;
|
|
@@ -4306,33 +4306,47 @@ var LimeBundleElement = class extends HTMLElement {
|
|
|
4306
4306
|
}
|
|
4307
4307
|
}
|
|
4308
4308
|
/**
|
|
4309
|
-
* Resolve the visitor's
|
|
4310
|
-
*
|
|
4311
|
-
*
|
|
4312
|
-
*
|
|
4313
|
-
*
|
|
4314
|
-
* the
|
|
4309
|
+
* Resolve the visitor's assigned variant for every primary bundle in a link
|
|
4310
|
+
* group. Runs in parallel; any assignment failure logs internally and still
|
|
4311
|
+
* renders the primary (safe default). The `getLinkGroupAssignment` helper
|
|
4312
|
+
* persists the bucket via a first-party cookie; variant attribution is
|
|
4313
|
+
* recorded server-side from the cart-line `_lime_bundle_gid` + `_lime_link_group`
|
|
4314
|
+
* attributes the cart-add path stamps when an assignment lands on a non-primary
|
|
4315
|
+
* variant.
|
|
4316
|
+
*
|
|
4317
|
+
* When the assignment points to a non-primary variant the SDK swaps in that
|
|
4318
|
+
* variant's `ParsedBundle` from the primary's `linkGroup.variants` list. The
|
|
4319
|
+
* variant data must already be present in the storefront query response — the
|
|
4320
|
+
* SDK does NOT issue a separate metaobject fetch on the hot path.
|
|
4315
4321
|
*/
|
|
4316
|
-
async
|
|
4322
|
+
async applyLinkGroupVariants() {
|
|
4317
4323
|
if (this.bundles.length === 0) return;
|
|
4324
|
+
const bundleLookupByMetaobjectId = /* @__PURE__ */ new Map();
|
|
4325
|
+
for (const b of this.bundles) {
|
|
4326
|
+
bundleLookupByMetaobjectId.set(b.id, b);
|
|
4327
|
+
}
|
|
4318
4328
|
const results = await Promise.all(
|
|
4319
4329
|
this.bundles.map(async (bundle) => {
|
|
4320
|
-
|
|
4330
|
+
const lg = bundle.linkGroup;
|
|
4331
|
+
if (!lg || !lg.isPrimary || !lg.variants || lg.variants.length < 2) {
|
|
4332
|
+
return bundle;
|
|
4333
|
+
}
|
|
4321
4334
|
try {
|
|
4322
|
-
const assignment = await (0, import_core8.
|
|
4323
|
-
|
|
4324
|
-
|
|
4335
|
+
const assignment = await (0, import_core8.getLinkGroupAssignment)(lg.id, lg.variants);
|
|
4336
|
+
if (!assignment) return bundle;
|
|
4337
|
+
if (assignment.variantMetaobjectId === bundle.id) return bundle;
|
|
4338
|
+
const swap = bundleLookupByMetaobjectId.get(
|
|
4339
|
+
assignment.variantMetaobjectId
|
|
4325
4340
|
);
|
|
4326
|
-
if (
|
|
4327
|
-
|
|
4328
|
-
}
|
|
4341
|
+
if (!swap) return bundle;
|
|
4342
|
+
return swap;
|
|
4329
4343
|
} catch (err) {
|
|
4330
4344
|
console.warn(
|
|
4331
|
-
`[lime-bundle]
|
|
4345
|
+
`[lime-bundle] link-group assignment failed for bundle ${bundle.id}; falling back to primary.`,
|
|
4332
4346
|
err
|
|
4333
4347
|
);
|
|
4348
|
+
return bundle;
|
|
4334
4349
|
}
|
|
4335
|
-
return bundle;
|
|
4336
4350
|
})
|
|
4337
4351
|
);
|
|
4338
4352
|
this.bundles = results;
|