@hatchet-dev/typescript-sdk 0.1.11 → 0.1.12
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.
|
@@ -79,7 +79,7 @@ class HatchetClient {
|
|
|
79
79
|
// Initializes a new Client instance.
|
|
80
80
|
// Loads config in the following order: config param > yaml file > env vars
|
|
81
81
|
var _a;
|
|
82
|
-
const loaded = config_loader_1.ConfigLoader.
|
|
82
|
+
const loaded = config_loader_1.ConfigLoader.loadClientConfig({
|
|
83
83
|
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
84
84
|
});
|
|
85
85
|
try {
|
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.12",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"yaml": "^2.3.4",
|
|
73
73
|
"zod": "^3.22.4"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
|
@@ -4,10 +4,10 @@ interface LoadClientConfigOptions {
|
|
|
4
4
|
path?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare class ConfigLoader {
|
|
7
|
-
static
|
|
7
|
+
static loadClientConfig(config?: LoadClientConfigOptions): Partial<ClientConfig>;
|
|
8
8
|
static get default_yaml_config_path(): string;
|
|
9
9
|
static createCredentials(config: ClientConfig['tls_config']): ChannelCredentials;
|
|
10
|
-
static
|
|
10
|
+
static loadYamlConfig(path?: string): ClientConfig | undefined;
|
|
11
11
|
private static env;
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
@@ -30,11 +30,12 @@ const p = __importStar(require("path"));
|
|
|
30
30
|
const zod_1 = require("zod");
|
|
31
31
|
const hatchet_client_1 = require("../../clients/hatchet-client");
|
|
32
32
|
const nice_grpc_1 = require("nice-grpc");
|
|
33
|
+
const token_1 = require("./token");
|
|
33
34
|
const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
|
|
34
35
|
class ConfigLoader {
|
|
35
|
-
static
|
|
36
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
37
|
-
const yaml = this.
|
|
36
|
+
static loadClientConfig(config) {
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
38
|
+
const yaml = this.loadYamlConfig(config === null || config === void 0 ? void 0 : config.path);
|
|
38
39
|
const tlsConfig = {
|
|
39
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',
|
|
40
41
|
cert_file: (_e = (_d = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _d === void 0 ? void 0 : _d.cert_file) !== null && _e !== void 0 ? _e : this.env('HATCHET_CLIENT_TLS_CERT_FILE'),
|
|
@@ -42,11 +43,21 @@ class ConfigLoader {
|
|
|
42
43
|
ca_file: (_j = (_h = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _h === void 0 ? void 0 : _h.ca_file) !== null && _j !== void 0 ? _j : this.env('HATCHET_CLIENT_TLS_ROOT_CA_FILE'),
|
|
43
44
|
server_name: (_l = (_k = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _k === void 0 ? void 0 : _k.server_name) !== null && _l !== void 0 ? _l : this.env('HATCHET_CLIENT_TLS_SERVER_NAME'),
|
|
44
45
|
};
|
|
46
|
+
const token = (_m = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _m !== void 0 ? _m : this.env('HATCHET_CLIENT_TOKEN');
|
|
47
|
+
let grpcBroadcastAddress;
|
|
48
|
+
try {
|
|
49
|
+
const addresses = (0, token_1.getAddressesFromJWT)(token);
|
|
50
|
+
grpcBroadcastAddress =
|
|
51
|
+
(_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;
|
|
52
|
+
}
|
|
53
|
+
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');
|
|
55
|
+
}
|
|
45
56
|
return {
|
|
46
|
-
token: (
|
|
47
|
-
host_port:
|
|
57
|
+
token: (_r = yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _r !== void 0 ? _r : this.env('HATCHET_CLIENT_TOKEN'),
|
|
58
|
+
host_port: grpcBroadcastAddress,
|
|
48
59
|
tls_config: tlsConfig,
|
|
49
|
-
log_level: (
|
|
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',
|
|
50
61
|
};
|
|
51
62
|
}
|
|
52
63
|
static get default_yaml_config_path() {
|
|
@@ -62,7 +73,7 @@ class ConfigLoader {
|
|
|
62
73
|
const certChain = config.cert_file ? (0, fs_1.readFileSync)(config.cert_file) : null;
|
|
63
74
|
return nice_grpc_1.ChannelCredentials.createSsl(rootCerts, privateKey, certChain);
|
|
64
75
|
}
|
|
65
|
-
static
|
|
76
|
+
static loadYamlConfig(path) {
|
|
66
77
|
try {
|
|
67
78
|
const configFile = (0, fs_1.readFileSync)(p.join(__dirname, path !== null && path !== void 0 ? path : this.default_yaml_config_path), 'utf8');
|
|
68
79
|
const config = (0, yaml_1.parse)(configFile);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressesFromJWT = void 0;
|
|
4
|
+
function getAddressesFromJWT(token) {
|
|
5
|
+
const claims = extractClaimsFromJWT(token);
|
|
6
|
+
return {
|
|
7
|
+
serverUrl: claims.server_url,
|
|
8
|
+
grpcBroadcastAddress: claims.grpc_broadcast_address,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.getAddressesFromJWT = getAddressesFromJWT;
|
|
12
|
+
function extractClaimsFromJWT(token) {
|
|
13
|
+
const parts = token.split('.');
|
|
14
|
+
if (parts.length !== 3) {
|
|
15
|
+
throw new Error('Invalid token format');
|
|
16
|
+
}
|
|
17
|
+
const claimsPart = parts[1];
|
|
18
|
+
const claimsData = atob(claimsPart.replace(/-/g, '+').replace(/_/g, '/'));
|
|
19
|
+
const claims = JSON.parse(claimsData);
|
|
20
|
+
return claims;
|
|
21
|
+
}
|