@vio-live/web-sdk 0.6.0 → 0.7.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-MOKVTWQW.js → chunk-4ZEN4J7I.js} +189 -2
- package/dist/chunk-4ZEN4J7I.js.map +1 -0
- package/dist/{chunk-6X225SGW.js → chunk-GPMDZSC2.js} +246 -6
- package/dist/{chunk-6X225SGW.js.map → chunk-GPMDZSC2.js.map} +1 -1
- package/dist/core/index.d.ts +180 -100
- package/dist/core/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +3 -3
- package/dist/{tokens-TIH4RkPl.d.ts → tokens-CCZuuTN6.d.ts} +12 -0
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-MOKVTWQW.js.map +0 -1
|
@@ -2501,6 +2501,96 @@ async function createKlarnaPaymentsWidget(input) {
|
|
|
2501
2501
|
};
|
|
2502
2502
|
}
|
|
2503
2503
|
|
|
2504
|
+
// src/core/checkout/payments/kustom.ts
|
|
2505
|
+
var CREATE_PAYMENT_KUSTOM_MUTATION = `
|
|
2506
|
+
mutation CreatePaymentKustom($checkoutId: String!, $countryCode: String!, $href: String!, $email: String) {
|
|
2507
|
+
Payment {
|
|
2508
|
+
CreatePaymentKustom(checkout_id: $checkoutId, country_code: $countryCode, href: $href, email: $email) {
|
|
2509
|
+
order_id
|
|
2510
|
+
status
|
|
2511
|
+
html_snippet
|
|
2512
|
+
purchase_country
|
|
2513
|
+
purchase_currency
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
`;
|
|
2518
|
+
var GET_KUSTOM_ORDER_QUERY = `
|
|
2519
|
+
query GetKustomOrder($orderId: String!) {
|
|
2520
|
+
Payment {
|
|
2521
|
+
GetKustomOrder(order_id: $orderId) {
|
|
2522
|
+
order_id
|
|
2523
|
+
status
|
|
2524
|
+
html_snippet
|
|
2525
|
+
purchase_country
|
|
2526
|
+
purchase_currency
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
`;
|
|
2531
|
+
async function createPaymentKustom(variables, options) {
|
|
2532
|
+
const json = await executeCartGraphQL(CREATE_PAYMENT_KUSTOM_MUTATION, variables, options);
|
|
2533
|
+
return json?.data?.Payment?.CreatePaymentKustom ?? null;
|
|
2534
|
+
}
|
|
2535
|
+
async function getKustomOrder(orderId, options) {
|
|
2536
|
+
const json = await executeCartGraphQL(GET_KUSTOM_ORDER_QUERY, { orderId }, options);
|
|
2537
|
+
return json?.data?.Payment?.GetKustomOrder ?? null;
|
|
2538
|
+
}
|
|
2539
|
+
function kustomCleanHref() {
|
|
2540
|
+
if (typeof window === "undefined" || !window.location) return "";
|
|
2541
|
+
return `${window.location.origin}${window.location.pathname}`;
|
|
2542
|
+
}
|
|
2543
|
+
function renderKustomSnippet(container, htmlSnippet) {
|
|
2544
|
+
container.innerHTML = htmlSnippet;
|
|
2545
|
+
const scripts = Array.from(container.querySelectorAll("script"));
|
|
2546
|
+
for (const oldScript of scripts) {
|
|
2547
|
+
const newScript = document.createElement("script");
|
|
2548
|
+
for (const attr of Array.from(oldScript.attributes)) {
|
|
2549
|
+
newScript.setAttribute(attr.name, attr.value);
|
|
2550
|
+
}
|
|
2551
|
+
newScript.text = oldScript.text;
|
|
2552
|
+
oldScript.parentNode?.replaceChild(newScript, oldScript);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
// src/core/checkout/payments/qliro.ts
|
|
2557
|
+
var CREATE_PAYMENT_QLIRO_MUTATION = `
|
|
2558
|
+
mutation CreatePaymentQliro($checkoutId: String!, $countryCode: String!, $href: String!, $email: String) {
|
|
2559
|
+
Payment {
|
|
2560
|
+
CreatePaymentQliro(checkout_id: $checkoutId, country_code: $countryCode, href: $href, email: $email) {
|
|
2561
|
+
order_id
|
|
2562
|
+
status
|
|
2563
|
+
html_snippet
|
|
2564
|
+
purchase_country
|
|
2565
|
+
purchase_currency
|
|
2566
|
+
total_price
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
`;
|
|
2571
|
+
var GET_QLIRO_ORDER_QUERY = `
|
|
2572
|
+
query GetQliroOrder($checkoutId: String!) {
|
|
2573
|
+
Payment {
|
|
2574
|
+
GetQliroOrder(checkout_id: $checkoutId) {
|
|
2575
|
+
order_id
|
|
2576
|
+
status
|
|
2577
|
+
html_snippet
|
|
2578
|
+
purchase_country
|
|
2579
|
+
purchase_currency
|
|
2580
|
+
total_price
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
`;
|
|
2585
|
+
async function createPaymentQliro(variables, options) {
|
|
2586
|
+
const json = await executeCartGraphQL(CREATE_PAYMENT_QLIRO_MUTATION, variables, options);
|
|
2587
|
+
return json?.data?.Payment?.CreatePaymentQliro ?? null;
|
|
2588
|
+
}
|
|
2589
|
+
async function getQliroOrder(checkoutId, options) {
|
|
2590
|
+
const json = await executeCartGraphQL(GET_QLIRO_ORDER_QUERY, { checkoutId }, options);
|
|
2591
|
+
return json?.data?.Payment?.GetQliroOrder ?? null;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2504
2594
|
// src/core/checkout/checkout-manager.ts
|
|
2505
2595
|
function describeError(err) {
|
|
2506
2596
|
if (err instanceof Error) return err.message;
|
|
@@ -3062,6 +3152,103 @@ var CheckoutManager = class _CheckoutManager extends EventTarget {
|
|
|
3062
3152
|
const opts = await getCartGraphQLOptions(sponsorId ?? this.state?.sponsorId);
|
|
3063
3153
|
return getVippsStatus({ checkoutId }, opts);
|
|
3064
3154
|
}
|
|
3155
|
+
/**
|
|
3156
|
+
* Kustom (former Klarna Checkout) — create the KCO order via Vio Commerce
|
|
3157
|
+
* and render its html_snippet into `container`. The widget collects
|
|
3158
|
+
* address, shipping and payment by itself; the SDK renders nothing else.
|
|
3159
|
+
*/
|
|
3160
|
+
async mountKustomCheckout(container, sponsorId) {
|
|
3161
|
+
const spId = sponsorId ?? this.state?.sponsorId;
|
|
3162
|
+
if (!spId) throw new Error("[CheckoutManager] no sponsor for Kustom");
|
|
3163
|
+
const cart = this.cartManager.getCart(spId);
|
|
3164
|
+
let cartId = cart?.cartId;
|
|
3165
|
+
if (!cartId) cartId = await this.cartManager.ensureCartId(spId);
|
|
3166
|
+
if (!cartId) {
|
|
3167
|
+
throw new Error(`[CheckoutManager] Failed to obtain cart_id for sponsor ${spId}`);
|
|
3168
|
+
}
|
|
3169
|
+
const opts = await getCartGraphQLOptions(spId);
|
|
3170
|
+
let checkoutId = this.state?.checkoutId;
|
|
3171
|
+
if (!checkoutId) {
|
|
3172
|
+
const checkoutRes = await createCheckout(cartId, opts);
|
|
3173
|
+
checkoutId = checkoutRes?.id;
|
|
3174
|
+
if (checkoutId && this.state) {
|
|
3175
|
+
this.state = { ...this.state, checkoutId };
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
if (!checkoutId) {
|
|
3179
|
+
throw new Error("[CheckoutManager] no backend checkout for the Kustom order");
|
|
3180
|
+
}
|
|
3181
|
+
const href = kustomCleanHref();
|
|
3182
|
+
const order = await createPaymentKustom(
|
|
3183
|
+
{
|
|
3184
|
+
checkoutId,
|
|
3185
|
+
countryCode: getGlobalCountryCode(),
|
|
3186
|
+
href,
|
|
3187
|
+
email: this.state?.address?.email || void 0
|
|
3188
|
+
},
|
|
3189
|
+
opts
|
|
3190
|
+
);
|
|
3191
|
+
if (!order?.html_snippet) {
|
|
3192
|
+
throw new Error("Kustom order creation failed: missing html_snippet");
|
|
3193
|
+
}
|
|
3194
|
+
renderKustomSnippet(container, order.html_snippet);
|
|
3195
|
+
return order;
|
|
3196
|
+
}
|
|
3197
|
+
/** Re-read a Kustom order — used on the confirmation return trip. */
|
|
3198
|
+
async getKustomOrder(orderId, sponsorId) {
|
|
3199
|
+
const opts = await getCartGraphQLOptions(sponsorId ?? this.state?.sponsorId);
|
|
3200
|
+
return getKustomOrder(orderId, opts);
|
|
3201
|
+
}
|
|
3202
|
+
/** Render a Kustom html_snippet (e.g. the confirmation receipt) into a container. */
|
|
3203
|
+
renderKustomSnippet(container, htmlSnippet) {
|
|
3204
|
+
renderKustomSnippet(container, htmlSnippet);
|
|
3205
|
+
}
|
|
3206
|
+
/**
|
|
3207
|
+
* Qliro Checkout — create the order via Vio Commerce and render its
|
|
3208
|
+
* html_snippet into `container` (widget-does-everything, like Kustom).
|
|
3209
|
+
*/
|
|
3210
|
+
async mountQliroCheckout(container, sponsorId) {
|
|
3211
|
+
const spId = sponsorId ?? this.state?.sponsorId;
|
|
3212
|
+
if (!spId) throw new Error("[CheckoutManager] no sponsor for Qliro");
|
|
3213
|
+
const cart = this.cartManager.getCart(spId);
|
|
3214
|
+
let cartId = cart?.cartId;
|
|
3215
|
+
if (!cartId) cartId = await this.cartManager.ensureCartId(spId);
|
|
3216
|
+
if (!cartId) {
|
|
3217
|
+
throw new Error(`[CheckoutManager] Failed to obtain cart_id for sponsor ${spId}`);
|
|
3218
|
+
}
|
|
3219
|
+
const opts = await getCartGraphQLOptions(spId);
|
|
3220
|
+
let checkoutId = this.state?.checkoutId;
|
|
3221
|
+
if (!checkoutId) {
|
|
3222
|
+
const checkoutRes = await createCheckout(cartId, opts);
|
|
3223
|
+
checkoutId = checkoutRes?.id;
|
|
3224
|
+
if (checkoutId && this.state) {
|
|
3225
|
+
this.state = { ...this.state, checkoutId };
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
if (!checkoutId) {
|
|
3229
|
+
throw new Error("[CheckoutManager] no backend checkout for the Qliro order");
|
|
3230
|
+
}
|
|
3231
|
+
const href = kustomCleanHref();
|
|
3232
|
+
const order = await createPaymentQliro(
|
|
3233
|
+
{
|
|
3234
|
+
checkoutId,
|
|
3235
|
+
countryCode: getGlobalCountryCode(),
|
|
3236
|
+
href,
|
|
3237
|
+
email: this.state?.address?.email || void 0
|
|
3238
|
+
},
|
|
3239
|
+
opts
|
|
3240
|
+
);
|
|
3241
|
+
if (!order?.html_snippet) {
|
|
3242
|
+
throw new Error("Qliro order creation failed: missing html_snippet");
|
|
3243
|
+
}
|
|
3244
|
+
renderKustomSnippet(container, order.html_snippet);
|
|
3245
|
+
return order;
|
|
3246
|
+
}
|
|
3247
|
+
/** Re-read the Qliro order owned by a checkout — the confirmation trip. */
|
|
3248
|
+
async getQliroOrder(checkoutId, sponsorId) {
|
|
3249
|
+
const opts = await getCartGraphQLOptions(sponsorId ?? this.state?.sponsorId);
|
|
3250
|
+
return getQliroOrder(checkoutId, opts);
|
|
3251
|
+
}
|
|
3065
3252
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
3066
3253
|
setAddress(address) {
|
|
3067
3254
|
if (!this.state) return;
|
|
@@ -4497,5 +4684,5 @@ var _vioGlobal = globalThis;
|
|
|
4497
4684
|
var Vio = _vioGlobal.__VIO_FACADE__ ?? (_vioGlobal.__VIO_FACADE__ = new VioFacade());
|
|
4498
4685
|
|
|
4499
4686
|
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 };
|
|
4500
|
-
//# sourceMappingURL=chunk-
|
|
4501
|
-
//# sourceMappingURL=chunk-
|
|
4687
|
+
//# sourceMappingURL=chunk-4ZEN4J7I.js.map
|
|
4688
|
+
//# sourceMappingURL=chunk-4ZEN4J7I.js.map
|