transloadit 4.8.0 → 4.8.1
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/README.md +51 -3
- package/dist/bearerToken.d.ts +1 -0
- package/dist/bearerToken.d.ts.map +1 -1
- package/dist/bearerToken.js +5 -3
- package/dist/bearerToken.js.map +1 -1
- package/dist/cli/commands/BaseCommand.d.ts +0 -1
- package/dist/cli/commands/BaseCommand.d.ts.map +1 -1
- package/dist/cli/commands/BaseCommand.js +7 -9
- package/dist/cli/commands/BaseCommand.js.map +1 -1
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +49 -29
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/generateIntentDocs.d.ts.map +1 -1
- package/dist/cli/generateIntentDocs.js +2 -0
- package/dist/cli/generateIntentDocs.js.map +1 -1
- package/dist/cli/helpers.d.ts +19 -4
- package/dist/cli/helpers.d.ts.map +1 -1
- package/dist/cli/helpers.js +232 -10
- package/dist/cli/helpers.js.map +1 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/bearerToken.ts +14 -3
- package/src/cli/commands/BaseCommand.ts +7 -9
- package/src/cli/commands/auth.ts +66 -32
- package/src/cli/generateIntentDocs.ts +2 -0
- package/src/cli/helpers.ts +278 -13
- package/src/cli.ts +3 -2
package/dist/cli/helpers.js
CHANGED
|
@@ -1,19 +1,241 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import fsp from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { parse as parseDotenv } from 'dotenv';
|
|
3
6
|
import { isAPIError } from "./types.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let loadedProjectDotenvPath;
|
|
8
|
+
let projectDotenvInjectedValues;
|
|
9
|
+
let projectDotenvPreviousValues;
|
|
10
|
+
let shellEnvBeforeProjectDotenv;
|
|
11
|
+
function normalizeEnvValue(value) {
|
|
12
|
+
const trimmed = value?.trim();
|
|
13
|
+
return trimmed ? trimmed : undefined;
|
|
14
|
+
}
|
|
15
|
+
function getConfiguredCredentialsFilePath() {
|
|
16
|
+
const configuredPath = normalizeEnvValue(process.env.TRANSLOADIT_CREDENTIALS_FILE);
|
|
17
|
+
if (configuredPath != null) {
|
|
18
|
+
return path.resolve(configuredPath);
|
|
19
|
+
}
|
|
20
|
+
return path.join(homedir(), '.transloadit', 'credentials');
|
|
21
|
+
}
|
|
22
|
+
function getProjectDotenvPath() {
|
|
23
|
+
return path.resolve(process.cwd(), '.env');
|
|
24
|
+
}
|
|
25
|
+
function getDisplayPath(filePath) {
|
|
26
|
+
const normalizedHome = path.resolve(homedir());
|
|
27
|
+
const normalizedFilePath = path.resolve(filePath);
|
|
28
|
+
if (normalizedFilePath === normalizedHome)
|
|
29
|
+
return '~';
|
|
30
|
+
if (normalizedFilePath.startsWith(`${normalizedHome}${path.sep}`)) {
|
|
31
|
+
return `~${normalizedFilePath.slice(normalizedHome.length)}`;
|
|
32
|
+
}
|
|
33
|
+
return normalizedFilePath;
|
|
34
|
+
}
|
|
35
|
+
export function buildMissingCredentialsMessage() {
|
|
36
|
+
return [
|
|
37
|
+
'Missing credentials.',
|
|
38
|
+
'',
|
|
39
|
+
'Looked for TRANSLOADIT_KEY + TRANSLOADIT_SECRET in this order:',
|
|
40
|
+
'1. Shell env: TRANSLOADIT_KEY / TRANSLOADIT_SECRET',
|
|
41
|
+
`2. Current directory .env: ${getProjectDotenvPath()}`,
|
|
42
|
+
`3. Credentials file: ${getDisplayPath(getConfiguredCredentialsFilePath())}`,
|
|
43
|
+
].join('\n');
|
|
44
|
+
}
|
|
45
|
+
export function buildMissingAuthMessage() {
|
|
46
|
+
return [
|
|
47
|
+
'Missing authentication.',
|
|
48
|
+
'',
|
|
49
|
+
'Looked for TRANSLOADIT_AUTH_TOKEN or TRANSLOADIT_KEY + TRANSLOADIT_SECRET in this order:',
|
|
50
|
+
'1. Shell env: TRANSLOADIT_AUTH_TOKEN, or TRANSLOADIT_KEY / TRANSLOADIT_SECRET',
|
|
51
|
+
`2. Current directory .env: ${getProjectDotenvPath()}`,
|
|
52
|
+
`3. Credentials file: ${getDisplayPath(getConfiguredCredentialsFilePath())}`,
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
function readEnvFile(filePath) {
|
|
56
|
+
if (!fs.existsSync(filePath))
|
|
9
57
|
return null;
|
|
58
|
+
try {
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
source: {
|
|
62
|
+
name: 'credentialsFile',
|
|
63
|
+
values: parseDotenv(fs.readFileSync(filePath)),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (!(err instanceof Error)) {
|
|
69
|
+
throw new Error(`Was thrown a non-error: ${err}`);
|
|
70
|
+
}
|
|
71
|
+
return { ok: false, error: `Failed to read ${filePath}: ${err.message}` };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function loadProjectDotenvIntoProcessEnv() {
|
|
75
|
+
const projectDotenvPath = getProjectDotenvPath();
|
|
76
|
+
if (loadedProjectDotenvPath !== projectDotenvPath) {
|
|
77
|
+
restoreProjectDotenvFromProcessEnv();
|
|
78
|
+
shellEnvBeforeProjectDotenv = { ...process.env };
|
|
79
|
+
loadedProjectDotenvPath = projectDotenvPath;
|
|
80
|
+
}
|
|
81
|
+
const projectDotenvResult = readEnvFile(projectDotenvPath);
|
|
82
|
+
if (projectDotenvResult == null) {
|
|
83
|
+
restoreProjectDotenvFromProcessEnv();
|
|
84
|
+
projectDotenvInjectedValues = undefined;
|
|
85
|
+
projectDotenvPreviousValues = undefined;
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (!projectDotenvResult.ok)
|
|
89
|
+
return projectDotenvResult.error;
|
|
90
|
+
if (projectDotenvInjectedValues != null)
|
|
91
|
+
return undefined;
|
|
92
|
+
const previousValues = {};
|
|
93
|
+
const injectedValues = {};
|
|
94
|
+
for (const [key, value] of Object.entries(projectDotenvResult.source.values)) {
|
|
95
|
+
if (value == null)
|
|
96
|
+
continue;
|
|
97
|
+
if (normalizeEnvValue(process.env[key]) != null)
|
|
98
|
+
continue;
|
|
99
|
+
previousValues[key] = process.env[key];
|
|
100
|
+
process.env[key] = value;
|
|
101
|
+
injectedValues[key] = value;
|
|
102
|
+
}
|
|
103
|
+
projectDotenvPreviousValues = previousValues;
|
|
104
|
+
projectDotenvInjectedValues = injectedValues;
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
function getShellEnvValues() {
|
|
108
|
+
if (loadedProjectDotenvPath === getProjectDotenvPath() && shellEnvBeforeProjectDotenv != null) {
|
|
109
|
+
return shellEnvBeforeProjectDotenv;
|
|
110
|
+
}
|
|
111
|
+
return { ...process.env };
|
|
112
|
+
}
|
|
113
|
+
function restoreProjectDotenvFromProcessEnv() {
|
|
114
|
+
if (projectDotenvInjectedValues == null || projectDotenvPreviousValues == null)
|
|
115
|
+
return;
|
|
116
|
+
for (const [key, injectedValue] of Object.entries(projectDotenvInjectedValues)) {
|
|
117
|
+
if (process.env[key] !== injectedValue)
|
|
118
|
+
continue;
|
|
119
|
+
const previousValue = projectDotenvPreviousValues[key];
|
|
120
|
+
if (previousValue == null) {
|
|
121
|
+
delete process.env[key];
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
process.env[key] = previousValue;
|
|
125
|
+
}
|
|
126
|
+
projectDotenvInjectedValues = undefined;
|
|
127
|
+
projectDotenvPreviousValues = undefined;
|
|
128
|
+
}
|
|
129
|
+
function loadCliEnvSources() {
|
|
130
|
+
const shellEnvSource = {
|
|
131
|
+
name: 'env',
|
|
132
|
+
values: getShellEnvValues(),
|
|
133
|
+
};
|
|
134
|
+
const loadErrors = [];
|
|
135
|
+
const projectDotenvLoadError = loadProjectDotenvIntoProcessEnv();
|
|
136
|
+
if (projectDotenvLoadError != null) {
|
|
137
|
+
loadErrors.push(projectDotenvLoadError);
|
|
138
|
+
}
|
|
139
|
+
const sources = [
|
|
140
|
+
{
|
|
141
|
+
name: 'env',
|
|
142
|
+
values: { ...process.env },
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
const credentialsFilePath = getConfiguredCredentialsFilePath();
|
|
146
|
+
const credentialsFileResult = readEnvFile(credentialsFilePath);
|
|
147
|
+
if (credentialsFileResult?.ok === true) {
|
|
148
|
+
sources.push(credentialsFileResult.source);
|
|
149
|
+
}
|
|
150
|
+
else if (credentialsFileResult?.ok === false) {
|
|
151
|
+
loadErrors.push(credentialsFileResult.error);
|
|
152
|
+
}
|
|
153
|
+
else if (normalizeEnvValue(process.env.TRANSLOADIT_CREDENTIALS_FILE) != null) {
|
|
154
|
+
loadErrors.push(`Configured credentials file does not exist: ${credentialsFilePath}`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
shellEnvSource,
|
|
158
|
+
sources,
|
|
159
|
+
...(loadErrors[0] ? { loadError: loadErrors[0] } : {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function getSourceValue(source, keys) {
|
|
163
|
+
for (const key of keys) {
|
|
164
|
+
const value = normalizeEnvValue(source.values[key]);
|
|
165
|
+
if (value != null)
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
function getSourceCredentials(source) {
|
|
171
|
+
const authKey = getSourceValue(source, ['TRANSLOADIT_KEY', 'TRANSLOADIT_AUTH_KEY']);
|
|
172
|
+
const authSecret = getSourceValue(source, ['TRANSLOADIT_SECRET', 'TRANSLOADIT_AUTH_SECRET']);
|
|
173
|
+
if (authKey == null || authSecret == null)
|
|
174
|
+
return undefined;
|
|
10
175
|
return { authKey, authSecret };
|
|
11
176
|
}
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
16
|
-
return {
|
|
177
|
+
function getSourceAuthToken(source) {
|
|
178
|
+
const authToken = getSourceValue(source, ['TRANSLOADIT_AUTH_TOKEN']);
|
|
179
|
+
if (authToken == null)
|
|
180
|
+
return undefined;
|
|
181
|
+
return { authToken };
|
|
182
|
+
}
|
|
183
|
+
function resolveEndpointForSource(source, shellEnvSource) {
|
|
184
|
+
const shellEndpoint = getSourceValue(shellEnvSource, ['TRANSLOADIT_ENDPOINT']);
|
|
185
|
+
if (shellEndpoint != null)
|
|
186
|
+
return shellEndpoint;
|
|
187
|
+
if (source == null)
|
|
188
|
+
return undefined;
|
|
189
|
+
return getSourceValue(source, ['TRANSLOADIT_ENDPOINT']);
|
|
190
|
+
}
|
|
191
|
+
export function resolveCliConfig() {
|
|
192
|
+
const { loadError, shellEnvSource, sources } = loadCliEnvSources();
|
|
193
|
+
let auth;
|
|
194
|
+
let authSource;
|
|
195
|
+
let credentials;
|
|
196
|
+
let credentialsSource;
|
|
197
|
+
for (const source of sources) {
|
|
198
|
+
if (auth == null) {
|
|
199
|
+
const authToken = getSourceAuthToken(source);
|
|
200
|
+
if (authToken != null) {
|
|
201
|
+
auth = authToken;
|
|
202
|
+
authSource = source;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const sourceCredentials = getSourceCredentials(source);
|
|
206
|
+
if (sourceCredentials != null) {
|
|
207
|
+
auth = sourceCredentials;
|
|
208
|
+
authSource = source;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (credentials != null)
|
|
213
|
+
continue;
|
|
214
|
+
const sourceCredentials = getSourceCredentials(source);
|
|
215
|
+
if (sourceCredentials != null) {
|
|
216
|
+
credentials = sourceCredentials;
|
|
217
|
+
credentialsSource = source;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
...(auth != null ? { auth } : {}),
|
|
222
|
+
...(credentials != null ? { credentials } : {}),
|
|
223
|
+
...(authSource != null
|
|
224
|
+
? { endpoint: resolveEndpointForSource(authSource, shellEnvSource) }
|
|
225
|
+
: {}),
|
|
226
|
+
...(credentialsSource != null
|
|
227
|
+
? { credentialsEndpoint: resolveEndpointForSource(credentialsSource, shellEnvSource) }
|
|
228
|
+
: {}),
|
|
229
|
+
...(loadError != null ? { loadError } : {}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
export function requireCliCredentials() {
|
|
233
|
+
const { credentials, loadError } = resolveCliConfig();
|
|
234
|
+
if (credentials != null)
|
|
235
|
+
return { ok: true, credentials };
|
|
236
|
+
if (loadError != null)
|
|
237
|
+
return { ok: false, error: loadError };
|
|
238
|
+
return { ok: false, error: buildMissingCredentialsMessage() };
|
|
17
239
|
}
|
|
18
240
|
export function createReadStream(file) {
|
|
19
241
|
if (file === '-')
|
package/dist/cli/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/cli/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,GAAG,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/cli/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,GAAG,MAAM,kBAAkB,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAUvC,IAAI,uBAA2C,CAAA;AAC/C,IAAI,2BAA+D,CAAA;AACnE,IAAI,2BAA2E,CAAA;AAC/E,IAAI,2BAA2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M,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAM,CAAC,CAAA;IAC/C,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAoBA,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAItD;AAED,wBAAsB,IAAI,CAAC,IAAI,WAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtE;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAOxD"}
|
package/dist/cli.js
CHANGED
|
@@ -3,8 +3,7 @@ import { realpathSync } from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import
|
|
7
|
-
import { createCli } from "./cli/commands/index.js";
|
|
6
|
+
import { loadProjectDotenvIntoProcessEnv } from "./cli/helpers.js";
|
|
8
7
|
import { ensureError } from "./cli/types.js";
|
|
9
8
|
const currentFile = realpathSync(fileURLToPath(import.meta.url));
|
|
10
9
|
function resolveInvokedPath(invoked) {
|
|
@@ -24,6 +23,8 @@ export function shouldRunCli(invoked) {
|
|
|
24
23
|
return resolved === currentFile;
|
|
25
24
|
}
|
|
26
25
|
export async function main(args = process.argv.slice(2)) {
|
|
26
|
+
loadProjectDotenvIntoProcessEnv();
|
|
27
|
+
const { createCli } = await import("./cli/commands/index.js");
|
|
27
28
|
const cli = createCli();
|
|
28
29
|
const exitCode = await cli.run(args);
|
|
29
30
|
if (exitCode !== 0) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEhE,SAAS,kBAAkB,CAAC,OAAgB;IAC1C,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IAChC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC5C,IAAI,QAAQ,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAClC,OAAO,QAAQ,KAAK,WAAW,CAAA;AACjC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,+BAA+B,EAAE,CAAA;IACjC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;IAC7D,MAAM,GAAG,GAAG,SAAS,EAAE,CAAA;IACvB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC7B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAE,OAAM;IAE1C,MAAM,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA;QACzC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,kBAAkB,EAAE,CAAA"}
|
package/package.json
CHANGED
package/src/bearerToken.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type BearerTokenResponse = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type MintBearerTokenOptions = {
|
|
13
|
+
allowProcessEnvEndpointFallback?: boolean
|
|
13
14
|
endpoint?: string
|
|
14
15
|
aud?: BearerTokenAudience | string
|
|
15
16
|
/**
|
|
@@ -49,8 +50,15 @@ const isLoopbackHost = (hostname: string): boolean =>
|
|
|
49
50
|
|
|
50
51
|
type TokenBaseResult = { ok: true; baseUrl: URL } | { ok: false; error: string }
|
|
51
52
|
|
|
52
|
-
const normalizeTokenBaseEndpoint = (
|
|
53
|
-
|
|
53
|
+
const normalizeTokenBaseEndpoint = (
|
|
54
|
+
raw?: string,
|
|
55
|
+
allowProcessEnvEndpointFallback = true,
|
|
56
|
+
): TokenBaseResult => {
|
|
57
|
+
const baseRaw = (
|
|
58
|
+
raw ||
|
|
59
|
+
(allowProcessEnvEndpointFallback ? process.env.TRANSLOADIT_ENDPOINT : undefined) ||
|
|
60
|
+
'https://api2.transloadit.com'
|
|
61
|
+
).trim()
|
|
54
62
|
|
|
55
63
|
let url: URL
|
|
56
64
|
try {
|
|
@@ -118,7 +126,10 @@ export async function mintBearerTokenWithCredentials(
|
|
|
118
126
|
credentials: { authKey: string; authSecret: string },
|
|
119
127
|
options: MintBearerTokenOptions = {},
|
|
120
128
|
): Promise<MintBearerTokenResult> {
|
|
121
|
-
const endpointResult = normalizeTokenBaseEndpoint(
|
|
129
|
+
const endpointResult = normalizeTokenBaseEndpoint(
|
|
130
|
+
options.endpoint,
|
|
131
|
+
options.allowProcessEnvEndpointFallback,
|
|
132
|
+
)
|
|
122
133
|
if (!endpointResult.ok) {
|
|
123
134
|
return { ok: false, error: endpointResult.error }
|
|
124
135
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import 'dotenv/config'
|
|
2
|
-
import process from 'node:process'
|
|
3
1
|
import { Command, Option } from 'clipanion'
|
|
4
2
|
import { Transloadit as TransloaditClient } from '../../Transloadit.ts'
|
|
5
|
-
import {
|
|
3
|
+
import { buildMissingAuthMessage, resolveCliConfig } from '../helpers.ts'
|
|
6
4
|
import type { IOutputCtl } from '../OutputCtl.ts'
|
|
7
5
|
import OutputCtl, { LOG_LEVEL_DEFAULT, LOG_LEVEL_NAMES, parseLogLevel } from '../OutputCtl.ts'
|
|
8
6
|
|
|
@@ -17,7 +15,7 @@ abstract class BaseCommand extends Command {
|
|
|
17
15
|
|
|
18
16
|
endpoint = Option.String('--endpoint', {
|
|
19
17
|
description:
|
|
20
|
-
'API endpoint URL (default: https://api2.transloadit.com, or TRANSLOADIT_ENDPOINT env
|
|
18
|
+
'API endpoint URL (default: https://api2.transloadit.com, or TRANSLOADIT_ENDPOINT from the environment, .env, or ~/.transloadit/credentials)',
|
|
21
19
|
})
|
|
22
20
|
|
|
23
21
|
protected output!: IOutputCtl
|
|
@@ -32,16 +30,16 @@ abstract class BaseCommand extends Command {
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
protected setupClient(): boolean {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
this.output.error(
|
|
33
|
+
const config = resolveCliConfig()
|
|
34
|
+
if (config.auth == null) {
|
|
35
|
+
this.output.error(config.loadError ?? buildMissingAuthMessage())
|
|
38
36
|
return false
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const endpoint = this.endpoint ||
|
|
39
|
+
const endpoint = this.endpoint || config.endpoint
|
|
42
40
|
|
|
43
41
|
this.client = new TransloaditClient({
|
|
44
|
-
...
|
|
42
|
+
...config.auth,
|
|
45
43
|
...(endpoint && { endpoint }),
|
|
46
44
|
})
|
|
47
45
|
return true
|
package/src/cli/commands/auth.ts
CHANGED
|
@@ -9,7 +9,14 @@ import {
|
|
|
9
9
|
import type { OptionalAuthParams } from '../../apiTypes.ts'
|
|
10
10
|
import { mintBearerTokenWithCredentials } from '../../bearerToken.ts'
|
|
11
11
|
import { Transloadit } from '../../Transloadit.ts'
|
|
12
|
-
import {
|
|
12
|
+
import type { CliKeySecretCredentials, ResolvedCliConfig } from '../helpers.ts'
|
|
13
|
+
import {
|
|
14
|
+
buildMissingCredentialsMessage,
|
|
15
|
+
readCliInput,
|
|
16
|
+
requireCliCredentials,
|
|
17
|
+
resolveCliConfig,
|
|
18
|
+
} from '../helpers.ts'
|
|
19
|
+
import type { IOutputCtl } from '../OutputCtl.ts'
|
|
13
20
|
import { UnauthenticatedCommand } from './BaseCommand.ts'
|
|
14
21
|
|
|
15
22
|
type UrlParamPrimitive = string | number | boolean
|
|
@@ -195,14 +202,49 @@ export interface RunSmartSigOptions {
|
|
|
195
202
|
providedInput?: string
|
|
196
203
|
}
|
|
197
204
|
|
|
198
|
-
|
|
199
|
-
|
|
205
|
+
function reportStandaloneCredentialsError(error: string): null {
|
|
206
|
+
console.error(error)
|
|
207
|
+
process.exitCode = 1
|
|
208
|
+
return null
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getStandaloneCredentials(): CliKeySecretCredentials | null {
|
|
212
|
+
const credentialsResult = requireCliCredentials()
|
|
200
213
|
if (!credentialsResult.ok) {
|
|
201
|
-
|
|
202
|
-
|
|
214
|
+
return reportStandaloneCredentialsError(credentialsResult.error)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return credentialsResult.credentials
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getCommandCredentials(output: IOutputCtl): CliKeySecretCredentials | null {
|
|
221
|
+
const credentialsResult = requireCliCredentials()
|
|
222
|
+
if (!credentialsResult.ok) {
|
|
223
|
+
output.error(credentialsResult.error)
|
|
224
|
+
return null
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return credentialsResult.credentials
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getCommandConfigWithCredentials(output: IOutputCtl): {
|
|
231
|
+
config: ResolvedCliConfig
|
|
232
|
+
credentials: CliKeySecretCredentials
|
|
233
|
+
} | null {
|
|
234
|
+
const config = resolveCliConfig()
|
|
235
|
+
if (config.credentials == null) {
|
|
236
|
+
output.error(config.loadError ?? buildMissingCredentialsMessage())
|
|
237
|
+
return null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return { config, credentials: config.credentials }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export async function runSig(options: RunSigOptions = {}): Promise<void> {
|
|
244
|
+
const credentials = getStandaloneCredentials()
|
|
245
|
+
if (credentials == null) {
|
|
203
246
|
return
|
|
204
247
|
}
|
|
205
|
-
const credentials = credentialsResult.credentials
|
|
206
248
|
|
|
207
249
|
const { content } = await readCliInput({
|
|
208
250
|
providedInput: options.providedInput,
|
|
@@ -220,13 +262,10 @@ export async function runSig(options: RunSigOptions = {}): Promise<void> {
|
|
|
220
262
|
}
|
|
221
263
|
|
|
222
264
|
export async function runSmartSig(options: RunSmartSigOptions = {}): Promise<void> {
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
console.error(credentialsResult.error)
|
|
226
|
-
process.exitCode = 1
|
|
265
|
+
const credentials = getStandaloneCredentials()
|
|
266
|
+
if (credentials == null) {
|
|
227
267
|
return
|
|
228
268
|
}
|
|
229
|
-
const credentials = credentialsResult.credentials
|
|
230
269
|
|
|
231
270
|
const { content } = await readCliInput({
|
|
232
271
|
providedInput: options.providedInput,
|
|
@@ -260,6 +299,8 @@ export class SignatureCommand extends UnauthenticatedCommand {
|
|
|
260
299
|
details: `
|
|
261
300
|
Read params JSON from stdin and output signed payload JSON.
|
|
262
301
|
If no input is provided, generates a signature with default params.
|
|
302
|
+
Credentials are resolved from the shell environment, the current working directory .env, or
|
|
303
|
+
~/.transloadit/credentials.
|
|
263
304
|
`,
|
|
264
305
|
examples: [
|
|
265
306
|
['Generate signature', 'echo \'{"steps":{}}\' | transloadit signature'],
|
|
@@ -273,12 +314,8 @@ export class SignatureCommand extends UnauthenticatedCommand {
|
|
|
273
314
|
})
|
|
274
315
|
|
|
275
316
|
protected async run(): Promise<number | undefined> {
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
this.output.error(credentialsResult.error)
|
|
279
|
-
return 1
|
|
280
|
-
}
|
|
281
|
-
const credentials = credentialsResult.credentials
|
|
317
|
+
const credentials = getCommandCredentials(this.output)
|
|
318
|
+
if (credentials == null) return 1
|
|
282
319
|
|
|
283
320
|
const { content } = await readCliInput({ allowStdinWhenNoPath: true })
|
|
284
321
|
const rawInput = (content ?? '').trim()
|
|
@@ -312,6 +349,8 @@ export class SmartCdnSignatureCommand extends UnauthenticatedCommand {
|
|
|
312
349
|
Read Smart CDN params JSON from stdin and output a signed URL.
|
|
313
350
|
Required fields: workspace, template, input
|
|
314
351
|
Optional fields: expire_at_ms, url_params
|
|
352
|
+
Credentials are resolved from the shell environment, the current working directory .env, or
|
|
353
|
+
~/.transloadit/credentials.
|
|
315
354
|
`,
|
|
316
355
|
examples: [
|
|
317
356
|
[
|
|
@@ -326,12 +365,8 @@ export class SmartCdnSignatureCommand extends UnauthenticatedCommand {
|
|
|
326
365
|
})
|
|
327
366
|
|
|
328
367
|
protected async run(): Promise<number | undefined> {
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
this.output.error(credentialsResult.error)
|
|
332
|
-
return 1
|
|
333
|
-
}
|
|
334
|
-
const credentials = credentialsResult.credentials
|
|
368
|
+
const credentials = getCommandCredentials(this.output)
|
|
369
|
+
if (credentials == null) return 1
|
|
335
370
|
|
|
336
371
|
const { content } = await readCliInput({ allowStdinWhenNoPath: true })
|
|
337
372
|
const rawInput = (content ?? '').trim()
|
|
@@ -359,8 +394,9 @@ export class TokenCommand extends UnauthenticatedCommand {
|
|
|
359
394
|
category: 'Auth',
|
|
360
395
|
description: 'Mint a short-lived bearer token',
|
|
361
396
|
details: `
|
|
362
|
-
Calls POST /token using HTTP Basic Auth
|
|
363
|
-
|
|
397
|
+
Calls POST /token using HTTP Basic Auth and prints the JSON response to stdout.
|
|
398
|
+
Credentials are resolved from the shell environment, the current working directory .env, or
|
|
399
|
+
~/.transloadit/credentials.
|
|
364
400
|
`,
|
|
365
401
|
examples: [
|
|
366
402
|
['Mint an MCP token (default aud)', 'transloadit auth token'],
|
|
@@ -378,14 +414,12 @@ export class TokenCommand extends UnauthenticatedCommand {
|
|
|
378
414
|
})
|
|
379
415
|
|
|
380
416
|
protected override async run(): Promise<number | undefined> {
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
this.output.error(credentialsResult.error)
|
|
384
|
-
return 1
|
|
385
|
-
}
|
|
417
|
+
const resolved = getCommandConfigWithCredentials(this.output)
|
|
418
|
+
if (resolved == null) return 1
|
|
386
419
|
|
|
387
|
-
const result = await mintBearerTokenWithCredentials(
|
|
388
|
-
|
|
420
|
+
const result = await mintBearerTokenWithCredentials(resolved.credentials, {
|
|
421
|
+
allowProcessEnvEndpointFallback: false,
|
|
422
|
+
endpoint: this.endpoint ?? resolved.config.credentialsEndpoint,
|
|
389
423
|
aud: this.aud,
|
|
390
424
|
scope: this.scope,
|
|
391
425
|
})
|
|
@@ -342,6 +342,8 @@ export function renderIntentDocsBody({
|
|
|
342
342
|
`${heading} At a glance`,
|
|
343
343
|
'',
|
|
344
344
|
'Intent commands are the fastest path to common one-off tasks from the CLI.',
|
|
345
|
+
'Authentication is resolved in this order: shell environment, the current working directory `.env`, then `~/.transloadit/credentials`.',
|
|
346
|
+
'The home credentials file uses dotenv syntax and can include `TRANSLOADIT_KEY`, `TRANSLOADIT_SECRET`, `TRANSLOADIT_ENDPOINT`, and `TRANSLOADIT_AUTH_TOKEN`.',
|
|
345
347
|
'Use `--print-urls` when you want temporary result URLs without downloading locally.',
|
|
346
348
|
'All intent commands also support the global CLI flags `--json`, `--log-level`, `--endpoint`, and `--help`.',
|
|
347
349
|
'',
|