@hatchet-dev/typescript-sdk 1.15.2 → 1.16.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.
Files changed (136) hide show
  1. package/clients/admin/admin-client.js +8 -9
  2. package/clients/dispatcher/action-listener.js +42 -6
  3. package/clients/dispatcher/dispatcher-client.js +5 -8
  4. package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
  5. package/clients/event/event-client.d.ts +2 -2
  6. package/clients/event/event-client.js +5 -11
  7. package/clients/hatchet-client/hatchet-logger.js +8 -17
  8. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +10 -8
  9. package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
  10. package/clients/listeners/run-listener/child-listener-client.js +34 -30
  11. package/clients/listeners/run-listener/pooled-child-listener-client.js +8 -5
  12. package/clients/rest/generated/Api.d.ts +21 -1
  13. package/clients/rest/generated/Api.js +20 -0
  14. package/clients/rest/generated/data-contracts.d.ts +46 -1
  15. package/clients/rest/generated/data-contracts.js +4 -0
  16. package/legacy/examples/affinity-workers.js +0 -1
  17. package/legacy/examples/byo-logger.js +0 -2
  18. package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
  19. package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
  20. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
  21. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
  22. package/legacy/examples/example-event.js +0 -3
  23. package/legacy/examples/logger.js +0 -1
  24. package/legacy/examples/sticky-worker-with-check.js +0 -1
  25. package/legacy/examples/sticky-worker.js +0 -1
  26. package/legacy/legacy-client.js +1 -1
  27. package/legacy/legacy-transformer.js +2 -4
  28. package/legacy/step.d.ts +14 -14
  29. package/legacy/step.js +5 -15
  30. package/legacy/workflow.d.ts +56 -56
  31. package/package.json +20 -29
  32. package/util/abort-error.d.ts +5 -1
  33. package/util/abort-error.js +15 -5
  34. package/util/config-loader/config-loader.js +4 -3
  35. package/util/config-loader/token.js +9 -2
  36. package/util/errors/hatchet-error.d.ts +9 -1
  37. package/util/errors/hatchet-error.js +23 -2
  38. package/util/grpc-error.d.ts +9 -0
  39. package/util/grpc-error.js +25 -0
  40. package/util/hatchet-promise/hatchet-promise.d.ts +5 -1
  41. package/util/hatchet-promise/hatchet-promise.js +6 -1
  42. package/util/logger/logger.js +0 -1
  43. package/util/parse.d.ts +1 -1
  44. package/util/parse.js +4 -2
  45. package/util/retrier.js +2 -3
  46. package/util/workflow-run-ref.js +5 -3
  47. package/v1/client/admin.js +2 -6
  48. package/v1/client/client.d.ts +7 -11
  49. package/v1/client/client.interface.d.ts +5 -8
  50. package/v1/client/client.js +33 -39
  51. package/v1/client/features/cel.js +1 -1
  52. package/v1/client/features/crons.js +2 -2
  53. package/v1/client/features/index.d.ts +5 -0
  54. package/v1/client/features/index.js +5 -0
  55. package/v1/client/features/logs.d.ts +37 -0
  56. package/v1/client/features/logs.js +46 -0
  57. package/v1/client/features/runs.js +0 -1
  58. package/v1/client/features/schedules.js +4 -4
  59. package/v1/client/features/webhooks.js +4 -2
  60. package/v1/client/features/workflows.js +1 -1
  61. package/v1/client/worker/context.js +10 -23
  62. package/v1/client/worker/deprecated/deprecation.js +8 -4
  63. package/v1/client/worker/deprecated/legacy-worker.js +2 -2
  64. package/v1/client/worker/health-server.js +3 -3
  65. package/v1/client/worker/slot-utils.js +0 -3
  66. package/v1/client/worker/worker-internal.js +39 -10
  67. package/v1/client/worker/worker.js +2 -1
  68. package/v1/conditions/base.js +0 -1
  69. package/v1/conditions/index.js +2 -4
  70. package/v1/declaration.d.ts +1 -1
  71. package/v1/declaration.js +12 -7
  72. package/v1/examples/__e2e__/harness.js +4 -3
  73. package/v1/examples/affinity/affinity-workers.js +0 -1
  74. package/v1/examples/bulk_operations/workflow.js +0 -1
  75. package/v1/examples/cancellation/run.js +0 -1
  76. package/v1/examples/cancellations/run.js +0 -1
  77. package/v1/examples/child_workflows/run.js +0 -2
  78. package/v1/examples/child_workflows/workflow.js +0 -1
  79. package/v1/examples/concurrency-rr/load.js +0 -1
  80. package/v1/examples/concurrency-rr/run.js +0 -3
  81. package/v1/examples/concurrency_limit_rr/load.js +0 -1
  82. package/v1/examples/concurrency_limit_rr/run.js +0 -3
  83. package/v1/examples/conditions/event.js +0 -1
  84. package/v1/examples/conditions/run.js +0 -1
  85. package/v1/examples/dag/run.js +0 -1
  86. package/v1/examples/dag_match_condition/event.js +0 -1
  87. package/v1/examples/dag_match_condition/run.js +0 -1
  88. package/v1/examples/deep/run.js +0 -2
  89. package/v1/examples/durable/workflow.js +2 -3
  90. package/v1/examples/durable-event/event.js +0 -1
  91. package/v1/examples/durable-event/run.js +0 -2
  92. package/v1/examples/durable-sleep/event.js +0 -1
  93. package/v1/examples/durable-sleep/run.js +0 -2
  94. package/v1/examples/durable_event/event.js +0 -1
  95. package/v1/examples/durable_event/run.js +0 -2
  96. package/v1/examples/durable_sleep/event.js +0 -1
  97. package/v1/examples/durable_sleep/run.js +0 -2
  98. package/v1/examples/events/event.js +0 -1
  99. package/v1/examples/high-memory/run.js +0 -1
  100. package/v1/examples/inferred-typing/run.js +0 -1
  101. package/v1/examples/landing_page/durable-excution.js +0 -1
  102. package/v1/examples/landing_page/queues.js +0 -1
  103. package/v1/examples/legacy/run.js +0 -1
  104. package/v1/examples/logger/byo-logger.js +0 -2
  105. package/v1/examples/logger/logger.js +0 -1
  106. package/v1/examples/logging/byo-logger.js +0 -2
  107. package/v1/examples/logging/logger.js +0 -1
  108. package/v1/examples/middleware/recipes.js +3 -1
  109. package/v1/examples/migration-guides/mergent.js +2 -1
  110. package/v1/examples/multiple_wf_concurrency/run.js +0 -3
  111. package/v1/examples/non_retryable/run.js +0 -1
  112. package/v1/examples/on_event/event.js +0 -1
  113. package/v1/examples/on_failure/run.js +0 -1
  114. package/v1/examples/on_failure/workflow.js +0 -1
  115. package/v1/examples/on_success/run.js +0 -1
  116. package/v1/examples/on_success/workflow.js +0 -1
  117. package/v1/examples/priority/run.js +0 -1
  118. package/v1/examples/priority/workflow.js +0 -1
  119. package/v1/examples/retries/run.js +0 -1
  120. package/v1/examples/retries/workflow.js +0 -1
  121. package/v1/examples/simple/bulk.js +0 -1
  122. package/v1/examples/simple/cron.js +0 -2
  123. package/v1/examples/simple/delay.js +0 -1
  124. package/v1/examples/simple/enqueue.js +0 -2
  125. package/v1/examples/simple/run.js +0 -1
  126. package/v1/examples/simple/schedule.js +0 -1
  127. package/v1/examples/simple/workflow-with-child.js +10 -4
  128. package/v1/examples/sticky/run.js +0 -1
  129. package/v1/examples/sticky/workflow.js +0 -1
  130. package/v1/examples/streaming/nextjs-proxy.js +0 -1
  131. package/v1/examples/streaming/run.js +0 -1
  132. package/v1/examples/timeout/run.js +0 -1
  133. package/v1/examples/timeouts/run.js +0 -1
  134. package/v1/slot-types.js +0 -1
  135. package/version.d.ts +1 -1
  136. package/version.js +1 -1
@@ -17,16 +17,16 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
17
17
  units: string | number;
18
18
  key?: string | undefined;
19
19
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
20
+ limit?: string | number | undefined;
20
21
  staticKey?: string | undefined;
21
22
  dynamicKey?: string | undefined;
22
- limit?: string | number | undefined;
23
23
  }, {
24
24
  units: string | number;
25
25
  key?: string | undefined;
26
26
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
27
+ limit?: string | number | undefined;
27
28
  staticKey?: string | undefined;
28
29
  dynamicKey?: string | undefined;
29
- limit?: string | number | undefined;
30
30
  }>, "many">>;
31
31
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
32
32
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -59,13 +59,17 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
59
59
  timeout?: string | undefined;
60
60
  parents?: string[] | undefined;
61
61
  retries?: number | undefined;
62
+ backoff?: {
63
+ factor?: number | undefined;
64
+ maxSeconds?: number | undefined;
65
+ } | undefined;
62
66
  rate_limits?: {
63
67
  units: string | number;
64
68
  key?: string | undefined;
65
69
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
70
+ limit?: string | number | undefined;
66
71
  staticKey?: string | undefined;
67
72
  dynamicKey?: string | undefined;
68
- limit?: string | number | undefined;
69
73
  }[] | undefined;
70
74
  worker_labels?: Record<string, string | number | {
71
75
  value: string | number;
@@ -73,22 +77,22 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
73
77
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
74
78
  weight?: number | undefined;
75
79
  } | undefined> | undefined;
76
- backoff?: {
77
- factor?: number | undefined;
78
- maxSeconds?: number | undefined;
79
- } | undefined;
80
80
  }, {
81
81
  name: string;
82
82
  timeout?: string | undefined;
83
83
  parents?: string[] | undefined;
84
84
  retries?: number | undefined;
85
+ backoff?: {
86
+ factor?: number | undefined;
87
+ maxSeconds?: number | undefined;
88
+ } | undefined;
85
89
  rate_limits?: {
86
90
  units: string | number;
87
91
  key?: string | undefined;
88
92
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
93
+ limit?: string | number | undefined;
89
94
  staticKey?: string | undefined;
90
95
  dynamicKey?: string | undefined;
91
- limit?: string | number | undefined;
92
96
  }[] | undefined;
93
97
  worker_labels?: Record<string, string | number | {
94
98
  value: string | number;
@@ -96,10 +100,6 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
96
100
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
97
101
  weight?: number | undefined;
98
102
  } | undefined> | undefined;
99
- backoff?: {
100
- factor?: number | undefined;
101
- maxSeconds?: number | undefined;
102
- } | undefined;
103
103
  }>, "many">;
104
104
  export type Steps = z.infer<typeof StepsSchema>;
105
105
  export declare const ConcurrencyLimitStrategy: typeof PbConcurrencyLimitStrategy;
@@ -166,16 +166,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
166
166
  units: string | number;
167
167
  key?: string | undefined;
168
168
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
169
+ limit?: string | number | undefined;
169
170
  staticKey?: string | undefined;
170
171
  dynamicKey?: string | undefined;
171
- limit?: string | number | undefined;
172
172
  }, {
173
173
  units: string | number;
174
174
  key?: string | undefined;
175
175
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
176
+ limit?: string | number | undefined;
176
177
  staticKey?: string | undefined;
177
178
  dynamicKey?: string | undefined;
178
- limit?: string | number | undefined;
179
179
  }>, "many">>;
180
180
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
181
181
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -208,13 +208,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
208
208
  timeout?: string | undefined;
209
209
  parents?: string[] | undefined;
210
210
  retries?: number | undefined;
211
+ backoff?: {
212
+ factor?: number | undefined;
213
+ maxSeconds?: number | undefined;
214
+ } | undefined;
211
215
  rate_limits?: {
212
216
  units: string | number;
213
217
  key?: string | undefined;
214
218
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
219
+ limit?: string | number | undefined;
215
220
  staticKey?: string | undefined;
216
221
  dynamicKey?: string | undefined;
217
- limit?: string | number | undefined;
218
222
  }[] | undefined;
219
223
  worker_labels?: Record<string, string | number | {
220
224
  value: string | number;
@@ -222,22 +226,22 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
222
226
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
223
227
  weight?: number | undefined;
224
228
  } | undefined> | undefined;
225
- backoff?: {
226
- factor?: number | undefined;
227
- maxSeconds?: number | undefined;
228
- } | undefined;
229
229
  }, {
230
230
  name: string;
231
231
  timeout?: string | undefined;
232
232
  parents?: string[] | undefined;
233
233
  retries?: number | undefined;
234
+ backoff?: {
235
+ factor?: number | undefined;
236
+ maxSeconds?: number | undefined;
237
+ } | undefined;
234
238
  rate_limits?: {
235
239
  units: string | number;
236
240
  key?: string | undefined;
237
241
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
242
+ limit?: string | number | undefined;
238
243
  staticKey?: string | undefined;
239
244
  dynamicKey?: string | undefined;
240
- limit?: string | number | undefined;
241
245
  }[] | undefined;
242
246
  worker_labels?: Record<string, string | number | {
243
247
  value: string | number;
@@ -245,10 +249,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
245
249
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
246
250
  weight?: number | undefined;
247
251
  } | undefined> | undefined;
248
- backoff?: {
249
- factor?: number | undefined;
250
- maxSeconds?: number | undefined;
251
- } | undefined;
252
252
  }>, "many">;
253
253
  onFailure: z.ZodOptional<z.ZodObject<{
254
254
  name: z.ZodString;
@@ -266,16 +266,16 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
266
266
  units: string | number;
267
267
  key?: string | undefined;
268
268
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
269
+ limit?: string | number | undefined;
269
270
  staticKey?: string | undefined;
270
271
  dynamicKey?: string | undefined;
271
- limit?: string | number | undefined;
272
272
  }, {
273
273
  units: string | number;
274
274
  key?: string | undefined;
275
275
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
276
+ limit?: string | number | undefined;
276
277
  staticKey?: string | undefined;
277
278
  dynamicKey?: string | undefined;
278
- limit?: string | number | undefined;
279
279
  }>, "many">>;
280
280
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
281
281
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -308,13 +308,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
308
308
  timeout?: string | undefined;
309
309
  parents?: string[] | undefined;
310
310
  retries?: number | undefined;
311
+ backoff?: {
312
+ factor?: number | undefined;
313
+ maxSeconds?: number | undefined;
314
+ } | undefined;
311
315
  rate_limits?: {
312
316
  units: string | number;
313
317
  key?: string | undefined;
314
318
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
319
+ limit?: string | number | undefined;
315
320
  staticKey?: string | undefined;
316
321
  dynamicKey?: string | undefined;
317
- limit?: string | number | undefined;
318
322
  }[] | undefined;
319
323
  worker_labels?: Record<string, string | number | {
320
324
  value: string | number;
@@ -322,22 +326,22 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
322
326
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
323
327
  weight?: number | undefined;
324
328
  } | undefined> | undefined;
325
- backoff?: {
326
- factor?: number | undefined;
327
- maxSeconds?: number | undefined;
328
- } | undefined;
329
329
  }, {
330
330
  name: string;
331
331
  timeout?: string | undefined;
332
332
  parents?: string[] | undefined;
333
333
  retries?: number | undefined;
334
+ backoff?: {
335
+ factor?: number | undefined;
336
+ maxSeconds?: number | undefined;
337
+ } | undefined;
334
338
  rate_limits?: {
335
339
  units: string | number;
336
340
  key?: string | undefined;
337
341
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
342
+ limit?: string | number | undefined;
338
343
  staticKey?: string | undefined;
339
344
  dynamicKey?: string | undefined;
340
- limit?: string | number | undefined;
341
345
  }[] | undefined;
342
346
  worker_labels?: Record<string, string | number | {
343
347
  value: string | number;
@@ -345,10 +349,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
345
349
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
346
350
  weight?: number | undefined;
347
351
  } | undefined> | undefined;
348
- backoff?: {
349
- factor?: number | undefined;
350
- maxSeconds?: number | undefined;
351
- } | undefined;
352
352
  }>>;
353
353
  }, "strip", z.ZodTypeAny, {
354
354
  description: string;
@@ -358,13 +358,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
358
358
  timeout?: string | undefined;
359
359
  parents?: string[] | undefined;
360
360
  retries?: number | undefined;
361
+ backoff?: {
362
+ factor?: number | undefined;
363
+ maxSeconds?: number | undefined;
364
+ } | undefined;
361
365
  rate_limits?: {
362
366
  units: string | number;
363
367
  key?: string | undefined;
364
368
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
369
+ limit?: string | number | undefined;
365
370
  staticKey?: string | undefined;
366
371
  dynamicKey?: string | undefined;
367
- limit?: string | number | undefined;
368
372
  }[] | undefined;
369
373
  worker_labels?: Record<string, string | number | {
370
374
  value: string | number;
@@ -372,10 +376,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
372
376
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
373
377
  weight?: number | undefined;
374
378
  } | undefined> | undefined;
375
- backoff?: {
376
- factor?: number | undefined;
377
- maxSeconds?: number | undefined;
378
- } | undefined;
379
379
  }[];
380
380
  version?: string | undefined;
381
381
  timeout?: string | undefined;
@@ -393,13 +393,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
393
393
  timeout?: string | undefined;
394
394
  parents?: string[] | undefined;
395
395
  retries?: number | undefined;
396
+ backoff?: {
397
+ factor?: number | undefined;
398
+ maxSeconds?: number | undefined;
399
+ } | undefined;
396
400
  rate_limits?: {
397
401
  units: string | number;
398
402
  key?: string | undefined;
399
403
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
404
+ limit?: string | number | undefined;
400
405
  staticKey?: string | undefined;
401
406
  dynamicKey?: string | undefined;
402
- limit?: string | number | undefined;
403
407
  }[] | undefined;
404
408
  worker_labels?: Record<string, string | number | {
405
409
  value: string | number;
@@ -407,10 +411,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
407
411
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
408
412
  weight?: number | undefined;
409
413
  } | undefined> | undefined;
410
- backoff?: {
411
- factor?: number | undefined;
412
- maxSeconds?: number | undefined;
413
- } | undefined;
414
414
  } | undefined;
415
415
  }, {
416
416
  description: string;
@@ -420,13 +420,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
420
420
  timeout?: string | undefined;
421
421
  parents?: string[] | undefined;
422
422
  retries?: number | undefined;
423
+ backoff?: {
424
+ factor?: number | undefined;
425
+ maxSeconds?: number | undefined;
426
+ } | undefined;
423
427
  rate_limits?: {
424
428
  units: string | number;
425
429
  key?: string | undefined;
426
430
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
431
+ limit?: string | number | undefined;
427
432
  staticKey?: string | undefined;
428
433
  dynamicKey?: string | undefined;
429
- limit?: string | number | undefined;
430
434
  }[] | undefined;
431
435
  worker_labels?: Record<string, string | number | {
432
436
  value: string | number;
@@ -434,10 +438,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
434
438
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
435
439
  weight?: number | undefined;
436
440
  } | undefined> | undefined;
437
- backoff?: {
438
- factor?: number | undefined;
439
- maxSeconds?: number | undefined;
440
- } | undefined;
441
441
  }[];
442
442
  version?: string | undefined;
443
443
  timeout?: string | undefined;
@@ -455,13 +455,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
455
455
  timeout?: string | undefined;
456
456
  parents?: string[] | undefined;
457
457
  retries?: number | undefined;
458
+ backoff?: {
459
+ factor?: number | undefined;
460
+ maxSeconds?: number | undefined;
461
+ } | undefined;
458
462
  rate_limits?: {
459
463
  units: string | number;
460
464
  key?: string | undefined;
461
465
  duration?: import("../protoc/workflows").RateLimitDuration | undefined;
466
+ limit?: string | number | undefined;
462
467
  staticKey?: string | undefined;
463
468
  dynamicKey?: string | undefined;
464
- limit?: string | number | undefined;
465
469
  }[] | undefined;
466
470
  worker_labels?: Record<string, string | number | {
467
471
  value: string | number;
@@ -469,10 +473,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
469
473
  comparator?: import("../protoc/workflows").WorkerLabelComparator | undefined;
470
474
  weight?: number | undefined;
471
475
  } | undefined> | undefined;
472
- backoff?: {
473
- factor?: number | undefined;
474
- maxSeconds?: number | undefined;
475
- } | undefined;
476
476
  } | undefined;
477
477
  }>;
478
478
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.15.2",
3
+ "version": "1.16.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -19,53 +19,44 @@
19
19
  "author": "",
20
20
  "license": "MIT",
21
21
  "devDependencies": {
22
- "@tsd/typescript": "^5.8.2",
22
+ "@eslint/js": "^10.0.1",
23
+ "@tsd/typescript": "^5.9.3",
23
24
  "@types/jest": "^29.5.14",
24
25
  "@types/node": "^22.13.14",
25
- "@typescript-eslint/eslint-plugin": "^7.0.0",
26
- "@typescript-eslint/parser": "^7.0.0",
27
- "autoprefixer": "^10.4.21",
26
+ "autoprefixer": "^10.4.27",
28
27
  "dotenv-cli": "^7.4.4",
29
- "eslint": "^8.56.0",
30
- "eslint-config-airbnb-typescript": "^18.0.0",
31
- "eslint-config-prettier": "^9.1.0",
32
- "eslint-config-standard": "^17.1.0",
28
+ "eslint": "^10.0.3",
29
+ "eslint-config-prettier": "^10.1.8",
33
30
  "eslint-import-resolver-typescript": "^3.10.0",
34
- "eslint-plugin-import": "^2.31.0",
35
- "eslint-plugin-jest": "^28.11.0",
36
- "eslint-plugin-n": "^16.6.2",
37
- "eslint-plugin-prettier": "^5.2.5",
38
- "eslint-plugin-promise": "^6.6.0",
39
- "eslint-plugin-react": "^7.37.4",
40
- "eslint-plugin-react-hooks": "^4.6.2",
41
- "eslint-plugin-react-refresh": "^0.4.19",
42
- "eslint-plugin-unused-imports": "^4.1.4",
43
- "grpc-tools": "^1.13.0",
31
+ "eslint-plugin-prettier": "^5.5.5",
32
+ "eslint-plugin-unused-imports": "^4.4.1",
33
+ "grpc-tools": "^1.13.1",
44
34
  "jest": "^29.7.0",
45
35
  "jest-tsd": "^0.2.2",
46
36
  "pino": "^9.12.0",
47
- "prettier": "^3.5.3",
37
+ "prettier": "^3.8.1",
48
38
  "resolve-tspaths": "^0.8.23",
49
- "ts-jest": "^29.3.1",
39
+ "ts-jest": "^29.4.6",
50
40
  "ts-node": "^10.9.2",
51
- "ts-proto": "^2.7.0",
41
+ "ts-proto": "^2.11.4",
52
42
  "typedoc": "^0.28.17",
53
- "typedoc-plugin-markdown": "^4.6.0",
43
+ "typedoc-plugin-markdown": "^4.10.0",
54
44
  "typedoc-plugin-no-inherit": "^1.6.1",
55
- "typescript": "^5.8.2"
45
+ "typescript": "^5.8.2",
46
+ "typescript-eslint": "^8.56.1"
56
47
  },
57
48
  "dependencies": {
58
- "@bufbuild/protobuf": "^2.2.5",
59
- "@types/qs": "^6.9.18",
49
+ "@bufbuild/protobuf": "^2.11.0",
50
+ "@types/qs": "^6.15.0",
60
51
  "abort-controller-x": "^0.4.3",
61
52
  "axios": "^1.13.5",
62
53
  "long": "^5.3.1",
63
- "nice-grpc": "^2.1.12",
54
+ "nice-grpc": "^2.1.14",
64
55
  "nice-grpc-common": "^2.0.2",
65
56
  "protobufjs": "^7.4.0",
66
57
  "qs": "^6.14.2",
67
- "semver": "^7.7.1",
68
- "yaml": "^2.7.1",
58
+ "semver": "^7.7.4",
59
+ "yaml": "^2.8.2",
69
60
  "zod": "^3.24.2",
70
61
  "zod-to-json-schema": "^3.24.1"
71
62
  },
@@ -1,4 +1,8 @@
1
- export declare function createAbortError(message?: string): Error;
1
+ export declare class AbortError extends Error {
2
+ readonly code = "ABORT_ERR";
3
+ constructor(message?: string);
4
+ }
5
+ export declare function createAbortError(message?: string): AbortError;
2
6
  export declare function isAbortError(err: unknown): err is Error;
3
7
  /**
4
8
  * Helper to be used inside broad `catch` blocks so cancellation isn't accidentally swallowed.
@@ -1,17 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbortError = void 0;
3
4
  exports.createAbortError = createAbortError;
4
5
  exports.isAbortError = isAbortError;
5
6
  exports.rethrowIfAborted = rethrowIfAborted;
6
7
  exports.throwIfAborted = throwIfAborted;
8
+ class AbortError extends Error {
9
+ constructor(message = 'Operation aborted') {
10
+ super(message);
11
+ this.code = 'ABORT_ERR';
12
+ this.name = 'AbortError';
13
+ }
14
+ }
15
+ exports.AbortError = AbortError;
7
16
  function createAbortError(message = 'Operation aborted') {
8
- const err = new Error(message);
9
- err.name = 'AbortError';
10
- err.code = 'ABORT_ERR';
11
- return err;
17
+ return new AbortError(message);
12
18
  }
13
19
  function isAbortError(err) {
14
- return err instanceof Error && (err.name === 'AbortError' || err.code === 'ABORT_ERR');
20
+ if (err instanceof AbortError) {
21
+ return true;
22
+ }
23
+ return (err instanceof Error &&
24
+ (err.name === 'AbortError' || err.code === 'ABORT_ERR'));
15
25
  }
16
26
  /**
17
27
  * Helper to be used inside broad `catch` blocks so cancellation isn't accidentally swallowed.
@@ -74,7 +74,7 @@ class ConfigLoader {
74
74
  apiUrl =
75
75
  (_x = (_w = (_v = override === null || override === void 0 ? void 0 : override.api_url) !== null && _v !== void 0 ? _v : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _w !== void 0 ? _w : this.env('HATCHET_CLIENT_API_URL')) !== null && _x !== void 0 ? _x : addresses.serverUrl;
76
76
  }
77
- catch (e) {
77
+ catch (_9) {
78
78
  grpcBroadcastAddress =
79
79
  (_z = (_y = override === null || override === void 0 ? void 0 : override.host_port) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_HOST_PORT');
80
80
  apiUrl = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.api_url) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_API_URL');
@@ -119,10 +119,11 @@ class ConfigLoader {
119
119
  return config;
120
120
  }
121
121
  catch (e) {
122
- if (!path)
122
+ if (!path) {
123
123
  return undefined;
124
+ }
124
125
  if (e instanceof zod_1.z.ZodError) {
125
- throw new Error(`Invalid yaml config: ${e.message}`);
126
+ throw new Error(`Invalid yaml config: ${e.message}`, { cause: e });
126
127
  }
127
128
  throw e;
128
129
  }
@@ -2,12 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTenantIdFromJWT = getTenantIdFromJWT;
4
4
  exports.getAddressesFromJWT = getAddressesFromJWT;
5
+ const parse_1 = require("../parse");
5
6
  function getTenantIdFromJWT(token) {
6
7
  const claims = extractClaimsFromJWT(token);
8
+ if (claims.sub === undefined) {
9
+ throw new Error('Invalid token: missing sub');
10
+ }
7
11
  return claims.sub;
8
12
  }
9
13
  function getAddressesFromJWT(token) {
10
14
  const claims = extractClaimsFromJWT(token);
15
+ if (claims.server_url === undefined || claims.grpc_broadcast_address === undefined) {
16
+ throw new Error('Invalid token: missing server_url or grpc_broadcast_address');
17
+ }
11
18
  return {
12
19
  serverUrl: claims.server_url,
13
20
  grpcBroadcastAddress: claims.grpc_broadcast_address,
@@ -18,8 +25,8 @@ function extractClaimsFromJWT(token) {
18
25
  if (parts.length !== 3) {
19
26
  throw new Error('Invalid token format');
20
27
  }
21
- const claimsPart = parts[1];
28
+ const [_, claimsPart] = parts;
22
29
  const claimsData = atob(claimsPart.replace(/-/g, '+').replace(/_/g, '/'));
23
- const claims = JSON.parse(claimsData);
30
+ const claims = (0, parse_1.parseJSON)(claimsData);
24
31
  return claims;
25
32
  }
@@ -1,4 +1,12 @@
1
+ /** Returns a string message from an unknown value (e.g. from a catch block). */
2
+ export declare function getErrorMessage(e: unknown): string;
1
3
  declare class HatchetError extends Error {
2
- constructor(message: string);
4
+ constructor(message: string, options?: {
5
+ cause?: unknown;
6
+ });
3
7
  }
8
+ export declare function toHatchetError(e: unknown, defaultMessageOrOptions?: string | {
9
+ defaultMessage?: string;
10
+ prefix?: string;
11
+ }): HatchetError;
4
12
  export default HatchetError;
@@ -1,9 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorMessage = getErrorMessage;
4
+ exports.toHatchetError = toHatchetError;
5
+ /** Returns a string message from an unknown value (e.g. from a catch block). */
6
+ function getErrorMessage(e) {
7
+ return e instanceof Error ? e.message : String(e);
8
+ }
3
9
  class HatchetError extends Error {
4
- constructor(message) {
5
- super(message);
10
+ constructor(message, options) {
11
+ super(message, options);
6
12
  this.name = 'HatchetError';
7
13
  }
8
14
  }
15
+ function toHatchetError(e, defaultMessageOrOptions = 'An error occurred') {
16
+ var _a;
17
+ if (e instanceof HatchetError) {
18
+ return e;
19
+ }
20
+ const opts = typeof defaultMessageOrOptions === 'string'
21
+ ? { defaultMessage: defaultMessageOrOptions }
22
+ : defaultMessageOrOptions;
23
+ const defaultMessage = (_a = opts.defaultMessage) !== null && _a !== void 0 ? _a : 'An error occurred';
24
+ let message = getErrorMessage(e) || defaultMessage;
25
+ if (opts.prefix) {
26
+ message = opts.prefix + message;
27
+ }
28
+ return new HatchetError(message, { cause: e });
29
+ }
9
30
  exports.default = HatchetError;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns the gRPC status code from an unknown value (e.g. from a catch block).
3
+ * Used for checking Status.CANCELLED, Status.UNAVAILABLE, etc.
4
+ */
5
+ export declare function getGrpcErrorCode(e: unknown): number | undefined;
6
+ /**
7
+ * Returns the gRPC error details string from an unknown value (e.g. from a catch block).
8
+ */
9
+ export declare function getGrpcErrorDetails(e: unknown): string | undefined;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGrpcErrorCode = getGrpcErrorCode;
4
+ exports.getGrpcErrorDetails = getGrpcErrorDetails;
5
+ /**
6
+ * Returns the gRPC status code from an unknown value (e.g. from a catch block).
7
+ * Used for checking Status.CANCELLED, Status.UNAVAILABLE, etc.
8
+ */
9
+ function getGrpcErrorCode(e) {
10
+ if (e != null && typeof e === 'object' && 'code' in e) {
11
+ const { code } = e;
12
+ return typeof code === 'number' ? code : undefined;
13
+ }
14
+ return undefined;
15
+ }
16
+ /**
17
+ * Returns the gRPC error details string from an unknown value (e.g. from a catch block).
18
+ */
19
+ function getGrpcErrorDetails(e) {
20
+ if (e != null && typeof e === 'object' && 'details' in e) {
21
+ const { details } = e;
22
+ return typeof details === 'string' ? details : undefined;
23
+ }
24
+ return undefined;
25
+ }
@@ -1,5 +1,9 @@
1
+ /** Canonical reasons when cancelling a HatchetPromise (e.g. worker shutdown). */
2
+ export declare enum CancellationReason {
3
+ CANCELLED_BY_WORKER = "Cancelled by worker"
4
+ }
1
5
  declare class HatchetPromise<T> {
2
- cancel: (reason?: any) => void;
6
+ cancel: (reason?: CancellationReason) => void;
3
7
  promise: Promise<T>;
4
8
  /**
5
9
  * The original (non-cancelable) promise passed to the constructor.
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CancellationReason = void 0;
4
+ /** Canonical reasons when cancelling a HatchetPromise (e.g. worker shutdown). */
5
+ var CancellationReason;
6
+ (function (CancellationReason) {
7
+ CancellationReason["CANCELLED_BY_WORKER"] = "Cancelled by worker";
8
+ })(CancellationReason || (exports.CancellationReason = CancellationReason = {}));
3
9
  class HatchetPromise {
4
10
  constructor(promise) {
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
11
  this.cancel = (_reason) => { };
7
12
  this.inner = Promise.resolve(promise);
8
13
  this.promise = new Promise((resolve, reject) => {
@@ -4,7 +4,6 @@ exports.LogLevelEnum = exports.Logger = void 0;
4
4
  class Logger {
5
5
  }
6
6
  exports.Logger = Logger;
7
- // eslint-disable-next-line no-shadow
8
7
  var LogLevelEnum;
9
8
  (function (LogLevelEnum) {
10
9
  LogLevelEnum[LogLevelEnum["OFF"] = -1] = "OFF";
package/util/parse.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function parseJSON(json: string): any;
1
+ export declare function parseJSON<T = any>(json: string): T;