@expresscsv/sdk 0.1.22 → 0.1.24

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.mts CHANGED
@@ -1256,6 +1256,8 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1256
1256
  private importerMode;
1257
1257
  private canRestart;
1258
1258
  private lastError;
1259
+ private stateChangeListeners;
1260
+ private lastTerminalSessionState;
1259
1261
  private openOptions;
1260
1262
  private cachedSchemaJson;
1261
1263
  private initCompletePromise;
@@ -1263,11 +1265,17 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1263
1265
  private resolvedTemplateDownload;
1264
1266
  private importerStartupGeneration;
1265
1267
  constructor(options: SDKOptions<TSchema>);
1268
+ private getCustomStorageRpcHandler;
1266
1269
  /**
1267
1270
  * Enhanced state management
1268
1271
  */
1269
1272
  private setState;
1270
1273
  private updateDerivedState;
1274
+ private createSessionId;
1275
+ private getOrCreateSessionId;
1276
+ private getImportSessionContext;
1277
+ private getChunkIdempotencyKey;
1278
+ private createRecordsChunk;
1271
1279
  private handleError;
1272
1280
  private sendImportProgress;
1273
1281
  private waitForEvent;
@@ -1297,16 +1305,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1297
1305
  */
1298
1306
  private createImportSession;
1299
1307
  /**
1300
- * Deliver results to webhook endpoint via backend API
1301
- * Chunks data using SDK-determined chunk size (independent of customer's chunkSize)
1302
- */
1303
- private deliverToWebhook;
1304
- /**
1305
- * Send a single chunk to backend webhook API with retry logic
1306
- */
1307
- private sendChunkToBackend;
1308
- /**
1309
- * Process results in chunks, calling onData and/or webhook for each chunk with backpressure control
1308
+ * Process results in chunks, calling onData with backpressure control
1310
1309
  */
1311
1310
  private processResultsInChunks;
1312
1311
  /**
@@ -1342,6 +1341,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1342
1341
  private handleImporterClosed;
1343
1342
  private hideContainer;
1344
1343
  getConnectionStatus(): boolean;
1344
+ subscribeToStateChanges(listener: StateChangeListener): () => void;
1345
1345
  getState(): ImporterState;
1346
1346
  getMode(): ImporterMode;
1347
1347
  getIsReady(): boolean;
@@ -1358,7 +1358,6 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1358
1358
  lastError: Error | null;
1359
1359
  connectionStatus: boolean;
1360
1360
  };
1361
- getVersion(): string;
1362
1361
  }
1363
1362
 
1364
1363
  /**
@@ -2004,6 +2003,13 @@ declare const CurrencyCodes: readonly [{
2004
2003
  readonly numeric: "932";
2005
2004
  }];
2006
2005
 
2006
+ export declare type CustomStorageOptions = {
2007
+ type: 'custom';
2008
+ get: (key: StorageKey) => Promise<StoredSession | null>;
2009
+ set: (key: StorageKey, value: StoredSession) => Promise<void>;
2010
+ remove: (key: StorageKey) => Promise<void>;
2011
+ };
2012
+
2007
2013
  declare interface DatetimeOptions {
2008
2014
  message?: string;
2009
2015
  }
@@ -2012,19 +2018,9 @@ export declare type DeepPartial<T> = {
2012
2018
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
2013
2019
  };
2014
2020
 
2015
- /**
2016
- * Delivery options - requires at least one of onData or webhook
2017
- */
2018
- export declare type DeliveryOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'>;
2019
-
2020
- /**
2021
- * Base delivery options - at least one must be provided
2022
- */
2023
- declare interface DeliveryOptionsBase<T> {
2024
- /** Local callback for processing chunks */
2025
- onData?: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2026
- /** Webhook configuration for remote delivery */
2027
- webhook?: WebhookConfig;
2021
+ export declare interface DeliveryOptions<T> {
2022
+ /** Callback for processing delivered chunks */
2023
+ onData: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2028
2024
  }
2029
2025
 
2030
2026
  /**
@@ -3624,12 +3620,21 @@ export declare enum ImporterState {
3624
3620
  DESTROYED = "destroyed"
3625
3621
  }
3626
3622
 
3623
+ export declare interface ImportSessionContext {
3624
+ /** Generated session ID for the current import run */
3625
+ sessionId: string;
3626
+ }
3627
+
3627
3628
  export declare type Infer<T extends ExType<unknown, ExBaseDef, unknown>> = T extends ExType<infer Output, ExBaseDef, unknown> ? Output : never;
3628
3629
 
3629
3630
  export declare type InferCSVImporter<TSchema extends ExType<unknown, ExBaseDef, unknown>> = CSVImporter<TSchema>;
3630
3631
 
3631
3632
  declare type IPAddressVersion = 'v4' | 'v6' | 'all';
3632
3633
 
3634
+ export declare type LocalStorageOptions = {
3635
+ type: 'local';
3636
+ };
3637
+
3633
3638
  declare interface MultiselectOptions {
3634
3639
  enforceCaseSensitiveMatch?: boolean;
3635
3640
  message?: string;
@@ -3637,17 +3642,17 @@ declare interface MultiselectOptions {
3637
3642
 
3638
3643
  /**
3639
3644
  * Options for the open() method
3640
- * Requires at least one of onData or webhook for delivery
3645
+ * Requires an onData callback for delivery
3641
3646
  */
3642
- export declare type OpenOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'> & {
3647
+ export declare type OpenOptions<T> = DeliveryOptions<T> & {
3643
3648
  /** Number of records per chunk (default: 1000) */
3644
3649
  chunkSize?: number;
3645
3650
  /** Called when all chunks have been processed */
3646
- onComplete?: () => void;
3651
+ onComplete?: (context: ImportSessionContext) => void;
3647
3652
  /** Called when the user cancels the import */
3648
- onCancel?: () => void;
3653
+ onCancel?: (context: ImportSessionContext) => void;
3649
3654
  /** Called when an error occurs */
3650
- onError?: (error: Error) => void;
3655
+ onError?: (error: Error, context: ImportSessionContext) => void;
3651
3656
  /** Called when the importer opens */
3652
3657
  onImporterOpen?: () => void;
3653
3658
  /** Called when the importer closes */
@@ -3656,6 +3661,17 @@ export declare type OpenOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, '
3656
3661
  onStepChange?: (stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => void;
3657
3662
  };
3658
3663
 
3664
+ declare interface PersistedImportSessionData {
3665
+ data: PersistedImportSessionPayload;
3666
+ }
3667
+
3668
+ declare type PersistedImportSessionKey = string;
3669
+
3670
+ declare type PersistedImportSessionPayload = {
3671
+ rowData: Record<string, unknown>[];
3672
+ columnKeys: string[];
3673
+ };
3674
+
3659
3675
  declare type PhoneNumberFormat = 'international' | 'national' | 'both';
3660
3676
 
3661
3677
  declare type PhoneNumberOutput = 'e164' | 'formatted' | 'digits';
@@ -3762,6 +3778,10 @@ export declare interface RecordsChunk<T> {
3762
3778
  currentChunkIndex: number;
3763
3779
  /** Total number of records across all chunks */
3764
3780
  totalRecords: number;
3781
+ /** Generated session ID for the current import run */
3782
+ sessionId: string;
3783
+ /** Stable per-chunk idempotency key */
3784
+ chunkIdempotencyKey: string;
3765
3785
  }
3766
3786
 
3767
3787
  declare type RefineBatchResultItem = {
@@ -3793,13 +3813,6 @@ declare type RefineResultItem = {
3793
3813
  };
3794
3814
  };
3795
3815
 
3796
- /**
3797
- * Type helper that requires at least one of the specified keys to be present
3798
- */
3799
- declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
3800
- [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
3801
- }[Keys];
3802
-
3803
3816
  export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, unknown>> {
3804
3817
  schema: TSchema;
3805
3818
  getSessionToken: () => Promise<string>;
@@ -3813,8 +3826,10 @@ export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, u
3813
3826
  fonts?: Record<string, ECSVFontSource>;
3814
3827
  stepDisplay?: 'progressBar' | 'segmented' | 'numbered';
3815
3828
  previewSchemaBeforeUpload?: boolean;
3829
+ aiColumnMatching?: boolean;
3830
+ aiTransform?: boolean;
3816
3831
  templateDownload?: TemplateDownloadOptions<TSchema>;
3817
- saveSession?: boolean;
3832
+ storage?: StorageOptions;
3818
3833
  locale?: DeepPartial<ExpressCSVLocaleInput>;
3819
3834
  disableStatusStep?: boolean;
3820
3835
  }
@@ -3831,6 +3846,16 @@ declare interface SelectOptions {
3831
3846
  message?: string;
3832
3847
  }
3833
3848
 
3849
+ declare type StateChangeListener = (state: ImporterState) => void;
3850
+
3851
+ export declare type StorageKey = PersistedImportSessionKey;
3852
+
3853
+ export declare type StorageOptions = LocalStorageOptions | CustomStorageOptions;
3854
+
3855
+ export declare type StoredSession = PersistedImportSessionData;
3856
+
3857
+ export declare type StoredSessionData = PersistedImportSessionPayload;
3858
+
3834
3859
  declare type StripBrand<T> = {
3835
3860
  [K in keyof T]: T[K] extends TemplateString<string> ? string : T[K] extends object ? StripBrand<T[K]> : T[K];
3836
3861
  };
@@ -3927,31 +3952,6 @@ declare interface ValidatorCheck {
3927
3952
  message?: string;
3928
3953
  }
3929
3954
 
3930
- /**
3931
- * Webhook configuration for remote delivery of results
3932
- */
3933
- export declare interface WebhookConfig {
3934
- /** The URL to send webhook requests to */
3935
- url: string;
3936
- /** Optional HTTP headers to include in the request */
3937
- headers?: Record<string, string>;
3938
- /** HTTP method to use (default: 'POST') */
3939
- method?: 'POST' | 'PUT' | 'PATCH';
3940
- /** Request timeout in milliseconds (default: 30000) */
3941
- timeout?: number;
3942
- /** Number of retry attempts on failure (default: 0) */
3943
- retries?: number;
3944
- /** Arbitrary developer-provided metadata */
3945
- metadata?: Record<string, unknown>;
3946
- /**
3947
- * Whether to wait for the delivery service to confirm the webhook was
3948
- * successfully received before considering the import complete.
3949
- * When false, the import completes as soon as all chunks are queued.
3950
- * Default: false
3951
- */
3952
- awaitWebhookArrival?: boolean;
3953
- }
3954
-
3955
3955
  export declare const x: {
3956
3956
  string: typeof ExString.create;
3957
3957
  number: typeof ExNumber.create;
package/dist/index.d.ts CHANGED
@@ -1256,6 +1256,8 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1256
1256
  private importerMode;
1257
1257
  private canRestart;
1258
1258
  private lastError;
1259
+ private stateChangeListeners;
1260
+ private lastTerminalSessionState;
1259
1261
  private openOptions;
1260
1262
  private cachedSchemaJson;
1261
1263
  private initCompletePromise;
@@ -1263,11 +1265,17 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1263
1265
  private resolvedTemplateDownload;
1264
1266
  private importerStartupGeneration;
1265
1267
  constructor(options: SDKOptions<TSchema>);
1268
+ private getCustomStorageRpcHandler;
1266
1269
  /**
1267
1270
  * Enhanced state management
1268
1271
  */
1269
1272
  private setState;
1270
1273
  private updateDerivedState;
1274
+ private createSessionId;
1275
+ private getOrCreateSessionId;
1276
+ private getImportSessionContext;
1277
+ private getChunkIdempotencyKey;
1278
+ private createRecordsChunk;
1271
1279
  private handleError;
1272
1280
  private sendImportProgress;
1273
1281
  private waitForEvent;
@@ -1297,16 +1305,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1297
1305
  */
1298
1306
  private createImportSession;
1299
1307
  /**
1300
- * Deliver results to webhook endpoint via backend API
1301
- * Chunks data using SDK-determined chunk size (independent of customer's chunkSize)
1302
- */
1303
- private deliverToWebhook;
1304
- /**
1305
- * Send a single chunk to backend webhook API with retry logic
1306
- */
1307
- private sendChunkToBackend;
1308
- /**
1309
- * Process results in chunks, calling onData and/or webhook for each chunk with backpressure control
1308
+ * Process results in chunks, calling onData with backpressure control
1310
1309
  */
1311
1310
  private processResultsInChunks;
1312
1311
  /**
@@ -1342,6 +1341,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1342
1341
  private handleImporterClosed;
1343
1342
  private hideContainer;
1344
1343
  getConnectionStatus(): boolean;
1344
+ subscribeToStateChanges(listener: StateChangeListener): () => void;
1345
1345
  getState(): ImporterState;
1346
1346
  getMode(): ImporterMode;
1347
1347
  getIsReady(): boolean;
@@ -1358,7 +1358,6 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1358
1358
  lastError: Error | null;
1359
1359
  connectionStatus: boolean;
1360
1360
  };
1361
- getVersion(): string;
1362
1361
  }
1363
1362
 
1364
1363
  /**
@@ -2004,6 +2003,13 @@ declare const CurrencyCodes: readonly [{
2004
2003
  readonly numeric: "932";
2005
2004
  }];
2006
2005
 
2006
+ export declare type CustomStorageOptions = {
2007
+ type: 'custom';
2008
+ get: (key: StorageKey) => Promise<StoredSession | null>;
2009
+ set: (key: StorageKey, value: StoredSession) => Promise<void>;
2010
+ remove: (key: StorageKey) => Promise<void>;
2011
+ };
2012
+
2007
2013
  declare interface DatetimeOptions {
2008
2014
  message?: string;
2009
2015
  }
@@ -2012,19 +2018,9 @@ export declare type DeepPartial<T> = {
2012
2018
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
2013
2019
  };
2014
2020
 
2015
- /**
2016
- * Delivery options - requires at least one of onData or webhook
2017
- */
2018
- export declare type DeliveryOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'>;
2019
-
2020
- /**
2021
- * Base delivery options - at least one must be provided
2022
- */
2023
- declare interface DeliveryOptionsBase<T> {
2024
- /** Local callback for processing chunks */
2025
- onData?: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2026
- /** Webhook configuration for remote delivery */
2027
- webhook?: WebhookConfig;
2021
+ export declare interface DeliveryOptions<T> {
2022
+ /** Callback for processing delivered chunks */
2023
+ onData: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2028
2024
  }
2029
2025
 
2030
2026
  /**
@@ -3624,12 +3620,21 @@ export declare enum ImporterState {
3624
3620
  DESTROYED = "destroyed"
3625
3621
  }
3626
3622
 
3623
+ export declare interface ImportSessionContext {
3624
+ /** Generated session ID for the current import run */
3625
+ sessionId: string;
3626
+ }
3627
+
3627
3628
  export declare type Infer<T extends ExType<unknown, ExBaseDef, unknown>> = T extends ExType<infer Output, ExBaseDef, unknown> ? Output : never;
3628
3629
 
3629
3630
  export declare type InferCSVImporter<TSchema extends ExType<unknown, ExBaseDef, unknown>> = CSVImporter<TSchema>;
3630
3631
 
3631
3632
  declare type IPAddressVersion = 'v4' | 'v6' | 'all';
3632
3633
 
3634
+ export declare type LocalStorageOptions = {
3635
+ type: 'local';
3636
+ };
3637
+
3633
3638
  declare interface MultiselectOptions {
3634
3639
  enforceCaseSensitiveMatch?: boolean;
3635
3640
  message?: string;
@@ -3637,17 +3642,17 @@ declare interface MultiselectOptions {
3637
3642
 
3638
3643
  /**
3639
3644
  * Options for the open() method
3640
- * Requires at least one of onData or webhook for delivery
3645
+ * Requires an onData callback for delivery
3641
3646
  */
3642
- export declare type OpenOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'> & {
3647
+ export declare type OpenOptions<T> = DeliveryOptions<T> & {
3643
3648
  /** Number of records per chunk (default: 1000) */
3644
3649
  chunkSize?: number;
3645
3650
  /** Called when all chunks have been processed */
3646
- onComplete?: () => void;
3651
+ onComplete?: (context: ImportSessionContext) => void;
3647
3652
  /** Called when the user cancels the import */
3648
- onCancel?: () => void;
3653
+ onCancel?: (context: ImportSessionContext) => void;
3649
3654
  /** Called when an error occurs */
3650
- onError?: (error: Error) => void;
3655
+ onError?: (error: Error, context: ImportSessionContext) => void;
3651
3656
  /** Called when the importer opens */
3652
3657
  onImporterOpen?: () => void;
3653
3658
  /** Called when the importer closes */
@@ -3656,6 +3661,17 @@ export declare type OpenOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, '
3656
3661
  onStepChange?: (stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => void;
3657
3662
  };
3658
3663
 
3664
+ declare interface PersistedImportSessionData {
3665
+ data: PersistedImportSessionPayload;
3666
+ }
3667
+
3668
+ declare type PersistedImportSessionKey = string;
3669
+
3670
+ declare type PersistedImportSessionPayload = {
3671
+ rowData: Record<string, unknown>[];
3672
+ columnKeys: string[];
3673
+ };
3674
+
3659
3675
  declare type PhoneNumberFormat = 'international' | 'national' | 'both';
3660
3676
 
3661
3677
  declare type PhoneNumberOutput = 'e164' | 'formatted' | 'digits';
@@ -3762,6 +3778,10 @@ export declare interface RecordsChunk<T> {
3762
3778
  currentChunkIndex: number;
3763
3779
  /** Total number of records across all chunks */
3764
3780
  totalRecords: number;
3781
+ /** Generated session ID for the current import run */
3782
+ sessionId: string;
3783
+ /** Stable per-chunk idempotency key */
3784
+ chunkIdempotencyKey: string;
3765
3785
  }
3766
3786
 
3767
3787
  declare type RefineBatchResultItem = {
@@ -3793,13 +3813,6 @@ declare type RefineResultItem = {
3793
3813
  };
3794
3814
  };
3795
3815
 
3796
- /**
3797
- * Type helper that requires at least one of the specified keys to be present
3798
- */
3799
- declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
3800
- [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
3801
- }[Keys];
3802
-
3803
3816
  export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, unknown>> {
3804
3817
  schema: TSchema;
3805
3818
  getSessionToken: () => Promise<string>;
@@ -3813,8 +3826,10 @@ export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, u
3813
3826
  fonts?: Record<string, ECSVFontSource>;
3814
3827
  stepDisplay?: 'progressBar' | 'segmented' | 'numbered';
3815
3828
  previewSchemaBeforeUpload?: boolean;
3829
+ aiColumnMatching?: boolean;
3830
+ aiTransform?: boolean;
3816
3831
  templateDownload?: TemplateDownloadOptions<TSchema>;
3817
- saveSession?: boolean;
3832
+ storage?: StorageOptions;
3818
3833
  locale?: DeepPartial<ExpressCSVLocaleInput>;
3819
3834
  disableStatusStep?: boolean;
3820
3835
  }
@@ -3831,6 +3846,16 @@ declare interface SelectOptions {
3831
3846
  message?: string;
3832
3847
  }
3833
3848
 
3849
+ declare type StateChangeListener = (state: ImporterState) => void;
3850
+
3851
+ export declare type StorageKey = PersistedImportSessionKey;
3852
+
3853
+ export declare type StorageOptions = LocalStorageOptions | CustomStorageOptions;
3854
+
3855
+ export declare type StoredSession = PersistedImportSessionData;
3856
+
3857
+ export declare type StoredSessionData = PersistedImportSessionPayload;
3858
+
3834
3859
  declare type StripBrand<T> = {
3835
3860
  [K in keyof T]: T[K] extends TemplateString<string> ? string : T[K] extends object ? StripBrand<T[K]> : T[K];
3836
3861
  };
@@ -3927,31 +3952,6 @@ declare interface ValidatorCheck {
3927
3952
  message?: string;
3928
3953
  }
3929
3954
 
3930
- /**
3931
- * Webhook configuration for remote delivery of results
3932
- */
3933
- export declare interface WebhookConfig {
3934
- /** The URL to send webhook requests to */
3935
- url: string;
3936
- /** Optional HTTP headers to include in the request */
3937
- headers?: Record<string, string>;
3938
- /** HTTP method to use (default: 'POST') */
3939
- method?: 'POST' | 'PUT' | 'PATCH';
3940
- /** Request timeout in milliseconds (default: 30000) */
3941
- timeout?: number;
3942
- /** Number of retry attempts on failure (default: 0) */
3943
- retries?: number;
3944
- /** Arbitrary developer-provided metadata */
3945
- metadata?: Record<string, unknown>;
3946
- /**
3947
- * Whether to wait for the delivery service to confirm the webhook was
3948
- * successfully received before considering the import complete.
3949
- * When false, the import completes as soon as all chunks are queued.
3950
- * Default: false
3951
- */
3952
- awaitWebhookArrival?: boolean;
3953
- }
3954
-
3955
3955
  export declare const x: {
3956
3956
  string: typeof ExString.create;
3957
3957
  number: typeof ExNumber.create;