arky-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/README.md +11 -3
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js.map +1 -1
- package/dist/index.cjs +43 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/dist/storefront.cjs +42 -8
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.js +42 -8
- package/dist/storefront.js.map +1 -1
- package/package.json +1 -1
package/dist/storefront.js
CHANGED
|
@@ -210,11 +210,27 @@ var createStorefrontApi = (apiConfig, updateContactSession, lifecycle) => {
|
|
|
210
210
|
},
|
|
211
211
|
async get(params, options) {
|
|
212
212
|
await lifecycle.ensureVisitorSession();
|
|
213
|
+
const queryParams = Object.fromEntries(
|
|
214
|
+
Object.entries(
|
|
215
|
+
options?.params || {}
|
|
216
|
+
).filter(
|
|
217
|
+
([name]) => !["token", "cart_token"].includes(name.toLowerCase())
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
const headers = Object.fromEntries(
|
|
221
|
+
Object.entries(options?.headers || {}).filter(
|
|
222
|
+
([name]) => name.toLowerCase() !== "x-arky-cart-token"
|
|
223
|
+
)
|
|
224
|
+
);
|
|
213
225
|
return apiConfig.httpClient.get(
|
|
214
226
|
`${base}/carts/${params.id}`,
|
|
215
227
|
{
|
|
216
228
|
...options,
|
|
217
|
-
|
|
229
|
+
headers: {
|
|
230
|
+
...headers,
|
|
231
|
+
...params.token ? { "X-Arky-Cart-Token": params.token } : {}
|
|
232
|
+
},
|
|
233
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
218
234
|
}
|
|
219
235
|
);
|
|
220
236
|
},
|
|
@@ -1439,7 +1455,8 @@ function createElements(stripe, config) {
|
|
|
1439
1455
|
amount: config.amount,
|
|
1440
1456
|
currency: normalizeCurrency(config.currency),
|
|
1441
1457
|
paymentMethodCreation: "manual",
|
|
1442
|
-
...config.appearance ? { appearance: config.appearance } : {}
|
|
1458
|
+
...config.appearance ? { appearance: config.appearance } : {},
|
|
1459
|
+
...config.setupFutureUsage ? { setupFutureUsage: config.setupFutureUsage } : {}
|
|
1443
1460
|
});
|
|
1444
1461
|
}
|
|
1445
1462
|
|
|
@@ -1908,7 +1925,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
1908
1925
|
}
|
|
1909
1926
|
return result;
|
|
1910
1927
|
}
|
|
1911
|
-
async function
|
|
1928
|
+
async function mountPayment(target, options = {}) {
|
|
1912
1929
|
await loadSetup();
|
|
1913
1930
|
const publishableKey2 = currentStripePublishableKey();
|
|
1914
1931
|
if (!publishableKey2) {
|
|
@@ -1932,7 +1949,8 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
1932
1949
|
connectedAccountId: currentStripeConnectedAccountId() || void 0,
|
|
1933
1950
|
amount,
|
|
1934
1951
|
currency: paymentCurrency,
|
|
1935
|
-
...options.appearance ? { appearance: options.appearance } : {}
|
|
1952
|
+
...options.appearance ? { appearance: options.appearance } : {},
|
|
1953
|
+
...options.setupFutureUsage ? { setupFutureUsage: options.setupFutureUsage } : {}
|
|
1936
1954
|
});
|
|
1937
1955
|
controller.mount(target);
|
|
1938
1956
|
setPaymentController(controller);
|
|
@@ -2013,8 +2031,16 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
2013
2031
|
async function buildProductCartItem(item, source, productHint) {
|
|
2014
2032
|
try {
|
|
2015
2033
|
const product = productHint?.id === item.product_id ? productHint : await client.eshop.product.get({ id: item.product_id });
|
|
2016
|
-
const variant = product.variants.find(
|
|
2017
|
-
|
|
2034
|
+
const variant = product.variants.find(
|
|
2035
|
+
(candidate) => candidate.id === item.variant_id
|
|
2036
|
+
);
|
|
2037
|
+
if (!variant) {
|
|
2038
|
+
cart_status.setKey(
|
|
2039
|
+
"error",
|
|
2040
|
+
`Cart product ${item.product_id} references unavailable variant ${item.variant_id}.`
|
|
2041
|
+
);
|
|
2042
|
+
return null;
|
|
2043
|
+
}
|
|
2018
2044
|
return {
|
|
2019
2045
|
id: item.id || createId("product"),
|
|
2020
2046
|
product_id: product.id,
|
|
@@ -2028,7 +2054,14 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
2028
2054
|
added_at: source.created_at ? source.created_at * 1e3 : Date.now(),
|
|
2029
2055
|
max_stock: availableStock(client, variant)
|
|
2030
2056
|
};
|
|
2031
|
-
} catch {
|
|
2057
|
+
} catch (error) {
|
|
2058
|
+
cart_status.setKey(
|
|
2059
|
+
"error",
|
|
2060
|
+
readErrorMessage(
|
|
2061
|
+
error,
|
|
2062
|
+
`Failed to load cart product ${item.product_id}.`
|
|
2063
|
+
)
|
|
2064
|
+
);
|
|
2032
2065
|
return null;
|
|
2033
2066
|
}
|
|
2034
2067
|
}
|
|
@@ -2067,6 +2100,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
2067
2100
|
promo_code.set(response.promo_code || null);
|
|
2068
2101
|
quote.set(response.quote_snapshot || null);
|
|
2069
2102
|
const items = response.items || [];
|
|
2103
|
+
if (items.length > 0) await loadSetup();
|
|
2070
2104
|
const products = await Promise.all(
|
|
2071
2105
|
items.filter((item) => item.type === "product").map((item) => buildProductCartItem(item, response, options.productHint))
|
|
2072
2106
|
);
|
|
@@ -2985,7 +3019,7 @@ function initializeStoreCore(publishableKey, config, scopedClient) {
|
|
|
2985
3019
|
ready: payment_ready,
|
|
2986
3020
|
setController: setPaymentController,
|
|
2987
3021
|
getController: () => payment_controller.get(),
|
|
2988
|
-
|
|
3022
|
+
mount: mountPayment,
|
|
2989
3023
|
update: updatePaymentController,
|
|
2990
3024
|
destroy: destroyPaymentController
|
|
2991
3025
|
},
|