@hatchet-dev/typescript-sdk 0.1.11 → 0.1.13
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/clients/admin/admin-client.d.ts +72 -1
- package/clients/admin/admin-client.js +93 -2
- package/clients/admin/index.d.ts +1 -0
- package/clients/admin/index.js +17 -0
- package/clients/hatchet-client/client-config.d.ts +6 -0
- package/clients/hatchet-client/client-config.js +2 -0
- package/clients/hatchet-client/hatchet-client.d.ts +6 -2
- package/clients/hatchet-client/hatchet-client.js +8 -5
- package/clients/listener/listener-client.js +1 -1
- package/clients/rest/api.d.ts +4 -0
- package/clients/rest/api.js +13 -0
- package/clients/rest/generated/Api.d.ts +417 -0
- package/clients/rest/generated/Api.js +363 -0
- package/clients/rest/generated/data-contracts.d.ts +509 -0
- package/clients/rest/generated/data-contracts.js +54 -0
- package/clients/rest/generated/http-client.d.ts +41 -0
- package/clients/rest/generated/http-client.js +99 -0
- package/clients/rest/index.d.ts +8 -0
- package/clients/rest/index.js +35 -0
- package/clients/worker/worker.d.ts +3 -2
- package/clients/worker/worker.js +4 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +12 -3
- package/protoc/workflows/workflows.d.ts +2 -0
- package/protoc/workflows/workflows.js +16 -2
- package/step.d.ts +10 -7
- package/step.js +6 -2
- package/util/config-loader/config-loader.d.ts +2 -2
- package/util/config-loader/config-loader.js +27 -7
- package/util/config-loader/token.d.ts +5 -0
- package/util/config-loader/token.js +26 -0
- package/workflow.d.ts +1 -1
|
@@ -1,12 +1,83 @@
|
|
|
1
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
2
|
import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '../../protoc/workflows';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
|
+
import { Api } from '../rest';
|
|
5
|
+
/**
|
|
6
|
+
* AdminClient is a client for interacting with the Hatchet Admin API. This allows you to configure, trigger,
|
|
7
|
+
* and monitor workflows.
|
|
8
|
+
* The admin client can be accessed via:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const hatchet = Hatchet.init()
|
|
11
|
+
* const admin = hatchet.admin as AdminClient;
|
|
12
|
+
*
|
|
13
|
+
* // Now you can use the admin client to interact with the Hatchet Admin API
|
|
14
|
+
* admin.list_workflows().then((res) => {
|
|
15
|
+
* res.rows?.forEach((row) => {
|
|
16
|
+
* console.log(row);
|
|
17
|
+
* });
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
export declare class AdminClient {
|
|
5
22
|
config: ClientConfig;
|
|
6
23
|
client: WorkflowServiceClient;
|
|
7
|
-
|
|
24
|
+
api: Api;
|
|
25
|
+
tenantId: string;
|
|
26
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api, tenantId: string);
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically
|
|
29
|
+
* determine if the workflow definition has changed and create a new version if necessary.
|
|
30
|
+
* @param workflow a workflow definition to create
|
|
31
|
+
*/
|
|
8
32
|
put_workflow(workflow: CreateWorkflowVersionOpts): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
35
|
+
* new run.
|
|
36
|
+
* @param workflowName the name of the workflow to run
|
|
37
|
+
* @param input an object containing the input to the workflow
|
|
38
|
+
* @returns the ID of the new workflow run
|
|
39
|
+
*/
|
|
9
40
|
run_workflow(workflowName: string, input: object): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* List workflows in the tenant associated with the API token.
|
|
43
|
+
* @returns a list of all workflows in the tenant
|
|
44
|
+
*/
|
|
45
|
+
list_workflows(): Promise<import("../rest/generated/data-contracts").WorkflowList>;
|
|
46
|
+
/**
|
|
47
|
+
* Get a workflow by its ID.
|
|
48
|
+
* @param workflowId the workflow ID (**note:** this is not the same as the workflow version id)
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
get_workflow(workflowId: string): Promise<import("../rest/generated/data-contracts").Workflow>;
|
|
52
|
+
/**
|
|
53
|
+
* Get a workflow version.
|
|
54
|
+
* @param workflowId the workflow ID
|
|
55
|
+
* @param version the version of the workflow to get. If not provided, the latest version will be returned.
|
|
56
|
+
* @returns the workflow version
|
|
57
|
+
*/
|
|
58
|
+
get_workflow_version(workflowId: string, version?: string): Promise<import("../rest/generated/data-contracts").WorkflowVersion>;
|
|
59
|
+
/**
|
|
60
|
+
* Get a workflow run.
|
|
61
|
+
* @param workflowRunId the id of the workflow run to get
|
|
62
|
+
* @returns the workflow run
|
|
63
|
+
*/
|
|
64
|
+
get_workflow_run(workflowRunId: string): Promise<import("../rest/generated/data-contracts").WorkflowRun>;
|
|
65
|
+
/**
|
|
66
|
+
* List workflow runs in the tenant associated with the API token.
|
|
67
|
+
* @param query the query to filter the list of workflow runs
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
list_workflow_runs(query: {
|
|
71
|
+
offset?: number | undefined;
|
|
72
|
+
limit?: number | undefined;
|
|
73
|
+
eventId?: string | undefined;
|
|
74
|
+
workflowId?: string | undefined;
|
|
75
|
+
}): Promise<import("../rest/generated/data-contracts").WorkflowRunList>;
|
|
76
|
+
/**
|
|
77
|
+
* Schedule a workflow to run at a specific time or times.
|
|
78
|
+
* @param workflowId the ID of the workflow to schedule
|
|
79
|
+
* @param options an object containing the schedules to set
|
|
80
|
+
*/
|
|
10
81
|
schedule_workflow(workflowId: string, options?: {
|
|
11
82
|
schedules?: Date[];
|
|
12
83
|
}): void;
|
|
@@ -15,11 +15,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.AdminClient = void 0;
|
|
16
16
|
const workflows_1 = require("../../protoc/workflows");
|
|
17
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
18
|
+
/**
|
|
19
|
+
* AdminClient is a client for interacting with the Hatchet Admin API. This allows you to configure, trigger,
|
|
20
|
+
* and monitor workflows.
|
|
21
|
+
* The admin client can be accessed via:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const hatchet = Hatchet.init()
|
|
24
|
+
* const admin = hatchet.admin as AdminClient;
|
|
25
|
+
*
|
|
26
|
+
* // Now you can use the admin client to interact with the Hatchet Admin API
|
|
27
|
+
* admin.list_workflows().then((res) => {
|
|
28
|
+
* res.rows?.forEach((row) => {
|
|
29
|
+
* console.log(row);
|
|
30
|
+
* });
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
18
34
|
class AdminClient {
|
|
19
|
-
constructor(config, channel, factory) {
|
|
35
|
+
constructor(config, channel, factory, api, tenantId) {
|
|
20
36
|
this.config = config;
|
|
21
37
|
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
38
|
+
this.api = api;
|
|
39
|
+
this.tenantId = tenantId;
|
|
22
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically
|
|
43
|
+
* determine if the workflow definition has changed and create a new version if necessary.
|
|
44
|
+
* @param workflow a workflow definition to create
|
|
45
|
+
*/
|
|
23
46
|
put_workflow(workflow) {
|
|
24
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
48
|
try {
|
|
@@ -32,6 +55,13 @@ class AdminClient {
|
|
|
32
55
|
}
|
|
33
56
|
});
|
|
34
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
60
|
+
* new run.
|
|
61
|
+
* @param workflowName the name of the workflow to run
|
|
62
|
+
* @param input an object containing the input to the workflow
|
|
63
|
+
* @returns the ID of the new workflow run
|
|
64
|
+
*/
|
|
35
65
|
run_workflow(workflowName, input) {
|
|
36
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
67
|
try {
|
|
@@ -47,7 +77,68 @@ class AdminClient {
|
|
|
47
77
|
}
|
|
48
78
|
});
|
|
49
79
|
}
|
|
50
|
-
|
|
80
|
+
/**
|
|
81
|
+
* List workflows in the tenant associated with the API token.
|
|
82
|
+
* @returns a list of all workflows in the tenant
|
|
83
|
+
*/
|
|
84
|
+
list_workflows() {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const res = yield this.api.workflowList(this.tenantId);
|
|
87
|
+
return res.data;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get a workflow by its ID.
|
|
92
|
+
* @param workflowId the workflow ID (**note:** this is not the same as the workflow version id)
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
get_workflow(workflowId) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const res = yield this.api.workflowGet(workflowId);
|
|
98
|
+
return res.data;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get a workflow version.
|
|
103
|
+
* @param workflowId the workflow ID
|
|
104
|
+
* @param version the version of the workflow to get. If not provided, the latest version will be returned.
|
|
105
|
+
* @returns the workflow version
|
|
106
|
+
*/
|
|
107
|
+
get_workflow_version(workflowId, version) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const res = yield this.api.workflowVersionGet(workflowId, {
|
|
110
|
+
version,
|
|
111
|
+
});
|
|
112
|
+
return res.data;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get a workflow run.
|
|
117
|
+
* @param workflowRunId the id of the workflow run to get
|
|
118
|
+
* @returns the workflow run
|
|
119
|
+
*/
|
|
120
|
+
get_workflow_run(workflowRunId) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const res = yield this.api.workflowRunGet(this.tenantId, workflowRunId);
|
|
123
|
+
return res.data;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* List workflow runs in the tenant associated with the API token.
|
|
128
|
+
* @param query the query to filter the list of workflow runs
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
list_workflow_runs(query) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const res = yield this.api.workflowRunList(this.tenantId, query);
|
|
134
|
+
return res.data;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Schedule a workflow to run at a specific time or times.
|
|
139
|
+
* @param workflowId the ID of the workflow to schedule
|
|
140
|
+
* @param options an object containing the schedules to set
|
|
141
|
+
*/
|
|
51
142
|
schedule_workflow(workflowId, options) {
|
|
52
143
|
try {
|
|
53
144
|
this.client.scheduleWorkflow({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './admin-client';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./admin-client"), exports);
|
|
@@ -41,7 +41,9 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
41
41
|
server_name?: string | undefined;
|
|
42
42
|
}>;
|
|
43
43
|
host_port: z.ZodString;
|
|
44
|
+
api_url: z.ZodString;
|
|
44
45
|
log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
|
|
46
|
+
tenant_id: z.ZodString;
|
|
45
47
|
}, "strip", z.ZodTypeAny, {
|
|
46
48
|
token: string;
|
|
47
49
|
tls_config: {
|
|
@@ -52,6 +54,8 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
52
54
|
server_name?: string | undefined;
|
|
53
55
|
};
|
|
54
56
|
host_port: string;
|
|
57
|
+
api_url: string;
|
|
58
|
+
tenant_id: string;
|
|
55
59
|
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
56
60
|
}, {
|
|
57
61
|
token: string;
|
|
@@ -63,6 +67,8 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
63
67
|
server_name?: string | undefined;
|
|
64
68
|
};
|
|
65
69
|
host_port: string;
|
|
70
|
+
api_url: string;
|
|
71
|
+
tenant_id: string;
|
|
66
72
|
log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
|
|
67
73
|
}>;
|
|
68
74
|
export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
|
|
@@ -13,5 +13,7 @@ exports.ClientConfigSchema = zod_1.z.object({
|
|
|
13
13
|
token: zod_1.z.string(),
|
|
14
14
|
tls_config: ClientTLSConfigSchema,
|
|
15
15
|
host_port: zod_1.z.string(),
|
|
16
|
+
api_url: zod_1.z.string(),
|
|
16
17
|
log_level: zod_1.z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
|
|
18
|
+
tenant_id: zod_1.z.string(),
|
|
17
19
|
});
|
|
@@ -5,8 +5,10 @@ import { Channel, ChannelCredentials } from 'nice-grpc';
|
|
|
5
5
|
import { Workflow } from '../../workflow';
|
|
6
6
|
import { Worker } from '../worker';
|
|
7
7
|
import Logger from '../../util/logger/logger';
|
|
8
|
+
import { AxiosRequestConfig } from 'axios';
|
|
8
9
|
import { ClientConfig } from './client-config';
|
|
9
10
|
import { ListenerClient } from '../listener/listener-client';
|
|
11
|
+
import { Api } from '../rest/generated/Api';
|
|
10
12
|
export interface HatchetClientOptions {
|
|
11
13
|
config_path?: string;
|
|
12
14
|
credentials?: ChannelCredentials;
|
|
@@ -18,11 +20,13 @@ export declare class HatchetClient {
|
|
|
18
20
|
event: EventClient;
|
|
19
21
|
dispatcher: DispatcherClient;
|
|
20
22
|
admin: AdminClient;
|
|
23
|
+
api: Api;
|
|
21
24
|
listener: ListenerClient;
|
|
25
|
+
tenantId: string;
|
|
22
26
|
logger: Logger;
|
|
23
|
-
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions);
|
|
27
|
+
constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosOpts?: AxiosRequestConfig);
|
|
24
28
|
static with_host_port(host: string, port: number, config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
|
|
25
|
-
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions): HatchetClient;
|
|
29
|
+
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
|
|
26
30
|
run(workflow: string | Workflow): Promise<Worker>;
|
|
27
31
|
worker(workflow: string | Workflow): Promise<Worker>;
|
|
28
32
|
}
|
|
@@ -48,6 +48,7 @@ const worker_1 = require("../worker");
|
|
|
48
48
|
const logger_1 = __importDefault(require("../../util/logger/logger"));
|
|
49
49
|
const client_config_1 = require("./client-config");
|
|
50
50
|
const listener_client_1 = require("../listener/listener-client");
|
|
51
|
+
const rest_1 = __importDefault(require("../rest"));
|
|
51
52
|
const addTokenMiddleware = (token) => function _(call, options) {
|
|
52
53
|
return __asyncGenerator(this, arguments, function* _1() {
|
|
53
54
|
var _a, e_1, _b, _c;
|
|
@@ -75,11 +76,11 @@ const addTokenMiddleware = (token) => function _(call, options) {
|
|
|
75
76
|
});
|
|
76
77
|
};
|
|
77
78
|
class HatchetClient {
|
|
78
|
-
constructor(config, options) {
|
|
79
|
+
constructor(config, options, axiosOpts) {
|
|
79
80
|
// Initializes a new Client instance.
|
|
80
81
|
// Loads config in the following order: config param > yaml file > env vars
|
|
81
82
|
var _a;
|
|
82
|
-
const loaded = config_loader_1.ConfigLoader.
|
|
83
|
+
const loaded = config_loader_1.ConfigLoader.loadClientConfig({
|
|
83
84
|
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
84
85
|
});
|
|
85
86
|
try {
|
|
@@ -98,9 +99,11 @@ class HatchetClient {
|
|
|
98
99
|
'grpc.ssl_target_name_override': this.config.tls_config.server_name,
|
|
99
100
|
});
|
|
100
101
|
const clientFactory = (0, nice_grpc_1.createClientFactory)().use(addTokenMiddleware(this.config.token));
|
|
102
|
+
this.tenantId = this.config.tenant_id;
|
|
103
|
+
this.api = (0, rest_1.default)(this.config.api_url, this.config.token, axiosOpts);
|
|
101
104
|
this.event = new event_client_1.EventClient(this.config, this.channel, clientFactory);
|
|
102
105
|
this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, this.channel, clientFactory);
|
|
103
|
-
this.admin = new admin_client_1.AdminClient(this.config, this.channel, clientFactory);
|
|
106
|
+
this.admin = new admin_client_1.AdminClient(this.config, this.channel, clientFactory, this.api, this.tenantId);
|
|
104
107
|
this.listener = new listener_client_1.ListenerClient(this.config, this.channel, clientFactory);
|
|
105
108
|
this.logger = new logger_1.default('HatchetClient', this.config.log_level);
|
|
106
109
|
this.logger.info(`Initialized HatchetClient`);
|
|
@@ -108,8 +111,8 @@ class HatchetClient {
|
|
|
108
111
|
static with_host_port(host, port, config, options) {
|
|
109
112
|
return new HatchetClient(Object.assign(Object.assign({}, config), { host_port: `${host}:${port}` }), options);
|
|
110
113
|
}
|
|
111
|
-
static init(config, options) {
|
|
112
|
-
return new HatchetClient(config, options);
|
|
114
|
+
static init(config, options, axiosConfig) {
|
|
115
|
+
return new HatchetClient(config, options, axiosConfig);
|
|
113
116
|
}
|
|
114
117
|
run(workflow) {
|
|
115
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,7 +40,7 @@ class ListenerClient {
|
|
|
40
40
|
constructor(config, channel, factory) {
|
|
41
41
|
this.config = config;
|
|
42
42
|
this.client = factory.create(dispatcher_1.DispatcherDefinition, channel);
|
|
43
|
-
this.logger = new logger_1.Logger(`
|
|
43
|
+
this.logger = new logger_1.Logger(`Listener`, config.log_level);
|
|
44
44
|
}
|
|
45
45
|
on(workflowRunId, handler) {
|
|
46
46
|
var _a, e_1, _b, _c;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const qs_1 = __importDefault(require("qs"));
|
|
7
|
+
const Api_1 = require("./generated/Api");
|
|
8
|
+
const api = (serverUrl, token, axiosOpts) => {
|
|
9
|
+
return new Api_1.Api(Object.assign({ baseURL: serverUrl, headers: {
|
|
10
|
+
Authorization: `Bearer ${token}`,
|
|
11
|
+
}, paramsSerializer: (params) => qs_1.default.stringify(params, { arrayFormat: 'repeat' }) }, axiosOpts));
|
|
12
|
+
};
|
|
13
|
+
exports.default = api;
|