@behio/storefront-sdk 2.22.0 → 2.25.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/react.mjs CHANGED
@@ -173,6 +173,7 @@ var BehioStorefront = class {
173
173
  this.forms = new FormsModule(this);
174
174
  this.collections = new CollectionsModule(this);
175
175
  this.faq = new FaqModule(this);
176
+ this.bookings = new BookingsModule(this);
176
177
  this.wishlist = new WishlistModule(this);
177
178
  this.reviews = new ReviewsModule(this);
178
179
  this.returns = new ReturnsModule(this);
@@ -1849,6 +1850,60 @@ var FaqModule = class {
1849
1850
  });
1850
1851
  }
1851
1852
  };
1853
+ var BookingsModule = class {
1854
+ constructor(client) {
1855
+ this.client = client;
1856
+ }
1857
+ /** Services, categories, staff, branches and rules of the booking flow. */
1858
+ async getConfig() {
1859
+ return this.client.request("GET", "/bookings/config", { auth: false });
1860
+ }
1861
+ /** Free start times for the selected services (at most 31 days per call). */
1862
+ async getSlots(query) {
1863
+ return this.client.request("GET", "/bookings/slots", {
1864
+ query: {
1865
+ serviceIds: query.serviceIds.join(","),
1866
+ staffId: query.staffId ?? void 0,
1867
+ from: query.from,
1868
+ to: query.to
1869
+ },
1870
+ auth: false
1871
+ });
1872
+ }
1873
+ /**
1874
+ * Create a booking. Counts toward the monthly online limit of the plan.
1875
+ * Keep `manageToken` only to link the customer to the change and cancel
1876
+ * page; the same link arrives in the confirmation email.
1877
+ */
1878
+ async create(input) {
1879
+ return this.client.request("POST", "/bookings", { body: input, auth: false });
1880
+ }
1881
+ /** The booking behind the token from the confirmation email. */
1882
+ async getByToken(token) {
1883
+ return this.client.request("GET", `/bookings/manage/${encodeURIComponent(token)}`, { auth: false });
1884
+ }
1885
+ /** Free times to move the booking to (same services and person rules). */
1886
+ async getManageSlots(token, query) {
1887
+ return this.client.request("GET", `/bookings/manage/${encodeURIComponent(token)}/slots`, {
1888
+ query: { from: query.from, to: query.to },
1889
+ auth: false
1890
+ });
1891
+ }
1892
+ /** Cancel the booking (optional reason for the business). */
1893
+ async cancel(token, input) {
1894
+ return this.client.request("POST", `/bookings/manage/${encodeURIComponent(token)}/cancel`, {
1895
+ body: { reason: input?.reason ?? null },
1896
+ auth: false
1897
+ });
1898
+ }
1899
+ /** Move the booking to `startMs` of a slot from `getManageSlots`. */
1900
+ async reschedule(token, input) {
1901
+ return this.client.request("POST", `/bookings/manage/${encodeURIComponent(token)}/reschedule`, {
1902
+ body: { startMs: input.startMs },
1903
+ auth: false
1904
+ });
1905
+ }
1906
+ };
1852
1907
  var FormsModule = class {
1853
1908
  constructor(client) {
1854
1909
  this.client = client;
@@ -2012,6 +2067,19 @@ var ReturnsModule = class {
2012
2067
  }
2013
2068
  );
2014
2069
  }
2070
+ /**
2071
+ * EU withdrawal function (Art. 11a Directive 2011/83/EU, 2.25.0). Two steps
2072
+ * in the template: the form (name, order number, e-mail), then a summary
2073
+ * with the "Confirm withdrawal" button that calls this. The result is the
2074
+ * acknowledgement to show; the same content with date and time goes out by
2075
+ * e-mail. Guests welcome, the order e-mail is the gate.
2076
+ */
2077
+ async withdraw(input) {
2078
+ return this.client.request("POST", "/returns/withdrawal", {
2079
+ body: input
2080
+ });
2081
+ }
2082
+ /** Return or complaint. Reason CHANGED_MIND is recorded as a withdrawal on the server. */
2015
2083
  async submit(input) {
2016
2084
  return this.client.request("POST", "/returns", {
2017
2085
  body: input
@@ -4139,11 +4207,73 @@ function useSiteFormSubmit(slug) {
4139
4207
  };
4140
4208
  }
4141
4209
 
4210
+ // src/react/hooks/use-bookings.ts
4211
+ import { useMutation as useMutation16, useQuery as useQuery34, useQueryClient as useQueryClient16 } from "@tanstack/react-query";
4212
+ function useBookingConfig(options) {
4213
+ const { client } = useBehio();
4214
+ return useQuery34({
4215
+ queryKey: ["behio", "bookings", "config"],
4216
+ queryFn: () => unwrap(client.bookings.getConfig()),
4217
+ enabled: options?.enabled !== false
4218
+ });
4219
+ }
4220
+ function useBookingSlots(query, options) {
4221
+ const { client } = useBehio();
4222
+ return useQuery34({
4223
+ queryKey: ["behio", "bookings", "slots", query.serviceIds.join(","), query.staffId ?? null, query.from, query.to],
4224
+ queryFn: () => unwrap(client.bookings.getSlots(query)),
4225
+ enabled: options?.enabled !== false && query.serviceIds.length > 0,
4226
+ staleTime: 3e4
4227
+ });
4228
+ }
4229
+ function useCreateBooking() {
4230
+ const { client } = useBehio();
4231
+ const queryClient = useQueryClient16();
4232
+ return useMutation16({
4233
+ mutationFn: (input) => unwrap(client.bookings.create(input)),
4234
+ onSettled: () => queryClient.invalidateQueries({ queryKey: ["behio", "bookings", "slots"] })
4235
+ });
4236
+ }
4237
+ function useManagedBooking(token, options) {
4238
+ const { client } = useBehio();
4239
+ return useQuery34({
4240
+ queryKey: ["behio", "bookings", "manage", token],
4241
+ queryFn: () => unwrap(client.bookings.getByToken(token)),
4242
+ enabled: options?.enabled !== false && !!token
4243
+ });
4244
+ }
4245
+ function useManagedBookingSlots(token, query, options) {
4246
+ const { client } = useBehio();
4247
+ return useQuery34({
4248
+ queryKey: ["behio", "bookings", "manage", token, "slots", query.from, query.to],
4249
+ queryFn: () => unwrap(client.bookings.getManageSlots(token, query)),
4250
+ enabled: options?.enabled !== false && !!token,
4251
+ staleTime: 3e4
4252
+ });
4253
+ }
4254
+ function useCancelBooking(token) {
4255
+ const { client } = useBehio();
4256
+ const queryClient = useQueryClient16();
4257
+ return useMutation16({
4258
+ mutationFn: (input) => unwrap(client.bookings.cancel(token, input ?? void 0)),
4259
+ onSuccess: (booking) => queryClient.setQueryData(["behio", "bookings", "manage", token], booking)
4260
+ });
4261
+ }
4262
+ function useRescheduleBooking(token) {
4263
+ const { client } = useBehio();
4264
+ const queryClient = useQueryClient16();
4265
+ return useMutation16({
4266
+ mutationFn: (input) => unwrap(client.bookings.reschedule(token, input)),
4267
+ onSuccess: (booking) => queryClient.setQueryData(["behio", "bookings", "manage", token], booking),
4268
+ onSettled: () => queryClient.invalidateQueries({ queryKey: ["behio", "bookings", "manage", token, "slots"] })
4269
+ });
4270
+ }
4271
+
4142
4272
  // src/react/hooks/use-shop-info.ts
4143
- import { useQuery as useQuery34 } from "@tanstack/react-query";
4273
+ import { useQuery as useQuery35 } from "@tanstack/react-query";
4144
4274
  function useShopInfo(options) {
4145
4275
  const { client } = useBehio();
4146
- return useQuery34({
4276
+ return useQuery35({
4147
4277
  queryKey: ["behio", "shop-info"],
4148
4278
  queryFn: () => unwrap(client.getShopInfo()),
4149
4279
  enabled: options?.enabled !== false
@@ -4151,10 +4281,10 @@ function useShopInfo(options) {
4151
4281
  }
4152
4282
 
4153
4283
  // src/react/hooks/use-shop-scripts.ts
4154
- import { useQuery as useQuery35 } from "@tanstack/react-query";
4284
+ import { useQuery as useQuery36 } from "@tanstack/react-query";
4155
4285
  function useShopScripts(options) {
4156
4286
  const { client } = useBehio();
4157
- return useQuery35({
4287
+ return useQuery36({
4158
4288
  queryKey: ["behio", "shop-scripts"],
4159
4289
  queryFn: () => unwrap(client.getShopScripts()),
4160
4290
  enabled: options?.enabled !== false,
@@ -4163,11 +4293,11 @@ function useShopScripts(options) {
4163
4293
  }
4164
4294
 
4165
4295
  // src/react/hooks/use-shop-seo.ts
4166
- import { useQuery as useQuery36 } from "@tanstack/react-query";
4296
+ import { useQuery as useQuery37 } from "@tanstack/react-query";
4167
4297
  function useShopSeo(options) {
4168
4298
  const { client } = useBehio();
4169
4299
  const { locale, initialData, enabled = true } = options ?? {};
4170
- return useQuery36({
4300
+ return useQuery37({
4171
4301
  queryKey: ["behio", "shop-seo", locale ?? "_default"],
4172
4302
  queryFn: () => unwrap(client.getShopSeo(locale)),
4173
4303
  initialData,
@@ -4230,20 +4360,20 @@ function CurrencySwitcher({
4230
4360
  import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4, useState as useState10 } from "react";
4231
4361
 
4232
4362
  // src/react/hooks/use-consent.ts
4233
- import { useQuery as useQuery37, useMutation as useMutation16, useQueryClient as useQueryClient16 } from "@tanstack/react-query";
4363
+ import { useQuery as useQuery38, useMutation as useMutation17, useQueryClient as useQueryClient17 } from "@tanstack/react-query";
4234
4364
  function useCookieConsent(visitorId) {
4235
4365
  const { client } = useBehio();
4236
- const qc = useQueryClient16();
4237
- const query = useQuery37({
4366
+ const qc = useQueryClient17();
4367
+ const query = useQuery38({
4238
4368
  queryKey: ["behio", "consent", visitorId],
4239
4369
  queryFn: () => unwrap(client.consent.get(visitorId)),
4240
4370
  enabled: Boolean(visitorId)
4241
4371
  });
4242
- const recordMutation = useMutation16({
4372
+ const recordMutation = useMutation17({
4243
4373
  mutationFn: (input) => unwrap(client.consent.record(input)),
4244
4374
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
4245
4375
  });
4246
- const revokeMutation = useMutation16({
4376
+ const revokeMutation = useMutation17({
4247
4377
  mutationFn: () => unwrap(client.consent.revoke(visitorId)),
4248
4378
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
4249
4379
  });
@@ -4622,11 +4752,11 @@ function RichText({ html, className, as = "div" }) {
4622
4752
  }
4623
4753
 
4624
4754
  // src/react/hooks/use-bundles.ts
4625
- import { useQuery as useQuery38 } from "@tanstack/react-query";
4755
+ import { useQuery as useQuery39 } from "@tanstack/react-query";
4626
4756
  function useBundles(options) {
4627
4757
  const { client, sessionRestored } = useBehio();
4628
4758
  const query = { locale: options?.locale ?? client.getLocale(), currency: options?.currency ?? client.getCurrency(), country: options?.country ?? client.getCountry() };
4629
- return useQuery38({
4759
+ return useQuery39({
4630
4760
  queryKey: ["behio", "bundles", query],
4631
4761
  queryFn: () => unwrap(client.catalog.getBundles(query)),
4632
4762
  enabled: sessionRestored && (options?.enabled ?? true),
@@ -4636,7 +4766,7 @@ function useBundles(options) {
4636
4766
  function useBundle(slug, options) {
4637
4767
  const { client, sessionRestored } = useBehio();
4638
4768
  const query = { locale: options?.locale ?? client.getLocale(), currency: options?.currency ?? client.getCurrency(), country: options?.country ?? client.getCountry() };
4639
- return useQuery38({
4769
+ return useQuery39({
4640
4770
  queryKey: ["behio", "bundle", slug, query],
4641
4771
  queryFn: () => unwrap(client.catalog.getBundle(slug, query)),
4642
4772
  enabled: sessionRestored && Boolean(slug) && (options?.enabled ?? true),
@@ -4645,10 +4775,10 @@ function useBundle(slug, options) {
4645
4775
  }
4646
4776
 
4647
4777
  // src/react/hooks/use-product-group.ts
4648
- import { useQuery as useQuery39 } from "@tanstack/react-query";
4778
+ import { useQuery as useQuery40 } from "@tanstack/react-query";
4649
4779
  function useProductGroup(slug, options) {
4650
4780
  const { client } = useBehio();
4651
- return useQuery39({
4781
+ return useQuery40({
4652
4782
  queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
4653
4783
  queryFn: () => unwrap(
4654
4784
  client.catalog.getProductGroup(slug, {
@@ -4662,10 +4792,10 @@ function useProductGroup(slug, options) {
4662
4792
  }
4663
4793
 
4664
4794
  // src/react/hooks/use-cross-sell.ts
4665
- import { useQuery as useQuery40 } from "@tanstack/react-query";
4795
+ import { useQuery as useQuery41 } from "@tanstack/react-query";
4666
4796
  function useCrossSell(productSlug, options) {
4667
4797
  const { client } = useBehio();
4668
- return useQuery40({
4798
+ return useQuery41({
4669
4799
  queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
4670
4800
  queryFn: () => unwrap(
4671
4801
  client.catalog.getCrossSell(productSlug, {
@@ -4679,10 +4809,10 @@ function useCrossSell(productSlug, options) {
4679
4809
  }
4680
4810
 
4681
4811
  // src/react/hooks/use-product-promotions.ts
4682
- import { useQuery as useQuery41 } from "@tanstack/react-query";
4812
+ import { useQuery as useQuery42 } from "@tanstack/react-query";
4683
4813
  function useProductPromotions(productSlug, options) {
4684
4814
  const { client } = useBehio();
4685
- return useQuery41({
4815
+ return useQuery42({
4686
4816
  queryKey: ["behio", "product-promotions", productSlug],
4687
4817
  queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
4688
4818
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
@@ -4691,11 +4821,11 @@ function useProductPromotions(productSlug, options) {
4691
4821
  }
4692
4822
 
4693
4823
  // src/react/hooks/use-gift-card.ts
4694
- import { useQuery as useQuery42 } from "@tanstack/react-query";
4824
+ import { useQuery as useQuery43 } from "@tanstack/react-query";
4695
4825
  function useGiftCardBalance(code, options) {
4696
4826
  const { client } = useBehio();
4697
4827
  const trimmed = code?.trim();
4698
- return useQuery42({
4828
+ return useQuery43({
4699
4829
  queryKey: ["behio", "gift-card-balance", trimmed],
4700
4830
  queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
4701
4831
  enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
@@ -4703,20 +4833,20 @@ function useGiftCardBalance(code, options) {
4703
4833
  }
4704
4834
 
4705
4835
  // src/react/hooks/use-wishlist.ts
4706
- import { useQuery as useQuery43, useMutation as useMutation17, useQueryClient as useQueryClient17 } from "@tanstack/react-query";
4836
+ import { useQuery as useQuery44, useMutation as useMutation18, useQueryClient as useQueryClient18 } from "@tanstack/react-query";
4707
4837
  function useWishlist(options) {
4708
4838
  const { client } = useBehio();
4709
- const qc = useQueryClient17();
4710
- const query = useQuery43({
4839
+ const qc = useQueryClient18();
4840
+ const query = useQuery44({
4711
4841
  queryKey: ["behio", "wishlist"],
4712
4842
  queryFn: () => unwrap(client.wishlist.get()),
4713
4843
  enabled: options?.enabled ?? true
4714
4844
  });
4715
- const addMutation = useMutation17({
4845
+ const addMutation = useMutation18({
4716
4846
  mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
4717
4847
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
4718
4848
  });
4719
- const removeMutation = useMutation17({
4849
+ const removeMutation = useMutation18({
4720
4850
  mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
4721
4851
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
4722
4852
  });
@@ -4730,7 +4860,7 @@ function useWishlist(options) {
4730
4860
  }
4731
4861
  function useIsInWishlist(productId) {
4732
4862
  const { client } = useBehio();
4733
- return useQuery43({
4863
+ return useQuery44({
4734
4864
  queryKey: ["behio", "wishlist-check", productId],
4735
4865
  queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
4736
4866
  enabled: Boolean(productId)
@@ -4738,10 +4868,10 @@ function useIsInWishlist(productId) {
4738
4868
  }
4739
4869
 
4740
4870
  // src/react/hooks/use-reviews.ts
4741
- import { useQuery as useQuery44, useMutation as useMutation18, useQueryClient as useQueryClient18 } from "@tanstack/react-query";
4871
+ import { useQuery as useQuery45, useMutation as useMutation19, useQueryClient as useQueryClient19 } from "@tanstack/react-query";
4742
4872
  function useProductReviews(productId, options) {
4743
4873
  const { client } = useBehio();
4744
- return useQuery44({
4874
+ return useQuery45({
4745
4875
  queryKey: ["behio", "reviews", productId, options?.page ?? 1, options?.limit ?? 20],
4746
4876
  queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
4747
4877
  initialData: options?.initialData,
@@ -4751,30 +4881,36 @@ function useProductReviews(productId, options) {
4751
4881
  }
4752
4882
  function useSubmitReview() {
4753
4883
  const { client } = useBehio();
4754
- const qc = useQueryClient18();
4755
- return useMutation18({
4884
+ const qc = useQueryClient19();
4885
+ return useMutation19({
4756
4886
  mutationFn: (input) => unwrap(client.reviews.submit(input)),
4757
4887
  onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
4758
4888
  });
4759
4889
  }
4760
4890
 
4761
4891
  // src/react/hooks/use-returns.ts
4762
- import { useQuery as useQuery45, useMutation as useMutation19 } from "@tanstack/react-query";
4892
+ import { useQuery as useQuery46, useMutation as useMutation20 } from "@tanstack/react-query";
4763
4893
  function useLookupReturnableOrder() {
4764
4894
  const { client } = useBehio();
4765
- return useMutation19({
4895
+ return useMutation20({
4766
4896
  mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
4767
4897
  });
4768
4898
  }
4899
+ function useSubmitWithdrawal() {
4900
+ const { client } = useBehio();
4901
+ return useMutation20({
4902
+ mutationFn: (input) => unwrap(client.returns.withdraw(input))
4903
+ });
4904
+ }
4769
4905
  function useSubmitReturn() {
4770
4906
  const { client } = useBehio();
4771
- return useMutation19({
4907
+ return useMutation20({
4772
4908
  mutationFn: (input) => unwrap(client.returns.submit(input))
4773
4909
  });
4774
4910
  }
4775
4911
  function useReturnStatus(returnId, email) {
4776
4912
  const { client } = useBehio();
4777
- return useQuery45({
4913
+ return useQuery46({
4778
4914
  queryKey: ["behio", "return-status", returnId],
4779
4915
  queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
4780
4916
  enabled: Boolean(returnId && email)
@@ -4782,16 +4918,16 @@ function useReturnStatus(returnId, email) {
4782
4918
  }
4783
4919
 
4784
4920
  // src/react/hooks/use-quotes.ts
4785
- import { useMutation as useMutation20, useQuery as useQuery46 } from "@tanstack/react-query";
4921
+ import { useMutation as useMutation21, useQuery as useQuery47 } from "@tanstack/react-query";
4786
4922
  function useSubmitQuote() {
4787
4923
  const { client } = useBehio();
4788
- return useMutation20({
4924
+ return useMutation21({
4789
4925
  mutationFn: (input) => unwrap(client.quotes.submit(input))
4790
4926
  });
4791
4927
  }
4792
4928
  function useQuoteStatus(quoteId, email) {
4793
4929
  const { client } = useBehio();
4794
- return useQuery46({
4930
+ return useQuery47({
4795
4931
  queryKey: ["behio", "quote-status", quoteId],
4796
4932
  queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
4797
4933
  enabled: Boolean(quoteId && email)
@@ -4799,10 +4935,10 @@ function useQuoteStatus(quoteId, email) {
4799
4935
  }
4800
4936
 
4801
4937
  // src/react/hooks/use-back-in-stock.ts
4802
- import { useMutation as useMutation21 } from "@tanstack/react-query";
4938
+ import { useMutation as useMutation22 } from "@tanstack/react-query";
4803
4939
  function useNotifyWhenAvailable() {
4804
4940
  const { client } = useBehio();
4805
- return useMutation21({
4941
+ return useMutation22({
4806
4942
  mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
4807
4943
  });
4808
4944
  }
@@ -4950,8 +5086,11 @@ export {
4950
5086
  useBlogPost,
4951
5087
  useBlogPosts,
4952
5088
  useBlogs,
5089
+ useBookingConfig,
5090
+ useBookingSlots,
4953
5091
  useBundle,
4954
5092
  useBundles,
5093
+ useCancelBooking,
4955
5094
  useCart,
4956
5095
  useCartCount,
4957
5096
  useCategories,
@@ -4965,6 +5104,7 @@ export {
4965
5104
  useCourse,
4966
5105
  useCourseCertificates,
4967
5106
  useCourses,
5107
+ useCreateBooking,
4968
5108
  useCrossSell,
4969
5109
  useCurrency,
4970
5110
  useCustomer,
@@ -4982,6 +5122,8 @@ export {
4982
5122
  useLessonTutor,
4983
5123
  useLookupReturnableOrder,
4984
5124
  useLoyalty,
5125
+ useManagedBooking,
5126
+ useManagedBookingSlots,
4985
5127
  useMenu,
4986
5128
  useNewsletterSubscribe,
4987
5129
  useNewsletterUnsubscribe,
@@ -5001,6 +5143,7 @@ export {
5001
5143
  useProductReviews,
5002
5144
  useProducts,
5003
5145
  useQuoteStatus,
5146
+ useRescheduleBooking,
5004
5147
  useReturnStatus,
5005
5148
  useSearch,
5006
5149
  useShippingMethods,
@@ -5013,6 +5156,7 @@ export {
5013
5156
  useSubmitQuote,
5014
5157
  useSubmitReturn,
5015
5158
  useSubmitReview,
5159
+ useSubmitWithdrawal,
5016
5160
  useSubscriptions,
5017
5161
  useVisitorMessages,
5018
5162
  useWishlist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behio/storefront-sdk",
3
- "version": "2.22.0",
3
+ "version": "2.25.0",
4
4
  "description": "TypeScript SDK for Behio headless e-commerce: core client + React hooks",
5
5
  "author": "Behio",
6
6
  "license": "MIT",