@viu/emporix-sdk-react 2.4.0 → 2.5.1

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.
@@ -0,0 +1,649 @@
1
+ import { Customer, AuthContext, Product, PaginatedItems, ShoppingListItem, ShoppingListDraft, ShoppingList, Category, CategoryNode, Cart, CartItemInput, CartItemUpdate, CartAddress, CartCreated, CreateCartInput, CheckoutResult, CheckoutInput, QuoteCheckoutInput, PaymentMode, PriceMatchByContextInput, PriceMatch, Media, SegmentCategoryTree, SegmentItem, Segment, PasswordChangeInput, CustomerUpdateInput, Address, AddressCreateInput, AddressUpdateInput, PasswordResetRequestInput, PasswordResetConfirmInput, Site, LegalEntity, ContactAssignment, Location, IamGroup, ContactAssignmentCreate, LegalEntityCreate, LocationCreate, LegalEntityUpdate, ContactAssignmentUpdate, LocationUpdate, OrderStatus, Order, SalesOrderPatch, Availability, RedemptionInput, RedemptionCreated, PointsSummary, RedeemOptionList, RedeemCouponResult, RedeemMyPointsInput, ReturnCreated, ReturnInput, ReturnList, Return } from '@viu/emporix-sdk';
2
+ import * as _tanstack_react_query from '@tanstack/react-query';
3
+ import { UseQueryResult, UseInfiniteQueryResult, UseMutationResult } from '@tanstack/react-query';
4
+ import { S as SiteContextValue } from './provider-fvcYdqqX.js';
5
+
6
+ /** Customer authentication state and actions. */
7
+ interface CustomerSessionApi {
8
+ customerToken: string | null;
9
+ customer: Customer | null;
10
+ isAuthenticated: boolean;
11
+ isLoading: boolean;
12
+ /** Current refresh token (in-session; set by `login`). */
13
+ refreshToken: string | null;
14
+ login: (input: {
15
+ email: string;
16
+ password: string;
17
+ }) => Promise<void>;
18
+ signup: (input: {
19
+ email: string;
20
+ password: string;
21
+ }) => Promise<void>;
22
+ /** Authorization-Code SSO: exchanges an IdP `code` for a customer session. */
23
+ socialLogin: (input: {
24
+ code: string;
25
+ redirectUri: string;
26
+ codeVerifier?: string;
27
+ sessionId?: string;
28
+ }) => Promise<void>;
29
+ /** RFC 8693 token exchange: exchanges an external IdP JWT for a session. */
30
+ exchangeToken: (input: {
31
+ subjectToken: string;
32
+ config?: string;
33
+ }) => Promise<void>;
34
+ /** Server-side logout (best-effort), then clears the local session. */
35
+ logout: () => Promise<void>;
36
+ /** Refetches the `me` profile query. */
37
+ refresh: () => Promise<void>;
38
+ /**
39
+ * Exchanges the stored refresh token for a fresh customer token (same
40
+ * sessionId) and updates the stored token. No-op if there is no refresh
41
+ * token. Throws if the refresh itself fails.
42
+ */
43
+ refreshSession: () => Promise<void>;
44
+ }
45
+ /** Manages the customer session: login/signup/logout and the `me` query. */
46
+ declare function useCustomerSession(): CustomerSessionApi;
47
+
48
+ /** Options accepted by every read hook to override the per-call auth context. */
49
+ interface QueryOpts {
50
+ auth?: AuthContext;
51
+ }
52
+
53
+ /** Fetches one product. Default auth: customer if logged in, else anonymous. */
54
+ declare function useProduct(productId: string, options?: QueryOpts): UseQueryResult<Product>;
55
+ /** Fetches one page of products. */
56
+ declare function useProducts(params?: {
57
+ pageNumber?: number;
58
+ pageSize?: number;
59
+ }, options?: QueryOpts): UseQueryResult<PaginatedItems<Product>>;
60
+ /** Infinite product list — terminates on `hasNextPage=false`. */
61
+ declare function useProductsInfinite(params?: {
62
+ pageSize?: number;
63
+ }, options?: QueryOpts): UseInfiniteQueryResult<{
64
+ pages: PaginatedItems<Product>[];
65
+ pageParams: number[];
66
+ }>;
67
+ /** Fetches one product by its `code` (URL slug). Disabled when code is empty. */
68
+ declare function useProductByCode(code: string | undefined, options?: QueryOpts): UseQueryResult<Product>;
69
+ /** Full-text product search. Disabled when query is empty/whitespace. */
70
+ declare function useProductSearch(query: string | undefined, params?: {
71
+ pageNumber?: number;
72
+ pageSize?: number;
73
+ }, options?: QueryOpts): UseQueryResult<PaginatedItems<Product>>;
74
+ /**
75
+ * Bulk-fetches products by `code`. Order is not guaranteed — re-index by
76
+ * `code` if needed. Disabled when `codes` is empty.
77
+ */
78
+ declare function useProductsByCodes(codes: string[], options?: {
79
+ chunkSize?: number;
80
+ } & QueryOpts): UseQueryResult<Product[]>;
81
+
82
+ /** The caller's shopping lists (customer-only). Optionally filtered by name. */
83
+ declare function useShoppingLists(opts?: {
84
+ name?: string;
85
+ }): UseQueryResult<ShoppingList[]>;
86
+ /** Create a shopping list. */
87
+ declare function useCreateShoppingList(): UseMutationResult<{
88
+ id: string;
89
+ }, unknown, ShoppingListDraft>;
90
+ /** Delete a named list (or all the customer's lists when `name` is omitted). */
91
+ declare function useDeleteShoppingList(): UseMutationResult<void, unknown, {
92
+ customerId: string;
93
+ name?: string;
94
+ }>;
95
+ /** Add/replace an item in a list. */
96
+ declare function useAddToShoppingList(): UseMutationResult<void, unknown, {
97
+ customerId: string;
98
+ listName: string;
99
+ item: ShoppingListItem;
100
+ }>;
101
+ /** Remove an item from a list by productId. */
102
+ declare function useRemoveFromShoppingList(): UseMutationResult<void, unknown, {
103
+ customerId: string;
104
+ listName: string;
105
+ productId: string;
106
+ }>;
107
+ /** Set an item's quantity (0 removes it). */
108
+ declare function useSetShoppingListItemQuantity(): UseMutationResult<void, unknown, {
109
+ customerId: string;
110
+ listName: string;
111
+ productId: string;
112
+ quantity: number;
113
+ }>;
114
+
115
+ type UseVariantChildrenOptions = QueryOpts & {
116
+ pageSize?: number;
117
+ };
118
+ /**
119
+ * Resolves the VARIANT children of a PARENT_VARIANT product via
120
+ * `products.listVariantChildren`. The cache key contains `parentVariantId`.
121
+ * Disabled until `parentVariantId` is a non-empty string.
122
+ */
123
+ declare function useVariantChildren(parentVariantId: string | undefined, options?: UseVariantChildrenOptions): UseQueryResult<Product[]>;
124
+
125
+ /** Fetches one category. */
126
+ declare function useCategory(categoryId: string, options?: QueryOpts): UseQueryResult<Category>;
127
+ /** Fetches one page of categories. */
128
+ declare function useCategories(params?: {
129
+ pageNumber?: number;
130
+ pageSize?: number;
131
+ }, options?: QueryOpts): UseQueryResult<PaginatedItems<Category>>;
132
+ /** Infinite category list — terminates on `hasNextPage=false`. */
133
+ declare function useCategoriesInfinite(params?: {
134
+ pageSize?: number;
135
+ }, options?: QueryOpts): UseInfiniteQueryResult<{
136
+ pages: PaginatedItems<Category>[];
137
+ pageParams: number[];
138
+ }>;
139
+ /** Fetches the category tree. */
140
+ declare function useCategoryTree(rootId?: string, options?: QueryOpts): UseQueryResult<CategoryNode>;
141
+ /** One page of products in a category. Disabled when categoryId is empty. */
142
+ declare function useProductsInCategory(categoryId: string | undefined, params?: {
143
+ pageNumber?: number;
144
+ pageSize?: number;
145
+ }, options?: QueryOpts): UseQueryResult<PaginatedItems<Product>>;
146
+ /** Infinite-scroll product list for a category. Terminates on `hasNextPage=false`. */
147
+ declare function useProductsInCategoryInfinite(categoryId: string | undefined, params?: {
148
+ pageSize?: number;
149
+ }, options?: QueryOpts): UseInfiniteQueryResult<{
150
+ pages: PaginatedItems<Product>[];
151
+ pageParams: number[];
152
+ }>;
153
+
154
+ /** Fetches a cart by id. Falls back to `storage.getCartId()` when no argument is passed; disabled when neither is set. */
155
+ declare function useCart(cartId?: string, options?: QueryOpts): UseQueryResult<Cart>;
156
+ type Mut<TVars> = UseMutationResult<Cart, unknown, TVars, {
157
+ previous: Cart | undefined;
158
+ }>;
159
+ /** Cart write operations with optimistic cache updates and rollback. */
160
+ interface CartMutationsApi {
161
+ addItem: Mut<CartItemInput>;
162
+ updateItem: Mut<{
163
+ itemId: string;
164
+ patch: CartItemUpdate;
165
+ }>;
166
+ removeItem: Mut<{
167
+ itemId: string;
168
+ }>;
169
+ clear: Mut<void>;
170
+ applyCoupon: Mut<{
171
+ code: string;
172
+ }>;
173
+ removeCoupon: Mut<{
174
+ code: string;
175
+ }>;
176
+ setShippingAddress: Mut<CartAddress>;
177
+ setBillingAddress: Mut<CartAddress>;
178
+ }
179
+ /**
180
+ * Cart write operations with optimistic cache updates and rollback.
181
+ *
182
+ * `cartId` is optional — when omitted, `storage.getCartId()` is resolved at
183
+ * **mutate-time** (inside `mutationFn`/`onMutate`), so post-mount writes from
184
+ * `useActiveCart({ create: true })` work without a render race. Throws
185
+ * `EmporixError("useCartMutations: no cartId available — …")` when storage
186
+ * is still empty at mutate-time.
187
+ */
188
+ declare function useCartMutations(cartId?: string): CartMutationsApi;
189
+ /**
190
+ * Creates a cart. Auto-detects auth (customer if a token is stored, else
191
+ * anonymous). On success, persists `cartId` via `storage.setCartId` so a later
192
+ * page reload can resume the same cart with the same anonymous session, then
193
+ * invalidates `["emporix","cart"]` so `useActiveCart` re-reads storage on the
194
+ * next render.
195
+ *
196
+ * Note: the SDK's `carts.create` returns `CartCreated = { cartId, yrn }`, not
197
+ * the full `Cart`. The full cart is loaded on demand by `useCart(cartId)` /
198
+ * `useActiveCart()`.
199
+ */
200
+ declare function useCreateCart(): UseMutationResult<CartCreated, unknown, CreateCartInput | undefined>;
201
+ /**
202
+ * Resolves to "the active cart": the cart matching `storage.cartId` if one is
203
+ * present. With `create: true`, bootstraps a new cart via
204
+ * `client.carts.getCurrent({siteCode, create: true})` when storage is empty —
205
+ * useful on cart-page mounts where you want a cart unconditionally.
206
+ *
207
+ * Internally delegates to `useCart` so both hooks share the canonical
208
+ * `["emporix","cart", id, …]` cache entry — optimistic updates from
209
+ * `useCartMutations` propagate automatically.
210
+ *
211
+ * Returns `UseQueryResult<Cart | null>`. `data: null` means "no cart yet and
212
+ * create was not requested" — a deliberate signal so an empty-state can
213
+ * render without confusing it with the loading state.
214
+ */
215
+ declare function useActiveCart(opts?: {
216
+ create?: boolean;
217
+ type?: string;
218
+ legalEntityId?: string;
219
+ auth?: AuthContext;
220
+ }): UseQueryResult<Cart | null>;
221
+
222
+ /** Checkout actions bound to the stored customer session. */
223
+ interface CheckoutApi {
224
+ placeOrder: UseMutationResult<CheckoutResult, unknown, {
225
+ input: CheckoutInput;
226
+ saasToken?: string;
227
+ siteCode?: string;
228
+ }>;
229
+ placeOrderFromQuote: UseMutationResult<CheckoutResult, unknown, {
230
+ input: QuoteCheckoutInput;
231
+ saasToken?: string;
232
+ siteCode?: string;
233
+ }>;
234
+ }
235
+ /** React bindings for the checkout flow. */
236
+ declare function useCheckout(): CheckoutApi;
237
+ /** Lists frontend payment modes for the logged-in customer. */
238
+ declare function usePaymentModes(options?: {
239
+ enabled?: boolean;
240
+ }): UseQueryResult<PaymentMode[]>;
241
+
242
+ /**
243
+ * Resolves prices for `input.items` via `prices.matchByContext`. Defaults to
244
+ * the anonymous session token (context bound at anonymous-login); pass a
245
+ * customer token for personalized pricing. The SDK does not cache prices —
246
+ * control freshness via the query key / `enabled` (re-run before checkout).
247
+ */
248
+ declare function useMatchPrices(input: PriceMatchByContextInput, options?: {
249
+ enabled?: boolean;
250
+ customerToken?: string | null;
251
+ }): UseQueryResult<PriceMatch[]>;
252
+
253
+ /**
254
+ * Like {@link useMatchPrices} but chunks large `items` arrays via
255
+ * `prices.matchByContextChunked` (default 50 items per request, 4 in flight).
256
+ * Result order is not guaranteed — match by `priceId` / `itemRef.id`.
257
+ */
258
+ declare function useMatchPricesChunked(input: PriceMatchByContextInput, options?: {
259
+ enabled?: boolean;
260
+ customerToken?: string | null;
261
+ chunkSize?: number;
262
+ concurrency?: number;
263
+ }): UseQueryResult<PriceMatch[]>;
264
+
265
+ /**
266
+ * Reads `productMedia` from the existing product query — no Media-Service
267
+ * call (those need a server-only scope). For admin/server flows, use
268
+ * `client.media.listForProduct(productId)` instead.
269
+ */
270
+ declare function useProductMedia(productId: string): {
271
+ data: Media[] | undefined;
272
+ isLoading: boolean;
273
+ error: unknown;
274
+ };
275
+
276
+ /** Segments the logged-in customer belongs to (`segment_read_own`). */
277
+ declare function useMySegments(query?: {
278
+ q?: string;
279
+ pageNumber?: number;
280
+ pageSize?: number;
281
+ }): UseQueryResult<Segment[]>;
282
+ /** Item assignments (PRODUCT + CATEGORY) across the caller's active segments. */
283
+ declare function useMySegmentItems(query?: {
284
+ q?: string;
285
+ siteCode?: string;
286
+ legalEntityId?: string;
287
+ onlyActive?: boolean;
288
+ }): UseQueryResult<SegmentItem[]>;
289
+ /** Category tree filtered to the caller's segments. */
290
+ declare function useMySegmentCategoryTree(query?: {
291
+ siteCode?: string;
292
+ legalEntityId?: string;
293
+ }): UseQueryResult<SegmentCategoryTree>;
294
+ /** Hydrated PRODUCT page for the caller's segments (single-page). */
295
+ declare function useMySegmentProducts(query?: {
296
+ q?: string;
297
+ siteCode?: string;
298
+ legalEntityId?: string;
299
+ onlyActive?: boolean;
300
+ pageNumber?: number;
301
+ pageSize?: number;
302
+ }): UseQueryResult<PaginatedItems<Product>>;
303
+ /**
304
+ * Hydrated PRODUCT pages — infinite scroll. `data.pages` is an array of
305
+ * pages; call `fetchNextPage()` to load the next one. Terminates when
306
+ * the source segment-items page is not full.
307
+ */
308
+ declare function useMySegmentProductsInfinite(query?: {
309
+ q?: string;
310
+ siteCode?: string;
311
+ legalEntityId?: string;
312
+ onlyActive?: boolean;
313
+ pageSize?: number;
314
+ }): _tanstack_react_query.UseInfiniteQueryResult<{
315
+ pages: PaginatedItems<Product>[];
316
+ pageParams: number[];
317
+ }>;
318
+ /** Hydrated CATEGORY page for the caller's segments (single-page). */
319
+ declare function useMySegmentCategories(query?: {
320
+ q?: string;
321
+ siteCode?: string;
322
+ legalEntityId?: string;
323
+ onlyActive?: boolean;
324
+ pageNumber?: number;
325
+ pageSize?: number;
326
+ }): UseQueryResult<PaginatedItems<Category>>;
327
+ /**
328
+ * Hydrated CATEGORY pages — infinite scroll. Same semantics as
329
+ * {@link useMySegmentProductsInfinite}.
330
+ */
331
+ declare function useMySegmentCategoriesInfinite(query?: {
332
+ q?: string;
333
+ siteCode?: string;
334
+ legalEntityId?: string;
335
+ onlyActive?: boolean;
336
+ pageSize?: number;
337
+ }): _tanstack_react_query.UseInfiniteQueryResult<{
338
+ pages: PaginatedItems<{
339
+ id: string;
340
+ parentId?: string | null;
341
+ localizedName: {
342
+ [key: string]: string;
343
+ };
344
+ localizedDescription?: {
345
+ [key: string]: string;
346
+ };
347
+ localizedSlug?: {
348
+ [key: string]: string;
349
+ };
350
+ name?: string;
351
+ description?: string;
352
+ code?: string;
353
+ ecn?: Array<string>;
354
+ validity?: {
355
+ from?: string;
356
+ to?: string;
357
+ };
358
+ position: number;
359
+ published: boolean;
360
+ supercategoriesIds?: Array<string>;
361
+ ownClassificationMixins?: Array<{
362
+ name: string;
363
+ schemaUrl: string;
364
+ required?: boolean;
365
+ }>;
366
+ classificationMixins?: Array<{
367
+ name: string;
368
+ mixinPath?: string;
369
+ schemaUrl: string;
370
+ required?: boolean;
371
+ sourceCategoryId?: string;
372
+ }>;
373
+ mixins?: {
374
+ [key: string]: unknown;
375
+ };
376
+ metadata: {
377
+ createdAt?: string;
378
+ modifiedAt?: string;
379
+ } & {
380
+ version?: number;
381
+ } & {
382
+ mixins?: {
383
+ [key: string]: string;
384
+ };
385
+ };
386
+ media: Array<{
387
+ id?: string;
388
+ url?: string;
389
+ contentType?: string;
390
+ metadata?: {
391
+ createdAt?: string;
392
+ modifiedAt?: string;
393
+ } & unknown;
394
+ customAttributes?: {
395
+ id?: string;
396
+ height?: number;
397
+ width?: number;
398
+ sizeKB?: number;
399
+ type?: string;
400
+ name?: string;
401
+ } & unknown;
402
+ }>;
403
+ }>[];
404
+ pageParams: number[];
405
+ }>;
406
+
407
+ /** Updates the logged-in customer's profile and invalidates the `me` query. */
408
+ declare function useUpdateCustomer(): UseMutationResult<Customer, unknown, CustomerUpdateInput>;
409
+ /**
410
+ * Changes the customer's password. No cache invalidation — no read query
411
+ * surfaces the password.
412
+ */
413
+ declare function useChangePassword(): UseMutationResult<void, unknown, PasswordChangeInput>;
414
+
415
+ /**
416
+ * Lists the logged-in customer's addresses. Disabled when no customer token
417
+ * is in storage (returns idle state, not an error).
418
+ */
419
+ declare function useCustomerAddresses(options?: QueryOpts): UseQueryResult<Address[]>;
420
+ /** Address CRUD mutations. Each invalidates `customer.addresses` on success. */
421
+ interface AddressMutationsApi {
422
+ add: UseMutationResult<Address, unknown, AddressCreateInput>;
423
+ update: UseMutationResult<Address, unknown, {
424
+ id: string;
425
+ patch: AddressUpdateInput;
426
+ }>;
427
+ remove: UseMutationResult<void, unknown, {
428
+ id: string;
429
+ }>;
430
+ }
431
+ declare function useAddressMutations(): AddressMutationsApi;
432
+
433
+ /**
434
+ * The 2-step anonymous password-reset flow. `request` triggers the reset
435
+ * email; `confirm` consumes the token + new password. Both use anonymous
436
+ * auth — the user is by definition locked out when running this flow.
437
+ */
438
+ interface PasswordResetApi {
439
+ request: UseMutationResult<void, unknown, PasswordResetRequestInput>;
440
+ confirm: UseMutationResult<void, unknown, PasswordResetConfirmInput>;
441
+ }
442
+ declare function usePasswordReset(): PasswordResetApi;
443
+
444
+ /** Lists active sites for the tenant. */
445
+ declare function useSites(options?: QueryOpts): UseQueryResult<Site[]>;
446
+ /** Convenience: the tenant's default site (the one flagged `default: true`). */
447
+ declare function useDefaultSite(options?: QueryOpts): UseQueryResult<Site>;
448
+
449
+ /**
450
+ * Returns the active site context: `{ siteCode, currency, targetLocation,
451
+ * setSite }`. In MS-2, `currency` and `targetLocation` are always `null`;
452
+ * they auto-populate in MS-4. `setSite(code)` is sync void in MS-2; it
453
+ * becomes async in MS-3 (PATCHing `/session-context/{tenant}/me/context`).
454
+ */
455
+ declare function useSiteContext(): SiteContextValue;
456
+
457
+ /** Lists the legal entities the calling customer is assigned to. */
458
+ declare function useMyCompanies(): UseQueryResult<LegalEntity[]>;
459
+
460
+ /** Fetches one legal entity by id. Disabled until a customer token is stored. */
461
+ declare function useCompany(legalEntityId: string | undefined): UseQueryResult<LegalEntity>;
462
+
463
+ /** Lists contact assignments for one legal entity. */
464
+ declare function useCompanyContacts(legalEntityId: string | undefined): UseQueryResult<ContactAssignment[]>;
465
+
466
+ /** Lists locations owned by one legal entity. */
467
+ declare function useCompanyLocations(legalEntityId: string | undefined): UseQueryResult<Location[]>;
468
+
469
+ /** Lists IAM customer-groups for one legal entity. */
470
+ declare function useCompanyGroups(legalEntityId: string | undefined): UseQueryResult<IamGroup[]>;
471
+
472
+ declare function useCreateCompany(): UseMutationResult<{
473
+ id: string;
474
+ }, unknown, LegalEntityCreate>;
475
+ declare function useUpdateCompany(): UseMutationResult<LegalEntity, unknown, {
476
+ id: string;
477
+ patch: LegalEntityUpdate;
478
+ }>;
479
+ declare function useDeleteCompany(): UseMutationResult<void, unknown, string>;
480
+ declare function useAssignContact(): UseMutationResult<{
481
+ id: string;
482
+ }, unknown, ContactAssignmentCreate>;
483
+ declare function useUpdateContactAssignment(): UseMutationResult<ContactAssignment, unknown, {
484
+ id: string;
485
+ patch: ContactAssignmentUpdate;
486
+ }>;
487
+ declare function useUnassignContact(): UseMutationResult<void, unknown, string>;
488
+ declare function useCreateLocation(): UseMutationResult<{
489
+ id: string;
490
+ }, unknown, LocationCreate>;
491
+ declare function useUpdateLocation(): UseMutationResult<Location, unknown, {
492
+ id: string;
493
+ patch: LocationUpdate;
494
+ }>;
495
+ declare function useDeleteLocation(): UseMutationResult<void, unknown, string>;
496
+
497
+ interface CompanySwitcherApi {
498
+ companies: LegalEntity[];
499
+ active: LegalEntity | null;
500
+ status: "idle" | "loading" | "switching" | "error";
501
+ switch: (legalEntityId: string) => Promise<void>;
502
+ clear: () => Promise<void>;
503
+ }
504
+ /** UI-friendly wrapper around useActiveCompany — exposes switch/clear pair. */
505
+ declare function useCompanySwitcher(): CompanySwitcherApi;
506
+
507
+ /** Options for `useMyOrders`. Passing `legalEntityId: null` disables the active-company auto-default. */
508
+ interface UseMyOrdersOptions {
509
+ pageNumber?: number;
510
+ pageSize?: number;
511
+ status?: OrderStatus;
512
+ /** `undefined` = default from `useActiveCompany`. `null` = no filter. */
513
+ legalEntityId?: string | null;
514
+ saasToken?: string;
515
+ }
516
+ /** Paginated read of the customer's own orders. Disabled without a customer token. */
517
+ declare function useMyOrders(options?: UseMyOrdersOptions): UseQueryResult<PaginatedItems<Order>>;
518
+
519
+ interface UseMyOrdersInfiniteOptions {
520
+ pageSize?: number;
521
+ status?: OrderStatus;
522
+ legalEntityId?: string | null;
523
+ saasToken?: string;
524
+ }
525
+ /** Infinite paginated read of customer orders. Same defaulting rules as useMyOrders. */
526
+ declare function useMyOrdersInfinite(options?: UseMyOrdersInfiniteOptions): UseInfiniteQueryResult<{
527
+ pages: PaginatedItems<Order>[];
528
+ pageParams: number[];
529
+ }>;
530
+
531
+ interface UseOrderOptions {
532
+ saasToken?: string;
533
+ }
534
+ /** Single-order read by id. Disabled without a customer token or when orderId is undefined. */
535
+ declare function useOrder(orderId: string | undefined, options?: UseOrderOptions): UseQueryResult<Order>;
536
+
537
+ interface UseCancelOrderVars {
538
+ orderId: string;
539
+ saasToken?: string;
540
+ }
541
+ /** Cancels (transitions to DECLINED) a customer's order. Invalidates ["emporix","orders"] on success. */
542
+ declare function useCancelOrder(): UseMutationResult<void, unknown, string | UseCancelOrderVars>;
543
+
544
+ interface UseOrderTransitionVars {
545
+ orderId: string;
546
+ status: OrderStatus;
547
+ comment?: string;
548
+ saasToken?: string;
549
+ }
550
+ /** Generic status transition. Server enforces legality. Invalidates ["emporix","orders"] on success. */
551
+ declare function useOrderTransition(): UseMutationResult<void, unknown, UseOrderTransitionVars>;
552
+
553
+ interface UseReorderVars {
554
+ orderId: string;
555
+ saasToken?: string;
556
+ }
557
+ interface UseReorderResult {
558
+ added: number;
559
+ errors: unknown[];
560
+ }
561
+ /**
562
+ * Re-populates the active cart from a past order via a single
563
+ * `cart.addItemsBatch` call. Best-effort: item-level failures land in
564
+ * `errors[]` instead of throwing; partial-success result shape stays
565
+ * `{ added, errors }`.
566
+ *
567
+ * Emporix's batch endpoint caps at 200 items per request. Orders with more
568
+ * line-items are not supported here — extend with chunking if a real use
569
+ * case appears.
570
+ */
571
+ declare function useReorder(): UseMutationResult<UseReorderResult, unknown, UseReorderVars>;
572
+
573
+ /** Service-account read of a single sales-order. Disabled when `auth` is undefined. */
574
+ declare function useSalesOrder(orderId: string | undefined, authCtx: AuthContext | undefined): UseQueryResult<Order>;
575
+
576
+ interface UseUpdateSalesOrderVars {
577
+ orderId: string;
578
+ patch: SalesOrderPatch;
579
+ auth: AuthContext;
580
+ recalculate?: boolean;
581
+ }
582
+ /**
583
+ * Service-account update of a sales-order. Invalidates both
584
+ * ["emporix","salesorders",id] and ["emporix","orders",id] (the customer-view
585
+ * cache for the same order) on success.
586
+ */
587
+ declare function useUpdateSalesOrder(): UseMutationResult<Order, unknown, UseUpdateSalesOrderVars>;
588
+
589
+ interface UseAvailabilityOptions {
590
+ enabled?: boolean;
591
+ customerToken?: string | null;
592
+ defaultAvailableOnNotFound?: boolean;
593
+ }
594
+ /**
595
+ * Reads availability for one product on one site via `availability.get`.
596
+ * Defaults to the anonymous token; pass `customerToken` for a customer context.
597
+ */
598
+ declare function useAvailability(productId: string, siteCode: string, options?: UseAvailabilityOptions): UseQueryResult<Availability>;
599
+
600
+ interface UseAvailabilitiesOptions {
601
+ enabled?: boolean;
602
+ customerToken?: string | null;
603
+ defaultAvailableOnNotFound?: boolean;
604
+ }
605
+ /**
606
+ * Reads availability for many products on one site via `availability.getMany`
607
+ * (a single batch request). Returns records in input order; missing products
608
+ * are `{ available: false }` (or `{ available: true }` with
609
+ * `defaultAvailableOnNotFound`).
610
+ */
611
+ declare function useAvailabilities(productIds: string[], siteCode: string, options?: UseAvailabilitiesOptions): UseQueryResult<Availability[]>;
612
+
613
+ /** Variables for the coupon action hooks. */
614
+ interface CouponActionVars {
615
+ code: string;
616
+ redemption: RedemptionInput;
617
+ }
618
+ /**
619
+ * Check whether a coupon can be redeemed for the current shopper. Resolves on
620
+ * success (redeemable); the mutation enters `isError` when the coupon is not
621
+ * redeemable. Uses the browser auth context (customer if logged in, else
622
+ * anonymous) — never the service token.
623
+ */
624
+ declare function useValidateCoupon(): UseMutationResult<void, unknown, CouponActionVars>;
625
+ /**
626
+ * Redeem a coupon for the current shopper (creates a redemption). Invalidates
627
+ * the `["emporix", "coupons"]` cache on success.
628
+ */
629
+ declare function useRedeemCoupon(): UseMutationResult<RedemptionCreated, unknown, CouponActionVars>;
630
+
631
+ /** The signed-in customer's reward-points balance (customer-only). */
632
+ declare function useMyRewardPoints(): UseQueryResult<number>;
633
+ /** The signed-in customer's reward-points summary (customer-only). */
634
+ declare function useMyRewardPointsSummary(): UseQueryResult<PointsSummary>;
635
+ /** List redeem options (works for guests and customers). */
636
+ declare function useRedeemOptions(): UseQueryResult<RedeemOptionList>;
637
+ /** Redeem the signed-in customer's points for a coupon code. */
638
+ declare function useRedeemRewardPoints(): UseMutationResult<RedeemCouponResult, unknown, RedeemMyPointsInput>;
639
+
640
+ /** The signed-in customer's returns (customer-only). */
641
+ declare function useMyReturns(opts?: {
642
+ query?: Record<string, string | number>;
643
+ }): UseQueryResult<ReturnList>;
644
+ /** A single return by id (customer-only). */
645
+ declare function useReturn(returnId: string | undefined): UseQueryResult<Return>;
646
+ /** Create a return for the signed-in customer. Invalidates the returns list. */
647
+ declare function useCreateReturn(): UseMutationResult<ReturnCreated, unknown, ReturnInput>;
648
+
649
+ export { useMyOrdersInfinite as $, type AddressMutationsApi as A, useCategoryTree as B, type CartMutationsApi as C, useChangePassword as D, useCheckout as E, useCompany as F, useCompanyContacts as G, useCompanyGroups as H, useCompanyLocations as I, useCompanySwitcher as J, useCreateCart as K, useCreateCompany as L, useCreateLocation as M, useCreateReturn as N, useCreateShoppingList as O, type PasswordResetApi as P, useCustomerAddresses as Q, useCustomerSession as R, useDefaultSite as S, useDeleteCompany as T, type UseAvailabilitiesOptions as U, useDeleteLocation as V, useDeleteShoppingList as W, useMatchPrices as X, useMatchPricesChunked as Y, useMyCompanies as Z, useMyOrders as _, type CheckoutApi as a, useMyReturns as a0, useMyRewardPoints as a1, useMyRewardPointsSummary as a2, useMySegmentCategories as a3, useMySegmentCategoriesInfinite as a4, useMySegmentCategoryTree as a5, useMySegmentItems as a6, useMySegmentProducts as a7, useMySegmentProductsInfinite as a8, useMySegments as a9, useUpdateContactAssignment as aA, useUpdateCustomer as aB, useUpdateLocation as aC, useUpdateSalesOrder as aD, useValidateCoupon as aE, useVariantChildren as aF, useOrder as aa, useOrderTransition as ab, usePasswordReset as ac, usePaymentModes as ad, useProduct as ae, useProductByCode as af, useProductMedia as ag, useProductSearch as ah, useProducts as ai, useProductsByCodes as aj, useProductsInCategory as ak, useProductsInCategoryInfinite as al, useProductsInfinite as am, useRedeemCoupon as an, useRedeemOptions as ao, useRedeemRewardPoints as ap, useRemoveFromShoppingList as aq, useReorder as ar, useReturn as as, useSalesOrder as at, useSetShoppingListItemQuantity as au, useShoppingLists as av, useSiteContext as aw, useSites as ax, useUnassignContact as ay, useUpdateCompany as az, type CompanySwitcherApi as b, type CouponActionVars as c, type CustomerSessionApi as d, type UseAvailabilityOptions as e, type UseCancelOrderVars as f, type UseMyOrdersInfiniteOptions as g, type UseMyOrdersOptions as h, type UseOrderOptions as i, type UseOrderTransitionVars as j, type UseReorderResult as k, type UseReorderVars as l, type UseUpdateSalesOrderVars as m, type UseVariantChildrenOptions as n, useAddToShoppingList as o, useAddressMutations as p, useAssignContact as q, useAvailabilities as r, useAvailability as s, useCancelOrder as t, useActiveCart as u, useCart as v, useCartMutations as w, useCategories as x, useCategoriesInfinite as y, useCategory as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viu/emporix-sdk-react",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "React bindings for the Emporix SDK",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -71,7 +71,7 @@
71
71
  "peerDependencies": {
72
72
  "@tanstack/react-query": "^5.51.0",
73
73
  "react": "^18.0.0 || ^19.0.0",
74
- "@viu/emporix-sdk": "^2.4.0"
74
+ "@viu/emporix-sdk": "^2.5.0"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@tanstack/react-query": "^5.51.0",
@@ -93,7 +93,7 @@
93
93
  "undici": "^6.19.0",
94
94
  "typescript": "^5.6.0",
95
95
  "vitest": "^2.0.0",
96
- "@viu/emporix-sdk": "2.4.0"
96
+ "@viu/emporix-sdk": "2.5.0"
97
97
  },
98
98
  "scripts": {
99
99
  "build": "tsup",