@expresscsv/sdk 0.1.21 → 0.1.23

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.cts CHANGED
@@ -1244,31 +1244,57 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1244
1244
  private debug;
1245
1245
  private importIdentifier;
1246
1246
  private sessionId;
1247
+ private currentSessionToken;
1248
+ private currentSessionTokenExpiresAt;
1249
+ private sessionTokenRefreshTimer;
1250
+ private sessionTokenRefreshPromise;
1247
1251
  private _destroyTimer;
1248
1252
  private _beforeUnloadHandler;
1249
- private widgetUrl;
1253
+ private importerUrl;
1250
1254
  private appUrl;
1251
- private widgetState;
1252
- private widgetMode;
1255
+ private importerState;
1256
+ private importerMode;
1253
1257
  private canRestart;
1254
1258
  private lastError;
1259
+ private stateChangeListeners;
1260
+ private lastTerminalSessionState;
1255
1261
  private openOptions;
1256
1262
  private cachedSchemaJson;
1257
1263
  private initCompletePromise;
1258
1264
  private resolveInitComplete;
1259
1265
  private resolvedTemplateDownload;
1266
+ private importerStartupGeneration;
1260
1267
  constructor(options: SDKOptions<TSchema>);
1268
+ private getCustomStorageRpcHandler;
1261
1269
  /**
1262
1270
  * Enhanced state management
1263
1271
  */
1264
1272
  private setState;
1265
1273
  private updateDerivedState;
1274
+ private createSessionId;
1275
+ private getOrCreateSessionId;
1276
+ private getImportSessionContext;
1277
+ private getChunkIdempotencyKey;
1278
+ private createRecordsChunk;
1266
1279
  private handleError;
1267
1280
  private sendImportProgress;
1268
1281
  private waitForEvent;
1282
+ private fetchImporterSessionToken;
1283
+ private updateSessionToken;
1284
+ private clearSessionTokenRefreshTimer;
1285
+ private scheduleSessionTokenRefresh;
1286
+ private ensureActiveSessionToken;
1287
+ private refreshSessionBoundToken;
1288
+ private beginImporterStartup;
1289
+ private cancelImporterStartup;
1290
+ private assertActiveImporterStartup;
1291
+ private withTimeout;
1292
+ private sendSessionDetailsToImporter;
1293
+ private sendStartupErrorToImporter;
1294
+ private bootstrapImporterSession;
1269
1295
  /**
1270
1296
  * Open the import flow with chunk-based data processing.
1271
- * Automatically opens the widget if not already open.
1297
+ * Automatically opens the importer if not already open.
1272
1298
  *
1273
1299
  * @param options Configuration including onData callback for processing chunks
1274
1300
  */
@@ -1279,21 +1305,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1279
1305
  */
1280
1306
  private createImportSession;
1281
1307
  /**
1282
- * Deliver results to webhook endpoint via backend API
1283
- * Chunks data using SDK-determined chunk size (independent of customer's chunkSize)
1284
- */
1285
- private deliverToWebhook;
1286
- /**
1287
- * Poll the delivery status endpoint until the delivery reaches a terminal state
1288
- * ('success' or 'failed'), or until the timeout is exceeded.
1289
- */
1290
- private pollDeliveryStatus;
1291
- /**
1292
- * Send a single chunk to backend webhook API with retry logic
1293
- */
1294
- private sendChunkToBackend;
1295
- /**
1296
- * 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
1297
1309
  */
1298
1310
  private processResultsInChunks;
1299
1311
  /**
@@ -1313,7 +1325,7 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1313
1325
  private removeBeforeUnloadListener;
1314
1326
  private waitForIframeLoad;
1315
1327
  private setupConnectionAndInit;
1316
- openWidget(options?: {
1328
+ openImporter(options?: {
1317
1329
  reset?: boolean;
1318
1330
  }): Promise<void>;
1319
1331
  /**
@@ -1324,20 +1336,21 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1324
1336
  private createAndAppendIframe;
1325
1337
  private destroy;
1326
1338
  close(reason?: 'user_close' | 'cancel' | 'complete' | 'error'): Promise<void>;
1327
- private resetWidget;
1339
+ private resetImporter;
1328
1340
  restart(newOptions?: Partial<SDKOptions<TSchema>>): Promise<void>;
1329
- private handleWidgetClosed;
1341
+ private handleImporterClosed;
1330
1342
  private hideContainer;
1331
1343
  getConnectionStatus(): boolean;
1332
- getState(): WidgetState;
1333
- getMode(): WidgetMode;
1344
+ subscribeToStateChanges(listener: StateChangeListener): () => void;
1345
+ getState(): ImporterState;
1346
+ getMode(): ImporterMode;
1334
1347
  getIsReady(): boolean;
1335
1348
  getIsOpen(): boolean;
1336
1349
  getCanRestart(): boolean;
1337
1350
  getLastError(): Error | null;
1338
1351
  getStatus(): {
1339
- state: WidgetState;
1340
- mode: WidgetMode;
1352
+ state: ImporterState;
1353
+ mode: ImporterMode;
1341
1354
  isReady: boolean;
1342
1355
  isOpen: boolean;
1343
1356
  canRestart: boolean;
@@ -1345,7 +1358,6 @@ export declare class CSVImporter<TSchema extends ExType<unknown, ExBaseDef, unkn
1345
1358
  lastError: Error | null;
1346
1359
  connectionStatus: boolean;
1347
1360
  };
1348
- getVersion(): string;
1349
1361
  }
1350
1362
 
1351
1363
  /**
@@ -1991,6 +2003,13 @@ declare const CurrencyCodes: readonly [{
1991
2003
  readonly numeric: "932";
1992
2004
  }];
1993
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
+
1994
2013
  declare interface DatetimeOptions {
1995
2014
  message?: string;
1996
2015
  }
@@ -1999,19 +2018,9 @@ export declare type DeepPartial<T> = {
1999
2018
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
2000
2019
  };
2001
2020
 
2002
- /**
2003
- * Delivery options - requires at least one of onData or webhook
2004
- */
2005
- export declare type DeliveryOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'>;
2006
-
2007
- /**
2008
- * Base delivery options - at least one must be provided
2009
- */
2010
- declare interface DeliveryOptionsBase<T> {
2011
- /** Local callback for processing chunks */
2012
- onData?: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2013
- /** Webhook configuration for remote delivery */
2014
- webhook?: WebhookConfig;
2021
+ export declare interface DeliveryOptions<T> {
2022
+ /** Callback for processing delivered chunks */
2023
+ onData: (chunk: RecordsChunk<T>, next: () => void) => void | Promise<void>;
2015
2024
  }
2016
2025
 
2017
2026
  /**
@@ -2867,7 +2876,7 @@ declare interface ExpressCSVLocale {
2867
2876
  nextDisabledReviewValidating: string;
2868
2877
  nextDisabledReviewInvalid: string;
2869
2878
  };
2870
- widget: {
2879
+ importer: {
2871
2880
  title: string;
2872
2881
  loading: string;
2873
2882
  closeConfirmTitle: string;
@@ -2876,7 +2885,6 @@ declare interface ExpressCSVLocale {
2876
2885
  closeConfirmContinue: string;
2877
2886
  errorTitle: string;
2878
2887
  startOver: string;
2879
- invalidPublishableKey: string;
2880
2888
  };
2881
2889
  sessionRecovery: {
2882
2890
  message: string;
@@ -3589,12 +3597,44 @@ export declare class ImportCancelledError extends Error {
3589
3597
  constructor(message?: string);
3590
3598
  }
3591
3599
 
3600
+ /**
3601
+ * Importer preload mode
3602
+ */
3603
+ export declare enum ImporterMode {
3604
+ NORMAL = "normal",
3605
+ PRELOAD = "preload"
3606
+ }
3607
+
3608
+ /**
3609
+ * Importer lifecycle state
3610
+ */
3611
+ export declare enum ImporterState {
3612
+ UNINITIALIZED = "uninitialized",
3613
+ INITIALIZING = "initializing",
3614
+ READY = "ready",
3615
+ OPENING = "opening",
3616
+ OPEN = "open",
3617
+ CLOSING = "closing",
3618
+ RESETTING = "resetting",
3619
+ ERROR = "error",
3620
+ DESTROYED = "destroyed"
3621
+ }
3622
+
3623
+ export declare interface ImportSessionContext {
3624
+ /** Generated session ID for the current import run */
3625
+ sessionId: string;
3626
+ }
3627
+
3592
3628
  export declare type Infer<T extends ExType<unknown, ExBaseDef, unknown>> = T extends ExType<infer Output, ExBaseDef, unknown> ? Output : never;
3593
3629
 
3594
3630
  export declare type InferCSVImporter<TSchema extends ExType<unknown, ExBaseDef, unknown>> = CSVImporter<TSchema>;
3595
3631
 
3596
3632
  declare type IPAddressVersion = 'v4' | 'v6' | 'all';
3597
3633
 
3634
+ export declare type LocalStorageOptions = {
3635
+ type: 'local';
3636
+ };
3637
+
3598
3638
  declare interface MultiselectOptions {
3599
3639
  enforceCaseSensitiveMatch?: boolean;
3600
3640
  message?: string;
@@ -3602,23 +3642,34 @@ declare interface MultiselectOptions {
3602
3642
 
3603
3643
  /**
3604
3644
  * Options for the open() method
3605
- * Requires at least one of onData or webhook for delivery
3645
+ * Requires an onData callback for delivery
3606
3646
  */
3607
- export declare type OpenOptions<T> = RequireAtLeastOne<DeliveryOptionsBase<T>, 'onData' | 'webhook'> & {
3647
+ export declare type OpenOptions<T> = DeliveryOptions<T> & {
3608
3648
  /** Number of records per chunk (default: 1000) */
3609
3649
  chunkSize?: number;
3610
3650
  /** Called when all chunks have been processed */
3611
- onComplete?: () => void;
3651
+ onComplete?: (context: ImportSessionContext) => void;
3612
3652
  /** Called when the user cancels the import */
3613
- onCancel?: () => void;
3653
+ onCancel?: (context: ImportSessionContext) => void;
3614
3654
  /** Called when an error occurs */
3615
- onError?: (error: Error) => void;
3616
- /** Called when the widget opens */
3617
- onWidgetOpen?: () => void;
3655
+ onError?: (error: Error, context: ImportSessionContext) => void;
3656
+ /** Called when the importer opens */
3657
+ onImporterOpen?: () => void;
3658
+ /** Called when the importer closes */
3659
+ onImporterClose?: (reason: 'user_close' | 'cancel' | 'complete' | 'error') => void;
3618
3660
  /** Called when the step changes in the wizard */
3619
3661
  onStepChange?: (stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => void;
3620
- /** Called when the widget closes */
3621
- onWidgetClose?: (reason: 'user_close' | 'cancel' | 'complete' | 'error') => void;
3662
+ };
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[];
3622
3673
  };
3623
3674
 
3624
3675
  declare type PhoneNumberFormat = 'international' | 'national' | 'both';
@@ -3727,6 +3778,10 @@ export declare interface RecordsChunk<T> {
3727
3778
  currentChunkIndex: number;
3728
3779
  /** Total number of records across all chunks */
3729
3780
  totalRecords: number;
3781
+ /** Generated session ID for the current import run */
3782
+ sessionId: string;
3783
+ /** Stable per-chunk idempotency key */
3784
+ chunkIdempotencyKey: string;
3730
3785
  }
3731
3786
 
3732
3787
  declare type RefineBatchResultItem = {
@@ -3758,16 +3813,9 @@ declare type RefineResultItem = {
3758
3813
  };
3759
3814
  };
3760
3815
 
3761
- /**
3762
- * Type helper that requires at least one of the specified keys to be present
3763
- */
3764
- declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
3765
- [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
3766
- }[Keys];
3767
-
3768
3816
  export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, unknown>> {
3769
3817
  schema: TSchema;
3770
- publishableKey: string;
3818
+ getSessionToken: () => Promise<string>;
3771
3819
  importIdentifier: string;
3772
3820
  title?: string;
3773
3821
  debug?: boolean;
@@ -3778,8 +3826,10 @@ export declare interface SDKOptions<TSchema extends ExType<unknown, ExBaseDef, u
3778
3826
  fonts?: Record<string, ECSVFontSource>;
3779
3827
  stepDisplay?: 'progressBar' | 'segmented' | 'numbered';
3780
3828
  previewSchemaBeforeUpload?: boolean;
3829
+ aiColumnMatching?: boolean;
3830
+ aiTransform?: boolean;
3781
3831
  templateDownload?: TemplateDownloadOptions<TSchema>;
3782
- saveSession?: boolean;
3832
+ storage?: StorageOptions;
3783
3833
  locale?: DeepPartial<ExpressCSVLocaleInput>;
3784
3834
  disableStatusStep?: boolean;
3785
3835
  }
@@ -3796,6 +3846,16 @@ declare interface SelectOptions {
3796
3846
  message?: string;
3797
3847
  }
3798
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
+
3799
3859
  declare type StripBrand<T> = {
3800
3860
  [K in keyof T]: T[K] extends TemplateString<string> ? string : T[K] extends object ? StripBrand<T[K]> : T[K];
3801
3861
  };
@@ -3860,7 +3920,7 @@ export declare type TemplateDownloadOptions<TSchema extends ExType<unknown, ExBa
3860
3920
 
3861
3921
  /**
3862
3922
  * A branded string type for locale entries that require interpolation via `{variable}` syntax.
3863
- * Widget code cannot render a `TemplateString` directly in JSX — it must go through the `t()` function.
3923
+ * Importer code cannot render a `TemplateString` directly in JSX — it must go through the `t()` function.
3864
3924
  * The generic `TVars` encodes the expected variable names so `t()` enforces the correct vars argument.
3865
3925
  */
3866
3926
  declare type TemplateString<TVars extends string = string> = string & {
@@ -3892,54 +3952,6 @@ declare interface ValidatorCheck {
3892
3952
  message?: string;
3893
3953
  }
3894
3954
 
3895
- /**
3896
- * Webhook configuration for remote delivery of results
3897
- */
3898
- export declare interface WebhookConfig {
3899
- /** The URL to send webhook requests to */
3900
- url: string;
3901
- /** Optional HTTP headers to include in the request */
3902
- headers?: Record<string, string>;
3903
- /** HTTP method to use (default: 'POST') */
3904
- method?: 'POST' | 'PUT' | 'PATCH';
3905
- /** Request timeout in milliseconds (default: 30000) */
3906
- timeout?: number;
3907
- /** Number of retry attempts on failure (default: 0) */
3908
- retries?: number;
3909
- /** Arbitrary developer-provided metadata */
3910
- metadata?: Record<string, unknown>;
3911
- /**
3912
- * Whether to wait for the delivery service to confirm the webhook was
3913
- * successfully received before considering the import complete.
3914
- * When false, the import completes as soon as all chunks are queued.
3915
- * Default: false
3916
- */
3917
- awaitWebhookArrival?: boolean;
3918
- }
3919
-
3920
- /**
3921
- * Widget mode enumeration
3922
- */
3923
- export declare enum WidgetMode {
3924
- NORMAL = "normal",
3925
- PRELOAD = "preload"
3926
- }
3927
-
3928
- /**
3929
- * Widget state enumeration for consistent state management
3930
- */
3931
- export declare enum WidgetState {
3932
- UNINITIALIZED = "uninitialized",
3933
- INITIALIZING = "initializing",
3934
- READY = "ready",
3935
- OPENING = "opening",
3936
- OPEN = "open",
3937
- CLOSING = "closing",
3938
- RESETTING = "resetting",
3939
- ERROR = "error",
3940
- DESTROYED = "destroyed"
3941
- }
3942
-
3943
3955
  export declare const x: {
3944
3956
  string: typeof ExString.create;
3945
3957
  number: typeof ExNumber.create;