arky-sdk 0.3.84 → 0.3.85

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,6 +1,7 @@
1
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
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';
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';
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, t as formatTime, u as formatSlotTime, w as getTzOffset, x as toUtcTimestamp, y as formatDateDisplay, z as getIsoDate, A as parseIsoDate, B as computeSlotsForDate, C as hasAvailableSlots, D as buildCalendar, E as getMonthYear, F as getTotalDuration, G as isBlocked, H as getWorkingHoursForDate } from './time-DPOc8E1C.cjs';
4
+ export { L as AvailableSlot, Q as BuildCalendarOptions, N as CalendarDay, M as ComputeSlotsOptions, O as OutcastDate, S as ServiceDuration, P as SlotProviderWithTimeline, J as SpecificDate, T as TimelinePoint, I as WorkingDay, W as WorkingHours, K as WorkingTime } from './time-DPOc8E1C.cjs';
4
5
 
5
6
  interface AuthTokens {
6
7
  accessToken: string;
@@ -58,7 +59,7 @@ interface RunScriptResponse {
58
59
  message: string;
59
60
  }
60
61
 
61
- declare const SDK_VERSION = "0.3.84";
62
+ declare const SDK_VERSION = "0.3.85";
62
63
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
63
64
  interface ApiConfig {
64
65
  httpClient: any;
@@ -268,6 +269,20 @@ declare function createArkySDK(config: HttpClientConfig & {
268
269
  getSvgContentForAstro: typeof getSvgContentForAstro;
269
270
  fetchSvgContent: typeof fetchSvgContent;
270
271
  injectSvgIntoElement: typeof injectSvgIntoElement;
272
+ formatTime: typeof formatTime;
273
+ formatSlotTime: typeof formatSlotTime;
274
+ getTzOffset: typeof getTzOffset;
275
+ toUtcTimestamp: typeof toUtcTimestamp;
276
+ formatDateDisplay: typeof formatDateDisplay;
277
+ getIsoDate: typeof getIsoDate;
278
+ parseIsoDate: typeof parseIsoDate;
279
+ computeSlotsForDate: typeof computeSlotsForDate;
280
+ hasAvailableSlots: typeof hasAvailableSlots;
281
+ buildCalendar: typeof buildCalendar;
282
+ getMonthYear: typeof getMonthYear;
283
+ getTotalDuration: typeof getTotalDuration;
284
+ isBlocked: typeof isBlocked;
285
+ getWorkingHoursForDate: typeof getWorkingHoursForDate;
271
286
  };
272
287
  }>;
273
288
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
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
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';
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';
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, t as formatTime, u as formatSlotTime, w as getTzOffset, x as toUtcTimestamp, y as formatDateDisplay, z as getIsoDate, A as parseIsoDate, B as computeSlotsForDate, C as hasAvailableSlots, D as buildCalendar, E as getMonthYear, F as getTotalDuration, G as isBlocked, H as getWorkingHoursForDate } from './time-DAeZRwPk.js';
4
+ export { L as AvailableSlot, Q as BuildCalendarOptions, N as CalendarDay, M as ComputeSlotsOptions, O as OutcastDate, S as ServiceDuration, P as SlotProviderWithTimeline, J as SpecificDate, T as TimelinePoint, I as WorkingDay, W as WorkingHours, K as WorkingTime } from './time-DAeZRwPk.js';
4
5
 
5
6
  interface AuthTokens {
6
7
  accessToken: string;
@@ -58,7 +59,7 @@ interface RunScriptResponse {
58
59
  message: string;
59
60
  }
60
61
 
61
- declare const SDK_VERSION = "0.3.84";
62
+ declare const SDK_VERSION = "0.3.85";
62
63
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
63
64
  interface ApiConfig {
64
65
  httpClient: any;
@@ -268,6 +269,20 @@ declare function createArkySDK(config: HttpClientConfig & {
268
269
  getSvgContentForAstro: typeof getSvgContentForAstro;
269
270
  fetchSvgContent: typeof fetchSvgContent;
270
271
  injectSvgIntoElement: typeof injectSvgIntoElement;
272
+ formatTime: typeof formatTime;
273
+ formatSlotTime: typeof formatSlotTime;
274
+ getTzOffset: typeof getTzOffset;
275
+ toUtcTimestamp: typeof toUtcTimestamp;
276
+ formatDateDisplay: typeof formatDateDisplay;
277
+ getIsoDate: typeof getIsoDate;
278
+ parseIsoDate: typeof parseIsoDate;
279
+ computeSlotsForDate: typeof computeSlotsForDate;
280
+ hasAvailableSlots: typeof hasAvailableSlots;
281
+ buildCalendar: typeof buildCalendar;
282
+ getMonthYear: typeof getMonthYear;
283
+ getTotalDuration: typeof getTotalDuration;
284
+ isBlocked: typeof isBlocked;
285
+ getWorkingHoursForDate: typeof getWorkingHoursForDate;
271
286
  };
272
287
  }>;
273
288
 
package/dist/index.js CHANGED
@@ -1710,8 +1710,164 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1710
1710
  }
1711
1711
  }
1712
1712
 
1713
+ // src/utils/time.ts
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 formatDateDisplay(dateStr, tz) {
1735
+ if (!dateStr) return "";
1736
+ const date = /* @__PURE__ */ new Date(dateStr + "T00:00:00");
1737
+ return date.toLocaleDateString("en-US", {
1738
+ weekday: "short",
1739
+ month: "short",
1740
+ day: "numeric",
1741
+ timeZone: tz
1742
+ });
1743
+ }
1744
+ function getIsoDate(date, tz) {
1745
+ return date.toLocaleDateString("en-CA", { timeZone: tz });
1746
+ }
1747
+ function parseIsoDate(isoDate) {
1748
+ const [year, month, day] = isoDate.split("-").map(Number);
1749
+ return { year, month, day };
1750
+ }
1751
+
1752
+ // src/utils/slots.ts
1753
+ function getTotalDuration(durations) {
1754
+ return durations.reduce((sum, d) => sum + d.duration, 0);
1755
+ }
1756
+ function isBlocked(from, to, timeline, limit) {
1757
+ const before = timeline.filter((p) => p.timestamp <= from).sort((a, b) => b.timestamp - a.timestamp);
1758
+ if (before.length > 0 && before[0].concurrent >= limit) return true;
1759
+ for (const p of timeline) {
1760
+ if (p.timestamp >= from && p.timestamp < to && p.concurrent >= limit) {
1761
+ return true;
1762
+ }
1763
+ }
1764
+ return false;
1765
+ }
1766
+ function getWorkingHoursForDate(wt, date, tz) {
1767
+ if (!wt) return [];
1768
+ const dayName = date.toLocaleDateString("en-US", { weekday: "long", timeZone: tz }).toLowerCase();
1769
+ const m = date.getMonth() + 1;
1770
+ const d = date.getDate();
1771
+ const ts = Math.floor(date.getTime() / 1e3);
1772
+ const specific = wt.specificDates?.find((s) => s.date === ts);
1773
+ if (specific) return specific.workingHours || [];
1774
+ const outcast = wt.outcastDates?.find((o) => o.month === m && o.day === d);
1775
+ if (outcast) return outcast.workingHours || [];
1776
+ return wt.workingDays?.find((w) => w.day === dayName)?.workingHours || [];
1777
+ }
1778
+ function computeSlotsForDate(opts) {
1779
+ const { providers, date, durations, timezone, slotInterval } = opts;
1780
+ const total = getTotalDuration(durations);
1781
+ const interval = slotInterval || total;
1782
+ const slots = [];
1783
+ const nowTs = Math.floor(Date.now() / 1e3);
1784
+ const today = /* @__PURE__ */ new Date();
1785
+ today.setHours(0, 0, 0, 0);
1786
+ if (date < today) return [];
1787
+ const [year, month, day] = date.toLocaleDateString("en-CA", { timeZone: timezone }).split("-").map(Number);
1788
+ for (const provider of providers) {
1789
+ const workingHours = getWorkingHoursForDate(provider.workingTime, date, timezone);
1790
+ for (const wh of workingHours) {
1791
+ for (let m = wh.from; m + total <= wh.to; m += interval) {
1792
+ const from = toUtcTimestamp(year, month, day, m, timezone);
1793
+ const to = from + total * 60;
1794
+ if (from < nowTs) continue;
1795
+ if (!isBlocked(from, to, provider.timeline, provider.concurrentLimit)) {
1796
+ slots.push({ from, to, providerId: provider.id });
1797
+ }
1798
+ }
1799
+ }
1800
+ }
1801
+ return slots.sort((a, b) => a.from - b.from);
1802
+ }
1803
+ function hasAvailableSlots(opts) {
1804
+ return computeSlotsForDate(opts).length > 0;
1805
+ }
1806
+ function buildCalendar(opts) {
1807
+ const {
1808
+ currentMonth,
1809
+ selectedDate,
1810
+ startDate,
1811
+ endDate,
1812
+ providers,
1813
+ selectedProvider,
1814
+ durations,
1815
+ timezone,
1816
+ isMultiDay
1817
+ } = opts;
1818
+ const year = currentMonth.getFullYear();
1819
+ const month = currentMonth.getMonth();
1820
+ const first = new Date(year, month, 1);
1821
+ const last = new Date(year, month + 1, 0);
1822
+ const today = /* @__PURE__ */ new Date();
1823
+ today.setHours(0, 0, 0, 0);
1824
+ const cells = [];
1825
+ const pad = (first.getDay() + 6) % 7;
1826
+ for (let i = 0; i < pad; i++) {
1827
+ cells.push({
1828
+ date: /* @__PURE__ */ new Date(0),
1829
+ iso: "",
1830
+ available: false,
1831
+ isSelected: false,
1832
+ isInRange: false,
1833
+ isToday: false,
1834
+ blank: true
1835
+ });
1836
+ }
1837
+ const activeProviders = selectedProvider ? providers.filter((p) => p.id === selectedProvider.id) : providers;
1838
+ for (let d = 1; d <= last.getDate(); d++) {
1839
+ const date = new Date(year, month, d);
1840
+ const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1841
+ const available = activeProviders.length > 0 && hasAvailableSlots({ providers: activeProviders, date, durations, timezone });
1842
+ const isToday = date.getTime() === today.getTime();
1843
+ let isSelected = false;
1844
+ let isInRange = false;
1845
+ if (isMultiDay) {
1846
+ isSelected = iso === startDate || iso === endDate;
1847
+ if (startDate && endDate) {
1848
+ isInRange = iso > startDate && iso < endDate;
1849
+ }
1850
+ } else {
1851
+ isSelected = iso === selectedDate;
1852
+ }
1853
+ cells.push({
1854
+ date,
1855
+ iso,
1856
+ available,
1857
+ isSelected,
1858
+ isInRange,
1859
+ isToday,
1860
+ blank: false
1861
+ });
1862
+ }
1863
+ return cells;
1864
+ }
1865
+ function getMonthYear(date) {
1866
+ return date.toLocaleDateString("en-US", { month: "long", year: "numeric" });
1867
+ }
1868
+
1713
1869
  // src/index.ts
1714
- var SDK_VERSION = "0.3.84";
1870
+ var SDK_VERSION = "0.3.85";
1715
1871
  var SUPPORTED_FRAMEWORKS = [
1716
1872
  "astro",
1717
1873
  "react",
@@ -1812,7 +1968,23 @@ async function createArkySDK(config) {
1812
1968
  // SVG utilities
1813
1969
  getSvgContentForAstro,
1814
1970
  fetchSvgContent,
1815
- injectSvgIntoElement
1971
+ injectSvgIntoElement,
1972
+ // Time utilities
1973
+ formatTime,
1974
+ formatSlotTime,
1975
+ getTzOffset,
1976
+ toUtcTimestamp,
1977
+ formatDateDisplay,
1978
+ getIsoDate,
1979
+ parseIsoDate,
1980
+ // Slot computation utilities
1981
+ computeSlotsForDate,
1982
+ hasAvailableSlots,
1983
+ buildCalendar,
1984
+ getMonthYear,
1985
+ getTotalDuration,
1986
+ isBlocked,
1987
+ getWorkingHoursForDate
1816
1988
  }
1817
1989
  };
1818
1990
  return sdk;