arky-sdk 0.1.1 → 0.1.2
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 +125 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -27
- package/dist/index.js.map +1 -1
- package/dist/stores.cjs +1 -1
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.js +1 -1
- package/dist/stores.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var nanostores = require('nanostores');
|
|
4
|
+
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
7
|
var __esm = (fn, res) => function __init() {
|
|
@@ -194,7 +196,7 @@ var reservationApi = {
|
|
|
194
196
|
token,
|
|
195
197
|
businessId,
|
|
196
198
|
market,
|
|
197
|
-
currency,
|
|
199
|
+
currency: currency2,
|
|
198
200
|
userId,
|
|
199
201
|
parts,
|
|
200
202
|
paymentMethod = "CASH",
|
|
@@ -209,7 +211,7 @@ var reservationApi = {
|
|
|
209
211
|
const payload = {
|
|
210
212
|
businessId,
|
|
211
213
|
market,
|
|
212
|
-
currency,
|
|
214
|
+
currency: currency2,
|
|
213
215
|
userId,
|
|
214
216
|
paymentMethod,
|
|
215
217
|
lines,
|
|
@@ -502,7 +504,7 @@ var eshopApi = {
|
|
|
502
504
|
businessId,
|
|
503
505
|
items,
|
|
504
506
|
market,
|
|
505
|
-
currency,
|
|
507
|
+
currency: currency2,
|
|
506
508
|
userId,
|
|
507
509
|
paymentMethod,
|
|
508
510
|
shippingMethodId,
|
|
@@ -518,7 +520,7 @@ var eshopApi = {
|
|
|
518
520
|
const payload = {
|
|
519
521
|
businessId,
|
|
520
522
|
market,
|
|
521
|
-
currency,
|
|
523
|
+
currency: currency2,
|
|
522
524
|
userId,
|
|
523
525
|
paymentMethod,
|
|
524
526
|
lines,
|
|
@@ -602,7 +604,7 @@ var eshopApi = {
|
|
|
602
604
|
}
|
|
603
605
|
},
|
|
604
606
|
// Create payment intent for Stripe
|
|
605
|
-
async createPaymentIntent({ amount, currency, businessId }) {
|
|
607
|
+
async createPaymentIntent({ amount, currency: currency2, businessId }) {
|
|
606
608
|
try {
|
|
607
609
|
const tokenResponse = await reservationApi.getGuestToken();
|
|
608
610
|
if (!tokenResponse.success || !tokenResponse.data) {
|
|
@@ -617,7 +619,7 @@ var eshopApi = {
|
|
|
617
619
|
},
|
|
618
620
|
body: JSON.stringify({
|
|
619
621
|
amount,
|
|
620
|
-
currency,
|
|
622
|
+
currency: currency2,
|
|
621
623
|
businessId
|
|
622
624
|
})
|
|
623
625
|
});
|
|
@@ -1071,7 +1073,7 @@ var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
|
1071
1073
|
var errors = ERROR_CONSTANTS;
|
|
1072
1074
|
|
|
1073
1075
|
// src/utils/currency.ts
|
|
1074
|
-
function getCurrencySymbol(
|
|
1076
|
+
function getCurrencySymbol(currency2) {
|
|
1075
1077
|
const currencySymbols = {
|
|
1076
1078
|
USD: "$",
|
|
1077
1079
|
EUR: "\u20AC",
|
|
@@ -1152,7 +1154,7 @@ function getCurrencySymbol(currency) {
|
|
|
1152
1154
|
BYR: "p.",
|
|
1153
1155
|
MDL: "L"
|
|
1154
1156
|
};
|
|
1155
|
-
return currencySymbols[
|
|
1157
|
+
return currencySymbols[currency2.toUpperCase()] || currency2;
|
|
1156
1158
|
}
|
|
1157
1159
|
|
|
1158
1160
|
// src/utils/price.ts
|
|
@@ -1176,24 +1178,24 @@ function convertToMajor(minorAmount) {
|
|
|
1176
1178
|
function convertToMinor(majorAmount) {
|
|
1177
1179
|
return Math.round((majorAmount ?? 0) * 100);
|
|
1178
1180
|
}
|
|
1179
|
-
function getSymbol(
|
|
1180
|
-
return CURRENCY_SYMBOLS[
|
|
1181
|
+
function getSymbol(currency2) {
|
|
1182
|
+
return CURRENCY_SYMBOLS[currency2] || "$";
|
|
1181
1183
|
}
|
|
1182
1184
|
function getCurrencyFromMarket(marketId) {
|
|
1183
1185
|
return MARKET_CURRENCIES[marketId] || "USD";
|
|
1184
1186
|
}
|
|
1185
|
-
function formatCurrencyAmount(amount,
|
|
1187
|
+
function formatCurrencyAmount(amount, currency2, options = {}) {
|
|
1186
1188
|
const { showSymbols = true, decimalPlaces = 2, customSymbol } = options;
|
|
1187
1189
|
const roundedAmount = amount.toFixed(decimalPlaces);
|
|
1188
1190
|
if (!showSymbols) {
|
|
1189
|
-
return `${roundedAmount} ${
|
|
1191
|
+
return `${roundedAmount} ${currency2}`;
|
|
1190
1192
|
}
|
|
1191
|
-
const symbol = customSymbol || getSymbol(
|
|
1193
|
+
const symbol = customSymbol || getSymbol(currency2);
|
|
1192
1194
|
return `${symbol}${roundedAmount}`;
|
|
1193
1195
|
}
|
|
1194
|
-
function formatMinor(amountMinor,
|
|
1196
|
+
function formatMinor(amountMinor, currency2, options = {}) {
|
|
1195
1197
|
const major = convertToMajor(amountMinor);
|
|
1196
|
-
return formatCurrencyAmount(major,
|
|
1198
|
+
return formatCurrencyAmount(major, currency2, options);
|
|
1197
1199
|
}
|
|
1198
1200
|
function formatPayment(payment, options = {}) {
|
|
1199
1201
|
if (!payment) return "";
|
|
@@ -1224,28 +1226,28 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
|
|
|
1224
1226
|
price = prices.find((p) => p.market === fallbackMarket) || prices[0];
|
|
1225
1227
|
}
|
|
1226
1228
|
if (!price) return "";
|
|
1227
|
-
let
|
|
1229
|
+
let currency2;
|
|
1228
1230
|
let symbol;
|
|
1229
1231
|
if (businessMarkets) {
|
|
1230
1232
|
const marketData = businessMarkets.find((m) => m.id === price.market || m.code === price.market);
|
|
1231
1233
|
if (marketData?.currency) {
|
|
1232
|
-
|
|
1233
|
-
symbol = getCurrencySymbol(
|
|
1234
|
+
currency2 = marketData.currency;
|
|
1235
|
+
symbol = getCurrencySymbol(currency2);
|
|
1234
1236
|
} else {
|
|
1235
|
-
|
|
1236
|
-
symbol = getSymbol(
|
|
1237
|
+
currency2 = getCurrencyFromMarket(price.market);
|
|
1238
|
+
symbol = getSymbol(currency2);
|
|
1237
1239
|
}
|
|
1238
1240
|
} else {
|
|
1239
|
-
|
|
1240
|
-
symbol = getSymbol(
|
|
1241
|
+
currency2 = getCurrencyFromMarket(price.market);
|
|
1242
|
+
symbol = getSymbol(currency2);
|
|
1241
1243
|
}
|
|
1242
|
-
const formattedPrice = formatMinor(price.amount ?? 0,
|
|
1244
|
+
const formattedPrice = formatMinor(price.amount ?? 0, currency2, {
|
|
1243
1245
|
showSymbols,
|
|
1244
1246
|
decimalPlaces,
|
|
1245
1247
|
customSymbol: symbol
|
|
1246
1248
|
});
|
|
1247
1249
|
if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
|
|
1248
|
-
const formattedCompareAt = formatMinor(price.compareAt,
|
|
1250
|
+
const formattedCompareAt = formatMinor(price.compareAt, currency2, {
|
|
1249
1251
|
showSymbols,
|
|
1250
1252
|
decimalPlaces,
|
|
1251
1253
|
customSymbol: symbol
|
|
@@ -1259,11 +1261,11 @@ function getPriceAmount(prices, marketId, fallbackMarket = "US") {
|
|
|
1259
1261
|
const price = prices.find((p) => p.market === marketId) || prices.find((p) => p.market === fallbackMarket) || prices[0];
|
|
1260
1262
|
return price?.amount || 0;
|
|
1261
1263
|
}
|
|
1262
|
-
function createPaymentForCheckout(subtotalMinor, marketId,
|
|
1264
|
+
function createPaymentForCheckout(subtotalMinor, marketId, currency2, paymentMethod, options = {}) {
|
|
1263
1265
|
const { discount = 0, tax = 0, promoCodeId } = options;
|
|
1264
1266
|
const total = subtotalMinor - discount + tax;
|
|
1265
1267
|
return {
|
|
1266
|
-
currency,
|
|
1268
|
+
currency: currency2,
|
|
1267
1269
|
market: marketId,
|
|
1268
1270
|
subtotal: subtotalMinor,
|
|
1269
1271
|
shipping: 0,
|
|
@@ -1442,7 +1444,100 @@ function validateRequired(value, fieldName = "This field") {
|
|
|
1442
1444
|
|
|
1443
1445
|
// src/index.ts
|
|
1444
1446
|
init_config();
|
|
1445
|
-
|
|
1447
|
+
|
|
1448
|
+
// src/stores/business.ts
|
|
1449
|
+
init_config();
|
|
1450
|
+
var businessStore = nanostores.deepMap({
|
|
1451
|
+
data: null,
|
|
1452
|
+
loading: false,
|
|
1453
|
+
error: null,
|
|
1454
|
+
initialized: false
|
|
1455
|
+
});
|
|
1456
|
+
var selectedMarket = nanostores.computed(businessStore, (state) => {
|
|
1457
|
+
if (!state.data?.configs?.markets) return null;
|
|
1458
|
+
const markets2 = state.data.configs.markets;
|
|
1459
|
+
return markets2.find((m) => m.id === "us") || markets2[0] || null;
|
|
1460
|
+
});
|
|
1461
|
+
nanostores.computed(selectedMarket, (market) => {
|
|
1462
|
+
return market?.currency || "USD";
|
|
1463
|
+
});
|
|
1464
|
+
nanostores.computed(selectedMarket, (market) => {
|
|
1465
|
+
return getCurrencySymbol(market?.currency || "USD");
|
|
1466
|
+
});
|
|
1467
|
+
nanostores.computed(businessStore, (state) => {
|
|
1468
|
+
if (!state.data?.configs?.markets) return [];
|
|
1469
|
+
return state.data.configs.markets;
|
|
1470
|
+
});
|
|
1471
|
+
nanostores.computed(businessStore, (state) => {
|
|
1472
|
+
if (!state.data?.configs?.zones) return [];
|
|
1473
|
+
return state.data.configs.zones;
|
|
1474
|
+
});
|
|
1475
|
+
var paymentMethods = nanostores.computed(selectedMarket, (market) => {
|
|
1476
|
+
if (!market) return ["CASH"];
|
|
1477
|
+
const methods = market.paymentMethods || [];
|
|
1478
|
+
return methods.map((pm) => pm.method || pm);
|
|
1479
|
+
});
|
|
1480
|
+
nanostores.computed(businessStore, (state) => {
|
|
1481
|
+
if (!state.data?.configs) return { provider: null, enabled: false };
|
|
1482
|
+
const provider = state.data.configs.paymentProvider || null;
|
|
1483
|
+
const hasCreditCard = paymentMethods.get().includes("CREDIT_CARD");
|
|
1484
|
+
return {
|
|
1485
|
+
provider,
|
|
1486
|
+
enabled: hasCreditCard && !!provider
|
|
1487
|
+
};
|
|
1488
|
+
});
|
|
1489
|
+
nanostores.computed(businessStore, (state) => {
|
|
1490
|
+
return state.data?.configs?.orderBlocks || [];
|
|
1491
|
+
});
|
|
1492
|
+
nanostores.computed(businessStore, (state) => {
|
|
1493
|
+
return state.data?.configs?.reservationBlocks || [];
|
|
1494
|
+
});
|
|
1495
|
+
var businessActions = {
|
|
1496
|
+
// Initialize business data - SINGLE API CALL for entire app
|
|
1497
|
+
async init() {
|
|
1498
|
+
const state = businessStore.get();
|
|
1499
|
+
if (state.initialized && state.data) {
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
try {
|
|
1503
|
+
businessStore.setKey("loading", true);
|
|
1504
|
+
businessStore.setKey("error", null);
|
|
1505
|
+
const result = await getBusinessConfig(exports.BUSINESS_ID);
|
|
1506
|
+
if (result.success) {
|
|
1507
|
+
businessStore.setKey("data", result.data);
|
|
1508
|
+
businessStore.setKey("initialized", true);
|
|
1509
|
+
} else {
|
|
1510
|
+
throw new Error(result.error || "Failed to load business configuration");
|
|
1511
|
+
}
|
|
1512
|
+
} catch (error) {
|
|
1513
|
+
businessStore.setKey("error", error.message);
|
|
1514
|
+
console.error("Business store initialization failed:", error);
|
|
1515
|
+
} finally {
|
|
1516
|
+
businessStore.setKey("loading", false);
|
|
1517
|
+
}
|
|
1518
|
+
},
|
|
1519
|
+
// Reset store (useful for testing)
|
|
1520
|
+
reset() {
|
|
1521
|
+
businessStore.setKey("data", null);
|
|
1522
|
+
businessStore.setKey("loading", false);
|
|
1523
|
+
businessStore.setKey("error", null);
|
|
1524
|
+
businessStore.setKey("initialized", false);
|
|
1525
|
+
},
|
|
1526
|
+
// Get business data (with auto-init)
|
|
1527
|
+
async getBusiness() {
|
|
1528
|
+
const state = businessStore.get();
|
|
1529
|
+
if (!state.initialized || !state.data) {
|
|
1530
|
+
await this.init();
|
|
1531
|
+
}
|
|
1532
|
+
return businessStore.get().data;
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
if (typeof window !== "undefined" && exports.BUSINESS_ID) {
|
|
1536
|
+
businessActions.init().catch(console.error);
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
// src/index.ts
|
|
1540
|
+
var SDK_VERSION = "0.1.2";
|
|
1446
1541
|
var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
|
|
1447
1542
|
function initArky(config) {
|
|
1448
1543
|
if (!config.apiUrl) {
|
|
@@ -1452,6 +1547,9 @@ function initArky(config) {
|
|
|
1452
1547
|
throw new Error("businessId is required");
|
|
1453
1548
|
}
|
|
1454
1549
|
setGlobalConfig(config);
|
|
1550
|
+
if (typeof window !== "undefined") {
|
|
1551
|
+
businessActions.init().catch(console.error);
|
|
1552
|
+
}
|
|
1455
1553
|
return config;
|
|
1456
1554
|
}
|
|
1457
1555
|
|