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.
package/dist/stores.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ArkyConfig } from './config-CPkOgumU.cjs';
1
+ import { A as ArkyConfig } from './config-B7Oy_bdX.cjs';
2
2
  import * as nanostores from 'nanostores';
3
3
  import { Business, Market, Zone, ShippingMethod, PaymentProviderConfig, EshopCartItem, Payment, Quote, Block, PaymentMethod, Price, ReservationCartPart } from './types.cjs';
4
4
 
@@ -32,7 +32,6 @@ declare const cartItems: nanostores.WritableAtom<EshopCartItem[]>;
32
32
  declare const promoCodeAtom: nanostores.PreinitializedWritableAtom<string> & object;
33
33
  declare const quoteAtom: nanostores.PreinitializedWritableAtom<Quote> & object;
34
34
  declare const store$1: nanostores.DeepMapStore<{
35
- businessId: string;
36
35
  selectedShippingMethodId: any;
37
36
  shippingLocation: any;
38
37
  userToken: any;
@@ -138,9 +137,6 @@ declare const store: nanostores.DeepMapStore<{
138
137
  quoteError: any;
139
138
  guestToken: any;
140
139
  service: any;
141
- apiUrl: string;
142
- businessId: string;
143
- storageUrl: string;
144
140
  timezone: string;
145
141
  tzGroups: {
146
142
  label: string;
package/dist/stores.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ArkyConfig } from './config-CPkOgumU.js';
1
+ import { A as ArkyConfig } from './config-B7Oy_bdX.js';
2
2
  import * as nanostores from 'nanostores';
3
3
  import { Business, Market, Zone, ShippingMethod, PaymentProviderConfig, EshopCartItem, Payment, Quote, Block, PaymentMethod, Price, ReservationCartPart } from './types.js';
4
4
 
@@ -32,7 +32,6 @@ declare const cartItems: nanostores.WritableAtom<EshopCartItem[]>;
32
32
  declare const promoCodeAtom: nanostores.PreinitializedWritableAtom<string> & object;
33
33
  declare const quoteAtom: nanostores.PreinitializedWritableAtom<Quote> & object;
34
34
  declare const store$1: nanostores.DeepMapStore<{
35
- businessId: string;
36
35
  selectedShippingMethodId: any;
37
36
  shippingLocation: any;
38
37
  userToken: any;
@@ -138,9 +137,6 @@ declare const store: nanostores.DeepMapStore<{
138
137
  quoteError: any;
139
138
  guestToken: any;
140
139
  service: any;
141
- apiUrl: string;
142
- businessId: string;
143
- storageUrl: string;
144
140
  timezone: string;
145
141
  tzGroups: {
146
142
  label: string;
package/dist/stores.js CHANGED
@@ -2,14 +2,18 @@ import { deepMap, computed, atom } from 'nanostores';
2
2
  import { persistentAtom } from '@nanostores/persistent';
3
3
 
4
4
  // src/config.ts
5
+ var globalConfig = null;
5
6
  function setGlobalConfig(config) {
6
- API_URL = config.apiUrl;
7
- BUSINESS_ID = config.businessId;
8
- STORAGE_URL = config.storageUrl || "";
7
+ globalConfig = config;
8
+ }
9
+ function getGlobalConfig() {
10
+ if (!globalConfig) {
11
+ throw new Error(
12
+ "Arky SDK not initialized. Call initArky() first."
13
+ );
14
+ }
15
+ return globalConfig;
9
16
  }
10
- var API_URL = "";
11
- var BUSINESS_ID = "";
12
- var STORAGE_URL = "";
13
17
 
14
18
  // src/utils/queryParams.ts
15
19
  function buildQueryString(params) {
@@ -105,6 +109,7 @@ var reservationApi = {
105
109
  promoCode
106
110
  }) {
107
111
  try {
112
+ const config = getGlobalConfig();
108
113
  const lines = parts.map((part) => ({
109
114
  type: "SERVICE",
110
115
  serviceId: part.serviceId,
@@ -120,7 +125,7 @@ var reservationApi = {
120
125
  promoCode: promoCode || void 0,
121
126
  shippingMethodId: null
122
127
  };
123
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
128
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
124
129
  method: "POST",
125
130
  headers: {
126
131
  "Content-Type": "application/json",
@@ -155,7 +160,8 @@ var reservationApi = {
155
160
  limit = 1e3,
156
161
  providerId = null
157
162
  }) {
158
- const url = `${API_URL}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
163
+ const config = getGlobalConfig();
164
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
159
165
  const response = await http_default.get(url, {
160
166
  params: {
161
167
  from,
@@ -181,7 +187,8 @@ var reservationApi = {
181
187
  },
182
188
  // Get all providers for a service
183
189
  async getProviders({ businessId, serviceId, limit = 50 }) {
184
- const url = `${API_URL}/v1/businesses/${businessId}/providers`;
190
+ const config = getGlobalConfig();
191
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
185
192
  const response = await http_default.get(url, {
186
193
  params: {
187
194
  serviceId,
@@ -206,7 +213,8 @@ var reservationApi = {
206
213
  // Get guest token or create a new one
207
214
  async getGuestToken() {
208
215
  try {
209
- const res = await fetch(`${API_URL}/v1/users/login`, {
216
+ const config = getGlobalConfig();
217
+ const res = await fetch(`${config.apiUrl}/v1/users/login`, {
210
218
  method: "POST",
211
219
  headers: { "Content-Type": "application/json" },
212
220
  body: JSON.stringify({ provider: "GUEST" })
@@ -227,7 +235,8 @@ var reservationApi = {
227
235
  // Update user's phone number
228
236
  async updateProfilePhone({ token, phoneNumber }) {
229
237
  try {
230
- const res = await fetch(`${API_URL}/v1/users/update`, {
238
+ const config = getGlobalConfig();
239
+ const res = await fetch(`${config.apiUrl}/v1/users/update`, {
231
240
  method: "PUT",
232
241
  headers: {
233
242
  "Content-Type": "application/json",
@@ -259,7 +268,8 @@ var reservationApi = {
259
268
  // Verify phone number with code
260
269
  async verifyPhoneCode({ token, phoneNumber, code }) {
261
270
  try {
262
- const res = await fetch(`${API_URL}/v1/users/confirm/phone-number`, {
271
+ const config = getGlobalConfig();
272
+ const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
263
273
  method: "PUT",
264
274
  headers: {
265
275
  "Content-Type": "application/json",
@@ -298,6 +308,7 @@ var reservationApi = {
298
308
  promoCode
299
309
  }) {
300
310
  try {
311
+ const config = getGlobalConfig();
301
312
  const payload = {
302
313
  businessId,
303
314
  blocks,
@@ -317,7 +328,7 @@ var reservationApi = {
317
328
  if (promoCode) {
318
329
  payload.promoCode = promoCode;
319
330
  }
320
- const res = await fetch(`${API_URL}/v1/reservations/checkout`, {
331
+ const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
321
332
  method: "POST",
322
333
  headers: {
323
334
  "Content-Type": "application/json",
@@ -377,7 +388,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
377
388
  }
378
389
  async function getBusinessConfig(businessId) {
379
390
  try {
380
- const response = await fetch(`${API_URL}/v1/businesses/${businessId}`, {
391
+ const config = getGlobalConfig();
392
+ const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
381
393
  method: "GET",
382
394
  headers: {
383
395
  "Content-Type": "application/json"
@@ -551,7 +563,8 @@ var businessActions = {
551
563
  try {
552
564
  businessStore.setKey("loading", true);
553
565
  businessStore.setKey("error", null);
554
- const result = await getBusinessConfig(BUSINESS_ID);
566
+ const config = getGlobalConfig();
567
+ const result = await getBusinessConfig(config.businessId);
555
568
  if (result.success) {
556
569
  businessStore.setKey("data", result.data);
557
570
  businessStore.setKey("initialized", true);
@@ -581,9 +594,6 @@ var businessActions = {
581
594
  return businessStore.get().data;
582
595
  }
583
596
  };
584
- if (typeof window !== "undefined" && BUSINESS_ID) {
585
- businessActions.init().catch(console.error);
586
- }
587
597
 
588
598
  // src/api/eshop.ts
589
599
  var eshopApi = {
@@ -595,7 +605,8 @@ var eshopApi = {
595
605
  limit = 20,
596
606
  cursor = null
597
607
  }) {
598
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products`;
608
+ const config = getGlobalConfig();
609
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
599
610
  const response = await http_default.get(url, {
600
611
  params: {
601
612
  categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
@@ -624,7 +635,8 @@ var eshopApi = {
624
635
  // Get product by slug
625
636
  async getProductBySlug({ businessId, slug }) {
626
637
  try {
627
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
638
+ const config = getGlobalConfig();
639
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
628
640
  const res = await fetch(url);
629
641
  if (!res.ok) throw new Error("Product not found");
630
642
  const json = await res.json();
@@ -654,6 +666,7 @@ var eshopApi = {
654
666
  promoCode
655
667
  }) {
656
668
  try {
669
+ const config = getGlobalConfig();
657
670
  const lines = items.map((item) => ({
658
671
  type: "PRODUCT_VARIANT",
659
672
  productId: item.productId,
@@ -670,7 +683,7 @@ var eshopApi = {
670
683
  ...shippingMethodId && { shippingMethodId },
671
684
  ...promoCode && { promoCode }
672
685
  };
673
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
686
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
674
687
  method: "POST",
675
688
  headers: {
676
689
  "Content-Type": "application/json",
@@ -710,6 +723,7 @@ var eshopApi = {
710
723
  paymentIntentId = null
711
724
  }) {
712
725
  try {
726
+ const config = getGlobalConfig();
713
727
  const payload = {
714
728
  businessId,
715
729
  items,
@@ -720,7 +734,7 @@ var eshopApi = {
720
734
  ...promoCode && { promoCode },
721
735
  ...paymentIntentId && { paymentIntentId }
722
736
  };
723
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
737
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
724
738
  method: "POST",
725
739
  headers: {
726
740
  "Content-Type": "application/json",
@@ -749,12 +763,13 @@ var eshopApi = {
749
763
  // Create payment intent for Stripe
750
764
  async createPaymentIntent({ amount, currency: currency2, businessId }) {
751
765
  try {
766
+ const config = getGlobalConfig();
752
767
  const tokenResponse = await reservationApi.getGuestToken();
753
768
  if (!tokenResponse.success || !tokenResponse.data) {
754
769
  throw new Error("Failed to get guest token");
755
770
  }
756
771
  const token = tokenResponse.data.token;
757
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
772
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
758
773
  method: "POST",
759
774
  headers: {
760
775
  "Content-Type": "application/json",
@@ -901,7 +916,6 @@ var cartItems = persistentAtom("eshopCart", [], {
901
916
  var promoCodeAtom = atom(null);
902
917
  var quoteAtom = atom(null);
903
918
  var store = deepMap({
904
- businessId: BUSINESS_ID,
905
919
  selectedShippingMethodId: null,
906
920
  // Selected shipping method ID
907
921
  shippingLocation: null,
@@ -1044,10 +1058,11 @@ var actions = {
1044
1058
  if (!shippingMethod) {
1045
1059
  throw new Error("No shipping method available");
1046
1060
  }
1061
+ const config = getGlobalConfig();
1047
1062
  const promo = promoCode !== void 0 ? promoCode : promoCodeAtom.get();
1048
1063
  const response = await eshopApi.checkout({
1049
1064
  token,
1050
- businessId: BUSINESS_ID,
1065
+ businessId: config.businessId,
1051
1066
  items: orderItems,
1052
1067
  paymentMethod,
1053
1068
  blocks,
@@ -1154,11 +1169,12 @@ var actions = {
1154
1169
  try {
1155
1170
  store.setKey("fetchingQuote", true);
1156
1171
  store.setKey("quoteError", null);
1172
+ const config = getGlobalConfig();
1157
1173
  const token = await this.getGuestToken();
1158
1174
  const shippingMethodId = state.selectedShippingMethodId || void 0;
1159
1175
  const response = await eshopApi.getQuote({
1160
1176
  token,
1161
- businessId: BUSINESS_ID,
1177
+ businessId: config.businessId,
1162
1178
  items: items.map((item) => ({
1163
1179
  productId: item.productId,
1164
1180
  variantId: item.variantId,
@@ -1349,9 +1365,6 @@ var store2 = deepMap({
1349
1365
  // Service & config
1350
1366
  guestToken: null,
1351
1367
  service: null,
1352
- apiUrl: API_URL,
1353
- businessId: BUSINESS_ID,
1354
- storageUrl: STORAGE_URL,
1355
1368
  timezone: findTimeZone(tzGroups),
1356
1369
  tzGroups,
1357
1370
  parts: []
@@ -1607,8 +1620,9 @@ var actions2 = {
1607
1620
  store2.setKey("loading", true);
1608
1621
  store2.setKey("providers", []);
1609
1622
  try {
1610
- const { businessId, service } = store2.get();
1611
- const res = await reservationApi.getProviders({ businessId, serviceId: service.id });
1623
+ const config = getGlobalConfig();
1624
+ const { service } = store2.get();
1625
+ const res = await reservationApi.getProviders({ businessId: config.businessId, serviceId: service.id });
1612
1626
  store2.setKey("providers", res.success ? res.data : []);
1613
1627
  } catch (e) {
1614
1628
  console.error("Error loading providers:", e);
@@ -1657,7 +1671,8 @@ var actions2 = {
1657
1671
  store2.setKey("loading", false);
1658
1672
  return;
1659
1673
  }
1660
- const params = { businessId: state.businessId, serviceId: state.service.id, from, to, limit };
1674
+ const config = getGlobalConfig();
1675
+ const params = { businessId: config.businessId, serviceId: state.service.id, from, to, limit };
1661
1676
  if (state.selectedProvider) params.providerId = state.selectedProvider.id;
1662
1677
  const result = await reservationApi.getAvailableSlots(params);
1663
1678
  if (!result.success) {
@@ -1930,9 +1945,10 @@ var actions2 = {
1930
1945
  store2.setKey("loading", true);
1931
1946
  try {
1932
1947
  const token = await this.getGuestToken();
1948
+ const config = getGlobalConfig();
1933
1949
  const result = await reservationApi.checkout({
1934
1950
  token,
1935
- businessId: state.businessId,
1951
+ businessId: config.businessId,
1936
1952
  blocks: reservationBlocks3 || [],
1937
1953
  parts: state.parts,
1938
1954
  paymentMethod,
@@ -1973,9 +1989,10 @@ var actions2 = {
1973
1989
  const market = marketObj?.id || "us";
1974
1990
  const curr = currency.get() || "USD";
1975
1991
  console.log("Calling reservationApi.getQuote with:", { market, currency: curr, promoCode });
1992
+ const config = getGlobalConfig();
1976
1993
  const result = await reservationApi.getQuote({
1977
1994
  token,
1978
- businessId: state.businessId,
1995
+ businessId: config.businessId,
1979
1996
  market,
1980
1997
  currency: curr,
1981
1998
  userId: token,