@anakonn/ankk 0.1.3 → 0.1.4
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/index.js +236 -206
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2157,7 +2157,7 @@ var {
|
|
|
2157
2157
|
// package.json
|
|
2158
2158
|
var package_default = {
|
|
2159
2159
|
name: "@anakonn/ankk",
|
|
2160
|
-
version: "0.1.
|
|
2160
|
+
version: "0.1.4",
|
|
2161
2161
|
description: "Bun-first CLI for the ankk public API.",
|
|
2162
2162
|
private: false,
|
|
2163
2163
|
license: "UNLICENSED",
|
|
@@ -2697,171 +2697,12 @@ var configureCommanderOutput = (program2, io) => {
|
|
|
2697
2697
|
};
|
|
2698
2698
|
var isSuccessfulCommanderExit = (error) => typeof error === "object" && error !== null && ("exitCode" in error) && error.exitCode === 0;
|
|
2699
2699
|
|
|
2700
|
-
// src/brand-image-upload.ts
|
|
2701
|
-
import { readFile, stat } from "fs/promises";
|
|
2702
|
-
import { basename } from "path";
|
|
2703
|
-
|
|
2704
|
-
// src/output.ts
|
|
2705
|
-
var defaultIo = {
|
|
2706
|
-
stderr: process.stderr,
|
|
2707
|
-
stdout: process.stdout
|
|
2708
|
-
};
|
|
2709
|
-
var writeOutput = (io, mode, value, human) => {
|
|
2710
|
-
if (mode === "json") {
|
|
2711
|
-
io.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
2712
|
-
`);
|
|
2713
|
-
return;
|
|
2714
|
-
}
|
|
2715
|
-
io.stdout.write(`${human}
|
|
2716
|
-
`);
|
|
2717
|
-
};
|
|
2718
|
-
var writeError = (io, error, mode = "human") => {
|
|
2719
|
-
if (mode === "json") {
|
|
2720
|
-
io.stderr.write(`${JSON.stringify(errorJson(error), null, 2)}
|
|
2721
|
-
`);
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
if (error instanceof CliHttpError) {
|
|
2725
|
-
io.stderr.write(`${error.message}
|
|
2726
|
-
`);
|
|
2727
|
-
return;
|
|
2728
|
-
}
|
|
2729
|
-
if (error instanceof Error) {
|
|
2730
|
-
io.stderr.write(`${error.message}
|
|
2731
|
-
`);
|
|
2732
|
-
return;
|
|
2733
|
-
}
|
|
2734
|
-
io.stderr.write(`Unexpected CLI error.
|
|
2735
|
-
`);
|
|
2736
|
-
};
|
|
2737
|
-
var errorJson = (error) => {
|
|
2738
|
-
if (error instanceof CliHttpError) {
|
|
2739
|
-
const body = error.body && typeof error.body === "object" && !Array.isArray(error.body) ? error.body : {};
|
|
2740
|
-
return {
|
|
2741
|
-
error: "http_error",
|
|
2742
|
-
message: error.message,
|
|
2743
|
-
...body,
|
|
2744
|
-
status: error.status
|
|
2745
|
-
};
|
|
2746
|
-
}
|
|
2747
|
-
if (error instanceof Error) {
|
|
2748
|
-
return {
|
|
2749
|
-
error: "cli_error",
|
|
2750
|
-
message: error.message
|
|
2751
|
-
};
|
|
2752
|
-
}
|
|
2753
|
-
return {
|
|
2754
|
-
error: "unexpected_cli_error",
|
|
2755
|
-
message: "Unexpected CLI error."
|
|
2756
|
-
};
|
|
2757
|
-
};
|
|
2758
|
-
|
|
2759
|
-
// src/brand-image-upload.ts
|
|
2760
|
-
var runBrandImageUploadCommand = async ({
|
|
2761
|
-
alt,
|
|
2762
|
-
brandRef,
|
|
2763
|
-
client,
|
|
2764
|
-
contentType,
|
|
2765
|
-
description,
|
|
2766
|
-
fetch,
|
|
2767
|
-
file,
|
|
2768
|
-
io,
|
|
2769
|
-
outputMode,
|
|
2770
|
-
type
|
|
2771
|
-
}) => {
|
|
2772
|
-
const upload = await readBrandImageUploadFile(file, contentType);
|
|
2773
|
-
const prepared = responseOrThrow(await client.POST("/v1/brand-images/uploads", {
|
|
2774
|
-
body: {
|
|
2775
|
-
brand_ref: brandRef,
|
|
2776
|
-
content_type: upload.contentType,
|
|
2777
|
-
filename: upload.filename,
|
|
2778
|
-
size: upload.size
|
|
2779
|
-
}
|
|
2780
|
-
}));
|
|
2781
|
-
const uploaded = await fetch(prepared.upload_url, {
|
|
2782
|
-
body: upload.data,
|
|
2783
|
-
headers: {
|
|
2784
|
-
"content-type": prepared.content_type
|
|
2785
|
-
},
|
|
2786
|
-
method: prepared.method
|
|
2787
|
-
});
|
|
2788
|
-
if (!uploaded.ok) {
|
|
2789
|
-
throw new Error(`Brand image upload failed with HTTP ${uploaded.status}.`);
|
|
2790
|
-
}
|
|
2791
|
-
const image = responseOrThrow(await client.POST("/v1/brand-images", {
|
|
2792
|
-
body: {
|
|
2793
|
-
brand_ref: brandRef,
|
|
2794
|
-
origin_url: prepared.origin_url,
|
|
2795
|
-
...type ? { type } : {},
|
|
2796
|
-
...alt !== undefined ? { alt } : {},
|
|
2797
|
-
...description !== undefined ? { description } : {}
|
|
2798
|
-
}
|
|
2799
|
-
}));
|
|
2800
|
-
writeOutput(io, outputMode, {
|
|
2801
|
-
...image,
|
|
2802
|
-
uploaded: true
|
|
2803
|
-
}, `image_ref: ${image.image_ref}
|
|
2804
|
-
url: ${image.url}`);
|
|
2805
|
-
};
|
|
2806
|
-
var brandImageUploadPolicies = {
|
|
2807
|
-
".gif": { contentType: "image/gif", maxSize: 20 * 1024 * 1024 },
|
|
2808
|
-
".jpeg": { contentType: "image/jpeg", maxSize: 20 * 1024 * 1024 },
|
|
2809
|
-
".jpg": { contentType: "image/jpeg", maxSize: 20 * 1024 * 1024 },
|
|
2810
|
-
".png": { contentType: "image/png", maxSize: 20 * 1024 * 1024 },
|
|
2811
|
-
".webp": { contentType: "image/webp", maxSize: 20 * 1024 * 1024 }
|
|
2812
|
-
};
|
|
2813
|
-
var readBrandImageUploadFile = async (file, contentTypeOverride) => {
|
|
2814
|
-
const filename = basename(file);
|
|
2815
|
-
const extension = brandImageExtension(filename);
|
|
2816
|
-
const extensionPolicy = brandImageUploadPolicies[extension];
|
|
2817
|
-
const contentType = contentTypeOverride?.trim().toLowerCase() || extensionPolicy.contentType;
|
|
2818
|
-
const contentTypePolicy = brandImageUploadPolicyForContentType(contentType);
|
|
2819
|
-
if (!contentTypePolicy) {
|
|
2820
|
-
throw new Error(`Unsupported brand image content type: ${contentType}`);
|
|
2821
|
-
}
|
|
2822
|
-
if (!contentTypePolicy.extensions.includes(extension)) {
|
|
2823
|
-
throw new Error(`Brand image file extension does not match content type: ${filename} (${contentType})`);
|
|
2824
|
-
}
|
|
2825
|
-
const info = await stat(file);
|
|
2826
|
-
if (!info.isFile()) {
|
|
2827
|
-
throw new Error(`Brand image path is not a file: ${file}`);
|
|
2828
|
-
}
|
|
2829
|
-
if (info.size <= 0) {
|
|
2830
|
-
throw new Error("Brand image file is empty.");
|
|
2831
|
-
}
|
|
2832
|
-
if (info.size > contentTypePolicy.maxSize) {
|
|
2833
|
-
throw new Error(`Brand image file exceeds ${contentTypePolicy.maxSize} bytes.`);
|
|
2834
|
-
}
|
|
2835
|
-
return {
|
|
2836
|
-
contentType,
|
|
2837
|
-
data: await readFile(file),
|
|
2838
|
-
filename,
|
|
2839
|
-
size: info.size
|
|
2840
|
-
};
|
|
2841
|
-
};
|
|
2842
|
-
var brandImageExtension = (filename) => {
|
|
2843
|
-
const index = filename.lastIndexOf(".");
|
|
2844
|
-
const extension = index > 0 ? filename.slice(index).toLowerCase() : "";
|
|
2845
|
-
if (extension in brandImageUploadPolicies)
|
|
2846
|
-
return extension;
|
|
2847
|
-
throw new Error(`Unsupported brand image file extension: ${filename}`);
|
|
2848
|
-
};
|
|
2849
|
-
var brandImageUploadPolicyForContentType = (contentType) => {
|
|
2850
|
-
const extensions = Object.entries(brandImageUploadPolicies).filter(([, policy]) => policy.contentType === contentType).map(([extension]) => extension);
|
|
2851
|
-
if (extensions.length === 0)
|
|
2852
|
-
return null;
|
|
2853
|
-
return {
|
|
2854
|
-
extensions,
|
|
2855
|
-
maxSize: brandImageUploadPolicies[extensions[0] ?? ".jpg"].maxSize
|
|
2856
|
-
};
|
|
2857
|
-
};
|
|
2858
|
-
|
|
2859
2700
|
// src/config-command.ts
|
|
2860
2701
|
import { createInterface } from "readline/promises";
|
|
2861
2702
|
import { Writable } from "stream";
|
|
2862
2703
|
|
|
2863
2704
|
// src/config.ts
|
|
2864
|
-
import { mkdir, readFile
|
|
2705
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
2865
2706
|
import { dirname, join } from "path";
|
|
2866
2707
|
|
|
2867
2708
|
// ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
@@ -17158,7 +16999,7 @@ var defaultConfigPath = ({
|
|
|
17158
16999
|
};
|
|
17159
17000
|
var loadConfig = async (path) => {
|
|
17160
17001
|
try {
|
|
17161
|
-
const raw = await
|
|
17002
|
+
const raw = await readFile(path, "utf8");
|
|
17162
17003
|
return configSchema.parse(JSON.parse(raw));
|
|
17163
17004
|
} catch (error51) {
|
|
17164
17005
|
if (isMissingFileError(error51))
|
|
@@ -17168,7 +17009,7 @@ var loadConfig = async (path) => {
|
|
|
17168
17009
|
};
|
|
17169
17010
|
var configFileExists = async (path) => {
|
|
17170
17011
|
try {
|
|
17171
|
-
await
|
|
17012
|
+
await readFile(path, "utf8");
|
|
17172
17013
|
return true;
|
|
17173
17014
|
} catch (error51) {
|
|
17174
17015
|
if (isMissingFileError(error51))
|
|
@@ -17208,6 +17049,61 @@ var redactApiKey = (apiKey) => {
|
|
|
17208
17049
|
var normalizeBaseUrl = (value) => value.replace(/\/+$/, "");
|
|
17209
17050
|
var isMissingFileError = (error51) => typeof error51 === "object" && error51 !== null && ("code" in error51) && error51.code === "ENOENT";
|
|
17210
17051
|
|
|
17052
|
+
// src/output.ts
|
|
17053
|
+
var defaultIo = {
|
|
17054
|
+
stderr: process.stderr,
|
|
17055
|
+
stdout: process.stdout
|
|
17056
|
+
};
|
|
17057
|
+
var writeOutput = (io, mode, value, human) => {
|
|
17058
|
+
if (mode === "json") {
|
|
17059
|
+
io.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
17060
|
+
`);
|
|
17061
|
+
return;
|
|
17062
|
+
}
|
|
17063
|
+
io.stdout.write(`${human}
|
|
17064
|
+
`);
|
|
17065
|
+
};
|
|
17066
|
+
var writeError = (io, error51, mode = "human") => {
|
|
17067
|
+
if (mode === "json") {
|
|
17068
|
+
io.stderr.write(`${JSON.stringify(errorJson(error51), null, 2)}
|
|
17069
|
+
`);
|
|
17070
|
+
return;
|
|
17071
|
+
}
|
|
17072
|
+
if (error51 instanceof CliHttpError) {
|
|
17073
|
+
io.stderr.write(`${error51.message}
|
|
17074
|
+
`);
|
|
17075
|
+
return;
|
|
17076
|
+
}
|
|
17077
|
+
if (error51 instanceof Error) {
|
|
17078
|
+
io.stderr.write(`${error51.message}
|
|
17079
|
+
`);
|
|
17080
|
+
return;
|
|
17081
|
+
}
|
|
17082
|
+
io.stderr.write(`Unexpected CLI error.
|
|
17083
|
+
`);
|
|
17084
|
+
};
|
|
17085
|
+
var errorJson = (error51) => {
|
|
17086
|
+
if (error51 instanceof CliHttpError) {
|
|
17087
|
+
const body = error51.body && typeof error51.body === "object" && !Array.isArray(error51.body) ? error51.body : {};
|
|
17088
|
+
return {
|
|
17089
|
+
error: "http_error",
|
|
17090
|
+
message: error51.message,
|
|
17091
|
+
...body,
|
|
17092
|
+
status: error51.status
|
|
17093
|
+
};
|
|
17094
|
+
}
|
|
17095
|
+
if (error51 instanceof Error) {
|
|
17096
|
+
return {
|
|
17097
|
+
error: "cli_error",
|
|
17098
|
+
message: error51.message
|
|
17099
|
+
};
|
|
17100
|
+
}
|
|
17101
|
+
return {
|
|
17102
|
+
error: "unexpected_cli_error",
|
|
17103
|
+
message: "Unexpected CLI error."
|
|
17104
|
+
};
|
|
17105
|
+
};
|
|
17106
|
+
|
|
17211
17107
|
// src/config-command.ts
|
|
17212
17108
|
var registerConfigCommands = ({
|
|
17213
17109
|
env,
|
|
@@ -17463,9 +17359,9 @@ var formatSnsContent = (response) => {
|
|
|
17463
17359
|
};
|
|
17464
17360
|
|
|
17465
17361
|
// src/json-input.ts
|
|
17466
|
-
import { readFile as
|
|
17362
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
17467
17363
|
var readJsonInput = async (path, { readStdin = readProcessStdin } = {}) => {
|
|
17468
|
-
const raw = path === "-" ? await readStdin() : await
|
|
17364
|
+
const raw = path === "-" ? await readStdin() : await readFile2(path, "utf8");
|
|
17469
17365
|
try {
|
|
17470
17366
|
return JSON.parse(raw);
|
|
17471
17367
|
} catch (error51) {
|
|
@@ -17478,16 +17374,19 @@ var readJsonInput = async (path, { readStdin = readProcessStdin } = {}) => {
|
|
|
17478
17374
|
var readProcessStdin = async () => Bun.stdin.text();
|
|
17479
17375
|
|
|
17480
17376
|
// src/media-upload.ts
|
|
17481
|
-
import { readFile as
|
|
17482
|
-
import { basename
|
|
17377
|
+
import { readFile as readFile3, stat } from "fs/promises";
|
|
17378
|
+
import { basename } from "path";
|
|
17483
17379
|
var runMediaUploadCommand = async ({
|
|
17380
|
+
alt,
|
|
17484
17381
|
brandRef,
|
|
17485
17382
|
client,
|
|
17486
17383
|
contentType,
|
|
17384
|
+
description,
|
|
17487
17385
|
fetch,
|
|
17488
17386
|
file: file2,
|
|
17489
17387
|
io,
|
|
17490
|
-
outputMode: outputMode2
|
|
17388
|
+
outputMode: outputMode2,
|
|
17389
|
+
type
|
|
17491
17390
|
}) => {
|
|
17492
17391
|
const upload = await readMediaUploadFile(file2, contentType);
|
|
17493
17392
|
const prepared = responseOrThrow(await client.POST("/v1/media/uploads", {
|
|
@@ -17508,10 +17407,21 @@ var runMediaUploadCommand = async ({
|
|
|
17508
17407
|
if (!uploaded.ok) {
|
|
17509
17408
|
throw new Error(`Media upload failed with HTTP ${uploaded.status}.`);
|
|
17510
17409
|
}
|
|
17410
|
+
const media = responseOrThrow(await client.POST("/v1/media", {
|
|
17411
|
+
body: {
|
|
17412
|
+
brand_ref: brandRef,
|
|
17413
|
+
origin_url: prepared.origin_url,
|
|
17414
|
+
content_type: prepared.content_type,
|
|
17415
|
+
...type ? { type } : {},
|
|
17416
|
+
...alt !== undefined ? { alt } : {},
|
|
17417
|
+
...description !== undefined ? { description } : {}
|
|
17418
|
+
}
|
|
17419
|
+
}));
|
|
17511
17420
|
writeOutput(io, outputMode2, {
|
|
17512
|
-
...
|
|
17421
|
+
...media,
|
|
17513
17422
|
uploaded: true
|
|
17514
|
-
}, `
|
|
17423
|
+
}, `media_ref: ${media.media_ref}
|
|
17424
|
+
url: ${media.url}`);
|
|
17515
17425
|
};
|
|
17516
17426
|
var mediaUploadPolicies = {
|
|
17517
17427
|
".gif": { contentType: "image/gif", maxSize: 20 * 1024 * 1024 },
|
|
@@ -17524,7 +17434,7 @@ var mediaUploadPolicies = {
|
|
|
17524
17434
|
".webp": { contentType: "image/webp", maxSize: 20 * 1024 * 1024 }
|
|
17525
17435
|
};
|
|
17526
17436
|
var readMediaUploadFile = async (file2, contentTypeOverride) => {
|
|
17527
|
-
const filename =
|
|
17437
|
+
const filename = basename(file2);
|
|
17528
17438
|
const extension = mediaExtension(filename);
|
|
17529
17439
|
const extensionPolicy = mediaUploadPolicies[extension];
|
|
17530
17440
|
const contentType = contentTypeOverride?.trim().toLowerCase() || extensionPolicy.contentType;
|
|
@@ -17535,7 +17445,7 @@ var readMediaUploadFile = async (file2, contentTypeOverride) => {
|
|
|
17535
17445
|
if (!contentTypePolicy.extensions.includes(extension)) {
|
|
17536
17446
|
throw new Error(`Media file extension does not match content type: ${filename} (${contentType})`);
|
|
17537
17447
|
}
|
|
17538
|
-
const info = await
|
|
17448
|
+
const info = await stat(file2);
|
|
17539
17449
|
if (!info.isFile()) {
|
|
17540
17450
|
throw new Error(`Media path is not a file: ${file2}`);
|
|
17541
17451
|
}
|
|
@@ -17547,7 +17457,7 @@ var readMediaUploadFile = async (file2, contentTypeOverride) => {
|
|
|
17547
17457
|
}
|
|
17548
17458
|
return {
|
|
17549
17459
|
contentType,
|
|
17550
|
-
data: await
|
|
17460
|
+
data: await readFile3(file2),
|
|
17551
17461
|
filename,
|
|
17552
17462
|
size: info.size
|
|
17553
17463
|
};
|
|
@@ -17669,6 +17579,113 @@ var createProgram = ({
|
|
|
17669
17579
|
}));
|
|
17670
17580
|
writeOutput(context.io, context.outputMode, result, `Brand profile updated: ${result.brand_ref}`);
|
|
17671
17581
|
});
|
|
17582
|
+
const brandWiki = brands.command("wiki").description("Manage Brand Wiki documents");
|
|
17583
|
+
const brandWikiHome = brandWiki.command("home").description("Manage Brand Wiki Home");
|
|
17584
|
+
brandWikiHome.command("get").description("Get Brand Wiki Home").requiredOption("--brand-ref <brand_ref>", "Brand reference").action(async (options) => {
|
|
17585
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17586
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki/home", {
|
|
17587
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17588
|
+
}));
|
|
17589
|
+
writeOutput(context.io, context.outputMode, result, formatBrandWikiEntry(result));
|
|
17590
|
+
});
|
|
17591
|
+
brandWikiHome.command("patch").description("Update Brand Wiki Home").requiredOption("--brand-ref <brand_ref>", "Brand reference").requiredOption("--file <path>", "JSON request body file, or - for stdin").action(async (options) => {
|
|
17592
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17593
|
+
const body = apiBody(readObjectBody(await readJsonInput(options.file), "Brand Wiki Home patch body"));
|
|
17594
|
+
const result = responseOrThrow(await context.client.PATCH("/v1/brands/{brand_ref}/wiki/home", {
|
|
17595
|
+
body,
|
|
17596
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17597
|
+
}));
|
|
17598
|
+
writeOutput(context.io, context.outputMode, result, `Brand Wiki Home updated: ${result.brand_ref}`);
|
|
17599
|
+
});
|
|
17600
|
+
withBrandRef(brandWiki.command("list").description("List searchable Brand Wiki entries")).action(async (options) => {
|
|
17601
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17602
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki", {
|
|
17603
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17604
|
+
}));
|
|
17605
|
+
writeOutput(context.io, context.outputMode, result, formatGenericRead(result));
|
|
17606
|
+
});
|
|
17607
|
+
withBrandRef(brandWiki.command("create").description("Create a Brand Wiki entry").requiredOption("--file <path>", "JSON request body file, or - for stdin")).action(async (options) => {
|
|
17608
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17609
|
+
const body = apiBody(readObjectBody(await readJsonInput(options.file), "Brand Wiki create body"));
|
|
17610
|
+
const result = responseOrThrow(await context.client.POST("/v1/brands/{brand_ref}/wiki", {
|
|
17611
|
+
body,
|
|
17612
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17613
|
+
}));
|
|
17614
|
+
writeOutput(context.io, context.outputMode, result, `Brand Wiki entry created: ${result.entry_id}`);
|
|
17615
|
+
});
|
|
17616
|
+
withBrandRef(brandWiki.command("search").description("Search Brand Wiki entries").requiredOption("--query <text>", "Search query")).option("--limit <number>", "Maximum results", parsePositiveInteger).action(async (options) => {
|
|
17617
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17618
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki/search", {
|
|
17619
|
+
params: {
|
|
17620
|
+
path: { brand_ref: options.brandRef },
|
|
17621
|
+
query: {
|
|
17622
|
+
...options.limit !== undefined ? { limit: options.limit } : {},
|
|
17623
|
+
q: options.query
|
|
17624
|
+
}
|
|
17625
|
+
}
|
|
17626
|
+
}));
|
|
17627
|
+
writeOutput(context.io, context.outputMode, result, formatGenericRead(result));
|
|
17628
|
+
});
|
|
17629
|
+
withBrandRef(brandWiki.command("pending").description("List pending Brand Wiki user questions")).action(async (options) => {
|
|
17630
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17631
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki/pending", {
|
|
17632
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17633
|
+
}));
|
|
17634
|
+
writeOutput(context.io, context.outputMode, result, formatGenericRead(result));
|
|
17635
|
+
});
|
|
17636
|
+
withBrandRef(brandWiki.command("trash").description("List deleted Brand Wiki entries")).action(async (options) => {
|
|
17637
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17638
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki/trash", {
|
|
17639
|
+
params: { path: { brand_ref: options.brandRef } }
|
|
17640
|
+
}));
|
|
17641
|
+
writeOutput(context.io, context.outputMode, result, formatGenericRead(result));
|
|
17642
|
+
});
|
|
17643
|
+
withBrandRef(brandWiki.command("get").description("Get a Brand Wiki entry").argument("<entry_id>", "Brand Wiki entry id")).action(async (entryId, options) => {
|
|
17644
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17645
|
+
const result = responseOrThrow(await context.client.GET("/v1/brands/{brand_ref}/wiki/{entry_id}", {
|
|
17646
|
+
params: { path: { brand_ref: options.brandRef, entry_id: entryId } }
|
|
17647
|
+
}));
|
|
17648
|
+
writeOutput(context.io, context.outputMode, result, formatBrandWikiEntry(result));
|
|
17649
|
+
});
|
|
17650
|
+
withBrandRef(brandWiki.command("patch").description("Update a Brand Wiki entry").argument("<entry_id>", "Brand Wiki entry id").requiredOption("--file <path>", "JSON request body file, or - for stdin")).action(async (entryId, options) => {
|
|
17651
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17652
|
+
const body = apiBody(readObjectBody(await readJsonInput(options.file), "Brand Wiki patch body"));
|
|
17653
|
+
const result = responseOrThrow(await context.client.PATCH("/v1/brands/{brand_ref}/wiki/{entry_id}", {
|
|
17654
|
+
body,
|
|
17655
|
+
params: { path: { brand_ref: options.brandRef, entry_id: entryId } }
|
|
17656
|
+
}));
|
|
17657
|
+
writeOutput(context.io, context.outputMode, result, `Brand Wiki entry updated: ${result.entry_id}`);
|
|
17658
|
+
});
|
|
17659
|
+
for (const command of [
|
|
17660
|
+
{
|
|
17661
|
+
method: "DELETE",
|
|
17662
|
+
name: "delete",
|
|
17663
|
+
path: "/v1/brands/{brand_ref}/wiki/{entry_id}",
|
|
17664
|
+
text: "Soft delete a Brand Wiki entry"
|
|
17665
|
+
},
|
|
17666
|
+
{
|
|
17667
|
+
method: "DELETE",
|
|
17668
|
+
name: "purge",
|
|
17669
|
+
path: "/v1/brands/{brand_ref}/wiki/{entry_id}/purge",
|
|
17670
|
+
text: "Permanently delete a Brand Wiki entry"
|
|
17671
|
+
},
|
|
17672
|
+
{
|
|
17673
|
+
method: "POST",
|
|
17674
|
+
name: "restore",
|
|
17675
|
+
path: "/v1/brands/{brand_ref}/wiki/{entry_id}/restore",
|
|
17676
|
+
text: "Restore a deleted Brand Wiki entry"
|
|
17677
|
+
}
|
|
17678
|
+
]) {
|
|
17679
|
+
withBrandRef(brandWiki.command(command.name).description(command.text).argument("<entry_id>", "Brand Wiki entry id")).action(async (entryId, options) => {
|
|
17680
|
+
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17681
|
+
const result = responseOrThrow(command.method === "POST" ? await context.client.POST(command.path, {
|
|
17682
|
+
params: { path: { brand_ref: options.brandRef, entry_id: entryId } }
|
|
17683
|
+
}) : await context.client.DELETE(command.path, {
|
|
17684
|
+
params: { path: { brand_ref: options.brandRef, entry_id: entryId } }
|
|
17685
|
+
}));
|
|
17686
|
+
writeOutput(context.io, context.outputMode, result, `Brand Wiki entry ${command.name}: ${result.entry_id}`);
|
|
17687
|
+
});
|
|
17688
|
+
}
|
|
17672
17689
|
const connections = program2.command("connections").description("Read SNS provider connections");
|
|
17673
17690
|
withBrandRef(connections.command("list").description("List provider connections")).option("--sns-type <sns_type>", "SNS type filter").action(async (options) => {
|
|
17674
17691
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
@@ -17730,36 +17747,25 @@ var createProgram = ({
|
|
|
17730
17747
|
}));
|
|
17731
17748
|
writeOutput(context.io, context.outputMode, result, formatContentPublishResult(result, body));
|
|
17732
17749
|
});
|
|
17733
|
-
const media = program2.command("media").description("
|
|
17734
|
-
withBrandRef(media.command("
|
|
17735
|
-
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17736
|
-
await runMediaUploadCommand({
|
|
17737
|
-
brandRef: options.brandRef,
|
|
17738
|
-
client: context.client,
|
|
17739
|
-
contentType: options.contentType,
|
|
17740
|
-
fetch,
|
|
17741
|
-
file: file2,
|
|
17742
|
-
io: context.io,
|
|
17743
|
-
outputMode: context.outputMode
|
|
17744
|
-
});
|
|
17745
|
-
});
|
|
17746
|
-
const brandImages = program2.command("brand-images").description("Manage brand images shown in the web brand image screen");
|
|
17747
|
-
withBrandRef(brandImages.command("list").description("List brand images")).option("--type <type>", "Image type filter: logo, banner, product, gallery, other").action(async (options) => {
|
|
17750
|
+
const media = program2.command("media").description("Manage brand-owned media assets");
|
|
17751
|
+
withBrandRef(media.command("list").description("List brand-owned media")).option("--kind <kind>", "Media kind filter: image, video").option("--type <type>", "Media type filter: logo, banner, product, gallery, other").action(async (options) => {
|
|
17748
17752
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17749
|
-
const
|
|
17750
|
-
const
|
|
17753
|
+
const kind = options.kind ? parseMediaKind(options.kind) : undefined;
|
|
17754
|
+
const type = options.type ? parseMediaType(options.type) : undefined;
|
|
17755
|
+
const result = responseOrThrow(await context.client.GET("/v1/media", {
|
|
17751
17756
|
params: {
|
|
17752
17757
|
query: {
|
|
17753
17758
|
brand_ref: options.brandRef,
|
|
17759
|
+
...kind ? { kind } : {},
|
|
17754
17760
|
...type ? { type } : {}
|
|
17755
17761
|
}
|
|
17756
17762
|
}
|
|
17757
17763
|
}));
|
|
17758
17764
|
writeOutput(context.io, context.outputMode, result, formatGenericRead(result));
|
|
17759
17765
|
});
|
|
17760
|
-
withBrandRef(
|
|
17766
|
+
withBrandRef(media.command("upload").description("Upload and register an image or video file").argument("<file>", "Media file path")).option("--type <type>", "Media type: logo, banner, product, gallery, other").option("--alt <text>", "Alternative text").option("--description <text>", "Media description").option("--content-type <content_type>", "Override detected MIME type").action(async (file2, options) => {
|
|
17761
17767
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17762
|
-
await
|
|
17768
|
+
await runMediaUploadCommand({
|
|
17763
17769
|
alt: options.alt,
|
|
17764
17770
|
brandRef: options.brandRef,
|
|
17765
17771
|
client: context.client,
|
|
@@ -17769,41 +17775,41 @@ var createProgram = ({
|
|
|
17769
17775
|
file: file2,
|
|
17770
17776
|
io: context.io,
|
|
17771
17777
|
outputMode: context.outputMode,
|
|
17772
|
-
type: options.type ?
|
|
17778
|
+
type: options.type ? parseMediaType(options.type) : undefined
|
|
17773
17779
|
});
|
|
17774
17780
|
});
|
|
17775
|
-
withBrandRef(
|
|
17781
|
+
withBrandRef(media.command("update").description("Update media metadata").argument("<media_ref>", "Media reference")).option("--type <type>", "Media type: logo, banner, product, gallery, other").option("--alt <text>", "Alternative text").option("--description <text>", "Media description").action(async (mediaRef, options) => {
|
|
17776
17782
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17777
|
-
const result = responseOrThrow(await context.client.PATCH("/v1/
|
|
17783
|
+
const result = responseOrThrow(await context.client.PATCH("/v1/media/{media_ref}", {
|
|
17778
17784
|
body: apiBody({
|
|
17779
|
-
...options.type ? { type:
|
|
17785
|
+
...options.type ? { type: parseMediaType(options.type) } : {},
|
|
17780
17786
|
...options.alt !== undefined ? { alt: options.alt } : {},
|
|
17781
17787
|
...options.description !== undefined ? { description: options.description } : {}
|
|
17782
17788
|
}),
|
|
17783
17789
|
params: {
|
|
17784
17790
|
path: {
|
|
17785
|
-
|
|
17791
|
+
media_ref: mediaRef
|
|
17786
17792
|
},
|
|
17787
17793
|
query: {
|
|
17788
17794
|
brand_ref: options.brandRef
|
|
17789
17795
|
}
|
|
17790
17796
|
}
|
|
17791
17797
|
}));
|
|
17792
|
-
writeOutput(context.io, context.outputMode, result, `
|
|
17798
|
+
writeOutput(context.io, context.outputMode, result, `Media updated: ${result.media_ref}`);
|
|
17793
17799
|
});
|
|
17794
|
-
withBrandRef(
|
|
17800
|
+
withBrandRef(media.command("delete").description("Delete media metadata").argument("<media_ref>", "Media reference")).action(async (mediaRef, options) => {
|
|
17795
17801
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
17796
|
-
const result = responseOrThrow(await context.client.DELETE("/v1/
|
|
17802
|
+
const result = responseOrThrow(await context.client.DELETE("/v1/media/{media_ref}", {
|
|
17797
17803
|
params: {
|
|
17798
17804
|
path: {
|
|
17799
|
-
|
|
17805
|
+
media_ref: mediaRef
|
|
17800
17806
|
},
|
|
17801
17807
|
query: {
|
|
17802
17808
|
brand_ref: options.brandRef
|
|
17803
17809
|
}
|
|
17804
17810
|
}
|
|
17805
17811
|
}));
|
|
17806
|
-
writeOutput(context.io, context.outputMode, result, `
|
|
17812
|
+
writeOutput(context.io, context.outputMode, result, `Media deleted: ${result.media_ref}`);
|
|
17807
17813
|
});
|
|
17808
17814
|
withBrandRef(content.command("cancel").description("Cancel scheduled SNS content").argument("<content_id>", "Content id")).option("--file <path>", "JSON request body file, or - for stdin").action(async (contentId, options) => {
|
|
17809
17815
|
const context = await resolveCommandContext({ env, fetch, io, program: program2 });
|
|
@@ -18151,6 +18157,18 @@ var formatBrandInfo = (response) => {
|
|
|
18151
18157
|
].join(`
|
|
18152
18158
|
`);
|
|
18153
18159
|
};
|
|
18160
|
+
var formatBrandWikiEntry = (response) => [
|
|
18161
|
+
`entry_id: ${response.entry_id}`,
|
|
18162
|
+
`brand_ref: ${response.brand_ref}`,
|
|
18163
|
+
`type: ${response.type}`,
|
|
18164
|
+
`title: ${response.title}`,
|
|
18165
|
+
`question: ${response.question ?? "none"}`,
|
|
18166
|
+
`is_active: ${response.is_active ? "yes" : "no"}`,
|
|
18167
|
+
`body_length: ${response.body_markdown?.length ?? 0}`,
|
|
18168
|
+
`summary_length: ${response.summary?.length ?? 0}`,
|
|
18169
|
+
`updated_at: ${response.updated_at}`
|
|
18170
|
+
].join(`
|
|
18171
|
+
`);
|
|
18154
18172
|
var readBrandInfoPatchBody = (value) => {
|
|
18155
18173
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
18156
18174
|
throw new Error("Brand info patch body must be a JSON object.");
|
|
@@ -18164,11 +18182,23 @@ var readObjectBody = (value, name) => {
|
|
|
18164
18182
|
return value;
|
|
18165
18183
|
};
|
|
18166
18184
|
var apiBody = (body) => body;
|
|
18167
|
-
var
|
|
18168
|
-
|
|
18169
|
-
if (
|
|
18185
|
+
var parsePositiveInteger = (value) => {
|
|
18186
|
+
const parsed = Number.parseInt(value, 10);
|
|
18187
|
+
if (!Number.isInteger(parsed) || parsed <= 0)
|
|
18188
|
+
throw new Error(`Expected a positive integer: ${value}`);
|
|
18189
|
+
return parsed;
|
|
18190
|
+
};
|
|
18191
|
+
var mediaKinds = ["image", "video"];
|
|
18192
|
+
var mediaTypes = ["logo", "banner", "product", "gallery", "other"];
|
|
18193
|
+
var parseMediaKind = (value) => {
|
|
18194
|
+
if (mediaKinds.includes(value))
|
|
18195
|
+
return value;
|
|
18196
|
+
throw new Error(`Unsupported media kind: ${value}`);
|
|
18197
|
+
};
|
|
18198
|
+
var parseMediaType = (value) => {
|
|
18199
|
+
if (mediaTypes.includes(value))
|
|
18170
18200
|
return value;
|
|
18171
|
-
throw new Error(`Unsupported
|
|
18201
|
+
throw new Error(`Unsupported media type: ${value}`);
|
|
18172
18202
|
};
|
|
18173
18203
|
var readBodyOrBrandRef = async (options, name) => {
|
|
18174
18204
|
if (options.file) {
|