arky-sdk 0.3.76 → 0.3.78

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.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { UpdateUserProfileParams, RequestOptions, DeleteUserParams, AddPhoneNumberParams, PhoneNumberConfirmParams, GetMeParams, SearchUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, LogoutParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, UserSubscribeParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessesParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionPlansParams, GetSubscriptionParams, SubscribeParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, GetBusinessMediaParams2, SetProviderScheduleParams, ProcessRefundParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, UpdateMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GenerateBlocksParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, GetCollectionSubscribersParams, CreateProductParams, UpdateProductParams, DeleteProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetAvailableSlotsParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, CreateFeatureFlagParams, FeatureFlag, GetFeatureFlagParams, GetFeatureFlagsParams, UpdateFeatureFlagParams, DeleteFeatureFlagParams, GetFeatureFlagResultsParams, FlagResults, GetVariantParams, GetVariantResponse, TrackEventParams, TrackEventResponse } from './types.cjs';
2
- export { ApiResponse, Block, Business, BusinessConfig, EshopCartItem, EshopStoreState, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.cjs';
1
+ import * as nanostores from 'nanostores';
2
+ import { ProviderWithTimeline, Slot, UpdateUserProfileParams, RequestOptions, DeleteUserParams, AddPhoneNumberParams, PhoneNumberConfirmParams, GetMeParams, SearchUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, LogoutParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, UserSubscribeParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessesParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionPlansParams, GetSubscriptionParams, SubscribeParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, GetBusinessMediaParams2, SetProviderScheduleParams, ProcessRefundParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, UpdateMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GenerateBlocksParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, GetCollectionSubscribersParams, CreateProductParams, UpdateProductParams, DeleteProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetServiceProvidersParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, CreateFeatureFlagParams, FeatureFlag, GetFeatureFlagParams, GetFeatureFlagsParams, UpdateFeatureFlagParams, DeleteFeatureFlagParams, GetFeatureFlagResultsParams, FlagResults, GetVariantParams, GetVariantResponse, TrackEventParams, TrackEventResponse } from './types.cjs';
3
+ export { ApiResponse, Block, Business, BusinessConfig, DayAvailability, EshopCartItem, EshopStoreState, GetAvailabilityParams, GetSlotsForDateParams, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.cjs';
3
4
  import { e as extractBlockValues, g as getBlockLabel, a as getBlockTextValue, f as formatBlockValue, p as prepareBlocksForSubmission, b as getMarketPrice, c as getPriceAmount, d as formatPayment, h as formatMinor, i as createPaymentForCheckout, j as getCurrencySymbol, v as validatePhoneNumber, k as findTimeZone, s as slugify, l as humanize, m as categorify, n as formatDate, o as getSvgContentForAstro, q as fetchSvgContent, r as injectSvgIntoElement } from './svg-3F_m7296.cjs';
4
5
 
5
6
  interface AuthTokens {
@@ -44,7 +45,36 @@ interface RunScriptResponse {
44
45
  message: string;
45
46
  }
46
47
 
47
- declare const SDK_VERSION = "0.3.73";
48
+ interface CalendarDay {
49
+ date: Date;
50
+ iso: string;
51
+ available: boolean;
52
+ isSelected: boolean;
53
+ isInRange: boolean;
54
+ isToday: boolean;
55
+ blank: boolean;
56
+ }
57
+ interface ReservationEngineState {
58
+ service: any | null;
59
+ providers: ProviderWithTimeline[];
60
+ selectedProvider: ProviderWithTimeline | null;
61
+ selectedMethod: string | null;
62
+ currentMonth: Date;
63
+ calendar: CalendarDay[];
64
+ selectedDate: string | null;
65
+ startDate: string | null;
66
+ endDate: string | null;
67
+ slots: Slot[];
68
+ selectedSlot: Slot | null;
69
+ cart: Slot[];
70
+ timezone: string;
71
+ loading: boolean;
72
+ }
73
+ interface ReservationEngineConfig {
74
+ timezone?: string;
75
+ }
76
+
77
+ declare const SDK_VERSION = "0.3.78";
48
78
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
49
79
  interface ApiConfig {
50
80
  httpClient: any;
@@ -156,9 +186,13 @@ declare function createArkySDK(config: HttpClientConfig & {
156
186
  checkout(params: CheckoutParams, options?: RequestOptions): Promise<any>;
157
187
  };
158
188
  reservation: {
189
+ addToCart(slot: Slot): void;
190
+ removeFromCart(slotId: string): void;
191
+ getCart(): Slot[];
192
+ clearCart(): void;
159
193
  createReservation(params: CreateReservationParams, options?: RequestOptions): Promise<any>;
160
194
  updateReservation(params: UpdateReservationParams, options?: RequestOptions): Promise<any>;
161
- checkout(params: ReservationCheckoutParams, options?: RequestOptions): Promise<any>;
195
+ checkout(params?: Partial<ReservationCheckoutParams>, options?: RequestOptions): Promise<any>;
162
196
  getReservation(params: GetReservationParams, options?: RequestOptions): Promise<any>;
163
197
  searchReservations(params: SearchReservationsParams, options?: RequestOptions): Promise<any>;
164
198
  searchMyReservations(params: SearchMyReservationsParams, options?: RequestOptions): Promise<any>;
@@ -168,7 +202,7 @@ declare function createArkySDK(config: HttpClientConfig & {
168
202
  deleteService(params: DeleteServiceParams, options?: RequestOptions): Promise<any>;
169
203
  getService(params: GetServiceParams, options?: RequestOptions): Promise<any>;
170
204
  getServices(params: GetServicesParams, options?: RequestOptions): Promise<any>;
171
- getAvailableSlots(params: GetAvailableSlotsParams, options?: RequestOptions): Promise<any>;
205
+ getServiceProviders(params: GetServiceProvidersParams, options?: RequestOptions): Promise<any>;
172
206
  createProvider(params: CreateProviderParams, options?: RequestOptions): Promise<any>;
173
207
  updateProvider(params: UpdateProviderParams, options?: RequestOptions): Promise<any>;
174
208
  deleteProvider(params: DeleteProviderParams, options?: RequestOptions): Promise<any>;
@@ -203,6 +237,33 @@ declare function createArkySDK(config: HttpClientConfig & {
203
237
  activateFlag(id: string): Promise<FeatureFlag>;
204
238
  archiveFlag(id: string): Promise<FeatureFlag>;
205
239
  };
240
+ reservationEngine: (engineConfig?: ReservationEngineConfig) => {
241
+ setTimezone(tz: string): void;
242
+ setService(serviceId: string): Promise<void>;
243
+ loadMonth(): Promise<void>;
244
+ prevMonth(): void;
245
+ nextMonth(): void;
246
+ selectMethod(method: string): void;
247
+ selectProvider(provider: ProviderWithTimeline | null): void;
248
+ selectDate(day: CalendarDay): void;
249
+ selectSlot(slot: Slot): void;
250
+ findFirstAvailable(): void;
251
+ updateCalendar(): void;
252
+ addToCart(): void;
253
+ removeFromCart(slotId: string): void;
254
+ clearCart(): void;
255
+ checkout(options?: {
256
+ paymentMethod?: string;
257
+ blocks?: any[];
258
+ promoCode?: string;
259
+ }): Promise<any>;
260
+ getQuote(options?: {
261
+ paymentMethod?: string;
262
+ promoCode?: string;
263
+ }): Promise<any>;
264
+ getProvidersList(): Promise<any[]>;
265
+ store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
266
+ };
206
267
  setBusinessId: (businessId: string) => void;
207
268
  getBusinessId: () => string;
208
269
  setMarket: (market: string) => void;
@@ -249,4 +310,4 @@ declare function createArkySDK(config: HttpClientConfig & {
249
310
  };
250
311
  }>;
251
312
 
252
- export { type ApiConfig, type HttpClientConfig, SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
313
+ export { type ApiConfig, type CalendarDay, type HttpClientConfig, ProviderWithTimeline, type ReservationEngineConfig, type ReservationEngineState, SDK_VERSION, SUPPORTED_FRAMEWORKS, Slot, createArkySDK };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { UpdateUserProfileParams, RequestOptions, DeleteUserParams, AddPhoneNumberParams, PhoneNumberConfirmParams, GetMeParams, SearchUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, LogoutParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, UserSubscribeParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessesParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionPlansParams, GetSubscriptionParams, SubscribeParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, GetBusinessMediaParams2, SetProviderScheduleParams, ProcessRefundParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, UpdateMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GenerateBlocksParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, GetCollectionSubscribersParams, CreateProductParams, UpdateProductParams, DeleteProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetAvailableSlotsParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, CreateFeatureFlagParams, FeatureFlag, GetFeatureFlagParams, GetFeatureFlagsParams, UpdateFeatureFlagParams, DeleteFeatureFlagParams, GetFeatureFlagResultsParams, FlagResults, GetVariantParams, GetVariantResponse, TrackEventParams, TrackEventResponse } from './types.js';
2
- export { ApiResponse, Block, Business, BusinessConfig, EshopCartItem, EshopStoreState, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.js';
1
+ import * as nanostores from 'nanostores';
2
+ import { ProviderWithTimeline, Slot, UpdateUserProfileParams, RequestOptions, DeleteUserParams, AddPhoneNumberParams, PhoneNumberConfirmParams, GetMeParams, SearchUsersParams, SetRoleParams, LoginUserParams, RegisterUserParams, LogoutParams, ConfirmUserParams, GetLoginUrlParams, ForgotPasswordParams, ResetForgotPasswordParams, ResetPasswordParams, UserSubscribeParams, CreateBusinessParams, UpdateBusinessParams, DeleteBusinessParams, GetBusinessParams, GetBusinessesParams, GetBusinessParentsParams, TriggerBuildsParams, GetSubscriptionPlansParams, GetSubscriptionParams, SubscribeParams, CreatePortalSessionParams, InviteUserParams, HandleInvitationParams, TestWebhookParams, GetBusinessMediaParams2, SetProviderScheduleParams, ProcessRefundParams, UploadBusinessMediaParams, DeleteBusinessMediaParams, GetBusinessMediaParams, UpdateMediaParams, CreateRoleParams, UpdateRoleParams, DeleteRoleParams, GetRoleParams, GetRolesParams, TrackEmailOpenParams, GetDeliveryStatsParams, CreatePromoCodeParams, UpdatePromoCodeParams, DeletePromoCodeParams, GetPromoCodeParams, GetPromoCodesParams, GetAnalyticsParams, CreateCollectionParams, UpdateCollectionParams, DeleteCollectionParams, GetCollectionParams, GetCollectionsParams, GenerateBlocksParams, GetEntriesParams, CreateEntryParams, UpdateEntryParams, DeleteCollectionEntryParams, GetCollectionEntryParams, SendEntryParams, GetVariableMetadataParams, GetCollectionSubscribersParams, CreateProductParams, UpdateProductParams, DeleteProductParams, GetProductParams, GetProductsParams, CreateOrderParams, UpdateOrderParams, GetOrderParams, GetOrdersParams, UpdateOrderStatusParams, UpdateOrderPaymentStatusParams, GetQuoteParams, CheckoutParams, CreateReservationParams, UpdateReservationParams, ReservationCheckoutParams, GetReservationParams, SearchReservationsParams, SearchMyReservationsParams, GetReservationQuoteParams, CreateServiceParams, UpdateServiceParams, DeleteServiceParams, GetServiceParams, GetServicesParams, GetServiceProvidersParams, CreateProviderParams, UpdateProviderParams, DeleteProviderParams, GetProviderParams, GetProvidersParams, GetBusinessServiceWorkingTimeParams, CreateFeatureFlagParams, FeatureFlag, GetFeatureFlagParams, GetFeatureFlagsParams, UpdateFeatureFlagParams, DeleteFeatureFlagParams, GetFeatureFlagResultsParams, FlagResults, GetVariantParams, GetVariantResponse, TrackEventParams, TrackEventResponse } from './types.js';
3
+ export { ApiResponse, Block, Business, BusinessConfig, DayAvailability, EshopCartItem, EshopStoreState, GetAvailabilityParams, GetSlotsForDateParams, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.js';
3
4
  import { e as extractBlockValues, g as getBlockLabel, a as getBlockTextValue, f as formatBlockValue, p as prepareBlocksForSubmission, b as getMarketPrice, c as getPriceAmount, d as formatPayment, h as formatMinor, i as createPaymentForCheckout, j as getCurrencySymbol, v as validatePhoneNumber, k as findTimeZone, s as slugify, l as humanize, m as categorify, n as formatDate, o as getSvgContentForAstro, q as fetchSvgContent, r as injectSvgIntoElement } from './svg-4hIdMU6f.js';
4
5
 
5
6
  interface AuthTokens {
@@ -44,7 +45,36 @@ interface RunScriptResponse {
44
45
  message: string;
45
46
  }
46
47
 
47
- declare const SDK_VERSION = "0.3.73";
48
+ interface CalendarDay {
49
+ date: Date;
50
+ iso: string;
51
+ available: boolean;
52
+ isSelected: boolean;
53
+ isInRange: boolean;
54
+ isToday: boolean;
55
+ blank: boolean;
56
+ }
57
+ interface ReservationEngineState {
58
+ service: any | null;
59
+ providers: ProviderWithTimeline[];
60
+ selectedProvider: ProviderWithTimeline | null;
61
+ selectedMethod: string | null;
62
+ currentMonth: Date;
63
+ calendar: CalendarDay[];
64
+ selectedDate: string | null;
65
+ startDate: string | null;
66
+ endDate: string | null;
67
+ slots: Slot[];
68
+ selectedSlot: Slot | null;
69
+ cart: Slot[];
70
+ timezone: string;
71
+ loading: boolean;
72
+ }
73
+ interface ReservationEngineConfig {
74
+ timezone?: string;
75
+ }
76
+
77
+ declare const SDK_VERSION = "0.3.78";
48
78
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
49
79
  interface ApiConfig {
50
80
  httpClient: any;
@@ -156,9 +186,13 @@ declare function createArkySDK(config: HttpClientConfig & {
156
186
  checkout(params: CheckoutParams, options?: RequestOptions): Promise<any>;
157
187
  };
158
188
  reservation: {
189
+ addToCart(slot: Slot): void;
190
+ removeFromCart(slotId: string): void;
191
+ getCart(): Slot[];
192
+ clearCart(): void;
159
193
  createReservation(params: CreateReservationParams, options?: RequestOptions): Promise<any>;
160
194
  updateReservation(params: UpdateReservationParams, options?: RequestOptions): Promise<any>;
161
- checkout(params: ReservationCheckoutParams, options?: RequestOptions): Promise<any>;
195
+ checkout(params?: Partial<ReservationCheckoutParams>, options?: RequestOptions): Promise<any>;
162
196
  getReservation(params: GetReservationParams, options?: RequestOptions): Promise<any>;
163
197
  searchReservations(params: SearchReservationsParams, options?: RequestOptions): Promise<any>;
164
198
  searchMyReservations(params: SearchMyReservationsParams, options?: RequestOptions): Promise<any>;
@@ -168,7 +202,7 @@ declare function createArkySDK(config: HttpClientConfig & {
168
202
  deleteService(params: DeleteServiceParams, options?: RequestOptions): Promise<any>;
169
203
  getService(params: GetServiceParams, options?: RequestOptions): Promise<any>;
170
204
  getServices(params: GetServicesParams, options?: RequestOptions): Promise<any>;
171
- getAvailableSlots(params: GetAvailableSlotsParams, options?: RequestOptions): Promise<any>;
205
+ getServiceProviders(params: GetServiceProvidersParams, options?: RequestOptions): Promise<any>;
172
206
  createProvider(params: CreateProviderParams, options?: RequestOptions): Promise<any>;
173
207
  updateProvider(params: UpdateProviderParams, options?: RequestOptions): Promise<any>;
174
208
  deleteProvider(params: DeleteProviderParams, options?: RequestOptions): Promise<any>;
@@ -203,6 +237,33 @@ declare function createArkySDK(config: HttpClientConfig & {
203
237
  activateFlag(id: string): Promise<FeatureFlag>;
204
238
  archiveFlag(id: string): Promise<FeatureFlag>;
205
239
  };
240
+ reservationEngine: (engineConfig?: ReservationEngineConfig) => {
241
+ setTimezone(tz: string): void;
242
+ setService(serviceId: string): Promise<void>;
243
+ loadMonth(): Promise<void>;
244
+ prevMonth(): void;
245
+ nextMonth(): void;
246
+ selectMethod(method: string): void;
247
+ selectProvider(provider: ProviderWithTimeline | null): void;
248
+ selectDate(day: CalendarDay): void;
249
+ selectSlot(slot: Slot): void;
250
+ findFirstAvailable(): void;
251
+ updateCalendar(): void;
252
+ addToCart(): void;
253
+ removeFromCart(slotId: string): void;
254
+ clearCart(): void;
255
+ checkout(options?: {
256
+ paymentMethod?: string;
257
+ blocks?: any[];
258
+ promoCode?: string;
259
+ }): Promise<any>;
260
+ getQuote(options?: {
261
+ paymentMethod?: string;
262
+ promoCode?: string;
263
+ }): Promise<any>;
264
+ getProvidersList(): Promise<any[]>;
265
+ store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
266
+ };
206
267
  setBusinessId: (businessId: string) => void;
207
268
  getBusinessId: () => string;
208
269
  setMarket: (market: string) => void;
@@ -249,4 +310,4 @@ declare function createArkySDK(config: HttpClientConfig & {
249
310
  };
250
311
  }>;
251
312
 
252
- export { type ApiConfig, type HttpClientConfig, SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
313
+ export { type ApiConfig, type CalendarDay, type HttpClientConfig, ProviderWithTimeline, type ReservationEngineConfig, type ReservationEngineState, SDK_VERSION, SUPPORTED_FRAMEWORKS, Slot, createArkySDK };
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { map } from 'nanostores';
2
+
1
3
  // src/types/index.ts
2
4
  var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
3
5
  PaymentMethodType2["Cash"] = "CASH";
@@ -978,7 +980,21 @@ var createEshopApi = (apiConfig) => {
978
980
 
979
981
  // src/api/reservation.ts
980
982
  var createReservationApi = (apiConfig) => {
983
+ let cart = [];
981
984
  return {
985
+ // ===== CART =====
986
+ addToCart(slot) {
987
+ cart.push(slot);
988
+ },
989
+ removeFromCart(slotId) {
990
+ cart = cart.filter((s) => s.id !== slotId);
991
+ },
992
+ getCart() {
993
+ return [...cart];
994
+ },
995
+ clearCart() {
996
+ cart = [];
997
+ },
982
998
  // ===== RESERVATIONS =====
983
999
  async createReservation(params, options) {
984
1000
  const payload = {
@@ -997,16 +1013,25 @@ var createReservationApi = (apiConfig) => {
997
1013
  );
998
1014
  },
999
1015
  async checkout(params, options) {
1016
+ const items = params?.items || cart.map((s) => ({
1017
+ serviceId: s.serviceId,
1018
+ providerId: s.providerId,
1019
+ from: s.from,
1020
+ to: s.to
1021
+ }));
1000
1022
  const payload = {
1001
1023
  businessId: apiConfig.businessId,
1002
1024
  market: apiConfig.market,
1003
- ...params
1025
+ ...params,
1026
+ items
1004
1027
  };
1005
- return apiConfig.httpClient.post(
1028
+ const result = await apiConfig.httpClient.post(
1006
1029
  `/v1/reservations/checkout`,
1007
1030
  payload,
1008
1031
  options
1009
1032
  );
1033
+ cart = [];
1034
+ return result;
1010
1035
  },
1011
1036
  async getReservation(params, options) {
1012
1037
  return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
@@ -1093,16 +1118,13 @@ var createReservationApi = (apiConfig) => {
1093
1118
  }
1094
1119
  );
1095
1120
  },
1096
- async getAvailableSlots(params, options) {
1121
+ async getServiceProviders(params, options) {
1097
1122
  const { serviceId, ...queryParams } = params;
1098
1123
  return apiConfig.httpClient.get(
1099
- `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
1124
+ `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/providers`,
1100
1125
  {
1101
1126
  ...options,
1102
- params: {
1103
- ...queryParams,
1104
- limit: queryParams.limit || 1e3
1105
- }
1127
+ params: queryParams
1106
1128
  }
1107
1129
  );
1108
1130
  },
@@ -1676,9 +1698,328 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1676
1698
  console.error("Error injecting SVG:", error);
1677
1699
  }
1678
1700
  }
1701
+ function formatTime(ts, tz) {
1702
+ return new Date(ts * 1e3).toLocaleTimeString([], {
1703
+ hour: "2-digit",
1704
+ minute: "2-digit",
1705
+ timeZone: tz
1706
+ });
1707
+ }
1708
+ function formatSlotTime(from, to, tz) {
1709
+ return `${formatTime(from, tz)} \u2013 ${formatTime(to, tz)}`;
1710
+ }
1711
+ function getTzOffset(date, tz) {
1712
+ const utc = new Date(date.toLocaleString("en-US", { timeZone: "UTC" }));
1713
+ const local = new Date(date.toLocaleString("en-US", { timeZone: tz }));
1714
+ return (utc.getTime() - local.getTime()) / 6e4;
1715
+ }
1716
+ function toUtcTimestamp(year, month, day, mins, tz) {
1717
+ const midnight = new Date(Date.UTC(year, month - 1, day));
1718
+ const offset = getTzOffset(midnight, tz);
1719
+ return Math.floor(midnight.getTime() / 1e3) + (mins + offset) * 60;
1720
+ }
1721
+ function isBlocked(from, to, timeline, limit) {
1722
+ const before = timeline.filter((p) => p.timestamp <= from).sort((a, b) => b.timestamp - a.timestamp);
1723
+ if (before.length > 0 && before[0].concurrent >= limit) return true;
1724
+ for (const p of timeline) {
1725
+ if (p.timestamp >= from && p.timestamp < to && p.concurrent >= limit) return true;
1726
+ }
1727
+ return false;
1728
+ }
1729
+ function getTotalDuration(durations) {
1730
+ return durations.reduce((sum, d) => sum + d.duration, 0);
1731
+ }
1732
+ function getWorkingHoursForDate(wt, date, tz) {
1733
+ if (!wt) return [];
1734
+ const dayName = date.toLocaleDateString("en-US", { weekday: "long", timeZone: tz }).toLowerCase();
1735
+ const m = date.getMonth() + 1;
1736
+ const d = date.getDate();
1737
+ const ts = Math.floor(date.getTime() / 1e3);
1738
+ const specific = wt.specificDates?.find((s) => s.date === ts);
1739
+ if (specific) return specific.workingHours || [];
1740
+ const outcast = wt.outcastDates?.find((o) => o.month === m && o.day === d);
1741
+ if (outcast) return outcast.workingHours || [];
1742
+ return wt.workingDays?.find((w) => w.day === dayName)?.workingHours || [];
1743
+ }
1744
+ function computeSlotsForDate(opts) {
1745
+ const { providers, date, durations, timezone, slotInterval } = opts;
1746
+ const total = getTotalDuration(durations);
1747
+ const interval = slotInterval || total;
1748
+ const slots = [];
1749
+ const nowTs = Math.floor(Date.now() / 1e3);
1750
+ const today = /* @__PURE__ */ new Date();
1751
+ today.setHours(0, 0, 0, 0);
1752
+ if (date < today) return [];
1753
+ const [year, month, day] = date.toLocaleDateString("en-CA", { timeZone: timezone }).split("-").map(Number);
1754
+ for (const p of providers) {
1755
+ for (const wh of getWorkingHoursForDate(p.workingTime, date, timezone)) {
1756
+ for (let m = wh.from; m + total <= wh.to; m += interval) {
1757
+ const from = toUtcTimestamp(year, month, day, m, timezone);
1758
+ const to = from + total * 60;
1759
+ if (from < nowTs) continue;
1760
+ if (!isBlocked(from, to, p.timeline, p.concurrentLimit)) {
1761
+ slots.push({ from, to, providerId: p.id });
1762
+ }
1763
+ }
1764
+ }
1765
+ }
1766
+ return slots.sort((a, b) => a.from - b.from);
1767
+ }
1768
+ function hasAvailableSlots(opts) {
1769
+ return computeSlotsForDate(opts).length > 0;
1770
+ }
1771
+ var createInitialState = (timezone) => ({
1772
+ service: null,
1773
+ providers: [],
1774
+ selectedProvider: null,
1775
+ selectedMethod: null,
1776
+ currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
1777
+ calendar: [],
1778
+ selectedDate: null,
1779
+ startDate: null,
1780
+ endDate: null,
1781
+ slots: [],
1782
+ selectedSlot: null,
1783
+ cart: [],
1784
+ timezone,
1785
+ loading: false
1786
+ });
1787
+ var createReservationEngine = (api, config = {}) => {
1788
+ const timezone = config.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone;
1789
+ const store = map(createInitialState(timezone));
1790
+ const getServiceDurations = () => {
1791
+ const state = store.get();
1792
+ if (!state.service?.durations?.length) return [{ duration: 60, isPause: false }];
1793
+ return state.service.durations.map((d) => ({
1794
+ duration: d.duration,
1795
+ isPause: d.isPause || d.is_pause || false
1796
+ }));
1797
+ };
1798
+ const buildCalendar = () => {
1799
+ const state = store.get();
1800
+ const { currentMonth, selectedDate, startDate, endDate, providers, selectedProvider, timezone: timezone2 } = state;
1801
+ const year = currentMonth.getFullYear();
1802
+ const month = currentMonth.getMonth();
1803
+ const first = new Date(year, month, 1);
1804
+ const last = new Date(year, month + 1, 0);
1805
+ const today = /* @__PURE__ */ new Date();
1806
+ today.setHours(0, 0, 0, 0);
1807
+ const cells = [];
1808
+ const pad = (first.getDay() + 6) % 7;
1809
+ for (let i = 0; i < pad; i++) {
1810
+ cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
1811
+ }
1812
+ const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1813
+ const durations = getServiceDurations();
1814
+ for (let d = 1; d <= last.getDate(); d++) {
1815
+ const date = new Date(year, month, d);
1816
+ const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1817
+ const available = activeProviders.length > 0 && hasAvailableSlots({ providers: activeProviders, date, durations, timezone: timezone2 });
1818
+ const isToday = date.getTime() === today.getTime();
1819
+ const isSelected = iso === selectedDate || iso === startDate || iso === endDate;
1820
+ let isInRange = false;
1821
+ if (startDate && endDate) {
1822
+ const t = date.getTime();
1823
+ isInRange = t > new Date(startDate).getTime() && t < new Date(endDate).getTime();
1824
+ }
1825
+ cells.push({ date, iso, available, isSelected, isInRange, isToday, blank: false });
1826
+ }
1827
+ const suffix = (7 - cells.length % 7) % 7;
1828
+ for (let i = 0; i < suffix; i++) {
1829
+ cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
1830
+ }
1831
+ return cells;
1832
+ };
1833
+ const computeSlots = (dateStr) => {
1834
+ const state = store.get();
1835
+ const { providers, selectedProvider, timezone: timezone2, service } = state;
1836
+ const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
1837
+ const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1838
+ const raw = computeSlotsForDate({ providers: activeProviders, date, durations: getServiceDurations(), timezone: timezone2 });
1839
+ return raw.map((s, i) => ({
1840
+ id: `${service?.id}-${s.from}-${i}`,
1841
+ serviceId: service?.id || "",
1842
+ providerId: s.providerId,
1843
+ from: s.from,
1844
+ to: s.to,
1845
+ timeText: formatSlotTime(s.from, s.to, timezone2),
1846
+ dateText: new Date(s.from * 1e3).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric", timeZone: timezone2 })
1847
+ }));
1848
+ };
1849
+ const actions = {
1850
+ setTimezone(tz) {
1851
+ store.setKey("timezone", tz);
1852
+ store.setKey("calendar", buildCalendar());
1853
+ const state = store.get();
1854
+ if (state.selectedDate) {
1855
+ store.setKey("slots", computeSlots(state.selectedDate));
1856
+ store.setKey("selectedSlot", null);
1857
+ }
1858
+ },
1859
+ async setService(serviceId) {
1860
+ store.setKey("loading", true);
1861
+ try {
1862
+ const service = await api.getService({ id: serviceId });
1863
+ store.set({
1864
+ ...store.get(),
1865
+ service,
1866
+ selectedMethod: service.reservationMethods?.length === 1 ? service.reservationMethods[0] : null,
1867
+ selectedProvider: null,
1868
+ providers: [],
1869
+ selectedDate: null,
1870
+ startDate: null,
1871
+ endDate: null,
1872
+ slots: [],
1873
+ selectedSlot: null,
1874
+ currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
1875
+ loading: false
1876
+ });
1877
+ await actions.loadMonth();
1878
+ } catch (e) {
1879
+ store.setKey("loading", false);
1880
+ throw e;
1881
+ }
1882
+ },
1883
+ async loadMonth() {
1884
+ const state = store.get();
1885
+ if (!state.service) return;
1886
+ store.setKey("loading", true);
1887
+ try {
1888
+ const { currentMonth, service } = state;
1889
+ const year = currentMonth.getFullYear();
1890
+ const month = currentMonth.getMonth();
1891
+ const from = Math.floor(new Date(year, month, 1).getTime() / 1e3);
1892
+ const to = Math.floor(new Date(year, month + 1, 0, 23, 59, 59).getTime() / 1e3);
1893
+ const providers = await api.getServiceProviders({ serviceId: service.id, from, to });
1894
+ store.setKey("providers", providers || []);
1895
+ store.setKey("calendar", buildCalendar());
1896
+ } finally {
1897
+ store.setKey("loading", false);
1898
+ }
1899
+ },
1900
+ prevMonth() {
1901
+ const { currentMonth } = store.get();
1902
+ store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
1903
+ actions.loadMonth();
1904
+ },
1905
+ nextMonth() {
1906
+ const { currentMonth } = store.get();
1907
+ store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
1908
+ actions.loadMonth();
1909
+ },
1910
+ selectMethod(method) {
1911
+ store.set({
1912
+ ...store.get(),
1913
+ selectedMethod: method,
1914
+ selectedProvider: null,
1915
+ selectedDate: null,
1916
+ startDate: null,
1917
+ endDate: null,
1918
+ slots: [],
1919
+ selectedSlot: null
1920
+ });
1921
+ store.setKey("calendar", buildCalendar());
1922
+ },
1923
+ selectProvider(provider) {
1924
+ store.set({
1925
+ ...store.get(),
1926
+ selectedProvider: provider,
1927
+ selectedDate: null,
1928
+ startDate: null,
1929
+ endDate: null,
1930
+ slots: [],
1931
+ selectedSlot: null
1932
+ });
1933
+ store.setKey("calendar", buildCalendar());
1934
+ },
1935
+ selectDate(day) {
1936
+ if (day.blank || !day.available) return;
1937
+ const state = store.get();
1938
+ const slots = computeSlots(day.iso);
1939
+ store.set({ ...state, selectedDate: day.iso, slots, selectedSlot: null });
1940
+ store.setKey("calendar", buildCalendar());
1941
+ },
1942
+ selectSlot(slot) {
1943
+ store.setKey("selectedSlot", slot);
1944
+ },
1945
+ findFirstAvailable() {
1946
+ const state = store.get();
1947
+ for (const day of state.calendar) {
1948
+ if (!day.blank && day.available) {
1949
+ actions.selectDate(day);
1950
+ return;
1951
+ }
1952
+ }
1953
+ },
1954
+ updateCalendar() {
1955
+ store.setKey("calendar", buildCalendar());
1956
+ },
1957
+ addToCart() {
1958
+ const state = store.get();
1959
+ if (!state.selectedSlot) return;
1960
+ store.set({
1961
+ ...state,
1962
+ cart: [...state.cart, state.selectedSlot],
1963
+ selectedDate: null,
1964
+ startDate: null,
1965
+ endDate: null,
1966
+ slots: [],
1967
+ selectedSlot: null
1968
+ });
1969
+ store.setKey("calendar", buildCalendar());
1970
+ },
1971
+ removeFromCart(slotId) {
1972
+ const state = store.get();
1973
+ store.setKey("cart", state.cart.filter((s) => s.id !== slotId));
1974
+ },
1975
+ clearCart() {
1976
+ store.setKey("cart", []);
1977
+ },
1978
+ async checkout(options = {}) {
1979
+ const state = store.get();
1980
+ if (!state.cart.length) throw new Error("Cart is empty");
1981
+ store.setKey("loading", true);
1982
+ try {
1983
+ const result = await api.checkout({
1984
+ items: state.cart.map((s) => ({
1985
+ serviceId: s.serviceId,
1986
+ providerId: s.providerId,
1987
+ from: s.from,
1988
+ to: s.to,
1989
+ blocks: s.serviceBlocks || [],
1990
+ reservationMethod: s.reservationMethod || state.selectedMethod || "STANDARD"
1991
+ })),
1992
+ paymentMethod: options.paymentMethod,
1993
+ promoCode: options.promoCode ?? null,
1994
+ blocks: options.blocks || []
1995
+ });
1996
+ store.setKey("cart", []);
1997
+ return result;
1998
+ } finally {
1999
+ store.setKey("loading", false);
2000
+ }
2001
+ },
2002
+ async getQuote(options = {}) {
2003
+ const state = store.get();
2004
+ if (!state.cart.length) return null;
2005
+ return api.getQuote({
2006
+ items: state.cart.map((s) => ({ serviceId: s.serviceId })),
2007
+ paymentMethod: options.paymentMethod || "CASH",
2008
+ promoCode: options.promoCode
2009
+ });
2010
+ },
2011
+ async getProvidersList() {
2012
+ const state = store.get();
2013
+ if (!state.service) return [];
2014
+ const response = await api.getProviders({ serviceId: state.service.id, limit: 100 });
2015
+ return response?.items || [];
2016
+ }
2017
+ };
2018
+ return { store, ...actions };
2019
+ };
1679
2020
 
1680
2021
  // src/index.ts
1681
- var SDK_VERSION = "0.3.73";
2022
+ var SDK_VERSION = "0.3.78";
1682
2023
  var SUPPORTED_FRAMEWORKS = [
1683
2024
  "astro",
1684
2025
  "react",
@@ -1728,6 +2069,11 @@ async function createArkySDK(config) {
1728
2069
  reservation: createReservationApi(apiConfig),
1729
2070
  database: createDatabaseApi(apiConfig),
1730
2071
  featureFlags: createFeatureFlagsApi(apiConfig),
2072
+ // High-level reservation engine
2073
+ reservationEngine: (engineConfig) => {
2074
+ const reservationApi = createReservationApi(apiConfig);
2075
+ return createReservationEngine(reservationApi, engineConfig);
2076
+ },
1731
2077
  setBusinessId: (businessId) => {
1732
2078
  apiConfig.businessId = businessId;
1733
2079
  },