@alter-ai/alter-sdk 0.3.1 → 0.4.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/index.d.cts CHANGED
@@ -48,6 +48,8 @@ declare class TokenResponse {
48
48
  readonly injectionHeader: string;
49
49
  /** Header value format with {token} placeholder (e.g., "Bearer {token}", "{token}") */
50
50
  readonly injectionFormat: string;
51
+ /** Extra credentials for multi-part auth (e.g. AWS SigV4 secret_key, region) */
52
+ readonly additionalCredentials: Record<string, string> | null;
51
53
  constructor(data: {
52
54
  access_token: string;
53
55
  token_type?: string;
@@ -58,6 +60,7 @@ declare class TokenResponse {
58
60
  provider_id?: string;
59
61
  injection_header?: string;
60
62
  injection_format?: string;
63
+ additional_credentials?: Record<string, string> | null;
61
64
  });
62
65
  /**
63
66
  * Parse expires_at from ISO string.
@@ -157,6 +160,27 @@ declare class ConnectionListResult {
157
160
  has_more: boolean;
158
161
  });
159
162
  }
163
+ /**
164
+ * Result of a headless connect() flow.
165
+ *
166
+ * Returned by connect() after the user completes OAuth in the browser.
167
+ * Contains the connection metadata (no tokens — use request() with
168
+ * the connectionId to make authenticated API calls).
169
+ */
170
+ declare class ConnectResult {
171
+ readonly connectionId: string;
172
+ readonly providerId: string;
173
+ readonly accountIdentifier: string | null;
174
+ readonly scopes: string[];
175
+ constructor(data: {
176
+ connection_id: string;
177
+ provider_id: string;
178
+ account_identifier?: string | null;
179
+ scopes?: string[];
180
+ });
181
+ toJSON(): Record<string, unknown>;
182
+ toString(): string;
183
+ }
160
184
  /**
161
185
  * Audit log entry for an API call to a provider.
162
186
  *
@@ -325,6 +349,25 @@ interface ListConnectionsOptions {
325
349
  /** Offset for pagination (default 0) */
326
350
  offset?: number;
327
351
  }
352
+ /**
353
+ * Options for the connect() method.
354
+ */
355
+ interface ConnectOptions {
356
+ /** End user to create session for (requires at least id) */
357
+ endUser: {
358
+ id: string;
359
+ email?: string;
360
+ name?: string;
361
+ };
362
+ /** Restrict to specific providers (e.g., ["google"]) */
363
+ providers?: string[];
364
+ /** Max seconds to wait for completion (default 300 = 5 min) */
365
+ timeout?: number;
366
+ /** Seconds between poll requests (default 2) */
367
+ pollInterval?: number;
368
+ /** If true, opens browser automatically. If false, prints URL. (default true) */
369
+ openBrowser?: boolean;
370
+ }
328
371
  /**
329
372
  * Options for the createConnectSession() method.
330
373
  */
@@ -402,6 +445,20 @@ declare class AlterVault {
402
445
  * Returns a URL the user can open in their browser to authorize access.
403
446
  */
404
447
  createConnectSession(options: CreateConnectSessionOptions): Promise<ConnectSession>;
448
+ /**
449
+ * Open OAuth in the user's browser and wait for completion.
450
+ *
451
+ * This is the headless connect flow for CLI tools, scripts, and
452
+ * server-side applications. It creates a Connect session, opens the
453
+ * browser, and polls until the user completes OAuth.
454
+ *
455
+ * @param options - Connect options (endUser is required)
456
+ * @returns Array of ConnectResult objects (one per connected provider)
457
+ * @throws ConnectTimeoutError if the user doesn't complete within timeout
458
+ * @throws ConnectFlowError if the user denies or provider returns error
459
+ * @throws AlterSDKError if SDK is closed or session creation fails
460
+ */
461
+ connect(options: ConnectOptions): Promise<ConnectResult[]>;
405
462
  /**
406
463
  * Close HTTP clients and release resources.
407
464
  * Waits for any pending audit tasks before closing.
@@ -461,6 +518,25 @@ declare class TokenExpiredError extends TokenRetrievalError {
461
518
  readonly connectionId: string | undefined;
462
519
  constructor(message: string, connectionId?: string, details?: Record<string, unknown>);
463
520
  }
521
+ /**
522
+ * Raised when the headless connect() flow fails.
523
+ *
524
+ * This can happen when:
525
+ * - The user denies authorization
526
+ * - The provider returns an error
527
+ * - The session expires before completion
528
+ */
529
+ declare class ConnectFlowError extends AlterSDKError {
530
+ constructor(message: string, details?: Record<string, unknown>);
531
+ }
532
+ /**
533
+ * Raised when the connect() flow times out.
534
+ *
535
+ * The user did not complete OAuth within the specified timeout period.
536
+ */
537
+ declare class ConnectTimeoutError extends ConnectFlowError {
538
+ constructor(message: string, details?: Record<string, unknown>);
539
+ }
464
540
  /**
465
541
  * Raised when provider API call fails.
466
542
  *
@@ -493,4 +569,4 @@ declare class TimeoutError extends NetworkError {
493
569
  constructor(message: string, details?: Record<string, unknown>);
494
570
  }
495
571
 
496
- export { APICallAuditLog, ActorType, AlterSDKError, AlterVault, type AlterVaultOptions, ConnectSession, ConnectionInfo, ConnectionListResult, ConnectionNotFoundError, type CreateConnectSessionOptions, HttpMethod, type ListConnectionsOptions, NetworkError, PolicyViolationError, Provider, ProviderAPIError, type RequestOptions, TimeoutError, TokenExpiredError, TokenResponse, TokenRetrievalError };
572
+ export { APICallAuditLog, ActorType, AlterSDKError, AlterVault, type AlterVaultOptions, ConnectFlowError, type ConnectOptions, ConnectResult, ConnectSession, ConnectTimeoutError, ConnectionInfo, ConnectionListResult, ConnectionNotFoundError, type CreateConnectSessionOptions, HttpMethod, type ListConnectionsOptions, NetworkError, PolicyViolationError, Provider, ProviderAPIError, type RequestOptions, TimeoutError, TokenExpiredError, TokenResponse, TokenRetrievalError };
package/dist/index.d.ts CHANGED
@@ -48,6 +48,8 @@ declare class TokenResponse {
48
48
  readonly injectionHeader: string;
49
49
  /** Header value format with {token} placeholder (e.g., "Bearer {token}", "{token}") */
50
50
  readonly injectionFormat: string;
51
+ /** Extra credentials for multi-part auth (e.g. AWS SigV4 secret_key, region) */
52
+ readonly additionalCredentials: Record<string, string> | null;
51
53
  constructor(data: {
52
54
  access_token: string;
53
55
  token_type?: string;
@@ -58,6 +60,7 @@ declare class TokenResponse {
58
60
  provider_id?: string;
59
61
  injection_header?: string;
60
62
  injection_format?: string;
63
+ additional_credentials?: Record<string, string> | null;
61
64
  });
62
65
  /**
63
66
  * Parse expires_at from ISO string.
@@ -157,6 +160,27 @@ declare class ConnectionListResult {
157
160
  has_more: boolean;
158
161
  });
159
162
  }
163
+ /**
164
+ * Result of a headless connect() flow.
165
+ *
166
+ * Returned by connect() after the user completes OAuth in the browser.
167
+ * Contains the connection metadata (no tokens — use request() with
168
+ * the connectionId to make authenticated API calls).
169
+ */
170
+ declare class ConnectResult {
171
+ readonly connectionId: string;
172
+ readonly providerId: string;
173
+ readonly accountIdentifier: string | null;
174
+ readonly scopes: string[];
175
+ constructor(data: {
176
+ connection_id: string;
177
+ provider_id: string;
178
+ account_identifier?: string | null;
179
+ scopes?: string[];
180
+ });
181
+ toJSON(): Record<string, unknown>;
182
+ toString(): string;
183
+ }
160
184
  /**
161
185
  * Audit log entry for an API call to a provider.
162
186
  *
@@ -325,6 +349,25 @@ interface ListConnectionsOptions {
325
349
  /** Offset for pagination (default 0) */
326
350
  offset?: number;
327
351
  }
352
+ /**
353
+ * Options for the connect() method.
354
+ */
355
+ interface ConnectOptions {
356
+ /** End user to create session for (requires at least id) */
357
+ endUser: {
358
+ id: string;
359
+ email?: string;
360
+ name?: string;
361
+ };
362
+ /** Restrict to specific providers (e.g., ["google"]) */
363
+ providers?: string[];
364
+ /** Max seconds to wait for completion (default 300 = 5 min) */
365
+ timeout?: number;
366
+ /** Seconds between poll requests (default 2) */
367
+ pollInterval?: number;
368
+ /** If true, opens browser automatically. If false, prints URL. (default true) */
369
+ openBrowser?: boolean;
370
+ }
328
371
  /**
329
372
  * Options for the createConnectSession() method.
330
373
  */
@@ -402,6 +445,20 @@ declare class AlterVault {
402
445
  * Returns a URL the user can open in their browser to authorize access.
403
446
  */
404
447
  createConnectSession(options: CreateConnectSessionOptions): Promise<ConnectSession>;
448
+ /**
449
+ * Open OAuth in the user's browser and wait for completion.
450
+ *
451
+ * This is the headless connect flow for CLI tools, scripts, and
452
+ * server-side applications. It creates a Connect session, opens the
453
+ * browser, and polls until the user completes OAuth.
454
+ *
455
+ * @param options - Connect options (endUser is required)
456
+ * @returns Array of ConnectResult objects (one per connected provider)
457
+ * @throws ConnectTimeoutError if the user doesn't complete within timeout
458
+ * @throws ConnectFlowError if the user denies or provider returns error
459
+ * @throws AlterSDKError if SDK is closed or session creation fails
460
+ */
461
+ connect(options: ConnectOptions): Promise<ConnectResult[]>;
405
462
  /**
406
463
  * Close HTTP clients and release resources.
407
464
  * Waits for any pending audit tasks before closing.
@@ -461,6 +518,25 @@ declare class TokenExpiredError extends TokenRetrievalError {
461
518
  readonly connectionId: string | undefined;
462
519
  constructor(message: string, connectionId?: string, details?: Record<string, unknown>);
463
520
  }
521
+ /**
522
+ * Raised when the headless connect() flow fails.
523
+ *
524
+ * This can happen when:
525
+ * - The user denies authorization
526
+ * - The provider returns an error
527
+ * - The session expires before completion
528
+ */
529
+ declare class ConnectFlowError extends AlterSDKError {
530
+ constructor(message: string, details?: Record<string, unknown>);
531
+ }
532
+ /**
533
+ * Raised when the connect() flow times out.
534
+ *
535
+ * The user did not complete OAuth within the specified timeout period.
536
+ */
537
+ declare class ConnectTimeoutError extends ConnectFlowError {
538
+ constructor(message: string, details?: Record<string, unknown>);
539
+ }
464
540
  /**
465
541
  * Raised when provider API call fails.
466
542
  *
@@ -493,4 +569,4 @@ declare class TimeoutError extends NetworkError {
493
569
  constructor(message: string, details?: Record<string, unknown>);
494
570
  }
495
571
 
496
- export { APICallAuditLog, ActorType, AlterSDKError, AlterVault, type AlterVaultOptions, ConnectSession, ConnectionInfo, ConnectionListResult, ConnectionNotFoundError, type CreateConnectSessionOptions, HttpMethod, type ListConnectionsOptions, NetworkError, PolicyViolationError, Provider, ProviderAPIError, type RequestOptions, TimeoutError, TokenExpiredError, TokenResponse, TokenRetrievalError };
572
+ export { APICallAuditLog, ActorType, AlterSDKError, AlterVault, type AlterVaultOptions, ConnectFlowError, type ConnectOptions, ConnectResult, ConnectSession, ConnectTimeoutError, ConnectionInfo, ConnectionListResult, ConnectionNotFoundError, type CreateConnectSessionOptions, HttpMethod, type ListConnectionsOptions, NetworkError, PolicyViolationError, Provider, ProviderAPIError, type RequestOptions, TimeoutError, TokenExpiredError, TokenResponse, TokenRetrievalError };