@spooled/sdk 1.0.30 → 1.0.31

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-Dv2jBkfc.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 CheckSlugResponse, G as CircuitBreaker, H as CircuitBreakerConfig, I as CircuitState, J as ClaimJobsParams, K as ClaimJobsResult, L as ClaimedJob, M as CompleteJobParams, N as CreateApiKeyParams, O as CreateApiKeyResponse, P as CreateBillingPortalParams, Q as CreateBillingPortalResponse, T as CreateJobParams, U as CreateJobResult, V as CreateOrganizationParams, W as CreateOrganizationResponse, X as CreateOutgoingWebhookParams, Y as CreateScheduleParams, Z as CreateScheduleResponse, _ as CreateWorkflowParams, $ as CreateWorkflowResponse, a0 as CurrentUserResponse, a1 as DEFAULT_CONFIG, a2 as DashboardData, a3 as DashboardResource, a4 as DashboardWorkerSummary, a5 as DebugFn, a6 as DependencyMode, a7 as FailJobParams, a8 as GrpcClientOptions, a9 as GrpcCompleteJobParams, aa as GrpcCompleteJobResponse, ab as GrpcCompleteRequest, ac as GrpcCompleteResponse, ad as GrpcDequeueJobParams, ae as GrpcDequeueJobResponse, af as GrpcDequeueRequest, ag as GrpcDequeueResponse, ah as GrpcDeregisterRequest, ai as GrpcDeregisterResponse, aj as GrpcEnqueueJobParams, ak as GrpcEnqueueJobResponse, al as GrpcEnqueueRequest, am as GrpcEnqueueResponse, an as GrpcErrorResponse, ao as GrpcFailJobParams, ap as GrpcFailJobResponse, aq as GrpcFailRequest, ar as GrpcFailResponse, as as GrpcGetJobRequest, at as GrpcGetJobResponse, au as GrpcGetQueueStatsRequest, av as GrpcGetQueueStatsResponse, aw as GrpcGetQueueStatsResponse_Legacy, ax as GrpcHeartbeatParams, ay as GrpcHeartbeatRequest, az as GrpcHeartbeatResponse, aA as GrpcHeartbeatResponse_Legacy, aB as GrpcJob, aC as GrpcJobStatus, aD as GrpcJobStatusNumber, aE as GrpcProcessRequest, aF as GrpcProcessResponse, aG as GrpcQueueOperations, aH as GrpcRegisterWorkerParams, aI as GrpcRegisterWorkerRequest, aJ as GrpcRegisterWorkerResponse, aK as GrpcRegisterWorkerResponse_Legacy, aL as GrpcRenewLeaseParams, aM as GrpcRenewLeaseRequest, aN as GrpcRenewLeaseResponse, aO as GrpcRenewLeaseResponse_Legacy, aP as GrpcStreamJobsRequest, aQ as GrpcTimestamp, aR as GrpcWorkerOperations, aS as HealthResource, aT as HealthResponse, aU as HeartbeatEvent, aV as HeartbeatJobParams, aW as HttpClient, aX as IngestCustomWebhookParams, aY as IngestGitHubWebhookOptions, aZ as IngestStripeWebhookOptions, a_ as InitialApiKey, a$ as Job, b0 as JobCompletedEvent, b1 as JobContext, b2 as JobCreatedEvent, b3 as JobFailedEvent, b4 as JobHandler, b5 as JobProgressEvent, b6 as JobResult, b7 as JobStartedEvent, b8 as JobStats, b9 as JobStatus, ba as JobStatusChangedEvent, bb as JobStream, bc as JobSummary, bd as JobSummaryStats, be as JobWithDependencies, bf as JobsResource, bg as JsonArray, bh as JsonObject, bi as JsonPrimitive, bj as JsonValue, bk as ListDlqParams, bl as ListJobsParams, bm as ListParams, bn as ListSchedulesParams, bo as ListWorkflowsParams, bp as LoginParams, bq as LoginResponse, br as MetricsResource, bs as Organization, bt as OrganizationMember, bu as OrganizationSummary, bv as OrganizationUsage, bw as OrganizationsResource, bx as OutgoingWebhook, by as OutgoingWebhookDelivery, bz as PaginatedResponse, bA as PaginationParams, bB as PauseQueueResponse, bC as PlanCount, bD as PlanLimits, bE as PlanTier, bF as ProcessJobsStream, bG as PurgeDlqParams, bH as PurgeDlqResponse, bI as QueueConfig, bJ as QueueConfigSummary, bK as QueuePausedEvent, bL as QueueResumedEvent, bM as QueueStats, bN as QueueSummary, bO as QueuesResource, bP as RealtimeEventData, bQ as RecentActivity, bR as RefreshTokenParams, bS as RefreshTokenResponse, bT as RegisterWorkerParams, bU as RegisterWorkerResponse, bV as ResolvedConfig, bW as ResourceUsage, bX as ResumeQueueResponse, bY as RetryDlqParams, bZ as RetryDlqResponse, b_ as SDK_VERSION, b$ as Schedule, c0 as ScheduleRun, c1 as ScheduleRunStatus, c2 as ScheduleTriggeredEvent, c3 as SchedulesResource, c4 as SpooledClient, c5 as SpooledClientConfig, c6 as SpooledGrpcClient, c7 as SpooledRealtime, c8 as SpooledRealtimeOptions, c9 as SpooledWorker, ca as SpooledWorkerOptions, cb as StreamOptions, cc as SystemInfo, cd as TestWebhookResponse, ce as TriggerScheduleResponse, cf as UpdateApiKeyParams, cg as UpdateOrganizationParams, ch as UpdateOutgoingWebhookParams, ci as UpdateQueueConfigParams, cj as UpdateScheduleParams, ck as UsageItem, cl as UsageWarning, cm as ValidateTokenParams, cn as ValidateTokenResponse, co as WebhookDeliveryStatus, cp as WebhookEventType, cq as WebhookIngestionResource, cr as WebhookTokenResponse, cs as WebhooksResource, ct as Worker, cu as WorkerDeregisteredEvent, cv as WorkerEvent, cw as WorkerEventData, cx as WorkerHeartbeatParams, cy as WorkerRegisteredEvent, cz as WorkerState, cA as WorkerStatus, cB as WorkerSummary, cC as WorkersResource, cD as Workflow, cE as WorkflowJob, cF as WorkflowJobDefinition, cG as WorkflowJobStatus, cH as WorkflowResponse, cI as WorkflowStatus, cJ as WorkflowsResource, cK as asyncIterableFromStream, cL as createCircuitBreaker, cM as createClient, cN as createHttpClient, cO as createJobStream, cP as createPaginatedResponse, cQ as createProcessJobsStream, cR as dateToTimestamp, cS as resolveConfig, cT as timestampToDate, cU as validateConfig } from './index-Dv2jBkfc.cjs';
1
+ import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-CfLL1w6Y.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 CheckSlugResponse, G as CircuitBreaker, H as CircuitBreakerConfig, I as CircuitState, J as ClaimJobsParams, K as ClaimJobsResult, L as ClaimedJob, M as CompleteJobParams, N as CreateApiKeyParams, O as CreateApiKeyResponse, P as CreateBillingPortalParams, Q as CreateBillingPortalResponse, T as CreateJobParams, U as CreateJobResult, V as CreateOrganizationParams, W as CreateOrganizationResponse, X as CreateOutgoingWebhookParams, Y as CreateScheduleParams, Z as CreateScheduleResponse, _ as CreateWorkflowParams, $ as CreateWorkflowResponse, a0 as CurrentUserResponse, a1 as DEFAULT_CONFIG, a2 as DashboardData, a3 as DashboardResource, a4 as DashboardWorkerSummary, a5 as DebugFn, a6 as DependencyMode, a7 as FailJobParams, a8 as GrpcClientOptions, a9 as GrpcCompleteJobParams, aa as GrpcCompleteJobResponse, ab as GrpcCompleteRequest, ac as GrpcCompleteResponse, ad as GrpcDequeueJobParams, ae as GrpcDequeueJobResponse, af as GrpcDequeueRequest, ag as GrpcDequeueResponse, ah as GrpcDeregisterRequest, ai as GrpcDeregisterResponse, aj as GrpcEnqueueJobParams, ak as GrpcEnqueueJobResponse, al as GrpcEnqueueRequest, am as GrpcEnqueueResponse, an as GrpcErrorResponse, ao as GrpcFailJobParams, ap as GrpcFailJobResponse, aq as GrpcFailRequest, ar as GrpcFailResponse, as as GrpcGetJobRequest, at as GrpcGetJobResponse, au as GrpcGetQueueStatsRequest, av as GrpcGetQueueStatsResponse, aw as GrpcGetQueueStatsResponse_Legacy, ax as GrpcHeartbeatParams, ay as GrpcHeartbeatRequest, az as GrpcHeartbeatResponse, aA as GrpcHeartbeatResponse_Legacy, aB as GrpcJob, aC as GrpcJobStatus, aD as GrpcJobStatusNumber, aE as GrpcProcessRequest, aF as GrpcProcessResponse, aG as GrpcQueueOperations, aH as GrpcRegisterWorkerParams, aI as GrpcRegisterWorkerRequest, aJ as GrpcRegisterWorkerResponse, aK as GrpcRegisterWorkerResponse_Legacy, aL as GrpcRenewLeaseParams, aM as GrpcRenewLeaseRequest, aN as GrpcRenewLeaseResponse, aO as GrpcRenewLeaseResponse_Legacy, aP as GrpcStreamJobsRequest, aQ as GrpcTimestamp, aR as GrpcWorkerOperations, aS as HealthResource, aT as HealthResponse, aU as HeartbeatEvent, aV as HeartbeatJobParams, aW as HttpClient, aX as IngestCustomWebhookParams, aY as IngestGitHubWebhookOptions, aZ as IngestStripeWebhookOptions, a_ as InitialApiKey, a$ as Job, b0 as JobCompletedEvent, b1 as JobContext, b2 as JobCreatedEvent, b3 as JobFailedEvent, b4 as JobHandler, b5 as JobProgressEvent, b6 as JobResult, b7 as JobStartedEvent, b8 as JobStats, b9 as JobStatus, ba as JobStatusChangedEvent, bb as JobStream, bc as JobSummary, bd as JobSummaryStats, be as JobWithDependencies, bf as JobsResource, bg as JsonArray, bh as JsonObject, bi as JsonPrimitive, bj as JsonValue, bk as ListDlqParams, bl as ListJobsParams, bm as ListParams, bn as ListSchedulesParams, bo as ListWorkflowsParams, bp as LoginParams, bq as LoginResponse, br as MetricsResource, bs as Organization, bt as OrganizationMember, bu as OrganizationSummary, bv as OrganizationUsage, bw as OrganizationsResource, bx as OutgoingWebhook, by as OutgoingWebhookDelivery, bz as PaginatedResponse, bA as PaginationParams, bB as PauseQueueResponse, bC as PlanCount, bD as PlanLimits, bE as PlanTier, bF as ProcessJobsStream, bG as PurgeDlqParams, bH as PurgeDlqResponse, bI as QueueConfig, bJ as QueueConfigSummary, bK as QueuePausedEvent, bL as QueueResumedEvent, bM as QueueStats, bN as QueueSummary, bO as QueuesResource, bP as RealtimeEventData, bQ as RecentActivity, bR as RefreshTokenParams, bS as RefreshTokenResponse, bT as RegisterWorkerParams, bU as RegisterWorkerResponse, bV as ResolvedConfig, bW as ResourceUsage, bX as ResumeQueueResponse, bY as RetryDlqParams, bZ as RetryDlqResponse, b_ as SDK_VERSION, b$ as Schedule, c0 as ScheduleRun, c1 as ScheduleRunStatus, c2 as ScheduleTriggeredEvent, c3 as SchedulesResource, c4 as SpooledClient, c5 as SpooledClientConfig, c6 as SpooledGrpcClient, c7 as SpooledRealtime, c8 as SpooledRealtimeOptions, c9 as SpooledWorker, ca as SpooledWorkerOptions, cb as StreamOptions, cc as SystemInfo, cd as TestWebhookResponse, ce as TriggerScheduleResponse, cf as UpdateApiKeyParams, cg as UpdateOrganizationParams, ch as UpdateOutgoingWebhookParams, ci as UpdateQueueConfigParams, cj as UpdateScheduleParams, ck as UsageItem, cl as UsageWarning, cm as ValidateTokenParams, cn as ValidateTokenResponse, co as WebhookDeliveryStatus, cp as WebhookEventType, cq as WebhookIngestionResource, cr as WebhookTokenResponse, cs as WebhooksResource, ct as Worker, cu as WorkerDeregisteredEvent, cv as WorkerEvent, cw as WorkerEventData, cx as WorkerHeartbeatParams, cy as WorkerRegisteredEvent, cz as WorkerState, cA as WorkerStatus, cB as WorkerSummary, cC as WorkersResource, cD as Workflow, cE as WorkflowJob, cF as WorkflowJobDefinition, cG as WorkflowJobStatus, cH as WorkflowResponse, cI as WorkflowStatus, cJ as WorkflowsResource, cK as asyncIterableFromStream, cL as createCircuitBreaker, cM as createClient, cN as createHttpClient, cO as createJobStream, cP as createPaginatedResponse, cQ as createProcessJobsStream, cR as dateToTimestamp, cS as resolveConfig, cT as timestampToDate, cU as validateConfig } from './index-CfLL1w6Y.cjs';
3
3
  import * as protoLoader from '@grpc/proto-loader';
4
4
  import { ServiceClientConstructor } from '@grpc/grpc-js';
5
5
 
@@ -24,6 +24,12 @@ declare class WebSocketRealtimeClient {
24
24
  private state;
25
25
  private reconnectAttempts;
26
26
  private reconnectTimer;
27
+ /**
28
+ * Set when the server rejected our token on the upgrade (e.g. HTTP 401/403).
29
+ * The next (re)connect uses it to force the token provider to mint a fresh
30
+ * JWT instead of replaying the rejected one (which would loop forever).
31
+ */
32
+ private authFailure;
27
33
  private subscriptions;
28
34
  private pendingCommands;
29
35
  private eventHandlers;
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-Dv2jBkfc.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 CheckSlugResponse, G as CircuitBreaker, H as CircuitBreakerConfig, I as CircuitState, J as ClaimJobsParams, K as ClaimJobsResult, L as ClaimedJob, M as CompleteJobParams, N as CreateApiKeyParams, O as CreateApiKeyResponse, P as CreateBillingPortalParams, Q as CreateBillingPortalResponse, T as CreateJobParams, U as CreateJobResult, V as CreateOrganizationParams, W as CreateOrganizationResponse, X as CreateOutgoingWebhookParams, Y as CreateScheduleParams, Z as CreateScheduleResponse, _ as CreateWorkflowParams, $ as CreateWorkflowResponse, a0 as CurrentUserResponse, a1 as DEFAULT_CONFIG, a2 as DashboardData, a3 as DashboardResource, a4 as DashboardWorkerSummary, a5 as DebugFn, a6 as DependencyMode, a7 as FailJobParams, a8 as GrpcClientOptions, a9 as GrpcCompleteJobParams, aa as GrpcCompleteJobResponse, ab as GrpcCompleteRequest, ac as GrpcCompleteResponse, ad as GrpcDequeueJobParams, ae as GrpcDequeueJobResponse, af as GrpcDequeueRequest, ag as GrpcDequeueResponse, ah as GrpcDeregisterRequest, ai as GrpcDeregisterResponse, aj as GrpcEnqueueJobParams, ak as GrpcEnqueueJobResponse, al as GrpcEnqueueRequest, am as GrpcEnqueueResponse, an as GrpcErrorResponse, ao as GrpcFailJobParams, ap as GrpcFailJobResponse, aq as GrpcFailRequest, ar as GrpcFailResponse, as as GrpcGetJobRequest, at as GrpcGetJobResponse, au as GrpcGetQueueStatsRequest, av as GrpcGetQueueStatsResponse, aw as GrpcGetQueueStatsResponse_Legacy, ax as GrpcHeartbeatParams, ay as GrpcHeartbeatRequest, az as GrpcHeartbeatResponse, aA as GrpcHeartbeatResponse_Legacy, aB as GrpcJob, aC as GrpcJobStatus, aD as GrpcJobStatusNumber, aE as GrpcProcessRequest, aF as GrpcProcessResponse, aG as GrpcQueueOperations, aH as GrpcRegisterWorkerParams, aI as GrpcRegisterWorkerRequest, aJ as GrpcRegisterWorkerResponse, aK as GrpcRegisterWorkerResponse_Legacy, aL as GrpcRenewLeaseParams, aM as GrpcRenewLeaseRequest, aN as GrpcRenewLeaseResponse, aO as GrpcRenewLeaseResponse_Legacy, aP as GrpcStreamJobsRequest, aQ as GrpcTimestamp, aR as GrpcWorkerOperations, aS as HealthResource, aT as HealthResponse, aU as HeartbeatEvent, aV as HeartbeatJobParams, aW as HttpClient, aX as IngestCustomWebhookParams, aY as IngestGitHubWebhookOptions, aZ as IngestStripeWebhookOptions, a_ as InitialApiKey, a$ as Job, b0 as JobCompletedEvent, b1 as JobContext, b2 as JobCreatedEvent, b3 as JobFailedEvent, b4 as JobHandler, b5 as JobProgressEvent, b6 as JobResult, b7 as JobStartedEvent, b8 as JobStats, b9 as JobStatus, ba as JobStatusChangedEvent, bb as JobStream, bc as JobSummary, bd as JobSummaryStats, be as JobWithDependencies, bf as JobsResource, bg as JsonArray, bh as JsonObject, bi as JsonPrimitive, bj as JsonValue, bk as ListDlqParams, bl as ListJobsParams, bm as ListParams, bn as ListSchedulesParams, bo as ListWorkflowsParams, bp as LoginParams, bq as LoginResponse, br as MetricsResource, bs as Organization, bt as OrganizationMember, bu as OrganizationSummary, bv as OrganizationUsage, bw as OrganizationsResource, bx as OutgoingWebhook, by as OutgoingWebhookDelivery, bz as PaginatedResponse, bA as PaginationParams, bB as PauseQueueResponse, bC as PlanCount, bD as PlanLimits, bE as PlanTier, bF as ProcessJobsStream, bG as PurgeDlqParams, bH as PurgeDlqResponse, bI as QueueConfig, bJ as QueueConfigSummary, bK as QueuePausedEvent, bL as QueueResumedEvent, bM as QueueStats, bN as QueueSummary, bO as QueuesResource, bP as RealtimeEventData, bQ as RecentActivity, bR as RefreshTokenParams, bS as RefreshTokenResponse, bT as RegisterWorkerParams, bU as RegisterWorkerResponse, bV as ResolvedConfig, bW as ResourceUsage, bX as ResumeQueueResponse, bY as RetryDlqParams, bZ as RetryDlqResponse, b_ as SDK_VERSION, b$ as Schedule, c0 as ScheduleRun, c1 as ScheduleRunStatus, c2 as ScheduleTriggeredEvent, c3 as SchedulesResource, c4 as SpooledClient, c5 as SpooledClientConfig, c6 as SpooledGrpcClient, c7 as SpooledRealtime, c8 as SpooledRealtimeOptions, c9 as SpooledWorker, ca as SpooledWorkerOptions, cb as StreamOptions, cc as SystemInfo, cd as TestWebhookResponse, ce as TriggerScheduleResponse, cf as UpdateApiKeyParams, cg as UpdateOrganizationParams, ch as UpdateOutgoingWebhookParams, ci as UpdateQueueConfigParams, cj as UpdateScheduleParams, ck as UsageItem, cl as UsageWarning, cm as ValidateTokenParams, cn as ValidateTokenResponse, co as WebhookDeliveryStatus, cp as WebhookEventType, cq as WebhookIngestionResource, cr as WebhookTokenResponse, cs as WebhooksResource, ct as Worker, cu as WorkerDeregisteredEvent, cv as WorkerEvent, cw as WorkerEventData, cx as WorkerHeartbeatParams, cy as WorkerRegisteredEvent, cz as WorkerState, cA as WorkerStatus, cB as WorkerSummary, cC as WorkersResource, cD as Workflow, cE as WorkflowJob, cF as WorkflowJobDefinition, cG as WorkflowJobStatus, cH as WorkflowResponse, cI as WorkflowStatus, cJ as WorkflowsResource, cK as asyncIterableFromStream, cL as createCircuitBreaker, cM as createClient, cN as createHttpClient, cO as createJobStream, cP as createPaginatedResponse, cQ as createProcessJobsStream, cR as dateToTimestamp, cS as resolveConfig, cT as timestampToDate, cU as validateConfig } from './index-Dv2jBkfc.js';
1
+ import { R as RealtimeConnectionOptions, C as ConnectionState, S as SubscriptionFilter, a as RealtimeEventType, b as RealtimeEvent, c as RetryConfig } from './index-CfLL1w6Y.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 CheckSlugResponse, G as CircuitBreaker, H as CircuitBreakerConfig, I as CircuitState, J as ClaimJobsParams, K as ClaimJobsResult, L as ClaimedJob, M as CompleteJobParams, N as CreateApiKeyParams, O as CreateApiKeyResponse, P as CreateBillingPortalParams, Q as CreateBillingPortalResponse, T as CreateJobParams, U as CreateJobResult, V as CreateOrganizationParams, W as CreateOrganizationResponse, X as CreateOutgoingWebhookParams, Y as CreateScheduleParams, Z as CreateScheduleResponse, _ as CreateWorkflowParams, $ as CreateWorkflowResponse, a0 as CurrentUserResponse, a1 as DEFAULT_CONFIG, a2 as DashboardData, a3 as DashboardResource, a4 as DashboardWorkerSummary, a5 as DebugFn, a6 as DependencyMode, a7 as FailJobParams, a8 as GrpcClientOptions, a9 as GrpcCompleteJobParams, aa as GrpcCompleteJobResponse, ab as GrpcCompleteRequest, ac as GrpcCompleteResponse, ad as GrpcDequeueJobParams, ae as GrpcDequeueJobResponse, af as GrpcDequeueRequest, ag as GrpcDequeueResponse, ah as GrpcDeregisterRequest, ai as GrpcDeregisterResponse, aj as GrpcEnqueueJobParams, ak as GrpcEnqueueJobResponse, al as GrpcEnqueueRequest, am as GrpcEnqueueResponse, an as GrpcErrorResponse, ao as GrpcFailJobParams, ap as GrpcFailJobResponse, aq as GrpcFailRequest, ar as GrpcFailResponse, as as GrpcGetJobRequest, at as GrpcGetJobResponse, au as GrpcGetQueueStatsRequest, av as GrpcGetQueueStatsResponse, aw as GrpcGetQueueStatsResponse_Legacy, ax as GrpcHeartbeatParams, ay as GrpcHeartbeatRequest, az as GrpcHeartbeatResponse, aA as GrpcHeartbeatResponse_Legacy, aB as GrpcJob, aC as GrpcJobStatus, aD as GrpcJobStatusNumber, aE as GrpcProcessRequest, aF as GrpcProcessResponse, aG as GrpcQueueOperations, aH as GrpcRegisterWorkerParams, aI as GrpcRegisterWorkerRequest, aJ as GrpcRegisterWorkerResponse, aK as GrpcRegisterWorkerResponse_Legacy, aL as GrpcRenewLeaseParams, aM as GrpcRenewLeaseRequest, aN as GrpcRenewLeaseResponse, aO as GrpcRenewLeaseResponse_Legacy, aP as GrpcStreamJobsRequest, aQ as GrpcTimestamp, aR as GrpcWorkerOperations, aS as HealthResource, aT as HealthResponse, aU as HeartbeatEvent, aV as HeartbeatJobParams, aW as HttpClient, aX as IngestCustomWebhookParams, aY as IngestGitHubWebhookOptions, aZ as IngestStripeWebhookOptions, a_ as InitialApiKey, a$ as Job, b0 as JobCompletedEvent, b1 as JobContext, b2 as JobCreatedEvent, b3 as JobFailedEvent, b4 as JobHandler, b5 as JobProgressEvent, b6 as JobResult, b7 as JobStartedEvent, b8 as JobStats, b9 as JobStatus, ba as JobStatusChangedEvent, bb as JobStream, bc as JobSummary, bd as JobSummaryStats, be as JobWithDependencies, bf as JobsResource, bg as JsonArray, bh as JsonObject, bi as JsonPrimitive, bj as JsonValue, bk as ListDlqParams, bl as ListJobsParams, bm as ListParams, bn as ListSchedulesParams, bo as ListWorkflowsParams, bp as LoginParams, bq as LoginResponse, br as MetricsResource, bs as Organization, bt as OrganizationMember, bu as OrganizationSummary, bv as OrganizationUsage, bw as OrganizationsResource, bx as OutgoingWebhook, by as OutgoingWebhookDelivery, bz as PaginatedResponse, bA as PaginationParams, bB as PauseQueueResponse, bC as PlanCount, bD as PlanLimits, bE as PlanTier, bF as ProcessJobsStream, bG as PurgeDlqParams, bH as PurgeDlqResponse, bI as QueueConfig, bJ as QueueConfigSummary, bK as QueuePausedEvent, bL as QueueResumedEvent, bM as QueueStats, bN as QueueSummary, bO as QueuesResource, bP as RealtimeEventData, bQ as RecentActivity, bR as RefreshTokenParams, bS as RefreshTokenResponse, bT as RegisterWorkerParams, bU as RegisterWorkerResponse, bV as ResolvedConfig, bW as ResourceUsage, bX as ResumeQueueResponse, bY as RetryDlqParams, bZ as RetryDlqResponse, b_ as SDK_VERSION, b$ as Schedule, c0 as ScheduleRun, c1 as ScheduleRunStatus, c2 as ScheduleTriggeredEvent, c3 as SchedulesResource, c4 as SpooledClient, c5 as SpooledClientConfig, c6 as SpooledGrpcClient, c7 as SpooledRealtime, c8 as SpooledRealtimeOptions, c9 as SpooledWorker, ca as SpooledWorkerOptions, cb as StreamOptions, cc as SystemInfo, cd as TestWebhookResponse, ce as TriggerScheduleResponse, cf as UpdateApiKeyParams, cg as UpdateOrganizationParams, ch as UpdateOutgoingWebhookParams, ci as UpdateQueueConfigParams, cj as UpdateScheduleParams, ck as UsageItem, cl as UsageWarning, cm as ValidateTokenParams, cn as ValidateTokenResponse, co as WebhookDeliveryStatus, cp as WebhookEventType, cq as WebhookIngestionResource, cr as WebhookTokenResponse, cs as WebhooksResource, ct as Worker, cu as WorkerDeregisteredEvent, cv as WorkerEvent, cw as WorkerEventData, cx as WorkerHeartbeatParams, cy as WorkerRegisteredEvent, cz as WorkerState, cA as WorkerStatus, cB as WorkerSummary, cC as WorkersResource, cD as Workflow, cE as WorkflowJob, cF as WorkflowJobDefinition, cG as WorkflowJobStatus, cH as WorkflowResponse, cI as WorkflowStatus, cJ as WorkflowsResource, cK as asyncIterableFromStream, cL as createCircuitBreaker, cM as createClient, cN as createHttpClient, cO as createJobStream, cP as createPaginatedResponse, cQ as createProcessJobsStream, cR as dateToTimestamp, cS as resolveConfig, cT as timestampToDate, cU as validateConfig } from './index-CfLL1w6Y.js';
3
3
  import * as protoLoader from '@grpc/proto-loader';
4
4
  import { ServiceClientConstructor } from '@grpc/grpc-js';
5
5
 
@@ -24,6 +24,12 @@ declare class WebSocketRealtimeClient {
24
24
  private state;
25
25
  private reconnectAttempts;
26
26
  private reconnectTimer;
27
+ /**
28
+ * Set when the server rejected our token on the upgrade (e.g. HTTP 401/403).
29
+ * The next (re)connect uses it to force the token provider to mint a fresh
30
+ * JWT instead of replaying the rejected one (which would loop forever).
31
+ */
32
+ private authFailure;
27
33
  private subscriptions;
28
34
  private pendingCommands;
29
35
  private eventHandlers;
package/dist/index.js CHANGED
@@ -25,10 +25,10 @@ var DEFAULT_CONFIG = {
25
25
  successThreshold: 3,
26
26
  timeout: 3e4
27
27
  },
28
- userAgent: "@spooled/sdk-nodejs/1.0.26",
28
+ userAgent: "@spooled/sdk-nodejs/1.0.31",
29
29
  autoRefreshToken: true
30
30
  };
31
- var SDK_VERSION = "1.0.26";
31
+ var SDK_VERSION = "1.0.31";
32
32
  var API_VERSION = "v1";
33
33
  var API_BASE_PATH = `/api/${API_VERSION}`;
34
34
  function resolveConfig(options) {
@@ -1825,6 +1825,12 @@ var WebSocketRealtimeClient = class {
1825
1825
  state = "disconnected";
1826
1826
  reconnectAttempts = 0;
1827
1827
  reconnectTimer = null;
1828
+ /**
1829
+ * Set when the server rejected our token on the upgrade (e.g. HTTP 401/403).
1830
+ * The next (re)connect uses it to force the token provider to mint a fresh
1831
+ * JWT instead of replaying the rejected one (which would loop forever).
1832
+ */
1833
+ authFailure = false;
1828
1834
  subscriptions = /* @__PURE__ */ new Map();
1829
1835
  pendingCommands = /* @__PURE__ */ new Map();
1830
1836
  // Event handlers
@@ -1906,6 +1912,9 @@ var WebSocketRealtimeClient = class {
1906
1912
  };
1907
1913
  this.ws.onerror = (event) => {
1908
1914
  this.options.debug("WebSocket error", event);
1915
+ if (isAuthFailureEvent(event)) {
1916
+ this.authFailure = true;
1917
+ }
1909
1918
  };
1910
1919
  } catch (error) {
1911
1920
  this.setState("disconnected");
@@ -1992,7 +2001,9 @@ var WebSocketRealtimeClient = class {
1992
2001
  // Private methods
1993
2002
  async buildWsUrl() {
1994
2003
  const wsBase = this.options.wsUrl;
1995
- const token = await this.options.tokenProvider();
2004
+ const forceRefresh = this.authFailure;
2005
+ this.authFailure = false;
2006
+ const token = await this.options.tokenProvider(forceRefresh);
1996
2007
  return `${wsBase}/api/v1/ws?token=${encodeURIComponent(token)}`;
1997
2008
  }
1998
2009
  setState(state) {
@@ -2115,6 +2126,17 @@ var WebSocketRealtimeClient = class {
2115
2126
  function redactToken(url) {
2116
2127
  return url.replace(/([?&](?:token|api_key)=)[^&]*/gi, "$1***");
2117
2128
  }
2129
+ function isAuthFailureEvent(event) {
2130
+ if (!event) {
2131
+ return false;
2132
+ }
2133
+ const status = event.status ?? event.statusCode ?? event.error?.status;
2134
+ if (status === 401 || status === 403) {
2135
+ return true;
2136
+ }
2137
+ const text = String(event.message ?? event.error?.message ?? event.reason ?? "");
2138
+ return /\b(401|403)\b/.test(text);
2139
+ }
2118
2140
 
2119
2141
  // src/realtime/sse.ts
2120
2142
  var SseRealtimeClient = class {
@@ -2853,6 +2875,18 @@ var SpooledClient = class _SpooledClient {
2853
2875
  /** Token refresh state */
2854
2876
  refreshPromise = null;
2855
2877
  tokenExpiresAt = null;
2878
+ /**
2879
+ * Cached JWT for realtime connections (API-key auth path).
2880
+ *
2881
+ * The realtime layer requests a token on every (re)connect. Minting a brand
2882
+ * new JWT via POST /auth/login each time trips the login rate limit (429)
2883
+ * under a reconnect storm, after which realtime can never recover. We cache
2884
+ * the token here — at the client level, shared across reconnects — and reuse
2885
+ * it until it nears expiry.
2886
+ */
2887
+ cachedJwt = null;
2888
+ /** Deduplicates concurrent logins (e.g. WS + SSE reconnecting together). */
2889
+ jwtLoginPromise = null;
2856
2890
  constructor(options) {
2857
2891
  this.config = resolveConfig(options);
2858
2892
  validateConfig(this.config);
@@ -2940,9 +2974,10 @@ var SpooledClient = class _SpooledClient {
2940
2974
  baseUrl: this.config.baseUrl,
2941
2975
  wsUrl: this.config.wsUrl,
2942
2976
  token,
2943
- // Provider so each (re)connect mints a fresh JWT via login/refresh,
2944
- // rather than reusing the short-lived token captured above.
2945
- tokenProvider: () => this.getJwtToken(),
2977
+ // Provider the realtime layer calls on every (re)connect. It returns a
2978
+ // cached JWT and only re-logs-in when the token is absent, near expiry,
2979
+ // or the transport asks to force a refresh (e.g. after a 401 upgrade).
2980
+ tokenProvider: (forceRefresh) => this.getJwtToken(forceRefresh),
2946
2981
  ...options,
2947
2982
  // Only forward debug when the client actually has a logger, so we never
2948
2983
  // hand the realtime layer an explicit `debug: undefined`. The WS/SSE
@@ -2952,23 +2987,59 @@ var SpooledClient = class _SpooledClient {
2952
2987
  });
2953
2988
  }
2954
2989
  /**
2955
- * Get or acquire a JWT token for realtime connections
2990
+ * Get or acquire a JWT token for realtime connections.
2991
+ *
2992
+ * The realtime layer calls this on every (re)connect. We cache the JWT and
2993
+ * reuse it until it nears expiry so a reconnect storm doesn't hammer
2994
+ * /auth/login and trip its rate limit. A fresh login happens only when the
2995
+ * cached token is absent, within ~60s of its `exp`, or a refresh is forced.
2996
+ *
2997
+ * @param forceRefresh Bypass the cache and mint a new token. Set by the
2998
+ * transport when the server rejected the current token (e.g. a 401 on the
2999
+ * WebSocket upgrade), so a stale/revoked token is replaced without waiting
3000
+ * for it to expire.
2956
3001
  */
2957
- async getJwtToken() {
3002
+ async getJwtToken(forceRefresh = false) {
2958
3003
  if (this.config.accessToken) {
2959
- if (this.shouldRefreshToken()) {
3004
+ if (forceRefresh || this.shouldRefreshToken()) {
2960
3005
  return this.refreshAccessToken();
2961
3006
  }
2962
3007
  return this.config.accessToken;
2963
3008
  }
2964
3009
  if (this.config.apiKey) {
3010
+ if (forceRefresh) {
3011
+ this.cachedJwt = null;
3012
+ }
3013
+ if (this.cachedJwt && !isJwtNearExpiry(this.cachedJwt)) {
3014
+ return this.cachedJwt;
3015
+ }
3016
+ return this.loginForJwt();
3017
+ }
3018
+ throw new AuthenticationError("No authentication method available for realtime connection");
3019
+ }
3020
+ /**
3021
+ * Exchange the API key for a JWT via /auth/login and cache the result.
3022
+ *
3023
+ * Concurrent callers share a single in-flight login so a burst of reconnects
3024
+ * (e.g. WebSocket and SSE at once) issues just one request.
3025
+ */
3026
+ async loginForJwt() {
3027
+ if (this.jwtLoginPromise) {
3028
+ return this.jwtLoginPromise;
3029
+ }
3030
+ this.jwtLoginPromise = (async () => {
2965
3031
  const response = await this.auth.login({ apiKey: this.config.apiKey });
2966
3032
  this.http.setAuthToken(response.accessToken);
2967
3033
  this.tokenExpiresAt = Date.now() + response.expiresIn * 1e3;
2968
3034
  this.config.refreshToken = response.refreshToken;
3035
+ this.cachedJwt = response.accessToken;
2969
3036
  return response.accessToken;
3037
+ })();
3038
+ try {
3039
+ return await this.jwtLoginPromise;
3040
+ } finally {
3041
+ this.jwtLoginPromise = null;
2970
3042
  }
2971
- throw new AuthenticationError("No authentication method available for realtime connection");
2972
3043
  }
2973
3044
  /**
2974
3045
  * Check if token should be refreshed
@@ -3069,6 +3140,34 @@ var SpooledClient = class _SpooledClient {
3069
3140
  function createClient(options) {
3070
3141
  return new SpooledClient(options);
3071
3142
  }
3143
+ function decodeJwtExp(token) {
3144
+ const parts = token.split(".");
3145
+ if (parts.length < 2) {
3146
+ return null;
3147
+ }
3148
+ try {
3149
+ const payload = JSON.parse(base64UrlDecode(parts[1]));
3150
+ return typeof payload.exp === "number" ? payload.exp : null;
3151
+ } catch {
3152
+ return null;
3153
+ }
3154
+ }
3155
+ function isJwtNearExpiry(token, skewMs = 6e4) {
3156
+ const exp = decodeJwtExp(token);
3157
+ if (exp === null) {
3158
+ return true;
3159
+ }
3160
+ return Date.now() >= exp * 1e3 - skewMs;
3161
+ }
3162
+ function base64UrlDecode(segment) {
3163
+ const b64 = segment.replace(/-/g, "+").replace(/_/g, "/");
3164
+ if (typeof globalThis.Buffer !== "undefined") {
3165
+ return globalThis.Buffer.from(b64, "base64").toString("utf8");
3166
+ }
3167
+ const binary = globalThis.atob(b64);
3168
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
3169
+ return new globalThis.TextDecoder().decode(bytes);
3170
+ }
3072
3171
 
3073
3172
  // src/types/common.ts
3074
3173
  function createPaginatedResponse(items, limit, offset = 0, total) {