@vio-live/web-sdk 0.5.0 → 0.6.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.
@@ -3079,14 +3079,38 @@ var CheckoutManager = class _CheckoutManager extends EventTarget {
3079
3079
  );
3080
3080
  }
3081
3081
  // MARK: - Apple Pay (Stripe Payment Request)
3082
+ /**
3083
+ * The Stripe publishable key for a sponsor, taken from its own commerce
3084
+ * channel (`GetAvailablePaymentMethods` → Stripe → config.publishableKey).
3085
+ *
3086
+ * The channel is the right source: the key belongs to the brand's Stripe
3087
+ * account, so two brands on one page each get theirs, and a host never has
3088
+ * to configure it. `Vio.init({ stripePublishableKey })` still wins when set,
3089
+ * which keeps existing integrations working and allows an override.
3090
+ */
3091
+ async resolveStripePublishableKey(sponsorId) {
3092
+ const cfg = Configuration.isInitialized ? Configuration.get() : null;
3093
+ if (cfg?.stripePublishableKey) return cfg.stripePublishableKey;
3094
+ if (this.applePayPublishableKey) return this.applePayPublishableKey;
3095
+ try {
3096
+ const methods = await this.getAvailablePaymentMethods(sponsorId);
3097
+ const stripe = methods?.find((m) => String(m?.name ?? "").toLowerCase() === "stripe");
3098
+ const key = stripe?.config?.find((c) => c?.name === "publishableKey")?.value;
3099
+ if (typeof key === "string" && key.startsWith("pk_")) {
3100
+ this.applePayPublishableKey = key;
3101
+ return key;
3102
+ }
3103
+ } catch {
3104
+ }
3105
+ return "";
3106
+ }
3082
3107
  /**
3083
3108
  * Returns true if Apple Pay can be shown on this device + Stripe config.
3084
3109
  * Result is memoised — call `clearApplePayCache()` if config changes.
3085
3110
  */
3086
3111
  async isApplePayAvailable(country = "NO") {
3087
3112
  if (this.applePayAvailableCache !== null) return this.applePayAvailableCache;
3088
- const cfg = Configuration.isInitialized ? Configuration.get() : null;
3089
- const publishableKey = cfg?.stripePublishableKey ?? "";
3113
+ const publishableKey = await this.resolveStripePublishableKey(this.state?.sponsorId);
3090
3114
  if (!publishableKey || !this.state) {
3091
3115
  this.applePayAvailableCache = false;
3092
3116
  return false;
@@ -3115,8 +3139,7 @@ var CheckoutManager = class _CheckoutManager extends EventTarget {
3115
3139
  * `payment-error`. `available` is true only when Apple Pay will actually work.
3116
3140
  */
3117
3141
  async prepareApplePayFor(amount, currency, country = "NO") {
3118
- const cfg = Configuration.isInitialized ? Configuration.get() : null;
3119
- const publishableKey = this.applePayPublishableKey || cfg?.stripePublishableKey || "";
3142
+ const publishableKey = await this.resolveStripePublishableKey(this.state?.sponsorId);
3120
3143
  if (!publishableKey) return { available: false, show: async () => {
3121
3144
  } };
3122
3145
  const prepared = await prepareApplePay({
@@ -3177,8 +3200,7 @@ var CheckoutManager = class _CheckoutManager extends EventTarget {
3177
3200
  * called synchronously inside the tap (Apple's user-gesture rule).
3178
3201
  */
3179
3202
  async prepareApplePayExpress(amount, currency, country = "NO", sponsorId) {
3180
- const cfg = Configuration.isInitialized ? Configuration.get() : null;
3181
- const publishableKey = this.applePayPublishableKey || cfg?.stripePublishableKey || "";
3203
+ const publishableKey = await this.resolveStripePublishableKey(sponsorId ?? this.state?.sponsorId);
3182
3204
  if (!publishableKey) return { available: false, show: async () => null };
3183
3205
  const spId = sponsorId ?? this.state?.sponsorId ?? [...this.cartManager.getAllCarts().keys()][0];
3184
3206
  const prepared = await prepareApplePay({
@@ -3301,8 +3323,7 @@ var CheckoutManager = class _CheckoutManager extends EventTarget {
3301
3323
  async startApplePay(options = {}) {
3302
3324
  if (!this.state) throw new Error("[VioCheckout] no active checkout \u2014 call open() first");
3303
3325
  const spId = options.sponsorId ?? this.state.sponsorId;
3304
- const cfg = Configuration.isInitialized ? Configuration.get() : null;
3305
- const publishableKey = this.applePayPublishableKey || cfg?.stripePublishableKey || "";
3326
+ const publishableKey = await this.resolveStripePublishableKey(spId);
3306
3327
  if (!publishableKey) {
3307
3328
  throw new Error(
3308
3329
  "[VioCheckout] No Stripe publishable key configured. Pass `stripePublishableKey` to Vio.init({ ... })."
@@ -3850,7 +3871,7 @@ function toSmallestUnit(amount, currency) {
3850
3871
  }
3851
3872
 
3852
3873
  // src/core/version.ts
3853
- var SDK_VERSION = "0.5.0";
3874
+ var SDK_VERSION = "0.5.1";
3854
3875
 
3855
3876
  // src/core/analytics/analytics-manager.ts
3856
3877
  var SESSION_TTL_MS = 30 * 60 * 1e3;
@@ -3872,6 +3893,8 @@ var AnalyticsManager = class extends EventTarget {
3872
3893
  this.retryAttempt = 0;
3873
3894
  this.retryNotBefore = 0;
3874
3895
  this.sessionId = null;
3896
+ /** Set via start({ sessionId }) — the host owns the session, we follow. */
3897
+ this.externalSessionId = null;
3875
3898
  this.sessionStartedAt = 0;
3876
3899
  /** Impression once-per-(session, component) guard; reset on session rotation. */
3877
3900
  this.impressedComponents = /* @__PURE__ */ new Set();
@@ -3893,6 +3916,7 @@ var AnalyticsManager = class extends EventTarget {
3893
3916
  debug: options.debug ?? this.options.debug,
3894
3917
  autoTrack: options.autoTrack ?? this.options.autoTrack
3895
3918
  };
3919
+ if (options.sessionId) this.externalSessionId = options.sessionId;
3896
3920
  if (this.started || !hasDom()) return;
3897
3921
  this.started = true;
3898
3922
  this.ensureSession();
@@ -4030,6 +4054,11 @@ var AnalyticsManager = class extends EventTarget {
4030
4054
  sponsor_id: ctx.sponsorId,
4031
4055
  activation_id: ctx.activationId,
4032
4056
  content_url: ctx.contentUrl ?? (typeof location !== "undefined" ? location.href : void 0),
4057
+ // The host's own content id — its join key back onto its reporting.
4058
+ content_id: ctx.contentId,
4059
+ // Deletion-proof reporting: sources have no trash bin — the title
4060
+ // snapshotted at event time keeps reports legible if content dies.
4061
+ content_title: ctx.contentTitle ?? (typeof document !== "undefined" && document.title ? document.title.slice(0, 255) : void 0),
4033
4062
  variant: ctx.variant
4034
4063
  });
4035
4064
  const com = opts.commerce;
@@ -4098,6 +4127,13 @@ var AnalyticsManager = class extends EventTarget {
4098
4127
  }
4099
4128
  }
4100
4129
  }
4130
+ if (this.externalSessionId) {
4131
+ if (this.sessionId !== this.externalSessionId) {
4132
+ this.sessionId = this.externalSessionId;
4133
+ this.sessionStartedAt = now;
4134
+ this.impressedComponents.clear();
4135
+ }
4136
+ }
4101
4137
  if (!this.sessionId) {
4102
4138
  this.sessionId = `s-${uuid()}`;
4103
4139
  this.sessionStartedAt = now;
@@ -4461,5 +4497,5 @@ var _vioGlobal = globalThis;
4461
4497
  var Vio = _vioGlobal.__VIO_FACADE__ ?? (_vioGlobal.__VIO_FACADE__ = new VioFacade());
4462
4498
 
4463
4499
  export { ADD_ITEM_MUTATION, AnalyticsManager, CREATE_CART_MUTATION, CREATE_CHECKOUT_MUTATION, CREATE_PAYMENT_STRIPE_MUTATION, CREATE_PAYMENT_VIPPS_MUTATION, CartManager, CheckoutManager, CommerceClient, Configuration, DELETE_ITEM_MUTATION, GET_AVAILABLE_PAYMENT_METHODS_QUERY, GET_CART_QUERY, GET_CHECKOUT_QUERY, GET_LINE_ITEMS_BY_SUPPLIER_QUERY, GET_VIPPS_STATUS_QUERY, SDK_VERSION, UPDATE_CHECKOUT_MUTATION, UPDATE_ITEM_MUTATION, UPDATE_SHIPPINGS_BY_SUPPLIER_MUTATION, Vio, VioApi, VioApiError, __decorateClass, addItem, checkApplePayAvailability, createCart, createCheckout, createCommerceClient, createPaymentStripe, createPaymentVipps, createVioApi, deleteItem, displayPrice, executeCartGraphQL, formatPrice, getAvailablePaymentMethods, getCart, getCartGraphQLOptions, getCheckout, getCustomerSessionId, getGlobalCurrency, getLineItemsBySupplier, getVippsStatus, primaryImageUrl, showApplePaySheet, updateCheckout, updateItem, updateShippingsBySupplier };
4464
- //# sourceMappingURL=chunk-HNQG56SD.js.map
4465
- //# sourceMappingURL=chunk-HNQG56SD.js.map
4500
+ //# sourceMappingURL=chunk-MOKVTWQW.js.map
4501
+ //# sourceMappingURL=chunk-MOKVTWQW.js.map