aemdm 0.2.3 → 0.3.0
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/dist/cli.js +44 -16
- package/dist/lib/client.js +4 -4
- package/dist/lib/config.js +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { Command, CommanderError, Option } from "commander";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { CliError, request, requestJson, resolveBucket, resolveOptionalImsToken, resolveSearchAuth, } from "./lib/client.js";
|
|
6
|
+
import { CliError, normalizeBucket, request, requestJson, resolveBucket, resolveOptionalImsToken, resolveSearchAuth, } from "./lib/client.js";
|
|
7
7
|
import { readProfileConfig, writeProfileConfig, } from "./lib/config.js";
|
|
8
8
|
import { buildAssetUrl, buildMetadataUrl, deliveryFormatSchema, resolveDimensions, } from "./lib/delivery.js";
|
|
9
9
|
import { buildSearchRequest, getAssetIdFromHit, loadRawQuery, } from "./lib/search.js";
|
|
@@ -167,7 +167,7 @@ async function handleAssetGet(assetId, options, runtime) {
|
|
|
167
167
|
const parsed = parseWithSchema(assetGetSchema, options);
|
|
168
168
|
const profile = await readProfileConfig(runtime.env);
|
|
169
169
|
const baseUrl = resolveBucket(parsed.bucket, runtime.env, profile.bucket);
|
|
170
|
-
const imsToken = resolveOptionalImsToken(parsed.imsToken, runtime.env);
|
|
170
|
+
const imsToken = resolveOptionalImsToken(parsed.imsToken, runtime.env, profile.imsToken);
|
|
171
171
|
const dimensions = resolveDimensions(parsed.size, parsed.width, parsed.height);
|
|
172
172
|
verbose(runtime, `bucket: ${baseUrl}`);
|
|
173
173
|
verbose(runtime, `asset: ${assetId}`);
|
|
@@ -227,7 +227,7 @@ async function handleSearch(options, runtime) {
|
|
|
227
227
|
const parsed = parseWithSchema(searchSchema, options);
|
|
228
228
|
const profile = await readProfileConfig(runtime.env);
|
|
229
229
|
const baseUrl = resolveBucket(parsed.bucket, runtime.env, profile.bucket);
|
|
230
|
-
const { imsToken, apiKey } = resolveSearchAuth(parsed.imsToken, parsed.apiKey, runtime.env);
|
|
230
|
+
const { imsToken, apiKey } = resolveSearchAuth(parsed.imsToken, parsed.apiKey, runtime.env, profile.imsToken);
|
|
231
231
|
const searchBody = await buildSearchBody(parsed);
|
|
232
232
|
const searchUrl = `${baseUrl}/search`;
|
|
233
233
|
verbose(runtime, `bucket: ${baseUrl}`);
|
|
@@ -347,7 +347,7 @@ function buildProgram(runtime) {
|
|
|
347
347
|
program
|
|
348
348
|
.name("aemdm")
|
|
349
349
|
.description("CLI for Adobe Dynamic Media with OpenAPI")
|
|
350
|
-
.version("0.
|
|
350
|
+
.version("0.3.0")
|
|
351
351
|
.showHelpAfterError()
|
|
352
352
|
.option("-v, --verbose", "Show additional diagnostic output")
|
|
353
353
|
.configureOutput({
|
|
@@ -401,7 +401,8 @@ Core commands:
|
|
|
401
401
|
Important defaults:
|
|
402
402
|
- Bucket comes from --bucket or AEMDM_BUCKET.
|
|
403
403
|
- A standalone call like aemdm --bucket delivery-p123-e456.adobeaemcloud.com saves the default bucket to the local aemdm profile config.
|
|
404
|
-
-
|
|
404
|
+
- aemdm --ims-token <token> saves the IMS token to the profile config. Both can be saved together.
|
|
405
|
+
- Search auth comes from --ims-token/AEMDM_IMS_TOKEN/profile config and --api-key/AEMDM_API_KEY.
|
|
405
406
|
- asset get prints a URL by default.
|
|
406
407
|
- asset get --metadata prints full JSON metadata when authenticated, or basic public JSON metadata when no token is supplied.
|
|
407
408
|
- asset get --binary downloads the asset and requires --output.
|
|
@@ -444,14 +445,31 @@ LLM usage guidance:
|
|
|
444
445
|
- Prefer --first-binary with --output when the user wants the downloaded file.
|
|
445
446
|
`;
|
|
446
447
|
}
|
|
447
|
-
function
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
function parseStandaloneConfig(argv) {
|
|
449
|
+
const config = {};
|
|
450
|
+
const args = [...argv];
|
|
451
|
+
while (args.length > 0) {
|
|
452
|
+
const arg = args.shift();
|
|
453
|
+
if (arg.startsWith("--bucket=")) {
|
|
454
|
+
config.bucket = arg.slice("--bucket=".length);
|
|
455
|
+
}
|
|
456
|
+
else if (arg === "--bucket" && args.length > 0) {
|
|
457
|
+
config.bucket = args.shift();
|
|
458
|
+
}
|
|
459
|
+
else if (arg.startsWith("--ims-token=")) {
|
|
460
|
+
config.imsToken = arg.slice("--ims-token=".length);
|
|
461
|
+
}
|
|
462
|
+
else if (arg === "--ims-token" && args.length > 0) {
|
|
463
|
+
config.imsToken = args.shift();
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
450
468
|
}
|
|
451
|
-
if (
|
|
452
|
-
return
|
|
469
|
+
if (!config.bucket && !config.imsToken) {
|
|
470
|
+
return undefined;
|
|
453
471
|
}
|
|
454
|
-
return
|
|
472
|
+
return config;
|
|
455
473
|
}
|
|
456
474
|
function toCliError(error) {
|
|
457
475
|
if (error instanceof CliError) {
|
|
@@ -482,11 +500,21 @@ export async function runCli(argv, runtimeOverrides = {}) {
|
|
|
482
500
|
...runtimeOverrides,
|
|
483
501
|
};
|
|
484
502
|
try {
|
|
485
|
-
const
|
|
486
|
-
if (
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
|
|
503
|
+
const standaloneConfig = parseStandaloneConfig(argv);
|
|
504
|
+
if (standaloneConfig !== undefined) {
|
|
505
|
+
const existing = await readProfileConfig(runtime.env);
|
|
506
|
+
const merged = { ...existing };
|
|
507
|
+
if (standaloneConfig.bucket) {
|
|
508
|
+
merged.bucket = normalizeBucket(standaloneConfig.bucket);
|
|
509
|
+
}
|
|
510
|
+
if (standaloneConfig.imsToken) {
|
|
511
|
+
merged.imsToken = standaloneConfig.imsToken;
|
|
512
|
+
}
|
|
513
|
+
const configPath = await writeProfileConfig(runtime.env, merged);
|
|
514
|
+
if (merged.bucket)
|
|
515
|
+
writeLine(runtime.stdout, `Saved bucket: ${merged.bucket}`);
|
|
516
|
+
if (standaloneConfig.imsToken)
|
|
517
|
+
writeLine(runtime.stdout, `Saved IMS token to profile config`);
|
|
490
518
|
writeLine(runtime.stdout, `Config file: ${configPath}`);
|
|
491
519
|
return 0;
|
|
492
520
|
}
|
package/dist/lib/client.js
CHANGED
|
@@ -40,11 +40,11 @@ export function resolveBucket(explicitValue, env, profileBucket) {
|
|
|
40
40
|
}
|
|
41
41
|
return normalizeBucket(bucket);
|
|
42
42
|
}
|
|
43
|
-
export function resolveOptionalImsToken(explicitValue, env) {
|
|
44
|
-
return explicitValue ?? env.AEMDM_IMS_TOKEN;
|
|
43
|
+
export function resolveOptionalImsToken(explicitValue, env, profileImsToken) {
|
|
44
|
+
return explicitValue ?? env.AEMDM_IMS_TOKEN ?? profileImsToken;
|
|
45
45
|
}
|
|
46
|
-
export function resolveSearchAuth(imsToken, apiKey, env) {
|
|
47
|
-
const resolvedImsToken = imsToken ?? env.AEMDM_IMS_TOKEN;
|
|
46
|
+
export function resolveSearchAuth(imsToken, apiKey, env, profileImsToken) {
|
|
47
|
+
const resolvedImsToken = imsToken ?? env.AEMDM_IMS_TOKEN ?? profileImsToken;
|
|
48
48
|
const resolvedApiKey = apiKey ?? env.AEMDM_API_KEY ?? "asset_search_service";
|
|
49
49
|
if (!resolvedImsToken) {
|
|
50
50
|
throw new CliError("Missing IMS token. Use --ims-token or set AEMDM_IMS_TOKEN.");
|
package/dist/lib/config.js
CHANGED