@spooled/sdk 1.2.1 → 1.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
@@ -1,5 +1,5 @@
1
- import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-CWVI9LRo.cjs';
2
- export { A as API_VERSION, d as AddDependenciesParams, e as AddDependenciesResponse, f as AdminApiKeyResponse, g as AdminCreateApiKeyParams, h as AdminCreateOrganizationParams, i as AdminCreateOrganizationResponse, j as AdminDeleteOrganizationParams, k as AdminListOrganizationsParams, l as AdminOrganizationDetail, m as AdminOrganizationList, n as AdminOrganizationSummary, o as AdminPlanLimits, p as AdminPlatformStats, q as AdminResource, r as AdminUpdateOrganizationParams, s as AdminUsageStats, t as ApiKeySummary, u as ApiKeysResource, v as AuthResource, B as BatchJobStatus, w as BillingResource, x as BillingStatus, y as BoostPriorityResponse, z as BulkEnqueueParams, D as BulkEnqueueResponse, E as BulkJobItem, F as CheckEmailResponse, G as CheckSlugResponse, H as CircuitBreaker, I as CircuitBreakerConfig, J as CircuitState, K as ClaimJobsParams, L as ClaimJobsResult, M as ClaimedJob, N as CompleteJobParams, O as CreateApiKeyParams, P as CreateApiKeyResponse, Q as CreateBillingPortalParams, T as CreateBillingPortalResponse, U as CreateJobParams, V as CreateJobResult, W as CreateOrganizationParams, X as CreateOrganizationResponse, Y as CreateOutgoingWebhookParams, Z as CreateScheduleParams, _ as CreateScheduleResponse, $ as CreateWorkflowParams, a0 as CreateWorkflowResponse, a1 as CurrentUserResponse, a2 as DEFAULT_CONFIG, a3 as DashboardData, a4 as DashboardResource, a5 as DashboardWorkerSummary, a6 as DebugFn, a7 as DependencyInfo, a8 as DependencyMode, a9 as FailJobParams, aa as GrpcClientOptions, ab as GrpcCompleteJobParams, ac as GrpcCompleteJobResponse, ad as GrpcCompleteRequest, ae as GrpcCompleteResponse, af as GrpcDequeueJobParams, ag as GrpcDequeueJobResponse, ah as GrpcDequeueRequest, ai as GrpcDequeueResponse, aj as GrpcDeregisterRequest, ak as GrpcDeregisterResponse, al as GrpcEnqueueJobParams, am as GrpcEnqueueJobResponse, an as GrpcEnqueueRequest, ao as GrpcEnqueueResponse, ap as GrpcErrorResponse, aq as GrpcFailJobParams, ar as GrpcFailJobResponse, as as GrpcFailRequest, at as GrpcFailResponse, au as GrpcGetJobRequest, av as GrpcGetJobResponse, aw as GrpcGetQueueStatsRequest, ax as GrpcGetQueueStatsResponse, ay as GrpcGetQueueStatsResponse_Legacy, az as GrpcHeartbeatParams, aA as GrpcHeartbeatRequest, aB as GrpcHeartbeatResponse, aC as GrpcHeartbeatResponse_Legacy, aD as GrpcJob, aE as GrpcJobStatus, aF as GrpcJobStatusNumber, aG as GrpcProcessRequest, aH as GrpcProcessResponse, aI as GrpcQueueOperations, aJ as GrpcRegisterWorkerParams, aK as GrpcRegisterWorkerRequest, aL as GrpcRegisterWorkerResponse, aM as GrpcRegisterWorkerResponse_Legacy, aN as GrpcRenewLeaseParams, aO as GrpcRenewLeaseRequest, aP as GrpcRenewLeaseResponse, aQ as GrpcRenewLeaseResponse_Legacy, aR as GrpcStreamJobsRequest, aS as GrpcTimestamp, aT as GrpcWorkerOperations, aU as HealthResource, aV as HealthResponse, aW as HeartbeatEvent, aX as HeartbeatJobParams, aY as HttpClient, aZ as IngestCustomWebhookParams, a_ as IngestCustomWebhookResponse, a$ as IngestGitHubWebhookOptions, b0 as IngestStripeWebhookOptions, b1 as InitialApiKey, b2 as Job, b3 as JobCompletedEvent, b4 as JobContext, b5 as JobCreatedEvent, b6 as JobFailedEvent, b7 as JobHandler, b8 as JobProgressEvent, b9 as JobResult, ba as JobStartedEvent, bb as JobStats, bc as JobStatus, bd as JobStatusChangedEvent, be as JobStream, bf as JobSummary, bg as JobSummaryStats, bh as JobWithDependencies, bi as JobsResource, bj as JsonArray, bk as JsonObject, bl as JsonPrimitive, bm as JsonValue, bn as ListDlqParams, bo as ListJobsParams, bp as ListParams, bq as ListSchedulesParams, br as ListWorkflowsParams, bs as LoginParams, bt as LoginResponse, bu as MetricsResource, bv as Organization, bw as OrganizationMember, bx as OrganizationSummary, by as OrganizationUsage, bz as OrganizationsResource, bA as OutgoingWebhook, bB as OutgoingWebhookDelivery, bC as PaginatedResponse, bD as PaginationParams, bE as PauseQueueResponse, bF as PlanCount, bG as PlanLimits, bH as PlanTier, bI as ProcessJobsStream, bJ as PurgeDlqParams, bK as PurgeDlqResponse, bL as QueueConfig, bM as QueueConfigSummary, bN as QueuePausedEvent, bO as QueueResumedEvent, bP as QueueStats, bQ as QueueSummary, bR as QueuesResource, bS as RealtimeEventData, bT as RecentActivity, bU as RefreshTokenParams, bV as RefreshTokenResponse, bW as RegisterWorkerParams, bX as RegisterWorkerResponse, bY as ResolvedConfig, bZ as ResourceUsage, b_ as ResumeQueueResponse, b$ as RetryDlqParams, c0 as RetryDlqResponse, c1 as SDK_VERSION, c2 as Schedule, c3 as ScheduleRun, c4 as ScheduleRunStatus, c5 as ScheduleTriggeredEvent, c6 as SchedulesResource, c7 as SpooledClient, c8 as SpooledClientConfig, c9 as SpooledGrpcClient, ca as SpooledRealtime, cb as SpooledRealtimeOptions, cc as SpooledWorker, cd as SpooledWorkerOptions, ce as StartEmailLoginResponse, cf as StreamOptions, cg as SystemInfo, ch as TestWebhookResponse, ci as TokenClaims, cj as TriggerScheduleResponse, ck as UpdateApiKeyParams, cl as UpdateOrganizationParams, cm as UpdateOutgoingWebhookParams, cn as UpdateQueueConfigParams, co as UpdateScheduleParams, cp as UsageItem, cq as UsageWarning, cr as ValidateTokenParams, cs as ValidateTokenResponse, ct as WebhookDeliveryStatus, cu as WebhookEventType, cv as WebhookIngestionResource, cw as WebhookTokenResponse, cx as WebhooksResource, cy as Worker, cz as WorkerDeregisteredEvent, cA as WorkerEvent, cB as WorkerEventData, cC as WorkerHeartbeatParams, cD as WorkerRegisteredEvent, cE as WorkerState, cF as WorkerStatus, cG as WorkerSummary, cH as WorkersResource, cI as Workflow, cJ as WorkflowJob, cK as WorkflowJobDefinition, cL as WorkflowJobStatus, cM as WorkflowResponse, cN as WorkflowStatus, cO as WorkflowsResource, cP as asyncIterableFromStream, cQ as createCircuitBreaker, cR as createClient, cS as createHttpClient, cT as createJobStream, cU as createPaginatedResponse, cV as createProcessJobsStream, cW as dateToTimestamp, cX as resolveConfig, cY as timestampToDate, cZ as validateConfig } from './index-CWVI9LRo.cjs';
1
+ import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-DzTC8ld3.cjs';
2
+ export { A as API_VERSION, d as AddDependenciesParams, e as AddDependenciesResponse, f as AdminApiKeyResponse, g as AdminCreateApiKeyParams, h as AdminCreateOrganizationParams, i as AdminCreateOrganizationResponse, j as AdminDeleteOrganizationParams, k as AdminListOrganizationsParams, l as AdminOrganizationDetail, m as AdminOrganizationList, n as AdminOrganizationSummary, o as AdminPlanLimits, p as AdminPlatformStats, q as AdminResource, r as AdminUpdateOrganizationParams, s as AdminUsageStats, t as ApiErrorBody, u as ApiKeySummary, v as ApiKeysResource, w as AuthResource, x as AuthenticationError, y as AuthorizationError, B as BatchJobStatus, z as BillingResource, D as BillingStatus, E as BoostPriorityResponse, F as BulkEnqueueParams, G as BulkEnqueueResponse, H as BulkJobItem, I as CheckEmailResponse, J as CheckSlugResponse, K as CircuitBreaker, L as CircuitBreakerConfig, M as CircuitBreakerOpenError, N as CircuitBreakerOptions, O as CircuitState, P as CircuitStateChange, Q as ClaimJobsParams, T as ClaimJobsResult, U as ClaimedJob, V as CompleteJobParams, W as ConflictError, X as CreateApiKeyParams, Y as CreateApiKeyResponse, Z as CreateBillingPortalParams, _ as CreateBillingPortalResponse, $ as CreateJobParams, a0 as CreateJobResult, a1 as CreateOrganizationParams, a2 as CreateOrganizationResponse, a3 as CreateOutgoingWebhookParams, a4 as CreateScheduleParams, a5 as CreateScheduleResponse, a6 as CreateWorkflowParams, a7 as CreateWorkflowResponse, a8 as CurrentUserResponse, a9 as DEFAULT_CONFIG, aa as DashboardData, ab as DashboardResource, ac as DashboardWorkerSummary, ad as DebugFn, ae as DeleteQueueOptions, af as DependencyInfo, ag as DependencyMode, ah as FailJobParams, ai as GrpcClientOptions, aj as GrpcCompleteJobParams, ak as GrpcCompleteJobResponse, al as GrpcCompleteRequest, am as GrpcCompleteResponse, an as GrpcDequeueJobParams, ao as GrpcDequeueJobResponse, ap as GrpcDequeueRequest, aq as GrpcDequeueResponse, ar as GrpcDeregisterRequest, as as GrpcDeregisterResponse, at as GrpcEnqueueJobParams, au as GrpcEnqueueJobResponse, av as GrpcEnqueueRequest, aw as GrpcEnqueueResponse, ax as GrpcErrorResponse, ay as GrpcFailJobParams, az as GrpcFailJobResponse, aA as GrpcFailRequest, aB as GrpcFailResponse, aC as GrpcGetJobRequest, aD as GrpcGetJobResponse, aE as GrpcGetQueueStatsRequest, aF as GrpcGetQueueStatsResponse, aG as GrpcGetQueueStatsResponse_Legacy, aH as GrpcHeartbeatParams, aI as GrpcHeartbeatRequest, aJ as GrpcHeartbeatResponse, aK as GrpcHeartbeatResponse_Legacy, aL as GrpcJob, aM as GrpcJobStatus, aN as GrpcJobStatusNumber, aO as GrpcProcessRequest, aP as GrpcProcessResponse, aQ as GrpcQueueOperations, aR as GrpcRegisterWorkerParams, aS as GrpcRegisterWorkerRequest, aT as GrpcRegisterWorkerResponse, aU as GrpcRegisterWorkerResponse_Legacy, aV as GrpcRenewLeaseParams, aW as GrpcRenewLeaseRequest, aX as GrpcRenewLeaseResponse, aY as GrpcRenewLeaseResponse_Legacy, aZ as GrpcStreamJobsRequest, a_ as GrpcTimestamp, a$ as GrpcWorkerOperations, b0 as HealthResource, b1 as HealthResponse, b2 as HeartbeatEvent, b3 as HeartbeatJobParams, b4 as HttpClient, b5 as InboundDeliveryStatus, b6 as InboundWebhookDelivery, b7 as IngestCustomWebhookParams, b8 as IngestCustomWebhookResponse, b9 as IngestGitHubWebhookOptions, ba as IngestStripeWebhookOptions, bb as InitialApiKey, bc as Job, bd as JobCompletedEvent, be as JobContext, bf as JobCreatedEvent, bg as JobFailedEvent, bh as JobHandler, bi as JobHistoryEvent, bj as JobHistoryEventType, bk as JobHistoryParams, bl as JobProgressEvent, bm as JobResult, bn as JobSearchParams, bo as JobStartedEvent, bp as JobStats, bq as JobStatus, br as JobStatusChangedEvent, bs as JobStream, bt as JobSummary, bu as JobSummaryStats, bv as JobWithDependencies, bw as JobsResource, bx as JsonArray, by as JsonObject, bz as JsonPrimitive, bA as JsonValue, bB as ListDlqParams, bC as ListInboundDeliveriesParams, bD as ListJobsParams, bE as ListPage, bF as ListParams, bG as ListSchedulesParams, bH as ListWorkflowsParams, bI as LoginParams, bJ as LoginResponse, bK as MetricsResource, bL as NetworkError, bM as NotFoundError, bN as Organization, bO as OrganizationMember, bP as OrganizationSummary, bQ as OrganizationUsage, bR as OrganizationsResource, bS as OutgoingWebhook, bT as OutgoingWebhookDelivery, bU as PaginatedResponse, bV as PaginationParams, bW as PauseQueueResponse, bX as PayloadTooLargeError, bY as PlanCount, bZ as PlanLimits, b_ as PlanTier, b$ as ProcessJobsStream, c0 as PurgeDlqParams, c1 as PurgeDlqResponse, c2 as QueueConfig, c3 as QueueConfigSummary, c4 as QueuePausedEvent, c5 as QueueResumedEvent, c6 as QueueStats, c7 as QueueSummary, c8 as QueuesResource, c9 as RateLimitError, ca as RateLimitInfo, cb as RealtimeEventData, cc as RecentActivity, cd as RefreshTokenParams, ce as RefreshTokenResponse, cf as RegisterWorkerParams, cg as RegisterWorkerResponse, ch as ResolvedConfig, ci as ResourceUsage, cj as ResumeQueueResponse, ck as RetryDlqParams, cl as RetryDlqResponse, cm as SDK_VERSION, cn as Schedule, co as ScheduleRun, cp as ScheduleRunStatus, cq as ScheduleTriggeredEvent, cr as SchedulesResource, cs as ServerError, ct as SpooledClient, cu as SpooledClientConfig, cv as SpooledError, cw as SpooledGrpcClient, cx as SpooledRealtime, cy as SpooledRealtimeOptions, cz as SpooledWorker, cA as SpooledWorkerOptions, cB as StartEmailLoginResponse, cC as StreamOptions, cD as SystemInfo, cE as TestWebhookResponse, cF as TimeoutError, cG as TokenClaims, cH as TriggerScheduleResponse, cI as UnsupportedOperationError, cJ as UpdateApiKeyParams, cK as UpdateOrganizationParams, cL as UpdateOutgoingWebhookParams, cM as UpdateQueueConfigParams, cN as UpdateScheduleParams, cO as UsageItem, cP as UsageWarning, cQ as ValidateTokenParams, cR as ValidateTokenResponse, cS as ValidationError, cT as WebhookDeliveryStatus, cU as WebhookEventType, cV as WebhookFormat, cW as WebhookIngestionResource, cX as WebhookTokenResponse, cY as WebhooksResource, cZ as Worker, c_ as WorkerDeregisteredEvent, c$ as WorkerEvent, d0 as WorkerEventData, d1 as WorkerHeartbeatParams, d2 as WorkerRegisteredEvent, d3 as WorkerState, d4 as WorkerStatus, d5 as WorkerSummary, d6 as WorkersResource, d7 as Workflow, d8 as WorkflowJob, d9 as WorkflowJobDefinition, da as WorkflowJobStatus, db as WorkflowResponse, dc as WorkflowStatus, dd as WorkflowsResource, de as asyncIterableFromStream, df as createCircuitBreaker, dg as createClient, dh as createErrorFromResponse, di as createHttpClient, dj as createJobStream, dk as createPaginatedResponse, dl as createProcessJobsStream, dm as dateToTimestamp, dn as isCircuitBreakerFailure, dp as isRetryableError, dq as isSpooledError, dr as parseRateLimitHeaders, ds as resolveConfig, dt as timestampToDate, du as validateConfig } from './index-DzTC8ld3.cjs';
3
3
  import * as protoLoader from '@grpc/proto-loader';
4
4
  import { ServiceClientConstructor } from '@grpc/grpc-js';
5
5
 
@@ -122,6 +122,12 @@ declare class SseRealtimeClient {
122
122
  private reconnectAttempts;
123
123
  private reconnectTimer;
124
124
  private filter;
125
+ /** When the current connection opened (for the stable-connection check). */
126
+ private connectedAt;
127
+ /** The server finished this stream on purpose (terminal job); do not reconnect. */
128
+ private streamEnded;
129
+ /** The server rejected our token; mint a fresh one for the next connect. */
130
+ private forceTokenRefresh;
125
131
  private eventHandlers;
126
132
  private allEventsHandlers;
127
133
  private stateChangeHandlers;
@@ -165,154 +171,6 @@ declare class SseRealtimeClient {
165
171
  private scheduleReconnect;
166
172
  }
167
173
 
168
- /**
169
- * Custom Error Classes
170
- *
171
- * Provides a hierarchy of error types for the Spooled SDK.
172
- */
173
- /** Error response body from the API */
174
- interface ApiErrorBody {
175
- code: string;
176
- message: string;
177
- details?: Record<string, unknown>;
178
- }
179
- /** Rate limit information parsed from headers */
180
- interface RateLimitInfo {
181
- /** Maximum requests per window */
182
- limit?: number;
183
- /** Remaining requests in current window */
184
- remaining?: number;
185
- /** Unix timestamp when the window resets */
186
- reset?: Date;
187
- /** Seconds to wait before retrying */
188
- retryAfter?: number;
189
- }
190
- /**
191
- * Base error class for all Spooled SDK errors
192
- */
193
- declare class SpooledError extends Error {
194
- /** HTTP status code (if applicable) */
195
- readonly statusCode: number;
196
- /** Error code from API response */
197
- readonly code: string;
198
- /** Additional error details */
199
- readonly details?: Record<string, unknown>;
200
- /** Request ID for debugging */
201
- readonly requestId?: string;
202
- /** Original cause of the error */
203
- readonly cause?: Error;
204
- constructor(message: string, statusCode?: number, code?: string, details?: Record<string, unknown>, requestId?: string, cause?: Error);
205
- /** Whether this error is retryable */
206
- isRetryable(): boolean;
207
- /** Convert to plain object for logging */
208
- toJSON(): Record<string, unknown>;
209
- }
210
- /**
211
- * Authentication error (401)
212
- * Thrown when authentication fails (invalid/expired token or API key)
213
- */
214
- declare class AuthenticationError extends SpooledError {
215
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
216
- }
217
- /**
218
- * Authorization error (403)
219
- * Thrown when the authenticated user lacks permission
220
- */
221
- declare class AuthorizationError extends SpooledError {
222
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
223
- }
224
- /**
225
- * Not found error (404)
226
- * Thrown when a requested resource doesn't exist
227
- */
228
- declare class NotFoundError extends SpooledError {
229
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
230
- }
231
- /**
232
- * Conflict error (409)
233
- * Thrown when there's a conflict (e.g., duplicate resource)
234
- */
235
- declare class ConflictError extends SpooledError {
236
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
237
- }
238
- /**
239
- * Validation error (400)
240
- * Thrown when request validation fails
241
- */
242
- declare class ValidationError extends SpooledError {
243
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
244
- }
245
- /**
246
- * Payload too large error (413)
247
- * Thrown when request body exceeds size limit
248
- */
249
- declare class PayloadTooLargeError extends SpooledError {
250
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
251
- }
252
- /**
253
- * Rate limit error (429)
254
- * Thrown when rate limit is exceeded
255
- */
256
- declare class RateLimitError extends SpooledError {
257
- /** Rate limit information */
258
- readonly rateLimitInfo: RateLimitInfo;
259
- constructor(message?: string, code?: string, rateLimitInfo?: RateLimitInfo, details?: Record<string, unknown>, requestId?: string);
260
- isRetryable(): boolean;
261
- /** Get the number of seconds to wait before retrying */
262
- getRetryAfter(): number;
263
- toJSON(): Record<string, unknown>;
264
- }
265
- /**
266
- * Server error (5xx)
267
- * Thrown when the server encounters an error
268
- */
269
- declare class ServerError extends SpooledError {
270
- constructor(message?: string, statusCode?: number, code?: string, details?: Record<string, unknown>, requestId?: string);
271
- isRetryable(): boolean;
272
- }
273
- /**
274
- * Network error
275
- * Thrown when a network request fails (no response received)
276
- */
277
- declare class NetworkError extends SpooledError {
278
- constructor(message?: string, cause?: Error);
279
- isRetryable(): boolean;
280
- }
281
- /**
282
- * Timeout error
283
- * Thrown when a request times out
284
- */
285
- declare class TimeoutError extends SpooledError {
286
- /** Timeout duration in milliseconds */
287
- readonly timeoutMs: number;
288
- constructor(message?: string, timeoutMs?: number);
289
- isRetryable(): boolean;
290
- }
291
- /**
292
- * Circuit breaker open error
293
- * Thrown when the circuit breaker is open and rejecting requests
294
- */
295
- declare class CircuitBreakerOpenError extends SpooledError {
296
- constructor(message?: string);
297
- isRetryable(): boolean;
298
- }
299
- /**
300
- * Parse rate limit headers from a Response
301
- */
302
- declare function parseRateLimitHeaders(headers: Headers): RateLimitInfo;
303
- /**
304
- * Create an appropriate error from an HTTP response
305
- */
306
- declare function createErrorFromResponse(response: Response): Promise<SpooledError>;
307
- /**
308
- * Check if an error is a SpooledError instance
309
- */
310
- declare function isSpooledError(error: unknown): error is SpooledError;
311
- /**
312
- * Check if an error is retryable
313
- */
314
- declare function isRetryableError(error: unknown): boolean;
315
-
316
174
  /**
317
175
  * Proto Loader Utility
318
176
  *
@@ -456,4 +314,4 @@ declare function convertResponse<T>(body: T): T;
456
314
  */
457
315
  declare function convertQueryParams(params: Record<string, string | number | boolean | undefined>): Record<string, string>;
458
316
 
459
- export { type ApiErrorBody, AuthenticationError, AuthorizationError, CircuitBreakerOpenError, ConflictError, ConnectionState, NetworkError, NotFoundError, PROTO_LOADER_OPTIONS, PayloadTooLargeError, RateLimitError, type RateLimitInfo, RealtimeConnectionOptions, RealtimeEvent, RealtimeEventType, RetryConfig, ServerError, SpooledError, type SpooledProtoDefinition, SseRealtimeClient, SubscriptionFilter, TimeoutError, ValidationError, WebSocketRealtimeClient, calculateDelay, camelToSnake, clearProtoCache, convertQueryParams, convertRequest, convertResponse, createErrorFromResponse, createRetryWrapper, getProtoPath, isRetryableError, isSpooledError, loadProtoDefinition, loadProtoDefinitionAsync, parseRateLimitHeaders, shouldRetry, sleep, snakeToCamel, toCamelCase, toSnakeCase, withRetry };
317
+ export { ConnectionState, PROTO_LOADER_OPTIONS, RealtimeConnectionOptions, RealtimeEvent, RealtimeEventType, RetryConfig, type SpooledProtoDefinition, SseRealtimeClient, SubscriptionFilter, WebSocketRealtimeClient, calculateDelay, camelToSnake, clearProtoCache, convertQueryParams, convertRequest, convertResponse, createRetryWrapper, getProtoPath, loadProtoDefinition, loadProtoDefinitionAsync, shouldRetry, sleep, snakeToCamel, toCamelCase, toSnakeCase, withRetry };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-CWVI9LRo.js';
2
- export { A as API_VERSION, d as AddDependenciesParams, e as AddDependenciesResponse, f as AdminApiKeyResponse, g as AdminCreateApiKeyParams, h as AdminCreateOrganizationParams, i as AdminCreateOrganizationResponse, j as AdminDeleteOrganizationParams, k as AdminListOrganizationsParams, l as AdminOrganizationDetail, m as AdminOrganizationList, n as AdminOrganizationSummary, o as AdminPlanLimits, p as AdminPlatformStats, q as AdminResource, r as AdminUpdateOrganizationParams, s as AdminUsageStats, t as ApiKeySummary, u as ApiKeysResource, v as AuthResource, B as BatchJobStatus, w as BillingResource, x as BillingStatus, y as BoostPriorityResponse, z as BulkEnqueueParams, D as BulkEnqueueResponse, E as BulkJobItem, F as CheckEmailResponse, G as CheckSlugResponse, H as CircuitBreaker, I as CircuitBreakerConfig, J as CircuitState, K as ClaimJobsParams, L as ClaimJobsResult, M as ClaimedJob, N as CompleteJobParams, O as CreateApiKeyParams, P as CreateApiKeyResponse, Q as CreateBillingPortalParams, T as CreateBillingPortalResponse, U as CreateJobParams, V as CreateJobResult, W as CreateOrganizationParams, X as CreateOrganizationResponse, Y as CreateOutgoingWebhookParams, Z as CreateScheduleParams, _ as CreateScheduleResponse, $ as CreateWorkflowParams, a0 as CreateWorkflowResponse, a1 as CurrentUserResponse, a2 as DEFAULT_CONFIG, a3 as DashboardData, a4 as DashboardResource, a5 as DashboardWorkerSummary, a6 as DebugFn, a7 as DependencyInfo, a8 as DependencyMode, a9 as FailJobParams, aa as GrpcClientOptions, ab as GrpcCompleteJobParams, ac as GrpcCompleteJobResponse, ad as GrpcCompleteRequest, ae as GrpcCompleteResponse, af as GrpcDequeueJobParams, ag as GrpcDequeueJobResponse, ah as GrpcDequeueRequest, ai as GrpcDequeueResponse, aj as GrpcDeregisterRequest, ak as GrpcDeregisterResponse, al as GrpcEnqueueJobParams, am as GrpcEnqueueJobResponse, an as GrpcEnqueueRequest, ao as GrpcEnqueueResponse, ap as GrpcErrorResponse, aq as GrpcFailJobParams, ar as GrpcFailJobResponse, as as GrpcFailRequest, at as GrpcFailResponse, au as GrpcGetJobRequest, av as GrpcGetJobResponse, aw as GrpcGetQueueStatsRequest, ax as GrpcGetQueueStatsResponse, ay as GrpcGetQueueStatsResponse_Legacy, az as GrpcHeartbeatParams, aA as GrpcHeartbeatRequest, aB as GrpcHeartbeatResponse, aC as GrpcHeartbeatResponse_Legacy, aD as GrpcJob, aE as GrpcJobStatus, aF as GrpcJobStatusNumber, aG as GrpcProcessRequest, aH as GrpcProcessResponse, aI as GrpcQueueOperations, aJ as GrpcRegisterWorkerParams, aK as GrpcRegisterWorkerRequest, aL as GrpcRegisterWorkerResponse, aM as GrpcRegisterWorkerResponse_Legacy, aN as GrpcRenewLeaseParams, aO as GrpcRenewLeaseRequest, aP as GrpcRenewLeaseResponse, aQ as GrpcRenewLeaseResponse_Legacy, aR as GrpcStreamJobsRequest, aS as GrpcTimestamp, aT as GrpcWorkerOperations, aU as HealthResource, aV as HealthResponse, aW as HeartbeatEvent, aX as HeartbeatJobParams, aY as HttpClient, aZ as IngestCustomWebhookParams, a_ as IngestCustomWebhookResponse, a$ as IngestGitHubWebhookOptions, b0 as IngestStripeWebhookOptions, b1 as InitialApiKey, b2 as Job, b3 as JobCompletedEvent, b4 as JobContext, b5 as JobCreatedEvent, b6 as JobFailedEvent, b7 as JobHandler, b8 as JobProgressEvent, b9 as JobResult, ba as JobStartedEvent, bb as JobStats, bc as JobStatus, bd as JobStatusChangedEvent, be as JobStream, bf as JobSummary, bg as JobSummaryStats, bh as JobWithDependencies, bi as JobsResource, bj as JsonArray, bk as JsonObject, bl as JsonPrimitive, bm as JsonValue, bn as ListDlqParams, bo as ListJobsParams, bp as ListParams, bq as ListSchedulesParams, br as ListWorkflowsParams, bs as LoginParams, bt as LoginResponse, bu as MetricsResource, bv as Organization, bw as OrganizationMember, bx as OrganizationSummary, by as OrganizationUsage, bz as OrganizationsResource, bA as OutgoingWebhook, bB as OutgoingWebhookDelivery, bC as PaginatedResponse, bD as PaginationParams, bE as PauseQueueResponse, bF as PlanCount, bG as PlanLimits, bH as PlanTier, bI as ProcessJobsStream, bJ as PurgeDlqParams, bK as PurgeDlqResponse, bL as QueueConfig, bM as QueueConfigSummary, bN as QueuePausedEvent, bO as QueueResumedEvent, bP as QueueStats, bQ as QueueSummary, bR as QueuesResource, bS as RealtimeEventData, bT as RecentActivity, bU as RefreshTokenParams, bV as RefreshTokenResponse, bW as RegisterWorkerParams, bX as RegisterWorkerResponse, bY as ResolvedConfig, bZ as ResourceUsage, b_ as ResumeQueueResponse, b$ as RetryDlqParams, c0 as RetryDlqResponse, c1 as SDK_VERSION, c2 as Schedule, c3 as ScheduleRun, c4 as ScheduleRunStatus, c5 as ScheduleTriggeredEvent, c6 as SchedulesResource, c7 as SpooledClient, c8 as SpooledClientConfig, c9 as SpooledGrpcClient, ca as SpooledRealtime, cb as SpooledRealtimeOptions, cc as SpooledWorker, cd as SpooledWorkerOptions, ce as StartEmailLoginResponse, cf as StreamOptions, cg as SystemInfo, ch as TestWebhookResponse, ci as TokenClaims, cj as TriggerScheduleResponse, ck as UpdateApiKeyParams, cl as UpdateOrganizationParams, cm as UpdateOutgoingWebhookParams, cn as UpdateQueueConfigParams, co as UpdateScheduleParams, cp as UsageItem, cq as UsageWarning, cr as ValidateTokenParams, cs as ValidateTokenResponse, ct as WebhookDeliveryStatus, cu as WebhookEventType, cv as WebhookIngestionResource, cw as WebhookTokenResponse, cx as WebhooksResource, cy as Worker, cz as WorkerDeregisteredEvent, cA as WorkerEvent, cB as WorkerEventData, cC as WorkerHeartbeatParams, cD as WorkerRegisteredEvent, cE as WorkerState, cF as WorkerStatus, cG as WorkerSummary, cH as WorkersResource, cI as Workflow, cJ as WorkflowJob, cK as WorkflowJobDefinition, cL as WorkflowJobStatus, cM as WorkflowResponse, cN as WorkflowStatus, cO as WorkflowsResource, cP as asyncIterableFromStream, cQ as createCircuitBreaker, cR as createClient, cS as createHttpClient, cT as createJobStream, cU as createPaginatedResponse, cV as createProcessJobsStream, cW as dateToTimestamp, cX as resolveConfig, cY as timestampToDate, cZ as validateConfig } from './index-CWVI9LRo.js';
1
+ import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-DzTC8ld3.js';
2
+ export { A as API_VERSION, d as AddDependenciesParams, e as AddDependenciesResponse, f as AdminApiKeyResponse, g as AdminCreateApiKeyParams, h as AdminCreateOrganizationParams, i as AdminCreateOrganizationResponse, j as AdminDeleteOrganizationParams, k as AdminListOrganizationsParams, l as AdminOrganizationDetail, m as AdminOrganizationList, n as AdminOrganizationSummary, o as AdminPlanLimits, p as AdminPlatformStats, q as AdminResource, r as AdminUpdateOrganizationParams, s as AdminUsageStats, t as ApiErrorBody, u as ApiKeySummary, v as ApiKeysResource, w as AuthResource, x as AuthenticationError, y as AuthorizationError, B as BatchJobStatus, z as BillingResource, D as BillingStatus, E as BoostPriorityResponse, F as BulkEnqueueParams, G as BulkEnqueueResponse, H as BulkJobItem, I as CheckEmailResponse, J as CheckSlugResponse, K as CircuitBreaker, L as CircuitBreakerConfig, M as CircuitBreakerOpenError, N as CircuitBreakerOptions, O as CircuitState, P as CircuitStateChange, Q as ClaimJobsParams, T as ClaimJobsResult, U as ClaimedJob, V as CompleteJobParams, W as ConflictError, X as CreateApiKeyParams, Y as CreateApiKeyResponse, Z as CreateBillingPortalParams, _ as CreateBillingPortalResponse, $ as CreateJobParams, a0 as CreateJobResult, a1 as CreateOrganizationParams, a2 as CreateOrganizationResponse, a3 as CreateOutgoingWebhookParams, a4 as CreateScheduleParams, a5 as CreateScheduleResponse, a6 as CreateWorkflowParams, a7 as CreateWorkflowResponse, a8 as CurrentUserResponse, a9 as DEFAULT_CONFIG, aa as DashboardData, ab as DashboardResource, ac as DashboardWorkerSummary, ad as DebugFn, ae as DeleteQueueOptions, af as DependencyInfo, ag as DependencyMode, ah as FailJobParams, ai as GrpcClientOptions, aj as GrpcCompleteJobParams, ak as GrpcCompleteJobResponse, al as GrpcCompleteRequest, am as GrpcCompleteResponse, an as GrpcDequeueJobParams, ao as GrpcDequeueJobResponse, ap as GrpcDequeueRequest, aq as GrpcDequeueResponse, ar as GrpcDeregisterRequest, as as GrpcDeregisterResponse, at as GrpcEnqueueJobParams, au as GrpcEnqueueJobResponse, av as GrpcEnqueueRequest, aw as GrpcEnqueueResponse, ax as GrpcErrorResponse, ay as GrpcFailJobParams, az as GrpcFailJobResponse, aA as GrpcFailRequest, aB as GrpcFailResponse, aC as GrpcGetJobRequest, aD as GrpcGetJobResponse, aE as GrpcGetQueueStatsRequest, aF as GrpcGetQueueStatsResponse, aG as GrpcGetQueueStatsResponse_Legacy, aH as GrpcHeartbeatParams, aI as GrpcHeartbeatRequest, aJ as GrpcHeartbeatResponse, aK as GrpcHeartbeatResponse_Legacy, aL as GrpcJob, aM as GrpcJobStatus, aN as GrpcJobStatusNumber, aO as GrpcProcessRequest, aP as GrpcProcessResponse, aQ as GrpcQueueOperations, aR as GrpcRegisterWorkerParams, aS as GrpcRegisterWorkerRequest, aT as GrpcRegisterWorkerResponse, aU as GrpcRegisterWorkerResponse_Legacy, aV as GrpcRenewLeaseParams, aW as GrpcRenewLeaseRequest, aX as GrpcRenewLeaseResponse, aY as GrpcRenewLeaseResponse_Legacy, aZ as GrpcStreamJobsRequest, a_ as GrpcTimestamp, a$ as GrpcWorkerOperations, b0 as HealthResource, b1 as HealthResponse, b2 as HeartbeatEvent, b3 as HeartbeatJobParams, b4 as HttpClient, b5 as InboundDeliveryStatus, b6 as InboundWebhookDelivery, b7 as IngestCustomWebhookParams, b8 as IngestCustomWebhookResponse, b9 as IngestGitHubWebhookOptions, ba as IngestStripeWebhookOptions, bb as InitialApiKey, bc as Job, bd as JobCompletedEvent, be as JobContext, bf as JobCreatedEvent, bg as JobFailedEvent, bh as JobHandler, bi as JobHistoryEvent, bj as JobHistoryEventType, bk as JobHistoryParams, bl as JobProgressEvent, bm as JobResult, bn as JobSearchParams, bo as JobStartedEvent, bp as JobStats, bq as JobStatus, br as JobStatusChangedEvent, bs as JobStream, bt as JobSummary, bu as JobSummaryStats, bv as JobWithDependencies, bw as JobsResource, bx as JsonArray, by as JsonObject, bz as JsonPrimitive, bA as JsonValue, bB as ListDlqParams, bC as ListInboundDeliveriesParams, bD as ListJobsParams, bE as ListPage, bF as ListParams, bG as ListSchedulesParams, bH as ListWorkflowsParams, bI as LoginParams, bJ as LoginResponse, bK as MetricsResource, bL as NetworkError, bM as NotFoundError, bN as Organization, bO as OrganizationMember, bP as OrganizationSummary, bQ as OrganizationUsage, bR as OrganizationsResource, bS as OutgoingWebhook, bT as OutgoingWebhookDelivery, bU as PaginatedResponse, bV as PaginationParams, bW as PauseQueueResponse, bX as PayloadTooLargeError, bY as PlanCount, bZ as PlanLimits, b_ as PlanTier, b$ as ProcessJobsStream, c0 as PurgeDlqParams, c1 as PurgeDlqResponse, c2 as QueueConfig, c3 as QueueConfigSummary, c4 as QueuePausedEvent, c5 as QueueResumedEvent, c6 as QueueStats, c7 as QueueSummary, c8 as QueuesResource, c9 as RateLimitError, ca as RateLimitInfo, cb as RealtimeEventData, cc as RecentActivity, cd as RefreshTokenParams, ce as RefreshTokenResponse, cf as RegisterWorkerParams, cg as RegisterWorkerResponse, ch as ResolvedConfig, ci as ResourceUsage, cj as ResumeQueueResponse, ck as RetryDlqParams, cl as RetryDlqResponse, cm as SDK_VERSION, cn as Schedule, co as ScheduleRun, cp as ScheduleRunStatus, cq as ScheduleTriggeredEvent, cr as SchedulesResource, cs as ServerError, ct as SpooledClient, cu as SpooledClientConfig, cv as SpooledError, cw as SpooledGrpcClient, cx as SpooledRealtime, cy as SpooledRealtimeOptions, cz as SpooledWorker, cA as SpooledWorkerOptions, cB as StartEmailLoginResponse, cC as StreamOptions, cD as SystemInfo, cE as TestWebhookResponse, cF as TimeoutError, cG as TokenClaims, cH as TriggerScheduleResponse, cI as UnsupportedOperationError, cJ as UpdateApiKeyParams, cK as UpdateOrganizationParams, cL as UpdateOutgoingWebhookParams, cM as UpdateQueueConfigParams, cN as UpdateScheduleParams, cO as UsageItem, cP as UsageWarning, cQ as ValidateTokenParams, cR as ValidateTokenResponse, cS as ValidationError, cT as WebhookDeliveryStatus, cU as WebhookEventType, cV as WebhookFormat, cW as WebhookIngestionResource, cX as WebhookTokenResponse, cY as WebhooksResource, cZ as Worker, c_ as WorkerDeregisteredEvent, c$ as WorkerEvent, d0 as WorkerEventData, d1 as WorkerHeartbeatParams, d2 as WorkerRegisteredEvent, d3 as WorkerState, d4 as WorkerStatus, d5 as WorkerSummary, d6 as WorkersResource, d7 as Workflow, d8 as WorkflowJob, d9 as WorkflowJobDefinition, da as WorkflowJobStatus, db as WorkflowResponse, dc as WorkflowStatus, dd as WorkflowsResource, de as asyncIterableFromStream, df as createCircuitBreaker, dg as createClient, dh as createErrorFromResponse, di as createHttpClient, dj as createJobStream, dk as createPaginatedResponse, dl as createProcessJobsStream, dm as dateToTimestamp, dn as isCircuitBreakerFailure, dp as isRetryableError, dq as isSpooledError, dr as parseRateLimitHeaders, ds as resolveConfig, dt as timestampToDate, du as validateConfig } from './index-DzTC8ld3.js';
3
3
  import * as protoLoader from '@grpc/proto-loader';
4
4
  import { ServiceClientConstructor } from '@grpc/grpc-js';
5
5
 
@@ -122,6 +122,12 @@ declare class SseRealtimeClient {
122
122
  private reconnectAttempts;
123
123
  private reconnectTimer;
124
124
  private filter;
125
+ /** When the current connection opened (for the stable-connection check). */
126
+ private connectedAt;
127
+ /** The server finished this stream on purpose (terminal job); do not reconnect. */
128
+ private streamEnded;
129
+ /** The server rejected our token; mint a fresh one for the next connect. */
130
+ private forceTokenRefresh;
125
131
  private eventHandlers;
126
132
  private allEventsHandlers;
127
133
  private stateChangeHandlers;
@@ -165,154 +171,6 @@ declare class SseRealtimeClient {
165
171
  private scheduleReconnect;
166
172
  }
167
173
 
168
- /**
169
- * Custom Error Classes
170
- *
171
- * Provides a hierarchy of error types for the Spooled SDK.
172
- */
173
- /** Error response body from the API */
174
- interface ApiErrorBody {
175
- code: string;
176
- message: string;
177
- details?: Record<string, unknown>;
178
- }
179
- /** Rate limit information parsed from headers */
180
- interface RateLimitInfo {
181
- /** Maximum requests per window */
182
- limit?: number;
183
- /** Remaining requests in current window */
184
- remaining?: number;
185
- /** Unix timestamp when the window resets */
186
- reset?: Date;
187
- /** Seconds to wait before retrying */
188
- retryAfter?: number;
189
- }
190
- /**
191
- * Base error class for all Spooled SDK errors
192
- */
193
- declare class SpooledError extends Error {
194
- /** HTTP status code (if applicable) */
195
- readonly statusCode: number;
196
- /** Error code from API response */
197
- readonly code: string;
198
- /** Additional error details */
199
- readonly details?: Record<string, unknown>;
200
- /** Request ID for debugging */
201
- readonly requestId?: string;
202
- /** Original cause of the error */
203
- readonly cause?: Error;
204
- constructor(message: string, statusCode?: number, code?: string, details?: Record<string, unknown>, requestId?: string, cause?: Error);
205
- /** Whether this error is retryable */
206
- isRetryable(): boolean;
207
- /** Convert to plain object for logging */
208
- toJSON(): Record<string, unknown>;
209
- }
210
- /**
211
- * Authentication error (401)
212
- * Thrown when authentication fails (invalid/expired token or API key)
213
- */
214
- declare class AuthenticationError extends SpooledError {
215
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
216
- }
217
- /**
218
- * Authorization error (403)
219
- * Thrown when the authenticated user lacks permission
220
- */
221
- declare class AuthorizationError extends SpooledError {
222
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
223
- }
224
- /**
225
- * Not found error (404)
226
- * Thrown when a requested resource doesn't exist
227
- */
228
- declare class NotFoundError extends SpooledError {
229
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
230
- }
231
- /**
232
- * Conflict error (409)
233
- * Thrown when there's a conflict (e.g., duplicate resource)
234
- */
235
- declare class ConflictError extends SpooledError {
236
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
237
- }
238
- /**
239
- * Validation error (400)
240
- * Thrown when request validation fails
241
- */
242
- declare class ValidationError extends SpooledError {
243
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
244
- }
245
- /**
246
- * Payload too large error (413)
247
- * Thrown when request body exceeds size limit
248
- */
249
- declare class PayloadTooLargeError extends SpooledError {
250
- constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
251
- }
252
- /**
253
- * Rate limit error (429)
254
- * Thrown when rate limit is exceeded
255
- */
256
- declare class RateLimitError extends SpooledError {
257
- /** Rate limit information */
258
- readonly rateLimitInfo: RateLimitInfo;
259
- constructor(message?: string, code?: string, rateLimitInfo?: RateLimitInfo, details?: Record<string, unknown>, requestId?: string);
260
- isRetryable(): boolean;
261
- /** Get the number of seconds to wait before retrying */
262
- getRetryAfter(): number;
263
- toJSON(): Record<string, unknown>;
264
- }
265
- /**
266
- * Server error (5xx)
267
- * Thrown when the server encounters an error
268
- */
269
- declare class ServerError extends SpooledError {
270
- constructor(message?: string, statusCode?: number, code?: string, details?: Record<string, unknown>, requestId?: string);
271
- isRetryable(): boolean;
272
- }
273
- /**
274
- * Network error
275
- * Thrown when a network request fails (no response received)
276
- */
277
- declare class NetworkError extends SpooledError {
278
- constructor(message?: string, cause?: Error);
279
- isRetryable(): boolean;
280
- }
281
- /**
282
- * Timeout error
283
- * Thrown when a request times out
284
- */
285
- declare class TimeoutError extends SpooledError {
286
- /** Timeout duration in milliseconds */
287
- readonly timeoutMs: number;
288
- constructor(message?: string, timeoutMs?: number);
289
- isRetryable(): boolean;
290
- }
291
- /**
292
- * Circuit breaker open error
293
- * Thrown when the circuit breaker is open and rejecting requests
294
- */
295
- declare class CircuitBreakerOpenError extends SpooledError {
296
- constructor(message?: string);
297
- isRetryable(): boolean;
298
- }
299
- /**
300
- * Parse rate limit headers from a Response
301
- */
302
- declare function parseRateLimitHeaders(headers: Headers): RateLimitInfo;
303
- /**
304
- * Create an appropriate error from an HTTP response
305
- */
306
- declare function createErrorFromResponse(response: Response): Promise<SpooledError>;
307
- /**
308
- * Check if an error is a SpooledError instance
309
- */
310
- declare function isSpooledError(error: unknown): error is SpooledError;
311
- /**
312
- * Check if an error is retryable
313
- */
314
- declare function isRetryableError(error: unknown): boolean;
315
-
316
174
  /**
317
175
  * Proto Loader Utility
318
176
  *
@@ -456,4 +314,4 @@ declare function convertResponse<T>(body: T): T;
456
314
  */
457
315
  declare function convertQueryParams(params: Record<string, string | number | boolean | undefined>): Record<string, string>;
458
316
 
459
- export { type ApiErrorBody, AuthenticationError, AuthorizationError, CircuitBreakerOpenError, ConflictError, ConnectionState, NetworkError, NotFoundError, PROTO_LOADER_OPTIONS, PayloadTooLargeError, RateLimitError, type RateLimitInfo, RealtimeConnectionOptions, RealtimeEvent, RealtimeEventType, RetryConfig, ServerError, SpooledError, type SpooledProtoDefinition, SseRealtimeClient, SubscriptionFilter, TimeoutError, ValidationError, WebSocketRealtimeClient, calculateDelay, camelToSnake, clearProtoCache, convertQueryParams, convertRequest, convertResponse, createErrorFromResponse, createRetryWrapper, getProtoPath, isRetryableError, isSpooledError, loadProtoDefinition, loadProtoDefinitionAsync, parseRateLimitHeaders, shouldRetry, sleep, snakeToCamel, toCamelCase, toSnakeCase, withRetry };
317
+ export { ConnectionState, PROTO_LOADER_OPTIONS, RealtimeConnectionOptions, RealtimeEvent, RealtimeEventType, RetryConfig, type SpooledProtoDefinition, SseRealtimeClient, SubscriptionFilter, WebSocketRealtimeClient, calculateDelay, camelToSnake, clearProtoCache, convertQueryParams, convertRequest, convertResponse, createRetryWrapper, getProtoPath, loadProtoDefinition, loadProtoDefinitionAsync, shouldRetry, sleep, snakeToCamel, toCamelCase, toSnakeCase, withRetry };