@hatchet-dev/typescript-sdk 0.1.12 → 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 +7 -4
- 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 +11 -2
- 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.js +13 -4
- package/util/config-loader/token.d.ts +1 -0
- package/util/config-loader/token.js +6 -1
- package/workflow.d.ts +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import api from './api';
|
|
2
|
+
import { Api } from './generated/Api';
|
|
3
|
+
import { Worker as _Worker, Workflow as _Workflow } from './generated/data-contracts';
|
|
4
|
+
import * as APIContracts from './generated/data-contracts';
|
|
5
|
+
type ApiWorker = _Worker;
|
|
6
|
+
type ApiWorkflow = _Workflow;
|
|
7
|
+
export { ApiWorker, ApiWorkflow, APIContracts, Api };
|
|
8
|
+
export default api;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Api = exports.APIContracts = void 0;
|
|
30
|
+
const api_1 = __importDefault(require("./api"));
|
|
31
|
+
const Api_1 = require("./generated/Api");
|
|
32
|
+
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return Api_1.Api; } });
|
|
33
|
+
const APIContracts = __importStar(require("./generated/data-contracts"));
|
|
34
|
+
exports.APIContracts = APIContracts;
|
|
35
|
+
exports.default = api_1.default;
|
|
@@ -4,7 +4,7 @@ import { StepActionEvent, StepActionEventType, GroupKeyActionEvent, GroupKeyActi
|
|
|
4
4
|
import HatchetPromise from '../../util/hatchet-promise/hatchet-promise';
|
|
5
5
|
import { Workflow } from '../../workflow';
|
|
6
6
|
import { Logger } from '../../util/logger';
|
|
7
|
-
import { Context } from '../../step';
|
|
7
|
+
import { Context, StepRunFunction } from '../../step';
|
|
8
8
|
export type ActionRegistry = Record<Action['actionId'], Function>;
|
|
9
9
|
export declare class Worker {
|
|
10
10
|
serviceName: string;
|
|
@@ -15,13 +15,14 @@ export declare class Worker {
|
|
|
15
15
|
action_registry: ActionRegistry;
|
|
16
16
|
listener: ActionListener | undefined;
|
|
17
17
|
futures: Record<Action['stepRunId'], HatchetPromise<any>>;
|
|
18
|
-
contexts: Record<Action['stepRunId'], Context<any>>;
|
|
18
|
+
contexts: Record<Action['stepRunId'], Context<any, any>>;
|
|
19
19
|
logger: Logger;
|
|
20
20
|
constructor(client: HatchetClient, options: {
|
|
21
21
|
name: string;
|
|
22
22
|
handleKill?: boolean;
|
|
23
23
|
});
|
|
24
24
|
registerWorkflow(workflow: Workflow): Promise<void>;
|
|
25
|
+
registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
|
|
25
26
|
handleStartStepRun(action: Action): void;
|
|
26
27
|
handleStartGroupKeyRun(action: Action): void;
|
|
27
28
|
getStepActionEvent(action: Action, eventType: StepActionEventType, payload?: any): StepActionEvent;
|
package/clients/worker/worker.js
CHANGED
|
@@ -73,6 +73,7 @@ class Worker {
|
|
|
73
73
|
timeout: step.timeout || '60s',
|
|
74
74
|
inputs: '{}',
|
|
75
75
|
parents: (_a = step.parents) !== null && _a !== void 0 ? _a : [],
|
|
76
|
+
userData: '{}',
|
|
76
77
|
});
|
|
77
78
|
}),
|
|
78
79
|
},
|
|
@@ -90,6 +91,9 @@ class Worker {
|
|
|
90
91
|
? Object.assign(Object.assign({}, this.action_registry), { [`${this.serviceName}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
|
|
91
92
|
});
|
|
92
93
|
}
|
|
94
|
+
registerAction(actionId, action) {
|
|
95
|
+
this.action_registry[actionId] = action;
|
|
96
|
+
}
|
|
93
97
|
handleStartStepRun(action) {
|
|
94
98
|
const { actionId } = action;
|
|
95
99
|
const context = new step_1.Context(action.actionPayload);
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -18,4 +18,6 @@ const hatchet_client_1 = require("./clients/hatchet-client");
|
|
|
18
18
|
__exportStar(require("./workflow"), exports);
|
|
19
19
|
__exportStar(require("./step"), exports);
|
|
20
20
|
__exportStar(require("./clients/worker"), exports);
|
|
21
|
+
__exportStar(require("./clients/rest"), exports);
|
|
22
|
+
__exportStar(require("./clients/admin"), exports);
|
|
21
23
|
exports.default = hatchet_client_1.HatchetClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,14 +33,18 @@
|
|
|
33
33
|
"worker:dag": "npm run exec -- ./examples/dag-worker.ts",
|
|
34
34
|
"worker:concurrency": "npm run exec -- ./examples/concurrency/concurrency-worker.ts",
|
|
35
35
|
"event:concurrency": "npm run exec -- ./examples/concurrency/concurrency-event.ts",
|
|
36
|
+
"api": "npm run exec -- ./examples/api.ts",
|
|
36
37
|
"prepublish": "cp package.json dist/package.json;",
|
|
37
|
-
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks"
|
|
38
|
+
"publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
|
|
39
|
+
"generate-docs": "typedoc"
|
|
38
40
|
},
|
|
39
41
|
"keywords": [],
|
|
40
42
|
"author": "",
|
|
41
43
|
"license": "MIT",
|
|
42
44
|
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.11.16",
|
|
43
46
|
"@types/jest": "^29.5.11",
|
|
47
|
+
"@types/node": "^20.11.16",
|
|
44
48
|
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
45
49
|
"autoprefixer": "^10.4.16",
|
|
46
50
|
"dotenv-cli": "^7.3.0",
|
|
@@ -62,13 +66,18 @@
|
|
|
62
66
|
"ts-jest": "^29.1.1",
|
|
63
67
|
"ts-node": "^10.9.2",
|
|
64
68
|
"ts-proto": "^1.167.0",
|
|
69
|
+
"typedoc": "^0.25.7",
|
|
70
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
65
71
|
"typescript": "^5.3.3"
|
|
66
72
|
},
|
|
67
73
|
"dependencies": {
|
|
74
|
+
"@types/qs": "^6.9.11",
|
|
75
|
+
"axios": "^1.6.7",
|
|
68
76
|
"long": "^5.2.3",
|
|
69
77
|
"nice-grpc": "^2.1.7",
|
|
70
78
|
"nice-grpc-common": "^2.0.2",
|
|
71
79
|
"protobufjs": "^7.2.6",
|
|
80
|
+
"qs": "^6.11.2",
|
|
72
81
|
"yaml": "^2.3.4",
|
|
73
82
|
"zod": "^3.22.4"
|
|
74
83
|
}
|
|
@@ -62,6 +62,8 @@ export interface CreateWorkflowStepOpts {
|
|
|
62
62
|
inputs: string;
|
|
63
63
|
/** (optional) the step parents. if none are passed in, this is a root step */
|
|
64
64
|
parents: string[];
|
|
65
|
+
/** (optional) the custom step user data, assuming string representation of JSON */
|
|
66
|
+
userData: string;
|
|
65
67
|
}
|
|
66
68
|
/** ListWorkflowsRequest is the request for ListWorkflows. */
|
|
67
69
|
export interface ListWorkflowsRequest {
|
|
@@ -470,7 +470,7 @@ exports.CreateWorkflowJobOpts = {
|
|
|
470
470
|
},
|
|
471
471
|
};
|
|
472
472
|
function createBaseCreateWorkflowStepOpts() {
|
|
473
|
-
return { readableId: "", action: "", timeout: "", inputs: "", parents: [] };
|
|
473
|
+
return { readableId: "", action: "", timeout: "", inputs: "", parents: [], userData: "" };
|
|
474
474
|
}
|
|
475
475
|
exports.CreateWorkflowStepOpts = {
|
|
476
476
|
encode(message, writer = _m0.Writer.create()) {
|
|
@@ -489,6 +489,9 @@ exports.CreateWorkflowStepOpts = {
|
|
|
489
489
|
for (const v of message.parents) {
|
|
490
490
|
writer.uint32(42).string(v);
|
|
491
491
|
}
|
|
492
|
+
if (message.userData !== "") {
|
|
493
|
+
writer.uint32(50).string(message.userData);
|
|
494
|
+
}
|
|
492
495
|
return writer;
|
|
493
496
|
},
|
|
494
497
|
decode(input, length) {
|
|
@@ -528,6 +531,12 @@ exports.CreateWorkflowStepOpts = {
|
|
|
528
531
|
}
|
|
529
532
|
message.parents.push(reader.string());
|
|
530
533
|
continue;
|
|
534
|
+
case 6:
|
|
535
|
+
if (tag !== 50) {
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
message.userData = reader.string();
|
|
539
|
+
continue;
|
|
531
540
|
}
|
|
532
541
|
if ((tag & 7) === 4 || tag === 0) {
|
|
533
542
|
break;
|
|
@@ -543,6 +552,7 @@ exports.CreateWorkflowStepOpts = {
|
|
|
543
552
|
timeout: isSet(object.timeout) ? globalThis.String(object.timeout) : "",
|
|
544
553
|
inputs: isSet(object.inputs) ? globalThis.String(object.inputs) : "",
|
|
545
554
|
parents: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.parents) ? object.parents.map((e) => globalThis.String(e)) : [],
|
|
555
|
+
userData: isSet(object.userData) ? globalThis.String(object.userData) : "",
|
|
546
556
|
};
|
|
547
557
|
},
|
|
548
558
|
toJSON(message) {
|
|
@@ -563,19 +573,23 @@ exports.CreateWorkflowStepOpts = {
|
|
|
563
573
|
if ((_a = message.parents) === null || _a === void 0 ? void 0 : _a.length) {
|
|
564
574
|
obj.parents = message.parents;
|
|
565
575
|
}
|
|
576
|
+
if (message.userData !== "") {
|
|
577
|
+
obj.userData = message.userData;
|
|
578
|
+
}
|
|
566
579
|
return obj;
|
|
567
580
|
},
|
|
568
581
|
create(base) {
|
|
569
582
|
return exports.CreateWorkflowStepOpts.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
570
583
|
},
|
|
571
584
|
fromPartial(object) {
|
|
572
|
-
var _a, _b, _c, _d, _e;
|
|
585
|
+
var _a, _b, _c, _d, _e, _f;
|
|
573
586
|
const message = createBaseCreateWorkflowStepOpts();
|
|
574
587
|
message.readableId = (_a = object.readableId) !== null && _a !== void 0 ? _a : "";
|
|
575
588
|
message.action = (_b = object.action) !== null && _b !== void 0 ? _b : "";
|
|
576
589
|
message.timeout = (_c = object.timeout) !== null && _c !== void 0 ? _c : "";
|
|
577
590
|
message.inputs = (_d = object.inputs) !== null && _d !== void 0 ? _d : "";
|
|
578
591
|
message.parents = ((_e = object.parents) === null || _e === void 0 ? void 0 : _e.map((e) => e)) || [];
|
|
592
|
+
message.userData = (_f = object.userData) !== null && _f !== void 0 ? _f : "";
|
|
579
593
|
return message;
|
|
580
594
|
},
|
|
581
595
|
};
|
package/step.d.ts
CHANGED
|
@@ -15,20 +15,23 @@ export declare const CreateStepSchema: z.ZodObject<{
|
|
|
15
15
|
export type NextStep = {
|
|
16
16
|
[key: string]: string;
|
|
17
17
|
};
|
|
18
|
-
interface ContextData<T
|
|
18
|
+
interface ContextData<T, K> {
|
|
19
19
|
input: T;
|
|
20
20
|
parents: Record<string, any>;
|
|
21
|
-
|
|
21
|
+
triggered_by: string;
|
|
22
|
+
user_data: K;
|
|
22
23
|
}
|
|
23
|
-
export declare class Context<T
|
|
24
|
-
data: ContextData<T>;
|
|
24
|
+
export declare class Context<T, K> {
|
|
25
|
+
data: ContextData<T, K>;
|
|
25
26
|
controller: AbortController;
|
|
26
27
|
constructor(payload: string);
|
|
27
28
|
stepOutput(step: string): string;
|
|
28
29
|
triggeredByEvent(): boolean;
|
|
29
|
-
workflowInput():
|
|
30
|
+
workflowInput(): T;
|
|
31
|
+
userData(): K;
|
|
30
32
|
}
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
+
export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep> | NextStep | void;
|
|
34
|
+
export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
|
|
35
|
+
run: StepRunFunction<T, K>;
|
|
33
36
|
}
|
|
34
37
|
export {};
|
package/step.js
CHANGED
|
@@ -56,11 +56,15 @@ class Context {
|
|
|
56
56
|
}
|
|
57
57
|
triggeredByEvent() {
|
|
58
58
|
var _a;
|
|
59
|
-
return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.
|
|
59
|
+
return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.triggered_by) === 'event';
|
|
60
60
|
}
|
|
61
61
|
workflowInput() {
|
|
62
62
|
var _a;
|
|
63
|
-
return (
|
|
63
|
+
return (_a = this.data) === null || _a === void 0 ? void 0 : _a.input;
|
|
64
|
+
}
|
|
65
|
+
userData() {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = this.data) === null || _a === void 0 ? void 0 : _a.user_data;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
exports.Context = Context;
|
|
@@ -34,7 +34,7 @@ const token_1 = require("./token");
|
|
|
34
34
|
const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
|
|
35
35
|
class ConfigLoader {
|
|
36
36
|
static loadClientConfig(config) {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
38
38
|
const yaml = this.loadYamlConfig(config === null || config === void 0 ? void 0 : config.path);
|
|
39
39
|
const tlsConfig = {
|
|
40
40
|
tls_strategy: (_c = (_b = (_a = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _a === void 0 ? void 0 : _a.tls_strategy) !== null && _b !== void 0 ? _b : this.env('HATCHET_CLIENT_TLS_STRATEGY')) !== null && _c !== void 0 ? _c : 'tls',
|
|
@@ -45,19 +45,28 @@ class ConfigLoader {
|
|
|
45
45
|
};
|
|
46
46
|
const token = (_m = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _m !== void 0 ? _m : this.env('HATCHET_CLIENT_TOKEN');
|
|
47
47
|
let grpcBroadcastAddress;
|
|
48
|
+
let apiUrl;
|
|
49
|
+
const tenantId = (0, token_1.getTenantIdFromJWT)(token);
|
|
50
|
+
if (!tenantId) {
|
|
51
|
+
throw new Error('Tenant ID not found in subject claim of token');
|
|
52
|
+
}
|
|
48
53
|
try {
|
|
49
54
|
const addresses = (0, token_1.getAddressesFromJWT)(token);
|
|
50
55
|
grpcBroadcastAddress =
|
|
51
56
|
(_p = (_o = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _o !== void 0 ? _o : this.env('HATCHET_CLIENT_HOST_PORT')) !== null && _p !== void 0 ? _p : addresses.grpcBroadcastAddress;
|
|
57
|
+
apiUrl = (_r = (_q = yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _q !== void 0 ? _q : this.env('HATCHET_CLIENT_API_URL')) !== null && _r !== void 0 ? _r : addresses.serverUrl;
|
|
52
58
|
}
|
|
53
59
|
catch (e) {
|
|
54
|
-
grpcBroadcastAddress = (
|
|
60
|
+
grpcBroadcastAddress = (_s = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _s !== void 0 ? _s : this.env('HATCHET_CLIENT_HOST_PORT');
|
|
61
|
+
apiUrl = (_t = yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _t !== void 0 ? _t : this.env('HATCHET_CLIENT_API_URL');
|
|
55
62
|
}
|
|
56
63
|
return {
|
|
57
|
-
token: (
|
|
64
|
+
token: (_u = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _u !== void 0 ? _u : this.env('HATCHET_CLIENT_TOKEN'),
|
|
58
65
|
host_port: grpcBroadcastAddress,
|
|
66
|
+
api_url: apiUrl,
|
|
59
67
|
tls_config: tlsConfig,
|
|
60
|
-
log_level: (
|
|
68
|
+
log_level: (_w = (_v = yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _v !== void 0 ? _v : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _w !== void 0 ? _w : 'INFO',
|
|
69
|
+
tenant_id: tenantId,
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
static get default_yaml_config_path() {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAddressesFromJWT = void 0;
|
|
3
|
+
exports.getAddressesFromJWT = exports.getTenantIdFromJWT = void 0;
|
|
4
|
+
function getTenantIdFromJWT(token) {
|
|
5
|
+
const claims = extractClaimsFromJWT(token);
|
|
6
|
+
return claims.sub;
|
|
7
|
+
}
|
|
8
|
+
exports.getTenantIdFromJWT = getTenantIdFromJWT;
|
|
4
9
|
function getAddressesFromJWT(token) {
|
|
5
10
|
const claims = extractClaimsFromJWT(token);
|
|
6
11
|
return {
|
package/workflow.d.ts
CHANGED