@nickchristensen/ppls 1.0.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 +1190 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/add-command.d.ts +24 -0
- package/dist/add-command.js +47 -0
- package/dist/base-command.d.ts +63 -0
- package/dist/base-command.js +306 -0
- package/dist/commands/config/get.d.ts +11 -0
- package/dist/commands/config/get.js +34 -0
- package/dist/commands/config/init.d.ts +15 -0
- package/dist/commands/config/init.js +43 -0
- package/dist/commands/config/list.d.ts +13 -0
- package/dist/commands/config/list.js +64 -0
- package/dist/commands/config/remove.d.ts +11 -0
- package/dist/commands/config/remove.js +26 -0
- package/dist/commands/config/set.d.ts +12 -0
- package/dist/commands/config/set.js +58 -0
- package/dist/commands/correspondents/add.d.ts +12 -0
- package/dist/commands/correspondents/add.js +20 -0
- package/dist/commands/correspondents/delete.d.ts +16 -0
- package/dist/commands/correspondents/delete.js +18 -0
- package/dist/commands/correspondents/list.d.ts +9 -0
- package/dist/commands/correspondents/list.js +15 -0
- package/dist/commands/correspondents/show.d.ts +14 -0
- package/dist/commands/correspondents/show.js +17 -0
- package/dist/commands/correspondents/update.d.ts +18 -0
- package/dist/commands/correspondents/update.js +24 -0
- package/dist/commands/custom-fields/add.d.ts +16 -0
- package/dist/commands/custom-fields/add.js +91 -0
- package/dist/commands/custom-fields/delete.d.ts +16 -0
- package/dist/commands/custom-fields/delete.js +18 -0
- package/dist/commands/custom-fields/list.d.ts +9 -0
- package/dist/commands/custom-fields/list.js +12 -0
- package/dist/commands/custom-fields/show.d.ts +14 -0
- package/dist/commands/custom-fields/show.js +17 -0
- package/dist/commands/custom-fields/update.d.ts +20 -0
- package/dist/commands/custom-fields/update.js +93 -0
- package/dist/commands/document-types/add.d.ts +12 -0
- package/dist/commands/document-types/add.js +22 -0
- package/dist/commands/document-types/delete.d.ts +16 -0
- package/dist/commands/document-types/delete.js +18 -0
- package/dist/commands/document-types/list.d.ts +9 -0
- package/dist/commands/document-types/list.js +12 -0
- package/dist/commands/document-types/show.d.ts +14 -0
- package/dist/commands/document-types/show.js +17 -0
- package/dist/commands/document-types/update.d.ts +18 -0
- package/dist/commands/document-types/update.js +26 -0
- package/dist/commands/documents/add.d.ts +70 -0
- package/dist/commands/documents/add.js +166 -0
- package/dist/commands/documents/delete.d.ts +16 -0
- package/dist/commands/documents/delete.js +18 -0
- package/dist/commands/documents/download.d.ts +48 -0
- package/dist/commands/documents/download.js +152 -0
- package/dist/commands/documents/list.d.ts +9 -0
- package/dist/commands/documents/list.js +14 -0
- package/dist/commands/documents/show.d.ts +14 -0
- package/dist/commands/documents/show.js +19 -0
- package/dist/commands/documents/update.d.ts +25 -0
- package/dist/commands/documents/update.js +42 -0
- package/dist/commands/profile.d.ts +13 -0
- package/dist/commands/profile.js +19 -0
- package/dist/commands/tags/add.d.ts +17 -0
- package/dist/commands/tags/add.js +29 -0
- package/dist/commands/tags/delete.d.ts +16 -0
- package/dist/commands/tags/delete.js +18 -0
- package/dist/commands/tags/list.d.ts +10 -0
- package/dist/commands/tags/list.js +18 -0
- package/dist/commands/tags/show.d.ts +16 -0
- package/dist/commands/tags/show.js +24 -0
- package/dist/commands/tags/update.d.ts +21 -0
- package/dist/commands/tags/update.js +30 -0
- package/dist/delete-command.d.ts +20 -0
- package/dist/delete-command.js +48 -0
- package/dist/helpers/config-store.d.ts +4 -0
- package/dist/helpers/config-store.js +35 -0
- package/dist/helpers/date-utils.d.ts +3 -0
- package/dist/helpers/date-utils.js +27 -0
- package/dist/helpers/table.d.ts +20 -0
- package/dist/helpers/table.js +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/list-command.d.ts +49 -0
- package/dist/list-command.js +98 -0
- package/dist/paginated-command.d.ts +48 -0
- package/dist/paginated-command.js +89 -0
- package/dist/show-command.d.ts +27 -0
- package/dist/show-command.js +50 -0
- package/dist/types/correspondents.d.ts +28 -0
- package/dist/types/correspondents.js +1 -0
- package/dist/types/custom-fields.d.ts +18 -0
- package/dist/types/custom-fields.js +1 -0
- package/dist/types/document-types.d.ts +27 -0
- package/dist/types/document-types.js +1 -0
- package/dist/types/documents.d.ts +70 -0
- package/dist/types/documents.js +1 -0
- package/dist/types/profile.d.ts +15 -0
- package/dist/types/profile.js +1 -0
- package/dist/types/shared.d.ts +4 -0
- package/dist/types/shared.js +1 -0
- package/dist/types/tags.d.ts +31 -0
- package/dist/types/tags.js +1 -0
- package/dist/update-command.d.ts +28 -0
- package/dist/update-command.js +51 -0
- package/oclif.manifest.json +3313 -0
- package/package.json +87 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import { readConfig, writeConfig } from '../../helpers/config-store.js';
|
|
3
|
+
export default class ConfigRemove extends Command {
|
|
4
|
+
static args = {
|
|
5
|
+
key: Args.string({ description: 'Config key', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Remove a config value';
|
|
8
|
+
static enableJsonFlag = true;
|
|
9
|
+
static examples = ['<%= config.bin %> <%= command.id %> token'];
|
|
10
|
+
async run() {
|
|
11
|
+
const { args } = await this.parse();
|
|
12
|
+
const typedArgs = args;
|
|
13
|
+
const config = await readConfig(this.config.configDir);
|
|
14
|
+
if (Object.hasOwn(config, typedArgs.key)) {
|
|
15
|
+
delete config[typedArgs.key];
|
|
16
|
+
await writeConfig(this.config.configDir, config);
|
|
17
|
+
if (!this.jsonEnabled()) {
|
|
18
|
+
this.log(`Removed ${typedArgs.key}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (!this.jsonEnabled()) {
|
|
22
|
+
this.log(`Config key ${typedArgs.key} not set.`);
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import { type ConfigData } from '../../helpers/config-store.js';
|
|
3
|
+
export default class ConfigSet extends Command {
|
|
4
|
+
static args: {
|
|
5
|
+
key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
value: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
static description: string;
|
|
9
|
+
static enableJsonFlag: boolean;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
run(): Promise<ConfigData>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import { readConfig, writeConfig } from '../../helpers/config-store.js';
|
|
3
|
+
const parseConfigValue = (raw) => {
|
|
4
|
+
let trimmed = raw.trim();
|
|
5
|
+
if (!trimmed) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
|
|
9
|
+
(trimmed.startsWith('"') && trimmed.endsWith('"'))) {
|
|
10
|
+
trimmed = trimmed.slice(1, -1).trim();
|
|
11
|
+
}
|
|
12
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(trimmed);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
18
|
+
throw new Error(`Invalid JSON value: ${message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return trimmed;
|
|
22
|
+
};
|
|
23
|
+
export default class ConfigSet extends Command {
|
|
24
|
+
static args = {
|
|
25
|
+
key: Args.string({ description: 'Config key', required: true }),
|
|
26
|
+
value: Args.string({ description: 'Config value', required: true }),
|
|
27
|
+
};
|
|
28
|
+
static description = 'Set a config value';
|
|
29
|
+
static enableJsonFlag = true;
|
|
30
|
+
static examples = [
|
|
31
|
+
'<%= config.bin %> <%= command.id %> hostname https://paperless.example.com',
|
|
32
|
+
'<%= config.bin %> <%= command.id %> headers \'{"X-Api-Key":"token"}\'',
|
|
33
|
+
];
|
|
34
|
+
async run() {
|
|
35
|
+
const { args } = await this.parse();
|
|
36
|
+
const typedArgs = args;
|
|
37
|
+
const config = await readConfig(this.config.configDir);
|
|
38
|
+
let parsedValue;
|
|
39
|
+
try {
|
|
40
|
+
parsedValue = parseConfigValue(typedArgs.value);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
44
|
+
this.error(message);
|
|
45
|
+
}
|
|
46
|
+
if (typedArgs.key === 'headers' &&
|
|
47
|
+
(!parsedValue || typeof parsedValue !== 'object' || Array.isArray(parsedValue))) {
|
|
48
|
+
this.warn('Config key "headers" must be a JSON object. Example: {"X-Api-Key":"token"}');
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
config[typedArgs.key] = parsedValue;
|
|
52
|
+
await writeConfig(this.config.configDir, config);
|
|
53
|
+
if (!this.jsonEnabled()) {
|
|
54
|
+
this.log(`Set ${typedArgs.key}`);
|
|
55
|
+
}
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Correspondent, CorrespondentCreate } from '../../types/correspondents.js';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
export default class CorrespondentsAdd extends AddCommand<CorrespondentCreate, Correspondent> {
|
|
4
|
+
static args: {
|
|
5
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
protected createPath: string;
|
|
10
|
+
protected buildPayload(args: unknown, _flags: Record<string, unknown>): CorrespondentCreate;
|
|
11
|
+
protected plainTemplate(correspondent: Correspondent): string | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
export default class CorrespondentsAdd extends AddCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
name: Args.string({ description: 'Correspondent name', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Create a correspondent';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> "Acme Corp"'];
|
|
9
|
+
createPath = '/api/correspondents/';
|
|
10
|
+
buildPayload(args, _flags) {
|
|
11
|
+
const typedArgs = args;
|
|
12
|
+
return {
|
|
13
|
+
'matching_algorithm': 6,
|
|
14
|
+
name: typedArgs.name,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
plainTemplate(correspondent) {
|
|
18
|
+
return `[${correspondent.id}] ${correspondent.name}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DeleteCommand } from '../../delete-command.js';
|
|
2
|
+
export default class CorrespondentsDelete extends DeleteCommand {
|
|
3
|
+
static args: {
|
|
4
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
5
|
+
max?: number;
|
|
6
|
+
min?: number;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
static description: string;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
static flags: {
|
|
12
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
protected deleteLabel(id: number | string): string;
|
|
15
|
+
protected deletePath(id: number | string): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { DeleteCommand } from '../../delete-command.js';
|
|
3
|
+
export default class CorrespondentsDelete extends DeleteCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
id: Args.integer({ description: 'Correspondent id', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Delete a correspondent';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123'];
|
|
9
|
+
static flags = {
|
|
10
|
+
yes: Flags.boolean({ char: 'y', description: 'Skip confirmation prompt' }),
|
|
11
|
+
};
|
|
12
|
+
deleteLabel(id) {
|
|
13
|
+
return `correspondent ${id}`;
|
|
14
|
+
}
|
|
15
|
+
deletePath(id) {
|
|
16
|
+
return `/api/correspondents/${id}/`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Correspondent } from '../../types/correspondents.js';
|
|
2
|
+
import { ListCommand } from '../../list-command.js';
|
|
3
|
+
export default class CorrespondentsList extends ListCommand<Correspondent> {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
protected listPath: string;
|
|
7
|
+
protected tableAttrs: string[];
|
|
8
|
+
protected plainTemplate(correspondent: Correspondent): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ListCommand } from '../../list-command.js';
|
|
2
|
+
export default class CorrespondentsList extends ListCommand {
|
|
3
|
+
static description = 'List correspondents';
|
|
4
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
5
|
+
listPath = '/api/correspondents/';
|
|
6
|
+
tableAttrs = ['id', 'name', 'slug', 'document_count'];
|
|
7
|
+
plainTemplate(correspondent) {
|
|
8
|
+
if (!correspondent.name) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const count = correspondent.document_count;
|
|
12
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
13
|
+
return `[${correspondent.id}] ${correspondent.name}${suffix}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Correspondent } from '../../types/correspondents.js';
|
|
2
|
+
import { ShowCommand } from '../../show-command.js';
|
|
3
|
+
export default class CorrespondentsShow extends ShowCommand<Correspondent> {
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: string[];
|
|
12
|
+
protected plainTemplate(correspondent: Correspondent): string | undefined;
|
|
13
|
+
protected showPath(id: number | string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { ShowCommand } from '../../show-command.js';
|
|
3
|
+
export default class CorrespondentsShow extends ShowCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
id: Args.integer({ description: 'Correspondent id', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Show correspondent details';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123'];
|
|
9
|
+
plainTemplate(correspondent) {
|
|
10
|
+
const count = correspondent.document_count;
|
|
11
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
12
|
+
return `[${correspondent.id}] ${correspondent.name}${suffix}`;
|
|
13
|
+
}
|
|
14
|
+
showPath(id) {
|
|
15
|
+
return `/api/correspondents/${id}/`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Correspondent, CorrespondentUpdate } from '../../types/correspondents.js';
|
|
2
|
+
import { UpdateCommand } from '../../update-command.js';
|
|
3
|
+
export default class CorrespondentsUpdate extends UpdateCommand<CorrespondentUpdate, Correspondent> {
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: string[];
|
|
12
|
+
static flags: {
|
|
13
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
};
|
|
15
|
+
protected buildPayload(_args: unknown, flags: Record<string, unknown>): CorrespondentUpdate;
|
|
16
|
+
protected plainTemplate(correspondent: Correspondent): string | undefined;
|
|
17
|
+
protected updatePath(id: number | string): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { UpdateCommand } from '../../update-command.js';
|
|
3
|
+
export default class CorrespondentsUpdate extends UpdateCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
id: Args.integer({ description: 'Correspondent id', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Update a correspondent';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123 --name "Acme Corp"'];
|
|
9
|
+
static flags = {
|
|
10
|
+
name: Flags.string({ description: 'Correspondent name' }),
|
|
11
|
+
};
|
|
12
|
+
buildPayload(_args, flags) {
|
|
13
|
+
const typedFlags = flags;
|
|
14
|
+
return {
|
|
15
|
+
name: typedFlags.name,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
plainTemplate(correspondent) {
|
|
19
|
+
return `[${correspondent.id}] ${correspondent.name}`;
|
|
20
|
+
}
|
|
21
|
+
updatePath(id) {
|
|
22
|
+
return `/api/correspondents/${id}/`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CustomField, CustomFieldCreate } from '../../types/custom-fields.js';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
export default class CustomFieldsAdd extends AddCommand<CustomFieldCreate, CustomField> {
|
|
4
|
+
static args: {
|
|
5
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
static flags: {
|
|
10
|
+
'data-type': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
option: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
protected createPath: string;
|
|
14
|
+
protected buildPayload(args: unknown, flags: Record<string, unknown>): CustomFieldCreate;
|
|
15
|
+
protected plainTemplate(field: CustomField): string | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
const dataTypeOptions = [
|
|
4
|
+
'boolean',
|
|
5
|
+
'date',
|
|
6
|
+
'integer',
|
|
7
|
+
'number',
|
|
8
|
+
'monetary',
|
|
9
|
+
'text',
|
|
10
|
+
'url',
|
|
11
|
+
'document link',
|
|
12
|
+
'select',
|
|
13
|
+
'long text',
|
|
14
|
+
];
|
|
15
|
+
const dataTypeMap = {
|
|
16
|
+
boolean: 'boolean',
|
|
17
|
+
date: 'date',
|
|
18
|
+
'document link': 'documentlink',
|
|
19
|
+
integer: 'integer',
|
|
20
|
+
'long text': 'longtext',
|
|
21
|
+
monetary: 'monetary',
|
|
22
|
+
number: 'float',
|
|
23
|
+
select: 'select',
|
|
24
|
+
text: 'string',
|
|
25
|
+
url: 'url',
|
|
26
|
+
};
|
|
27
|
+
export default class CustomFieldsAdd extends AddCommand {
|
|
28
|
+
static args = {
|
|
29
|
+
name: Args.string({ description: 'Custom field name', required: true }),
|
|
30
|
+
};
|
|
31
|
+
static description = 'Create a custom field';
|
|
32
|
+
static examples = ['<%= config.bin %> <%= command.id %> "Due Date" --data-type date'];
|
|
33
|
+
static flags = {
|
|
34
|
+
'data-type': Flags.string({
|
|
35
|
+
description: 'Custom field data type',
|
|
36
|
+
options: [...dataTypeOptions],
|
|
37
|
+
relationships: [
|
|
38
|
+
{
|
|
39
|
+
flags: [
|
|
40
|
+
{
|
|
41
|
+
name: 'option',
|
|
42
|
+
when: async (flags) => flags['data-type'] === 'select',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
type: 'all',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
required: true,
|
|
49
|
+
}),
|
|
50
|
+
option: Flags.string({
|
|
51
|
+
description: 'Select option label (repeatable)',
|
|
52
|
+
multiple: true,
|
|
53
|
+
relationships: [
|
|
54
|
+
{
|
|
55
|
+
flags: [
|
|
56
|
+
{
|
|
57
|
+
name: 'data-type',
|
|
58
|
+
when: async (flags) => flags['data-type'] !== 'select',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
type: 'none',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
createPath = '/api/custom_fields/';
|
|
67
|
+
buildPayload(args, flags) {
|
|
68
|
+
const typedArgs = args;
|
|
69
|
+
const dataType = flags['data-type'].trim().toLowerCase();
|
|
70
|
+
const mappedType = dataTypeMap[dataType];
|
|
71
|
+
const options = flags.option ?? [];
|
|
72
|
+
const selectOptions = options.map((option) => option.trim()).filter(Boolean);
|
|
73
|
+
if (!mappedType) {
|
|
74
|
+
this.error(`Unsupported data type "${dataType}".`);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
'data_type': mappedType,
|
|
78
|
+
'extra_data': mappedType === 'select'
|
|
79
|
+
? {
|
|
80
|
+
'select_options': selectOptions.map((label) => ({ label })),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
83
|
+
name: typedArgs.name,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
plainTemplate(field) {
|
|
87
|
+
const count = field.document_count;
|
|
88
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
89
|
+
return `[${field.id}] ${field.name}${suffix}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DeleteCommand } from '../../delete-command.js';
|
|
2
|
+
export default class CustomFieldsDelete extends DeleteCommand {
|
|
3
|
+
static args: {
|
|
4
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
5
|
+
max?: number;
|
|
6
|
+
min?: number;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
static description: string;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
static flags: {
|
|
12
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
protected deleteLabel(id: number | string): string;
|
|
15
|
+
protected deletePath(id: number | string): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { DeleteCommand } from '../../delete-command.js';
|
|
3
|
+
export default class CustomFieldsDelete extends DeleteCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
id: Args.integer({ description: 'Custom field id', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Delete a custom field';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123'];
|
|
9
|
+
static flags = {
|
|
10
|
+
yes: Flags.boolean({ char: 'y', description: 'Skip confirmation prompt' }),
|
|
11
|
+
};
|
|
12
|
+
deleteLabel(id) {
|
|
13
|
+
return `custom field ${id}`;
|
|
14
|
+
}
|
|
15
|
+
deletePath(id) {
|
|
16
|
+
return `/api/custom_fields/${id}/`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CustomField } from '../../types/custom-fields.js';
|
|
2
|
+
import { ListCommand } from '../../list-command.js';
|
|
3
|
+
export default class CustomFieldsList extends ListCommand<CustomField> {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
protected listPath: string;
|
|
7
|
+
protected tableAttrs: string[];
|
|
8
|
+
protected plainTemplate(customField: CustomField): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ListCommand } from '../../list-command.js';
|
|
2
|
+
export default class CustomFieldsList extends ListCommand {
|
|
3
|
+
static description = 'List custom fields';
|
|
4
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
5
|
+
listPath = '/api/custom_fields/';
|
|
6
|
+
tableAttrs = ['id', 'name', 'data_type', 'document_count'];
|
|
7
|
+
plainTemplate(customField) {
|
|
8
|
+
const count = customField.document_count;
|
|
9
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
10
|
+
return `[${customField.id}] ${customField.name}${suffix}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CustomField } from '../../types/custom-fields.js';
|
|
2
|
+
import { ShowCommand } from '../../show-command.js';
|
|
3
|
+
export default class CustomFieldsShow extends ShowCommand<CustomField> {
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: string[];
|
|
12
|
+
protected plainTemplate(customField: CustomField): string | undefined;
|
|
13
|
+
protected showPath(id: number | string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { ShowCommand } from '../../show-command.js';
|
|
3
|
+
export default class CustomFieldsShow extends ShowCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
id: Args.integer({ description: 'Custom field id', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Show custom field details';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123'];
|
|
9
|
+
plainTemplate(customField) {
|
|
10
|
+
const count = customField.document_count;
|
|
11
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
12
|
+
return `[${customField.id}] ${customField.name}${suffix}`;
|
|
13
|
+
}
|
|
14
|
+
showPath(id) {
|
|
15
|
+
return `/api/custom_fields/${id}/`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CustomField, CustomFieldUpdate } from '../../types/custom-fields.js';
|
|
2
|
+
import { UpdateCommand } from '../../update-command.js';
|
|
3
|
+
export default class CustomFieldsUpdate extends UpdateCommand<CustomFieldUpdate, CustomField> {
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: string[];
|
|
12
|
+
static flags: {
|
|
13
|
+
'data-type': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
option: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
protected buildPayload(_args: unknown, flags: Record<string, unknown>): CustomFieldUpdate;
|
|
18
|
+
protected plainTemplate(field: CustomField): string | undefined;
|
|
19
|
+
protected updatePath(id: number | string): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { UpdateCommand } from '../../update-command.js';
|
|
3
|
+
const dataTypeOptions = [
|
|
4
|
+
'boolean',
|
|
5
|
+
'date',
|
|
6
|
+
'integer',
|
|
7
|
+
'number',
|
|
8
|
+
'monetary',
|
|
9
|
+
'text',
|
|
10
|
+
'url',
|
|
11
|
+
'document link',
|
|
12
|
+
'select',
|
|
13
|
+
'long text',
|
|
14
|
+
];
|
|
15
|
+
const dataTypeMap = {
|
|
16
|
+
boolean: 'boolean',
|
|
17
|
+
date: 'date',
|
|
18
|
+
'document link': 'documentlink',
|
|
19
|
+
integer: 'integer',
|
|
20
|
+
'long text': 'longtext',
|
|
21
|
+
monetary: 'monetary',
|
|
22
|
+
number: 'float',
|
|
23
|
+
select: 'select',
|
|
24
|
+
text: 'string',
|
|
25
|
+
url: 'url',
|
|
26
|
+
};
|
|
27
|
+
export default class CustomFieldsUpdate extends UpdateCommand {
|
|
28
|
+
static args = {
|
|
29
|
+
id: Args.integer({ description: 'Custom field id', required: true }),
|
|
30
|
+
};
|
|
31
|
+
static description = 'Update a custom field';
|
|
32
|
+
static examples = ['<%= config.bin %> <%= command.id %> 123 --name "Due Date"'];
|
|
33
|
+
static flags = {
|
|
34
|
+
'data-type': Flags.string({
|
|
35
|
+
description: 'Custom field data type',
|
|
36
|
+
options: [...dataTypeOptions],
|
|
37
|
+
relationships: [
|
|
38
|
+
{
|
|
39
|
+
flags: [
|
|
40
|
+
{
|
|
41
|
+
name: 'option',
|
|
42
|
+
when: async (flags) => flags['data-type'] === 'select',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
type: 'all',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
name: Flags.string({ description: 'Custom field name' }),
|
|
50
|
+
option: Flags.string({
|
|
51
|
+
description: 'Select option label (repeatable)',
|
|
52
|
+
multiple: true,
|
|
53
|
+
relationships: [
|
|
54
|
+
{
|
|
55
|
+
flags: [
|
|
56
|
+
{
|
|
57
|
+
name: 'data-type',
|
|
58
|
+
when: async (flags) => flags['data-type'] !== 'select',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
type: 'none',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
buildPayload(_args, flags) {
|
|
67
|
+
const typedFlags = flags;
|
|
68
|
+
const dataType = typedFlags['data-type']?.trim().toLowerCase();
|
|
69
|
+
const mappedType = dataType ? dataTypeMap[dataType] : undefined;
|
|
70
|
+
const options = typedFlags.option ?? [];
|
|
71
|
+
const selectOptions = options.map((option) => option.trim()).filter(Boolean);
|
|
72
|
+
if (dataType && !mappedType) {
|
|
73
|
+
this.error(`Unsupported data type "${dataType}".`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
'data_type': mappedType,
|
|
77
|
+
'extra_data': mappedType === 'select'
|
|
78
|
+
? {
|
|
79
|
+
'select_options': selectOptions.map((label) => ({ label })),
|
|
80
|
+
}
|
|
81
|
+
: undefined,
|
|
82
|
+
name: typedFlags.name,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
plainTemplate(field) {
|
|
86
|
+
const count = field.document_count;
|
|
87
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
88
|
+
return `[${field.id}] ${field.name}${suffix}`;
|
|
89
|
+
}
|
|
90
|
+
updatePath(id) {
|
|
91
|
+
return `/api/custom_fields/${id}/`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DocumentType, DocumentTypeCreate } from '../../types/document-types.js';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
export default class DocumentTypesAdd extends AddCommand<DocumentTypeCreate, DocumentType> {
|
|
4
|
+
static args: {
|
|
5
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
protected createPath: string;
|
|
10
|
+
protected buildPayload(args: unknown, _flags: Record<string, unknown>): DocumentTypeCreate;
|
|
11
|
+
protected plainTemplate(documentType: DocumentType): string | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { AddCommand } from '../../add-command.js';
|
|
3
|
+
export default class DocumentTypesAdd extends AddCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
name: Args.string({ description: 'Document type name', required: true }),
|
|
6
|
+
};
|
|
7
|
+
static description = 'Create a document type';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> "Invoice"'];
|
|
9
|
+
createPath = '/api/document_types/';
|
|
10
|
+
buildPayload(args, _flags) {
|
|
11
|
+
const typedArgs = args;
|
|
12
|
+
return {
|
|
13
|
+
'matching_algorithm': 6,
|
|
14
|
+
name: typedArgs.name,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
plainTemplate(documentType) {
|
|
18
|
+
const count = documentType.document_count;
|
|
19
|
+
const suffix = count === undefined ? '' : ` (${count} ${count === 1 ? 'document' : 'documents'})`;
|
|
20
|
+
return `[${documentType.id}] ${documentType.name}${suffix}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DeleteCommand } from '../../delete-command.js';
|
|
2
|
+
export default class DocumentTypesDelete extends DeleteCommand {
|
|
3
|
+
static args: {
|
|
4
|
+
id: import("@oclif/core/interfaces").Arg<number, {
|
|
5
|
+
max?: number;
|
|
6
|
+
min?: number;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
static description: string;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
static flags: {
|
|
12
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
protected deleteLabel(id: number | string): string;
|
|
15
|
+
protected deletePath(id: number | string): string;
|
|
16
|
+
}
|