@hatchet-dev/typescript-sdk 0.1.12 → 0.1.14

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/step.d.ts CHANGED
@@ -3,32 +3,38 @@ export declare const CreateStepSchema: z.ZodObject<{
3
3
  name: z.ZodString;
4
4
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
5
5
  timeout: z.ZodOptional<z.ZodString>;
6
+ retries: z.ZodOptional<z.ZodNumber>;
6
7
  }, "strip", z.ZodTypeAny, {
7
8
  name: string;
8
9
  parents?: string[] | undefined;
9
10
  timeout?: string | undefined;
11
+ retries?: number | undefined;
10
12
  }, {
11
13
  name: string;
12
14
  parents?: string[] | undefined;
13
15
  timeout?: string | undefined;
16
+ retries?: number | undefined;
14
17
  }>;
15
18
  export type NextStep = {
16
19
  [key: string]: string;
17
20
  };
18
- interface ContextData<T = unknown> {
21
+ interface ContextData<T, K> {
19
22
  input: T;
20
23
  parents: Record<string, any>;
21
- triggered_by_event: string;
24
+ triggered_by: string;
25
+ user_data: K;
22
26
  }
23
- export declare class Context<T = unknown> {
24
- data: ContextData<T>;
27
+ export declare class Context<T, K> {
28
+ data: ContextData<T, K>;
25
29
  controller: AbortController;
26
30
  constructor(payload: string);
27
31
  stepOutput(step: string): string;
28
32
  triggeredByEvent(): boolean;
29
- workflowInput(): any;
33
+ workflowInput(): T;
34
+ userData(): K;
30
35
  }
31
- export interface CreateStep<T> extends z.infer<typeof CreateStepSchema> {
32
- run: (ctx: Context) => Promise<NextStep> | NextStep | void;
36
+ export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep> | NextStep | void;
37
+ export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
38
+ run: StepRunFunction<T, K>;
33
39
  }
34
40
  export {};
package/step.js CHANGED
@@ -34,6 +34,7 @@ exports.CreateStepSchema = z.object({
34
34
  name: z.string(),
35
35
  parents: z.array(z.string()).optional(),
36
36
  timeout: workflow_1.HatchetTimeoutSchema.optional(),
37
+ retries: z.number().optional(),
37
38
  });
38
39
  class Context {
39
40
  constructor(payload) {
@@ -56,11 +57,15 @@ class Context {
56
57
  }
57
58
  triggeredByEvent() {
58
59
  var _a;
59
- return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.triggered_by_event) === 'event';
60
+ return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.triggered_by) === 'event';
60
61
  }
61
62
  workflowInput() {
62
63
  var _a;
63
- return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.input) || {};
64
+ return (_a = this.data) === null || _a === void 0 ? void 0 : _a.input;
65
+ }
66
+ userData() {
67
+ var _a;
68
+ return (_a = this.data) === null || _a === void 0 ? void 0 : _a.user_data;
64
69
  }
65
70
  }
66
71
  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 = (_q = yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _q !== void 0 ? _q : this.env('HATCHET_CLIENT_HOST_PORT');
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: (_r = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _r !== void 0 ? _r : this.env('HATCHET_CLIENT_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: (_t = (_s = yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _s !== void 0 ? _s : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _t !== void 0 ? _t : 'INFO',
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,3 +1,4 @@
1
+ export declare function getTenantIdFromJWT(token: string): string;
1
2
  export declare function getAddressesFromJWT(token: string): {
2
3
  serverUrl: string;
3
4
  grpcBroadcastAddress: string;
@@ -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
@@ -5,14 +5,17 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
5
5
  name: z.ZodString;
6
6
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
7
7
  timeout: z.ZodOptional<z.ZodString>;
8
+ retries: z.ZodOptional<z.ZodNumber>;
8
9
  }, "strip", z.ZodTypeAny, {
9
10
  name: string;
10
11
  parents?: string[] | undefined;
11
12
  timeout?: string | undefined;
13
+ retries?: number | undefined;
12
14
  }, {
13
15
  name: string;
14
16
  parents?: string[] | undefined;
15
17
  timeout?: string | undefined;
18
+ retries?: number | undefined;
16
19
  }>, "many">;
17
20
  export type Steps = z.infer<typeof StepsSchema>;
18
21
  export declare const ConcurrencyLimitStrategy: typeof PbConcurrencyLimitStrategy;
@@ -58,14 +61,17 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
58
61
  name: z.ZodString;
59
62
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
60
63
  timeout: z.ZodOptional<z.ZodString>;
64
+ retries: z.ZodOptional<z.ZodNumber>;
61
65
  }, "strip", z.ZodTypeAny, {
62
66
  name: string;
63
67
  parents?: string[] | undefined;
64
68
  timeout?: string | undefined;
69
+ retries?: number | undefined;
65
70
  }, {
66
71
  name: string;
67
72
  parents?: string[] | undefined;
68
73
  timeout?: string | undefined;
74
+ retries?: number | undefined;
69
75
  }>, "many">;
70
76
  }, "strip", z.ZodTypeAny, {
71
77
  description: string;
@@ -73,6 +79,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
73
79
  name: string;
74
80
  parents?: string[] | undefined;
75
81
  timeout?: string | undefined;
82
+ retries?: number | undefined;
76
83
  }[];
77
84
  id: string;
78
85
  on: {
@@ -90,6 +97,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
90
97
  name: string;
91
98
  parents?: string[] | undefined;
92
99
  timeout?: string | undefined;
100
+ retries?: number | undefined;
93
101
  }[];
94
102
  id: string;
95
103
  on: {
@@ -106,6 +114,6 @@ export interface Workflow extends z.infer<typeof CreateWorkflowSchema> {
106
114
  concurrency?: z.infer<typeof WorkflowConcurrency> & {
107
115
  key: (ctx: any) => string;
108
116
  };
109
- steps: CreateStep<any>[];
117
+ steps: CreateStep<any, any>[];
110
118
  }
111
119
  export {};