@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 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.applyABVariants();
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 A/B bucket for every bundle with an active test
4310
- * and merge Variant B overrides where applicable. Runs in parallel; any
4311
- * assignment failure logs internally but still renders Variant A (safe
4312
- * default). The `getABTestAssignment` helper persists the bucket via a
4313
- * first-party cookie; variant attribution is recorded server-side from
4314
- * the analytics events the widget already emits.
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 applyABVariants() {
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
- if (!bundle.abTestId || !bundle.abVariantB) return bundle;
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.getABTestAssignment)(
4323
- bundle.abTestId,
4324
- bundle.id
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 (assignment?.variant === "B") {
4327
- return (0, import_core8.applyABVariantB)(bundle);
4328
- }
4341
+ if (!swap) return bundle;
4342
+ return swap;
4329
4343
  } catch (err) {
4330
4344
  console.warn(
4331
- `[lime-bundle] A/B assignment failed for bundle ${bundle.id}; falling back to Variant A.`,
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;