@hatchet-dev/typescript-sdk 1.10.8 → 1.11.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.
@@ -807,6 +807,10 @@ export interface V1Webhook {
807
807
  sourceName: V1WebhookSourceName;
808
808
  /** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
809
809
  eventKeyExpression: string;
810
+ /** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
811
+ scopeExpression?: string;
812
+ /** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
813
+ staticPayload?: object;
810
814
  /** The type of authentication to use for the webhook */
811
815
  authType: V1WebhookAuthType;
812
816
  }
@@ -821,6 +825,10 @@ export interface V1CreateWebhookRequestBase {
821
825
  name: string;
822
826
  /** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
823
827
  eventKeyExpression: string;
828
+ /** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
829
+ scopeExpression?: string;
830
+ /** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
831
+ staticPayload?: object;
824
832
  }
825
833
  export interface V1WebhookBasicAuth {
826
834
  /** The username for basic auth */
@@ -863,6 +871,10 @@ export type V1CreateWebhookRequest = V1CreateWebhookRequestBasicAuth | V1CreateW
863
871
  export interface V1UpdateWebhookRequest {
864
872
  /** The CEL expression to use for the event key. This is used to create the event key from the webhook payload. */
865
873
  eventKeyExpression: string;
874
+ /** The CEL expression to use for the scope. This is used to filter the correct workflow to trigger. */
875
+ scopeExpression?: string;
876
+ /** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
877
+ staticPayload?: object;
866
878
  }
867
879
  export interface V1CELDebugRequest {
868
880
  /** The CEL expression to evaluate */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.10.8",
3
+ "version": "1.11.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,6 +1,11 @@
1
- import { BaseWorkflowDeclaration } from '../..';
2
- import { Workflow } from '../../../workflow';
3
1
  import { HatchetClient } from '../client';
2
+ export type TaskStatusMetrics = {
3
+ cancelled: number;
4
+ completed: number;
5
+ failed: number;
6
+ queued: number;
7
+ running: number;
8
+ };
4
9
  /**
5
10
  * MetricsClient is used to get metrics for workflows
6
11
  */
@@ -8,7 +13,13 @@ export declare class MetricsClient {
8
13
  tenantId: string;
9
14
  api: HatchetClient['api'];
10
15
  constructor(client: HatchetClient);
11
- getWorkflowMetrics(workflow: string | Workflow | BaseWorkflowDeclaration<any, any>, opts?: Parameters<typeof this.api.workflowGetMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowMetrics>;
12
- getQueueMetrics(opts?: Parameters<typeof this.api.tenantGetQueueMetrics>[1] & {}): Promise<import("../../../clients/rest/generated/data-contracts").TenantQueueMetrics>;
13
- getTaskMetrics(opts?: Parameters<typeof this.api.tenantGetStepRunQueueMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").TenantStepRunQueueMetrics>;
16
+ /**
17
+ * Get task/run status metrics for a tenant.
18
+ *
19
+ * This backs the dashboard "runs list" status count badges.
20
+ *
21
+ * Endpoint: GET /api/v1/stable/tenants/{tenant}/task-metrics
22
+ */
23
+ getTaskStatusMetrics(query: Parameters<typeof this.api.v1TaskListStatusMetrics>[1], requestParams?: Parameters<typeof this.api.v1TaskListStatusMetrics>[2]): Promise<TaskStatusMetrics>;
24
+ getQueueMetrics(opts?: Parameters<typeof this.api.tenantGetStepRunQueueMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").TenantStepRunQueueMetrics>;
14
25
  }
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MetricsClient = void 0;
13
- const v1_1 = require("../..");
14
13
  /**
15
14
  * MetricsClient is used to get metrics for workflows
16
15
  */
@@ -19,24 +18,24 @@ class MetricsClient {
19
18
  this.tenantId = client.tenantId;
20
19
  this.api = client.api;
21
20
  }
22
- getWorkflowMetrics(workflow, opts) {
21
+ /**
22
+ * Get task/run status metrics for a tenant.
23
+ *
24
+ * This backs the dashboard "runs list" status count badges.
25
+ *
26
+ * Endpoint: GET /api/v1/stable/tenants/{tenant}/task-metrics
27
+ */
28
+ getTaskStatusMetrics(query, requestParams) {
23
29
  return __awaiter(this, void 0, void 0, function* () {
24
- const name = (0, v1_1.workflowNameString)(workflow);
25
- const { data } = yield this.api.workflowGetMetrics(name, opts);
26
- return data;
30
+ const { data } = yield this.api.v1TaskListStatusMetrics(this.tenantId, query, requestParams);
31
+ return data.reduce((acc, curr) => {
32
+ acc[curr.status.toLowerCase()] = curr.count;
33
+ return acc;
34
+ }, {});
27
35
  });
28
36
  }
29
37
  getQueueMetrics(opts) {
30
38
  return __awaiter(this, void 0, void 0, function* () {
31
- // TODO IMPORTANT workflow id is the uuid for the workflow... not its name
32
- // const stringWorkflows = opts?.workflows?
33
- const { data } = yield this.api.tenantGetQueueMetrics(this.tenantId, Object.assign({}, opts));
34
- return data;
35
- });
36
- }
37
- getTaskMetrics(opts) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- // TODO what is this...
40
39
  const { data } = yield this.api.tenantGetStepRunQueueMetrics(this.tenantId, opts);
41
40
  return data;
42
41
  });
@@ -266,14 +266,14 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
266
266
  * @returns A promise that resolves with the workflow metrics.
267
267
  * @throws Error if the workflow is not bound to a Hatchet client.
268
268
  */
269
- metrics(opts?: Parameters<MetricsClient['getWorkflowMetrics']>[1]): Promise<import("../clients/rest/generated/data-contracts").WorkflowMetrics>;
269
+ metrics(opts?: Omit<Parameters<MetricsClient['getTaskStatusMetrics']>[0], 'workflows'>): Promise<import("./client/features/metrics").TaskStatusMetrics>;
270
270
  /**
271
271
  * Get queue metrics for the workflow.
272
272
  * @param opts Optional configuration for the metrics request.
273
273
  * @returns A promise that resolves with the workflow metrics.
274
274
  * @throws Error if the workflow is not bound to a Hatchet client.
275
275
  */
276
- queueMetrics(opts?: Omit<Parameters<MetricsClient['getQueueMetrics']>[0], 'workflows'>): Promise<import("../clients/rest/generated/data-contracts").TenantQueueMetrics>;
276
+ taskStatusMetrics(opts?: Omit<Parameters<MetricsClient['getTaskStatusMetrics']>[0], 'workflows'>): Promise<import("./client/features/metrics").TaskStatusMetrics>;
277
277
  /**
278
278
  * Get the current state of the workflow.
279
279
  * @returns A promise that resolves with the workflow state.
package/v1/declaration.js CHANGED
@@ -166,10 +166,17 @@ class BaseWorkflowDeclaration {
166
166
  * @throws Error if the workflow is not bound to a Hatchet client.
167
167
  */
168
168
  metrics(opts) {
169
- if (!this.client) {
170
- throw UNBOUND_ERR;
171
- }
172
- return this.client.metrics.getWorkflowMetrics(this.definition.name, opts);
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ if (!this.client) {
171
+ throw UNBOUND_ERR;
172
+ }
173
+ const workflow = yield this.client.workflows.get(this.definition.name);
174
+ return this.client.metrics.getTaskStatusMetrics({
175
+ since: (opts === null || opts === void 0 ? void 0 : opts.since) || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
176
+ until: (opts === null || opts === void 0 ? void 0 : opts.until) || new Date().toISOString(),
177
+ workflow_ids: [workflow.metadata.id],
178
+ });
179
+ });
173
180
  }
174
181
  /**
175
182
  * Get queue metrics for the workflow.
@@ -177,11 +184,18 @@ class BaseWorkflowDeclaration {
177
184
  * @returns A promise that resolves with the workflow metrics.
178
185
  * @throws Error if the workflow is not bound to a Hatchet client.
179
186
  */
180
- queueMetrics(opts) {
181
- if (!this.client) {
182
- throw UNBOUND_ERR;
183
- }
184
- return this.client.metrics.getQueueMetrics(Object.assign(Object.assign({}, opts), { workflows: [this.definition.name] }));
187
+ taskStatusMetrics(opts) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ if (!this.client) {
190
+ throw UNBOUND_ERR;
191
+ }
192
+ const workflow = yield this.client.workflows.get(this.definition.name);
193
+ return this.client.metrics.getTaskStatusMetrics({
194
+ since: (opts === null || opts === void 0 ? void 0 : opts.since) || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
195
+ until: (opts === null || opts === void 0 ? void 0 : opts.until) || new Date().toISOString(),
196
+ workflow_ids: [workflow.metadata.id],
197
+ });
198
+ });
185
199
  }
186
200
  /**
187
201
  * Get the current state of the workflow.
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.10.8";
1
+ export declare const HATCHET_VERSION = "1.11.0";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.10.8';
4
+ exports.HATCHET_VERSION = '1.11.0';