arky-sdk 0.1.2 → 0.2.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.
@@ -9,8 +9,5 @@ interface ArkyConfig {
9
9
  }
10
10
  declare function setGlobalConfig(config: ArkyConfig): void;
11
11
  declare function getGlobalConfig(): ArkyConfig;
12
- declare let API_URL: string;
13
- declare let BUSINESS_ID: string;
14
- declare let STORAGE_URL: string;
15
12
 
16
- export { type ArkyConfig as A, BUSINESS_ID as B, STORAGE_URL as S, API_URL as a, getGlobalConfig as g, setGlobalConfig as s };
13
+ export { type ArkyConfig as A, getGlobalConfig as g, setGlobalConfig as s };
@@ -9,8 +9,5 @@ interface ArkyConfig {
9
9
  }
10
10
  declare function setGlobalConfig(config: ArkyConfig): void;
11
11
  declare function getGlobalConfig(): ArkyConfig;
12
- declare let API_URL: string;
13
- declare let BUSINESS_ID: string;
14
- declare let STORAGE_URL: string;
15
12
 
16
- export { type ArkyConfig as A, BUSINESS_ID as B, STORAGE_URL as S, API_URL as a, getGlobalConfig as g, setGlobalConfig as s };
13
+ export { type ArkyConfig as A, getGlobalConfig as g, setGlobalConfig as s };
package/dist/index.cjs CHANGED
@@ -1,52 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var nanostores = require('nanostores');
4
-
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
-
15
3
  // src/config.ts
16
- var config_exports = {};
17
- __export(config_exports, {
18
- API_URL: () => exports.API_URL,
19
- BUSINESS_ID: () => exports.BUSINESS_ID,
20
- STORAGE_URL: () => exports.STORAGE_URL,
21
- getGlobalConfig: () => getGlobalConfig,
22
- setGlobalConfig: () => setGlobalConfig
23
- });
4
+ var globalConfig = null;
24
5
  function setGlobalConfig(config) {
25
6
  globalConfig = config;
26
- exports.API_URL = config.apiUrl;
27
- exports.BUSINESS_ID = config.businessId;
28
- exports.STORAGE_URL = config.storageUrl || "";
29
7
  }
30
8
  function getGlobalConfig() {
31
9
  if (!globalConfig) {
32
10
  throw new Error(
33
- "Arky SDK not initialized. Call initArky() or create an ArkyClient instance."
11
+ "Arky SDK not initialized. Call initArky() first."
34
12
  );
35
13
  }
36
14
  return globalConfig;
37
15
  }
38
- var globalConfig; exports.API_URL = void 0; exports.BUSINESS_ID = void 0; exports.STORAGE_URL = void 0;
39
- var init_config = __esm({
40
- "src/config.ts"() {
41
- globalConfig = null;
42
- exports.API_URL = "";
43
- exports.BUSINESS_ID = "";
44
- exports.STORAGE_URL = "";
45
- }
46
- });
47
-
48
- // src/index.ts
49
- init_config();
50
16
 
51
17
  // src/types/index.ts
52
18
  var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
@@ -56,9 +22,6 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
56
22
  return PaymentMethod2;
57
23
  })(PaymentMethod || {});
58
24
 
59
- // src/api/cms.ts
60
- init_config();
61
-
62
25
  // src/utils/queryParams.ts
63
26
  function buildQueryString(params) {
64
27
  const queryParts = [];
@@ -141,12 +104,14 @@ var http_default = httpClient;
141
104
 
142
105
  // src/api/cms.ts
143
106
  var getCollection = async (id) => {
144
- const url = `${exports.API_URL}/v1/businesses/${exports.BUSINESS_ID}/collections/${id}`;
107
+ const config = getGlobalConfig();
108
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${id}`;
145
109
  const { value } = await http_default.get(url);
146
110
  return value;
147
111
  };
148
112
  var getCollections = async ({ name = null, ids = null }) => {
149
- const url = `${exports.API_URL}/v1/businesses/${exports.BUSINESS_ID}/collections`;
113
+ const config = getGlobalConfig();
114
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections`;
150
115
  const response = await http_default.get(url, {
151
116
  params: { name, ids }
152
117
  });
@@ -158,14 +123,16 @@ var getCollectionEntries = async ({
158
123
  cursor,
159
124
  ids = null
160
125
  }) => {
161
- const url = `${exports.API_URL}/v1/businesses/${exports.BUSINESS_ID}/collections/${collectionId}/entries`;
126
+ const config = getGlobalConfig();
127
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries`;
162
128
  const response = await http_default.get(url, {
163
129
  params: { limit, cursor, ids }
164
130
  });
165
131
  return response.value;
166
132
  };
167
133
  var createCollectionEntry = async (collectionEntryData) => {
168
- const url = `${exports.API_URL}/v1/businesses/${exports.BUSINESS_ID}/collections/${collectionEntryData.collectionId}/entries`;
134
+ const config = getGlobalConfig();
135
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionEntryData.collectionId}/entries`;
169
136
  const result = await http_default.post(url, collectionEntryData, {
170
137
  successMessage: "Created successfully",
171
138
  errorMessage: "Failed to create collection"
@@ -173,7 +140,8 @@ var createCollectionEntry = async (collectionEntryData) => {
173
140
  return result;
174
141
  };
175
142
  var getCollectionEntry = async ({ collectionId, id }) => {
176
- const url = `${exports.API_URL}/v1/businesses/${exports.BUSINESS_ID}/collections/${collectionId}/entries/${id}`;
143
+ const config = getGlobalConfig();
144
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries/${id}`;
177
145
  const response = await http_default.get(url);
178
146
  return response;
179
147
  };
@@ -185,24 +153,21 @@ var cmsApi = {
185
153
  createCollectionEntry
186
154
  };
187
155
 
188
- // src/api/eshop.ts
189
- init_config();
190
-
191
156
  // src/api/reservation.ts
192
- init_config();
193
157
  var reservationApi = {
194
158
  // Get quote for reservation parts
195
159
  async getQuote({
196
160
  token,
197
161
  businessId,
198
162
  market,
199
- currency: currency2,
163
+ currency,
200
164
  userId,
201
165
  parts,
202
166
  paymentMethod = "CASH",
203
167
  promoCode
204
168
  }) {
205
169
  try {
170
+ const config = getGlobalConfig();
206
171
  const lines = parts.map((part) => ({
207
172
  type: "SERVICE",
208
173
  serviceId: part.serviceId,
@@ -211,14 +176,14 @@ var reservationApi = {
211
176
  const payload = {
212
177
  businessId,
213
178
  market,
214
- currency: currency2,
179
+ currency,
215
180
  userId,
216
181
  paymentMethod,
217
182
  lines,
218
183
  promoCode: promoCode || void 0,
219
184
  shippingMethodId: null
220
185
  };
221
- const res = await fetch(`${exports.API_URL}/v1/payments/quote`, {
186
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
222
187
  method: "POST",
223
188
  headers: {
224
189
  "Content-Type": "application/json",
@@ -253,7 +218,8 @@ var reservationApi = {
253
218
  limit = 1e3,
254
219
  providerId = null
255
220
  }) {
256
- const url = `${exports.API_URL}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
221
+ const config = getGlobalConfig();
222
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
257
223
  const response = await http_default.get(url, {
258
224
  params: {
259
225
  from,
@@ -279,7 +245,8 @@ var reservationApi = {
279
245
  },
280
246
  // Get all providers for a service
281
247
  async getProviders({ businessId, serviceId, limit = 50 }) {
282
- const url = `${exports.API_URL}/v1/businesses/${businessId}/providers`;
248
+ const config = getGlobalConfig();
249
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
283
250
  const response = await http_default.get(url, {
284
251
  params: {
285
252
  serviceId,
@@ -304,7 +271,8 @@ var reservationApi = {
304
271
  // Get guest token or create a new one
305
272
  async getGuestToken() {
306
273
  try {
307
- const res = await fetch(`${exports.API_URL}/v1/users/login`, {
274
+ const config = getGlobalConfig();
275
+ const res = await fetch(`${config.apiUrl}/v1/users/login`, {
308
276
  method: "POST",
309
277
  headers: { "Content-Type": "application/json" },
310
278
  body: JSON.stringify({ provider: "GUEST" })
@@ -325,7 +293,8 @@ var reservationApi = {
325
293
  // Update user's phone number
326
294
  async updateProfilePhone({ token, phoneNumber }) {
327
295
  try {
328
- const res = await fetch(`${exports.API_URL}/v1/users/update`, {
296
+ const config = getGlobalConfig();
297
+ const res = await fetch(`${config.apiUrl}/v1/users/update`, {
329
298
  method: "PUT",
330
299
  headers: {
331
300
  "Content-Type": "application/json",
@@ -357,7 +326,8 @@ var reservationApi = {
357
326
  // Verify phone number with code
358
327
  async verifyPhoneCode({ token, phoneNumber, code }) {
359
328
  try {
360
- const res = await fetch(`${exports.API_URL}/v1/users/confirm/phone-number`, {
329
+ const config = getGlobalConfig();
330
+ const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
361
331
  method: "PUT",
362
332
  headers: {
363
333
  "Content-Type": "application/json",
@@ -396,6 +366,7 @@ var reservationApi = {
396
366
  promoCode
397
367
  }) {
398
368
  try {
369
+ const config = getGlobalConfig();
399
370
  const payload = {
400
371
  businessId,
401
372
  blocks,
@@ -415,7 +386,7 @@ var reservationApi = {
415
386
  if (promoCode) {
416
387
  payload.promoCode = promoCode;
417
388
  }
418
- const res = await fetch(`${exports.API_URL}/v1/reservations/checkout`, {
389
+ const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
419
390
  method: "POST",
420
391
  headers: {
421
392
  "Content-Type": "application/json",
@@ -452,7 +423,8 @@ var eshopApi = {
452
423
  limit = 20,
453
424
  cursor = null
454
425
  }) {
455
- const url = `${exports.API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products`;
426
+ const config = getGlobalConfig();
427
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
456
428
  const response = await http_default.get(url, {
457
429
  params: {
458
430
  categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
@@ -481,7 +453,8 @@ var eshopApi = {
481
453
  // Get product by slug
482
454
  async getProductBySlug({ businessId, slug }) {
483
455
  try {
484
- const url = `${exports.API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
456
+ const config = getGlobalConfig();
457
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
485
458
  const res = await fetch(url);
486
459
  if (!res.ok) throw new Error("Product not found");
487
460
  const json = await res.json();
@@ -504,13 +477,14 @@ var eshopApi = {
504
477
  businessId,
505
478
  items,
506
479
  market,
507
- currency: currency2,
480
+ currency,
508
481
  userId,
509
482
  paymentMethod,
510
483
  shippingMethodId,
511
484
  promoCode
512
485
  }) {
513
486
  try {
487
+ const config = getGlobalConfig();
514
488
  const lines = items.map((item) => ({
515
489
  type: "PRODUCT_VARIANT",
516
490
  productId: item.productId,
@@ -520,14 +494,14 @@ var eshopApi = {
520
494
  const payload = {
521
495
  businessId,
522
496
  market,
523
- currency: currency2,
497
+ currency,
524
498
  userId,
525
499
  paymentMethod,
526
500
  lines,
527
501
  ...shippingMethodId && { shippingMethodId },
528
502
  ...promoCode && { promoCode }
529
503
  };
530
- const res = await fetch(`${exports.API_URL}/v1/payments/quote`, {
504
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
531
505
  method: "POST",
532
506
  headers: {
533
507
  "Content-Type": "application/json",
@@ -567,6 +541,7 @@ var eshopApi = {
567
541
  paymentIntentId = null
568
542
  }) {
569
543
  try {
544
+ const config = getGlobalConfig();
570
545
  const payload = {
571
546
  businessId,
572
547
  items,
@@ -577,7 +552,7 @@ var eshopApi = {
577
552
  ...promoCode && { promoCode },
578
553
  ...paymentIntentId && { paymentIntentId }
579
554
  };
580
- const res = await fetch(`${exports.API_URL}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
555
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
581
556
  method: "POST",
582
557
  headers: {
583
558
  "Content-Type": "application/json",
@@ -604,14 +579,15 @@ var eshopApi = {
604
579
  }
605
580
  },
606
581
  // Create payment intent for Stripe
607
- async createPaymentIntent({ amount, currency: currency2, businessId }) {
582
+ async createPaymentIntent({ amount, currency, businessId }) {
608
583
  try {
584
+ const config = getGlobalConfig();
609
585
  const tokenResponse = await reservationApi.getGuestToken();
610
586
  if (!tokenResponse.success || !tokenResponse.data) {
611
587
  throw new Error("Failed to get guest token");
612
588
  }
613
589
  const token = tokenResponse.data.token;
614
- const res = await fetch(`${exports.API_URL}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
590
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
615
591
  method: "POST",
616
592
  headers: {
617
593
  "Content-Type": "application/json",
@@ -619,7 +595,7 @@ var eshopApi = {
619
595
  },
620
596
  body: JSON.stringify({
621
597
  amount,
622
- currency: currency2,
598
+ currency,
623
599
  businessId
624
600
  })
625
601
  });
@@ -645,11 +621,11 @@ var eshopApi = {
645
621
  // src/api/newsletter.ts
646
622
  var newsletterApi = {
647
623
  async find(payload) {
624
+ const config = getGlobalConfig();
648
625
  const params = new URLSearchParams({
649
626
  businessId: payload.business_id
650
627
  });
651
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
652
- const url = `${API_URL2}/v1/newsletters?${params.toString()}`;
628
+ const url = `${config.apiUrl}/v1/newsletters?${params.toString()}`;
653
629
  const response = await fetch(url);
654
630
  if (!response.ok) {
655
631
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -665,8 +641,8 @@ var newsletterApi = {
665
641
  };
666
642
  },
667
643
  async get(id) {
668
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
669
- const url = `${API_URL2}/v1/newsletters/${id}`;
644
+ const config = getGlobalConfig();
645
+ const url = `${config.apiUrl}/v1/newsletters/${id}`;
670
646
  const response = await fetch(url);
671
647
  if (!response.ok) {
672
648
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -675,8 +651,8 @@ var newsletterApi = {
675
651
  },
676
652
  async subscribe(payload) {
677
653
  try {
678
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
679
- const url = `${API_URL2}/v1/newsletters/${payload.newsletterId}/subscribe`;
654
+ const config = getGlobalConfig();
655
+ const url = `${config.apiUrl}/v1/newsletters/${payload.newsletterId}/subscribe`;
680
656
  const response = await fetch(url, {
681
657
  method: "POST",
682
658
  headers: {
@@ -711,7 +687,6 @@ var newsletterApi = {
711
687
  };
712
688
 
713
689
  // src/services/auth.ts
714
- init_config();
715
690
  async function getGuestToken(currentToken = null) {
716
691
  if (currentToken) return currentToken;
717
692
  const response = await reservationApi.getGuestToken();
@@ -744,7 +719,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
744
719
  }
745
720
  async function getBusinessConfig(businessId) {
746
721
  try {
747
- const response = await fetch(`${exports.API_URL}/v1/businesses/${businessId}`, {
722
+ const config = getGlobalConfig();
723
+ const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
748
724
  method: "GET",
749
725
  headers: {
750
726
  "Content-Type": "application/json"
@@ -767,7 +743,6 @@ async function getBusinessConfig(businessId) {
767
743
  }
768
744
 
769
745
  // src/utils/blocks.ts
770
- init_config();
771
746
  function getBlockLabel(block, locale = "en") {
772
747
  if (!block) return "";
773
748
  if (block.properties?.label) {
@@ -899,7 +874,8 @@ var getBlockFromArray = (entry, blockKey, locale = "en") => {
899
874
  };
900
875
  var getImageUrl = (imageBlock, isBlock = true) => {
901
876
  if (!imageBlock) return null;
902
- const storageUrl = "https://storage.arky.io/dev";
877
+ const config = getGlobalConfig();
878
+ const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
903
879
  const isExternalUrl = (url) => {
904
880
  return url.startsWith("http://") || url.startsWith("https://");
905
881
  };
@@ -946,7 +922,8 @@ function getGalleryThumbnail(gallery) {
946
922
  return res?.url || null;
947
923
  }
948
924
  function thumbnailUrl(service) {
949
- const storageUrl = exports.STORAGE_URL || "";
925
+ const config = getGlobalConfig();
926
+ const storageUrl = config.storageUrl || "";
950
927
  const path = getGalleryThumbnail(service.gallery);
951
928
  return path ? `${storageUrl}/${path}` : null;
952
929
  }
@@ -1073,7 +1050,7 @@ var convertServerErrorToRequestError = (serverError, renameRules) => {
1073
1050
  var errors = ERROR_CONSTANTS;
1074
1051
 
1075
1052
  // src/utils/currency.ts
1076
- function getCurrencySymbol(currency2) {
1053
+ function getCurrencySymbol(currency) {
1077
1054
  const currencySymbols = {
1078
1055
  USD: "$",
1079
1056
  EUR: "\u20AC",
@@ -1154,7 +1131,7 @@ function getCurrencySymbol(currency2) {
1154
1131
  BYR: "p.",
1155
1132
  MDL: "L"
1156
1133
  };
1157
- return currencySymbols[currency2.toUpperCase()] || currency2;
1134
+ return currencySymbols[currency.toUpperCase()] || currency;
1158
1135
  }
1159
1136
 
1160
1137
  // src/utils/price.ts
@@ -1178,24 +1155,24 @@ function convertToMajor(minorAmount) {
1178
1155
  function convertToMinor(majorAmount) {
1179
1156
  return Math.round((majorAmount ?? 0) * 100);
1180
1157
  }
1181
- function getSymbol(currency2) {
1182
- return CURRENCY_SYMBOLS[currency2] || "$";
1158
+ function getSymbol(currency) {
1159
+ return CURRENCY_SYMBOLS[currency] || "$";
1183
1160
  }
1184
1161
  function getCurrencyFromMarket(marketId) {
1185
1162
  return MARKET_CURRENCIES[marketId] || "USD";
1186
1163
  }
1187
- function formatCurrencyAmount(amount, currency2, options = {}) {
1164
+ function formatCurrencyAmount(amount, currency, options = {}) {
1188
1165
  const { showSymbols = true, decimalPlaces = 2, customSymbol } = options;
1189
1166
  const roundedAmount = amount.toFixed(decimalPlaces);
1190
1167
  if (!showSymbols) {
1191
- return `${roundedAmount} ${currency2}`;
1168
+ return `${roundedAmount} ${currency}`;
1192
1169
  }
1193
- const symbol = customSymbol || getSymbol(currency2);
1170
+ const symbol = customSymbol || getSymbol(currency);
1194
1171
  return `${symbol}${roundedAmount}`;
1195
1172
  }
1196
- function formatMinor(amountMinor, currency2, options = {}) {
1173
+ function formatMinor(amountMinor, currency, options = {}) {
1197
1174
  const major = convertToMajor(amountMinor);
1198
- return formatCurrencyAmount(major, currency2, options);
1175
+ return formatCurrencyAmount(major, currency, options);
1199
1176
  }
1200
1177
  function formatPayment(payment, options = {}) {
1201
1178
  if (!payment) return "";
@@ -1226,28 +1203,28 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
1226
1203
  price = prices.find((p) => p.market === fallbackMarket) || prices[0];
1227
1204
  }
1228
1205
  if (!price) return "";
1229
- let currency2;
1206
+ let currency;
1230
1207
  let symbol;
1231
1208
  if (businessMarkets) {
1232
1209
  const marketData = businessMarkets.find((m) => m.id === price.market || m.code === price.market);
1233
1210
  if (marketData?.currency) {
1234
- currency2 = marketData.currency;
1235
- symbol = getCurrencySymbol(currency2);
1211
+ currency = marketData.currency;
1212
+ symbol = getCurrencySymbol(currency);
1236
1213
  } else {
1237
- currency2 = getCurrencyFromMarket(price.market);
1238
- symbol = getSymbol(currency2);
1214
+ currency = getCurrencyFromMarket(price.market);
1215
+ symbol = getSymbol(currency);
1239
1216
  }
1240
1217
  } else {
1241
- currency2 = getCurrencyFromMarket(price.market);
1242
- symbol = getSymbol(currency2);
1218
+ currency = getCurrencyFromMarket(price.market);
1219
+ symbol = getSymbol(currency);
1243
1220
  }
1244
- const formattedPrice = formatMinor(price.amount ?? 0, currency2, {
1221
+ const formattedPrice = formatMinor(price.amount ?? 0, currency, {
1245
1222
  showSymbols,
1246
1223
  decimalPlaces,
1247
1224
  customSymbol: symbol
1248
1225
  });
1249
1226
  if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
1250
- const formattedCompareAt = formatMinor(price.compareAt, currency2, {
1227
+ const formattedCompareAt = formatMinor(price.compareAt, currency, {
1251
1228
  showSymbols,
1252
1229
  decimalPlaces,
1253
1230
  customSymbol: symbol
@@ -1261,11 +1238,11 @@ function getPriceAmount(prices, marketId, fallbackMarket = "US") {
1261
1238
  const price = prices.find((p) => p.market === marketId) || prices.find((p) => p.market === fallbackMarket) || prices[0];
1262
1239
  return price?.amount || 0;
1263
1240
  }
1264
- function createPaymentForCheckout(subtotalMinor, marketId, currency2, paymentMethod, options = {}) {
1241
+ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
1265
1242
  const { discount = 0, tax = 0, promoCodeId } = options;
1266
1243
  const total = subtotalMinor - discount + tax;
1267
1244
  return {
1268
- currency: currency2,
1245
+ currency,
1269
1246
  market: marketId,
1270
1247
  subtotal: subtotalMinor,
1271
1248
  shipping: 0,
@@ -1443,101 +1420,7 @@ function validateRequired(value, fieldName = "This field") {
1443
1420
  }
1444
1421
 
1445
1422
  // src/index.ts
1446
- init_config();
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";
1423
+ var SDK_VERSION = "0.2.0";
1541
1424
  var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
1542
1425
  function initArky(config) {
1543
1426
  if (!config.apiUrl) {
@@ -1547,9 +1430,6 @@ function initArky(config) {
1547
1430
  throw new Error("businessId is required");
1548
1431
  }
1549
1432
  setGlobalConfig(config);
1550
- if (typeof window !== "undefined") {
1551
- businessActions.init().catch(console.error);
1552
- }
1553
1433
  return config;
1554
1434
  }
1555
1435