@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,98 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { createValueFormatter } from './helpers/table.js';
|
|
3
|
+
import { PaginatedCommand } from './paginated-command.js';
|
|
4
|
+
export class ListCommand extends PaginatedCommand {
|
|
5
|
+
static baseFlags = {
|
|
6
|
+
...PaginatedCommand.baseFlags,
|
|
7
|
+
'id-in': Flags.string({
|
|
8
|
+
description: 'Filter by id list (comma-separated)',
|
|
9
|
+
exclusive: ['name-contains'],
|
|
10
|
+
}),
|
|
11
|
+
'name-contains': Flags.string({
|
|
12
|
+
description: 'Filter by name substring',
|
|
13
|
+
exclusive: ['id-in'],
|
|
14
|
+
}),
|
|
15
|
+
sort: Flags.string({ description: 'Sort results by the provided field' }),
|
|
16
|
+
};
|
|
17
|
+
async fetchListResults(options) {
|
|
18
|
+
const { flags, params = {}, path } = options;
|
|
19
|
+
const url = this.buildPaginatedUrlFromFlags({
|
|
20
|
+
flags,
|
|
21
|
+
params: {
|
|
22
|
+
ordering: flags.sort,
|
|
23
|
+
...params,
|
|
24
|
+
},
|
|
25
|
+
path,
|
|
26
|
+
});
|
|
27
|
+
return this.fetchPaginatedResultsFromFlags({
|
|
28
|
+
autoPaginate: this.shouldAutoPaginate(flags),
|
|
29
|
+
flags,
|
|
30
|
+
url,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
listParams(flags) {
|
|
34
|
+
return {
|
|
35
|
+
'id__in': flags['id-in'],
|
|
36
|
+
'name__icontains': flags['name-contains'],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
renderListOutput(options) {
|
|
40
|
+
if (this.jsonEnabled()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const { flags, results } = options;
|
|
44
|
+
const dateFormat = flags['date-format'];
|
|
45
|
+
if (flags.plain) {
|
|
46
|
+
for (const item of results) {
|
|
47
|
+
const line = this.plainTemplate(item);
|
|
48
|
+
if (line) {
|
|
49
|
+
this.log(line);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const valueFormatter = createValueFormatter(dateFormat);
|
|
55
|
+
const columns = this.tableAttrs.map((value) => typeof value === 'string' ? { formatter: valueFormatter, value } : { formatter: valueFormatter, ...value });
|
|
56
|
+
this.logTable(columns, results);
|
|
57
|
+
}
|
|
58
|
+
async run() {
|
|
59
|
+
const { flags, metadata } = await this.parse();
|
|
60
|
+
const { dateFormat, ...apiFlags } = await this.resolveGlobalFlags(flags, metadata);
|
|
61
|
+
const listFlags = {
|
|
62
|
+
headers: apiFlags.headers,
|
|
63
|
+
hostname: apiFlags.hostname,
|
|
64
|
+
'id-in': flags['id-in'],
|
|
65
|
+
'name-contains': flags['name-contains'],
|
|
66
|
+
page: flags.page,
|
|
67
|
+
'page-size': flags['page-size'],
|
|
68
|
+
sort: flags.sort,
|
|
69
|
+
token: apiFlags.token,
|
|
70
|
+
};
|
|
71
|
+
const outputFlags = {
|
|
72
|
+
...listFlags,
|
|
73
|
+
'date-format': dateFormat,
|
|
74
|
+
plain: flags.plain,
|
|
75
|
+
table: flags.table,
|
|
76
|
+
};
|
|
77
|
+
const rawResults = await this.fetchListResults({
|
|
78
|
+
flags: listFlags,
|
|
79
|
+
params: this.listParams(listFlags),
|
|
80
|
+
path: this.listPath,
|
|
81
|
+
});
|
|
82
|
+
const results = this.transformResults(rawResults);
|
|
83
|
+
this.renderListOutput({
|
|
84
|
+
flags: outputFlags,
|
|
85
|
+
results,
|
|
86
|
+
});
|
|
87
|
+
return results;
|
|
88
|
+
}
|
|
89
|
+
shouldAutoPaginate(flags) {
|
|
90
|
+
return flags.page === undefined && flags['page-size'] === undefined;
|
|
91
|
+
}
|
|
92
|
+
transformResult(result) {
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
transformResults(results) {
|
|
96
|
+
return results.map((result) => this.transformResult(result));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ApiFlags } from './base-command.js';
|
|
2
|
+
import { BaseCommand } from './base-command.js';
|
|
3
|
+
type PaginatedFlags = ApiFlags & {
|
|
4
|
+
page?: number;
|
|
5
|
+
'page-size'?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare abstract class PaginatedCommand extends BaseCommand {
|
|
8
|
+
static baseFlags: {
|
|
9
|
+
page: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'page-size': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'date-format': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
header: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
hostname: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
plain: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
table: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
protected buildPaginatedUrl(options: {
|
|
19
|
+
hostname: string;
|
|
20
|
+
page?: number;
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
params?: Record<string, number | string | undefined>;
|
|
23
|
+
path: string;
|
|
24
|
+
}): URL;
|
|
25
|
+
protected buildPaginatedUrlFromFlags(options: {
|
|
26
|
+
flags: PaginatedFlags;
|
|
27
|
+
params?: Record<string, number | string | undefined>;
|
|
28
|
+
path: string;
|
|
29
|
+
}): URL;
|
|
30
|
+
protected fetchPaginatedResults<T>(options: {
|
|
31
|
+
autoPaginate: boolean;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
spinnerText?: string;
|
|
34
|
+
token: string;
|
|
35
|
+
url: URL;
|
|
36
|
+
}): Promise<T[]>;
|
|
37
|
+
protected fetchPaginatedResultsFromFlags<T>(options: {
|
|
38
|
+
autoPaginate: boolean;
|
|
39
|
+
flags: {
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
token: string;
|
|
42
|
+
};
|
|
43
|
+
spinnerText?: string;
|
|
44
|
+
url: URL;
|
|
45
|
+
}): Promise<T[]>;
|
|
46
|
+
protected paginate<T>(url: URL, tokenValue: string, headers: Record<string, string>, autoPaginate: boolean): AsyncGenerator<T>;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from './base-command.js';
|
|
3
|
+
export class PaginatedCommand extends BaseCommand {
|
|
4
|
+
static baseFlags = {
|
|
5
|
+
...BaseCommand.baseFlags,
|
|
6
|
+
page: Flags.integer({ description: 'Page number to fetch' }),
|
|
7
|
+
'page-size': Flags.integer({ description: 'Number of results per page' }),
|
|
8
|
+
};
|
|
9
|
+
buildPaginatedUrl(options) {
|
|
10
|
+
const { hostname, page, pageSize, params = {}, path } = options;
|
|
11
|
+
if (page !== undefined && page < 1) {
|
|
12
|
+
this.error('Invalid page value. Page must be 1 or greater.');
|
|
13
|
+
}
|
|
14
|
+
if (pageSize !== undefined && pageSize < 1) {
|
|
15
|
+
this.error('Invalid page size. Page size must be 1 or greater.');
|
|
16
|
+
}
|
|
17
|
+
return this.buildApiUrl(hostname, path, {
|
|
18
|
+
...params,
|
|
19
|
+
page,
|
|
20
|
+
'page_size': pageSize,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
buildPaginatedUrlFromFlags(options) {
|
|
24
|
+
const { flags, params, path } = options;
|
|
25
|
+
return this.buildPaginatedUrl({
|
|
26
|
+
hostname: flags.hostname,
|
|
27
|
+
page: flags.page,
|
|
28
|
+
pageSize: flags['page-size'],
|
|
29
|
+
params,
|
|
30
|
+
path,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async fetchPaginatedResults(options) {
|
|
34
|
+
const { autoPaginate, headers, spinnerText, token, url } = options;
|
|
35
|
+
const spinner = this.startSpinner(spinnerText ?? `Fetching ${url.pathname}`);
|
|
36
|
+
const results = [];
|
|
37
|
+
try {
|
|
38
|
+
let nextUrl = url;
|
|
39
|
+
while (nextUrl) {
|
|
40
|
+
// eslint-disable-next-line no-await-in-loop -- pagination is sequential and depends on the next page URL.
|
|
41
|
+
const payload = await this.fetchJson(nextUrl, token, headers);
|
|
42
|
+
results.push(...(payload.results ?? []));
|
|
43
|
+
if (!autoPaginate || !payload.next) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
nextUrl = new URL(payload.next, nextUrl);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
this.error('API returned an invalid next URL for pagination.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
spinner?.stop();
|
|
56
|
+
}
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
async fetchPaginatedResultsFromFlags(options) {
|
|
60
|
+
const { autoPaginate, flags, spinnerText, url } = options;
|
|
61
|
+
return this.fetchPaginatedResults({
|
|
62
|
+
autoPaginate,
|
|
63
|
+
headers: flags.headers,
|
|
64
|
+
spinnerText,
|
|
65
|
+
token: flags.token,
|
|
66
|
+
url,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async *paginate(url, tokenValue, headers, autoPaginate) {
|
|
70
|
+
let nextUrl = url;
|
|
71
|
+
while (nextUrl) {
|
|
72
|
+
// eslint-disable-next-line no-await-in-loop -- pagination is sequential and depends on the next page URL.
|
|
73
|
+
const payload = await this.fetchJson(nextUrl, tokenValue, headers);
|
|
74
|
+
const results = payload.results ?? [];
|
|
75
|
+
for (const result of results) {
|
|
76
|
+
yield result;
|
|
77
|
+
}
|
|
78
|
+
if (!autoPaginate || !payload.next) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
nextUrl = new URL(payload.next, nextUrl);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
this.error('API returned an invalid next URL for pagination.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ApiFlags } from './base-command.js';
|
|
2
|
+
import { BaseCommand } from './base-command.js';
|
|
3
|
+
type ShowCommandArgs = {
|
|
4
|
+
id: number | string;
|
|
5
|
+
};
|
|
6
|
+
type ShowCommandFlags = ApiFlags & {
|
|
7
|
+
'date-format': string;
|
|
8
|
+
plain?: boolean;
|
|
9
|
+
table?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type ShowTableRow = {
|
|
12
|
+
field: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare abstract class ShowCommand<TRaw extends Record<string, unknown> = Record<string, unknown>, TOutput extends Record<string, unknown> = TRaw> extends BaseCommand {
|
|
16
|
+
protected abstract plainTemplate(item: TOutput): null | string | undefined;
|
|
17
|
+
protected renderShowOutput(options: {
|
|
18
|
+
flags: ShowCommandFlags;
|
|
19
|
+
result: TOutput;
|
|
20
|
+
}): void;
|
|
21
|
+
run(): Promise<TOutput>;
|
|
22
|
+
protected showId(args: ShowCommandArgs): number | string;
|
|
23
|
+
protected abstract showPath(id: number | string): string;
|
|
24
|
+
protected showRows(result: TOutput): ShowTableRow[];
|
|
25
|
+
protected transformResult(result: TRaw): TOutput;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseCommand } from './base-command.js';
|
|
2
|
+
import { createValueFormatter, formatField } from './helpers/table.js';
|
|
3
|
+
export class ShowCommand extends BaseCommand {
|
|
4
|
+
renderShowOutput(options) {
|
|
5
|
+
if (this.jsonEnabled()) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const { flags, result } = options;
|
|
9
|
+
const dateFormat = flags['date-format'];
|
|
10
|
+
if (flags.plain) {
|
|
11
|
+
const line = this.plainTemplate(result);
|
|
12
|
+
if (line) {
|
|
13
|
+
this.log(line);
|
|
14
|
+
}
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const valueFormatter = createValueFormatter(dateFormat);
|
|
18
|
+
this.logTable([
|
|
19
|
+
{ align: 'right', formatter: formatField, value: 'field' },
|
|
20
|
+
{ formatter: valueFormatter, value: 'value' },
|
|
21
|
+
], this.showRows(result), { showHeader: false });
|
|
22
|
+
}
|
|
23
|
+
async run() {
|
|
24
|
+
const { args, flags, metadata } = await this.parse();
|
|
25
|
+
const { dateFormat, ...apiFlags } = await this.resolveGlobalFlags(flags, metadata);
|
|
26
|
+
const outputFlags = {
|
|
27
|
+
...apiFlags,
|
|
28
|
+
'date-format': dateFormat,
|
|
29
|
+
plain: flags.plain,
|
|
30
|
+
table: flags.table,
|
|
31
|
+
};
|
|
32
|
+
const id = this.showId(args);
|
|
33
|
+
const rawResult = await this.fetchApiJson(apiFlags, this.showPath(id));
|
|
34
|
+
const result = this.transformResult(rawResult);
|
|
35
|
+
this.renderShowOutput({ flags: outputFlags, result });
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
showId(args) {
|
|
39
|
+
return args.id;
|
|
40
|
+
}
|
|
41
|
+
showRows(result) {
|
|
42
|
+
return Object.entries(result).map(([field, value]) => ({
|
|
43
|
+
field,
|
|
44
|
+
value,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
transformResult(result) {
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MatchingAlgorithm } from './shared.js';
|
|
2
|
+
export type Correspondent = {
|
|
3
|
+
document_count: number;
|
|
4
|
+
id: number;
|
|
5
|
+
is_insensitive?: boolean;
|
|
6
|
+
last_correspondence: string;
|
|
7
|
+
match?: string;
|
|
8
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
9
|
+
name: string;
|
|
10
|
+
owner?: null | number;
|
|
11
|
+
permissions: {
|
|
12
|
+
change: {
|
|
13
|
+
groups: number[];
|
|
14
|
+
users: number[];
|
|
15
|
+
};
|
|
16
|
+
view: {
|
|
17
|
+
groups: number[];
|
|
18
|
+
users: number[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
slug: string;
|
|
22
|
+
user_can_change: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type CorrespondentCreate = {
|
|
25
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
export type CorrespondentUpdate = Partial<CorrespondentCreate>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DataTypeEnum } from './shared.js';
|
|
2
|
+
export type CustomField = {
|
|
3
|
+
data_type: DataTypeEnum;
|
|
4
|
+
document_count: number;
|
|
5
|
+
extra_data?: null | Record<string, unknown>;
|
|
6
|
+
id: number;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export type CustomFieldCreate = {
|
|
10
|
+
data_type: DataTypeEnum;
|
|
11
|
+
extra_data?: {
|
|
12
|
+
select_options: Array<{
|
|
13
|
+
label: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
export type CustomFieldUpdate = Partial<CustomFieldCreate>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MatchingAlgorithm } from './shared.js';
|
|
2
|
+
export type DocumentType = {
|
|
3
|
+
document_count: number;
|
|
4
|
+
id: number;
|
|
5
|
+
is_insensitive?: boolean;
|
|
6
|
+
match?: string;
|
|
7
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
8
|
+
name: string;
|
|
9
|
+
owner?: null | number;
|
|
10
|
+
permissions: {
|
|
11
|
+
change: {
|
|
12
|
+
groups: number[];
|
|
13
|
+
users: number[];
|
|
14
|
+
};
|
|
15
|
+
view: {
|
|
16
|
+
groups: number[];
|
|
17
|
+
users: number[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
slug: string;
|
|
21
|
+
user_can_change: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type DocumentTypeCreate = {
|
|
24
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
export type DocumentTypeUpdate = Partial<DocumentTypeCreate>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { DateString, DateTimeString } from './shared.js';
|
|
2
|
+
export type DocumentNote = {
|
|
3
|
+
created?: DateTimeString;
|
|
4
|
+
id: number;
|
|
5
|
+
note?: string;
|
|
6
|
+
user?: {
|
|
7
|
+
email?: string;
|
|
8
|
+
first_name?: string;
|
|
9
|
+
id?: number;
|
|
10
|
+
last_name?: string;
|
|
11
|
+
username?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type CustomFieldInstance = {
|
|
15
|
+
field: number;
|
|
16
|
+
value: null | number | object | string;
|
|
17
|
+
};
|
|
18
|
+
export type DocumentCreate = {
|
|
19
|
+
archive_serial_number?: number;
|
|
20
|
+
correspondent?: null | number;
|
|
21
|
+
created?: DateTimeString;
|
|
22
|
+
document_type?: null | number;
|
|
23
|
+
storage_path?: null | number;
|
|
24
|
+
tags?: number[];
|
|
25
|
+
title?: string;
|
|
26
|
+
};
|
|
27
|
+
export type DocumentUpdate = {
|
|
28
|
+
archive_serial_number?: null | number;
|
|
29
|
+
content?: string;
|
|
30
|
+
correspondent?: null | number;
|
|
31
|
+
created?: DateString;
|
|
32
|
+
document_type?: null | number;
|
|
33
|
+
storage_path?: null | number;
|
|
34
|
+
tags?: number[];
|
|
35
|
+
title?: string;
|
|
36
|
+
};
|
|
37
|
+
export type Document = {
|
|
38
|
+
added: DateTimeString;
|
|
39
|
+
archive_serial_number?: null | number;
|
|
40
|
+
archived_file_name?: null | string;
|
|
41
|
+
content?: string;
|
|
42
|
+
correspondent: null | number;
|
|
43
|
+
created: DateString;
|
|
44
|
+
created_date?: DateString;
|
|
45
|
+
custom_fields?: CustomFieldInstance[];
|
|
46
|
+
deleted_at?: DateTimeString | null;
|
|
47
|
+
document_type: null | number;
|
|
48
|
+
id: number;
|
|
49
|
+
is_shared_by_requester?: boolean;
|
|
50
|
+
mime_type?: string;
|
|
51
|
+
modified?: DateTimeString;
|
|
52
|
+
notes?: DocumentNote[];
|
|
53
|
+
original_file_name?: null | string;
|
|
54
|
+
owner?: null | number;
|
|
55
|
+
page_count?: null | number;
|
|
56
|
+
permissions?: {
|
|
57
|
+
change?: {
|
|
58
|
+
groups?: number[];
|
|
59
|
+
users?: number[];
|
|
60
|
+
};
|
|
61
|
+
view?: {
|
|
62
|
+
groups?: number[];
|
|
63
|
+
users?: number[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
storage_path: null | number;
|
|
67
|
+
tags: number[];
|
|
68
|
+
title?: string;
|
|
69
|
+
user_can_change?: boolean;
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type SocialAccount = {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
provider: string;
|
|
5
|
+
};
|
|
6
|
+
export type Profile = {
|
|
7
|
+
auth_token: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
first_name?: string;
|
|
10
|
+
has_usable_password: boolean;
|
|
11
|
+
is_mfa_enabled: boolean;
|
|
12
|
+
last_name?: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
social_accounts: SocialAccount[];
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type MatchingAlgorithm = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
2
|
+
export type DataTypeEnum = 'boolean' | 'date' | 'documentlink' | 'float' | 'integer' | 'longtext' | 'monetary' | 'select' | 'string' | 'url';
|
|
3
|
+
export type DateString = `${number}-${number}-${number}`;
|
|
4
|
+
export type DateTimeString = `${number}-${number}-${number}T${number}:${number}:${number}${string}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MatchingAlgorithm } from './shared.js';
|
|
2
|
+
type TagBase = {
|
|
3
|
+
color?: string;
|
|
4
|
+
document_count: number;
|
|
5
|
+
id: number;
|
|
6
|
+
is_inbox_tag?: boolean;
|
|
7
|
+
is_insensitive?: boolean;
|
|
8
|
+
match?: string;
|
|
9
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
10
|
+
name: string;
|
|
11
|
+
owner?: null | number;
|
|
12
|
+
parent?: null | number;
|
|
13
|
+
slug: string;
|
|
14
|
+
text_color: string;
|
|
15
|
+
user_can_change: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type TagCreate = {
|
|
18
|
+
color?: string;
|
|
19
|
+
is_inbox_tag?: boolean;
|
|
20
|
+
matching_algorithm?: MatchingAlgorithm;
|
|
21
|
+
name: string;
|
|
22
|
+
parent?: number;
|
|
23
|
+
};
|
|
24
|
+
export type TagUpdate = Partial<TagCreate>;
|
|
25
|
+
export type Tag = TagBase & {
|
|
26
|
+
children: number[];
|
|
27
|
+
};
|
|
28
|
+
export type TagApi = TagBase & {
|
|
29
|
+
children: TagApi[];
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ApiFlags } from './base-command.js';
|
|
2
|
+
import { BaseCommand } from './base-command.js';
|
|
3
|
+
type UpdateCommandArgs = {
|
|
4
|
+
id: number | string;
|
|
5
|
+
};
|
|
6
|
+
type UpdateCommandFlags = ApiFlags & {
|
|
7
|
+
'date-format': string;
|
|
8
|
+
plain?: boolean;
|
|
9
|
+
table?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type UpdateTableRow = {
|
|
12
|
+
field: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare abstract class UpdateCommand<TUpdate = Record<string, unknown>, TRaw extends Record<string, unknown> = Record<string, unknown>, TOutput extends Record<string, unknown> = TRaw> extends BaseCommand {
|
|
16
|
+
protected abstract buildPayload(args: unknown, flags: Record<string, unknown>): TUpdate;
|
|
17
|
+
protected abstract plainTemplate(item: TOutput): null | string | undefined;
|
|
18
|
+
protected renderUpdateOutput(options: {
|
|
19
|
+
flags: UpdateCommandFlags;
|
|
20
|
+
result: TOutput;
|
|
21
|
+
}): void;
|
|
22
|
+
run(): Promise<TOutput>;
|
|
23
|
+
protected transformResult(result: TRaw): TOutput;
|
|
24
|
+
protected updateId(args: UpdateCommandArgs): number | string;
|
|
25
|
+
protected abstract updatePath(id: number | string): string;
|
|
26
|
+
protected updateRows(result: TOutput): UpdateTableRow[];
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseCommand } from './base-command.js';
|
|
2
|
+
import { createValueFormatter, formatField } from './helpers/table.js';
|
|
3
|
+
export class UpdateCommand extends BaseCommand {
|
|
4
|
+
renderUpdateOutput(options) {
|
|
5
|
+
if (this.jsonEnabled()) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const { flags, result } = options;
|
|
9
|
+
const dateFormat = flags['date-format'];
|
|
10
|
+
if (flags.plain) {
|
|
11
|
+
const line = this.plainTemplate(result);
|
|
12
|
+
if (line) {
|
|
13
|
+
this.log(line);
|
|
14
|
+
}
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const valueFormatter = createValueFormatter(dateFormat);
|
|
18
|
+
this.logTable([
|
|
19
|
+
{ align: 'right', formatter: formatField, value: 'field' },
|
|
20
|
+
{ formatter: valueFormatter, value: 'value' },
|
|
21
|
+
], this.updateRows(result), { showHeader: false });
|
|
22
|
+
}
|
|
23
|
+
async run() {
|
|
24
|
+
const { args, flags, metadata } = await this.parse();
|
|
25
|
+
const { dateFormat, ...apiFlags } = await this.resolveGlobalFlags(flags, metadata);
|
|
26
|
+
const outputFlags = {
|
|
27
|
+
...apiFlags,
|
|
28
|
+
'date-format': dateFormat,
|
|
29
|
+
plain: flags.plain,
|
|
30
|
+
table: flags.table,
|
|
31
|
+
};
|
|
32
|
+
const payload = this.buildPayload(args, flags);
|
|
33
|
+
const id = this.updateId(args);
|
|
34
|
+
const rawResult = await this.patchApiJson(apiFlags, this.updatePath(id), payload);
|
|
35
|
+
const result = this.transformResult(rawResult);
|
|
36
|
+
this.renderUpdateOutput({ flags: outputFlags, result });
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
transformResult(result) {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
updateId(args) {
|
|
43
|
+
return args.id;
|
|
44
|
+
}
|
|
45
|
+
updateRows(result) {
|
|
46
|
+
return Object.entries(result).map(([field, value]) => ({
|
|
47
|
+
field,
|
|
48
|
+
value,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
}
|