arky-sdk 0.3.83 → 0.4.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/index.cjs +1 -309
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -59
- package/dist/index.d.ts +4 -59
- package/dist/index.js +1 -309
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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';
|
|
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, Slot, 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';
|
|
2
|
+
export { ApiResponse, Block, Business, BusinessConfig, DayAvailability, EshopCartItem, EshopStoreState, GetAvailabilityParams, GetSlotsForDateParams, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, ProviderWithTimeline, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.cjs';
|
|
4
3
|
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';
|
|
5
4
|
|
|
6
5
|
interface AuthTokens {
|
|
@@ -59,35 +58,7 @@ interface RunScriptResponse {
|
|
|
59
58
|
message: string;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
date: Date;
|
|
64
|
-
iso: string;
|
|
65
|
-
available: boolean;
|
|
66
|
-
isSelected: boolean;
|
|
67
|
-
isInRange: boolean;
|
|
68
|
-
isToday: boolean;
|
|
69
|
-
blank: boolean;
|
|
70
|
-
}
|
|
71
|
-
interface ReservationEngineState {
|
|
72
|
-
service: any | null;
|
|
73
|
-
providers: ProviderWithTimeline[];
|
|
74
|
-
selectedProvider: ProviderWithTimeline | null;
|
|
75
|
-
currentMonth: Date;
|
|
76
|
-
calendar: CalendarDay[];
|
|
77
|
-
selectedDate: string | null;
|
|
78
|
-
startDate: string | null;
|
|
79
|
-
endDate: string | null;
|
|
80
|
-
slots: Slot[];
|
|
81
|
-
selectedSlot: Slot | null;
|
|
82
|
-
cart: Slot[];
|
|
83
|
-
timezone: string;
|
|
84
|
-
loading: boolean;
|
|
85
|
-
}
|
|
86
|
-
interface ReservationEngineConfig {
|
|
87
|
-
timezone?: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
declare const SDK_VERSION = "0.3.83";
|
|
61
|
+
declare const SDK_VERSION = "0.4.0";
|
|
91
62
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
92
63
|
interface ApiConfig {
|
|
93
64
|
httpClient: any;
|
|
@@ -254,32 +225,6 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
254
225
|
getCountries(options?: RequestOptions): Promise<GetCountriesResponse>;
|
|
255
226
|
getCountryStates(countryCode: string, options?: RequestOptions): Promise<LocationCountry>;
|
|
256
227
|
};
|
|
257
|
-
reservationEngine: (engineConfig?: ReservationEngineConfig) => {
|
|
258
|
-
setTimezone(tz: string): void;
|
|
259
|
-
setService(serviceId: string): Promise<void>;
|
|
260
|
-
loadMonth(): Promise<void>;
|
|
261
|
-
prevMonth(): void;
|
|
262
|
-
nextMonth(): void;
|
|
263
|
-
selectProvider(provider: ProviderWithTimeline | null): void;
|
|
264
|
-
selectDate(day: CalendarDay): void;
|
|
265
|
-
selectSlot(slot: Slot): void;
|
|
266
|
-
findFirstAvailable(): void;
|
|
267
|
-
updateCalendar(): void;
|
|
268
|
-
addToCart(): void;
|
|
269
|
-
removeFromCart(slotId: string): void;
|
|
270
|
-
clearCart(): void;
|
|
271
|
-
checkout(options?: {
|
|
272
|
-
paymentMethod?: string;
|
|
273
|
-
blocks?: any[];
|
|
274
|
-
promoCode?: string;
|
|
275
|
-
}): Promise<any>;
|
|
276
|
-
getQuote(options?: {
|
|
277
|
-
paymentMethod?: string;
|
|
278
|
-
promoCode?: string;
|
|
279
|
-
}): Promise<any>;
|
|
280
|
-
getProvidersList(): Promise<any[]>;
|
|
281
|
-
store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
|
|
282
|
-
};
|
|
283
228
|
setBusinessId: (businessId: string) => void;
|
|
284
229
|
getBusinessId: () => string;
|
|
285
230
|
setMarket: (market: string) => void;
|
|
@@ -326,4 +271,4 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
326
271
|
};
|
|
327
272
|
}>;
|
|
328
273
|
|
|
329
|
-
export { type ApiConfig, type
|
|
274
|
+
export { type ApiConfig, type GetCountriesResponse, type HttpClientConfig, type LocationCountry, type LocationState, SDK_VERSION, SUPPORTED_FRAMEWORKS, Slot, createArkySDK };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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';
|
|
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, Slot, 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';
|
|
2
|
+
export { ApiResponse, Block, Business, BusinessConfig, DayAvailability, EshopCartItem, EshopStoreState, GetAvailabilityParams, GetSlotsForDateParams, Language, Location, Market, Media, MediaResolution, PaginatedResponse, Payment, PaymentMethod, PaymentMethodType, PaymentProviderConfig, Price, PromoCodeValidation, ProviderWithTimeline, Quote, QuoteLineItem, ReservationCartItem, ReservationStoreState, Seo, ShippingMethod, ShippingWeightTier, Zone } from './types.js';
|
|
4
3
|
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';
|
|
5
4
|
|
|
6
5
|
interface AuthTokens {
|
|
@@ -59,35 +58,7 @@ interface RunScriptResponse {
|
|
|
59
58
|
message: string;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
date: Date;
|
|
64
|
-
iso: string;
|
|
65
|
-
available: boolean;
|
|
66
|
-
isSelected: boolean;
|
|
67
|
-
isInRange: boolean;
|
|
68
|
-
isToday: boolean;
|
|
69
|
-
blank: boolean;
|
|
70
|
-
}
|
|
71
|
-
interface ReservationEngineState {
|
|
72
|
-
service: any | null;
|
|
73
|
-
providers: ProviderWithTimeline[];
|
|
74
|
-
selectedProvider: ProviderWithTimeline | null;
|
|
75
|
-
currentMonth: Date;
|
|
76
|
-
calendar: CalendarDay[];
|
|
77
|
-
selectedDate: string | null;
|
|
78
|
-
startDate: string | null;
|
|
79
|
-
endDate: string | null;
|
|
80
|
-
slots: Slot[];
|
|
81
|
-
selectedSlot: Slot | null;
|
|
82
|
-
cart: Slot[];
|
|
83
|
-
timezone: string;
|
|
84
|
-
loading: boolean;
|
|
85
|
-
}
|
|
86
|
-
interface ReservationEngineConfig {
|
|
87
|
-
timezone?: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
declare const SDK_VERSION = "0.3.83";
|
|
61
|
+
declare const SDK_VERSION = "0.4.0";
|
|
91
62
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
92
63
|
interface ApiConfig {
|
|
93
64
|
httpClient: any;
|
|
@@ -254,32 +225,6 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
254
225
|
getCountries(options?: RequestOptions): Promise<GetCountriesResponse>;
|
|
255
226
|
getCountryStates(countryCode: string, options?: RequestOptions): Promise<LocationCountry>;
|
|
256
227
|
};
|
|
257
|
-
reservationEngine: (engineConfig?: ReservationEngineConfig) => {
|
|
258
|
-
setTimezone(tz: string): void;
|
|
259
|
-
setService(serviceId: string): Promise<void>;
|
|
260
|
-
loadMonth(): Promise<void>;
|
|
261
|
-
prevMonth(): void;
|
|
262
|
-
nextMonth(): void;
|
|
263
|
-
selectProvider(provider: ProviderWithTimeline | null): void;
|
|
264
|
-
selectDate(day: CalendarDay): void;
|
|
265
|
-
selectSlot(slot: Slot): void;
|
|
266
|
-
findFirstAvailable(): void;
|
|
267
|
-
updateCalendar(): void;
|
|
268
|
-
addToCart(): void;
|
|
269
|
-
removeFromCart(slotId: string): void;
|
|
270
|
-
clearCart(): void;
|
|
271
|
-
checkout(options?: {
|
|
272
|
-
paymentMethod?: string;
|
|
273
|
-
blocks?: any[];
|
|
274
|
-
promoCode?: string;
|
|
275
|
-
}): Promise<any>;
|
|
276
|
-
getQuote(options?: {
|
|
277
|
-
paymentMethod?: string;
|
|
278
|
-
promoCode?: string;
|
|
279
|
-
}): Promise<any>;
|
|
280
|
-
getProvidersList(): Promise<any[]>;
|
|
281
|
-
store: nanostores.PreinitializedMapStore<ReservationEngineState> & object;
|
|
282
|
-
};
|
|
283
228
|
setBusinessId: (businessId: string) => void;
|
|
284
229
|
getBusinessId: () => string;
|
|
285
230
|
setMarket: (market: string) => void;
|
|
@@ -326,4 +271,4 @@ declare function createArkySDK(config: HttpClientConfig & {
|
|
|
326
271
|
};
|
|
327
272
|
}>;
|
|
328
273
|
|
|
329
|
-
export { type ApiConfig, type
|
|
274
|
+
export { type ApiConfig, type GetCountriesResponse, type HttpClientConfig, type LocationCountry, type LocationState, SDK_VERSION, SUPPORTED_FRAMEWORKS, Slot, createArkySDK };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { map } from 'nanostores';
|
|
2
|
-
|
|
3
1
|
// src/types/index.ts
|
|
4
2
|
var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
|
|
5
3
|
PaymentMethodType2["Cash"] = "CASH";
|
|
@@ -1711,310 +1709,9 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
|
1711
1709
|
console.error("Error injecting SVG:", error);
|
|
1712
1710
|
}
|
|
1713
1711
|
}
|
|
1714
|
-
function formatTime(ts, tz) {
|
|
1715
|
-
return new Date(ts * 1e3).toLocaleTimeString([], {
|
|
1716
|
-
hour: "2-digit",
|
|
1717
|
-
minute: "2-digit",
|
|
1718
|
-
timeZone: tz
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
function formatSlotTime(from, to, tz) {
|
|
1722
|
-
return `${formatTime(from, tz)} \u2013 ${formatTime(to, tz)}`;
|
|
1723
|
-
}
|
|
1724
|
-
function getTzOffset(date, tz) {
|
|
1725
|
-
const utc = new Date(date.toLocaleString("en-US", { timeZone: "UTC" }));
|
|
1726
|
-
const local = new Date(date.toLocaleString("en-US", { timeZone: tz }));
|
|
1727
|
-
return (utc.getTime() - local.getTime()) / 6e4;
|
|
1728
|
-
}
|
|
1729
|
-
function toUtcTimestamp(year, month, day, mins, tz) {
|
|
1730
|
-
const midnight = new Date(Date.UTC(year, month - 1, day));
|
|
1731
|
-
const offset = getTzOffset(midnight, tz);
|
|
1732
|
-
return Math.floor(midnight.getTime() / 1e3) + (mins + offset) * 60;
|
|
1733
|
-
}
|
|
1734
|
-
function isBlocked(from, to, timeline, limit) {
|
|
1735
|
-
const before = timeline.filter((p) => p.timestamp <= from).sort((a, b) => b.timestamp - a.timestamp);
|
|
1736
|
-
if (before.length > 0 && before[0].concurrent >= limit) return true;
|
|
1737
|
-
for (const p of timeline) {
|
|
1738
|
-
if (p.timestamp >= from && p.timestamp < to && p.concurrent >= limit) return true;
|
|
1739
|
-
}
|
|
1740
|
-
return false;
|
|
1741
|
-
}
|
|
1742
|
-
function getTotalDuration(durations) {
|
|
1743
|
-
return durations.reduce((sum, d) => sum + d.duration, 0);
|
|
1744
|
-
}
|
|
1745
|
-
function getWorkingHoursForDate(wt, date, tz) {
|
|
1746
|
-
if (!wt) return [];
|
|
1747
|
-
const dayName = date.toLocaleDateString("en-US", { weekday: "long", timeZone: tz }).toLowerCase();
|
|
1748
|
-
const m = date.getMonth() + 1;
|
|
1749
|
-
const d = date.getDate();
|
|
1750
|
-
const ts = Math.floor(date.getTime() / 1e3);
|
|
1751
|
-
const specific = wt.specificDates?.find((s) => s.date === ts);
|
|
1752
|
-
if (specific) return specific.workingHours || [];
|
|
1753
|
-
const outcast = wt.outcastDates?.find((o) => o.month === m && o.day === d);
|
|
1754
|
-
if (outcast) return outcast.workingHours || [];
|
|
1755
|
-
return wt.workingDays?.find((w) => w.day === dayName)?.workingHours || [];
|
|
1756
|
-
}
|
|
1757
|
-
function computeSlotsForDate(opts) {
|
|
1758
|
-
const { providers, date, durations, timezone, slotInterval } = opts;
|
|
1759
|
-
const total = getTotalDuration(durations);
|
|
1760
|
-
const interval = slotInterval || total;
|
|
1761
|
-
const slots = [];
|
|
1762
|
-
const nowTs = Math.floor(Date.now() / 1e3);
|
|
1763
|
-
const today = /* @__PURE__ */ new Date();
|
|
1764
|
-
today.setHours(0, 0, 0, 0);
|
|
1765
|
-
if (date < today) return [];
|
|
1766
|
-
const [year, month, day] = date.toLocaleDateString("en-CA", { timeZone: timezone }).split("-").map(Number);
|
|
1767
|
-
for (const p of providers) {
|
|
1768
|
-
for (const wh of getWorkingHoursForDate(p.workingTime, date, timezone)) {
|
|
1769
|
-
for (let m = wh.from; m + total <= wh.to; m += interval) {
|
|
1770
|
-
const from = toUtcTimestamp(year, month, day, m, timezone);
|
|
1771
|
-
const to = from + total * 60;
|
|
1772
|
-
if (from < nowTs) continue;
|
|
1773
|
-
if (!isBlocked(from, to, p.timeline, p.concurrentLimit)) {
|
|
1774
|
-
slots.push({ from, to, providerId: p.id });
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
return slots.sort((a, b) => a.from - b.from);
|
|
1780
|
-
}
|
|
1781
|
-
function hasAvailableSlots(opts) {
|
|
1782
|
-
return computeSlotsForDate(opts).length > 0;
|
|
1783
|
-
}
|
|
1784
|
-
var createInitialState = (timezone) => ({
|
|
1785
|
-
service: null,
|
|
1786
|
-
providers: [],
|
|
1787
|
-
selectedProvider: null,
|
|
1788
|
-
currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
|
|
1789
|
-
calendar: [],
|
|
1790
|
-
selectedDate: null,
|
|
1791
|
-
startDate: null,
|
|
1792
|
-
endDate: null,
|
|
1793
|
-
slots: [],
|
|
1794
|
-
selectedSlot: null,
|
|
1795
|
-
cart: [],
|
|
1796
|
-
timezone,
|
|
1797
|
-
loading: false
|
|
1798
|
-
});
|
|
1799
|
-
var createReservationEngine = (api, config = {}) => {
|
|
1800
|
-
const timezone = config.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1801
|
-
const store = map(createInitialState(timezone));
|
|
1802
|
-
const getServiceDurations = () => {
|
|
1803
|
-
const state = store.get();
|
|
1804
|
-
if (!state.service?.durations?.length) return [{ duration: 60, isPause: false }];
|
|
1805
|
-
return state.service.durations.map((d) => ({
|
|
1806
|
-
duration: d.duration,
|
|
1807
|
-
isPause: d.isPause || d.is_pause || false
|
|
1808
|
-
}));
|
|
1809
|
-
};
|
|
1810
|
-
const buildCalendar = () => {
|
|
1811
|
-
const state = store.get();
|
|
1812
|
-
const { currentMonth, selectedDate, startDate, endDate, providers, selectedProvider, timezone: timezone2 } = state;
|
|
1813
|
-
const year = currentMonth.getFullYear();
|
|
1814
|
-
const month = currentMonth.getMonth();
|
|
1815
|
-
const first = new Date(year, month, 1);
|
|
1816
|
-
const last = new Date(year, month + 1, 0);
|
|
1817
|
-
const today = /* @__PURE__ */ new Date();
|
|
1818
|
-
today.setHours(0, 0, 0, 0);
|
|
1819
|
-
const cells = [];
|
|
1820
|
-
const pad = (first.getDay() + 6) % 7;
|
|
1821
|
-
for (let i = 0; i < pad; i++) {
|
|
1822
|
-
cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
|
|
1823
|
-
}
|
|
1824
|
-
const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
|
|
1825
|
-
const durations = getServiceDurations();
|
|
1826
|
-
for (let d = 1; d <= last.getDate(); d++) {
|
|
1827
|
-
const date = new Date(year, month, d);
|
|
1828
|
-
const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
1829
|
-
const available = activeProviders.length > 0 && hasAvailableSlots({ providers: activeProviders, date, durations, timezone: timezone2 });
|
|
1830
|
-
const isToday = date.getTime() === today.getTime();
|
|
1831
|
-
const isSelected = iso === selectedDate || iso === startDate || iso === endDate;
|
|
1832
|
-
let isInRange = false;
|
|
1833
|
-
if (startDate && endDate) {
|
|
1834
|
-
const t = date.getTime();
|
|
1835
|
-
isInRange = t > new Date(startDate).getTime() && t < new Date(endDate).getTime();
|
|
1836
|
-
}
|
|
1837
|
-
cells.push({ date, iso, available, isSelected, isInRange, isToday, blank: false });
|
|
1838
|
-
}
|
|
1839
|
-
const suffix = (7 - cells.length % 7) % 7;
|
|
1840
|
-
for (let i = 0; i < suffix; i++) {
|
|
1841
|
-
cells.push({ date: /* @__PURE__ */ new Date(0), iso: "", available: false, isSelected: false, isInRange: false, isToday: false, blank: true });
|
|
1842
|
-
}
|
|
1843
|
-
return cells;
|
|
1844
|
-
};
|
|
1845
|
-
const computeSlots = (dateStr) => {
|
|
1846
|
-
const state = store.get();
|
|
1847
|
-
const { providers, selectedProvider, timezone: timezone2, service } = state;
|
|
1848
|
-
const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
|
|
1849
|
-
const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
|
|
1850
|
-
const raw = computeSlotsForDate({ providers: activeProviders, date, durations: getServiceDurations(), timezone: timezone2 });
|
|
1851
|
-
return raw.map((s, i) => ({
|
|
1852
|
-
id: `${service?.id}-${s.from}-${i}`,
|
|
1853
|
-
serviceId: service?.id || "",
|
|
1854
|
-
providerId: s.providerId,
|
|
1855
|
-
from: s.from,
|
|
1856
|
-
to: s.to,
|
|
1857
|
-
timeText: formatSlotTime(s.from, s.to, timezone2),
|
|
1858
|
-
dateText: new Date(s.from * 1e3).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric", timeZone: timezone2 })
|
|
1859
|
-
}));
|
|
1860
|
-
};
|
|
1861
|
-
const actions = {
|
|
1862
|
-
setTimezone(tz) {
|
|
1863
|
-
store.setKey("timezone", tz);
|
|
1864
|
-
store.setKey("calendar", buildCalendar());
|
|
1865
|
-
const state = store.get();
|
|
1866
|
-
if (state.selectedDate) {
|
|
1867
|
-
store.setKey("slots", computeSlots(state.selectedDate));
|
|
1868
|
-
store.setKey("selectedSlot", null);
|
|
1869
|
-
}
|
|
1870
|
-
},
|
|
1871
|
-
async setService(serviceId) {
|
|
1872
|
-
store.setKey("loading", true);
|
|
1873
|
-
try {
|
|
1874
|
-
const service = await api.getService({ id: serviceId });
|
|
1875
|
-
store.set({
|
|
1876
|
-
...store.get(),
|
|
1877
|
-
service,
|
|
1878
|
-
selectedProvider: null,
|
|
1879
|
-
providers: [],
|
|
1880
|
-
selectedDate: null,
|
|
1881
|
-
startDate: null,
|
|
1882
|
-
endDate: null,
|
|
1883
|
-
slots: [],
|
|
1884
|
-
selectedSlot: null,
|
|
1885
|
-
currentMonth: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
|
|
1886
|
-
loading: false
|
|
1887
|
-
});
|
|
1888
|
-
await actions.loadMonth();
|
|
1889
|
-
} catch (e) {
|
|
1890
|
-
store.setKey("loading", false);
|
|
1891
|
-
throw e;
|
|
1892
|
-
}
|
|
1893
|
-
},
|
|
1894
|
-
async loadMonth() {
|
|
1895
|
-
const state = store.get();
|
|
1896
|
-
if (!state.service) return;
|
|
1897
|
-
store.setKey("loading", true);
|
|
1898
|
-
try {
|
|
1899
|
-
const { currentMonth, service } = state;
|
|
1900
|
-
const year = currentMonth.getFullYear();
|
|
1901
|
-
const month = currentMonth.getMonth();
|
|
1902
|
-
const from = Math.floor(new Date(year, month, 1).getTime() / 1e3);
|
|
1903
|
-
const to = Math.floor(new Date(year, month + 1, 0, 23, 59, 59).getTime() / 1e3);
|
|
1904
|
-
const providers = await api.getServiceProviders({ serviceId: service.id, from, to });
|
|
1905
|
-
store.setKey("providers", providers || []);
|
|
1906
|
-
store.setKey("calendar", buildCalendar());
|
|
1907
|
-
} finally {
|
|
1908
|
-
store.setKey("loading", false);
|
|
1909
|
-
}
|
|
1910
|
-
},
|
|
1911
|
-
prevMonth() {
|
|
1912
|
-
const { currentMonth } = store.get();
|
|
1913
|
-
store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
|
|
1914
|
-
actions.loadMonth();
|
|
1915
|
-
},
|
|
1916
|
-
nextMonth() {
|
|
1917
|
-
const { currentMonth } = store.get();
|
|
1918
|
-
store.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
|
|
1919
|
-
actions.loadMonth();
|
|
1920
|
-
},
|
|
1921
|
-
selectProvider(provider) {
|
|
1922
|
-
store.set({
|
|
1923
|
-
...store.get(),
|
|
1924
|
-
selectedProvider: provider,
|
|
1925
|
-
selectedDate: null,
|
|
1926
|
-
startDate: null,
|
|
1927
|
-
endDate: null,
|
|
1928
|
-
slots: [],
|
|
1929
|
-
selectedSlot: null
|
|
1930
|
-
});
|
|
1931
|
-
store.setKey("calendar", buildCalendar());
|
|
1932
|
-
},
|
|
1933
|
-
selectDate(day) {
|
|
1934
|
-
if (day.blank || !day.available) return;
|
|
1935
|
-
const state = store.get();
|
|
1936
|
-
const slots = computeSlots(day.iso);
|
|
1937
|
-
store.set({ ...state, selectedDate: day.iso, slots, selectedSlot: null });
|
|
1938
|
-
store.setKey("calendar", buildCalendar());
|
|
1939
|
-
},
|
|
1940
|
-
selectSlot(slot) {
|
|
1941
|
-
store.setKey("selectedSlot", slot);
|
|
1942
|
-
},
|
|
1943
|
-
findFirstAvailable() {
|
|
1944
|
-
const state = store.get();
|
|
1945
|
-
for (const day of state.calendar) {
|
|
1946
|
-
if (!day.blank && day.available) {
|
|
1947
|
-
actions.selectDate(day);
|
|
1948
|
-
return;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
},
|
|
1952
|
-
updateCalendar() {
|
|
1953
|
-
store.setKey("calendar", buildCalendar());
|
|
1954
|
-
},
|
|
1955
|
-
addToCart() {
|
|
1956
|
-
const state = store.get();
|
|
1957
|
-
if (!state.selectedSlot) return;
|
|
1958
|
-
store.set({
|
|
1959
|
-
...state,
|
|
1960
|
-
cart: [...state.cart, state.selectedSlot],
|
|
1961
|
-
selectedDate: null,
|
|
1962
|
-
startDate: null,
|
|
1963
|
-
endDate: null,
|
|
1964
|
-
slots: [],
|
|
1965
|
-
selectedSlot: null
|
|
1966
|
-
});
|
|
1967
|
-
store.setKey("calendar", buildCalendar());
|
|
1968
|
-
},
|
|
1969
|
-
removeFromCart(slotId) {
|
|
1970
|
-
const state = store.get();
|
|
1971
|
-
store.setKey("cart", state.cart.filter((s) => s.id !== slotId));
|
|
1972
|
-
},
|
|
1973
|
-
clearCart() {
|
|
1974
|
-
store.setKey("cart", []);
|
|
1975
|
-
},
|
|
1976
|
-
async checkout(options = {}) {
|
|
1977
|
-
const state = store.get();
|
|
1978
|
-
if (!state.cart.length) throw new Error("Cart is empty");
|
|
1979
|
-
store.setKey("loading", true);
|
|
1980
|
-
try {
|
|
1981
|
-
return api.checkout({
|
|
1982
|
-
items: state.cart.map((s) => ({
|
|
1983
|
-
serviceId: s.serviceId,
|
|
1984
|
-
providerId: s.providerId,
|
|
1985
|
-
from: s.from,
|
|
1986
|
-
to: s.to,
|
|
1987
|
-
blocks: s.serviceBlocks || []
|
|
1988
|
-
})),
|
|
1989
|
-
paymentMethod: options.paymentMethod,
|
|
1990
|
-
promoCode: options.promoCode ?? null,
|
|
1991
|
-
blocks: options.blocks || []
|
|
1992
|
-
});
|
|
1993
|
-
} finally {
|
|
1994
|
-
store.setKey("loading", false);
|
|
1995
|
-
}
|
|
1996
|
-
},
|
|
1997
|
-
async getQuote(options = {}) {
|
|
1998
|
-
const state = store.get();
|
|
1999
|
-
if (!state.cart.length) return null;
|
|
2000
|
-
return api.getQuote({
|
|
2001
|
-
items: state.cart.map((s) => ({ serviceId: s.serviceId })),
|
|
2002
|
-
paymentMethod: options.paymentMethod || "CASH",
|
|
2003
|
-
promoCode: options.promoCode
|
|
2004
|
-
});
|
|
2005
|
-
},
|
|
2006
|
-
async getProvidersList() {
|
|
2007
|
-
const state = store.get();
|
|
2008
|
-
if (!state.service) return [];
|
|
2009
|
-
const response = await api.getProviders({ serviceId: state.service.id, limit: 100 });
|
|
2010
|
-
return response?.items || [];
|
|
2011
|
-
}
|
|
2012
|
-
};
|
|
2013
|
-
return { store, ...actions };
|
|
2014
|
-
};
|
|
2015
1712
|
|
|
2016
1713
|
// src/index.ts
|
|
2017
|
-
var SDK_VERSION = "0.
|
|
1714
|
+
var SDK_VERSION = "0.4.0";
|
|
2018
1715
|
var SUPPORTED_FRAMEWORKS = [
|
|
2019
1716
|
"astro",
|
|
2020
1717
|
"react",
|
|
@@ -2065,11 +1762,6 @@ async function createArkySDK(config) {
|
|
|
2065
1762
|
database: createDatabaseApi(apiConfig),
|
|
2066
1763
|
featureFlags: createFeatureFlagsApi(apiConfig),
|
|
2067
1764
|
location: createLocationApi(apiConfig),
|
|
2068
|
-
// High-level reservation engine
|
|
2069
|
-
reservationEngine: (engineConfig) => {
|
|
2070
|
-
const reservationApi = createReservationApi(apiConfig);
|
|
2071
|
-
return createReservationEngine(reservationApi, engineConfig);
|
|
2072
|
-
},
|
|
2073
1765
|
setBusinessId: (businessId) => {
|
|
2074
1766
|
apiConfig.businessId = businessId;
|
|
2075
1767
|
},
|