@temporalio/envconfig 1.13.2
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/LICENSE.md +23 -0
- package/README.md +5 -0
- package/lib/envconfig-toml.d.ts +57 -0
- package/lib/envconfig-toml.js +279 -0
- package/lib/envconfig-toml.js.map +1 -0
- package/lib/envconfig.d.ts +9 -0
- package/lib/envconfig.js +63 -0
- package/lib/envconfig.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +111 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +48 -0
- package/lib/utils.js +164 -0
- package/lib/utils.js.map +1 -0
- package/package.json +43 -0
- package/src/envconfig-toml.ts +341 -0
- package/src/envconfig.ts +78 -0
- package/src/index.ts +20 -0
- package/src/types.ts +116 -0
- package/src/utils.ts +172 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Temporal TypeScript SDK
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Temporal Technologies Inc. All Rights Reserved
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# `@temporalio/envconfig`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@temporalio/envconfig)
|
|
4
|
+
|
|
5
|
+
Part of [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/typescript/introduction/).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LoadClientConfigOptions, LoadClientProfileOptions } from './types';
|
|
2
|
+
export declare function normalizeGrpcMetaKey(key: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Raw TOML structure representing the client configuration file.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
8
|
+
*/
|
|
9
|
+
export interface TomlClientConfig {
|
|
10
|
+
profile: Record<string, TomlClientConfigProfile>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Raw TOML structure for a client configuration profile.
|
|
14
|
+
* Note: field names use snake_case to match TOML file fields for correct parser deserialization.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
18
|
+
*/
|
|
19
|
+
export interface TomlClientConfigProfile {
|
|
20
|
+
address?: string;
|
|
21
|
+
namespace?: string;
|
|
22
|
+
api_key?: string;
|
|
23
|
+
tls?: TomlClientConfigTLS;
|
|
24
|
+
codec?: TomlClientConfigCodec;
|
|
25
|
+
grpc_meta?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Raw TOML structure for client configuration TLS.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
32
|
+
*/
|
|
33
|
+
export interface TomlClientConfigTLS {
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
client_cert_path?: string;
|
|
36
|
+
client_cert_data?: string;
|
|
37
|
+
client_key_path?: string;
|
|
38
|
+
client_key_data?: string;
|
|
39
|
+
server_ca_cert_path?: string;
|
|
40
|
+
server_ca_cert_data?: string;
|
|
41
|
+
server_name?: string;
|
|
42
|
+
disable_host_verification?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Raw TOML structure for client configuration codec.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
49
|
+
*/
|
|
50
|
+
export interface TomlClientConfigCodec {
|
|
51
|
+
endpoint?: string;
|
|
52
|
+
auth?: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function tomlLoadClientConfig(options: LoadClientConfigOptions): TomlClientConfig;
|
|
55
|
+
export declare function loadFromTomlData(tomlData: string, isStrict: boolean): TomlClientConfig;
|
|
56
|
+
export declare function configToTomlData(config: TomlClientConfig): Uint8Array;
|
|
57
|
+
export declare function tomlLoadClientConfigProfile(options: LoadClientProfileOptions): TomlClientConfigProfile;
|
|
@@ -0,0 +1,279 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.normalizeGrpcMetaKey = normalizeGrpcMetaKey;
|
|
27
|
+
exports.tomlLoadClientConfig = tomlLoadClientConfig;
|
|
28
|
+
exports.loadFromTomlData = loadFromTomlData;
|
|
29
|
+
exports.configToTomlData = configToTomlData;
|
|
30
|
+
exports.tomlLoadClientConfigProfile = tomlLoadClientConfigProfile;
|
|
31
|
+
const fs_1 = require("fs");
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const os = __importStar(require("os"));
|
|
34
|
+
const smol_toml_1 = require("smol-toml");
|
|
35
|
+
const objects_helpers_1 = require("@temporalio/common/lib/internal-workflow/objects-helpers");
|
|
36
|
+
const encoding_1 = require("@temporalio/common/lib/encoding");
|
|
37
|
+
function normalizeGrpcMetaKey(key) {
|
|
38
|
+
return key.toLocaleLowerCase().replace('_', '-');
|
|
39
|
+
}
|
|
40
|
+
function sourceToStringData(source) {
|
|
41
|
+
if (source === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if ('path' in source) {
|
|
45
|
+
return (0, fs_1.readFileSync)(source.path, { encoding: 'utf-8' });
|
|
46
|
+
}
|
|
47
|
+
if (typeof source.data === 'string') {
|
|
48
|
+
return source.data;
|
|
49
|
+
}
|
|
50
|
+
return (0, encoding_1.decode)(source.data);
|
|
51
|
+
}
|
|
52
|
+
function tomlLoadClientConfig(options) {
|
|
53
|
+
const envProvider = options.overrideEnvVars ?? process.env;
|
|
54
|
+
let configData = undefined;
|
|
55
|
+
try {
|
|
56
|
+
configData = sourceToStringData(options.configSource) ?? getFallbackConfigData(envProvider);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const isFileNotFound = error?.code === 'ENOENT';
|
|
60
|
+
if (!isFileNotFound) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
// File not found is ok
|
|
64
|
+
}
|
|
65
|
+
if (configData !== undefined) {
|
|
66
|
+
return loadFromTomlData(configData, options.configFileStrict ?? false);
|
|
67
|
+
}
|
|
68
|
+
return { profile: {} }; // default ClientConfig
|
|
69
|
+
}
|
|
70
|
+
function loadFromTomlData(tomlData, isStrict) {
|
|
71
|
+
const parsed = (0, smol_toml_1.parse)(tomlData);
|
|
72
|
+
if (isStrict) {
|
|
73
|
+
strictValidateTomlStructure(parsed);
|
|
74
|
+
}
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
77
|
+
function configToTomlData(config) {
|
|
78
|
+
return (0, encoding_1.encode)((0, smol_toml_1.stringify)(config));
|
|
79
|
+
}
|
|
80
|
+
function strictValidateTomlStructure(parsed) {
|
|
81
|
+
const allowedTopLevel = new Set(['profile']);
|
|
82
|
+
const allowedProfile = new Set(['address', 'namespace', 'api_key', 'tls', 'codec', 'grpc_meta']);
|
|
83
|
+
const allowedTLS = new Set([
|
|
84
|
+
'disabled',
|
|
85
|
+
'client_cert_path',
|
|
86
|
+
'client_key_path',
|
|
87
|
+
'client_cert_data',
|
|
88
|
+
'client_key_data',
|
|
89
|
+
'server_ca_cert_path',
|
|
90
|
+
'server_ca_cert_data',
|
|
91
|
+
'server_name',
|
|
92
|
+
]);
|
|
93
|
+
const allowedCodec = new Set(['endpoint', 'auth']);
|
|
94
|
+
// Check top-level keys
|
|
95
|
+
const unknownTopLevel = Object.keys(parsed).filter((k) => !allowedTopLevel.has(k));
|
|
96
|
+
if (unknownTopLevel.length > 0) {
|
|
97
|
+
throw new Error(`Validation error: key(s) unrecognized: ${unknownTopLevel.join(', ')}`);
|
|
98
|
+
}
|
|
99
|
+
const profiles = parsed.profile;
|
|
100
|
+
if (profiles === undefined)
|
|
101
|
+
return;
|
|
102
|
+
// Ensure it's a TomlTable (not a primitive or array)
|
|
103
|
+
if (typeof profiles !== 'object' || Array.isArray(profiles)) {
|
|
104
|
+
throw new Error('Validation error: profile must be a table');
|
|
105
|
+
}
|
|
106
|
+
for (const [profileName, profileData] of Object.entries(profiles)) {
|
|
107
|
+
// Ensure profile is a table
|
|
108
|
+
if (typeof profileData !== 'object' || Array.isArray(profileData)) {
|
|
109
|
+
throw new Error(`Validation error: profile.${profileName} must be a table`);
|
|
110
|
+
}
|
|
111
|
+
const unknownProfile = Object.keys(profileData).filter((k) => !allowedProfile.has(k));
|
|
112
|
+
if (unknownProfile.length > 0) {
|
|
113
|
+
throw new Error(`Validation error: key(s) unrecognized in profile.${profileName}: ${unknownProfile.join(', ')}`);
|
|
114
|
+
}
|
|
115
|
+
// Validate TLS
|
|
116
|
+
const tls = profileData.tls;
|
|
117
|
+
if (tls !== undefined) {
|
|
118
|
+
if (typeof tls !== 'object' || Array.isArray(tls)) {
|
|
119
|
+
throw new Error(`Validation error: profile.${profileName}.tls must be a table`);
|
|
120
|
+
}
|
|
121
|
+
const unknownTLS = Object.keys(tls).filter((k) => !allowedTLS.has(k));
|
|
122
|
+
if (unknownTLS.length > 0) {
|
|
123
|
+
throw new Error(`Validation error: key(s) unrecognized in profile.${profileName}.tls: ${unknownTLS.join(', ')}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Validate codec
|
|
127
|
+
const codec = profileData.codec;
|
|
128
|
+
if (codec !== undefined) {
|
|
129
|
+
if (typeof codec !== 'object' || Array.isArray(codec)) {
|
|
130
|
+
throw new Error(`Validation error: profile.${profileName}.codec must be a table`);
|
|
131
|
+
}
|
|
132
|
+
const unknownCodec = Object.keys(codec).filter((k) => !allowedCodec.has(k));
|
|
133
|
+
if (unknownCodec.length > 0) {
|
|
134
|
+
throw new Error(`Validation error: key(s) unrecognized in profile.${profileName}.codec: ${unknownCodec.join(', ')}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getFallbackConfigData(envProvider) {
|
|
140
|
+
// configSource was not set - fallback to TEMPORAL_CONFIG_FILE, then the default file path
|
|
141
|
+
let filePath = envProvider['TEMPORAL_CONFIG_FILE'];
|
|
142
|
+
if (filePath === undefined) {
|
|
143
|
+
filePath = getDefaultConfigFilePath();
|
|
144
|
+
}
|
|
145
|
+
return (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
|
|
146
|
+
}
|
|
147
|
+
function tomlLoadClientConfigProfile(options) {
|
|
148
|
+
if (options.disableEnv && options.disableFile) {
|
|
149
|
+
throw new Error('Cannot disable both file and environment loading');
|
|
150
|
+
}
|
|
151
|
+
const envProvider = options.overrideEnvVars ?? process.env;
|
|
152
|
+
let profile = {};
|
|
153
|
+
if (!options.disableFile) {
|
|
154
|
+
const tomlClientConfig = tomlLoadClientConfig({
|
|
155
|
+
configSource: options.configSource,
|
|
156
|
+
configFileStrict: options.configFileStrict,
|
|
157
|
+
overrideEnvVars: options.overrideEnvVars,
|
|
158
|
+
});
|
|
159
|
+
// If profile name not provided, fallback to env variable.
|
|
160
|
+
const profileName = options.profile ?? envProvider['TEMPORAL_PROFILE'];
|
|
161
|
+
// If env var also not provided, fallback to default profile name.
|
|
162
|
+
const tomlProfile = tomlClientConfig.profile[profileName ?? DEFAULT_CONFIG_FILE_PROFILE];
|
|
163
|
+
// If toml profile does not exist and an explicit profile was requested, error.
|
|
164
|
+
if (tomlProfile === undefined && profileName) {
|
|
165
|
+
throw new Error(`Profile '${profileName}' not found in config data`);
|
|
166
|
+
}
|
|
167
|
+
// Use loaded profile if exists, otherwise fallback to default profile.
|
|
168
|
+
profile = tomlProfile ?? {};
|
|
169
|
+
}
|
|
170
|
+
if (!options.disableEnv) {
|
|
171
|
+
applyProfileEnvVars(profile, envProvider);
|
|
172
|
+
}
|
|
173
|
+
return profile;
|
|
174
|
+
}
|
|
175
|
+
function applyProfileEnvVars(profile, envProvider) {
|
|
176
|
+
profile.address = envProvider['TEMPORAL_ADDRESS'] ?? profile.address;
|
|
177
|
+
profile.namespace = envProvider['TEMPORAL_NAMESPACE'] ?? profile.namespace;
|
|
178
|
+
profile.api_key = envProvider['TEMPORAL_API_KEY'] ?? profile.api_key;
|
|
179
|
+
const tlsFromEnv = getTLSFromEnvVars(envProvider);
|
|
180
|
+
profile.tls = profile.tls || tlsFromEnv ? { ...profile.tls, ...tlsFromEnv } : undefined;
|
|
181
|
+
const codecFromEnv = getCodecFromEnvVars(envProvider);
|
|
182
|
+
profile.codec = profile.codec || codecFromEnv ? { ...profile.codec, ...codecFromEnv } : undefined;
|
|
183
|
+
applyGrpcMetaFromEnvVars(profile, envProvider);
|
|
184
|
+
}
|
|
185
|
+
function getTLSFromEnvVars(envProvider) {
|
|
186
|
+
const tlsConfig = (0, objects_helpers_1.filterNullAndUndefined)({
|
|
187
|
+
disabled: envVarToBool(envProvider['TEMPORAL_TLS']),
|
|
188
|
+
client_cert_path: envProvider['TEMPORAL_TLS_CLIENT_CERT_PATH'],
|
|
189
|
+
client_cert_data: envProvider['TEMPORAL_TLS_CLIENT_CERT_DATA'],
|
|
190
|
+
client_key_path: envProvider['TEMPORAL_TLS_CLIENT_KEY_PATH'],
|
|
191
|
+
client_key_data: envProvider['TEMPORAL_TLS_CLIENT_KEY_DATA'],
|
|
192
|
+
server_ca_cert_path: envProvider['TEMPORAL_TLS_SERVER_CA_CERT_PATH'],
|
|
193
|
+
server_ca_cert_data: envProvider['TEMPORAL_TLS_SERVER_CA_CERT_DATA'],
|
|
194
|
+
server_name: envProvider['TEMPORAL_TLS_SERVER_NAME'],
|
|
195
|
+
disable_host_verification: envVarToBool(envProvider['TEMPORAL_TLS_DISABLE_HOST_VERIFICATION']),
|
|
196
|
+
});
|
|
197
|
+
// If no properties were added, return undefined
|
|
198
|
+
return Object.keys(tlsConfig).length > 0 ? tlsConfig : undefined;
|
|
199
|
+
}
|
|
200
|
+
function getCodecFromEnvVars(envProvider) {
|
|
201
|
+
const codec = {};
|
|
202
|
+
const endpoint = envProvider['TEMPORAL_CODEC_ENDPOINT'];
|
|
203
|
+
if (endpoint !== undefined) {
|
|
204
|
+
codec.endpoint = endpoint;
|
|
205
|
+
}
|
|
206
|
+
const auth = envProvider['TEMPORAL_CODEC_AUTH'];
|
|
207
|
+
if (auth !== undefined) {
|
|
208
|
+
codec.auth = auth;
|
|
209
|
+
}
|
|
210
|
+
// If no properties were added, return undefined
|
|
211
|
+
return Object.keys(codec).length > 0 ? codec : undefined;
|
|
212
|
+
}
|
|
213
|
+
function applyGrpcMetaFromEnvVars(profile, envProvider) {
|
|
214
|
+
const PREFIX = 'TEMPORAL_GRPC_META_';
|
|
215
|
+
for (const [key, value] of Object.entries(envProvider)) {
|
|
216
|
+
if (key.startsWith(PREFIX)) {
|
|
217
|
+
const headerName = key.slice(PREFIX.length);
|
|
218
|
+
const normalizedKey = normalizeGrpcMetaKey(headerName);
|
|
219
|
+
if (profile.grpc_meta === undefined) {
|
|
220
|
+
profile.grpc_meta = {};
|
|
221
|
+
}
|
|
222
|
+
// Empty values remove the key, non-empty values set it
|
|
223
|
+
if (value === '' || value == null) {
|
|
224
|
+
delete profile.grpc_meta[normalizedKey];
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
profile.grpc_meta[normalizedKey] = value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function envVarToBool(envVar) {
|
|
233
|
+
if (envVar === undefined) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
return envVar === '1' || envVar === 'true';
|
|
237
|
+
}
|
|
238
|
+
const DEFAULT_CONFIG_FILE_PROFILE = 'default';
|
|
239
|
+
const DEFAULT_CONFIG_FILE = 'config.toml';
|
|
240
|
+
function getDefaultConfigFilePath() {
|
|
241
|
+
const configDir = getUserConfigDir();
|
|
242
|
+
const configPath = path.join(configDir, 'temporalio', DEFAULT_CONFIG_FILE);
|
|
243
|
+
return configPath;
|
|
244
|
+
}
|
|
245
|
+
function getUserConfigDir() {
|
|
246
|
+
const platform = os.platform();
|
|
247
|
+
switch (platform) {
|
|
248
|
+
case 'win32': {
|
|
249
|
+
const dir = process.env.APPDATA;
|
|
250
|
+
if (!dir) {
|
|
251
|
+
throw new Error('%AppData% is not defined');
|
|
252
|
+
}
|
|
253
|
+
return dir;
|
|
254
|
+
}
|
|
255
|
+
case 'darwin': {
|
|
256
|
+
const dir = process.env.HOME;
|
|
257
|
+
if (!dir) {
|
|
258
|
+
throw new Error('$HOME is not defined');
|
|
259
|
+
}
|
|
260
|
+
return path.join(dir, 'Library', 'Application Support');
|
|
261
|
+
}
|
|
262
|
+
default: {
|
|
263
|
+
// Unix/Linux
|
|
264
|
+
let dir = process.env.XDG_CONFIG_HOME;
|
|
265
|
+
if (!dir) {
|
|
266
|
+
const home = process.env.HOME;
|
|
267
|
+
if (!home) {
|
|
268
|
+
throw new Error('neither $XDG_CONFIG_HOME nor $HOME are defined');
|
|
269
|
+
}
|
|
270
|
+
dir = path.join(home, '.config');
|
|
271
|
+
}
|
|
272
|
+
else if (!path.isAbsolute(dir)) {
|
|
273
|
+
throw new Error('path in $XDG_CONFIG_HOME is relative');
|
|
274
|
+
}
|
|
275
|
+
return dir;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=envconfig-toml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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,GAAG,CAAC,IAAI,CAAC;YAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,aAAa;YACb,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;YACtC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;gBAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;gBACpE,CAAC;gBACD,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACnC,CAAC;iBAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
|
|
2
|
+
import { ClientConfig, ClientConfigFromTomlOptions, ClientConfigProfile, ClientConfigTLS, ClientConnectConfig, LoadClientConfigOptions, LoadClientProfileOptions } from './types';
|
|
3
|
+
export declare function loadClientConfig(options: LoadClientConfigOptions): ClientConfig;
|
|
4
|
+
export declare function loadClientConfigFromToml(tomlData: Uint8Array, options: ClientConfigFromTomlOptions): ClientConfig;
|
|
5
|
+
export declare function clientConfigToToml(config: ClientConfig): Uint8Array;
|
|
6
|
+
export declare function loadClientConfigProfile(options?: LoadClientProfileOptions): ClientConfigProfile;
|
|
7
|
+
export declare function loadClientConnectConfig(options?: LoadClientProfileOptions): ClientConnectConfig;
|
|
8
|
+
export declare function toClientOptions(profile: ClientConfigProfile): ClientConnectConfig;
|
|
9
|
+
export declare function toTLSConfig(config?: ClientConfigTLS): TLSConfig | boolean | undefined;
|
package/lib/envconfig.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadClientConfig = loadClientConfig;
|
|
4
|
+
exports.loadClientConfigFromToml = loadClientConfigFromToml;
|
|
5
|
+
exports.clientConfigToToml = clientConfigToToml;
|
|
6
|
+
exports.loadClientConfigProfile = loadClientConfigProfile;
|
|
7
|
+
exports.loadClientConnectConfig = loadClientConnectConfig;
|
|
8
|
+
exports.toClientOptions = toClientOptions;
|
|
9
|
+
exports.toTLSConfig = toTLSConfig;
|
|
10
|
+
const encoding_1 = require("@temporalio/common/lib/encoding");
|
|
11
|
+
const envconfig_toml_1 = require("./envconfig-toml");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
function loadClientConfig(options) {
|
|
14
|
+
return (0, utils_1.fromTomlConfig)((0, envconfig_toml_1.tomlLoadClientConfig)(options));
|
|
15
|
+
}
|
|
16
|
+
function loadClientConfigFromToml(tomlData, options) {
|
|
17
|
+
return (0, utils_1.fromTomlConfig)((0, envconfig_toml_1.loadFromTomlData)((0, encoding_1.decode)(tomlData), options.strict));
|
|
18
|
+
}
|
|
19
|
+
function clientConfigToToml(config) {
|
|
20
|
+
return (0, envconfig_toml_1.configToTomlData)((0, utils_1.toTomlConfig)(config));
|
|
21
|
+
}
|
|
22
|
+
function loadClientConfigProfile(options = {}) {
|
|
23
|
+
return (0, utils_1.fromTomlProfile)((0, envconfig_toml_1.tomlLoadClientConfigProfile)(options));
|
|
24
|
+
}
|
|
25
|
+
function loadClientConnectConfig(options = {}) {
|
|
26
|
+
return toClientOptions(loadClientConfigProfile(options));
|
|
27
|
+
}
|
|
28
|
+
function toClientOptions(profile) {
|
|
29
|
+
// TLS is enabled if we have an explicit TLS config, or if an api key is provided.
|
|
30
|
+
const tls = toTLSConfig(profile.tls) ?? (profile.apiKey !== undefined ? true : undefined);
|
|
31
|
+
return {
|
|
32
|
+
namespace: profile.namespace,
|
|
33
|
+
connectionOptions: {
|
|
34
|
+
address: profile.address,
|
|
35
|
+
apiKey: profile.apiKey,
|
|
36
|
+
tls,
|
|
37
|
+
metadata: profile.grpcMeta,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function toTLSConfig(config) {
|
|
42
|
+
if (config === undefined) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
if (config.disabled === true) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const serverRootCACert = (0, utils_1.loadConfigData)(config.serverCACert);
|
|
49
|
+
const crtBuffer = (0, utils_1.loadConfigData)(config.clientCert);
|
|
50
|
+
const keyBuffer = (0, utils_1.loadConfigData)(config.clientKey);
|
|
51
|
+
const tlsConfig = {
|
|
52
|
+
serverNameOverride: config.serverName,
|
|
53
|
+
serverRootCACertificate: serverRootCACert,
|
|
54
|
+
clientCertPair: crtBuffer && keyBuffer
|
|
55
|
+
? {
|
|
56
|
+
crt: crtBuffer,
|
|
57
|
+
key: keyBuffer,
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
};
|
|
61
|
+
return tlsConfig;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=envconfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envconfig.js","sourceRoot":"","sources":["../src/envconfig.ts"],"names":[],"mappings":";;AAmBA,4CAEC;AAED,4DAEC;AAED,gDAEC;AAED,0DAEC;AAED,0DAEC;AAED,0CAYC;AAED,kCAwBC;AA5ED,8DAAyD;AACzD,qDAK0B;AAU1B,mCAAwF;AAExF,SAAgB,gBAAgB,CAAC,OAAgC;IAC/D,OAAO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,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,SAAS,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAEnD,MAAM,SAAS,GAAc;QAC3B,kBAAkB,EAAE,MAAM,CAAC,UAAU;QACrC,uBAAuB,EAAE,gBAAgB;QACzC,cAAc,EACZ,SAAS,IAAI,SAAS;YACpB,CAAC,CAAC;gBACE,GAAG,EAAE,SAAS;gBACd,GAAG,EAAE,SAAS;aACf;YACH,CAAC,CAAC,SAAS;KAChB,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { loadClientConfig, loadClientConfigProfile, loadClientConnectConfig, loadClientConfigFromToml, clientConfigToToml, toClientOptions, } from './envconfig';
|
|
2
|
+
export { ClientConfig, ClientConfigProfile, ClientConfigTLS, LoadClientConfigOptions, LoadClientProfileOptions, ClientConfigFromTomlOptions, ConfigDataSource, } from './types';
|
|
3
|
+
export { fromTomlConfig, fromTomlProfile, toTomlConfig, toTomlProfile, loadConfigData } from './utils';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfigData = exports.toTomlProfile = exports.toTomlConfig = exports.fromTomlProfile = exports.fromTomlConfig = exports.toClientOptions = exports.clientConfigToToml = exports.loadClientConfigFromToml = exports.loadClientConnectConfig = exports.loadClientConfigProfile = exports.loadClientConfig = void 0;
|
|
4
|
+
var envconfig_1 = require("./envconfig");
|
|
5
|
+
Object.defineProperty(exports, "loadClientConfig", { enumerable: true, get: function () { return envconfig_1.loadClientConfig; } });
|
|
6
|
+
Object.defineProperty(exports, "loadClientConfigProfile", { enumerable: true, get: function () { return envconfig_1.loadClientConfigProfile; } });
|
|
7
|
+
Object.defineProperty(exports, "loadClientConnectConfig", { enumerable: true, get: function () { return envconfig_1.loadClientConnectConfig; } });
|
|
8
|
+
Object.defineProperty(exports, "loadClientConfigFromToml", { enumerable: true, get: function () { return envconfig_1.loadClientConfigFromToml; } });
|
|
9
|
+
Object.defineProperty(exports, "clientConfigToToml", { enumerable: true, get: function () { return envconfig_1.clientConfigToToml; } });
|
|
10
|
+
Object.defineProperty(exports, "toClientOptions", { enumerable: true, get: function () { return envconfig_1.toClientOptions; } });
|
|
11
|
+
var utils_1 = require("./utils");
|
|
12
|
+
Object.defineProperty(exports, "fromTomlConfig", { enumerable: true, get: function () { return utils_1.fromTomlConfig; } });
|
|
13
|
+
Object.defineProperty(exports, "fromTomlProfile", { enumerable: true, get: function () { return utils_1.fromTomlProfile; } });
|
|
14
|
+
Object.defineProperty(exports, "toTomlConfig", { enumerable: true, get: function () { return utils_1.toTomlConfig; } });
|
|
15
|
+
Object.defineProperty(exports, "toTomlProfile", { enumerable: true, get: function () { return utils_1.toTomlProfile; } });
|
|
16
|
+
Object.defineProperty(exports, "loadConfigData", { enumerable: true, get: function () { return utils_1.loadConfigData; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAOqB;AANnB,6GAAA,gBAAgB,OAAA;AAChB,oHAAA,uBAAuB,OAAA;AACvB,oHAAA,uBAAuB,OAAA;AACvB,qHAAA,wBAAwB,OAAA;AACxB,+GAAA,kBAAkB,OAAA;AAClB,4GAAA,eAAe,OAAA;AAajB,iCAAuG;AAA9F,uGAAA,cAAc,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,uGAAA,cAAc,OAAA"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { NativeConnectionOptions } from '@temporalio/worker';
|
|
2
|
+
/**
|
|
3
|
+
* A data source for configuration, which can be a path to a file,
|
|
4
|
+
* the string contents of a file, or raw bytes.
|
|
5
|
+
*
|
|
6
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
7
|
+
*/
|
|
8
|
+
export type ConfigDataSource = {
|
|
9
|
+
path: string;
|
|
10
|
+
} | {
|
|
11
|
+
data: string | Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* TLS configuration as specified as part of client configuration.
|
|
15
|
+
*
|
|
16
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
17
|
+
*/
|
|
18
|
+
export interface ClientConfigTLS {
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
serverName?: string;
|
|
21
|
+
clientCert?: ConfigDataSource;
|
|
22
|
+
clientKey?: ConfigDataSource;
|
|
23
|
+
serverCACert?: ConfigDataSource;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for connecting to a Temporal client, including connection options and namespace.
|
|
27
|
+
*
|
|
28
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
29
|
+
*/
|
|
30
|
+
export interface ClientConnectConfig {
|
|
31
|
+
connectionOptions: NativeConnectionOptions;
|
|
32
|
+
namespace?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options for loading a client configuration profile.
|
|
36
|
+
*
|
|
37
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
38
|
+
*/
|
|
39
|
+
export interface LoadClientProfileOptions {
|
|
40
|
+
/** The name of the profile to load from the config. Defaults to "default". */
|
|
41
|
+
profile?: string;
|
|
42
|
+
/**
|
|
43
|
+
* If present, this is used as the configuration source instead of default
|
|
44
|
+
* file locations. This can be a path to the file or the string/byte
|
|
45
|
+
* contents of the file.
|
|
46
|
+
*/
|
|
47
|
+
configSource?: ConfigDataSource;
|
|
48
|
+
/**
|
|
49
|
+
* If true, file loading is disabled. This is only used when `configSource`
|
|
50
|
+
* is not present.
|
|
51
|
+
*/
|
|
52
|
+
disableFile?: boolean;
|
|
53
|
+
/** If true, environment variable loading and overriding is disabled. */
|
|
54
|
+
disableEnv?: boolean;
|
|
55
|
+
/** If true, will error on unrecognized keys in the TOML file. */
|
|
56
|
+
configFileStrict?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* A dictionary of environment variables to use for loading and overrides.
|
|
59
|
+
* If not provided, the current process's environment is used.
|
|
60
|
+
*/
|
|
61
|
+
overrideEnvVars?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A client configuration profile with connection settings for a Temporal client.
|
|
65
|
+
*
|
|
66
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
67
|
+
*/
|
|
68
|
+
export interface ClientConfigProfile {
|
|
69
|
+
address?: string;
|
|
70
|
+
namespace?: string;
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
tls?: ClientConfigTLS;
|
|
73
|
+
grpcMeta?: Record<string, string>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for loading client configuration.
|
|
77
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
78
|
+
*/
|
|
79
|
+
export interface LoadClientConfigOptions {
|
|
80
|
+
/**
|
|
81
|
+
* If present, this is used as the configuration source instead of default
|
|
82
|
+
* file locations. This can be a path or the string/byte contents of the
|
|
83
|
+
* configuration file.
|
|
84
|
+
*/
|
|
85
|
+
configSource?: ConfigDataSource;
|
|
86
|
+
/** If true, will error on unrecognized keys in the TOML file. */
|
|
87
|
+
configFileStrict?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The environment variables to use for locating the
|
|
90
|
+
* default config file. If not provided, the current process's
|
|
91
|
+
* environment is used to check for `TEMPORAL_CONFIG_FILE`.
|
|
92
|
+
*/
|
|
93
|
+
overrideEnvVars?: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Client configuration represents a client config file.
|
|
97
|
+
*
|
|
98
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
99
|
+
*/
|
|
100
|
+
export interface ClientConfig {
|
|
101
|
+
/** Map of profile name to its corresponding ClientConfigProfile. */
|
|
102
|
+
profiles: Record<string, ClientConfigProfile>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Options for parsing client configuration from TOML format.
|
|
106
|
+
*
|
|
107
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
108
|
+
*/
|
|
109
|
+
export interface ClientConfigFromTomlOptions {
|
|
110
|
+
strict: boolean;
|
|
111
|
+
}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ClientConfigProfile, ClientConfigTLS, ClientConfig, ConfigDataSource } from './types';
|
|
2
|
+
import { TomlClientConfig, TomlClientConfigProfile, TomlClientConfigTLS } from './envconfig-toml';
|
|
3
|
+
/**
|
|
4
|
+
* Loads configuration data from a {@link ConfigDataSource} and returns it as a Uint8Array.
|
|
5
|
+
*
|
|
6
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadConfigData(source?: ConfigDataSource): Uint8Array | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a TOML profile structure to a {@link ClientConfigProfile}.
|
|
11
|
+
*
|
|
12
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
13
|
+
*/
|
|
14
|
+
export declare function fromTomlProfile(tomlProfile: TomlClientConfigProfile): ClientConfigProfile;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a {@link ClientConfigProfile} to a TOML profile structure.
|
|
17
|
+
*
|
|
18
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toTomlProfile(profile: ClientConfigProfile): TomlClientConfigProfile;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a TOML TLS configuration structure to a {@link ClientConfigTLS}.
|
|
23
|
+
*
|
|
24
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fromTomlTLS(tomlTLS?: TomlClientConfigTLS): ClientConfigTLS | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a {@link ClientConfigTLS} to a TOML TLS configuration structure.
|
|
29
|
+
*
|
|
30
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
31
|
+
*/
|
|
32
|
+
export declare function toTomlTLS(tlsConfig?: ClientConfigTLS): TomlClientConfigTLS | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a TOML client configuration structure to a {@link ClientConfig}.
|
|
35
|
+
*
|
|
36
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fromTomlConfig(tomlConfig: TomlClientConfig): ClientConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a {@link ClientConfig} to a TOML client configuration structure.
|
|
41
|
+
*
|
|
42
|
+
* @experimental Environment configuration is new feature and subject to change.
|
|
43
|
+
*/
|
|
44
|
+
export declare function toTomlConfig(config: ClientConfig): TomlClientConfig;
|
|
45
|
+
export declare function toPathAndData(source?: ConfigDataSource): {
|
|
46
|
+
path?: string;
|
|
47
|
+
data?: Uint8Array;
|
|
48
|
+
} | undefined;
|