@hatchet-dev/typescript-sdk 0.1.27 → 0.1.29

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.
@@ -32,14 +32,16 @@ class EventClient {
32
32
  this.logger = new logger_1.Logger(`Dispatcher`, config.log_level);
33
33
  }
34
34
  push(type, input) {
35
+ var _a;
36
+ const namespacedType = `${(_a = this.config.namespace) !== null && _a !== void 0 ? _a : ''}${type}`;
35
37
  const req = {
36
- key: type,
38
+ key: namespacedType,
37
39
  payload: JSON.stringify(input),
38
40
  eventTimestamp: new Date(),
39
41
  };
40
42
  try {
41
43
  const e = this.client.push(req);
42
- this.logger.info(`Event pushed: ${type}`);
44
+ this.logger.info(`Event pushed: ${namespacedType}`);
43
45
  return e;
44
46
  }
45
47
  catch (e) {
@@ -1,19 +1,19 @@
1
1
  import { ChannelCredentials } from 'nice-grpc';
2
2
  import { z } from 'zod';
3
3
  declare const ClientTLSConfigSchema: z.ZodObject<{
4
- tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
4
+ tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls", "none"]>>;
5
5
  cert_file: z.ZodOptional<z.ZodString>;
6
6
  ca_file: z.ZodOptional<z.ZodString>;
7
7
  key_file: z.ZodOptional<z.ZodString>;
8
8
  server_name: z.ZodOptional<z.ZodString>;
9
9
  }, "strip", z.ZodTypeAny, {
10
- tls_strategy?: "tls" | "mtls" | undefined;
10
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
11
11
  cert_file?: string | undefined;
12
12
  ca_file?: string | undefined;
13
13
  key_file?: string | undefined;
14
14
  server_name?: string | undefined;
15
15
  }, {
16
- tls_strategy?: "tls" | "mtls" | undefined;
16
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
17
17
  cert_file?: string | undefined;
18
18
  ca_file?: string | undefined;
19
19
  key_file?: string | undefined;
@@ -22,19 +22,19 @@ declare const ClientTLSConfigSchema: z.ZodObject<{
22
22
  export declare const ClientConfigSchema: z.ZodObject<{
23
23
  token: z.ZodString;
24
24
  tls_config: z.ZodObject<{
25
- tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls"]>>;
25
+ tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls", "none"]>>;
26
26
  cert_file: z.ZodOptional<z.ZodString>;
27
27
  ca_file: z.ZodOptional<z.ZodString>;
28
28
  key_file: z.ZodOptional<z.ZodString>;
29
29
  server_name: z.ZodOptional<z.ZodString>;
30
30
  }, "strip", z.ZodTypeAny, {
31
- tls_strategy?: "tls" | "mtls" | undefined;
31
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
32
32
  cert_file?: string | undefined;
33
33
  ca_file?: string | undefined;
34
34
  key_file?: string | undefined;
35
35
  server_name?: string | undefined;
36
36
  }, {
37
- tls_strategy?: "tls" | "mtls" | undefined;
37
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
38
38
  cert_file?: string | undefined;
39
39
  ca_file?: string | undefined;
40
40
  key_file?: string | undefined;
@@ -44,10 +44,11 @@ export declare const ClientConfigSchema: z.ZodObject<{
44
44
  api_url: z.ZodString;
45
45
  log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
46
46
  tenant_id: z.ZodString;
47
+ namespace: z.ZodOptional<z.ZodString>;
47
48
  }, "strip", z.ZodTypeAny, {
48
49
  token: string;
49
50
  tls_config: {
50
- tls_strategy?: "tls" | "mtls" | undefined;
51
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
51
52
  cert_file?: string | undefined;
52
53
  ca_file?: string | undefined;
53
54
  key_file?: string | undefined;
@@ -57,10 +58,11 @@ export declare const ClientConfigSchema: z.ZodObject<{
57
58
  api_url: string;
58
59
  tenant_id: string;
59
60
  log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
61
+ namespace?: string | undefined;
60
62
  }, {
61
63
  token: string;
62
64
  tls_config: {
63
- tls_strategy?: "tls" | "mtls" | undefined;
65
+ tls_strategy?: "tls" | "mtls" | "none" | undefined;
64
66
  cert_file?: string | undefined;
65
67
  ca_file?: string | undefined;
66
68
  key_file?: string | undefined;
@@ -70,6 +72,7 @@ export declare const ClientConfigSchema: z.ZodObject<{
70
72
  api_url: string;
71
73
  tenant_id: string;
72
74
  log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
75
+ namespace?: string | undefined;
73
76
  }>;
74
77
  export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
75
78
  credentials?: ChannelCredentials;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClientConfigSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const ClientTLSConfigSchema = zod_1.z.object({
6
- tls_strategy: zod_1.z.enum(['tls', 'mtls']).optional(),
6
+ tls_strategy: zod_1.z.enum(['tls', 'mtls', 'none']).optional(),
7
7
  cert_file: zod_1.z.string().optional(),
8
8
  ca_file: zod_1.z.string().optional(),
9
9
  key_file: zod_1.z.string().optional(),
@@ -16,4 +16,5 @@ exports.ClientConfigSchema = zod_1.z.object({
16
16
  api_url: zod_1.z.string(),
17
17
  log_level: zod_1.z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
18
18
  tenant_id: zod_1.z.string(),
19
+ namespace: zod_1.z.string().optional(),
19
20
  });
@@ -22,7 +22,7 @@ export declare class Worker {
22
22
  handleKill?: boolean;
23
23
  maxRuns?: number;
24
24
  });
25
- registerWorkflow(workflow: Workflow): Promise<void>;
25
+ registerWorkflow(initWorkflow: Workflow): Promise<void>;
26
26
  registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
27
27
  handleStartStepRun(action: Action): void;
28
28
  handleStartGroupKeyRun(action: Action): void;
@@ -32,7 +32,7 @@ class Worker {
32
32
  this.futures = {};
33
33
  this.contexts = {};
34
34
  this.client = client;
35
- this.name = options.name;
35
+ this.name = this.client.config.namespace + options.name;
36
36
  this.action_registry = {};
37
37
  this.maxRuns = options.maxRuns;
38
38
  process.on('SIGTERM', () => this.exitGracefully(true));
@@ -41,9 +41,10 @@ class Worker {
41
41
  this.handle_kill = options.handleKill === undefined ? true : options.handleKill;
42
42
  this.logger = new logger_1.Logger(`Worker/${this.name}`, this.client.config.log_level);
43
43
  }
44
- registerWorkflow(workflow) {
44
+ registerWorkflow(initWorkflow) {
45
45
  var _a, _b;
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
47
48
  try {
48
49
  const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
49
50
  ? {
@@ -56,7 +57,7 @@ class Worker {
56
57
  name: workflow.id,
57
58
  description: workflow.description,
58
59
  version: workflow.version || '',
59
- eventTriggers: workflow.on.event ? [workflow.on.event] : [],
60
+ eventTriggers: workflow.on.event ? [this.client.config.namespace + workflow.on.event] : [],
60
61
  cronTriggers: workflow.on.cron ? [workflow.on.cron] : [],
61
62
  scheduledTriggers: [],
62
63
  concurrency,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json",
35
35
  "example:event": "npm run exec -- ./examples/example-event.ts",
36
36
  "example:event-listen": "npm run exec -- ./examples/example-event-with-results.ts",
37
+ "worker:namespaced": "npm run exec -- ./examples/namespaced-worker.ts",
37
38
  "worker:simple": "npm run exec -- ./examples/simple-worker.ts",
38
39
  "manual:trigger": "npm run exec -- ./examples/manual-trigger.ts",
39
40
  "worker:dag": "npm run exec -- ./examples/dag-worker.ts",
@@ -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(override, config) {
37
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
37
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
38
38
  const yaml = this.loadYamlConfig(config === null || config === void 0 ? void 0 : config.path);
39
39
  const tlsConfig = (_a = override === null || override === void 0 ? void 0 : override.tls_config) !== null && _a !== void 0 ? _a : {
40
40
  tls_strategy: (_d = (_c = (_b = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _b === void 0 ? void 0 : _b.tls_strategy) !== null && _c !== void 0 ? _c : this.env('HATCHET_CLIENT_TLS_STRATEGY')) !== null && _d !== void 0 ? _d : 'tls',
@@ -44,6 +44,9 @@ class ConfigLoader {
44
44
  server_name: (_m = (_l = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _l === void 0 ? void 0 : _l.server_name) !== null && _m !== void 0 ? _m : this.env('HATCHET_CLIENT_TLS_SERVER_NAME'),
45
45
  };
46
46
  const token = (_p = (_o = override === null || override === void 0 ? void 0 : override.token) !== null && _o !== void 0 ? _o : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _p !== void 0 ? _p : this.env('HATCHET_CLIENT_TOKEN');
47
+ if (!token) {
48
+ throw new Error('No token provided. Provide it by setting the HATCHET_CLIENT_TOKEN environment variable.');
49
+ }
47
50
  let grpcBroadcastAddress;
48
51
  let apiUrl;
49
52
  const tenantId = (0, token_1.getTenantIdFromJWT)(token);
@@ -61,19 +64,25 @@ class ConfigLoader {
61
64
  grpcBroadcastAddress = (_v = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _v !== void 0 ? _v : this.env('HATCHET_CLIENT_HOST_PORT');
62
65
  apiUrl = (_x = (_w = override === null || override === void 0 ? void 0 : override.api_url) !== null && _w !== void 0 ? _w : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _x !== void 0 ? _x : this.env('HATCHET_CLIENT_API_URL');
63
66
  }
67
+ const namespace = (_z = (_y = override === null || override === void 0 ? void 0 : override.namespace) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_NAMESPACE');
64
68
  return {
65
- token: (_z = (_y = override === null || override === void 0 ? void 0 : override.token) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_TOKEN'),
69
+ token: (_1 = (_0 = override === null || override === void 0 ? void 0 : override.token) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_TOKEN'),
66
70
  host_port: grpcBroadcastAddress,
67
71
  api_url: apiUrl,
68
72
  tls_config: tlsConfig,
69
- log_level: (_2 = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _2 !== void 0 ? _2 : 'INFO',
73
+ log_level: (_4 = (_3 = (_2 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _4 !== void 0 ? _4 : 'INFO',
70
74
  tenant_id: tenantId,
75
+ namespace: namespace ? `${namespace}_` : '',
71
76
  };
72
77
  }
73
78
  static get default_yaml_config_path() {
74
79
  return p.join(process.cwd(), DEFAULT_CONFIG_FILE);
75
80
  }
76
81
  static createCredentials(config) {
82
+ // if none, create insecure credentials
83
+ if (config.tls_strategy === 'none') {
84
+ return nice_grpc_1.ChannelCredentials.createInsecure();
85
+ }
77
86
  if (config.tls_strategy === 'tls') {
78
87
  const rootCerts = config.ca_file ? (0, fs_1.readFileSync)(config.ca_file) : undefined;
79
88
  return nice_grpc_1.ChannelCredentials.createSsl(rootCerts);