@aderis-erp/cli 1.1.2 → 1.1.3
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/access-groups.d.ts +11 -2
- package/dist/commands/access-groups.js +158 -24
- package/dist/commands/account-transaction-allocations.d.ts +11 -2
- package/dist/commands/account-transaction-allocations.js +157 -23
- package/dist/commands/account-transactions.d.ts +15 -2
- package/dist/commands/account-transactions.js +162 -24
- package/dist/commands/accounts.d.ts +11 -2
- package/dist/commands/accounts.js +158 -24
- package/dist/commands/agent-platform.d.ts +11 -3
- package/dist/commands/agent-platform.js +157 -32
- package/dist/commands/agent-runs.d.ts +11 -2
- package/dist/commands/agent-runs.js +157 -23
- package/dist/commands/analytics.d.ts +11 -2
- package/dist/commands/analytics.js +157 -23
- package/dist/commands/api-keys.d.ts +11 -2
- package/dist/commands/api-keys.js +157 -23
- package/dist/commands/async-jobs.d.ts +11 -2
- package/dist/commands/async-jobs.js +158 -24
- package/dist/commands/audit-log.d.ts +11 -2
- package/dist/commands/audit-log.js +157 -23
- package/dist/commands/bank-accounts.d.ts +11 -2
- package/dist/commands/bank-accounts.js +158 -24
- package/dist/commands/bank-integrations.d.ts +11 -2
- package/dist/commands/bank-integrations.js +158 -24
- package/dist/commands/business-partners.d.ts +11 -2
- package/dist/commands/business-partners.js +158 -24
- package/dist/commands/chat.d.ts +11 -2
- package/dist/commands/chat.js +158 -24
- package/dist/commands/credit-card-accounts.d.ts +11 -2
- package/dist/commands/credit-card-accounts.js +158 -24
- package/dist/commands/delivery-notes.d.ts +11 -2
- package/dist/commands/delivery-notes.js +158 -24
- package/dist/commands/dunning-configs.d.ts +11 -2
- package/dist/commands/dunning-configs.js +158 -24
- package/dist/commands/dunning-reminders.d.ts +11 -2
- package/dist/commands/dunning-reminders.js +157 -23
- package/dist/commands/dunning-runs.d.ts +11 -2
- package/dist/commands/dunning-runs.js +157 -23
- package/dist/commands/email-transactions.d.ts +11 -2
- package/dist/commands/email-transactions.js +157 -23
- package/dist/commands/employees.d.ts +13 -2
- package/dist/commands/employees.js +169 -24
- package/dist/commands/entity-configurations.d.ts +11 -2
- package/dist/commands/entity-configurations.js +157 -23
- package/dist/commands/event-mapping-rules.d.ts +56 -0
- package/dist/commands/event-mapping-rules.js +1324 -0
- package/dist/commands/event-processor-mappings.d.ts +11 -2
- package/dist/commands/event-processor-mappings.js +158 -24
- package/dist/commands/files.d.ts +11 -2
- package/dist/commands/files.js +158 -24
- package/dist/commands/health.d.ts +11 -2
- package/dist/commands/health.js +157 -23
- package/dist/commands/imports.d.ts +11 -2
- package/dist/commands/imports.js +157 -23
- package/dist/commands/inbox.d.ts +11 -2
- package/dist/commands/inbox.js +157 -23
- package/dist/commands/integration-identities.d.ts +11 -2
- package/dist/commands/integration-identities.js +157 -23
- package/dist/commands/integrations.d.ts +11 -2
- package/dist/commands/integrations.js +157 -23
- package/dist/commands/item-categories.d.ts +11 -2
- package/dist/commands/item-categories.js +158 -24
- package/dist/commands/items.d.ts +15 -2
- package/dist/commands/items.js +163 -24
- package/dist/commands/journal-lines.d.ts +11 -2
- package/dist/commands/journal-lines.js +157 -23
- package/dist/commands/journals.d.ts +15 -2
- package/dist/commands/journals.js +163 -24
- package/dist/commands/ledgers.d.ts +11 -2
- package/dist/commands/ledgers.js +158 -24
- package/dist/commands/my-account.d.ts +11 -2
- package/dist/commands/my-account.js +157 -23
- package/dist/commands/office-locations.d.ts +11 -2
- package/dist/commands/office-locations.js +158 -24
- package/dist/commands/payment-methods.d.ts +11 -2
- package/dist/commands/payment-methods.js +158 -24
- package/dist/commands/payment-runs.d.ts +11 -2
- package/dist/commands/payment-runs.js +158 -24
- package/dist/commands/payment-terms.d.ts +11 -2
- package/dist/commands/payment-terms.js +159 -25
- package/dist/commands/payments.d.ts +11 -2
- package/dist/commands/payments.js +158 -24
- package/dist/commands/payroll-runs.d.ts +11 -2
- package/dist/commands/payroll-runs.js +158 -24
- package/dist/commands/permissions.d.ts +11 -2
- package/dist/commands/permissions.js +157 -23
- package/dist/commands/price-lists.d.ts +15 -2
- package/dist/commands/price-lists.js +164 -24
- package/dist/commands/processor-mappings.d.ts +11 -2
- package/dist/commands/processor-mappings.js +158 -24
- package/dist/commands/processors.d.ts +11 -2
- package/dist/commands/processors.js +158 -24
- package/dist/commands/purchase-order-types.d.ts +11 -2
- package/dist/commands/purchase-order-types.js +158 -24
- package/dist/commands/purchase-orders.d.ts +11 -2
- package/dist/commands/purchase-orders.js +158 -24
- package/dist/commands/reports.d.ts +11 -2
- package/dist/commands/reports.js +157 -23
- package/dist/commands/roles.d.ts +11 -2
- package/dist/commands/roles.js +158 -24
- package/dist/commands/salary-types.d.ts +11 -2
- package/dist/commands/salary-types.js +158 -24
- package/dist/commands/sales-invoices.d.ts +11 -2
- package/dist/commands/sales-invoices.js +161 -24
- package/dist/commands/sales-orders.d.ts +11 -2
- package/dist/commands/sales-orders.js +158 -24
- package/dist/commands/saved-views.d.ts +11 -2
- package/dist/commands/saved-views.js +157 -23
- package/dist/commands/scheduled-processor-mappings.d.ts +11 -2
- package/dist/commands/scheduled-processor-mappings.js +158 -24
- package/dist/commands/schedules.d.ts +11 -2
- package/dist/commands/schedules.js +158 -24
- package/dist/commands/tags.d.ts +11 -2
- package/dist/commands/tags.js +158 -24
- package/dist/commands/tax-codes.d.ts +11 -2
- package/dist/commands/tax-codes.js +158 -24
- package/dist/commands/tax-matrix.d.ts +11 -2
- package/dist/commands/tax-matrix.js +158 -24
- package/dist/commands/templates.d.ts +11 -2
- package/dist/commands/templates.js +162 -24
- package/dist/commands/tenants.d.ts +11 -2
- package/dist/commands/tenants.js +158 -24
- package/dist/commands/tools.d.ts +11 -2
- package/dist/commands/tools.js +157 -23
- package/dist/commands/users.d.ts +11 -2
- package/dist/commands/users.js +158 -24
- package/dist/commands/vat-declarations.d.ts +11 -2
- package/dist/commands/vat-declarations.js +158 -24
- package/dist/commands/vendor-invoices.d.ts +11 -2
- package/dist/commands/vendor-invoices.js +161 -24
- package/dist/commands/webhooks.d.ts +11 -2
- package/dist/commands/webhooks.js +158 -24
- package/dist/commands/workflows.d.ts +11 -2
- package/dist/commands/workflows.js +157 -23
- package/dist/lib/api-client.d.ts +1 -0
- package/dist/lib/api-client.js +3 -0
- package/oclif.manifest.json +466 -162
- package/package.json +1 -1
package/dist/commands/inbox.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Command, Args, Flags } from '@oclif/core';
|
|
2
2
|
import { apiRequest, ApiError, isTextualMediaType, normalizeSortBy } from '../lib/api-client.js';
|
|
3
3
|
import { getCurrentContext, getContext, getBaseUrls, hasCredentials, missingCredentialsMessage } from '../lib/config.js';
|
|
4
|
-
//
|
|
5
|
-
|
|
4
|
+
// 'upsert' loops create/update from the CLI, one request per record. It exists
|
|
5
|
+
// only where the API has no import endpoint of its own; those keep the name
|
|
6
|
+
// 'import' and are listed in SERVER_IMPORTS.
|
|
7
|
+
const HAS_UPSERT = false;
|
|
6
8
|
const HAS_EXPORT = false;
|
|
7
9
|
const HAS_CAMT053 = false;
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
+
const SERVER_IMPORTS = [];
|
|
11
|
+
const NESTED_UPSERTS = [];
|
|
12
|
+
const SUBCOMMANDS = [...["create-upload", "email-webhook", "document-types", "uploads-files-content", "list-processing-logs", "processing-logs"], ...(HAS_UPSERT ? ['upsert'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_UPSERTS.map(n => `upsert-${n}`)];
|
|
10
13
|
const ENDPOINTS = {
|
|
11
14
|
'create-upload': { method: 'POST', path: '/v1/inbox/upload', summary: 'Upload document(s) to inbox for processing', pathParams: [], hasBody: false, isMultipart: true, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
12
15
|
'email-webhook': { method: 'POST', path: '/v1/inbox/email-webhook/{secret}', summary: 'Email webhook for document ingestion (SendGrid inbound-parse)', pathParams: ['secret'], hasBody: false, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
@@ -24,7 +27,7 @@ export default class Inbox extends Command {
|
|
|
24
27
|
};
|
|
25
28
|
static flags = {
|
|
26
29
|
context: Flags.string({ char: 'c', aliases: ['config'], env: 'ADERIS_CONTEXT', description: 'Context to use for this command, overriding the current context (alias: --config)' }),
|
|
27
|
-
output: Flags.string({ char: 'o', description: 'Output format (default: table for
|
|
30
|
+
output: Flags.string({ char: 'o', description: 'Output format (default: table for upsert, json for other commands)', options: ['json', 'table', 'csv'] }),
|
|
28
31
|
table: Flags.boolean({ char: 't', description: 'Output as table (shortcut for --output table)' }),
|
|
29
32
|
csv: Flags.boolean({ description: 'Output as CSV (shortcut for --output csv)' }),
|
|
30
33
|
data: Flags.string({ char: 'd', description: 'JSON data for request body' }),
|
|
@@ -45,11 +48,26 @@ export default class Inbox extends Command {
|
|
|
45
48
|
};
|
|
46
49
|
async run() {
|
|
47
50
|
const { args, flags } = await this.parse(Inbox);
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// Bulk actions. 'import' is the API's own endpoint: one request, answered
|
|
52
|
+
// by a run that records what happened to every record. 'upsert' is the CLI
|
|
53
|
+
// looping create/update. A resource has one or the other, never both.
|
|
54
|
+
if (args.action === 'upsert') {
|
|
55
|
+
if (!HAS_UPSERT) {
|
|
56
|
+
this.error(SERVER_IMPORTS.includes('import')
|
|
57
|
+
? 'This resource is imported by the API. Use: aderis inbox import --file data.json'
|
|
58
|
+
: 'Upsert needs both a create and an update endpoint, which this resource does not have');
|
|
59
|
+
}
|
|
60
|
+
await this.runUpsert(flags);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (args.action.startsWith('upsert-')) {
|
|
64
|
+
const suffix = args.action.replace('upsert-', '');
|
|
65
|
+
if (!NESTED_UPSERTS.includes(suffix)) {
|
|
66
|
+
this.error(SERVER_IMPORTS.includes('import-' + suffix)
|
|
67
|
+
? `That resource is imported by the API. Use: aderis inbox import-${suffix} <id> --file data.json`
|
|
68
|
+
: `Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
await this.runNestedUpsert(suffix, args.id, flags);
|
|
53
71
|
return;
|
|
54
72
|
}
|
|
55
73
|
// Handle export action specially
|
|
@@ -66,12 +84,17 @@ export default class Inbox extends Command {
|
|
|
66
84
|
await this.runCamt053Import(flags);
|
|
67
85
|
return;
|
|
68
86
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
if (SERVER_IMPORTS.includes(args.action)) {
|
|
88
|
+
await this.runServerImport(args.action, args.id, flags);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// 'import' used to name the CLI's create/update loop on every resource. It
|
|
92
|
+
// now names the API endpoint, which most resources do not have.
|
|
93
|
+
if (args.action === 'import' || args.action.startsWith('import-')) {
|
|
94
|
+
const suffix = args.action === 'import' ? '' : '-' + args.action.replace('import-', '');
|
|
95
|
+
const loops = args.action === 'import' ? HAS_UPSERT : NESTED_UPSERTS.includes(args.action.replace('import-', ''));
|
|
96
|
+
if (loops) {
|
|
97
|
+
this.error(`This resource has no import endpoint. Use: aderis inbox upsert${suffix}${suffix ? ' <id>' : ''} --file data.json`);
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
100
|
const endpoint = ENDPOINTS[args.action];
|
|
@@ -386,7 +409,7 @@ export default class Inbox extends Command {
|
|
|
386
409
|
throw error;
|
|
387
410
|
}
|
|
388
411
|
}
|
|
389
|
-
async
|
|
412
|
+
async runUpsert(flags) {
|
|
390
413
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
391
414
|
if (!context)
|
|
392
415
|
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
@@ -450,12 +473,12 @@ export default class Inbox extends Command {
|
|
|
450
473
|
items = [item];
|
|
451
474
|
}
|
|
452
475
|
else {
|
|
453
|
-
this.error('
|
|
476
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
454
477
|
}
|
|
455
478
|
const createEndpoint = ENDPOINTS['create'];
|
|
456
479
|
const updateEndpoint = ENDPOINTS['update'];
|
|
457
480
|
if (!createEndpoint || !updateEndpoint) {
|
|
458
|
-
this.error('
|
|
481
|
+
this.error('Upsert requires both create and update endpoints');
|
|
459
482
|
}
|
|
460
483
|
// Helper to extract identifier from item (id, code, or xxxCode)
|
|
461
484
|
const getItemIdentifier = (item) => {
|
|
@@ -598,6 +621,117 @@ export default class Inbox extends Command {
|
|
|
598
621
|
this.log('');
|
|
599
622
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
600
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* The API's own import: the whole array goes up in one request and comes
|
|
626
|
+
* back as an import run, which records what happened to every record. A bad
|
|
627
|
+
* record lands in errorLog and the rest are still applied, and the run stays
|
|
628
|
+
* readable afterwards with: aderis imports get <id>.
|
|
629
|
+
*/
|
|
630
|
+
async runServerImport(action, parentId, flags) {
|
|
631
|
+
const endpoint = ENDPOINTS[action];
|
|
632
|
+
if (!endpoint)
|
|
633
|
+
this.error(`Unknown action: ${action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
634
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
635
|
+
if (!context)
|
|
636
|
+
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
637
|
+
if (!hasCredentials(context))
|
|
638
|
+
this.error(missingCredentialsMessage(context));
|
|
639
|
+
let apiPath = endpoint.path;
|
|
640
|
+
if (endpoint.pathParams.length > 0) {
|
|
641
|
+
if (!parentId)
|
|
642
|
+
this.error(`Missing required argument: id. Usage: aderis inbox ${action} <parent-id> --file data.json`);
|
|
643
|
+
apiPath = apiPath.replace(`{${endpoint.pathParams[0]}}`, parentId);
|
|
644
|
+
}
|
|
645
|
+
// The endpoint takes an array. A single object is wrapped, so importing
|
|
646
|
+
// one record reads the same as importing many.
|
|
647
|
+
let records = [];
|
|
648
|
+
if (flags.file) {
|
|
649
|
+
const fsModule = await import('node:fs');
|
|
650
|
+
try {
|
|
651
|
+
const content = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
652
|
+
records = Array.isArray(content) ? content : [content];
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
this.error(`Failed to read file: ${flags.file}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
else if (flags.data) {
|
|
659
|
+
try {
|
|
660
|
+
const content = JSON.parse(flags.data);
|
|
661
|
+
records = Array.isArray(content) ? content : [content];
|
|
662
|
+
}
|
|
663
|
+
catch {
|
|
664
|
+
this.error('Invalid JSON in --data');
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
this.error('Import requires --file or --data holding a JSON array of records');
|
|
669
|
+
}
|
|
670
|
+
if (records.length === 0)
|
|
671
|
+
this.error('Nothing to import: the input is an empty array');
|
|
672
|
+
const params = { format: 'json' };
|
|
673
|
+
if (flags.mode)
|
|
674
|
+
params.mode = flags.mode;
|
|
675
|
+
if (flags.reference)
|
|
676
|
+
params.reference = flags.reference;
|
|
677
|
+
if (flags.async)
|
|
678
|
+
params.async = true;
|
|
679
|
+
const headers = {};
|
|
680
|
+
if (flags['idempotency-key'])
|
|
681
|
+
headers['Idempotency-Key'] = flags['idempotency-key'];
|
|
682
|
+
if (flags['show-http-request']) {
|
|
683
|
+
const baseUrls = getBaseUrls(context.environment);
|
|
684
|
+
const queryString = '?' + Object.entries(params).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join('&');
|
|
685
|
+
process.stderr.write(`\n${endpoint.method.toUpperCase()} ${baseUrls.api}${apiPath}${queryString}\n`);
|
|
686
|
+
process.stderr.write(`Body: [${records.length} record${records.length === 1 ? '' : 's'}]\n\n`);
|
|
687
|
+
}
|
|
688
|
+
try {
|
|
689
|
+
const response = await apiRequest(endpoint.method, apiPath, {
|
|
690
|
+
contextName: flags.context,
|
|
691
|
+
data: records,
|
|
692
|
+
headers,
|
|
693
|
+
params,
|
|
694
|
+
});
|
|
695
|
+
this.printImportRun(response.data, flags);
|
|
696
|
+
}
|
|
697
|
+
catch (error) {
|
|
698
|
+
if (error instanceof ApiError) {
|
|
699
|
+
this.error(`API Error (${error.status}): ${error.message}`);
|
|
700
|
+
}
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/** Renders an import run: its counts, then whatever the server refused. */
|
|
705
|
+
printImportRun(run, flags) {
|
|
706
|
+
if (flags.output === 'json') {
|
|
707
|
+
this.log(JSON.stringify(run, null, 2));
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
const record = (run ?? {});
|
|
711
|
+
const count = (key) => (typeof record[key] === 'number' ? record[key] : 0);
|
|
712
|
+
const id = record.id ? String(record.id) : '';
|
|
713
|
+
this.log(`Import ${id} - ${String(record.status ?? 'UNKNOWN')}${record.async ? ' (background)' : ''}`);
|
|
714
|
+
this.log(` ${count('inputSize')} submitted, ${count('createdCount')} created, ${count('updatedCount')} updated, ${count('unchangedCount')} unchanged`);
|
|
715
|
+
if (count('errorCount') > 0)
|
|
716
|
+
this.log(` ${count('errorCount')} not applied: ${count('refusedCount')} refused, ${count('failedCount')} failed`);
|
|
717
|
+
if (count('warningCount') > 0)
|
|
718
|
+
this.log(` ${count('warningCount')} applied with a warning`);
|
|
719
|
+
// errorLog is keyed by the record's identifier, then by field name.
|
|
720
|
+
const errorLog = record.errorLog;
|
|
721
|
+
if (errorLog && Object.keys(errorLog).length > 0) {
|
|
722
|
+
this.log('');
|
|
723
|
+
for (const [key, fields] of Object.entries(errorLog)) {
|
|
724
|
+
for (const [field, messages] of Object.entries(fields ?? {})) {
|
|
725
|
+
for (const message of messages ?? [])
|
|
726
|
+
this.log(` ${key} ${field}: ${message}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (record.async && id) {
|
|
731
|
+
this.log('');
|
|
732
|
+
this.log(`Follow it with: aderis imports get ${id}`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
601
735
|
async runExport(flags) {
|
|
602
736
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
603
737
|
if (!context)
|
|
@@ -776,9 +910,9 @@ export default class Inbox extends Command {
|
|
|
776
910
|
throw error;
|
|
777
911
|
}
|
|
778
912
|
}
|
|
779
|
-
async
|
|
913
|
+
async runNestedUpsert(suffix, parentId, flags) {
|
|
780
914
|
if (!parentId) {
|
|
781
|
-
this.error(`Missing required argument: id. Usage: aderis inbox
|
|
915
|
+
this.error(`Missing required argument: id. Usage: aderis inbox upsert-${suffix} <parent-id> --file data.json`);
|
|
782
916
|
}
|
|
783
917
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
784
918
|
if (!context)
|
|
@@ -843,12 +977,12 @@ export default class Inbox extends Command {
|
|
|
843
977
|
items = [item];
|
|
844
978
|
}
|
|
845
979
|
else {
|
|
846
|
-
this.error(
|
|
980
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
847
981
|
}
|
|
848
982
|
const createEndpoint = ENDPOINTS[`create-${suffix}`];
|
|
849
983
|
const updateEndpoint = ENDPOINTS[`update-${suffix}`];
|
|
850
984
|
if (!createEndpoint || !updateEndpoint) {
|
|
851
|
-
this.error(`
|
|
985
|
+
this.error(`Upsert requires both create-${suffix} and update-${suffix} endpoints`);
|
|
852
986
|
}
|
|
853
987
|
// Build the base path with parent ID (first path param)
|
|
854
988
|
const firstParam = createEndpoint.pathParams[0];
|
|
@@ -28,10 +28,19 @@ export default class IntegrationIdentities extends Command {
|
|
|
28
28
|
'show-http-request': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
29
29
|
};
|
|
30
30
|
run(): Promise<void>;
|
|
31
|
-
private
|
|
31
|
+
private runUpsert;
|
|
32
|
+
/**
|
|
33
|
+
* The API's own import: the whole array goes up in one request and comes
|
|
34
|
+
* back as an import run, which records what happened to every record. A bad
|
|
35
|
+
* record lands in errorLog and the rest are still applied, and the run stays
|
|
36
|
+
* readable afterwards with: aderis imports get <id>.
|
|
37
|
+
*/
|
|
38
|
+
private runServerImport;
|
|
39
|
+
/** Renders an import run: its counts, then whatever the server refused. */
|
|
40
|
+
private printImportRun;
|
|
32
41
|
private runExport;
|
|
33
42
|
private runCamt053Import;
|
|
34
|
-
private
|
|
43
|
+
private runNestedUpsert;
|
|
35
44
|
private parseFilterValue;
|
|
36
45
|
/** The page line under a table: which page, how many, and any sums the API returned. */
|
|
37
46
|
private printPageSummary;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Command, Args, Flags } from '@oclif/core';
|
|
2
2
|
import { apiRequest, ApiError, isTextualMediaType, normalizeSortBy } from '../lib/api-client.js';
|
|
3
3
|
import { getCurrentContext, getContext, getBaseUrls, hasCredentials, missingCredentialsMessage } from '../lib/config.js';
|
|
4
|
-
//
|
|
5
|
-
|
|
4
|
+
// 'upsert' loops create/update from the CLI, one request per record. It exists
|
|
5
|
+
// only where the API has no import endpoint of its own; those keep the name
|
|
6
|
+
// 'import' and are listed in SERVER_IMPORTS.
|
|
7
|
+
const HAS_UPSERT = false;
|
|
6
8
|
const HAS_EXPORT = false;
|
|
7
9
|
const HAS_CAMT053 = false;
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
+
const SERVER_IMPORTS = [];
|
|
11
|
+
const NESTED_UPSERTS = [];
|
|
12
|
+
const SUBCOMMANDS = [...["list-integrations", "create-integrations", "integrations-disable-all", "get-integrations", "list-integrations-secrets", "create-integrations-secrets", "delete-integrations-secrets", "integrations-disable"], ...(HAS_UPSERT ? ['upsert'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_UPSERTS.map(n => `upsert-${n}`)];
|
|
10
13
|
const ENDPOINTS = {
|
|
11
14
|
'list-integrations': { method: 'GET', path: '/v1/auth/integrations', summary: 'List current tenant integrations, including disabled identities', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
12
15
|
'create-integrations': { method: 'POST', path: '/v1/auth/integrations', summary: 'Create an integration in the current tenant', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: ['permissions'] },
|
|
@@ -26,7 +29,7 @@ export default class IntegrationIdentities extends Command {
|
|
|
26
29
|
};
|
|
27
30
|
static flags = {
|
|
28
31
|
context: Flags.string({ char: 'c', aliases: ['config'], env: 'ADERIS_CONTEXT', description: 'Context to use for this command, overriding the current context (alias: --config)' }),
|
|
29
|
-
output: Flags.string({ char: 'o', description: 'Output format (default: table for
|
|
32
|
+
output: Flags.string({ char: 'o', description: 'Output format (default: table for upsert, json for other commands)', options: ['json', 'table', 'csv'] }),
|
|
30
33
|
table: Flags.boolean({ char: 't', description: 'Output as table (shortcut for --output table)' }),
|
|
31
34
|
csv: Flags.boolean({ description: 'Output as CSV (shortcut for --output csv)' }),
|
|
32
35
|
data: Flags.string({ char: 'd', description: 'JSON data for request body' }),
|
|
@@ -47,11 +50,26 @@ export default class IntegrationIdentities extends Command {
|
|
|
47
50
|
};
|
|
48
51
|
async run() {
|
|
49
52
|
const { args, flags } = await this.parse(IntegrationIdentities);
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// Bulk actions. 'import' is the API's own endpoint: one request, answered
|
|
54
|
+
// by a run that records what happened to every record. 'upsert' is the CLI
|
|
55
|
+
// looping create/update. A resource has one or the other, never both.
|
|
56
|
+
if (args.action === 'upsert') {
|
|
57
|
+
if (!HAS_UPSERT) {
|
|
58
|
+
this.error(SERVER_IMPORTS.includes('import')
|
|
59
|
+
? 'This resource is imported by the API. Use: aderis integration-identities import --file data.json'
|
|
60
|
+
: 'Upsert needs both a create and an update endpoint, which this resource does not have');
|
|
61
|
+
}
|
|
62
|
+
await this.runUpsert(flags);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (args.action.startsWith('upsert-')) {
|
|
66
|
+
const suffix = args.action.replace('upsert-', '');
|
|
67
|
+
if (!NESTED_UPSERTS.includes(suffix)) {
|
|
68
|
+
this.error(SERVER_IMPORTS.includes('import-' + suffix)
|
|
69
|
+
? `That resource is imported by the API. Use: aderis integration-identities import-${suffix} <id> --file data.json`
|
|
70
|
+
: `Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
71
|
+
}
|
|
72
|
+
await this.runNestedUpsert(suffix, args.id, flags);
|
|
55
73
|
return;
|
|
56
74
|
}
|
|
57
75
|
// Handle export action specially
|
|
@@ -68,12 +86,17 @@ export default class IntegrationIdentities extends Command {
|
|
|
68
86
|
await this.runCamt053Import(flags);
|
|
69
87
|
return;
|
|
70
88
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
if (SERVER_IMPORTS.includes(args.action)) {
|
|
90
|
+
await this.runServerImport(args.action, args.id, flags);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// 'import' used to name the CLI's create/update loop on every resource. It
|
|
94
|
+
// now names the API endpoint, which most resources do not have.
|
|
95
|
+
if (args.action === 'import' || args.action.startsWith('import-')) {
|
|
96
|
+
const suffix = args.action === 'import' ? '' : '-' + args.action.replace('import-', '');
|
|
97
|
+
const loops = args.action === 'import' ? HAS_UPSERT : NESTED_UPSERTS.includes(args.action.replace('import-', ''));
|
|
98
|
+
if (loops) {
|
|
99
|
+
this.error(`This resource has no import endpoint. Use: aderis integration-identities upsert${suffix}${suffix ? ' <id>' : ''} --file data.json`);
|
|
77
100
|
}
|
|
78
101
|
}
|
|
79
102
|
const endpoint = ENDPOINTS[args.action];
|
|
@@ -388,7 +411,7 @@ export default class IntegrationIdentities extends Command {
|
|
|
388
411
|
throw error;
|
|
389
412
|
}
|
|
390
413
|
}
|
|
391
|
-
async
|
|
414
|
+
async runUpsert(flags) {
|
|
392
415
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
393
416
|
if (!context)
|
|
394
417
|
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
@@ -452,12 +475,12 @@ export default class IntegrationIdentities extends Command {
|
|
|
452
475
|
items = [item];
|
|
453
476
|
}
|
|
454
477
|
else {
|
|
455
|
-
this.error('
|
|
478
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
456
479
|
}
|
|
457
480
|
const createEndpoint = ENDPOINTS['create'];
|
|
458
481
|
const updateEndpoint = ENDPOINTS['update'];
|
|
459
482
|
if (!createEndpoint || !updateEndpoint) {
|
|
460
|
-
this.error('
|
|
483
|
+
this.error('Upsert requires both create and update endpoints');
|
|
461
484
|
}
|
|
462
485
|
// Helper to extract identifier from item (id, code, or xxxCode)
|
|
463
486
|
const getItemIdentifier = (item) => {
|
|
@@ -600,6 +623,117 @@ export default class IntegrationIdentities extends Command {
|
|
|
600
623
|
this.log('');
|
|
601
624
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
602
625
|
}
|
|
626
|
+
/**
|
|
627
|
+
* The API's own import: the whole array goes up in one request and comes
|
|
628
|
+
* back as an import run, which records what happened to every record. A bad
|
|
629
|
+
* record lands in errorLog and the rest are still applied, and the run stays
|
|
630
|
+
* readable afterwards with: aderis imports get <id>.
|
|
631
|
+
*/
|
|
632
|
+
async runServerImport(action, parentId, flags) {
|
|
633
|
+
const endpoint = ENDPOINTS[action];
|
|
634
|
+
if (!endpoint)
|
|
635
|
+
this.error(`Unknown action: ${action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
636
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
637
|
+
if (!context)
|
|
638
|
+
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
639
|
+
if (!hasCredentials(context))
|
|
640
|
+
this.error(missingCredentialsMessage(context));
|
|
641
|
+
let apiPath = endpoint.path;
|
|
642
|
+
if (endpoint.pathParams.length > 0) {
|
|
643
|
+
if (!parentId)
|
|
644
|
+
this.error(`Missing required argument: id. Usage: aderis integration-identities ${action} <parent-id> --file data.json`);
|
|
645
|
+
apiPath = apiPath.replace(`{${endpoint.pathParams[0]}}`, parentId);
|
|
646
|
+
}
|
|
647
|
+
// The endpoint takes an array. A single object is wrapped, so importing
|
|
648
|
+
// one record reads the same as importing many.
|
|
649
|
+
let records = [];
|
|
650
|
+
if (flags.file) {
|
|
651
|
+
const fsModule = await import('node:fs');
|
|
652
|
+
try {
|
|
653
|
+
const content = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
654
|
+
records = Array.isArray(content) ? content : [content];
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
this.error(`Failed to read file: ${flags.file}`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
else if (flags.data) {
|
|
661
|
+
try {
|
|
662
|
+
const content = JSON.parse(flags.data);
|
|
663
|
+
records = Array.isArray(content) ? content : [content];
|
|
664
|
+
}
|
|
665
|
+
catch {
|
|
666
|
+
this.error('Invalid JSON in --data');
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
this.error('Import requires --file or --data holding a JSON array of records');
|
|
671
|
+
}
|
|
672
|
+
if (records.length === 0)
|
|
673
|
+
this.error('Nothing to import: the input is an empty array');
|
|
674
|
+
const params = { format: 'json' };
|
|
675
|
+
if (flags.mode)
|
|
676
|
+
params.mode = flags.mode;
|
|
677
|
+
if (flags.reference)
|
|
678
|
+
params.reference = flags.reference;
|
|
679
|
+
if (flags.async)
|
|
680
|
+
params.async = true;
|
|
681
|
+
const headers = {};
|
|
682
|
+
if (flags['idempotency-key'])
|
|
683
|
+
headers['Idempotency-Key'] = flags['idempotency-key'];
|
|
684
|
+
if (flags['show-http-request']) {
|
|
685
|
+
const baseUrls = getBaseUrls(context.environment);
|
|
686
|
+
const queryString = '?' + Object.entries(params).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join('&');
|
|
687
|
+
process.stderr.write(`\n${endpoint.method.toUpperCase()} ${baseUrls.api}${apiPath}${queryString}\n`);
|
|
688
|
+
process.stderr.write(`Body: [${records.length} record${records.length === 1 ? '' : 's'}]\n\n`);
|
|
689
|
+
}
|
|
690
|
+
try {
|
|
691
|
+
const response = await apiRequest(endpoint.method, apiPath, {
|
|
692
|
+
contextName: flags.context,
|
|
693
|
+
data: records,
|
|
694
|
+
headers,
|
|
695
|
+
params,
|
|
696
|
+
});
|
|
697
|
+
this.printImportRun(response.data, flags);
|
|
698
|
+
}
|
|
699
|
+
catch (error) {
|
|
700
|
+
if (error instanceof ApiError) {
|
|
701
|
+
this.error(`API Error (${error.status}): ${error.message}`);
|
|
702
|
+
}
|
|
703
|
+
throw error;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
/** Renders an import run: its counts, then whatever the server refused. */
|
|
707
|
+
printImportRun(run, flags) {
|
|
708
|
+
if (flags.output === 'json') {
|
|
709
|
+
this.log(JSON.stringify(run, null, 2));
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const record = (run ?? {});
|
|
713
|
+
const count = (key) => (typeof record[key] === 'number' ? record[key] : 0);
|
|
714
|
+
const id = record.id ? String(record.id) : '';
|
|
715
|
+
this.log(`Import ${id} - ${String(record.status ?? 'UNKNOWN')}${record.async ? ' (background)' : ''}`);
|
|
716
|
+
this.log(` ${count('inputSize')} submitted, ${count('createdCount')} created, ${count('updatedCount')} updated, ${count('unchangedCount')} unchanged`);
|
|
717
|
+
if (count('errorCount') > 0)
|
|
718
|
+
this.log(` ${count('errorCount')} not applied: ${count('refusedCount')} refused, ${count('failedCount')} failed`);
|
|
719
|
+
if (count('warningCount') > 0)
|
|
720
|
+
this.log(` ${count('warningCount')} applied with a warning`);
|
|
721
|
+
// errorLog is keyed by the record's identifier, then by field name.
|
|
722
|
+
const errorLog = record.errorLog;
|
|
723
|
+
if (errorLog && Object.keys(errorLog).length > 0) {
|
|
724
|
+
this.log('');
|
|
725
|
+
for (const [key, fields] of Object.entries(errorLog)) {
|
|
726
|
+
for (const [field, messages] of Object.entries(fields ?? {})) {
|
|
727
|
+
for (const message of messages ?? [])
|
|
728
|
+
this.log(` ${key} ${field}: ${message}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (record.async && id) {
|
|
733
|
+
this.log('');
|
|
734
|
+
this.log(`Follow it with: aderis imports get ${id}`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
603
737
|
async runExport(flags) {
|
|
604
738
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
605
739
|
if (!context)
|
|
@@ -778,9 +912,9 @@ export default class IntegrationIdentities extends Command {
|
|
|
778
912
|
throw error;
|
|
779
913
|
}
|
|
780
914
|
}
|
|
781
|
-
async
|
|
915
|
+
async runNestedUpsert(suffix, parentId, flags) {
|
|
782
916
|
if (!parentId) {
|
|
783
|
-
this.error(`Missing required argument: id. Usage: aderis integration-identities
|
|
917
|
+
this.error(`Missing required argument: id. Usage: aderis integration-identities upsert-${suffix} <parent-id> --file data.json`);
|
|
784
918
|
}
|
|
785
919
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
786
920
|
if (!context)
|
|
@@ -845,12 +979,12 @@ export default class IntegrationIdentities extends Command {
|
|
|
845
979
|
items = [item];
|
|
846
980
|
}
|
|
847
981
|
else {
|
|
848
|
-
this.error(
|
|
982
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
849
983
|
}
|
|
850
984
|
const createEndpoint = ENDPOINTS[`create-${suffix}`];
|
|
851
985
|
const updateEndpoint = ENDPOINTS[`update-${suffix}`];
|
|
852
986
|
if (!createEndpoint || !updateEndpoint) {
|
|
853
|
-
this.error(`
|
|
987
|
+
this.error(`Upsert requires both create-${suffix} and update-${suffix} endpoints`);
|
|
854
988
|
}
|
|
855
989
|
// Build the base path with parent ID (first path param)
|
|
856
990
|
const firstParam = createEndpoint.pathParams[0];
|
|
@@ -28,10 +28,19 @@ export default class Integrations extends Command {
|
|
|
28
28
|
'show-http-request': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
29
29
|
};
|
|
30
30
|
run(): Promise<void>;
|
|
31
|
-
private
|
|
31
|
+
private runUpsert;
|
|
32
|
+
/**
|
|
33
|
+
* The API's own import: the whole array goes up in one request and comes
|
|
34
|
+
* back as an import run, which records what happened to every record. A bad
|
|
35
|
+
* record lands in errorLog and the rest are still applied, and the run stays
|
|
36
|
+
* readable afterwards with: aderis imports get <id>.
|
|
37
|
+
*/
|
|
38
|
+
private runServerImport;
|
|
39
|
+
/** Renders an import run: its counts, then whatever the server refused. */
|
|
40
|
+
private printImportRun;
|
|
32
41
|
private runExport;
|
|
33
42
|
private runCamt053Import;
|
|
34
|
-
private
|
|
43
|
+
private runNestedUpsert;
|
|
35
44
|
private parseFilterValue;
|
|
36
45
|
/** The page line under a table: which page, how many, and any sums the API returned. */
|
|
37
46
|
private printPageSummary;
|