@nymbalhq/sdk 1.4.0 → 1.6.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/dist/chunk-2EEZZXZX.js +601 -0
  4. package/dist/chunk-2EEZZXZX.js.map +1 -0
  5. package/dist/chunk-4GP43MKT.js +19 -0
  6. package/dist/chunk-4GP43MKT.js.map +1 -0
  7. package/dist/chunk-7LQGOJIT.js +133 -0
  8. package/dist/chunk-7LQGOJIT.js.map +1 -0
  9. package/dist/chunk-CJVA46FR.js +52 -0
  10. package/dist/chunk-CJVA46FR.js.map +1 -0
  11. package/dist/chunk-PDZKR65O.js +148 -0
  12. package/dist/chunk-PDZKR65O.js.map +1 -0
  13. package/dist/chunk-U6QF2DRY.js +30 -0
  14. package/dist/chunk-U6QF2DRY.js.map +1 -0
  15. package/dist/chunk-VYX72KGY.js +116 -0
  16. package/dist/chunk-VYX72KGY.js.map +1 -0
  17. package/dist/chunk-XS7RNJSY.js +118 -0
  18. package/dist/chunk-XS7RNJSY.js.map +1 -0
  19. package/dist/chunk-YHXC7DS5.js +92 -0
  20. package/dist/chunk-YHXC7DS5.js.map +1 -0
  21. package/dist/core-BviXjOsX.d.ts +560 -0
  22. package/dist/core.d.ts +2 -0
  23. package/dist/core.js +21 -0
  24. package/dist/core.js.map +1 -0
  25. package/dist/index.d.ts +4 -483
  26. package/dist/index.js +33 -1048
  27. package/dist/index.js.map +1 -1
  28. package/dist/ns/auth.d.ts +2 -0
  29. package/dist/ns/auth.js +4 -0
  30. package/dist/ns/auth.js.map +1 -0
  31. package/dist/ns/cart.d.ts +2 -0
  32. package/dist/ns/cart.js +4 -0
  33. package/dist/ns/cart.js.map +1 -0
  34. package/dist/ns/checkout.d.ts +2 -0
  35. package/dist/ns/checkout.js +5 -0
  36. package/dist/ns/checkout.js.map +1 -0
  37. package/dist/ns/product-list.d.ts +2 -0
  38. package/dist/ns/product-list.js +4 -0
  39. package/dist/ns/product-list.js.map +1 -0
  40. package/dist/ns/product.d.ts +2 -0
  41. package/dist/ns/product.js +4 -0
  42. package/dist/ns/product.js.map +1 -0
  43. package/dist/ns/search.d.ts +2 -0
  44. package/dist/ns/search.js +4 -0
  45. package/dist/ns/search.js.map +1 -0
  46. package/package.json +17 -2
@@ -0,0 +1,560 @@
1
+ import { Address, Order, VariantOption, ProductRating, CartItem, Facet, ProductSortKey, PaymentIntent, OrderStatus, CheckoutPayment, Customer, StoreCapabilities, ShopperOrder, Cart, CustomerAddress, PublicReviewsResult, ReviewResult, AlertKind } from '@nymbalhq/types';
2
+
3
+ interface DenormalisedVariant {
4
+ id: string;
5
+ sku: string;
6
+ name: string;
7
+ priceMinor: number;
8
+ stock: number;
9
+ options: VariantOption[];
10
+ }
11
+ interface DenormalisedProduct {
12
+ id: string;
13
+ slug: string;
14
+ name: string;
15
+ description: string;
16
+ shortDescription: string;
17
+ status: string;
18
+ type: string;
19
+ media: unknown;
20
+ variantCount: number;
21
+ inStock: boolean;
22
+ priceRange: {
23
+ minMinor: number;
24
+ maxMinor: number;
25
+ } | null;
26
+ currency: string | null;
27
+ priceMinor: number | null;
28
+ variants: DenormalisedVariant[];
29
+ categoryIds: string[];
30
+ categories: Array<{
31
+ id: string;
32
+ name: string;
33
+ slug: string;
34
+ }>;
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ /** Served by the product routes, not stored: null when the product has no approved review. */
38
+ rating?: ProductRating | null;
39
+ }
40
+ interface CartState {
41
+ items: CartItem[];
42
+ subtotalMinor: number;
43
+ currency: string;
44
+ itemCount: number;
45
+ loading: boolean;
46
+ error: string | null;
47
+ }
48
+ interface ProductState {
49
+ product: DenormalisedProduct | null;
50
+ selectedVariant: DenormalisedVariant | null;
51
+ loading: boolean;
52
+ error: string | null;
53
+ }
54
+ interface ProductListState {
55
+ products: DenormalisedProduct[];
56
+ facets: Facet[];
57
+ filters: Record<string, string | string[]>;
58
+ sort: ProductSortKey;
59
+ pagination: {
60
+ cursor: string | null;
61
+ hasMore: boolean;
62
+ };
63
+ loading: boolean;
64
+ error: string | null;
65
+ }
66
+ interface SearchState {
67
+ query: string;
68
+ /** The category slug the search is narrowed to, or null for every category. */
69
+ category: string | null;
70
+ /** Every page loaded so far, in rank order. */
71
+ results: DenormalisedProduct[];
72
+ /** The API's count of every match, not of the results loaded. */
73
+ total: number;
74
+ /** The next page's cursor; null when every match is loaded. */
75
+ nextCursor: string | null;
76
+ /** The search's facets: the category facet when search reports `facet` and the query matches. */
77
+ facets: Facet[];
78
+ loading: boolean;
79
+ }
80
+ type CheckoutStep = 'contact' | 'shipping' | 'payment' | 'confirmation';
81
+ interface ShippingMethod {
82
+ carrier: string;
83
+ service: string;
84
+ amountMinor: number;
85
+ currency: string;
86
+ estimatedDays: number;
87
+ }
88
+ interface CheckoutState {
89
+ step: CheckoutStep;
90
+ email: string;
91
+ shippingAddress: Address | null;
92
+ billingAddress: Address | null;
93
+ shippingMethod: ShippingMethod | null;
94
+ /** What the server said about the payment; `succeeded` only once the order is paid. */
95
+ paymentStatus: 'idle' | 'processing' | 'requires_action' | 'succeeded' | 'failed';
96
+ error: string | null;
97
+ /** The API's code for `error` (`auth.token_invalid`, …), null when the error came from no API answer. */
98
+ errorCode: string | null;
99
+ order: {
100
+ orderId: string;
101
+ orderNumber: string;
102
+ paymentIntent: PaymentIntent;
103
+ } | null;
104
+ /** The order this cart already became, when the server refused a resubmit and named it. */
105
+ placedOrderNumber: string | null;
106
+ /** That order's key, when the refusal carried one. */
107
+ placedOrderKey: string | null;
108
+ }
109
+ interface AuthState {
110
+ customer: Customer | null;
111
+ isAuthenticated: boolean;
112
+ loading: boolean;
113
+ error: string | null;
114
+ }
115
+ interface ProductListParams {
116
+ limit?: number;
117
+ cursor?: string;
118
+ category?: string;
119
+ sort?: ProductSortKey;
120
+ }
121
+ interface ProductListResult {
122
+ items: DenormalisedProduct[];
123
+ nextCursor: string | null;
124
+ facets?: Facet[];
125
+ }
126
+ interface ProductSearchParams {
127
+ limit?: number;
128
+ cursor?: string;
129
+ /** A category slug, as on the listing. */
130
+ category?: string;
131
+ }
132
+ interface ProductSearchResult {
133
+ items: DenormalisedProduct[];
134
+ nextCursor: string | null;
135
+ total: number;
136
+ facets: Facet[];
137
+ }
138
+ interface CheckoutDetails {
139
+ email: string;
140
+ billingAddress: Address;
141
+ shippingAddress: Address;
142
+ notes?: string;
143
+ }
144
+ interface CheckoutResult {
145
+ orderId: string;
146
+ orderNumber: string;
147
+ paymentIntent: PaymentIntent;
148
+ currency: string;
149
+ totalMinor: number;
150
+ orderStatus: OrderStatus;
151
+ payment: CheckoutPayment;
152
+ /** Reads the order with no session (`customer.orders.get(n, { key })`); absent from an API that mints none. */
153
+ orderKey?: string;
154
+ }
155
+ interface RegisterParams {
156
+ email: string;
157
+ password: string;
158
+ firstName?: string;
159
+ lastName?: string;
160
+ phone?: string;
161
+ }
162
+ interface AuthResult {
163
+ customer: Customer;
164
+ accessToken: string;
165
+ expiresIn: number;
166
+ }
167
+ type NewAddress = Address & {
168
+ isDefaultBilling?: boolean;
169
+ isDefaultShipping?: boolean;
170
+ };
171
+ interface OrderPage {
172
+ items: Order[];
173
+ nextCursor: string | null;
174
+ }
175
+
176
+ interface CommerceAdapter {
177
+ /** What the store can do (GET /api/capabilities); an adapter without it cannot tell the storefront. */
178
+ capabilities?: {
179
+ get(): Promise<StoreCapabilities>;
180
+ };
181
+ /**
182
+ * A guest's orders, read with the order's key; an expired key opens the order beside the order's email. An adapter
183
+ * without it cannot open a guest's order.
184
+ */
185
+ orders?: {
186
+ get(orderNumber: string, options?: {
187
+ key?: string;
188
+ email?: string;
189
+ }): Promise<ShopperOrder>;
190
+ /** Asks the store to email the order's link to the order's own email; it answers the same whatever matched. */
191
+ requestLink(request: {
192
+ orderNumber: string;
193
+ email: string;
194
+ }): Promise<void>;
195
+ };
196
+ /** The shopper's recently viewed products; an adapter without it shows none. */
197
+ recentlyViewed?: {
198
+ record(productId: string): Promise<void>;
199
+ list(): Promise<{
200
+ items: DenormalisedProduct[];
201
+ }>;
202
+ };
203
+ cart: {
204
+ get(): Promise<Cart>;
205
+ addItem(variantId: string, qty: number): Promise<Cart>;
206
+ removeItem(variantId: string): Promise<Cart>;
207
+ updateQuantity(variantId: string, qty: number): Promise<Cart>;
208
+ clear(): Promise<Cart>;
209
+ };
210
+ products: {
211
+ getBySlug(slug: string): Promise<DenormalisedProduct>;
212
+ list(params?: ProductListParams): Promise<ProductListResult>;
213
+ search(query: string, params?: ProductSearchParams): Promise<ProductSearchResult>;
214
+ };
215
+ checkout: {
216
+ create(details: CheckoutDetails): Promise<CheckoutResult>;
217
+ };
218
+ customers: {
219
+ register(params: RegisterParams): Promise<AuthResult>;
220
+ login(email: string, password: string): Promise<AuthResult>;
221
+ logout(): Promise<void>;
222
+ refresh(): Promise<{
223
+ accessToken: string;
224
+ expiresIn: number;
225
+ }>;
226
+ getProfile(): Promise<Customer>;
227
+ updateProfile(updates: Partial<Pick<Customer, 'firstName' | 'lastName' | 'phone'>>): Promise<Customer>;
228
+ listAddresses(): Promise<CustomerAddress[]>;
229
+ addAddress(address: NewAddress): Promise<CustomerAddress>;
230
+ removeAddress(id: string): Promise<void>;
231
+ listOrders(params?: {
232
+ cursor?: string;
233
+ }): Promise<OrderPage>;
234
+ /** `key` is the order's key from its checkout, for a reader with no session. */
235
+ getOrder(orderNumber: string, options?: {
236
+ key?: string;
237
+ }): Promise<ShopperOrder>;
238
+ };
239
+ reviews: {
240
+ getForProduct(productId: string, params?: {
241
+ limit?: number;
242
+ cursor?: string;
243
+ }): Promise<PublicReviewsResult>;
244
+ submit(review: {
245
+ productId: string;
246
+ rating: number;
247
+ title: string;
248
+ body: string;
249
+ }): Promise<ReviewResult>;
250
+ };
251
+ alerts: {
252
+ /**
253
+ * Asks to be emailed when a variant is back; the store mails a confirmation first. The answer is `pending` whether
254
+ * or not the address has an account or an alert already.
255
+ */
256
+ subscribe(request: {
257
+ email: string;
258
+ variantId: string;
259
+ kind: AlertKind;
260
+ }): Promise<{
261
+ status: 'pending';
262
+ }>;
263
+ };
264
+ }
265
+
266
+ /** A refresh: its token for the manager to hold, or nothing when it has set (or cleared) the token itself. */
267
+ type RefreshFn = () => Promise<{
268
+ accessToken: string;
269
+ expiresIn: number;
270
+ } | void>;
271
+ interface TokenManagerOptions {
272
+ storage?: 'memory' | 'localStorage';
273
+ storageKey?: string;
274
+ }
275
+ interface TokenManager {
276
+ getAccessToken(): string | null;
277
+ setTokens(accessToken: string, expiresIn: number): void;
278
+ clear(): void;
279
+ scheduleRefresh(refreshFn: RefreshFn): void;
280
+ destroy(): void;
281
+ }
282
+ declare function createTokenManager(options?: TokenManagerOptions): TokenManager;
283
+
284
+ interface CartStore {
285
+ getState(): CartState;
286
+ subscribe(listener: () => void): () => void;
287
+ addItem(variantId: string, qty?: number): Promise<void>;
288
+ removeItem(variantId: string): Promise<void>;
289
+ updateQuantity(variantId: string, qty: number): Promise<void>;
290
+ clear(): Promise<void>;
291
+ load(): Promise<void>;
292
+ destroy(): void;
293
+ }
294
+ declare function createCartStore(adapter: CommerceAdapter): CartStore;
295
+
296
+ interface ProductStore {
297
+ getState(): ProductState;
298
+ subscribe(listener: () => void): () => void;
299
+ loadBySlug(slug: string): Promise<void>;
300
+ selectVariant(variant: DenormalisedVariant | null): void;
301
+ destroy(): void;
302
+ }
303
+ declare function createProductStore(adapter: CommerceAdapter): ProductStore;
304
+
305
+ interface ProductListStore {
306
+ getState(): ProductListState;
307
+ subscribe(listener: () => void): () => void;
308
+ load(params?: ProductListParams): Promise<void>;
309
+ loadMore(): Promise<void>;
310
+ applyFilter(name: string, value: string | string[]): Promise<void>;
311
+ removeFilter(name: string): Promise<void>;
312
+ setSort(sort: ProductSortKey): Promise<void>;
313
+ destroy(): void;
314
+ }
315
+ declare function createProductListStore(adapter: CommerceAdapter): ProductListStore;
316
+
317
+ interface SearchStore {
318
+ getState(): SearchState;
319
+ subscribe(listener: () => void): () => void;
320
+ /** Page 1 of `query`, in `options.category` (a slug) when given, otherwise in every category. */
321
+ search(query: string, options?: {
322
+ category?: string | null;
323
+ }): Promise<void>;
324
+ /** Appends the next page; a no-op when every match is loaded or a page is loading. */
325
+ loadMore(): Promise<void>;
326
+ /** Page 1 of the current query in `category` (a slug), or in every category when null. */
327
+ setCategory(category: string | null): Promise<void>;
328
+ clearSearch(): void;
329
+ destroy(): void;
330
+ }
331
+ declare function createSearchStore(adapter: CommerceAdapter): SearchStore;
332
+
333
+ interface CheckoutStore {
334
+ getState(): CheckoutState;
335
+ subscribe(listener: () => void): () => void;
336
+ setEmail(email: string): void;
337
+ setShippingAddress(address: Address): void;
338
+ setBillingAddress(address: Address): void;
339
+ setShippingMethod(method: ShippingMethod): void;
340
+ /** Places the order; resolves to the server's result, or null when there is none. */
341
+ submitPayment(): Promise<CheckoutResult | null>;
342
+ /** The provider confirmed the payment on the client (Stripe's `confirmCardPayment`). */
343
+ markConfirmed(): void;
344
+ reset(): void;
345
+ destroy(): void;
346
+ }
347
+ /**
348
+ * `cart`, when given, is loaded again once the server has answered a submit: placing an order changes the cart on the
349
+ * server (emptied when confirmed, kept while awaiting payment), and whatever renders the cart store must show that.
350
+ */
351
+ declare function createCheckoutStore(adapter: CommerceAdapter, cart?: CartStore): CheckoutStore;
352
+
353
+ interface AuthStore {
354
+ getState(): AuthState;
355
+ subscribe(listener: () => void): () => void;
356
+ login(email: string, password: string): Promise<void>;
357
+ register(params: RegisterParams): Promise<void>;
358
+ logout(): Promise<void>;
359
+ refreshToken(): Promise<void>;
360
+ updateProfile(updates: Partial<Pick<Customer, 'firstName' | 'lastName' | 'phone'>>): Promise<void>;
361
+ loadProfile(): Promise<void>;
362
+ /**
363
+ * Brings a page load's session back: the profile with a token held; with none, one refresh from the refresh cookie
364
+ * when this browser has signed in (the session hint), then the profile; a guest's sends nothing. Never throws.
365
+ */
366
+ restore(): Promise<void>;
367
+ destroy(): void;
368
+ }
369
+ declare function createAuthStore(adapter: CommerceAdapter, tokenManager: TokenManager, restoreSession?: () => Promise<void>): AuthStore;
370
+
371
+ type Listener = () => void;
372
+ interface Store<TState> {
373
+ getState(): TState;
374
+ setState(partial: Partial<TState> | ((prev: TState) => Partial<TState>)): void;
375
+ subscribe(listener: Listener): () => void;
376
+ destroy(): void;
377
+ }
378
+ declare function createStore<TState extends object>(initialState: TState): Store<TState>;
379
+
380
+ interface NymbalClientOptions {
381
+ baseUrl: string;
382
+ adapter?: CommerceAdapter;
383
+ tokenStorage?: 'memory' | 'localStorage';
384
+ credentials?: RequestCredentials;
385
+ getCartToken?: () => string | null;
386
+ }
387
+ /** The signed-in customer's own account; every call sends the session's bearer token. */
388
+ interface CustomerAccount {
389
+ addresses: {
390
+ list(): Promise<CustomerAddress[]>;
391
+ create(address: NewAddress): Promise<CustomerAddress>;
392
+ remove(id: string): Promise<void>;
393
+ };
394
+ orders: {
395
+ list(opts?: {
396
+ cursor?: string;
397
+ }): Promise<OrderPage>;
398
+ /** `key`, the order's key from its checkout, reads it with no session; without one, only its owner can. */
399
+ get(orderNumber: string, options?: {
400
+ key?: string;
401
+ }): Promise<ShopperOrder>;
402
+ };
403
+ }
404
+ /**
405
+ * A guest's orders, opened with the key from the checkout or the order email. Once the key has expired, the read is
406
+ * refused with `orders.key_expired` and opens with the order's email beside the key; the email travels in a header,
407
+ * never in a URL.
408
+ */
409
+ interface GuestOrders {
410
+ get(orderNumber: string, options?: {
411
+ key?: string;
412
+ email?: string;
413
+ }): Promise<ShopperOrder>;
414
+ /** Asks the store to email the order's link to the order's own email; it answers the same whatever matched. */
415
+ requestLink(request: {
416
+ orderNumber: string;
417
+ email: string;
418
+ }): Promise<void>;
419
+ }
420
+ /** The store's capabilities report, read once per client: what it can do does not change while it runs. */
421
+ interface StoreCapabilitiesReader {
422
+ get(): Promise<StoreCapabilities>;
423
+ }
424
+ /** The shopper's recently viewed products, kept by the store under the signed-in customer or the browser's visitor. */
425
+ interface RecentlyViewed {
426
+ /** Records a view of the product; the store ignores a product that is not active. */
427
+ record(productId: string): Promise<void>;
428
+ /** The shopper's active products, newest first. */
429
+ list(): Promise<{
430
+ items: DenormalisedProduct[];
431
+ }>;
432
+ }
433
+ interface NymbalClient {
434
+ capabilities: StoreCapabilitiesReader;
435
+ recentlyViewed: RecentlyViewed;
436
+ cart: CartStore;
437
+ product: ProductStore;
438
+ productList: ProductListStore;
439
+ search: SearchStore;
440
+ checkout: CheckoutStore;
441
+ auth: AuthStore;
442
+ customer: CustomerAccount;
443
+ orders: GuestOrders;
444
+ adapter: CommerceAdapter;
445
+ destroy(): void;
446
+ }
447
+ /** What `onStoreBuilt` hands its listener: any store, a hand-made client's included, reads and subscribes. */
448
+ type ObservedStore = Pick<Store<unknown>, 'getState' | 'subscribe'>;
449
+ type StoreListener = (store: ObservedStore) => void;
450
+ /**
451
+ * `auth.restore()`'s refresh without the auth store, for a page that reads no profile: with the session hint and no
452
+ * token held, the one refresh from the refresh cookie, which every other request the client sends meanwhile waits for.
453
+ * A guest's sends nothing. An `auth.restore()` called while it is in flight shares it. Never throws.
454
+ */
455
+ declare function resumeSession(client: NymbalClient): Promise<void>;
456
+ /**
457
+ * Calls `listener` with each store namespace the client has built, and with each it builds later; returns the
458
+ * unsubscribe. A client not made by `createNymbalClient` has its stores already: each is reported once, now.
459
+ */
460
+ declare function onStoreBuilt(client: NymbalClient, listener: StoreListener): () => void;
461
+ declare function createNymbalClient(options: NymbalClientOptions): NymbalClient;
462
+
463
+ /** What a checkout already knows about the shopper, which a driver may hand its processor with the payment. */
464
+ interface PaymentConfirmContext {
465
+ email?: string;
466
+ billing?: Address;
467
+ }
468
+ /** What a payment driver's `confirm` answers: paid now, accepted without a payment yet, or refused with a reason. */
469
+ type PaymentConfirmation = {
470
+ ok: true;
471
+ confirmed: boolean;
472
+ } | {
473
+ ok: false;
474
+ error: string;
475
+ };
476
+ /**
477
+ * The browser half of a payments adapter, named by the `driver` of GET /api/capabilities' payments client. `mount`
478
+ * renders whatever the shopper pays with inside `el`; `confirm` completes a payment the API left `requires_action`,
479
+ * with the shopper's email and billing address when the checkout has them.
480
+ */
481
+ interface PaymentDriver {
482
+ mount(el: HTMLElement, options: Record<string, string>): Promise<void> | void;
483
+ confirm(clientSecret: string, context?: PaymentConfirmContext): Promise<PaymentConfirmation>;
484
+ }
485
+ /** Registers `driver` under `name`, replacing any driver of that name. */
486
+ declare function registerPaymentDriver(name: string, driver: PaymentDriver): void;
487
+ declare function getPaymentDriver(name: string): PaymentDriver | undefined;
488
+
489
+ /**
490
+ * Set in `localStorage` while the browser holds a session the refresh cookie can bring back. It holds no token: a page
491
+ * load with no hint is a guest's, and restores nothing.
492
+ */
493
+ declare const SESSION_HINT_KEY = "nymbal.auth.session";
494
+
495
+ declare class NymbalApiError extends Error {
496
+ readonly code: string;
497
+ readonly status: number;
498
+ readonly context?: Record<string, unknown> | undefined;
499
+ constructor(code: string, message: string, status: number, context?: Record<string, unknown> | undefined);
500
+ }
501
+ interface FetchClientOptions {
502
+ baseUrl: string;
503
+ credentials?: RequestCredentials;
504
+ getAccessToken?: () => string | null;
505
+ getCartToken?: () => string | null;
506
+ onUnauthorized?: () => Promise<void>;
507
+ }
508
+ /** Per request: headers sent beside the client's own. */
509
+ interface RequestOptions {
510
+ headers?: Record<string, string>;
511
+ /**
512
+ * The token refresh itself (what `onUnauthorized` sends through this client): its 401 is thrown, never waited on or
513
+ * sent again, so a refused refresh cannot wait on itself. An unmarked one that is refused is cut off after
514
+ * 10 s with the original 401.
515
+ */
516
+ authRefresh?: boolean;
517
+ /**
518
+ * Sent with a customer's bearer, never sent again without one: when the 401's refresh leaves no token, the 401 is
519
+ * thrown. For a request the API would otherwise answer as a guest (a checkout begin).
520
+ */
521
+ keepIdentity?: boolean;
522
+ }
523
+ declare class FetchClient {
524
+ private readonly baseUrl;
525
+ private readonly credentials;
526
+ private readonly getAccessToken;
527
+ private readonly getCartToken;
528
+ private readonly onUnauthorized;
529
+ /** The refresh a refused request started, which every request refused meanwhile waits on rather than its own. */
530
+ private refreshing;
531
+ /** The token `GET /api/csrf` answered: the API's `nymbal.csrf` cookie, which this origin may not be able to read. */
532
+ private csrfToken;
533
+ /** A session restore's refresh, which every request sent meanwhile waits on so that none goes out as a guest. */
534
+ private held;
535
+ constructor(options: FetchClientOptions);
536
+ /** Starts the session's refresh, or joins the one in flight: a client sends one refresh at a time. */
537
+ refreshSession(): Promise<void>;
538
+ /**
539
+ * As `refreshSession`, and every other request sent until the refresh settles waits for it, at most
540
+ * `REFRESH_WAIT_MS`. Held from this call on, before any await: a page's first requests go in the same tick.
541
+ */
542
+ restoreSession(): Promise<void>;
543
+ request<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<T>;
544
+ /** Like `request`, keeping the envelope's `meta` (pagination cursors live there). */
545
+ requestWithMeta<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<{
546
+ data: T;
547
+ meta: Record<string, unknown>;
548
+ }>;
549
+ /** Whether the refresh ended within `REFRESH_WAIT_MS`; a refresh that fails throws here, as it always has. */
550
+ private waitFor;
551
+ private refresh;
552
+ private csrf;
553
+ private fetchCsrfToken;
554
+ private isCsrfRejection;
555
+ private doFetch;
556
+ private parseResponse;
557
+ }
558
+
559
+ export { getPaymentDriver as $, FetchClient as F, createAuthStore as M, createCartStore as Q, SESSION_HINT_KEY as S, createCheckoutStore as U, createNymbalClient as V, createProductListStore as W, createProductStore as X, createSearchStore as Y, createStore as Z, createTokenManager as _, registerPaymentDriver as a0, onStoreBuilt as a1, resumeSession as a2, NymbalApiError as m };
560
+ export type { AuthResult as A, SearchState as B, CommerceAdapter as C, DenormalisedProduct as D, SearchStore as E, GuestOrders as G, ShippingMethod as H, Store as I, StoreCapabilitiesReader as J, TokenManagerOptions as K, Listener as L, NewAddress as N, OrderPage as O, PaymentConfirmContext as P, RecentlyViewed as R, TokenManager as T, AuthState as a, AuthStore as b, CartState as c, CartStore as d, CheckoutDetails as e, CheckoutResult as f, CheckoutState as g, CheckoutStep as h, CheckoutStore as i, CustomerAccount as j, DenormalisedVariant as k, FetchClientOptions as l, NymbalClient as n, NymbalClientOptions as o, PaymentConfirmation as p, PaymentDriver as q, ProductListParams as r, ProductListResult as s, ProductListState as t, ProductListStore as u, ProductSearchParams as v, ProductSearchResult as w, ProductState as x, ProductStore as y, RegisterParams as z };
package/dist/core.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { j as CustomerAccount, G as GuestOrders, m as NymbalApiError, n as NymbalClient, o as NymbalClientOptions, P as PaymentConfirmContext, p as PaymentConfirmation, q as PaymentDriver, R as RecentlyViewed, S as SESSION_HINT_KEY, J as StoreCapabilitiesReader, V as createNymbalClient, $ as getPaymentDriver, a1 as onStoreBuilt, a0 as registerPaymentDriver, a2 as resumeSession } from './core-BviXjOsX.js';
2
+ import '@nymbalhq/types';
package/dist/core.js ADDED
@@ -0,0 +1,21 @@
1
+ import {
2
+ getPaymentDriver,
3
+ registerPaymentDriver
4
+ } from "./chunk-4GP43MKT.js";
5
+ import {
6
+ NymbalApiError,
7
+ SESSION_HINT_KEY,
8
+ createNymbalClient,
9
+ onStoreBuilt,
10
+ resumeSession
11
+ } from "./chunk-2EEZZXZX.js";
12
+ export {
13
+ NymbalApiError,
14
+ SESSION_HINT_KEY,
15
+ createNymbalClient,
16
+ getPaymentDriver,
17
+ onStoreBuilt,
18
+ registerPaymentDriver,
19
+ resumeSession
20
+ };
21
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}