@hatchet-dev/typescript-sdk 1.6.2 → 1.7.1

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 (50) hide show
  1. package/clients/admin/admin-client.d.ts +1 -0
  2. package/clients/admin/admin-client.js +5 -11
  3. package/clients/event/event-client.js +3 -4
  4. package/clients/hatchet-client/hatchet-client.d.ts +0 -4
  5. package/clients/hatchet-client/hatchet-client.js +0 -5
  6. package/clients/rest/generated/Api.d.ts +62 -1
  7. package/clients/rest/generated/Api.js +39 -0
  8. package/clients/rest/generated/data-contracts.d.ts +201 -161
  9. package/clients/rest/generated/data-contracts.js +168 -168
  10. package/clients/worker/worker.d.ts +1 -1
  11. package/clients/worker/worker.js +5 -4
  12. package/package.json +2 -2
  13. package/protoc/v1/workflows.d.ts +11 -0
  14. package/protoc/v1/workflows.js +105 -3
  15. package/step.js +3 -2
  16. package/util/apply-namespace.d.ts +1 -0
  17. package/util/apply-namespace.js +9 -0
  18. package/util/config-loader/config-loader.js +5 -2
  19. package/util/uuid.d.ts +1 -0
  20. package/util/uuid.js +7 -0
  21. package/v1/client/admin.js +3 -8
  22. package/v1/client/client.d.ts +20 -5
  23. package/v1/client/client.interface.d.ts +4 -0
  24. package/v1/client/client.js +48 -11
  25. package/{clients/hatchet-client/features/cron-client.d.ts → v1/client/features/crons.d.ts} +13 -19
  26. package/{clients/hatchet-client/features/cron-client.js → v1/client/features/crons.js} +31 -16
  27. package/v1/client/features/filters.d.ts +1 -0
  28. package/v1/client/features/filters.js +6 -0
  29. package/v1/client/features/index.d.ts +2 -0
  30. package/v1/client/features/index.js +2 -0
  31. package/v1/client/features/runs.d.ts +1 -0
  32. package/v1/client/features/runs.js +7 -0
  33. package/{clients/hatchet-client/features/schedule-client.d.ts → v1/client/features/schedules.d.ts} +12 -18
  34. package/{clients/hatchet-client/features/schedule-client.js → v1/client/features/schedules.js} +31 -16
  35. package/v1/client/features/tenant.d.ts +15 -0
  36. package/v1/client/features/tenant.js +31 -0
  37. package/v1/client/features/workflows.d.ts +10 -3
  38. package/v1/client/features/workflows.js +43 -1
  39. package/v1/client/worker/context.js +3 -2
  40. package/v1/client/worker/worker-internal.d.ts +1 -2
  41. package/v1/client/worker/worker-internal.js +11 -5
  42. package/v1/declaration.d.ts +7 -2
  43. package/v1/declaration.js +5 -3
  44. package/v1/examples/cancellations/workflow.js +2 -2
  45. package/v1/examples/on_event/workflow.d.ts +1 -0
  46. package/v1/examples/on_event/workflow.js +27 -1
  47. package/v1/examples/simple/cron.js +1 -1
  48. package/v1/examples/simple/schedule.js +3 -3
  49. package/version.d.ts +1 -1
  50. package/version.js +1 -1
package/step.js CHANGED
@@ -58,6 +58,7 @@ const declaration_1 = require("./v1/declaration");
58
58
  const conditions_1 = require("./v1/conditions");
59
59
  const condition_1 = require("./protoc/v1/shared/condition");
60
60
  const transformer_1 = require("./v1/conditions/transformer");
61
+ const apply_namespace_1 = require("./util/apply-namespace");
61
62
  exports.CreateRateLimitSchema = z.object({
62
63
  key: z.string().optional(),
63
64
  staticKey: z.string().optional(),
@@ -386,7 +387,7 @@ class V0Context {
386
387
  else {
387
388
  workflowName = workflow.id;
388
389
  }
389
- const name = this.v0.config.namespace + workflowName;
390
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v0.config.namespace);
390
391
  const opts = options || {};
391
392
  const { sticky } = opts;
392
393
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -470,7 +471,7 @@ class V0Context {
470
471
  else {
471
472
  workflowName = workflow.id;
472
473
  }
473
- const name = this.v0.config.namespace + workflowName;
474
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v0.config.namespace);
474
475
  const opts = options || {};
475
476
  const { sticky } = opts;
476
477
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -0,0 +1 @@
1
+ export declare function applyNamespace(name: string, namespace?: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyNamespace = applyNamespace;
4
+ function applyNamespace(name, namespace) {
5
+ if (namespace && !name.startsWith(namespace)) {
6
+ return `${namespace}${name}`;
7
+ }
8
+ return name;
9
+ }
@@ -75,7 +75,10 @@ class ConfigLoader {
75
75
  (_x = (_w = override === null || override === void 0 ? void 0 : override.host_port) !== null && _w !== void 0 ? _w : yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _x !== void 0 ? _x : this.env('HATCHET_CLIENT_HOST_PORT');
76
76
  apiUrl = (_z = (_y = override === null || override === void 0 ? void 0 : override.api_url) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_API_URL');
77
77
  }
78
- const namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
78
+ let namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
79
+ if (namespace && !(namespace === null || namespace === void 0 ? void 0 : namespace.endsWith('_'))) {
80
+ namespace = `${namespace}_`;
81
+ }
79
82
  return {
80
83
  token: (_3 = (_2 = override === null || override === void 0 ? void 0 : override.token) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_TOKEN'),
81
84
  host_port: grpcBroadcastAddress,
@@ -83,7 +86,7 @@ class ConfigLoader {
83
86
  tls_config: tlsConfig,
84
87
  log_level: (_6 = (_5 = (_4 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _4 !== void 0 ? _4 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _5 !== void 0 ? _5 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _6 !== void 0 ? _6 : 'INFO',
85
88
  tenant_id: tenantId,
86
- namespace: namespace ? `${namespace}_`.toLowerCase() : '',
89
+ namespace: namespace ? `${namespace}`.toLowerCase() : '',
87
90
  };
88
91
  }
89
92
  static get default_yaml_config_path() {
package/util/uuid.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function isValidUUID(uuid: string): boolean;
package/util/uuid.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidUUID = isValidUUID;
4
+ const zod_1 = require("zod");
5
+ function isValidUUID(uuid) {
6
+ return zod_1.z.string().uuid().safeParse(uuid).success;
7
+ }
@@ -19,6 +19,7 @@ const grpc_helpers_1 = require("../../util/grpc-helpers");
19
19
  const child_listener_client_1 = require("../../clients/listeners/run-listener/child-listener-client");
20
20
  const workflows_1 = require("../../protoc/workflows");
21
21
  const batch_1 = require("../../util/batch");
22
+ const apply_namespace_1 = require("../../util/apply-namespace");
22
23
  class AdminClient {
23
24
  constructor(config, api, runs) {
24
25
  this.config = config;
@@ -38,11 +39,8 @@ class AdminClient {
38
39
  */
39
40
  runWorkflow(workflowName, input, options) {
40
41
  return __awaiter(this, void 0, void 0, function* () {
41
- let computedName = workflowName;
42
42
  try {
43
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
44
- computedName = this.config.namespace + workflowName;
45
- }
43
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
46
44
  const inputStr = JSON.stringify(input);
47
45
  const resp = yield this.grpc.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
48
46
  ? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
@@ -69,10 +67,7 @@ class AdminClient {
69
67
  return __awaiter(this, arguments, void 0, function* (workflowRuns, batchSize = 500) {
70
68
  // Prepare workflows to be triggered in bulk
71
69
  const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
72
- let computedName = workflowName;
73
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
74
- computedName = this.config.namespace + workflowName;
75
- }
70
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
76
71
  const inputStr = JSON.stringify(input);
77
72
  return Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
78
73
  ? JSON.stringify(options.additionalMetadata)
@@ -15,6 +15,9 @@ import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } fro
15
15
  import { RatelimitsClient } from './features';
16
16
  import { AdminClient } from './admin';
17
17
  import { FiltersClient } from './features/filters';
18
+ import { ScheduleClient } from './features/schedules';
19
+ import { CronClient } from './features/crons';
20
+ import { TenantClient } from './features/tenant';
18
21
  /**
19
22
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
20
23
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -124,28 +127,34 @@ export declare class HatchetClient implements IHatchetClient {
124
127
  * @returns A promise that resolves with the workflow result
125
128
  */
126
129
  run<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options?: RunOpts): Promise<O>;
130
+ private _crons;
127
131
  /**
128
132
  * Get the cron client for creating and managing cron workflow runs
129
133
  * @returns A cron client instance
130
134
  */
131
- get crons(): import("../../clients/hatchet-client/features/cron-client").CronClient;
135
+ get crons(): CronClient;
132
136
  /**
133
137
  * Get the cron client for creating and managing cron workflow runs
134
138
  * @returns A cron client instance
135
139
  * @deprecated use client.crons instead
136
140
  */
137
- get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
141
+ get cron(): CronClient;
142
+ private _scheduled;
138
143
  /**
139
144
  * Get the schedules client for creating and managing scheduled workflow runs
140
145
  * @returns A schedules client instance
141
146
  */
142
- get schedules(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
147
+ get scheduled(): ScheduleClient;
143
148
  /**
144
149
  * Get the schedule client for creating and managing scheduled workflow runs
145
150
  * @returns A schedule client instance
146
- * @deprecated use client.schedules instead
151
+ * @deprecated use client.scheduled instead
147
152
  */
148
- get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
153
+ get schedule(): ScheduleClient;
154
+ /**
155
+ * @alias scheduled
156
+ */
157
+ get schedules(): ScheduleClient;
149
158
  /**
150
159
  * Get the event client for creating and managing event workflow runs
151
160
  * @returns A event client instance
@@ -169,6 +178,12 @@ export declare class HatchetClient implements IHatchetClient {
169
178
  * @returns A filters client instance
170
179
  */
171
180
  get filters(): FiltersClient;
181
+ private _tenant;
182
+ /**
183
+ * Get the tenant client for managing tenants
184
+ * @returns A tenant client instance
185
+ */
186
+ get tenant(): TenantClient;
172
187
  private _ratelimits;
173
188
  /**
174
189
  * Get the rate limits client for creating and managing rate limits
@@ -4,11 +4,15 @@ import { RunsClient } from './features/runs';
4
4
  import { WorkersClient } from './features/workers';
5
5
  import { WorkflowsClient } from './features/workflows';
6
6
  import { AdminClient } from './admin';
7
+ import { ScheduleClient } from './features/schedules';
8
+ import { CronClient } from './features/crons';
7
9
  export interface IHatchetClient {
8
10
  _v0: LegacyHatchetClient;
9
11
  metrics: MetricsClient;
10
12
  runs: RunsClient;
11
13
  workflows: WorkflowsClient;
12
14
  workers: WorkersClient;
15
+ scheduled: ScheduleClient;
16
+ crons: CronClient;
13
17
  admin: AdminClient;
14
18
  }
@@ -21,6 +21,7 @@ const rest_1 = __importDefault(require("../../clients/rest"));
21
21
  const config_loader_1 = require("../../util/config-loader");
22
22
  const hatchet_logger_1 = require("../../clients/hatchet-client/hatchet-logger");
23
23
  const zod_1 = require("zod");
24
+ const event_client_1 = require("../../clients/event/event-client");
24
25
  const declaration_1 = require("../declaration");
25
26
  const worker_1 = require("./worker/worker");
26
27
  const metrics_1 = require("./features/metrics");
@@ -30,6 +31,9 @@ const runs_1 = require("./features/runs");
30
31
  const features_1 = require("./features");
31
32
  const admin_1 = require("./admin");
32
33
  const filters_1 = require("./features/filters");
34
+ const schedules_1 = require("./features/schedules");
35
+ const crons_1 = require("./features/crons");
36
+ const tenant_1 = require("./features/tenant");
33
37
  /**
34
38
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
35
39
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -62,12 +66,6 @@ class HatchetClient {
62
66
  logConstructor = hatchet_logger_1.DEFAULT_LOGGER;
63
67
  }
64
68
  const clientConfig = Object.assign(Object.assign({}, valid), { logger: logConstructor });
65
- // FIXME: Remove this once we have a proper namespace validation
66
- if (clientConfig.namespace) {
67
- clientConfig.namespace = clientConfig.namespace.endsWith('_')
68
- ? clientConfig.namespace.slice(0, -1)
69
- : clientConfig.namespace;
70
- }
71
69
  this._config = clientConfig;
72
70
  this.tenantId = clientConfig.tenant_id;
73
71
  this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
@@ -79,6 +77,23 @@ class HatchetClient {
79
77
  }
80
78
  throw e;
81
79
  }
80
+ try {
81
+ this.tenant
82
+ .get()
83
+ .then((tenant) => {
84
+ if (tenant.version !== 'V1') {
85
+ this.config
86
+ .logger('client-init', event_client_1.LogLevel.INFO)
87
+ .warn('🚨⚠️‼️ YOU ARE USING A V0 ENGINE WITH A V1 SDK, WHICH IS NOT SUPPORTED. PLEASE UPGRADE YOUR ENGINE TO V1.🚨⚠️‼️');
88
+ }
89
+ })
90
+ .catch((error) => {
91
+ // Do nothing here
92
+ });
93
+ }
94
+ catch (e) {
95
+ // Do nothing here
96
+ }
82
97
  }
83
98
  /**
84
99
  * Static factory method to create a new Hatchet client instance.
@@ -175,7 +190,10 @@ class HatchetClient {
175
190
  * @returns A cron client instance
176
191
  */
177
192
  get crons() {
178
- return this._v0.cron;
193
+ if (!this._crons) {
194
+ this._crons = new crons_1.CronClient(this);
195
+ }
196
+ return this._crons;
179
197
  }
180
198
  /**
181
199
  * Get the cron client for creating and managing cron workflow runs
@@ -189,16 +207,25 @@ class HatchetClient {
189
207
  * Get the schedules client for creating and managing scheduled workflow runs
190
208
  * @returns A schedules client instance
191
209
  */
192
- get schedules() {
193
- return this._v0.schedule;
210
+ get scheduled() {
211
+ if (!this._scheduled) {
212
+ this._scheduled = new schedules_1.ScheduleClient(this);
213
+ }
214
+ return this._scheduled;
194
215
  }
195
216
  /**
196
217
  * Get the schedule client for creating and managing scheduled workflow runs
197
218
  * @returns A schedule client instance
198
- * @deprecated use client.schedules instead
219
+ * @deprecated use client.scheduled instead
199
220
  */
200
221
  get schedule() {
201
- return this.schedules;
222
+ return this.scheduled;
223
+ }
224
+ /**
225
+ * @alias scheduled
226
+ */
227
+ get schedules() {
228
+ return this.scheduled;
202
229
  }
203
230
  /**
204
231
  * Get the event client for creating and managing event workflow runs
@@ -235,6 +262,16 @@ class HatchetClient {
235
262
  }
236
263
  return this._filters;
237
264
  }
265
+ /**
266
+ * Get the tenant client for managing tenants
267
+ * @returns A tenant client instance
268
+ */
269
+ get tenant() {
270
+ if (!this._tenant) {
271
+ this._tenant = new tenant_1.TenantClient(this);
272
+ }
273
+ return this._tenant;
274
+ }
238
275
  /**
239
276
  * Get the rate limits client for creating and managing rate limits
240
277
  * @returns A rate limits client instance
@@ -1,9 +1,9 @@
1
- import { AdminClient } from '../../admin';
2
- import { Api } from '../../rest';
3
- import { CronWorkflows, CronWorkflowsList } from '../../rest/generated/data-contracts';
1
+ import { CronWorkflows, CronWorkflowsList } from '../../../clients/rest/generated/data-contracts';
4
2
  import { z } from 'zod';
5
3
  import { Workflow } from '../../../workflow';
6
- import { ClientConfig } from '../client-config';
4
+ import { BaseWorkflowDeclaration } from '../..';
5
+ import { HatchetClient } from '../client';
6
+ import { WorkflowsClient } from './workflows';
7
7
  /**
8
8
  * Schema for creating a Cron Trigger.
9
9
  */
@@ -34,19 +34,11 @@ export type CreateCronInput = z.infer<typeof CreateCronTriggerSchema>;
34
34
  * Client for managing Cron Triggers.
35
35
  */
36
36
  export declare class CronClient {
37
- private readonly tenantId;
38
- private readonly config;
39
- private readonly api;
40
- private readonly adminClient;
41
- private logger;
42
- /**
43
- * Initializes a new instance of CronClient.
44
- * @param tenantId - The tenant identifier.
45
- * @param config - Client configuration settings.
46
- * @param api - API instance for REST interactions.
47
- * @param adminClient - Admin client for administrative operations.
48
- */
49
- constructor(tenantId: string, config: ClientConfig, api: Api, adminClient: AdminClient);
37
+ api: HatchetClient['api'];
38
+ tenantId: string;
39
+ workflows: WorkflowsClient;
40
+ namespace: string | undefined;
41
+ constructor(client: HatchetClient);
50
42
  /**
51
43
  * Retrieves the Cron ID from a CronWorkflows object or a string.
52
44
  * @param cron - The CronWorkflows object or Cron ID as a string.
@@ -60,7 +52,7 @@ export declare class CronClient {
60
52
  * @returns A promise that resolves to the created CronWorkflows object.
61
53
  * @throws Will throw an error if the input is invalid or the API call fails.
62
54
  */
63
- create(workflow: string | Workflow, cron: CreateCronInput): Promise<CronWorkflows>;
55
+ create(workflow: string | Workflow | BaseWorkflowDeclaration<any, any>, cron: CreateCronInput): Promise<CronWorkflows>;
64
56
  /**
65
57
  * Deletes an existing Cron Trigger.
66
58
  * @param cron - The Cron Trigger ID as a string or CronWorkflows object.
@@ -72,7 +64,9 @@ export declare class CronClient {
72
64
  * @param query - Query parameters for listing Cron Triggers.
73
65
  * @returns A promise that resolves to a CronWorkflowsList object.
74
66
  */
75
- list(query: Parameters<typeof this.api.cronWorkflowList>[1]): Promise<CronWorkflowsList>;
67
+ list(query: Parameters<typeof this.api.cronWorkflowList>[1] & {
68
+ workflow?: string | Workflow | BaseWorkflowDeclaration<any, any>;
69
+ }): Promise<CronWorkflowsList>;
76
70
  /**
77
71
  * Retrieves a specific Cron Trigger by its ID.
78
72
  * @param cron - The Cron Trigger ID as a string or CronWorkflows object.
@@ -8,10 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.CronClient = exports.CreateCronTriggerSchema = void 0;
13
24
  const zod_1 = require("zod");
14
25
  const axios_1 = require("axios");
26
+ const uuid_1 = require("../../../util/uuid");
27
+ const apply_namespace_1 = require("../../../util/apply-namespace");
28
+ const workflows_1 = require("./workflows");
15
29
  /**
16
30
  * Schema for creating a Cron Trigger.
17
31
  */
@@ -26,19 +40,11 @@ exports.CreateCronTriggerSchema = zod_1.z.object({
26
40
  * Client for managing Cron Triggers.
27
41
  */
28
42
  class CronClient {
29
- /**
30
- * Initializes a new instance of CronClient.
31
- * @param tenantId - The tenant identifier.
32
- * @param config - Client configuration settings.
33
- * @param api - API instance for REST interactions.
34
- * @param adminClient - Admin client for administrative operations.
35
- */
36
- constructor(tenantId, config, api, adminClient) {
37
- this.tenantId = tenantId;
38
- this.config = config;
39
- this.api = api;
40
- this.adminClient = adminClient;
41
- this.logger = config.logger('Cron', this.config.log_level);
43
+ constructor(client) {
44
+ this.api = client.api;
45
+ this.tenantId = client.tenantId;
46
+ this.workflows = new workflows_1.WorkflowsClient(client);
47
+ this.namespace = client.config.namespace;
42
48
  }
43
49
  /**
44
50
  * Retrieves the Cron ID from a CronWorkflows object or a string.
@@ -46,7 +52,11 @@ class CronClient {
46
52
  * @returns The Cron ID as a string.
47
53
  */
48
54
  getCronId(cron) {
49
- return typeof cron === 'string' ? cron : cron.metadata.id;
55
+ const str = typeof cron === 'string' ? cron : cron.metadata.id;
56
+ if (!(0, uuid_1.isValidUUID)(str)) {
57
+ throw new Error('Invalid cron ID: must be a valid UUID');
58
+ }
59
+ return str;
50
60
  }
51
61
  /**
52
62
  * Creates a new Cron workflow.
@@ -58,7 +68,7 @@ class CronClient {
58
68
  create(workflow, cron) {
59
69
  return __awaiter(this, void 0, void 0, function* () {
60
70
  var _a, _b, _c;
61
- const workflowId = typeof workflow === 'string' ? workflow : workflow.id;
71
+ const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
62
72
  // Validate cron input with zod schema
63
73
  try {
64
74
  const parsedCron = exports.CreateCronTriggerSchema.parse(cron);
@@ -100,7 +110,12 @@ class CronClient {
100
110
  */
101
111
  list(query) {
102
112
  return __awaiter(this, void 0, void 0, function* () {
103
- const response = yield this.api.cronWorkflowList(this.tenantId, query);
113
+ const { workflow } = query, rest = __rest(query, ["workflow"]);
114
+ if (workflow) {
115
+ const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
116
+ rest.workflowId = workflowId;
117
+ }
118
+ const response = yield this.api.cronWorkflowList(this.tenantId, rest);
104
119
  return response.data;
105
120
  });
106
121
  }
@@ -18,4 +18,5 @@ export declare class FiltersClient {
18
18
  get(filterId: Parameters<typeof this.api.v1FilterGet>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
19
19
  create(opts: Parameters<typeof this.api.v1FilterCreate>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
20
20
  delete(filterId: Parameters<typeof this.api.v1FilterDelete>[1]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
21
+ update(filterId: Parameters<typeof this.api.v1FilterDelete>[1], updates: Parameters<typeof this.api.v1FilterUpdate>[2]): Promise<import("../../../clients/rest/generated/data-contracts").V1Filter>;
21
22
  }
@@ -55,5 +55,11 @@ class FiltersClient {
55
55
  return data;
56
56
  });
57
57
  }
58
+ update(filterId, updates) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const { data } = yield this.api.v1FilterUpdate(this.tenantId, filterId, updates);
61
+ return data;
62
+ });
63
+ }
58
64
  }
59
65
  exports.FiltersClient = FiltersClient;
@@ -1,5 +1,7 @@
1
+ export * from './crons';
1
2
  export * from './metrics';
2
3
  export * from './ratelimits';
3
4
  export * from './runs';
4
5
  export * from './workers';
5
6
  export * from './workflows';
7
+ export * from './schedules';
@@ -14,8 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./crons"), exports);
17
18
  __exportStar(require("./metrics"), exports);
18
19
  __exportStar(require("./ratelimits"), exports);
19
20
  __exportStar(require("./runs"), exports);
20
21
  __exportStar(require("./workers"), exports);
21
22
  __exportStar(require("./workflows"), exports);
23
+ __exportStar(require("./schedules"), exports);
@@ -62,6 +62,7 @@ export declare class RunsClient {
62
62
  workflows: WorkflowsClient;
63
63
  constructor(client: HatchetClient);
64
64
  get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").V1WorkflowRunDetails>;
65
+ get_status<T = any>(run: string | WorkflowRunRef<T>): Promise<V1TaskStatus>;
65
66
  list(opts?: Partial<ListRunsOpts>): Promise<import("../../../clients/rest/generated/data-contracts").V1TaskSummaryList>;
66
67
  cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
67
68
  replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
@@ -26,6 +26,13 @@ class RunsClient {
26
26
  return data;
27
27
  });
28
28
  }
29
+ get_status(run) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
32
+ const { data } = yield this.api.v1WorkflowRunGetStatus(runId);
33
+ return data;
34
+ });
35
+ }
29
36
  list(opts) {
30
37
  return __awaiter(this, void 0, void 0, function* () {
31
38
  const { data } = yield this.api.v1WorkflowRunList(this.tenantId, Object.assign({}, (yield this.prepareListFilter(opts || {}))));
@@ -1,9 +1,9 @@
1
- import { AdminClient } from '../../admin';
2
- import { Api } from '../../rest';
3
- import { ScheduledWorkflows, ScheduledWorkflowsList } from '../../rest/generated/data-contracts';
1
+ import { ScheduledWorkflows, ScheduledWorkflowsList } from '../../../clients/rest/generated/data-contracts';
4
2
  import { z } from 'zod';
5
3
  import { Workflow } from '../../../workflow';
6
- import { ClientConfig } from '../client-config';
4
+ import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
5
+ import { HatchetClient } from '../client';
6
+ import { WorkflowsClient } from './workflows';
7
7
  /**
8
8
  * Schema for creating a Scheduled Run Trigger.
9
9
  */
@@ -31,19 +31,11 @@ export type CreateScheduledRunInput = z.infer<typeof CreateScheduledRunTriggerSc
31
31
  * Client for managing Scheduled Runs.
32
32
  */
33
33
  export declare class ScheduleClient {
34
- private readonly tenantId;
35
- private readonly config;
36
- private readonly api;
37
- private readonly adminClient;
38
- private logger;
39
- /**
40
- * Initializes a new instance of ScheduleClient.
41
- * @param tenantId - The tenant identifier.
42
- * @param config - Client configuration settings.
43
- * @param api - API instance for REST interactions.
44
- * @param adminClient - Admin client for administrative operations.
45
- */
46
- constructor(tenantId: string, config: ClientConfig, api: Api, adminClient: AdminClient);
34
+ api: HatchetClient['api'];
35
+ tenantId: string;
36
+ workflows: WorkflowsClient;
37
+ namespace: string | undefined;
38
+ constructor(client: HatchetClient);
47
39
  /**
48
40
  * Retrieves the Scheduled Run ID from a ScheduledRun object or a string.
49
41
  * @param scheduledRun - The ScheduledRun object or Scheduled Run ID as a string.
@@ -69,7 +61,9 @@ export declare class ScheduleClient {
69
61
  * @param query - Query parameters for listing Scheduled Runs.
70
62
  * @returns A promise that resolves to a ScheduledWorkflowsList object.
71
63
  */
72
- list(query: Parameters<typeof this.api.workflowScheduledList>[1]): Promise<ScheduledWorkflowsList>;
64
+ list(query: Parameters<typeof this.api.workflowScheduledList>[1] & {
65
+ workflow?: string | Workflow | WorkflowDefinition | BaseWorkflowDeclaration<any, any>;
66
+ }): Promise<ScheduledWorkflowsList>;
73
67
  /**
74
68
  * Retrieves a specific Scheduled Run by its ID.
75
69
  * @param scheduledRun - The Scheduled Run ID as a string or ScheduledWorkflows object.
@@ -8,10 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.ScheduleClient = exports.CreateScheduledRunTriggerSchema = void 0;
13
24
  const zod_1 = require("zod");
14
25
  const axios_1 = require("axios");
26
+ const uuid_1 = require("../../../util/uuid");
27
+ const apply_namespace_1 = require("../../../util/apply-namespace");
28
+ const workflows_1 = require("./workflows");
15
29
  /**
16
30
  * Schema for creating a Scheduled Run Trigger.
17
31
  */
@@ -25,19 +39,11 @@ exports.CreateScheduledRunTriggerSchema = zod_1.z.object({
25
39
  * Client for managing Scheduled Runs.
26
40
  */
27
41
  class ScheduleClient {
28
- /**
29
- * Initializes a new instance of ScheduleClient.
30
- * @param tenantId - The tenant identifier.
31
- * @param config - Client configuration settings.
32
- * @param api - API instance for REST interactions.
33
- * @param adminClient - Admin client for administrative operations.
34
- */
35
- constructor(tenantId, config, api, adminClient) {
36
- this.tenantId = tenantId;
37
- this.config = config;
38
- this.api = api;
39
- this.adminClient = adminClient;
40
- this.logger = config.logger('Scheduled Run', this.config.log_level);
42
+ constructor(client) {
43
+ this.api = client.api;
44
+ this.tenantId = client.tenantId;
45
+ this.workflows = new workflows_1.WorkflowsClient(client);
46
+ this.namespace = client.config.namespace;
41
47
  }
42
48
  /**
43
49
  * Retrieves the Scheduled Run ID from a ScheduledRun object or a string.
@@ -45,7 +51,11 @@ class ScheduleClient {
45
51
  * @returns The Scheduled Run ID as a string.
46
52
  */
47
53
  getScheduledRunId(scheduledRun) {
48
- return typeof scheduledRun === 'string' ? scheduledRun : scheduledRun.metadata.id;
54
+ const str = typeof scheduledRun === 'string' ? scheduledRun : scheduledRun.metadata.id;
55
+ if (!(0, uuid_1.isValidUUID)(str)) {
56
+ throw new Error('Invalid scheduled run ID: must be a valid UUID');
57
+ }
58
+ return str;
49
59
  }
50
60
  /**
51
61
  * Creates a new Scheduled Run.
@@ -57,7 +67,7 @@ class ScheduleClient {
57
67
  create(workflow, cron) {
58
68
  return __awaiter(this, void 0, void 0, function* () {
59
69
  var _a, _b, _c;
60
- const workflowId = typeof workflow === 'string' ? workflow : workflow.id;
70
+ const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
61
71
  // Validate cron input with zod schema
62
72
  try {
63
73
  const parsedCron = exports.CreateScheduledRunTriggerSchema.parse(cron);
@@ -98,7 +108,12 @@ class ScheduleClient {
98
108
  */
99
109
  list(query) {
100
110
  return __awaiter(this, void 0, void 0, function* () {
101
- const response = yield this.api.workflowScheduledList(this.tenantId, query);
111
+ const { workflow } = query, rest = __rest(query, ["workflow"]);
112
+ if (workflow) {
113
+ const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
114
+ rest.workflowId = workflowId;
115
+ }
116
+ const response = yield this.api.workflowScheduledList(this.tenantId, rest);
102
117
  return response.data;
103
118
  });
104
119
  }