@vio-live/web-sdk 0.10.0 → 0.11.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/{chunk-PX27CQGX.js → chunk-U2QG4IVJ.js} +105 -17
- package/dist/chunk-U2QG4IVJ.js.map +1 -0
- package/dist/{chunk-WIQ53CCM.js → chunk-XU5LGUBU.js} +3 -3
- package/dist/{chunk-WIQ53CCM.js.map → chunk-XU5LGUBU.js.map} +1 -1
- package/dist/core/index.d.ts +26 -2
- package/dist/core/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +3 -3
- package/dist/ui/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-PX27CQGX.js.map +0 -1
|
@@ -1805,6 +1805,23 @@ var CartManager = class extends EventTarget {
|
|
|
1805
1805
|
const targetItemId = item.cartItemId;
|
|
1806
1806
|
if (quantity <= 0) {
|
|
1807
1807
|
cart.items = cart.items.filter((i) => i !== item);
|
|
1808
|
+
if (typeof document !== "undefined") {
|
|
1809
|
+
document.dispatchEvent(
|
|
1810
|
+
new CustomEvent("vio:removed-from-cart", {
|
|
1811
|
+
bubbles: true,
|
|
1812
|
+
detail: {
|
|
1813
|
+
productId: item.productId,
|
|
1814
|
+
variantId: item.variantId,
|
|
1815
|
+
name: item.name,
|
|
1816
|
+
brand: item.brand,
|
|
1817
|
+
price: item.unitPrice,
|
|
1818
|
+
quantity: item.quantity,
|
|
1819
|
+
currency: item.currency,
|
|
1820
|
+
sponsorId
|
|
1821
|
+
}
|
|
1822
|
+
})
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1808
1825
|
} else {
|
|
1809
1826
|
item.quantity = quantity;
|
|
1810
1827
|
}
|
|
@@ -4352,7 +4369,7 @@ function toSmallestUnit(amount, currency) {
|
|
|
4352
4369
|
}
|
|
4353
4370
|
|
|
4354
4371
|
// src/core/version.ts
|
|
4355
|
-
var SDK_VERSION = "0.
|
|
4372
|
+
var SDK_VERSION = "0.11.0";
|
|
4356
4373
|
|
|
4357
4374
|
// src/core/analytics/analytics-manager.ts
|
|
4358
4375
|
var SESSION_TTL_MS = 30 * 60 * 1e3;
|
|
@@ -4374,6 +4391,9 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4374
4391
|
this.retryAttempt = 0;
|
|
4375
4392
|
this.retryNotBefore = 0;
|
|
4376
4393
|
this.sessionId = null;
|
|
4394
|
+
this.requireConsent = false;
|
|
4395
|
+
this.consentGranted = false;
|
|
4396
|
+
this.anonIdCache = null;
|
|
4377
4397
|
/** Set via start({ sessionId }) — the host owns the session, we follow. */
|
|
4378
4398
|
this.externalSessionId = null;
|
|
4379
4399
|
this.sessionStartedAt = 0;
|
|
@@ -4389,7 +4409,29 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4389
4409
|
* Install listeners + begin flushing. Explicit on purpose (no module
|
|
4390
4410
|
* side-effects). Safe to call twice (second call only updates options).
|
|
4391
4411
|
*/
|
|
4412
|
+
/**
|
|
4413
|
+
* Consentimiento (ePrivacy/GDPR). Por defecto el SDK asume que el host ya
|
|
4414
|
+
* lo gestionó — su CMP decide si nos carga. Con `requireConsent: true`
|
|
4415
|
+
* arranca en modo **cookieless**: mide la visita con ids efímeros en
|
|
4416
|
+
* memoria y NO escribe nada en localStorage hasta que el host llame
|
|
4417
|
+
* `setConsent(true)`. Retirarlo borra lo persistido.
|
|
4418
|
+
*/
|
|
4419
|
+
setConsent(granted) {
|
|
4420
|
+
this.consentGranted = granted;
|
|
4421
|
+
if (granted) {
|
|
4422
|
+
if (this.anonIdCache) safeStorageSet(ANON_KEY, this.anonIdCache);
|
|
4423
|
+
if (this.sessionId) this.persistSession();
|
|
4424
|
+
return;
|
|
4425
|
+
}
|
|
4426
|
+
safeStorageRemove(ANON_KEY);
|
|
4427
|
+
safeStorageRemove(SESSION_KEY);
|
|
4428
|
+
}
|
|
4429
|
+
/** ¿Podemos escribir en el dispositivo? */
|
|
4430
|
+
get canPersist() {
|
|
4431
|
+
return !this.requireConsent || this.consentGranted;
|
|
4432
|
+
}
|
|
4392
4433
|
start(options = {}) {
|
|
4434
|
+
this.requireConsent = options.requireConsent === true;
|
|
4393
4435
|
this.options = {
|
|
4394
4436
|
host: options.host ?? this.options.host,
|
|
4395
4437
|
collector: options.collector ?? this.options.collector,
|
|
@@ -4539,6 +4581,7 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4539
4581
|
content_id: ctx.contentId,
|
|
4540
4582
|
// Deletion-proof reporting: sources have no trash bin — the title
|
|
4541
4583
|
// snapshotted at event time keeps reports legible if content dies.
|
|
4584
|
+
error_code: ctx.errorCode,
|
|
4542
4585
|
content_title: ctx.contentTitle ?? (typeof document !== "undefined" && document.title ? document.title.slice(0, 255) : void 0),
|
|
4543
4586
|
variant: ctx.variant
|
|
4544
4587
|
});
|
|
@@ -4574,18 +4617,35 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4574
4617
|
...opts.props ? { props: opts.props } : {}
|
|
4575
4618
|
};
|
|
4576
4619
|
}
|
|
4620
|
+
/** Guarda la sesión solo si podemos escribir en el dispositivo. */
|
|
4621
|
+
persistSession(now = Date.now()) {
|
|
4622
|
+
if (!this.canPersist || !this.sessionId) return;
|
|
4623
|
+
safeStorageSet(
|
|
4624
|
+
SESSION_KEY,
|
|
4625
|
+
JSON.stringify({
|
|
4626
|
+
id: this.sessionId,
|
|
4627
|
+
ts: now,
|
|
4628
|
+
startedAt: this.sessionStartedAt ?? now
|
|
4629
|
+
})
|
|
4630
|
+
);
|
|
4631
|
+
}
|
|
4577
4632
|
anonId() {
|
|
4578
|
-
|
|
4579
|
-
|
|
4633
|
+
if (this.anonIdCache) return this.anonIdCache;
|
|
4634
|
+
const stored = this.canPersist ? safeStorageGet(ANON_KEY) : null;
|
|
4635
|
+
if (stored) {
|
|
4636
|
+
this.anonIdCache = stored;
|
|
4637
|
+
return stored;
|
|
4638
|
+
}
|
|
4580
4639
|
const id = `a-${uuid()}`;
|
|
4581
|
-
safeStorageSet(ANON_KEY, id);
|
|
4582
|
-
|
|
4640
|
+
if (this.canPersist) safeStorageSet(ANON_KEY, id);
|
|
4641
|
+
this.anonIdCache = (this.canPersist ? safeStorageGet(ANON_KEY) : null) ?? id;
|
|
4642
|
+
return this.anonIdCache;
|
|
4583
4643
|
}
|
|
4584
4644
|
/** Rolling session: renewed by activity, rotated after 30 min idle. */
|
|
4585
4645
|
ensureSession() {
|
|
4586
4646
|
const now = Date.now();
|
|
4587
4647
|
if (!this.sessionId) {
|
|
4588
|
-
const stored = safeStorageGet(SESSION_KEY);
|
|
4648
|
+
const stored = this.canPersist ? safeStorageGet(SESSION_KEY) : null;
|
|
4589
4649
|
if (stored) {
|
|
4590
4650
|
try {
|
|
4591
4651
|
const parsed = JSON.parse(stored);
|
|
@@ -4597,7 +4657,7 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4597
4657
|
}
|
|
4598
4658
|
}
|
|
4599
4659
|
} else {
|
|
4600
|
-
const stored = safeStorageGet(SESSION_KEY);
|
|
4660
|
+
const stored = this.canPersist ? safeStorageGet(SESSION_KEY) : null;
|
|
4601
4661
|
if (stored) {
|
|
4602
4662
|
try {
|
|
4603
4663
|
if (now - JSON.parse(stored).ts >= SESSION_TTL_MS) {
|
|
@@ -4619,16 +4679,10 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4619
4679
|
this.sessionId = `s-${uuid()}`;
|
|
4620
4680
|
this.sessionStartedAt = now;
|
|
4621
4681
|
this.impressedComponents.clear();
|
|
4622
|
-
|
|
4623
|
-
SESSION_KEY,
|
|
4624
|
-
JSON.stringify({ id: this.sessionId, ts: now, startedAt: now })
|
|
4625
|
-
);
|
|
4682
|
+
this.persistSession(now);
|
|
4626
4683
|
this.track("session_start");
|
|
4627
4684
|
} else {
|
|
4628
|
-
|
|
4629
|
-
SESSION_KEY,
|
|
4630
|
-
JSON.stringify({ id: this.sessionId, ts: now, startedAt: this.sessionStartedAt })
|
|
4631
|
-
);
|
|
4685
|
+
this.persistSession(now);
|
|
4632
4686
|
}
|
|
4633
4687
|
}
|
|
4634
4688
|
trackSessionEnd() {
|
|
@@ -4693,6 +4747,34 @@ var AnalyticsManager = class extends EventTarget {
|
|
|
4693
4747
|
}
|
|
4694
4748
|
});
|
|
4695
4749
|
});
|
|
4750
|
+
on("vio:removed-from-cart", (ev) => {
|
|
4751
|
+
const d = ev.detail ?? {};
|
|
4752
|
+
if (d.productId === void 0) return;
|
|
4753
|
+
this.track("remove_from_cart", {
|
|
4754
|
+
context: { sponsorId: d.sponsorId },
|
|
4755
|
+
commerce: {
|
|
4756
|
+
items: [
|
|
4757
|
+
{
|
|
4758
|
+
productId: d.productId,
|
|
4759
|
+
variantId: d.variantId,
|
|
4760
|
+
name: d.name,
|
|
4761
|
+
brand: d.brand,
|
|
4762
|
+
price: d.price,
|
|
4763
|
+
quantity: d.quantity
|
|
4764
|
+
}
|
|
4765
|
+
],
|
|
4766
|
+
value: (d.price ?? 0) * (d.quantity ?? 1),
|
|
4767
|
+
currency: d.currency
|
|
4768
|
+
}
|
|
4769
|
+
});
|
|
4770
|
+
});
|
|
4771
|
+
on("vio:cart-error", (ev) => {
|
|
4772
|
+
const d = ev.detail ?? {};
|
|
4773
|
+
this.track("sdk_error", {
|
|
4774
|
+
context: { errorCode: "cart_error" },
|
|
4775
|
+
props: d.message ? { message: String(d.message).slice(0, 500) } : void 0
|
|
4776
|
+
});
|
|
4777
|
+
});
|
|
4696
4778
|
on("vio:product-click", (ev) => {
|
|
4697
4779
|
const d = ev.detail ?? {};
|
|
4698
4780
|
if (d.productId === void 0) return;
|
|
@@ -4793,6 +4875,12 @@ function safeStorageGet(key) {
|
|
|
4793
4875
|
return null;
|
|
4794
4876
|
}
|
|
4795
4877
|
}
|
|
4878
|
+
function safeStorageRemove(key) {
|
|
4879
|
+
try {
|
|
4880
|
+
window.localStorage.removeItem(key);
|
|
4881
|
+
} catch {
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4796
4884
|
function safeStorageSet(key, value) {
|
|
4797
4885
|
try {
|
|
4798
4886
|
window.localStorage.setItem(key, value);
|
|
@@ -4978,5 +5066,5 @@ var _vioGlobal = globalThis;
|
|
|
4978
5066
|
var Vio = _vioGlobal.__VIO_FACADE__ ?? (_vioGlobal.__VIO_FACADE__ = new VioFacade());
|
|
4979
5067
|
|
|
4980
5068
|
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 };
|
|
4981
|
-
//# sourceMappingURL=chunk-
|
|
4982
|
-
//# sourceMappingURL=chunk-
|
|
5069
|
+
//# sourceMappingURL=chunk-U2QG4IVJ.js.map
|
|
5070
|
+
//# sourceMappingURL=chunk-U2QG4IVJ.js.map
|