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