@ptkl/toolkit 0.14.0 → 1.0.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/commands/billing.js +111 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/forge.js +150 -9
- package/dist/commands/functions.js +87 -22
- package/dist/commands/index.js +21 -1
- package/dist/commands/integration.js +146 -0
- package/dist/commands/integrations/dms.js +625 -0
- package/dist/commands/integrations/mail.js +120 -0
- package/dist/commands/integrations/payments.js +199 -0
- package/dist/commands/integrations/serbia.js +610 -0
- package/dist/commands/integrations/timber.js +120 -0
- package/dist/commands/kortex.js +203 -12
- package/dist/commands/logs.js +4 -17
- package/dist/commands/project.js +147 -0
- package/dist/commands/ratchet.js +82 -0
- package/dist/commands/sandbox.js +122 -0
- package/dist/commands/satellite.js +111 -0
- package/dist/commands/template.js +96 -0
- package/dist/commands/thunder.js +123 -0
- package/dist/commands/users.js +31 -19
- package/dist/commands/workflow.js +225 -30
- package/dist/lib/forgeDevKernelPlugin.js +2 -1
- package/dist/lib/kortex/session.js +20 -16
- package/dist/lib/scaffold.js +51 -0
- package/dist/lib/sdk.js +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { resolve, basename } from "path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import * as sdk from "../../lib/sdk.js";
|
|
5
|
+
import { registerCommand, withEnvOption, withProfile } from "../../lib/scaffold.js";
|
|
6
|
+
import { isActive, integrationSub } from "../integration.js";
|
|
7
|
+
/** `ptkl integration dms` — typed interface for the Protokol DMS integration (RFC §4.3/§6.1
|
|
8
|
+
* layer 2, media-api v3 `internal/media/controllers/v3/`). Maps onto the SDK `DMS` client
|
|
9
|
+
* (`@ptkl/sdk/beta`, same door as `Integrations.getDMS()`, reached here via `sdk.dms(profile)`):
|
|
10
|
+
* file/document ops (`upload`/`download`/`libraries`/`dirs`/`convert`/`ocr`/`document`) plus
|
|
11
|
+
* three management groups — `backup` (library export archives), `policies` (quota/file-type/
|
|
12
|
+
* notification policy at library+dir scope) and `reminders` (the notification-rules engine).
|
|
13
|
+
* Every subcommand precheck's `isActive('protokol-dms')` so an inactive integration surfaces
|
|
14
|
+
* the friendly "run `ptkl integration activate protokol-dms`" hint instead of a raw 403. */
|
|
15
|
+
const DMS_ID = "protokol-dms";
|
|
16
|
+
function parseJSON(label, raw) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
console.error(`${label} must be valid JSON`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function readTextFile(path) {
|
|
26
|
+
return readFileSync(resolve(path), "utf-8");
|
|
27
|
+
}
|
|
28
|
+
function readBinaryFile(path) {
|
|
29
|
+
return readFileSync(resolve(path));
|
|
30
|
+
}
|
|
31
|
+
function writeOut(content, outPath, label = "Output") {
|
|
32
|
+
const p = resolve(outPath);
|
|
33
|
+
writeFileSync(p, content);
|
|
34
|
+
console.log(`${label} written to ${p}`);
|
|
35
|
+
}
|
|
36
|
+
function mimeFromPath(path) {
|
|
37
|
+
const ext = path.split(".").pop()?.toLowerCase();
|
|
38
|
+
const map = {
|
|
39
|
+
png: "image/png",
|
|
40
|
+
jpg: "image/jpeg",
|
|
41
|
+
jpeg: "image/jpeg",
|
|
42
|
+
gif: "image/gif",
|
|
43
|
+
webp: "image/webp",
|
|
44
|
+
bmp: "image/bmp",
|
|
45
|
+
tif: "image/tiff",
|
|
46
|
+
tiff: "image/tiff",
|
|
47
|
+
pdf: "application/pdf",
|
|
48
|
+
};
|
|
49
|
+
return (ext && map[ext]) || "application/octet-stream";
|
|
50
|
+
}
|
|
51
|
+
/** Best-effort coercion of a DMS/convert response body to a Buffer, regardless of whether the
|
|
52
|
+
* underlying axios call actually resolved with a Node Buffer, an ArrayBuffer/typed array, a
|
|
53
|
+
* (possibly polyfilled) `Blob`, or a plain string — the SDK's `responseType: 'blob'` calls are
|
|
54
|
+
* written isomorphically for browser + Node, so the runtime shape isn't guaranteed here. */
|
|
55
|
+
async function toBuffer(data) {
|
|
56
|
+
if (Buffer.isBuffer(data))
|
|
57
|
+
return data;
|
|
58
|
+
if (data instanceof ArrayBuffer)
|
|
59
|
+
return Buffer.from(data);
|
|
60
|
+
if (ArrayBuffer.isView(data))
|
|
61
|
+
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
62
|
+
if (typeof Blob !== "undefined" && data instanceof Blob)
|
|
63
|
+
return Buffer.from(await data.arrayBuffer());
|
|
64
|
+
if (typeof data === "string")
|
|
65
|
+
return Buffer.from(data, "utf-8");
|
|
66
|
+
return Buffer.from(JSON.stringify(data), "utf-8");
|
|
67
|
+
}
|
|
68
|
+
function isBinaryLike(data) {
|
|
69
|
+
return (Buffer.isBuffer(data) ||
|
|
70
|
+
data instanceof ArrayBuffer ||
|
|
71
|
+
ArrayBuffer.isView(data) ||
|
|
72
|
+
(typeof Blob !== "undefined" && data instanceof Blob));
|
|
73
|
+
}
|
|
74
|
+
/** Shared output path for `convert *` subcommands: binary results (Excel) always need `--out`;
|
|
75
|
+
* text/JSON results print to stdout unless `--out` is given. */
|
|
76
|
+
async function emitConvertResult(res, outPath) {
|
|
77
|
+
const data = res?.data ?? res;
|
|
78
|
+
if (isBinaryLike(data)) {
|
|
79
|
+
if (!outPath) {
|
|
80
|
+
console.error("--out is required to save binary output (e.g. Excel)");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
writeOut(await toBuffer(data), outPath, "Converted output");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const serialized = typeof data === "string" ? data : JSON.stringify(data, null, 4);
|
|
87
|
+
if (outPath)
|
|
88
|
+
writeOut(serialized, outPath, "Converted output");
|
|
89
|
+
else
|
|
90
|
+
console.log(serialized);
|
|
91
|
+
}
|
|
92
|
+
function conversionOptions(opts) {
|
|
93
|
+
const fieldOrder = opts.fieldOrder
|
|
94
|
+
? opts.fieldOrder
|
|
95
|
+
.split(",")
|
|
96
|
+
.map((s) => s.trim())
|
|
97
|
+
.filter(Boolean)
|
|
98
|
+
: undefined;
|
|
99
|
+
if (!opts.sheetName && !fieldOrder)
|
|
100
|
+
return undefined;
|
|
101
|
+
return {
|
|
102
|
+
...(opts.sheetName ? { sheet_name: opts.sheetName } : {}),
|
|
103
|
+
...(fieldOrder ? { field_order: fieldOrder } : {}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
class DMSCommand {
|
|
107
|
+
register() {
|
|
108
|
+
const cmd = new Command("dms").description("Protokol DMS integration: files/libraries/dirs, data conversion, OCR, documents, backup/policies/reminders");
|
|
109
|
+
cmd.addCommand(this.registerUpload());
|
|
110
|
+
cmd.addCommand(this.registerDownload());
|
|
111
|
+
cmd.addCommand(this.registerLibraries());
|
|
112
|
+
cmd.addCommand(this.registerDirs());
|
|
113
|
+
cmd.addCommand(this.registerConvert());
|
|
114
|
+
cmd.addCommand(this.registerOcr());
|
|
115
|
+
cmd.addCommand(this.registerDocument());
|
|
116
|
+
cmd.addCommand(this.registerBackup());
|
|
117
|
+
cmd.addCommand(this.registerPolicies());
|
|
118
|
+
cmd.addCommand(this.registerReminders());
|
|
119
|
+
return integrationSub(cmd);
|
|
120
|
+
}
|
|
121
|
+
// ===============================================================
|
|
122
|
+
// Files
|
|
123
|
+
// ===============================================================
|
|
124
|
+
registerUpload() {
|
|
125
|
+
return registerCommand(new Command("upload")
|
|
126
|
+
.description("Upload one or more local files to a DMS library directory")
|
|
127
|
+
.requiredOption("--file <paths...>", "Local file path(s) to upload")
|
|
128
|
+
.requiredOption("-d, --dir <uploadDir>", "Destination directory path in the library")
|
|
129
|
+
.option("--public", "Make uploaded files publicly accessible")
|
|
130
|
+
.option("--replace", "Replace files that already exist at the destination")
|
|
131
|
+
.option("--expires-at <iso8601>", "Expiration timestamp (RFC3339)")
|
|
132
|
+
.option("-m, --metadata <json>", "Additional metadata as a JSON object string")).action(withProfile(async (profile, opts) => {
|
|
133
|
+
await isActive(profile, DMS_ID);
|
|
134
|
+
const metadata = opts.metadata ? parseJSON("--metadata", opts.metadata) : undefined;
|
|
135
|
+
const files = opts.file.map((p) => new File([readBinaryFile(p)], basename(p)));
|
|
136
|
+
const res = await sdk.dms(profile).upload({
|
|
137
|
+
files: files,
|
|
138
|
+
uploadDir: opts.dir,
|
|
139
|
+
...(opts.public ? { public: true } : {}),
|
|
140
|
+
...(opts.replace ? { replace: true } : {}),
|
|
141
|
+
...(opts.expiresAt ? { expiresAt: opts.expiresAt } : {}),
|
|
142
|
+
...(metadata !== undefined ? { metadata } : {}),
|
|
143
|
+
});
|
|
144
|
+
return res?.data ?? res;
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
registerDownload() {
|
|
148
|
+
const cmd = withEnvOption(new Command("download")
|
|
149
|
+
.description("Download a file's binary content by its DMS key")
|
|
150
|
+
.argument("<key>", "The file's DMS key/path")
|
|
151
|
+
.requiredOption("-o, --out <file>", "File path to write the downloaded content to"));
|
|
152
|
+
cmd.action(withProfile(async (profile, key, opts) => {
|
|
153
|
+
await isActive(profile, DMS_ID);
|
|
154
|
+
const res = await sdk.dms(profile).download(key);
|
|
155
|
+
const buf = await toBuffer(res?.data ?? res);
|
|
156
|
+
writeOut(buf, opts.out, "File");
|
|
157
|
+
}));
|
|
158
|
+
return cmd;
|
|
159
|
+
}
|
|
160
|
+
registerLibraries() {
|
|
161
|
+
return registerCommand(new Command("libraries").description("List DMS libraries for the current project")).action(withProfile(async (profile) => {
|
|
162
|
+
await isActive(profile, DMS_ID);
|
|
163
|
+
const res = await sdk.dms(profile).libraries();
|
|
164
|
+
return res?.data ?? res;
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
registerDirs() {
|
|
168
|
+
const cmd = new Command("dirs").description("Manage library directories");
|
|
169
|
+
cmd.addCommand(registerCommand(new Command("list")
|
|
170
|
+
.description("List directories in a library")
|
|
171
|
+
.option("-p, --params <json>", "List parameters (e.g. library/path scope) as a JSON object string")).action(withProfile(async (profile, opts) => {
|
|
172
|
+
await isActive(profile, DMS_ID);
|
|
173
|
+
const params = opts.params ? parseJSON("--params", opts.params) : {};
|
|
174
|
+
const res = await sdk.dms(profile).dirs(params);
|
|
175
|
+
return res?.data ?? res;
|
|
176
|
+
})));
|
|
177
|
+
cmd.addCommand(registerCommand(new Command("create").description("Create a directory in a library").argument("<path>", "Directory path to create")).action(withProfile(async (profile, path) => {
|
|
178
|
+
await isActive(profile, DMS_ID);
|
|
179
|
+
const res = await sdk.dms(profile).createDir(path);
|
|
180
|
+
return res?.data ?? res;
|
|
181
|
+
})));
|
|
182
|
+
cmd.addCommand(registerCommand(new Command("delete").description("Delete a directory from a library").argument("<path>", "Directory path to delete")).action(withProfile(async (profile, path) => {
|
|
183
|
+
await isActive(profile, DMS_ID);
|
|
184
|
+
const res = await sdk.dms(profile).deleteDir(path);
|
|
185
|
+
return res?.data ?? res;
|
|
186
|
+
})));
|
|
187
|
+
return cmd;
|
|
188
|
+
}
|
|
189
|
+
// ===============================================================
|
|
190
|
+
// Data conversion (JSON / CSV / Excel matrix)
|
|
191
|
+
// ===============================================================
|
|
192
|
+
registerConvert() {
|
|
193
|
+
const cmd = new Command("convert").description("Convert data between JSON/CSV/Excel formats; inspect or validate data");
|
|
194
|
+
cmd.addCommand(this.registerConvertData());
|
|
195
|
+
cmd.addCommand(this.registerConvertInfo());
|
|
196
|
+
cmd.addCommand(this.registerConvertValidate());
|
|
197
|
+
cmd.addCommand(this.registerConvertJsonToCsv());
|
|
198
|
+
cmd.addCommand(this.registerConvertCsvToJson());
|
|
199
|
+
cmd.addCommand(this.registerConvertJsonToExcel());
|
|
200
|
+
cmd.addCommand(this.registerConvertCsvToExcel());
|
|
201
|
+
cmd.addCommand(this.registerConvertExcelToJson());
|
|
202
|
+
cmd.addCommand(this.registerConvertExcelToCsv());
|
|
203
|
+
return cmd;
|
|
204
|
+
}
|
|
205
|
+
readConvertSource(path, format) {
|
|
206
|
+
if (format === "json")
|
|
207
|
+
return JSON.parse(readTextFile(path));
|
|
208
|
+
if (format === "excel" || format === "xlsx")
|
|
209
|
+
return readBinaryFile(path);
|
|
210
|
+
return readTextFile(path);
|
|
211
|
+
}
|
|
212
|
+
registerConvertData() {
|
|
213
|
+
const cmd = withEnvOption(new Command("data")
|
|
214
|
+
.description("Convert data between formats via the generic conversion endpoint")
|
|
215
|
+
.requiredOption("-i, --input <path>", "Local file with the source data")
|
|
216
|
+
.requiredOption("--from <format>", "Source format: json | csv | excel | xlsx")
|
|
217
|
+
.requiredOption("--to <format>", "Target format: json | csv | excel | xlsx")
|
|
218
|
+
.option("--options <json>", "Additional conversion options as a JSON object (sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows, field_order)")
|
|
219
|
+
.option("-o, --out <file>", "Write the converted output to a file instead of stdout"));
|
|
220
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
221
|
+
await isActive(profile, DMS_ID);
|
|
222
|
+
const extra = opts.options ? parseJSON("--options", opts.options) : {};
|
|
223
|
+
const data = this.readConvertSource(opts.input, opts.from);
|
|
224
|
+
const res = await sdk.dms(profile).convertData(data, { from: opts.from, to: opts.to, ...extra });
|
|
225
|
+
await emitConvertResult(res, opts.out);
|
|
226
|
+
}));
|
|
227
|
+
return cmd;
|
|
228
|
+
}
|
|
229
|
+
registerConvertInfo() {
|
|
230
|
+
const cmd = withEnvOption(new Command("info")
|
|
231
|
+
.description("Analyze data structure and metadata without converting it")
|
|
232
|
+
.requiredOption("-i, --input <path>", "Local file with the data to analyze")
|
|
233
|
+
.requiredOption("--format <format>", "Format of the data: json | csv | excel | xlsx")
|
|
234
|
+
.option("-o, --out <file>", "Write the result to a file instead of stdout"));
|
|
235
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
236
|
+
await isActive(profile, DMS_ID);
|
|
237
|
+
const data = this.readConvertSource(opts.input, opts.format);
|
|
238
|
+
const res = await sdk.dms(profile).getDataInfo(data, { format: opts.format });
|
|
239
|
+
await emitConvertResult(res, opts.out);
|
|
240
|
+
}));
|
|
241
|
+
return cmd;
|
|
242
|
+
}
|
|
243
|
+
registerConvertValidate() {
|
|
244
|
+
const cmd = withEnvOption(new Command("validate")
|
|
245
|
+
.description("Validate data format without performing conversion")
|
|
246
|
+
.requiredOption("-i, --input <path>", "Local file with the data to validate")
|
|
247
|
+
.requiredOption("--format <format>", "Format to validate against: json | csv | excel | xlsx")
|
|
248
|
+
.option("-o, --out <file>", "Write the result to a file instead of stdout"));
|
|
249
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
250
|
+
await isActive(profile, DMS_ID);
|
|
251
|
+
const data = this.readConvertSource(opts.input, opts.format);
|
|
252
|
+
const res = await sdk.dms(profile).validateData(data, { format: opts.format });
|
|
253
|
+
await emitConvertResult(res, opts.out);
|
|
254
|
+
}));
|
|
255
|
+
return cmd;
|
|
256
|
+
}
|
|
257
|
+
registerConvertJsonToCsv() {
|
|
258
|
+
const cmd = withEnvOption(new Command("json-to-csv")
|
|
259
|
+
.description("Convert JSON data to CSV")
|
|
260
|
+
.requiredOption("-i, --input <path>", "Local JSON file to convert")
|
|
261
|
+
.option("--field-order <fields>", "Comma-separated column order")
|
|
262
|
+
.option("-o, --out <file>", "Write the CSV output to a file instead of stdout"));
|
|
263
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
264
|
+
await isActive(profile, DMS_ID);
|
|
265
|
+
const jsonData = JSON.parse(readTextFile(opts.input));
|
|
266
|
+
const options = conversionOptions({ fieldOrder: opts.fieldOrder });
|
|
267
|
+
const res = await sdk.dms(profile).jsonToCsv(jsonData, options);
|
|
268
|
+
await emitConvertResult(res, opts.out);
|
|
269
|
+
}));
|
|
270
|
+
return cmd;
|
|
271
|
+
}
|
|
272
|
+
registerConvertCsvToJson() {
|
|
273
|
+
const cmd = withEnvOption(new Command("csv-to-json")
|
|
274
|
+
.description("Convert CSV data to JSON")
|
|
275
|
+
.requiredOption("-i, --input <path>", "Local CSV file to convert")
|
|
276
|
+
.option("-o, --out <file>", "Write the JSON output to a file instead of stdout"));
|
|
277
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
278
|
+
await isActive(profile, DMS_ID);
|
|
279
|
+
const csvData = readTextFile(opts.input);
|
|
280
|
+
const res = await sdk.dms(profile).csvToJson(csvData);
|
|
281
|
+
await emitConvertResult(res, opts.out);
|
|
282
|
+
}));
|
|
283
|
+
return cmd;
|
|
284
|
+
}
|
|
285
|
+
registerConvertJsonToExcel() {
|
|
286
|
+
const cmd = withEnvOption(new Command("json-to-excel")
|
|
287
|
+
.description("Convert JSON data to Excel (.xlsx)")
|
|
288
|
+
.requiredOption("-i, --input <path>", "Local JSON file to convert")
|
|
289
|
+
.requiredOption("-o, --out <file>", "File path to write the Excel output to")
|
|
290
|
+
.option("--sheet-name <name>", "Excel sheet name")
|
|
291
|
+
.option("--field-order <fields>", "Comma-separated column order"));
|
|
292
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
293
|
+
await isActive(profile, DMS_ID);
|
|
294
|
+
const jsonData = JSON.parse(readTextFile(opts.input));
|
|
295
|
+
const options = conversionOptions({ sheetName: opts.sheetName, fieldOrder: opts.fieldOrder });
|
|
296
|
+
const res = await sdk.dms(profile).jsonToExcel(jsonData, options);
|
|
297
|
+
await emitConvertResult(res, opts.out);
|
|
298
|
+
}));
|
|
299
|
+
return cmd;
|
|
300
|
+
}
|
|
301
|
+
registerConvertCsvToExcel() {
|
|
302
|
+
const cmd = withEnvOption(new Command("csv-to-excel")
|
|
303
|
+
.description("Convert CSV data to Excel (.xlsx)")
|
|
304
|
+
.requiredOption("-i, --input <path>", "Local CSV file to convert")
|
|
305
|
+
.requiredOption("-o, --out <file>", "File path to write the Excel output to")
|
|
306
|
+
.option("--sheet-name <name>", "Excel sheet name"));
|
|
307
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
308
|
+
await isActive(profile, DMS_ID);
|
|
309
|
+
const csvData = readTextFile(opts.input);
|
|
310
|
+
const options = conversionOptions({ sheetName: opts.sheetName });
|
|
311
|
+
const res = await sdk.dms(profile).csvToExcel(csvData, options);
|
|
312
|
+
await emitConvertResult(res, opts.out);
|
|
313
|
+
}));
|
|
314
|
+
return cmd;
|
|
315
|
+
}
|
|
316
|
+
registerConvertExcelToJson() {
|
|
317
|
+
const cmd = withEnvOption(new Command("excel-to-json")
|
|
318
|
+
.description("Convert Excel (.xlsx) data to JSON")
|
|
319
|
+
.requiredOption("-i, --input <path>", "Local Excel file to convert")
|
|
320
|
+
.option("--sheet-name <name>", "Excel sheet name (defaults to the first sheet)")
|
|
321
|
+
.option("-o, --out <file>", "Write the JSON output to a file instead of stdout"));
|
|
322
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
323
|
+
await isActive(profile, DMS_ID);
|
|
324
|
+
const buf = readBinaryFile(opts.input);
|
|
325
|
+
const options = conversionOptions({ sheetName: opts.sheetName });
|
|
326
|
+
const res = await sdk.dms(profile).excelToJson(buf, options);
|
|
327
|
+
await emitConvertResult(res, opts.out);
|
|
328
|
+
}));
|
|
329
|
+
return cmd;
|
|
330
|
+
}
|
|
331
|
+
registerConvertExcelToCsv() {
|
|
332
|
+
const cmd = withEnvOption(new Command("excel-to-csv")
|
|
333
|
+
.description("Convert Excel (.xlsx) data to CSV")
|
|
334
|
+
.requiredOption("-i, --input <path>", "Local Excel file to convert")
|
|
335
|
+
.option("--sheet-name <name>", "Excel sheet name (defaults to the first sheet)")
|
|
336
|
+
.option("-o, --out <file>", "Write the CSV output to a file instead of stdout"));
|
|
337
|
+
cmd.action(withProfile(async (profile, opts) => {
|
|
338
|
+
await isActive(profile, DMS_ID);
|
|
339
|
+
const buf = readBinaryFile(opts.input);
|
|
340
|
+
const options = conversionOptions({ sheetName: opts.sheetName });
|
|
341
|
+
const res = await sdk.dms(profile).excelToCsv(buf, options);
|
|
342
|
+
await emitConvertResult(res, opts.out);
|
|
343
|
+
}));
|
|
344
|
+
return cmd;
|
|
345
|
+
}
|
|
346
|
+
// ===============================================================
|
|
347
|
+
// OCR
|
|
348
|
+
// ===============================================================
|
|
349
|
+
registerOcr() {
|
|
350
|
+
return registerCommand(new Command("ocr")
|
|
351
|
+
.description("Run OCR extraction on an image using a saved OCR model")
|
|
352
|
+
.requiredOption("-m, --model <uuid>", "OCR model UUID")
|
|
353
|
+
.option("-k, --image-key <key>", "DMS file key/path of the image")
|
|
354
|
+
.option("-i, --image-file <path>", "Local image file to OCR (base64-encoded and sent inline)")
|
|
355
|
+
.option("-b, --boundary <json>", "Optional document boundary as JSON: {x,y,width,height}")).action(withProfile(async (profile, opts) => {
|
|
356
|
+
await isActive(profile, DMS_ID);
|
|
357
|
+
if (!opts.imageKey && !opts.imageFile) {
|
|
358
|
+
console.error("one of --image-key or --image-file is required");
|
|
359
|
+
process.exit(1);
|
|
360
|
+
}
|
|
361
|
+
const boundary = opts.boundary ? parseJSON("--boundary", opts.boundary) : undefined;
|
|
362
|
+
const image = opts.imageFile
|
|
363
|
+
? `data:${mimeFromPath(opts.imageFile)};base64,${readBinaryFile(opts.imageFile).toString("base64")}`
|
|
364
|
+
: undefined;
|
|
365
|
+
const res = await sdk.dms(profile).ocrExtract({
|
|
366
|
+
model_uuid: opts.model,
|
|
367
|
+
...(opts.imageKey ? { image_key: opts.imageKey } : {}),
|
|
368
|
+
...(image ? { image } : {}),
|
|
369
|
+
...(boundary ? { document_boundary: boundary } : {}),
|
|
370
|
+
});
|
|
371
|
+
return res?.data ?? res;
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
// ===============================================================
|
|
375
|
+
// Documents
|
|
376
|
+
// ===============================================================
|
|
377
|
+
registerDocument() {
|
|
378
|
+
const cmd = new Command("document").description("Manage DMS documents (templated content with revisions)");
|
|
379
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
380
|
+
.description("Create a document")
|
|
381
|
+
.requiredOption("-p, --path <path>", "Document path (including directory and filename)")
|
|
382
|
+
.option("-c, --content <content>", "Document content")
|
|
383
|
+
.option("--variant <variant>", "Document variant identifier")
|
|
384
|
+
.option("--sources <json>", "Sources metadata as a JSON array")
|
|
385
|
+
.option("--fields <json>", "Custom fields metadata as a JSON array")).action(withProfile(async (profile, opts) => {
|
|
386
|
+
await isActive(profile, DMS_ID);
|
|
387
|
+
const sources = opts.sources ? parseJSON("--sources", opts.sources) : undefined;
|
|
388
|
+
const fields = opts.fields ? parseJSON("--fields", opts.fields) : undefined;
|
|
389
|
+
const res = await sdk.dms(profile).createDocument({
|
|
390
|
+
path: opts.path,
|
|
391
|
+
...(opts.content !== undefined ? { content: opts.content } : {}),
|
|
392
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
393
|
+
...(sources !== undefined ? { sources } : {}),
|
|
394
|
+
...(fields !== undefined ? { fields } : {}),
|
|
395
|
+
});
|
|
396
|
+
return res?.data ?? res;
|
|
397
|
+
})));
|
|
398
|
+
cmd.addCommand(registerCommand(new Command("get").description("Get a document by path").argument("<path>", "Document path")).action(withProfile(async (profile, path) => {
|
|
399
|
+
await isActive(profile, DMS_ID);
|
|
400
|
+
const res = await sdk.dms(profile).getDocument(path);
|
|
401
|
+
return res?.data ?? res;
|
|
402
|
+
})));
|
|
403
|
+
const rawCmd = withEnvOption(new Command("get-raw").description("Get a document's raw pdoc content").argument("<path>", "Document path"));
|
|
404
|
+
rawCmd.action(withProfile(async (profile, path) => {
|
|
405
|
+
await isActive(profile, DMS_ID);
|
|
406
|
+
const res = await sdk.dms(profile).getDocumentRaw(path);
|
|
407
|
+
console.log(res?.data ?? res);
|
|
408
|
+
}));
|
|
409
|
+
cmd.addCommand(rawCmd);
|
|
410
|
+
cmd.addCommand(registerCommand(new Command("update")
|
|
411
|
+
.description("Update an existing document")
|
|
412
|
+
.requiredOption("-p, --path <path>", "Document path")
|
|
413
|
+
.option("--variant <variant>", "Variant to update")
|
|
414
|
+
.option("--version <n>", "Current version for optimistic locking", (v) => parseInt(v, 10))
|
|
415
|
+
.option("-c, --content <content>", "Updated content")
|
|
416
|
+
.option("--sources <json>", "Updated sources metadata as a JSON array")
|
|
417
|
+
.option("--fields <json>", "Updated fields metadata as a JSON array")).action(withProfile(async (profile, opts) => {
|
|
418
|
+
await isActive(profile, DMS_ID);
|
|
419
|
+
const sources = opts.sources ? parseJSON("--sources", opts.sources) : undefined;
|
|
420
|
+
const fields = opts.fields ? parseJSON("--fields", opts.fields) : undefined;
|
|
421
|
+
const res = await sdk.dms(profile).updateDocument({
|
|
422
|
+
path: opts.path,
|
|
423
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
424
|
+
...(opts.version !== undefined ? { version: opts.version } : {}),
|
|
425
|
+
...(opts.content !== undefined ? { content: opts.content } : {}),
|
|
426
|
+
...(sources !== undefined ? { sources } : {}),
|
|
427
|
+
...(fields !== undefined ? { fields } : {}),
|
|
428
|
+
});
|
|
429
|
+
return res?.data ?? res;
|
|
430
|
+
})));
|
|
431
|
+
cmd.addCommand(registerCommand(new Command("delete").description("Delete a document").argument("<path>", "Document path")).action(withProfile(async (profile, path) => {
|
|
432
|
+
await isActive(profile, DMS_ID);
|
|
433
|
+
const res = await sdk.dms(profile).deleteDocument(path);
|
|
434
|
+
return res?.data ?? res;
|
|
435
|
+
})));
|
|
436
|
+
cmd.addCommand(registerCommand(new Command("list")
|
|
437
|
+
.description("List documents")
|
|
438
|
+
.option("-s, --search-text <text>", "Search text")
|
|
439
|
+
.option("-r, --recursive", "Search recursively through directories")).action(withProfile(async (profile, opts) => {
|
|
440
|
+
await isActive(profile, DMS_ID);
|
|
441
|
+
const params = opts.searchText || opts.recursive
|
|
442
|
+
? {
|
|
443
|
+
...(opts.searchText ? { searchText: opts.searchText } : {}),
|
|
444
|
+
...(opts.recursive ? { recursive: true } : {}),
|
|
445
|
+
}
|
|
446
|
+
: undefined;
|
|
447
|
+
const res = await sdk.dms(profile).listDocuments(params);
|
|
448
|
+
return res?.data ?? res;
|
|
449
|
+
})));
|
|
450
|
+
cmd.addCommand(registerCommand(new Command("list-deleted")
|
|
451
|
+
.description("List soft-deleted documents")
|
|
452
|
+
.option("-s, --search-text <text>", "Search text")
|
|
453
|
+
.option("-r, --recursive", "Search recursively through directories")).action(withProfile(async (profile, opts) => {
|
|
454
|
+
await isActive(profile, DMS_ID);
|
|
455
|
+
const params = opts.searchText || opts.recursive
|
|
456
|
+
? {
|
|
457
|
+
...(opts.searchText ? { searchText: opts.searchText } : {}),
|
|
458
|
+
...(opts.recursive ? { recursive: true } : {}),
|
|
459
|
+
}
|
|
460
|
+
: undefined;
|
|
461
|
+
const res = await sdk.dms(profile).listDeletedDocuments(params);
|
|
462
|
+
return res?.data ?? res;
|
|
463
|
+
})));
|
|
464
|
+
cmd.addCommand(registerCommand(new Command("restore")
|
|
465
|
+
.description("Restore a deleted document")
|
|
466
|
+
.requiredOption("-p, --path <path>", "Path of the deleted document")
|
|
467
|
+
.option("--new-path <path>", "Optional new path to restore to")).action(withProfile(async (profile, opts) => {
|
|
468
|
+
await isActive(profile, DMS_ID);
|
|
469
|
+
const res = await sdk.dms(profile).restoreDocument({
|
|
470
|
+
path: opts.path,
|
|
471
|
+
...(opts.newPath ? { newPath: opts.newPath } : {}),
|
|
472
|
+
});
|
|
473
|
+
return res?.data ?? res;
|
|
474
|
+
})));
|
|
475
|
+
cmd.addCommand(registerCommand(new Command("comment")
|
|
476
|
+
.description("Add a comment to a document")
|
|
477
|
+
.requiredOption("-p, --path <path>", "Target document path")
|
|
478
|
+
.requiredOption("-c, --content <content>", "Comment body")
|
|
479
|
+
.option("--variant <variant>", "Variant the comment belongs to")
|
|
480
|
+
.option("--from <n>", "Comment start position", (v) => parseInt(v, 10))
|
|
481
|
+
.option("--to <n>", "Comment end position", (v) => parseInt(v, 10))).action(withProfile(async (profile, opts) => {
|
|
482
|
+
await isActive(profile, DMS_ID);
|
|
483
|
+
const res = await sdk.dms(profile).createDocumentComment({
|
|
484
|
+
path: opts.path,
|
|
485
|
+
content: opts.content,
|
|
486
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
487
|
+
...(opts.from !== undefined ? { from: opts.from } : {}),
|
|
488
|
+
...(opts.to !== undefined ? { to: opts.to } : {}),
|
|
489
|
+
});
|
|
490
|
+
return res?.data ?? res;
|
|
491
|
+
})));
|
|
492
|
+
cmd.addCommand(registerCommand(new Command("generate")
|
|
493
|
+
.description("Generate (render) a document template with data")
|
|
494
|
+
.requiredOption("-p, --path <path>", "Path to the document template")
|
|
495
|
+
.option("--variant <variant>", 'Variant to render (defaults to "default")')
|
|
496
|
+
.requiredOption("-d, --data <json>", "Data map passed to the template engine, as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
497
|
+
await isActive(profile, DMS_ID);
|
|
498
|
+
const data = parseJSON("--data", opts.data);
|
|
499
|
+
const res = await sdk.dms(profile).generateDocument({
|
|
500
|
+
path: opts.path,
|
|
501
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
502
|
+
data,
|
|
503
|
+
});
|
|
504
|
+
return res?.data ?? res;
|
|
505
|
+
})));
|
|
506
|
+
cmd.addCommand(registerCommand(new Command("revisions").description("List revisions of a document").argument("<path>", "Document path")).action(withProfile(async (profile, path) => {
|
|
507
|
+
await isActive(profile, DMS_ID);
|
|
508
|
+
const res = await sdk.dms(profile).listDocumentRevisions(path);
|
|
509
|
+
return res?.data ?? res;
|
|
510
|
+
})));
|
|
511
|
+
cmd.addCommand(registerCommand(new Command("revision")
|
|
512
|
+
.description("Get a specific document revision")
|
|
513
|
+
.argument("<path>", "Document path")
|
|
514
|
+
.requiredOption("-v, --version <version>", "Revision version identifier")).action(withProfile(async (profile, path, opts) => {
|
|
515
|
+
await isActive(profile, DMS_ID);
|
|
516
|
+
const res = await sdk.dms(profile).getDocumentRevision(path, opts.version);
|
|
517
|
+
return res?.data ?? res;
|
|
518
|
+
})));
|
|
519
|
+
return cmd;
|
|
520
|
+
}
|
|
521
|
+
// ===============================================================
|
|
522
|
+
// Backup (library export archives)
|
|
523
|
+
// ===============================================================
|
|
524
|
+
registerBackup() {
|
|
525
|
+
const cmd = new Command("backup").description("Manage DMS library export archives (backups)");
|
|
526
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
527
|
+
.description("Create a library export archive (a snapshot of the project's library or a directory within it)")
|
|
528
|
+
.option("-p, --path <path>", "Optional directory path to scope the export to")
|
|
529
|
+
.option("--archive-format <format>", "Archive format: zip | tar | tar.gz")).action(withProfile(async (profile, opts) => {
|
|
530
|
+
await isActive(profile, DMS_ID);
|
|
531
|
+
const res = await sdk.dms(profile).createExport({
|
|
532
|
+
...(opts.path ? { path: opts.path } : {}),
|
|
533
|
+
...(opts.archiveFormat ? { format: opts.archiveFormat } : {}),
|
|
534
|
+
});
|
|
535
|
+
return res?.data ?? res;
|
|
536
|
+
})));
|
|
537
|
+
cmd.addCommand(registerCommand(new Command("list").description("List export archives for the project's library")).action(withProfile(async (profile) => {
|
|
538
|
+
await isActive(profile, DMS_ID);
|
|
539
|
+
const res = await sdk.dms(profile).listExports();
|
|
540
|
+
return res?.data ?? res;
|
|
541
|
+
})));
|
|
542
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
543
|
+
.description("Get a single export archive (metadata + download URL)")
|
|
544
|
+
.argument("<exportUuid>", "Export UUID")).action(withProfile(async (profile, exportUuid) => {
|
|
545
|
+
await isActive(profile, DMS_ID);
|
|
546
|
+
const res = await sdk.dms(profile).getExport(exportUuid);
|
|
547
|
+
return res?.data ?? res;
|
|
548
|
+
})));
|
|
549
|
+
return cmd;
|
|
550
|
+
}
|
|
551
|
+
// ===============================================================
|
|
552
|
+
// Policies (quota / file-type / notification, library + dir scope)
|
|
553
|
+
// ===============================================================
|
|
554
|
+
registerPolicies() {
|
|
555
|
+
const cmd = new Command("policies").description("Manage DMS library/directory policies (quota, file-type, notification)");
|
|
556
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
557
|
+
.description("Get the effective policy for the project's library or a directory within it")
|
|
558
|
+
.option("--dir <path>", "Directory path (resolves platform-default -> library -> dir); omit for the library-level policy")).action(withProfile(async (profile, opts) => {
|
|
559
|
+
await isActive(profile, DMS_ID);
|
|
560
|
+
const res = opts.dir
|
|
561
|
+
? await sdk.dms(profile).getDirPolicy(opts.dir)
|
|
562
|
+
: await sdk.dms(profile).getLibraryPolicy();
|
|
563
|
+
return res?.data ?? res;
|
|
564
|
+
})));
|
|
565
|
+
cmd.addCommand(registerCommand(new Command("set")
|
|
566
|
+
.description("Set/update the project's library or directory policy")
|
|
567
|
+
.option("--dir <path>", "Directory path to scope the policy to; omit to set the library-level policy")
|
|
568
|
+
.requiredOption("-p, --payload <json>", "Policy fields to set, as a JSON object")).action(withProfile(async (profile, opts) => {
|
|
569
|
+
await isActive(profile, DMS_ID);
|
|
570
|
+
const payload = parseJSON("--payload", opts.payload);
|
|
571
|
+
const res = opts.dir
|
|
572
|
+
? await sdk.dms(profile).setDirPolicy(opts.dir, payload)
|
|
573
|
+
: await sdk.dms(profile).setLibraryPolicy(payload);
|
|
574
|
+
return res?.data ?? res;
|
|
575
|
+
})));
|
|
576
|
+
return cmd;
|
|
577
|
+
}
|
|
578
|
+
// ===============================================================
|
|
579
|
+
// Reminders (notification-rules engine)
|
|
580
|
+
// ===============================================================
|
|
581
|
+
registerReminders() {
|
|
582
|
+
const cmd = new Command("reminders").description("Manage DMS notification rules (recurring file reminders)");
|
|
583
|
+
cmd.addCommand(registerCommand(new Command("list").description("List notification rules for the project's library")).action(withProfile(async (profile) => {
|
|
584
|
+
await isActive(profile, DMS_ID);
|
|
585
|
+
const res = await sdk.dms(profile).listNotificationRules();
|
|
586
|
+
return res?.data ?? res;
|
|
587
|
+
})));
|
|
588
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
589
|
+
.description("Create a recurring reminder (notification rule) for a media file")
|
|
590
|
+
.option("--media-uuid <uuid>", "Target file UUID (required unless --file-key is given)")
|
|
591
|
+
.option("--file-key <key>", "Target file key/path (alternative to --media-uuid)")
|
|
592
|
+
.requiredOption("--frequency <frequency>", "Recurrence frequency: daily | weekly | monthly | yearly")
|
|
593
|
+
.requiredOption("--start-at <iso8601>", "First occurrence timestamp (RFC3339, must be in the future)")
|
|
594
|
+
.option("--interval <n>", "Repeat every N frequency units (default: 1)", (v) => parseInt(v, 10))
|
|
595
|
+
.option("--end-at <iso8601>", "Optional recurrence end timestamp (RFC3339)")
|
|
596
|
+
.option("--max-occurrences <n>", "Optional cap on number of occurrences", (v) => parseInt(v, 10))
|
|
597
|
+
.option("--recipient-email <email>", "Recipient email for the reminder")).action(withProfile(async (profile, opts) => {
|
|
598
|
+
await isActive(profile, DMS_ID);
|
|
599
|
+
if (!opts.mediaUuid && !opts.fileKey) {
|
|
600
|
+
console.error("one of --media-uuid or --file-key is required");
|
|
601
|
+
process.exit(1);
|
|
602
|
+
}
|
|
603
|
+
const res = await sdk.dms(profile).createNotificationRule({
|
|
604
|
+
...(opts.mediaUuid ? { media_uuid: opts.mediaUuid } : {}),
|
|
605
|
+
...(opts.fileKey ? { file_key: opts.fileKey } : {}),
|
|
606
|
+
frequency: opts.frequency,
|
|
607
|
+
start_at: opts.startAt,
|
|
608
|
+
...(opts.interval !== undefined ? { interval: opts.interval } : {}),
|
|
609
|
+
...(opts.endAt ? { end_at: opts.endAt } : {}),
|
|
610
|
+
...(opts.maxOccurrences !== undefined ? { max_occurrences: opts.maxOccurrences } : {}),
|
|
611
|
+
...(opts.recipientEmail ? { recipient_email: opts.recipientEmail } : {}),
|
|
612
|
+
});
|
|
613
|
+
return res?.data ?? res;
|
|
614
|
+
})));
|
|
615
|
+
cmd.addCommand(registerCommand(new Command("delete")
|
|
616
|
+
.description("Delete a notification rule")
|
|
617
|
+
.argument("<ruleUuid>", "Notification rule UUID")).action(withProfile(async (profile, ruleUuid) => {
|
|
618
|
+
await isActive(profile, DMS_ID);
|
|
619
|
+
const res = await sdk.dms(profile).deleteNotificationRule(ruleUuid);
|
|
620
|
+
return res?.data ?? res;
|
|
621
|
+
})));
|
|
622
|
+
return cmd;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
export default new DMSCommand();
|