@viu/emporix-sdk-react 2.13.1 → 2.14.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.d.cts CHANGED
@@ -4,9 +4,8 @@ export { PersistedAnonymousSession, TokenStorage, createCookieStorage, createLoc
4
4
  export { A as AddressMutationsApi, C as CartMutationsApi, a as CheckoutApi, b as CompanySwitcherApi, c as CouponActionVars, d as CustomerSessionApi, I as InvokeCloudFunctionVars, P as PasswordResetApi, U as UseAvailabilitiesOptions, e as UseAvailabilityOptions, g as UseMyOrdersInfiniteOptions, h as UseMyOrdersOptions, n as UseVariantChildrenOptions, u as useActiveCart, o as useActiveSite, p as useAddGroupMember, q as useAddToShoppingList, r as useAddressMutations, s as useAssignContact, t as useAvailabilities, v as useAvailability, w as useCancelOrder, x as useCart, y as useCartMutations, z as useCategories, B as useCategoriesInfinite, D as useCategory, E as useCategoryTree, F as useChangePassword, G as useCheckout, H as useCloudFunction, J as useCompany, K as useCompanyContacts, L as useCompanyGroups, M as useCompanyLocations, N as useCompanySwitcher, O as useCreateCart, Q as useCreateCompany, R as useCreateLocation, S as useCreateReturn, T as useCreateShoppingList, V as useCustomerAddresses, W as useCustomerSession, X as useDefaultSite, Y as useDeleteCompany, Z as useDeleteLocation, _ as useDeleteShoppingList, $ as useInvokeCloudFunction, a0 as useMatchPrices, a1 as useMatchPricesChunked, a2 as useMyCompanies, a3 as useMyOrders, a4 as useMyOrdersInfinite, a5 as useMyReturns, a6 as useMyRewardPoints, a7 as useMyRewardPointsSummary, a8 as useMySegmentCategories, a9 as useMySegmentCategoriesInfinite, aa as useMySegmentCategoryTree, ab as useMySegmentItems, ac as useMySegmentProducts, ad as useMySegmentProductsInfinite, ae as useMySegments, af as useOrder, ag as useOrderTransition, ah as usePasswordReset, ai as usePaymentModes, aj as useProduct, ak as useProductByCode, al as useProductMedia, am as useProductNameSearch, an as useProductSearch, ao as useProducts, ap as useProductsByCodes, aq as useProductsInCategory, ar as useProductsInCategoryInfinite, as as useProductsInfinite, at as useRedeemCoupon, au as useRedeemOptions, av as useRedeemRewardPoints, aw as useRemoveFromShoppingList, ax as useRemoveGroupMember, ay as useReorder, az as useReturn, aA as useSalesOrder, aB as useSetShoppingListItemQuantity, aC as useShoppingLists, aD as useSiteContext, aE as useSites, aF as useSubcategories, aG as useUnassignContact, aH as useUpdateCompany, aI as useUpdateContactAssignment, aJ as useUpdateCustomer, aK as useUpdateLocation, aL as useUpdateSalesOrder, aM as useValidateCoupon, aN as useVariantChildren } from './use-returns-DT98Ptod.cjs';
5
5
  import * as react from 'react';
6
6
  import { Component, ReactNode, ErrorInfo } from 'react';
7
- import { EmporixAuthError, EmporixError, EmporixClient, LegalEntity } from '@viu/emporix-sdk';
8
- export { prefetchCart, prefetchOrder, prefetchProduct } from './ssr.cjs';
9
- import '@tanstack/react-query';
7
+ import { EmporixAuthError, EmporixError, EmporixClient, AuthContext, LegalEntity } from '@viu/emporix-sdk';
8
+ import { QueryClient } from '@tanstack/react-query';
10
9
 
11
10
  interface Props {
12
11
  children: ReactNode;
@@ -29,6 +28,41 @@ declare function useEmporixErrorHandler(handlers: {
29
28
  onError?: (e: EmporixError) => void;
30
29
  }): (error: unknown) => void;
31
30
 
31
+ /** Site/language discriminators for SSR prefetch keys. MUST mirror what the
32
+ * client's `useReadSite()` will resolve to at hydration time — `null` when the
33
+ * client mounts without a bound site (the default), the actual codes when the
34
+ * provider is mounted with `initialSiteCode`/`initialLanguage`. */
35
+ interface PrefetchSiteOpts {
36
+ siteCode?: string | null;
37
+ language?: string | null;
38
+ }
39
+ /**
40
+ * Server-side prefetch of a product into a {@link QueryClient}, using the same
41
+ * query key shape as `useProduct` (built through the shared `emporixKey`) so
42
+ * client hydration is a cache hit. Pass `siteCode`/`language` to match a
43
+ * provider mounted with a bound site; omit them when the client mounts without
44
+ * one (both resolve to `null`, the `useReadSite()` default).
45
+ * Create the `EmporixClient` once per server, never per request.
46
+ */
47
+ declare function prefetchProduct(qc: QueryClient, client: EmporixClient, productId: string, authCtx?: AuthContext, opts?: PrefetchSiteOpts): Promise<void>;
48
+ /**
49
+ * Server-side prefetch of a cart. Pass the customer/anonymous context resolved
50
+ * from the request (e.g. a token read from an httpOnly cookie). `activeCompanyId`
51
+ * mirrors the B2B active legal entity carried in `useCart`'s key.
52
+ */
53
+ declare function prefetchCart(qc: QueryClient, client: EmporixClient, cartId: string, authCtx: AuthContext, opts?: PrefetchSiteOpts & {
54
+ activeCompanyId?: string | null;
55
+ }): Promise<void>;
56
+ /**
57
+ * Server-side prefetch of a single customer order. Writes the same cache key
58
+ * `useOrder(orderId)` reads, so client hydration is a cache hit. Note: `useOrder`
59
+ * keys WITHOUT `siteCode` (language only) — keep in sync.
60
+ */
61
+ declare function prefetchOrder(qc: QueryClient, client: EmporixClient, orderId: string, authCtx: AuthContext, opts?: {
62
+ saasToken?: string;
63
+ language?: string | null;
64
+ }): Promise<void>;
65
+
32
66
  type CompanyMode = "b2c" | "b2b" | "unresolved";
33
67
  interface CompanyContextValue {
34
68
  /** Active legal entity. `null` = B2C mode. */
@@ -64,4 +98,4 @@ interface CompanyContextProviderProps {
64
98
  }
65
99
  declare function CompanyContextProvider({ client, storage, initialActiveLegalEntityId, children, }: CompanyContextProviderProps): React.JSX.Element;
66
100
 
67
- export { CompanyContextProvider, type CompanyContextValue, type CompanyMode, EmporixCompanyContext, EmporixErrorBoundary, EmporixStorage, useActiveCompany, useEmporixErrorHandler };
101
+ export { CompanyContextProvider, type CompanyContextValue, type CompanyMode, EmporixCompanyContext, EmporixErrorBoundary, EmporixStorage, prefetchCart, prefetchOrder, prefetchProduct, useActiveCompany, useEmporixErrorHandler };
package/dist/index.d.ts CHANGED
@@ -4,9 +4,8 @@ export { PersistedAnonymousSession, TokenStorage, createCookieStorage, createLoc
4
4
  export { A as AddressMutationsApi, C as CartMutationsApi, a as CheckoutApi, b as CompanySwitcherApi, c as CouponActionVars, d as CustomerSessionApi, I as InvokeCloudFunctionVars, P as PasswordResetApi, U as UseAvailabilitiesOptions, e as UseAvailabilityOptions, g as UseMyOrdersInfiniteOptions, h as UseMyOrdersOptions, n as UseVariantChildrenOptions, u as useActiveCart, o as useActiveSite, p as useAddGroupMember, q as useAddToShoppingList, r as useAddressMutations, s as useAssignContact, t as useAvailabilities, v as useAvailability, w as useCancelOrder, x as useCart, y as useCartMutations, z as useCategories, B as useCategoriesInfinite, D as useCategory, E as useCategoryTree, F as useChangePassword, G as useCheckout, H as useCloudFunction, J as useCompany, K as useCompanyContacts, L as useCompanyGroups, M as useCompanyLocations, N as useCompanySwitcher, O as useCreateCart, Q as useCreateCompany, R as useCreateLocation, S as useCreateReturn, T as useCreateShoppingList, V as useCustomerAddresses, W as useCustomerSession, X as useDefaultSite, Y as useDeleteCompany, Z as useDeleteLocation, _ as useDeleteShoppingList, $ as useInvokeCloudFunction, a0 as useMatchPrices, a1 as useMatchPricesChunked, a2 as useMyCompanies, a3 as useMyOrders, a4 as useMyOrdersInfinite, a5 as useMyReturns, a6 as useMyRewardPoints, a7 as useMyRewardPointsSummary, a8 as useMySegmentCategories, a9 as useMySegmentCategoriesInfinite, aa as useMySegmentCategoryTree, ab as useMySegmentItems, ac as useMySegmentProducts, ad as useMySegmentProductsInfinite, ae as useMySegments, af as useOrder, ag as useOrderTransition, ah as usePasswordReset, ai as usePaymentModes, aj as useProduct, ak as useProductByCode, al as useProductMedia, am as useProductNameSearch, an as useProductSearch, ao as useProducts, ap as useProductsByCodes, aq as useProductsInCategory, ar as useProductsInCategoryInfinite, as as useProductsInfinite, at as useRedeemCoupon, au as useRedeemOptions, av as useRedeemRewardPoints, aw as useRemoveFromShoppingList, ax as useRemoveGroupMember, ay as useReorder, az as useReturn, aA as useSalesOrder, aB as useSetShoppingListItemQuantity, aC as useShoppingLists, aD as useSiteContext, aE as useSites, aF as useSubcategories, aG as useUnassignContact, aH as useUpdateCompany, aI as useUpdateContactAssignment, aJ as useUpdateCustomer, aK as useUpdateLocation, aL as useUpdateSalesOrder, aM as useValidateCoupon, aN as useVariantChildren } from './use-returns-uZJiO46w.js';
5
5
  import * as react from 'react';
6
6
  import { Component, ReactNode, ErrorInfo } from 'react';
7
- import { EmporixAuthError, EmporixError, EmporixClient, LegalEntity } from '@viu/emporix-sdk';
8
- export { prefetchCart, prefetchOrder, prefetchProduct } from './ssr.js';
9
- import '@tanstack/react-query';
7
+ import { EmporixAuthError, EmporixError, EmporixClient, AuthContext, LegalEntity } from '@viu/emporix-sdk';
8
+ import { QueryClient } from '@tanstack/react-query';
10
9
 
11
10
  interface Props {
12
11
  children: ReactNode;
@@ -29,6 +28,41 @@ declare function useEmporixErrorHandler(handlers: {
29
28
  onError?: (e: EmporixError) => void;
30
29
  }): (error: unknown) => void;
31
30
 
31
+ /** Site/language discriminators for SSR prefetch keys. MUST mirror what the
32
+ * client's `useReadSite()` will resolve to at hydration time — `null` when the
33
+ * client mounts without a bound site (the default), the actual codes when the
34
+ * provider is mounted with `initialSiteCode`/`initialLanguage`. */
35
+ interface PrefetchSiteOpts {
36
+ siteCode?: string | null;
37
+ language?: string | null;
38
+ }
39
+ /**
40
+ * Server-side prefetch of a product into a {@link QueryClient}, using the same
41
+ * query key shape as `useProduct` (built through the shared `emporixKey`) so
42
+ * client hydration is a cache hit. Pass `siteCode`/`language` to match a
43
+ * provider mounted with a bound site; omit them when the client mounts without
44
+ * one (both resolve to `null`, the `useReadSite()` default).
45
+ * Create the `EmporixClient` once per server, never per request.
46
+ */
47
+ declare function prefetchProduct(qc: QueryClient, client: EmporixClient, productId: string, authCtx?: AuthContext, opts?: PrefetchSiteOpts): Promise<void>;
48
+ /**
49
+ * Server-side prefetch of a cart. Pass the customer/anonymous context resolved
50
+ * from the request (e.g. a token read from an httpOnly cookie). `activeCompanyId`
51
+ * mirrors the B2B active legal entity carried in `useCart`'s key.
52
+ */
53
+ declare function prefetchCart(qc: QueryClient, client: EmporixClient, cartId: string, authCtx: AuthContext, opts?: PrefetchSiteOpts & {
54
+ activeCompanyId?: string | null;
55
+ }): Promise<void>;
56
+ /**
57
+ * Server-side prefetch of a single customer order. Writes the same cache key
58
+ * `useOrder(orderId)` reads, so client hydration is a cache hit. Note: `useOrder`
59
+ * keys WITHOUT `siteCode` (language only) — keep in sync.
60
+ */
61
+ declare function prefetchOrder(qc: QueryClient, client: EmporixClient, orderId: string, authCtx: AuthContext, opts?: {
62
+ saasToken?: string;
63
+ language?: string | null;
64
+ }): Promise<void>;
65
+
32
66
  type CompanyMode = "b2c" | "b2b" | "unresolved";
33
67
  interface CompanyContextValue {
34
68
  /** Active legal entity. `null` = B2C mode. */
@@ -64,4 +98,4 @@ interface CompanyContextProviderProps {
64
98
  }
65
99
  declare function CompanyContextProvider({ client, storage, initialActiveLegalEntityId, children, }: CompanyContextProviderProps): React.JSX.Element;
66
100
 
67
- export { CompanyContextProvider, type CompanyContextValue, type CompanyMode, EmporixCompanyContext, EmporixErrorBoundary, EmporixStorage, useActiveCompany, useEmporixErrorHandler };
101
+ export { CompanyContextProvider, type CompanyContextValue, type CompanyMode, EmporixCompanyContext, EmporixErrorBoundary, EmporixStorage, prefetchCart, prefetchOrder, prefetchProduct, useActiveCompany, useEmporixErrorHandler };
package/dist/index.js CHANGED
@@ -1,10 +1,109 @@
1
- export { useActiveCart, useActiveSite, useAddGroupMember, useAddToShoppingList, useAddressMutations, useAssignContact, useAvailabilities, useAvailability, useCancelOrder, useCart, useCartMutations, useCategories, useCategoriesInfinite, useCategory, useCategoryTree, useChangePassword, useCheckout, useCloudFunction, useCompany, useCompanyContacts, useCompanyGroups, useCompanyLocations, useCompanySwitcher, useCreateCart, useCreateCompany, useCreateLocation, useCreateReturn, useCreateShoppingList, useCustomerAddresses, useCustomerSession, useDefaultSite, useDeleteCompany, useDeleteLocation, useDeleteShoppingList, useInvokeCloudFunction, useMatchPrices, useMatchPricesChunked, useMyCompanies, useMyOrders, useMyOrdersInfinite, useMyReturns, useMyRewardPoints, useMyRewardPointsSummary, useMySegmentCategories, useMySegmentCategoriesInfinite, useMySegmentCategoryTree, useMySegmentItems, useMySegmentProducts, useMySegmentProductsInfinite, useMySegments, useOrder, useOrderTransition, usePasswordReset, usePaymentModes, useProduct, useProductByCode, useProductMedia, useProductNameSearch, useProductSearch, useProducts, useProductsByCodes, useProductsInCategory, useProductsInCategoryInfinite, useProductsInfinite, useRedeemCoupon, useRedeemOptions, useRedeemRewardPoints, useRemoveFromShoppingList, useRemoveGroupMember, useReorder, useReturn, useSalesOrder, useSetShoppingListItemQuantity, useShoppingLists, useSiteContext, useSites, useSubcategories, useUnassignContact, useUpdateCompany, useUpdateContactAssignment, useUpdateCustomer, useUpdateLocation, useUpdateSalesOrder, useValidateCoupon, useVariantChildren } from './chunk-SXZCM2LE.js';
2
- export { CompanyContextProvider, EmporixCompanyContext, EmporixProvider, useActiveCompany, useEmporix, useEmporixTelemetry } from './chunk-4YDWCA7A.js';
3
- export { createCookieStorage, createLocalStorageStorage, createMemoryStorage } from './chunk-VMDBYVWG.js';
4
- export { prefetchCart, prefetchOrder, prefetchProduct } from './chunk-TIS4BKHK.js';
5
- import { Component } from 'react';
6
- import { EmporixAuthError, EmporixError } from '@viu/emporix-sdk';
1
+ "use client";
2
+ import {
3
+ emporixKey,
4
+ useActiveCart,
5
+ useActiveSite,
6
+ useAddGroupMember,
7
+ useAddToShoppingList,
8
+ useAddressMutations,
9
+ useAssignContact,
10
+ useAvailabilities,
11
+ useAvailability,
12
+ useCancelOrder,
13
+ useCart,
14
+ useCartMutations,
15
+ useCategories,
16
+ useCategoriesInfinite,
17
+ useCategory,
18
+ useCategoryTree,
19
+ useChangePassword,
20
+ useCheckout,
21
+ useCloudFunction,
22
+ useCompany,
23
+ useCompanyContacts,
24
+ useCompanyGroups,
25
+ useCompanyLocations,
26
+ useCompanySwitcher,
27
+ useCreateCart,
28
+ useCreateCompany,
29
+ useCreateLocation,
30
+ useCreateReturn,
31
+ useCreateShoppingList,
32
+ useCustomerAddresses,
33
+ useCustomerSession,
34
+ useDefaultSite,
35
+ useDeleteCompany,
36
+ useDeleteLocation,
37
+ useDeleteShoppingList,
38
+ useInvokeCloudFunction,
39
+ useMatchPrices,
40
+ useMatchPricesChunked,
41
+ useMyCompanies,
42
+ useMyOrders,
43
+ useMyOrdersInfinite,
44
+ useMyReturns,
45
+ useMyRewardPoints,
46
+ useMyRewardPointsSummary,
47
+ useMySegmentCategories,
48
+ useMySegmentCategoriesInfinite,
49
+ useMySegmentCategoryTree,
50
+ useMySegmentItems,
51
+ useMySegmentProducts,
52
+ useMySegmentProductsInfinite,
53
+ useMySegments,
54
+ useOrder,
55
+ useOrderTransition,
56
+ usePasswordReset,
57
+ usePaymentModes,
58
+ useProduct,
59
+ useProductByCode,
60
+ useProductMedia,
61
+ useProductNameSearch,
62
+ useProductSearch,
63
+ useProducts,
64
+ useProductsByCodes,
65
+ useProductsInCategory,
66
+ useProductsInCategoryInfinite,
67
+ useProductsInfinite,
68
+ useRedeemCoupon,
69
+ useRedeemOptions,
70
+ useRedeemRewardPoints,
71
+ useRemoveFromShoppingList,
72
+ useRemoveGroupMember,
73
+ useReorder,
74
+ useReturn,
75
+ useSalesOrder,
76
+ useSetShoppingListItemQuantity,
77
+ useShoppingLists,
78
+ useSiteContext,
79
+ useSites,
80
+ useSubcategories,
81
+ useUnassignContact,
82
+ useUpdateCompany,
83
+ useUpdateContactAssignment,
84
+ useUpdateCustomer,
85
+ useUpdateLocation,
86
+ useUpdateSalesOrder,
87
+ useValidateCoupon,
88
+ useVariantChildren
89
+ } from "./chunk-7F5EB5XY.js";
90
+ import {
91
+ CompanyContextProvider,
92
+ EmporixCompanyContext,
93
+ EmporixProvider,
94
+ useActiveCompany,
95
+ useEmporix,
96
+ useEmporixTelemetry
97
+ } from "./chunk-CZDVH3WH.js";
98
+ import {
99
+ createCookieStorage,
100
+ createLocalStorageStorage,
101
+ createMemoryStorage
102
+ } from "./chunk-ZNLAYNF5.js";
7
103
 
104
+ // src/errors.tsx
105
+ import { Component } from "react";
106
+ import { EmporixError, EmporixAuthError } from "@viu/emporix-sdk";
8
107
  var EmporixErrorBoundary = class extends Component {
9
108
  state = { error: null };
10
109
  static getDerivedStateFromError(error) {
@@ -25,6 +124,139 @@ function useEmporixErrorHandler(handlers) {
25
124
  };
26
125
  }
27
126
 
28
- export { EmporixErrorBoundary, useEmporixErrorHandler };
29
- //# sourceMappingURL=index.js.map
127
+ // src/ssr.ts
128
+ import { auth } from "@viu/emporix-sdk";
129
+ async function prefetchProduct(qc, client, productId, authCtx = auth.anonymous(), opts = {}) {
130
+ await qc.prefetchQuery({
131
+ queryKey: emporixKey("product", [productId], {
132
+ tenant: client.tenant,
133
+ authKind: authCtx.kind,
134
+ siteCode: opts.siteCode ?? null,
135
+ language: opts.language ?? null
136
+ }),
137
+ queryFn: () => client.products.get(productId, void 0, authCtx)
138
+ });
139
+ }
140
+ async function prefetchCart(qc, client, cartId, authCtx, opts = {}) {
141
+ await qc.prefetchQuery({
142
+ queryKey: emporixKey("cart", [cartId, opts.activeCompanyId ?? null], {
143
+ tenant: client.tenant,
144
+ authKind: authCtx.kind,
145
+ siteCode: opts.siteCode ?? null,
146
+ language: opts.language ?? null
147
+ }),
148
+ queryFn: () => client.carts.get(cartId, authCtx)
149
+ });
150
+ }
151
+ async function prefetchOrder(qc, client, orderId, authCtx, opts = {}) {
152
+ await qc.prefetchQuery({
153
+ queryKey: emporixKey("orders", [orderId], {
154
+ tenant: client.tenant,
155
+ authKind: authCtx.kind,
156
+ language: opts.language ?? null
157
+ }),
158
+ queryFn: () => client.orders.get(orderId, authCtx, opts.saasToken ? { saasToken: opts.saasToken } : {})
159
+ });
160
+ }
161
+ export {
162
+ CompanyContextProvider,
163
+ EmporixCompanyContext,
164
+ EmporixErrorBoundary,
165
+ EmporixProvider,
166
+ createCookieStorage,
167
+ createLocalStorageStorage,
168
+ createMemoryStorage,
169
+ prefetchCart,
170
+ prefetchOrder,
171
+ prefetchProduct,
172
+ useActiveCart,
173
+ useActiveCompany,
174
+ useActiveSite,
175
+ useAddGroupMember,
176
+ useAddToShoppingList,
177
+ useAddressMutations,
178
+ useAssignContact,
179
+ useAvailabilities,
180
+ useAvailability,
181
+ useCancelOrder,
182
+ useCart,
183
+ useCartMutations,
184
+ useCategories,
185
+ useCategoriesInfinite,
186
+ useCategory,
187
+ useCategoryTree,
188
+ useChangePassword,
189
+ useCheckout,
190
+ useCloudFunction,
191
+ useCompany,
192
+ useCompanyContacts,
193
+ useCompanyGroups,
194
+ useCompanyLocations,
195
+ useCompanySwitcher,
196
+ useCreateCart,
197
+ useCreateCompany,
198
+ useCreateLocation,
199
+ useCreateReturn,
200
+ useCreateShoppingList,
201
+ useCustomerAddresses,
202
+ useCustomerSession,
203
+ useDefaultSite,
204
+ useDeleteCompany,
205
+ useDeleteLocation,
206
+ useDeleteShoppingList,
207
+ useEmporix,
208
+ useEmporixErrorHandler,
209
+ useEmporixTelemetry,
210
+ useInvokeCloudFunction,
211
+ useMatchPrices,
212
+ useMatchPricesChunked,
213
+ useMyCompanies,
214
+ useMyOrders,
215
+ useMyOrdersInfinite,
216
+ useMyReturns,
217
+ useMyRewardPoints,
218
+ useMyRewardPointsSummary,
219
+ useMySegmentCategories,
220
+ useMySegmentCategoriesInfinite,
221
+ useMySegmentCategoryTree,
222
+ useMySegmentItems,
223
+ useMySegmentProducts,
224
+ useMySegmentProductsInfinite,
225
+ useMySegments,
226
+ useOrder,
227
+ useOrderTransition,
228
+ usePasswordReset,
229
+ usePaymentModes,
230
+ useProduct,
231
+ useProductByCode,
232
+ useProductMedia,
233
+ useProductNameSearch,
234
+ useProductSearch,
235
+ useProducts,
236
+ useProductsByCodes,
237
+ useProductsInCategory,
238
+ useProductsInCategoryInfinite,
239
+ useProductsInfinite,
240
+ useRedeemCoupon,
241
+ useRedeemOptions,
242
+ useRedeemRewardPoints,
243
+ useRemoveFromShoppingList,
244
+ useRemoveGroupMember,
245
+ useReorder,
246
+ useReturn,
247
+ useSalesOrder,
248
+ useSetShoppingListItemQuantity,
249
+ useShoppingLists,
250
+ useSiteContext,
251
+ useSites,
252
+ useSubcategories,
253
+ useUnassignContact,
254
+ useUpdateCompany,
255
+ useUpdateContactAssignment,
256
+ useUpdateCustomer,
257
+ useUpdateLocation,
258
+ useUpdateSalesOrder,
259
+ useValidateCoupon,
260
+ useVariantChildren
261
+ };
30
262
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.tsx"],"names":[],"mappings":";;;;;;;AAaO,IAAM,oBAAA,GAAN,cAAmC,SAAA,CAAwB;AAAA,EAChE,KAAA,GAAe,EAAE,KAAA,EAAO,IAAA,EAAK;AAAA,EAE7B,OAAO,yBAAyB,KAAA,EAAqB;AACnD,IAAA,OAAO,EAAE,KAAA,EAAM;AAAA,EACjB;AAAA,EAEA,iBAAA,CAAkB,OAAc,IAAA,EAAuB;AACrD,IAAA,IAAA,CAAK,KAAA,CAAM,OAAA,GAAU,KAAA,EAAO,IAAI,CAAA;AAAA,EAClC;AAAA,EAEA,MAAA,GAAoB;AAClB,IAAA,IAAI,IAAA,CAAK,KAAA,CAAM,KAAA,EAAO,OAAO,KAAK,KAAA,CAAM,QAAA;AACxC,IAAA,OAAO,KAAK,KAAA,CAAM,QAAA;AAAA,EACpB;AACF;AAGO,SAAS,uBAAuB,QAAA,EAGV;AAC3B,EAAA,OAAO,CAAC,KAAA,KAAmB;AACzB,IAAA,IAAI,KAAA,YAAiB,gBAAA,EAAkB,QAAA,CAAS,WAAA,GAAc,KAAK,CAAA;AAAA,SAAA,IAC1D,KAAA,YAAiB,YAAA,EAAc,QAAA,CAAS,OAAA,GAAU,KAAK,CAAA;AAAA,EAClE,CAAA;AACF","file":"index.js","sourcesContent":["import { Component, type ErrorInfo, type ReactNode } from \"react\";\nimport { EmporixError, EmporixAuthError } from \"@viu/emporix-sdk\";\n\ninterface Props {\n children: ReactNode;\n fallback: ReactNode;\n onError?: (error: Error, info: ErrorInfo) => void;\n}\ninterface State {\n error: Error | null;\n}\n\n/** Catches render errors (including thrown {@link EmporixError}) and shows a fallback. */\nexport class EmporixErrorBoundary extends Component<Props, State> {\n state: State = { error: null };\n\n static getDerivedStateFromError(error: Error): State {\n return { error };\n }\n\n componentDidCatch(error: Error, info: ErrorInfo): void {\n this.props.onError?.(error, info);\n }\n\n render(): ReactNode {\n if (this.state.error) return this.props.fallback;\n return this.props.children;\n }\n}\n\n/** Returns a handler that runs `onAuthError` for {@link EmporixAuthError}, else `onError`. */\nexport function useEmporixErrorHandler(handlers: {\n onAuthError?: (e: EmporixAuthError) => void;\n onError?: (e: EmporixError) => void;\n}): (error: unknown) => void {\n return (error: unknown) => {\n if (error instanceof EmporixAuthError) handlers.onAuthError?.(error);\n else if (error instanceof EmporixError) handlers.onError?.(error);\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/errors.tsx","../src/ssr.ts"],"sourcesContent":["import { Component, type ErrorInfo, type ReactNode } from \"react\";\nimport { EmporixError, EmporixAuthError } from \"@viu/emporix-sdk\";\n\ninterface Props {\n children: ReactNode;\n fallback: ReactNode;\n onError?: (error: Error, info: ErrorInfo) => void;\n}\ninterface State {\n error: Error | null;\n}\n\n/** Catches render errors (including thrown {@link EmporixError}) and shows a fallback. */\nexport class EmporixErrorBoundary extends Component<Props, State> {\n state: State = { error: null };\n\n static getDerivedStateFromError(error: Error): State {\n return { error };\n }\n\n componentDidCatch(error: Error, info: ErrorInfo): void {\n this.props.onError?.(error, info);\n }\n\n render(): ReactNode {\n if (this.state.error) return this.props.fallback;\n return this.props.children;\n }\n}\n\n/** Returns a handler that runs `onAuthError` for {@link EmporixAuthError}, else `onError`. */\nexport function useEmporixErrorHandler(handlers: {\n onAuthError?: (e: EmporixAuthError) => void;\n onError?: (e: EmporixError) => void;\n}): (error: unknown) => void {\n return (error: unknown) => {\n if (error instanceof EmporixAuthError) handlers.onAuthError?.(error);\n else if (error instanceof EmporixError) handlers.onError?.(error);\n };\n}\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport { auth, type AuthContext, type EmporixClient } from \"@viu/emporix-sdk\";\nimport { emporixKey } from \"./hooks/internal/query-keys\";\n\n/** Site/language discriminators for SSR prefetch keys. MUST mirror what the\n * client's `useReadSite()` will resolve to at hydration time — `null` when the\n * client mounts without a bound site (the default), the actual codes when the\n * provider is mounted with `initialSiteCode`/`initialLanguage`. */\nexport interface PrefetchSiteOpts {\n siteCode?: string | null;\n language?: string | null;\n}\n\n/**\n * Server-side prefetch of a product into a {@link QueryClient}, using the same\n * query key shape as `useProduct` (built through the shared `emporixKey`) so\n * client hydration is a cache hit. Pass `siteCode`/`language` to match a\n * provider mounted with a bound site; omit them when the client mounts without\n * one (both resolve to `null`, the `useReadSite()` default).\n * Create the `EmporixClient` once per server, never per request.\n */\nexport async function prefetchProduct(\n qc: QueryClient,\n client: EmporixClient,\n productId: string,\n authCtx: AuthContext = auth.anonymous(),\n opts: PrefetchSiteOpts = {},\n): Promise<void> {\n await qc.prefetchQuery({\n queryKey: emporixKey(\"product\", [productId], {\n tenant: client.tenant,\n authKind: authCtx.kind,\n siteCode: opts.siteCode ?? null,\n language: opts.language ?? null,\n }),\n queryFn: () => client.products.get(productId, undefined, authCtx),\n });\n}\n\n/**\n * Server-side prefetch of a cart. Pass the customer/anonymous context resolved\n * from the request (e.g. a token read from an httpOnly cookie). `activeCompanyId`\n * mirrors the B2B active legal entity carried in `useCart`'s key.\n */\nexport async function prefetchCart(\n qc: QueryClient,\n client: EmporixClient,\n cartId: string,\n authCtx: AuthContext,\n opts: PrefetchSiteOpts & { activeCompanyId?: string | null } = {},\n): Promise<void> {\n await qc.prefetchQuery({\n queryKey: emporixKey(\"cart\", [cartId, opts.activeCompanyId ?? null], {\n tenant: client.tenant,\n authKind: authCtx.kind,\n siteCode: opts.siteCode ?? null,\n language: opts.language ?? null,\n }),\n queryFn: () => client.carts.get(cartId, authCtx),\n });\n}\n\n/**\n * Server-side prefetch of a single customer order. Writes the same cache key\n * `useOrder(orderId)` reads, so client hydration is a cache hit. Note: `useOrder`\n * keys WITHOUT `siteCode` (language only) — keep in sync.\n */\nexport async function prefetchOrder(\n qc: QueryClient,\n client: EmporixClient,\n orderId: string,\n authCtx: AuthContext,\n opts: { saasToken?: string; language?: string | null } = {},\n): Promise<void> {\n await qc.prefetchQuery({\n queryKey: emporixKey(\"orders\", [orderId], {\n tenant: client.tenant,\n authKind: authCtx.kind,\n language: opts.language ?? null,\n }),\n queryFn: () =>\n client.orders.get(orderId, authCtx, opts.saasToken ? { saasToken: opts.saasToken } : {}),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiD;AAC1D,SAAS,cAAc,wBAAwB;AAYxC,IAAM,uBAAN,cAAmC,UAAwB;AAAA,EAChE,QAAe,EAAE,OAAO,KAAK;AAAA,EAE7B,OAAO,yBAAyB,OAAqB;AACnD,WAAO,EAAE,MAAM;AAAA,EACjB;AAAA,EAEA,kBAAkB,OAAc,MAAuB;AACrD,SAAK,MAAM,UAAU,OAAO,IAAI;AAAA,EAClC;AAAA,EAEA,SAAoB;AAClB,QAAI,KAAK,MAAM,MAAO,QAAO,KAAK,MAAM;AACxC,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;AAGO,SAAS,uBAAuB,UAGV;AAC3B,SAAO,CAAC,UAAmB;AACzB,QAAI,iBAAiB,iBAAkB,UAAS,cAAc,KAAK;AAAA,aAC1D,iBAAiB,aAAc,UAAS,UAAU,KAAK;AAAA,EAClE;AACF;;;ACtCA,SAAS,YAAkD;AAoB3D,eAAsB,gBACpB,IACA,QACA,WACA,UAAuB,KAAK,UAAU,GACtC,OAAyB,CAAC,GACX;AACf,QAAM,GAAG,cAAc;AAAA,IACrB,UAAU,WAAW,WAAW,CAAC,SAAS,GAAG;AAAA,MAC3C,QAAQ,OAAO;AAAA,MACf,UAAU,QAAQ;AAAA,MAClB,UAAU,KAAK,YAAY;AAAA,MAC3B,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AAAA,IACD,SAAS,MAAM,OAAO,SAAS,IAAI,WAAW,QAAW,OAAO;AAAA,EAClE,CAAC;AACH;AAOA,eAAsB,aACpB,IACA,QACA,QACA,SACA,OAA+D,CAAC,GACjD;AACf,QAAM,GAAG,cAAc;AAAA,IACrB,UAAU,WAAW,QAAQ,CAAC,QAAQ,KAAK,mBAAmB,IAAI,GAAG;AAAA,MACnE,QAAQ,OAAO;AAAA,MACf,UAAU,QAAQ;AAAA,MAClB,UAAU,KAAK,YAAY;AAAA,MAC3B,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AAAA,IACD,SAAS,MAAM,OAAO,MAAM,IAAI,QAAQ,OAAO;AAAA,EACjD,CAAC;AACH;AAOA,eAAsB,cACpB,IACA,QACA,SACA,SACA,OAAyD,CAAC,GAC3C;AACf,QAAM,GAAG,cAAc;AAAA,IACrB,UAAU,WAAW,UAAU,CAAC,OAAO,GAAG;AAAA,MACxC,QAAQ,OAAO;AAAA,MACf,UAAU,QAAQ;AAAA,MAClB,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AAAA,IACD,SAAS,MACP,OAAO,OAAO,IAAI,SAAS,SAAS,KAAK,YAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC,CAAC;AAAA,EAC3F,CAAC;AACH;","names":[]}