@sazito/client-sdk 1.2.2 → 1.2.4

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.ts CHANGED
@@ -68,6 +68,7 @@ interface RequestOptions {
68
68
  cache?: boolean;
69
69
  headers?: Record<string, string>;
70
70
  signal?: AbortSignal;
71
+ skipTransform?: boolean;
71
72
  }
72
73
  /**
73
74
  * Cookie options for token storage
@@ -96,9 +97,19 @@ interface Image {
96
97
  /**
97
98
  * Product attribute (e.g., color, size)
98
99
  */
100
+ /**
101
+ * Rich attribute value for typed fields like color swatches.
102
+ * `value` is the human-readable label; `extra` carries the payload
103
+ * (e.g. a hex color when `fieldType` is `'color'`).
104
+ */
105
+ interface ProductAttributeValueObject {
106
+ value: string;
107
+ extra?: string;
108
+ fieldType?: string;
109
+ }
99
110
  interface ProductAttribute {
100
111
  name: string;
101
- value: string;
112
+ value: string | ProductAttributeValueObject;
102
113
  }
103
114
  /**
104
115
  * Normalized product snapshot embedded in checkout entities
@@ -247,7 +258,6 @@ interface Cart {
247
258
  deleteCoupon?: boolean;
248
259
  }
249
260
  interface CartCredentials {
250
- id: number;
251
261
  identifier: string;
252
262
  }
253
263
  interface AddToCartInput {
@@ -330,6 +340,7 @@ interface ShippingAddress {
330
340
  city: ShippingAddressCity;
331
341
  address: string;
332
342
  postalCode?: string;
343
+ description?: string;
333
344
  latitude?: number;
334
345
  longitude?: number;
335
346
  userSetCoordinatesBefore?: boolean;
@@ -347,6 +358,7 @@ interface InvoiceShippingAddress {
347
358
  region?: InvoiceShippingAddressRegion;
348
359
  address: string;
349
360
  postalCode?: string;
361
+ description?: string;
350
362
  latitude?: number;
351
363
  longitude?: number;
352
364
  userSetCoordinatesBefore?: boolean;
@@ -396,11 +408,9 @@ interface InvoiceCredentials {
396
408
  identifier: string;
397
409
  }
398
410
  interface CreateInvoiceInput {
399
- cartId: number;
400
411
  cartIdentifier: string;
401
412
  }
402
413
  interface RefreshInvoiceInput {
403
- cartId: number;
404
414
  cartIdentifier: string;
405
415
  identifier: string;
406
416
  }
@@ -417,6 +427,7 @@ interface ShippingRate {
417
427
  id: number;
418
428
  name: string;
419
429
  price: number;
430
+ description?: string;
420
431
  icon?: string;
421
432
  color?: string;
422
433
  type?: string;
@@ -440,6 +451,7 @@ interface ShippingAddressInput {
440
451
  cityId?: number;
441
452
  address: string;
442
453
  postalCode?: string;
454
+ description?: string;
443
455
  latitude?: number;
444
456
  longitude?: number;
445
457
  showMap?: boolean;
@@ -492,6 +504,16 @@ type PaymentStatus = 'PENDING' | 'PROCESSING' | 'PAID' | 'FAILED' | 'CANCELLED'
492
504
  interface PaymentMethod {
493
505
  id: number;
494
506
  code: PaymentGateway;
507
+ /** Backend display title (English). */
508
+ title: string;
509
+ /** Backend display title (Persian). */
510
+ titleFa: string;
511
+ /** Backend description; often null. */
512
+ description: string | null;
513
+ /** Backend payment sub-type id; null when not provided. */
514
+ paymentSubType: number | null;
515
+ /** Display order from backend. */
516
+ order: number;
495
517
  isDefault: boolean;
496
518
  }
497
519
  interface Payment {
@@ -708,6 +730,73 @@ interface MenuNode {
708
730
  children: MenuNode[];
709
731
  }
710
732
 
733
+ /**
734
+ * Credentials Manager for guest users
735
+ * Manages cart, invoice, shipping, and payment credentials.
736
+ * Accepts an optional StorageAdapter — defaults to localStorage in browsers,
737
+ * in-memory otherwise (SSR / server actions).
738
+ */
739
+
740
+ interface StorageAdapter {
741
+ getItem(key: string): string | null;
742
+ setItem(key: string, value: string): void;
743
+ removeItem(key: string): void;
744
+ }
745
+ declare class MemoryStorage implements StorageAdapter {
746
+ private data;
747
+ getItem(key: string): string | null;
748
+ setItem(key: string, value: string): void;
749
+ removeItem(key: string): void;
750
+ }
751
+ declare class CredentialsManager {
752
+ private readonly CART_KEY;
753
+ private readonly INVOICE_KEY;
754
+ private readonly SHIPPING_KEY;
755
+ private readonly PAYMENT_KEY;
756
+ private readonly DISCOUNT_KEY;
757
+ private storage;
758
+ constructor(storage?: StorageAdapter);
759
+ /**
760
+ * Cart Credentials
761
+ */
762
+ getCartCredentials(): CartCredentials | null;
763
+ setCartCredentials(credentials: CartCredentials & {
764
+ id?: number;
765
+ }): void;
766
+ clearCartCredentials(): void;
767
+ /**
768
+ * Invoice Credentials
769
+ */
770
+ getInvoiceCredentials(): InvoiceCredentials | null;
771
+ setInvoiceCredentials(credentials: InvoiceCredentials): void;
772
+ clearInvoiceCredentials(): void;
773
+ /**
774
+ * Shipping Address Credentials
775
+ */
776
+ getShippingCredentials(): ShippingAddressCredentials | null;
777
+ setShippingCredentials(credentials: ShippingAddressCredentials): void;
778
+ clearShippingCredentials(): void;
779
+ /**
780
+ * Payment Credentials
781
+ */
782
+ getPaymentCredentials(): PaymentCredentials | null;
783
+ setPaymentCredentials(credentials: PaymentCredentials): void;
784
+ clearPaymentCredentials(): void;
785
+ /**
786
+ * Discount Code
787
+ */
788
+ getDiscountCode(): string | null;
789
+ setDiscountCode(code: string): void;
790
+ clearDiscountCode(): void;
791
+ /**
792
+ * Clear all credentials
793
+ */
794
+ clearAll(): void;
795
+ private getItem;
796
+ private setItem;
797
+ private removeItem;
798
+ }
799
+
711
800
  /**
712
801
  * Token storage for auth token persistence
713
802
  * Primary storage: localStorage (user_id_token), with cookie fallback.
@@ -892,65 +981,6 @@ declare class CategoriesAPI {
892
981
  list(filters?: CategoryFilters, options?: RequestOptions): Promise<SazitoResponse<CategoryListResponse>>;
893
982
  }
894
983
 
895
- /**
896
- * Credentials Manager for guest users
897
- * Manages cart, invoice, shipping, and payment credentials in localStorage
898
- */
899
-
900
- declare class CredentialsManager {
901
- private readonly CART_KEY;
902
- private readonly INVOICE_KEY;
903
- private readonly SHIPPING_KEY;
904
- private readonly PAYMENT_KEY;
905
- private readonly DISCOUNT_KEY;
906
- /**
907
- * Cart Credentials
908
- */
909
- getCartCredentials(): CartCredentials | null;
910
- setCartCredentials(credentials: CartCredentials): void;
911
- clearCartCredentials(): void;
912
- /**
913
- * Invoice Credentials
914
- */
915
- getInvoiceCredentials(): InvoiceCredentials | null;
916
- setInvoiceCredentials(credentials: InvoiceCredentials): void;
917
- clearInvoiceCredentials(): void;
918
- /**
919
- * Shipping Address Credentials
920
- */
921
- getShippingCredentials(): ShippingAddressCredentials | null;
922
- setShippingCredentials(credentials: ShippingAddressCredentials): void;
923
- clearShippingCredentials(): void;
924
- /**
925
- * Payment Credentials
926
- */
927
- getPaymentCredentials(): PaymentCredentials | null;
928
- setPaymentCredentials(credentials: PaymentCredentials): void;
929
- clearPaymentCredentials(): void;
930
- /**
931
- * Discount Code
932
- */
933
- getDiscountCode(): string | null;
934
- setDiscountCode(code: string): void;
935
- clearDiscountCode(): void;
936
- /**
937
- * Clear all credentials
938
- */
939
- clearAll(): void;
940
- /**
941
- * Get item from localStorage
942
- */
943
- private getItem;
944
- /**
945
- * Set item in localStorage
946
- */
947
- private setItem;
948
- /**
949
- * Remove item from localStorage
950
- */
951
- private removeItem;
952
- }
953
-
954
984
  /**
955
985
  * Cart API
956
986
  * Supports both authenticated and guest users via credentials
@@ -1100,14 +1130,25 @@ declare class ShippingAPI {
1100
1130
  private credentials;
1101
1131
  constructor(http: HttpClient, credentials: CredentialsManager);
1102
1132
  private sanitizeAddressInput;
1133
+ private unwrapAddressPayload;
1134
+ private extractAddressList;
1103
1135
  /**
1104
1136
  * Create shipping address
1105
1137
  */
1106
1138
  createAddress(address: ShippingAddressInput, options?: RequestOptions): Promise<SazitoResponse<ShippingAddress>>;
1107
1139
  /**
1108
- * Update shipping address
1140
+ * Update the address referenced by the currently stored credentials.
1141
+ * @deprecated Do not use during checkout. Existing invoices can reference
1142
+ * this row, so mutation can rewrite address data shown on previous orders.
1143
+ * Create a new address snapshot with createAddress instead.
1109
1144
  */
1110
1145
  updateAddress(address: ShippingAddressInput, options?: RequestOptions): Promise<SazitoResponse<ShippingAddress>>;
1146
+ /**
1147
+ * Get the authenticated user's shipping addresses, newest first.
1148
+ * This endpoint is intentionally not cached: checkout must see an address
1149
+ * created by the user's most recent order immediately.
1150
+ */
1151
+ listAddresses(options?: RequestOptions): Promise<SazitoResponse<ShippingAddress[]>>;
1111
1152
  /**
1112
1153
  * Get shipping address
1113
1154
  */
@@ -1140,13 +1181,30 @@ declare class PaymentsAPI {
1140
1181
  */
1141
1182
  create(paymentTypeId: number, options?: RequestOptions): Promise<SazitoResponse<Payment>>;
1142
1183
  /**
1143
- * Initialize payment (get payment action)
1184
+ * Initialize payment: start the payment step before redirecting the user to
1185
+ * the gateway. Returns the next {@link PaymentAction} (typically REDIRECT or
1186
+ * POST for hosted gateways, or showOrder for zero-amount/instant payments).
1144
1187
  */
1145
1188
  initialize(options?: RequestOptions): Promise<SazitoResponse<PaymentAction>>;
1146
1189
  /**
1147
- * Process payment step (for card-to-card or multi-step payments)
1190
+ * Verify payment after the user returns from the gateway. Forwards the
1191
+ * gateway callback parameters (e.g. `tatoken`, `trackingData`, `isFailed`,
1192
+ * `code`) to the same payment-step endpoint and returns the settled
1193
+ * {@link PaymentAction} (showOrder on success, FAIL/StockViolated otherwise,
1194
+ * or pending if the gateway has not reported back yet).
1195
+ */
1196
+ verify(input?: PaymentStepInput, options?: RequestOptions): Promise<SazitoResponse<PaymentAction>>;
1197
+ /**
1198
+ * Process payment step (for card-to-card or multi-step payments).
1199
+ *
1200
+ * @deprecated Prefer {@link verify} for gateway-return verification.
1148
1201
  */
1149
1202
  processStep(input: PaymentStepInput, options?: RequestOptions): Promise<SazitoResponse<PaymentAction>>;
1203
+ /**
1204
+ * Shared core for the `process_payment_step` endpoint used by
1205
+ * {@link initialize}, {@link verify} and {@link processStep}.
1206
+ */
1207
+ private submitPaymentStep;
1150
1208
  /**
1151
1209
  * Process payment step in form mode (non-JSON content-type).
1152
1210
  */
@@ -1162,7 +1220,12 @@ declare class PaymentsAPI {
1162
1220
  private withExactJsonHeader;
1163
1221
  private buildProcessStepFormData;
1164
1222
  private appendFormValue;
1165
- private normalizePayment;
1223
+ /**
1224
+ * Post-process a `process_payment_step` response. The exact-JSON endpoint
1225
+ * returns an envelope `{ result: PaymentAction, error, error_code, status }`;
1226
+ * unwrap `result`, surface envelope-level errors, and run the pinch hook.
1227
+ */
1228
+ private finalizeStepResponse;
1166
1229
  private normalizeAction;
1167
1230
  private callPinchAfterSuccessfulPayment;
1168
1231
  }
@@ -1834,6 +1897,7 @@ declare class MenuAPI {
1834
1897
  * Extract the display title for a menu node
1835
1898
  */
1836
1899
  private findNodeTitle;
1900
+ private firstNonEmpty;
1837
1901
  /**
1838
1902
  * Extract the URL for a menu node
1839
1903
  */
@@ -2078,7 +2142,7 @@ declare class SazitoClient {
2078
2142
  readonly general: GeneralAPI;
2079
2143
  readonly dynamicForms: DynamicFormsAPI;
2080
2144
  readonly regions: RegionsAPI;
2081
- constructor(config: SazitoConfig);
2145
+ constructor(config: SazitoConfig, credentialsManager?: CredentialsManager);
2082
2146
  /**
2083
2147
  * Set authentication token (stored in localStorage with cookie fallback)
2084
2148
  */
@@ -2103,6 +2167,12 @@ declare class SazitoClient {
2103
2167
  * Clear all guest credentials
2104
2168
  */
2105
2169
  clearCredentials(): void;
2170
+ /**
2171
+ * Access the guest credential store used by checkout-related modules.
2172
+ * Useful for integrations that receive an SDK client from the host app and
2173
+ * need to restore cart/invoice/payment credentials on that same instance.
2174
+ */
2175
+ getCredentialsManager(): CredentialsManager;
2106
2176
  /**
2107
2177
  * Clear everything (auth + cache + credentials)
2108
2178
  */
@@ -2115,7 +2185,7 @@ declare class SazitoClient {
2115
2185
  /**
2116
2186
  * Create a new Sazito SDK client instance
2117
2187
  */
2118
- declare function createSazitoClient(config: SazitoConfig): SazitoClient;
2188
+ declare function createSazitoClient(config: SazitoConfig, credentialsManager?: CredentialsManager): SazitoClient;
2119
2189
 
2120
2190
  interface ModuleContext {
2121
2191
  http: HttpClient;
@@ -2172,6 +2242,8 @@ interface ApiResponseEnvelope {
2172
2242
  result?: TransformObject;
2173
2243
  };
2174
2244
  }
2245
+ /** Convert Persian and Arabic-Indic numerals to ASCII digits. */
2246
+ declare function toEnglishDigits(input: string): string;
2175
2247
  /**
2176
2248
  * Transform object keys from snake_case to camelCase with field name beautification
2177
2249
  * @param obj - Object to transform
@@ -2213,5 +2285,5 @@ declare function transformAddToCartInput(variantId: number, quantity: number, fo
2213
2285
  */
2214
2286
  declare function transformCreateCartInput(input: TransformValue): TransformObject;
2215
2287
 
2216
- export { CredentialsManager, HttpClient, SazitoClient, TokenStorage, createBookingAPI as booking, createCartAPI as cart, createCategoriesAPI as categories, createCMSAPI as cms, createBookingAPI, createCMSAPI, createCartAPI, createCategoriesAPI, createDynamicFormsAPI, createEntityRoutesAPI, createFeedbacksAPI, createGeneralAPI, createImagesAPI, createInvoicesAPI, createMenuAPI, createOrdersAPI, createPaymentsAPI, createProductsAPI, createRegionsAPI, createSazitoClient, createSearchAPI, createShippingAPI, createUsersAPI, createVisitsAPI, createWalletAPI, createDynamicFormsAPI as dynamicForms, createEntityRoutesAPI as entityRoutes, createFeedbacksAPI as feedbacks, createGeneralAPI as general, createImagesAPI as images, createInvoicesAPI as invoices, createMenuAPI as menu, createOrdersAPI as orders, createPaymentsAPI as payments, createProductsAPI as products, createRegionsAPI as regions, createSearchAPI as search, createShippingAPI as shipping, transformAddToCartInput, transformApiResponse, transformCartResponse, transformCreateCartInput, transformInvoiceResponse, transformProductListResponse, transformRequestKeys, transformResponseKeys, transformShippingAddressInput, createUsersAPI as users, createVisitsAPI as visits, createWalletAPI as wallet };
2217
- export type { AddToCartInput, ApplicableShippingMethods, BlogPage, BlogPageEntityRoute, CMSPageEntityRoute, CMSPageType, CacheConfig, Cart, CartCredentials, CartProduct, CheckoutProductSnapshot, City$1 as City, CmsPage, CookieOptions, CreateCartInput, CreateInvoiceInput, CreatePaymentInput, EntityRoute, EntityRouteResponse, EntityType, FormAttributeValue, Image, Invoice, InvoiceCredentials, InvoiceItem, InvoiceItemFormAttributes, InvoiceShippingAddress, InvoiceShippingAddressRegion, ItemShippingRate, JsonArray, JsonObject, JsonPrimitive, JsonValue, MenuItem, MenuNode, MenuTree, Order, OrderFilters, OrdersListResponse, PaginatedResponse, Payment, PaymentAction, PaymentCredentials, PaymentGateway, PaymentMethod, PaymentStatus, PaymentStepFormFields, PaymentStepFormValue, PaymentStepInput, Product, ProductAttribute, ProductCategory, ProductCategoryEntityRoute, ProductEntityRoute, ProductFilters, ProductSort, ProductVariant, RefreshInvoiceInput, Region$1 as Region, RequestOptions, RetryConfig, SazitoConfig, SazitoResponse, SchedulerBookingAttributes, SearchFilters, SearchResponse, ShippingAddress, ShippingAddressCity, ShippingAddressCredentials, ShippingAddressInput, ShippingAddressRegion, ShippingAssignment, ShippingItem, ShippingMethod, ShippingRate, Tag, UnknownEntityRoute, UploadedFormFileAttribute, User };
2288
+ export { CredentialsManager, HttpClient, MemoryStorage, SazitoClient, TokenStorage, createBookingAPI as booking, createCartAPI as cart, createCategoriesAPI as categories, createCMSAPI as cms, createBookingAPI, createCMSAPI, createCartAPI, createCategoriesAPI, createDynamicFormsAPI, createEntityRoutesAPI, createFeedbacksAPI, createGeneralAPI, createImagesAPI, createInvoicesAPI, createMenuAPI, createOrdersAPI, createPaymentsAPI, createProductsAPI, createRegionsAPI, createSazitoClient, createSearchAPI, createShippingAPI, createUsersAPI, createVisitsAPI, createWalletAPI, createDynamicFormsAPI as dynamicForms, createEntityRoutesAPI as entityRoutes, createFeedbacksAPI as feedbacks, createGeneralAPI as general, createImagesAPI as images, createInvoicesAPI as invoices, createMenuAPI as menu, createOrdersAPI as orders, createPaymentsAPI as payments, createProductsAPI as products, createRegionsAPI as regions, createSearchAPI as search, createShippingAPI as shipping, toEnglishDigits, transformAddToCartInput, transformApiResponse, transformCartResponse, transformCreateCartInput, transformInvoiceResponse, transformProductListResponse, transformRequestKeys, transformResponseKeys, transformShippingAddressInput, createUsersAPI as users, createVisitsAPI as visits, createWalletAPI as wallet };
2289
+ export type { AddToCartInput, ApplicableShippingMethods, BlogPage, BlogPageEntityRoute, CMSPageEntityRoute, CMSPageType, CacheConfig, Cart, CartCredentials, CartProduct, CheckoutProductSnapshot, City$1 as City, CmsPage, CookieOptions, CreateCartInput, CreateInvoiceInput, CreatePaymentInput, EntityRoute, EntityRouteResponse, EntityType, FormAttributeValue, Image, Invoice, InvoiceCredentials, InvoiceItem, InvoiceItemFormAttributes, InvoiceShippingAddress, InvoiceShippingAddressRegion, ItemShippingRate, JsonArray, JsonObject, JsonPrimitive, JsonValue, MenuItem, MenuNode, MenuTree, Order, OrderFilters, OrdersListResponse, PaginatedResponse, Payment, PaymentAction, PaymentCredentials, PaymentGateway, PaymentMethod, PaymentStatus, PaymentStepFormFields, PaymentStepFormValue, PaymentStepInput, Product, ProductAttribute, ProductAttributeValueObject, ProductCategory, ProductCategoryEntityRoute, ProductEntityRoute, ProductFilters, ProductSort, ProductVariant, RefreshInvoiceInput, Region$1 as Region, RequestOptions, RetryConfig, SazitoConfig, SazitoResponse, SchedulerBookingAttributes, SearchFilters, SearchResponse, ShippingAddress, ShippingAddressCity, ShippingAddressCredentials, ShippingAddressInput, ShippingAddressRegion, ShippingAssignment, ShippingItem, ShippingMethod, ShippingRate, StorageAdapter, Tag, UnknownEntityRoute, UploadedFormFileAttribute, User };