@scryme/sdk 9.67.0 → 9.68.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/client.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance, AxiosResponse } from 'axios';
2
- import { ae as CustomerResponseDto, G as ProductResponseDto, K as ServiceCatalogResponseDto, cM as CartItemDto, b7 as CartResponseDto, dK as CustomerSessionDto, fT as RawAPI, cT as CatalogModule, ep as InventoryModule, fh as OrdersModule, cH as CRMModule, fp as POSModule, bN as AccountingModule, eR as LoyaltyModule, fa as MembersModule, cf as AdminModule, b6 as CartControllerGetCartParams, b9 as AddToCartDto, ba as RemoveFromCartDto, b8 as CartControllerClearCartParams, az as OrderResponseDto, ai as UpdateCustomerDto, aj as AddressDto, af as RegisterCustomerDto, dJ as CustomerAuthResponseDto, a0 as CreateBookingDto, gf as ServiceBookingItemDto, cs as AuthModule, s as AuthExchangeToken201 } from './base-1B2-e5i_.mjs';
2
+ import { ai as CustomerResponseDto, G as ProductResponseDto, K as ServiceCatalogResponseDto, cQ as CartItemDto, bb as CartResponseDto, dS as CustomerSessionDto, cZ as CatalogModule, ex as InventoryModule, fp as OrdersModule, cL as CRMModule, fx as POSModule, bR as AccountingModule, eZ as LoyaltyModule, fi as MembersModule, cj as AdminModule, ba as CartControllerGetCartParams, bd as AddToCartDto, be as RemoveFromCartDto, bc as CartControllerClearCartParams, aD as OrderResponseDto, am as UpdateCustomerDto, an as AddressDto, aj as RegisterCustomerDto, dQ as CustomerAuthResponseDto, a4 as CreateBookingDto, gu as ServiceBookingItemDto, cw as AuthModule, s as AuthExchangeToken201 } from './base-CSVOv3Nr.mjs';
3
3
 
4
4
  /**
5
5
  * Defines a storage contract for persisting authentication tokens and session data.
@@ -70,6 +70,22 @@ interface SessionState<TUser = CustomerResponseDto> {
70
70
  */
71
71
  expiresAt?: number | null;
72
72
  }
73
+ /**
74
+ * Standard client-side session structure matching better-auth.
75
+ */
76
+ interface ClientSessionStructure<TUser = CustomerResponseDto> {
77
+ data: {
78
+ session: {
79
+ id: string;
80
+ userId: string;
81
+ expiresAt: Date | null;
82
+ token: string | null;
83
+ };
84
+ user: TUser;
85
+ } | null;
86
+ isPending: boolean;
87
+ error: any;
88
+ }
73
89
  /**
74
90
  * Callback signature triggered whenever the customer authentication status changes.
75
91
  */
@@ -95,7 +111,7 @@ declare class ScrymeClientSDK<TProduct = ProductResponseDto, TService = ServiceC
95
111
  /**
96
112
  * Raw proxy API client exposing all standard endpoints auto-bound with the configured orgSlug.
97
113
  */
98
- api: RawAPI;
114
+ private api;
99
115
  /** Catalog operations submodule (products, services, categories, bookings, staff schedules). */
100
116
  catalog: CatalogModule<TProduct, TService>;
101
117
  /** Traceability, split/merge, physical reconciliation, and partner wallet operations submodule. */
@@ -119,20 +135,72 @@ declare class ScrymeClientSDK<TProduct = ProductResponseDto, TService = ServiceC
119
135
  * Leverages internal tracking and smart delta calculations for optimized storefront shopping.
120
136
  */
121
137
  cart: {
138
+ /**
139
+ * Retrieves the active shopping cart for the current session or customer.
140
+ * @param params Optional cart parameters including sessionId.
141
+ * @returns Promise containing the axios response with the cart details.
142
+ */
122
143
  get<T = TCartResponse>(params?: CartControllerGetCartParams): Promise<AxiosResponse<T & Record<string, any>>>;
144
+ /**
145
+ * Adds a product variant or service to the shopping cart.
146
+ * Automatically resolves and appends the customer ID from the active customer session if omitted.
147
+ * @param dto Data transfer object containing the item details and quantity.
148
+ * @returns Promise containing the axios response.
149
+ */
123
150
  add(dto: AddToCartDto): Promise<AxiosResponse<void>>;
151
+ /**
152
+ * Removes a product variant or service from the shopping cart.
153
+ * Automatically resolves and appends the customer ID from the active customer session if omitted.
154
+ * @param dto Data transfer object specifying the item to remove.
155
+ * @returns Promise containing the axios response.
156
+ */
124
157
  remove(dto: RemoveFromCartDto): Promise<AxiosResponse<void>>;
158
+ /**
159
+ * Clears all items from the active shopping cart.
160
+ * @param params Optional clear parameters containing sessionId.
161
+ * @returns Promise containing the axios response.
162
+ */
125
163
  clear(params?: CartControllerClearCartParams): Promise<AxiosResponse<void>>;
164
+ /**
165
+ * Updates the quantity of a product variant or service in the shopping cart.
166
+ * Computes the difference and invokes add or remove operations accordingly.
167
+ * Automatically resolves and appends the customer ID from the active customer session if omitted.
168
+ * @param dto Data transfer object containing item identifiers and the target absolute quantity.
169
+ * @returns Promise resolving to the updated cart state or undefined.
170
+ */
126
171
  update<T = TCartResponse>(dto: AddToCartDto & {
127
172
  quantity: number;
128
173
  }): Promise<AxiosResponse<void> | AxiosResponse<T> | undefined>;
174
+ /**
175
+ * Retrieves the flat list of cart items currently in the cart.
176
+ * @param params Optional parameters.
177
+ * @returns Promise resolving to an array of cart items.
178
+ */
129
179
  getItems<T = TCartItem>(params?: CartControllerGetCartParams): Promise<T[]>;
180
+ /**
181
+ * Calculates the totals, item counts, and summary metrics of the current shopping cart.
182
+ * @param params Optional parameters.
183
+ * @returns Promise resolving to the totals object containing the itemsCount, item array, and raw cart.
184
+ */
130
185
  getTotals<TItem = TCartItem, TRaw = TCartResponse>(params?: CartControllerGetCartParams): Promise<{
131
186
  itemsCount: number;
132
187
  items: TItem[];
133
188
  raw: TRaw;
134
189
  }>;
190
+ /**
191
+ * Merges a guest shopping cart session into an authenticated customer's shopping cart.
192
+ * @param guestSessionId The guest session token to migrate items from.
193
+ * @param customerId The destination customer ID.
194
+ * @returns Promise resolving to the merged cart state.
195
+ */
135
196
  mergeGuestCart<T = TCartResponse>(guestSessionId: string, customerId: string): Promise<AxiosResponse<T & Record<string, any>>>;
197
+ /**
198
+ * Finalizes the shopping cart, creating a physical Sales Order for checkout.
199
+ * Automatically resolves and appends the customer ID from the active customer session.
200
+ * Clears the shopping cart state upon successful transaction creation.
201
+ * @param params Checkout configurations including locationId, channel, and custom notes.
202
+ * @returns Promise resolving to the created order response.
203
+ */
136
204
  checkout(params: {
137
205
  locationId: string;
138
206
  notes?: string;
@@ -144,57 +212,241 @@ declare class ScrymeClientSDK<TProduct = ProductResponseDto, TService = ServiceC
144
212
  * Manages the authenticated user's self-serve account, update workflows, and shipping/billing directories.
145
213
  */
146
214
  customer: {
215
+ /**
216
+ * Fetches the current customer profile details.
217
+ * @template T The expected type of the user profile.
218
+ * @returns Promise resolving to the user profile object.
219
+ */
147
220
  getProfile<T = TUser>(): Promise<T>;
221
+ /**
222
+ * Updates the profile information of the authenticated customer.
223
+ * @param dto Updated field attributes.
224
+ * @returns Promise containing the updated customer profile response.
225
+ */
148
226
  updateProfile<T = TUser>(dto: UpdateCustomerDto): Promise<AxiosResponse<T>>;
227
+ /**
228
+ * Retrieves all saved billing/shipping addresses for the active customer.
229
+ * @returns Promise resolving to the list of address records.
230
+ */
149
231
  getAddresses(): Promise<AxiosResponse<AddressDto[]>>;
232
+ /**
233
+ * Saves a new address record to the active customer's profile directory.
234
+ * @param dto The address details to persist.
235
+ * @returns Promise containing the response of the creation operation.
236
+ */
150
237
  addAddress(dto: AddressDto): Promise<AxiosResponse<void>>;
238
+ /**
239
+ * Reactive & Stateful Customer Authentication Submodule.
240
+ */
151
241
  auth: {
242
+ /**
243
+ * Gets the current customer session synchronously in standard format.
244
+ * Reflects the active customer state immediately without causing React re-renders.
245
+ */
246
+ get session(): ClientSessionStructure<TUser>;
247
+ /**
248
+ * Registers a new customer storefront profile.
249
+ * Automatically performs sign-in and establishes a customer session if a password is provided.
250
+ * @param dto The customer registration attributes (email, name, password, etc.).
251
+ * @returns Promise containing the created customer details.
252
+ */
152
253
  signUp<T = TUser>(dto: RegisterCustomerDto): Promise<AxiosResponse<T>>;
254
+ /**
255
+ * Authenticates a customer using their credentials, starting an active session.
256
+ * Triggers a 'SIGNED_IN' authentication state change event.
257
+ * @param credentials Customer login email and optional password.
258
+ * @returns Promise containing the session token and user profile.
259
+ */
153
260
  signIn<TSess = TSession, TU = TUser>(credentials: {
154
261
  email: string;
155
262
  password?: string;
156
263
  }): Promise<CustomerAuthResponseDto<TU, TSess>>;
264
+ /**
265
+ * Terminate the active customer session, clearing persisted tokens and session memory.
266
+ * Triggers a 'SIGNED_OUT' authentication state change event.
267
+ * @returns Promise resolving once state cleanup is done.
268
+ */
157
269
  signOut(): Promise<void>;
270
+ /**
271
+ * Retrieves the raw internal authentication state synchronously/asynchronously.
272
+ * @returns Promise containing token and user state.
273
+ */
158
274
  getSession<TU = TUser>(): Promise<SessionState<TU>>;
275
+ /**
276
+ * Registers a listener to reactively monitor authentication events.
277
+ * Triggers callback upon 'SIGNED_IN', 'SIGNED_OUT', or 'INITIAL_SESSION' events.
278
+ * @param callback Callback function.
279
+ * @returns Subscription reference containing unsubscribe cleanup method.
280
+ */
159
281
  onAuthStateChange<TU = TUser>(callback: AuthStateCallback<TU>): {
160
282
  unsubscribe(): void;
161
283
  };
284
+ /**
285
+ * Lists all active concurrent sessions associated with this customer profile.
286
+ * @returns Promise containing the list of active session tokens and metadata.
287
+ */
162
288
  getSessions<TSess = TSession>(): Promise<TSess[]>;
289
+ /**
290
+ * Revokes and terminates a specific active customer session by its identifier.
291
+ * @param id The session identifier to destroy.
292
+ * @returns Promise containing the revocation response.
293
+ */
163
294
  revokeSession(id: string): Promise<AxiosResponse<void>>;
295
+ /**
296
+ * Revokes and terminates all other concurrent sessions for this customer.
297
+ * @param mode Optional mode configurations.
298
+ * @returns Promise containing the response.
299
+ */
164
300
  revokeAllSessions(mode?: string): Promise<AxiosResponse<void>>;
301
+ /**
302
+ * Retrieves the current customer user record from the backend.
303
+ * @returns Promise containing the active customer user details.
304
+ */
165
305
  getCurrentSession<TU = TUser>(): Promise<TU>;
306
+ /**
307
+ * Refreshes the active customer session, extending the validity of the customer JWT token.
308
+ * Triggers automatic session token updates and reactive state updates.
309
+ * @returns Promise resolving to the fresh customer authentication response.
310
+ */
166
311
  refreshSession<TSess = TSession, TU = TUser>(): Promise<CustomerAuthResponseDto<TU, TSess>>;
312
+ /**
313
+ * Stateful, reactive React Hook that fetches, manages, and updates the customer session.
314
+ * Subscribes to authentication state change listeners to ensure immediate UI synchronization.
315
+ * @returns Reactive session state containing session, user, error, pending flags, and refetch handler.
316
+ */
317
+ useSession<TSess = TSession, TU = TUser>(): {
318
+ data: {
319
+ session: TSess;
320
+ user: TU;
321
+ } | null;
322
+ isPending: boolean;
323
+ error: any;
324
+ refetch: () => Promise<void>;
325
+ };
167
326
  };
168
327
  };
169
328
  /**
170
329
  * Service Bookings & Appointments Submodule.
171
330
  */
172
331
  bookings: {
332
+ /**
333
+ * Creates a new booking appointment.
334
+ * Automatically resolves and appends the customer ID from the active customer session if omitted.
335
+ * @param dto The service booking reservation parameters.
336
+ * @returns Promise containing the booking creation response.
337
+ */
173
338
  create(dto: CreateBookingDto): Promise<AxiosResponse<void>>;
339
+ /**
340
+ * Retrieves the full details of a specific service booking by its identifier.
341
+ * @param id Service booking ID.
342
+ * @returns Promise containing the booking details response.
343
+ */
174
344
  get(id: string): Promise<AxiosResponse<ServiceBookingItemDto>>;
345
+ /**
346
+ * Lists all service bookings and reservations associated with the authenticated customer.
347
+ * @returns Promise containing the list of service booking records.
348
+ */
175
349
  list(): Promise<AxiosResponse<ServiceBookingItemDto[]>>;
350
+ /**
351
+ * Cancels an existing service booking appointment.
352
+ * @param id Service booking ID to cancel.
353
+ * @returns Promise containing the cancellation response.
354
+ */
176
355
  cancel(id: string): Promise<AxiosResponse<void>>;
177
356
  };
178
357
  /**
179
358
  * Authentication & Customer Session Submodule.
180
359
  */
181
360
  auth: AuthModule & {
361
+ /**
362
+ * Gets the current customer session synchronously in standard format.
363
+ * Reflects the active customer state immediately without causing React re-renders.
364
+ */
365
+ get session(): ClientSessionStructure<TUser>;
366
+ /**
367
+ * Registers a new customer storefront profile.
368
+ * Automatically performs sign-in and establishes a customer session if a password is provided.
369
+ * @param dto The customer registration attributes (email, name, password, etc.).
370
+ * @returns Promise containing the created customer details.
371
+ */
182
372
  signUp<T = TUser>(dto: RegisterCustomerDto): Promise<AxiosResponse<T>>;
373
+ /**
374
+ * Authenticates application or SDK client via client ID and client secret credentials.
375
+ * @returns Promise resolving to the token exchange response containing access token.
376
+ */
183
377
  authenticate(): Promise<AuthExchangeToken201>;
378
+ /**
379
+ * Authenticates a customer using their credentials, starting an active session.
380
+ * Triggers a 'SIGNED_IN' authentication state change event.
381
+ * @param credentials Customer login email and optional password.
382
+ * @returns Promise containing the session token and user profile.
383
+ */
184
384
  signIn<TSess = TSession, TU = TUser>(credentials: {
185
385
  email: string;
186
386
  password?: string;
187
387
  }): Promise<CustomerAuthResponseDto<TU, TSess>>;
388
+ /**
389
+ * Terminate the active customer session, clearing persisted tokens and session memory.
390
+ * Triggers a 'SIGNED_OUT' authentication state change event.
391
+ * @returns Promise resolving once state cleanup is done.
392
+ */
188
393
  signOut(): Promise<void>;
394
+ /**
395
+ * Retrieves the raw internal authentication state synchronously/asynchronously.
396
+ * @returns Promise containing token and user state.
397
+ */
189
398
  getSession<TU = TUser>(): Promise<SessionState<TU>>;
399
+ /**
400
+ * Registers a listener to reactively monitor authentication events.
401
+ * Triggers callback upon 'SIGNED_IN', 'SIGNED_OUT', or 'INITIAL_SESSION' events.
402
+ * @param callback Callback function.
403
+ * @returns Subscription reference containing unsubscribe cleanup method.
404
+ */
190
405
  onAuthStateChange<TU = TUser>(callback: AuthStateCallback<TU>): {
191
406
  unsubscribe(): void;
192
407
  };
408
+ /**
409
+ * Lists all active concurrent sessions associated with this customer profile.
410
+ * @returns Promise containing the list of active session tokens and metadata.
411
+ */
193
412
  getSessions<TSess = TSession>(): Promise<TSess[]>;
413
+ /**
414
+ * Revokes and terminates a specific active customer session by its identifier.
415
+ * @param id The session identifier to destroy.
416
+ * @returns Promise containing the revocation response.
417
+ */
194
418
  revokeSession(id: string): Promise<AxiosResponse<void>>;
419
+ /**
420
+ * Revokes and terminates all other concurrent sessions for this customer.
421
+ * @param mode Optional mode configurations.
422
+ * @returns Promise containing the response.
423
+ */
195
424
  revokeAllSessions(mode?: string): Promise<AxiosResponse<void>>;
425
+ /**
426
+ * Retrieves the current customer user record from the backend.
427
+ * @returns Promise containing the active customer user details.
428
+ */
196
429
  getCurrentSession<TU = TUser>(): Promise<TU>;
430
+ /**
431
+ * Refreshes the active customer session, extending the validity of the customer JWT token.
432
+ * Triggers automatic session token updates and reactive state updates.
433
+ * @returns Promise resolving to the fresh customer authentication response.
434
+ */
197
435
  refreshSession<TSess = TSession, TU = TUser>(): Promise<CustomerAuthResponseDto<TU, TSess>>;
436
+ /**
437
+ * Stateful, reactive React Hook that fetches, manages, and updates the customer session.
438
+ * Subscribes to authentication state change listeners to ensure immediate UI synchronization.
439
+ * @returns Reactive session state containing session, user, error, pending flags, and refetch handler.
440
+ */
441
+ useSession<TSess = TSession, TU = TUser>(): {
442
+ data: {
443
+ session: TSess;
444
+ user: TU;
445
+ } | null;
446
+ isPending: boolean;
447
+ error: any;
448
+ refetch: () => Promise<void>;
449
+ };
198
450
  };
199
451
  /**
200
452
  * Initializes the ScrymeClientSDK.
@@ -208,4 +460,4 @@ declare class ScrymeClientSDK<TProduct = ProductResponseDto, TService = ServiceC
208
460
  */
209
461
  declare function createClientSDK<TProduct = ProductResponseDto, TService = ServiceCatalogResponseDto, TCartItem = CartItemDto, TCartResponse = CartResponseDto, TUser = CustomerResponseDto, TSession = CustomerSessionDto>(config?: Partial<ClientSDKConfig>): ScrymeClientSDK<TProduct, TService, TCartItem, TCartResponse, TUser, TSession>;
210
462
 
211
- export { type AuthChangeEvent, type AuthStateCallback, type ClientSDKConfig, ScrymeClientSDK, type SessionState, type StorageProvider, createClientSDK };
463
+ export { type AuthChangeEvent, type AuthStateCallback, type ClientSDKConfig, type ClientSessionStructure, ScrymeClientSDK, type SessionState, type StorageProvider, createClientSDK };