arky-sdk 0.3.77 → 0.3.79

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, GetServiceProvidersParams, 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,35 @@ 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
+ currentMonth: Date;
62
+ calendar: CalendarDay[];
63
+ selectedDate: string | null;
64
+ startDate: string | null;
65
+ endDate: string | null;
66
+ slots: Slot[];
67
+ selectedSlot: Slot | null;
68
+ cart: Slot[];
69
+ timezone: string;
70
+ loading: boolean;
71
+ }
72
+ interface ReservationEngineConfig {
73
+ timezone?: string;
74
+ }
75
+
76
+ declare const SDK_VERSION = "0.3.78";
48
77
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
49
78
  interface ApiConfig {
50
79
  httpClient: any;
@@ -156,9 +185,13 @@ declare function createArkySDK(config: HttpClientConfig & {
156
185
  checkout(params: CheckoutParams, options?: RequestOptions): Promise<any>;
157
186
  };
158
187
  reservation: {
188
+ addToCart(slot: Slot): void;
189
+ removeFromCart(slotId: string): void;
190
+ getCart(): Slot[];
191
+ clearCart(): void;
159
192
  createReservation(params: CreateReservationParams, options?: RequestOptions): Promise<any>;
160
193
  updateReservation(params: UpdateReservationParams, options?: RequestOptions): Promise<any>;
161
- checkout(params: ReservationCheckoutParams, options?: RequestOptions): Promise<any>;
194
+ checkout(params?: Partial<ReservationCheckoutParams>, options?: RequestOptions): Promise<any>;
162
195
  getReservation(params: GetReservationParams, options?: RequestOptions): Promise<any>;
163
196
  searchReservations(params: SearchReservationsParams, options?: RequestOptions): Promise<any>;
164
197
  searchMyReservations(params: SearchMyReservationsParams, options?: RequestOptions): Promise<any>;
@@ -168,7 +201,6 @@ declare function createArkySDK(config: HttpClientConfig & {
168
201
  deleteService(params: DeleteServiceParams, options?: RequestOptions): Promise<any>;
169
202
  getService(params: GetServiceParams, options?: RequestOptions): Promise<any>;
170
203
  getServices(params: GetServicesParams, options?: RequestOptions): Promise<any>;
171
- getAvailableSlots(params: GetAvailableSlotsParams, options?: RequestOptions): Promise<any>;
172
204
  getServiceProviders(params: GetServiceProvidersParams, options?: RequestOptions): Promise<any>;
173
205
  createProvider(params: CreateProviderParams, options?: RequestOptions): Promise<any>;
174
206
  updateProvider(params: UpdateProviderParams, options?: RequestOptions): Promise<any>;
@@ -204,6 +236,32 @@ declare function createArkySDK(config: HttpClientConfig & {
204
236
  activateFlag(id: string): Promise<FeatureFlag>;
205
237
  archiveFlag(id: string): Promise<FeatureFlag>;
206
238
  };
239
+ reservationEngine: (engineConfig?: ReservationEngineConfig) => {
240
+ setTimezone(tz: string): void;
241
+ setService(serviceId: string): Promise<void>;
242
+ loadMonth(): Promise<void>;
243
+ prevMonth(): void;
244
+ nextMonth(): void;
245
+ selectProvider(provider: ProviderWithTimeline | null): void;
246
+ selectDate(day: CalendarDay): void;
247
+ selectSlot(slot: Slot): void;
248
+ findFirstAvailable(): void;
249
+ updateCalendar(): void;
250
+ addToCart(): void;
251
+ removeFromCart(slotId: string): void;
252
+ clearCart(): void;
253
+ checkout(options?: {
254
+ paymentMethod?: string;
255
+ blocks?: any[];
256
+ promoCode?: string;
257
+ }): Promise<any>;
258
+ getQuote(options?: {
259
+ paymentMethod?: string;
260
+ promoCode?: string;
261
+ }): Promise<any>;
262
+ getProvidersList(): Promise<any[]>;
263
+ store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
264
+ };
207
265
  setBusinessId: (businessId: string) => void;
208
266
  getBusinessId: () => string;
209
267
  setMarket: (market: string) => void;
@@ -250,4 +308,4 @@ declare function createArkySDK(config: HttpClientConfig & {
250
308
  };
251
309
  }>;
252
310
 
253
- export { type ApiConfig, type HttpClientConfig, SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
311
+ 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, GetServiceProvidersParams, 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,35 @@ 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
+ currentMonth: Date;
62
+ calendar: CalendarDay[];
63
+ selectedDate: string | null;
64
+ startDate: string | null;
65
+ endDate: string | null;
66
+ slots: Slot[];
67
+ selectedSlot: Slot | null;
68
+ cart: Slot[];
69
+ timezone: string;
70
+ loading: boolean;
71
+ }
72
+ interface ReservationEngineConfig {
73
+ timezone?: string;
74
+ }
75
+
76
+ declare const SDK_VERSION = "0.3.78";
48
77
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
49
78
  interface ApiConfig {
50
79
  httpClient: any;
@@ -156,9 +185,13 @@ declare function createArkySDK(config: HttpClientConfig & {
156
185
  checkout(params: CheckoutParams, options?: RequestOptions): Promise<any>;
157
186
  };
158
187
  reservation: {
188
+ addToCart(slot: Slot): void;
189
+ removeFromCart(slotId: string): void;
190
+ getCart(): Slot[];
191
+ clearCart(): void;
159
192
  createReservation(params: CreateReservationParams, options?: RequestOptions): Promise<any>;
160
193
  updateReservation(params: UpdateReservationParams, options?: RequestOptions): Promise<any>;
161
- checkout(params: ReservationCheckoutParams, options?: RequestOptions): Promise<any>;
194
+ checkout(params?: Partial<ReservationCheckoutParams>, options?: RequestOptions): Promise<any>;
162
195
  getReservation(params: GetReservationParams, options?: RequestOptions): Promise<any>;
163
196
  searchReservations(params: SearchReservationsParams, options?: RequestOptions): Promise<any>;
164
197
  searchMyReservations(params: SearchMyReservationsParams, options?: RequestOptions): Promise<any>;
@@ -168,7 +201,6 @@ declare function createArkySDK(config: HttpClientConfig & {
168
201
  deleteService(params: DeleteServiceParams, options?: RequestOptions): Promise<any>;
169
202
  getService(params: GetServiceParams, options?: RequestOptions): Promise<any>;
170
203
  getServices(params: GetServicesParams, options?: RequestOptions): Promise<any>;
171
- getAvailableSlots(params: GetAvailableSlotsParams, options?: RequestOptions): Promise<any>;
172
204
  getServiceProviders(params: GetServiceProvidersParams, options?: RequestOptions): Promise<any>;
173
205
  createProvider(params: CreateProviderParams, options?: RequestOptions): Promise<any>;
174
206
  updateProvider(params: UpdateProviderParams, options?: RequestOptions): Promise<any>;
@@ -204,6 +236,32 @@ declare function createArkySDK(config: HttpClientConfig & {
204
236
  activateFlag(id: string): Promise<FeatureFlag>;
205
237
  archiveFlag(id: string): Promise<FeatureFlag>;
206
238
  };
239
+ reservationEngine: (engineConfig?: ReservationEngineConfig) => {
240
+ setTimezone(tz: string): void;
241
+ setService(serviceId: string): Promise<void>;
242
+ loadMonth(): Promise<void>;
243
+ prevMonth(): void;
244
+ nextMonth(): void;
245
+ selectProvider(provider: ProviderWithTimeline | null): void;
246
+ selectDate(day: CalendarDay): void;
247
+ selectSlot(slot: Slot): void;
248
+ findFirstAvailable(): void;
249
+ updateCalendar(): void;
250
+ addToCart(): void;
251
+ removeFromCart(slotId: string): void;
252
+ clearCart(): void;
253
+ checkout(options?: {
254
+ paymentMethod?: string;
255
+ blocks?: any[];
256
+ promoCode?: string;
257
+ }): Promise<any>;
258
+ getQuote(options?: {
259
+ paymentMethod?: string;
260
+ promoCode?: string;
261
+ }): Promise<any>;
262
+ getProvidersList(): Promise<any[]>;
263
+ store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
264
+ };
207
265
  setBusinessId: (businessId: string) => void;
208
266
  getBusinessId: () => string;
209
267
  setMarket: (market: string) => void;
@@ -250,4 +308,4 @@ declare function createArkySDK(config: HttpClientConfig & {
250
308
  };
251
309
  }>;
252
310
 
253
- export { type ApiConfig, type HttpClientConfig, SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
311
+ 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,19 +1118,6 @@ var createReservationApi = (apiConfig) => {
1093
1118
  }
1094
1119
  );
1095
1120
  },
1096
- async getAvailableSlots(params, options) {
1097
- const { serviceId, ...queryParams } = params;
1098
- return apiConfig.httpClient.get(
1099
- `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
1100
- {
1101
- ...options,
1102
- params: {
1103
- ...queryParams,
1104
- limit: queryParams.limit || 1e3
1105
- }
1106
- }
1107
- );
1108
- },
1109
1121
  async getServiceProviders(params, options) {
1110
1122
  const { serviceId, ...queryParams } = params;
1111
1123
  return apiConfig.httpClient.get(
@@ -1686,9 +1698,312 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1686
1698
  console.error("Error injecting SVG:", error);
1687
1699
  }
1688
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
+ currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
1776
+ calendar: [],
1777
+ selectedDate: null,
1778
+ startDate: null,
1779
+ endDate: null,
1780
+ slots: [],
1781
+ selectedSlot: null,
1782
+ cart: [],
1783
+ timezone,
1784
+ loading: false
1785
+ });
1786
+ var createReservationEngine = (api, config = {}) => {
1787
+ const timezone = config.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone;
1788
+ const store = map(createInitialState(timezone));
1789
+ const getServiceDurations = () => {
1790
+ const state = store.get();
1791
+ if (!state.service?.durations?.length) return [{ duration: 60, isPause: false }];
1792
+ return state.service.durations.map((d) => ({
1793
+ duration: d.duration,
1794
+ isPause: d.isPause || d.is_pause || false
1795
+ }));
1796
+ };
1797
+ const buildCalendar = () => {
1798
+ const state = store.get();
1799
+ const { currentMonth, selectedDate, startDate, endDate, providers, selectedProvider, timezone: timezone2 } = state;
1800
+ const year = currentMonth.getFullYear();
1801
+ const month = currentMonth.getMonth();
1802
+ const first = new Date(year, month, 1);
1803
+ const last = new Date(year, month + 1, 0);
1804
+ const today = /* @__PURE__ */ new Date();
1805
+ today.setHours(0, 0, 0, 0);
1806
+ const cells = [];
1807
+ const pad = (first.getDay() + 6) % 7;
1808
+ for (let i = 0; i < pad; i++) {
1809
+ cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
1810
+ }
1811
+ const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1812
+ const durations = getServiceDurations();
1813
+ for (let d = 1; d <= last.getDate(); d++) {
1814
+ const date = new Date(year, month, d);
1815
+ const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1816
+ const available = activeProviders.length > 0 && hasAvailableSlots({ providers: activeProviders, date, durations, timezone: timezone2 });
1817
+ const isToday = date.getTime() === today.getTime();
1818
+ const isSelected = iso === selectedDate || iso === startDate || iso === endDate;
1819
+ let isInRange = false;
1820
+ if (startDate && endDate) {
1821
+ const t = date.getTime();
1822
+ isInRange = t > new Date(startDate).getTime() && t < new Date(endDate).getTime();
1823
+ }
1824
+ cells.push({ date, iso, available, isSelected, isInRange, isToday, blank: false });
1825
+ }
1826
+ const suffix = (7 - cells.length % 7) % 7;
1827
+ for (let i = 0; i < suffix; i++) {
1828
+ cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
1829
+ }
1830
+ return cells;
1831
+ };
1832
+ const computeSlots = (dateStr) => {
1833
+ const state = store.get();
1834
+ const { providers, selectedProvider, timezone: timezone2, service } = state;
1835
+ const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
1836
+ const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1837
+ const raw = computeSlotsForDate({ providers: activeProviders, date, durations: getServiceDurations(), timezone: timezone2 });
1838
+ return raw.map((s, i) => ({
1839
+ id: `${service?.id}-${s.from}-${i}`,
1840
+ serviceId: service?.id || "",
1841
+ providerId: s.providerId,
1842
+ from: s.from,
1843
+ to: s.to,
1844
+ timeText: formatSlotTime(s.from, s.to, timezone2),
1845
+ dateText: new Date(s.from * 1e3).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric", timeZone: timezone2 })
1846
+ }));
1847
+ };
1848
+ const actions = {
1849
+ setTimezone(tz) {
1850
+ store.setKey("timezone", tz);
1851
+ store.setKey("calendar", buildCalendar());
1852
+ const state = store.get();
1853
+ if (state.selectedDate) {
1854
+ store.setKey("slots", computeSlots(state.selectedDate));
1855
+ store.setKey("selectedSlot", null);
1856
+ }
1857
+ },
1858
+ async setService(serviceId) {
1859
+ store.setKey("loading", true);
1860
+ try {
1861
+ const service = await api.getService({ id: serviceId });
1862
+ store.set({
1863
+ ...store.get(),
1864
+ service,
1865
+ selectedProvider: null,
1866
+ providers: [],
1867
+ selectedDate: null,
1868
+ startDate: null,
1869
+ endDate: null,
1870
+ slots: [],
1871
+ selectedSlot: null,
1872
+ currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
1873
+ loading: false
1874
+ });
1875
+ await actions.loadMonth();
1876
+ } catch (e) {
1877
+ store.setKey("loading", false);
1878
+ throw e;
1879
+ }
1880
+ },
1881
+ async loadMonth() {
1882
+ const state = store.get();
1883
+ if (!state.service) return;
1884
+ store.setKey("loading", true);
1885
+ try {
1886
+ const { currentMonth, service } = state;
1887
+ const year = currentMonth.getFullYear();
1888
+ const month = currentMonth.getMonth();
1889
+ const from = Math.floor(new Date(year, month, 1).getTime() / 1e3);
1890
+ const to = Math.floor(new Date(year, month + 1, 0, 23, 59, 59).getTime() / 1e3);
1891
+ const providers = await api.getServiceProviders({ serviceId: service.id, from, to });
1892
+ store.setKey("providers", providers || []);
1893
+ store.setKey("calendar", buildCalendar());
1894
+ } finally {
1895
+ store.setKey("loading", false);
1896
+ }
1897
+ },
1898
+ prevMonth() {
1899
+ const { currentMonth } = store.get();
1900
+ store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
1901
+ actions.loadMonth();
1902
+ },
1903
+ nextMonth() {
1904
+ const { currentMonth } = store.get();
1905
+ store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
1906
+ actions.loadMonth();
1907
+ },
1908
+ selectProvider(provider) {
1909
+ store.set({
1910
+ ...store.get(),
1911
+ selectedProvider: provider,
1912
+ selectedDate: null,
1913
+ startDate: null,
1914
+ endDate: null,
1915
+ slots: [],
1916
+ selectedSlot: null
1917
+ });
1918
+ store.setKey("calendar", buildCalendar());
1919
+ },
1920
+ selectDate(day) {
1921
+ if (day.blank || !day.available) return;
1922
+ const state = store.get();
1923
+ const slots = computeSlots(day.iso);
1924
+ store.set({ ...state, selectedDate: day.iso, slots, selectedSlot: null });
1925
+ store.setKey("calendar", buildCalendar());
1926
+ },
1927
+ selectSlot(slot) {
1928
+ store.setKey("selectedSlot", slot);
1929
+ },
1930
+ findFirstAvailable() {
1931
+ const state = store.get();
1932
+ for (const day of state.calendar) {
1933
+ if (!day.blank && day.available) {
1934
+ actions.selectDate(day);
1935
+ return;
1936
+ }
1937
+ }
1938
+ },
1939
+ updateCalendar() {
1940
+ store.setKey("calendar", buildCalendar());
1941
+ },
1942
+ addToCart() {
1943
+ const state = store.get();
1944
+ if (!state.selectedSlot) return;
1945
+ store.set({
1946
+ ...state,
1947
+ cart: [...state.cart, state.selectedSlot],
1948
+ selectedDate: null,
1949
+ startDate: null,
1950
+ endDate: null,
1951
+ slots: [],
1952
+ selectedSlot: null
1953
+ });
1954
+ store.setKey("calendar", buildCalendar());
1955
+ },
1956
+ removeFromCart(slotId) {
1957
+ const state = store.get();
1958
+ store.setKey("cart", state.cart.filter((s) => s.id !== slotId));
1959
+ },
1960
+ clearCart() {
1961
+ store.setKey("cart", []);
1962
+ },
1963
+ async checkout(options = {}) {
1964
+ const state = store.get();
1965
+ if (!state.cart.length) throw new Error("Cart is empty");
1966
+ store.setKey("loading", true);
1967
+ try {
1968
+ const result = await api.checkout({
1969
+ items: state.cart.map((s) => ({
1970
+ serviceId: s.serviceId,
1971
+ providerId: s.providerId,
1972
+ from: s.from,
1973
+ to: s.to,
1974
+ blocks: s.serviceBlocks || []
1975
+ })),
1976
+ paymentMethod: options.paymentMethod,
1977
+ promoCode: options.promoCode ?? null,
1978
+ blocks: options.blocks || []
1979
+ });
1980
+ store.setKey("cart", []);
1981
+ return result;
1982
+ } finally {
1983
+ store.setKey("loading", false);
1984
+ }
1985
+ },
1986
+ async getQuote(options = {}) {
1987
+ const state = store.get();
1988
+ if (!state.cart.length) return null;
1989
+ return api.getQuote({
1990
+ items: state.cart.map((s) => ({ serviceId: s.serviceId })),
1991
+ paymentMethod: options.paymentMethod || "CASH",
1992
+ promoCode: options.promoCode
1993
+ });
1994
+ },
1995
+ async getProvidersList() {
1996
+ const state = store.get();
1997
+ if (!state.service) return [];
1998
+ const response = await api.getProviders({ serviceId: state.service.id, limit: 100 });
1999
+ return response?.items || [];
2000
+ }
2001
+ };
2002
+ return { store, ...actions };
2003
+ };
1689
2004
 
1690
2005
  // src/index.ts
1691
- var SDK_VERSION = "0.3.73";
2006
+ var SDK_VERSION = "0.3.78";
1692
2007
  var SUPPORTED_FRAMEWORKS = [
1693
2008
  "astro",
1694
2009
  "react",
@@ -1738,6 +2053,11 @@ async function createArkySDK(config) {
1738
2053
  reservation: createReservationApi(apiConfig),
1739
2054
  database: createDatabaseApi(apiConfig),
1740
2055
  featureFlags: createFeatureFlagsApi(apiConfig),
2056
+ // High-level reservation engine
2057
+ reservationEngine: (engineConfig) => {
2058
+ const reservationApi = createReservationApi(apiConfig);
2059
+ return createReservationEngine(reservationApi, engineConfig);
2060
+ },
1741
2061
  setBusinessId: (businessId) => {
1742
2062
  apiConfig.businessId = businessId;
1743
2063
  },