@aderis-erp/cli 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- 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-clients.d.ts +58 -0
- package/dist/commands/api-clients.js +1341 -0
- 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 +159 -25
- 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 +15 -2
- package/dist/commands/credit-card-accounts.js +163 -24
- package/dist/commands/currencies.d.ts +56 -0
- package/dist/commands/currencies.js +1327 -0
- package/dist/commands/custody-accounts.d.ts +56 -0
- package/dist/commands/custody-accounts.js +1335 -0
- package/dist/commands/dashboards.d.ts +57 -0
- package/dist/commands/dashboards.js +1347 -0
- package/dist/commands/delivery-notes.d.ts +11 -2
- package/dist/commands/delivery-notes.js +158 -24
- package/dist/commands/{integration-identities.d.ts → document-checksums.d.ts} +12 -4
- package/dist/commands/{integration-identities.js → document-checksums.js} +162 -36
- 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/financial-instrument-types.d.ts +56 -0
- package/dist/commands/financial-instrument-types.js +1335 -0
- package/dist/commands/financial-instruments.d.ts +56 -0
- package/dist/commands/financial-instruments.js +1335 -0
- 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/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 +165 -26
- 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/{workflows.d.ts → kpis.d.ts} +12 -3
- package/dist/commands/kpis.js +1337 -0
- package/dist/commands/ledgers.d.ts +11 -2
- package/dist/commands/ledgers.js +159 -25
- package/dist/commands/my-account.d.ts +11 -2
- package/dist/commands/my-account.js +157 -23
- package/dist/commands/notifications.d.ts +56 -0
- package/dist/commands/notifications.js +1326 -0
- 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 +159 -25
- 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/settings.d.ts +56 -0
- package/dist/commands/settings.js +1327 -0
- 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 +163 -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 +162 -24
- package/dist/commands/webhooks.d.ts +11 -2
- package/dist/commands/webhooks.js +158 -24
- package/dist/commands/work-summary.d.ts +56 -0
- package/dist/commands/{workflows.js → work-summary.js} +164 -33
- package/dist/lib/api-client.d.ts +1 -0
- package/dist/lib/api-client.js +3 -0
- package/dist/lib/auth/index.js +5 -0
- package/dist/lib/production-guard.d.ts +42 -0
- package/dist/lib/production-guard.js +92 -0
- package/oclif.manifest.json +2358 -442
- package/package.json +1 -1
|
@@ -1,22 +1,22 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
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;
|
|
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 = [...["get"], ...(HAS_UPSERT ? ['upsert'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_UPSERTS.map(n => `upsert-${n}`)];
|
|
10
13
|
const ENDPOINTS = {
|
|
11
|
-
'
|
|
12
|
-
'status': { method: 'POST', path: '/v1/workflows/status', summary: 'Create a new workflow status update', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
13
|
-
'find': { method: 'GET', path: '/v1/workflows/{workflowId}', summary: 'Get workflow details including status updates and entity changes', pathParams: ['workflowId'], hasBody: false, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
14
|
+
'get': { method: 'GET', path: '/v1/work-summary', summary: 'Count what is open for the caller', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, hasBinaryVariant: false, bodyArrayFields: [] },
|
|
14
15
|
};
|
|
15
|
-
export default class
|
|
16
|
-
static description = 'Manage
|
|
16
|
+
export default class WorkSummary extends Command {
|
|
17
|
+
static description = 'Manage work summary';
|
|
17
18
|
static examples = [
|
|
18
|
-
'<%= config.bin %>
|
|
19
|
-
'<%= config.bin %> workflows export --csv > workflows.csv',
|
|
19
|
+
'<%= config.bin %> work-summary get <id>',
|
|
20
20
|
];
|
|
21
21
|
static args = {
|
|
22
22
|
action: Args.string({ description: 'Action: ' + SUBCOMMANDS.join(', '), required: true }),
|
|
@@ -24,7 +24,7 @@ export default class Workflows extends Command {
|
|
|
24
24
|
};
|
|
25
25
|
static flags = {
|
|
26
26
|
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
|
|
27
|
+
output: Flags.string({ char: 'o', description: 'Output format (default: table for upsert, json for other commands)', options: ['json', 'table', 'csv'] }),
|
|
28
28
|
table: Flags.boolean({ char: 't', description: 'Output as table (shortcut for --output table)' }),
|
|
29
29
|
csv: Flags.boolean({ description: 'Output as CSV (shortcut for --output csv)' }),
|
|
30
30
|
data: Flags.string({ char: 'd', description: 'JSON data for request body' }),
|
|
@@ -43,12 +43,27 @@ export default class Workflows extends Command {
|
|
|
43
43
|
'show-http-request': Flags.boolean({ description: 'Show HTTP request details (method, URL, body)' }),
|
|
44
44
|
};
|
|
45
45
|
async run() {
|
|
46
|
-
const { args, flags } = await this.parse(
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const { args, flags } = await this.parse(WorkSummary);
|
|
47
|
+
// Bulk actions. 'import' is the API's own endpoint: one request, answered
|
|
48
|
+
// by a run that records what happened to every record. 'upsert' is the CLI
|
|
49
|
+
// looping create/update. A resource has one or the other, never both.
|
|
50
|
+
if (args.action === 'upsert') {
|
|
51
|
+
if (!HAS_UPSERT) {
|
|
52
|
+
this.error(SERVER_IMPORTS.includes('import')
|
|
53
|
+
? 'This resource is imported by the API. Use: aderis work-summary import --file data.json'
|
|
54
|
+
: 'Upsert needs both a create and an update endpoint, which this resource does not have');
|
|
55
|
+
}
|
|
56
|
+
await this.runUpsert(flags);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (args.action.startsWith('upsert-')) {
|
|
60
|
+
const suffix = args.action.replace('upsert-', '');
|
|
61
|
+
if (!NESTED_UPSERTS.includes(suffix)) {
|
|
62
|
+
this.error(SERVER_IMPORTS.includes('import-' + suffix)
|
|
63
|
+
? `That resource is imported by the API. Use: aderis work-summary import-${suffix} <id> --file data.json`
|
|
64
|
+
: `Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
await this.runNestedUpsert(suffix, args.id, flags);
|
|
52
67
|
return;
|
|
53
68
|
}
|
|
54
69
|
// Handle export action specially
|
|
@@ -65,12 +80,17 @@ export default class Workflows extends Command {
|
|
|
65
80
|
await this.runCamt053Import(flags);
|
|
66
81
|
return;
|
|
67
82
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
if (SERVER_IMPORTS.includes(args.action)) {
|
|
84
|
+
await this.runServerImport(args.action, args.id, flags);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// 'import' used to name the CLI's create/update loop on every resource. It
|
|
88
|
+
// now names the API endpoint, which most resources do not have.
|
|
89
|
+
if (args.action === 'import' || args.action.startsWith('import-')) {
|
|
90
|
+
const suffix = args.action === 'import' ? '' : '-' + args.action.replace('import-', '');
|
|
91
|
+
const loops = args.action === 'import' ? HAS_UPSERT : NESTED_UPSERTS.includes(args.action.replace('import-', ''));
|
|
92
|
+
if (loops) {
|
|
93
|
+
this.error(`This resource has no import endpoint. Use: aderis work-summary upsert${suffix}${suffix ? ' <id>' : ''} --file data.json`);
|
|
74
94
|
}
|
|
75
95
|
}
|
|
76
96
|
const endpoint = ENDPOINTS[args.action];
|
|
@@ -84,7 +104,7 @@ export default class Workflows extends Command {
|
|
|
84
104
|
// First path param always comes from positional argument
|
|
85
105
|
value = args.id;
|
|
86
106
|
if (!value)
|
|
87
|
-
this.error('Missing required argument: id. Usage: aderis
|
|
107
|
+
this.error('Missing required argument: id. Usage: aderis work-summary <action> <id>');
|
|
88
108
|
}
|
|
89
109
|
else {
|
|
90
110
|
const flagName = param.replace(/\./g, '-').replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
|
@@ -385,7 +405,7 @@ export default class Workflows extends Command {
|
|
|
385
405
|
throw error;
|
|
386
406
|
}
|
|
387
407
|
}
|
|
388
|
-
async
|
|
408
|
+
async runUpsert(flags) {
|
|
389
409
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
390
410
|
if (!context)
|
|
391
411
|
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
@@ -449,12 +469,12 @@ export default class Workflows extends Command {
|
|
|
449
469
|
items = [item];
|
|
450
470
|
}
|
|
451
471
|
else {
|
|
452
|
-
this.error('
|
|
472
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
453
473
|
}
|
|
454
474
|
const createEndpoint = ENDPOINTS['create'];
|
|
455
475
|
const updateEndpoint = ENDPOINTS['update'];
|
|
456
476
|
if (!createEndpoint || !updateEndpoint) {
|
|
457
|
-
this.error('
|
|
477
|
+
this.error('Upsert requires both create and update endpoints');
|
|
458
478
|
}
|
|
459
479
|
// Helper to extract identifier from item (id, code, or xxxCode)
|
|
460
480
|
const getItemIdentifier = (item) => {
|
|
@@ -597,6 +617,117 @@ export default class Workflows extends Command {
|
|
|
597
617
|
this.log('');
|
|
598
618
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
599
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* The API's own import: the whole array goes up in one request and comes
|
|
622
|
+
* back as an import run, which records what happened to every record. A bad
|
|
623
|
+
* record lands in errorLog and the rest are still applied, and the run stays
|
|
624
|
+
* readable afterwards with: aderis imports get <id>.
|
|
625
|
+
*/
|
|
626
|
+
async runServerImport(action, parentId, flags) {
|
|
627
|
+
const endpoint = ENDPOINTS[action];
|
|
628
|
+
if (!endpoint)
|
|
629
|
+
this.error(`Unknown action: ${action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
630
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
631
|
+
if (!context)
|
|
632
|
+
this.error(flags.context ? `Context "${flags.context}" not found. List contexts with: aderis config list` : 'No context configured. Run: aderis auth login --new');
|
|
633
|
+
if (!hasCredentials(context))
|
|
634
|
+
this.error(missingCredentialsMessage(context));
|
|
635
|
+
let apiPath = endpoint.path;
|
|
636
|
+
if (endpoint.pathParams.length > 0) {
|
|
637
|
+
if (!parentId)
|
|
638
|
+
this.error(`Missing required argument: id. Usage: aderis work-summary ${action} <parent-id> --file data.json`);
|
|
639
|
+
apiPath = apiPath.replace(`{${endpoint.pathParams[0]}}`, parentId);
|
|
640
|
+
}
|
|
641
|
+
// The endpoint takes an array. A single object is wrapped, so importing
|
|
642
|
+
// one record reads the same as importing many.
|
|
643
|
+
let records = [];
|
|
644
|
+
if (flags.file) {
|
|
645
|
+
const fsModule = await import('node:fs');
|
|
646
|
+
try {
|
|
647
|
+
const content = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
648
|
+
records = Array.isArray(content) ? content : [content];
|
|
649
|
+
}
|
|
650
|
+
catch {
|
|
651
|
+
this.error(`Failed to read file: ${flags.file}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
else if (flags.data) {
|
|
655
|
+
try {
|
|
656
|
+
const content = JSON.parse(flags.data);
|
|
657
|
+
records = Array.isArray(content) ? content : [content];
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
this.error('Invalid JSON in --data');
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
this.error('Import requires --file or --data holding a JSON array of records');
|
|
665
|
+
}
|
|
666
|
+
if (records.length === 0)
|
|
667
|
+
this.error('Nothing to import: the input is an empty array');
|
|
668
|
+
const params = { format: 'json' };
|
|
669
|
+
if (flags.mode)
|
|
670
|
+
params.mode = flags.mode;
|
|
671
|
+
if (flags.reference)
|
|
672
|
+
params.reference = flags.reference;
|
|
673
|
+
if (flags.async)
|
|
674
|
+
params.async = true;
|
|
675
|
+
const headers = {};
|
|
676
|
+
if (flags['idempotency-key'])
|
|
677
|
+
headers['Idempotency-Key'] = flags['idempotency-key'];
|
|
678
|
+
if (flags['show-http-request']) {
|
|
679
|
+
const baseUrls = getBaseUrls(context.environment);
|
|
680
|
+
const queryString = '?' + Object.entries(params).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join('&');
|
|
681
|
+
process.stderr.write(`\n${endpoint.method.toUpperCase()} ${baseUrls.api}${apiPath}${queryString}\n`);
|
|
682
|
+
process.stderr.write(`Body: [${records.length} record${records.length === 1 ? '' : 's'}]\n\n`);
|
|
683
|
+
}
|
|
684
|
+
try {
|
|
685
|
+
const response = await apiRequest(endpoint.method, apiPath, {
|
|
686
|
+
contextName: flags.context,
|
|
687
|
+
data: records,
|
|
688
|
+
headers,
|
|
689
|
+
params,
|
|
690
|
+
});
|
|
691
|
+
this.printImportRun(response.data, flags);
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
if (error instanceof ApiError) {
|
|
695
|
+
this.error(`API Error (${error.status}): ${error.message}`);
|
|
696
|
+
}
|
|
697
|
+
throw error;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
/** Renders an import run: its counts, then whatever the server refused. */
|
|
701
|
+
printImportRun(run, flags) {
|
|
702
|
+
if (flags.output === 'json') {
|
|
703
|
+
this.log(JSON.stringify(run, null, 2));
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
const record = (run ?? {});
|
|
707
|
+
const count = (key) => (typeof record[key] === 'number' ? record[key] : 0);
|
|
708
|
+
const id = record.id ? String(record.id) : '';
|
|
709
|
+
this.log(`Import ${id} - ${String(record.status ?? 'UNKNOWN')}${record.async ? ' (background)' : ''}`);
|
|
710
|
+
this.log(` ${count('inputSize')} submitted, ${count('createdCount')} created, ${count('updatedCount')} updated, ${count('unchangedCount')} unchanged`);
|
|
711
|
+
if (count('errorCount') > 0)
|
|
712
|
+
this.log(` ${count('errorCount')} not applied: ${count('refusedCount')} refused, ${count('failedCount')} failed`);
|
|
713
|
+
if (count('warningCount') > 0)
|
|
714
|
+
this.log(` ${count('warningCount')} applied with a warning`);
|
|
715
|
+
// errorLog is keyed by the record's identifier, then by field name.
|
|
716
|
+
const errorLog = record.errorLog;
|
|
717
|
+
if (errorLog && Object.keys(errorLog).length > 0) {
|
|
718
|
+
this.log('');
|
|
719
|
+
for (const [key, fields] of Object.entries(errorLog)) {
|
|
720
|
+
for (const [field, messages] of Object.entries(fields ?? {})) {
|
|
721
|
+
for (const message of messages ?? [])
|
|
722
|
+
this.log(` ${key} ${field}: ${message}`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (record.async && id) {
|
|
727
|
+
this.log('');
|
|
728
|
+
this.log(`Follow it with: aderis imports get ${id}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
600
731
|
async runExport(flags) {
|
|
601
732
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
602
733
|
if (!context)
|
|
@@ -775,9 +906,9 @@ export default class Workflows extends Command {
|
|
|
775
906
|
throw error;
|
|
776
907
|
}
|
|
777
908
|
}
|
|
778
|
-
async
|
|
909
|
+
async runNestedUpsert(suffix, parentId, flags) {
|
|
779
910
|
if (!parentId) {
|
|
780
|
-
this.error(`Missing required argument: id. Usage: aderis
|
|
911
|
+
this.error(`Missing required argument: id. Usage: aderis work-summary upsert-${suffix} <parent-id> --file data.json`);
|
|
781
912
|
}
|
|
782
913
|
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
783
914
|
if (!context)
|
|
@@ -842,12 +973,12 @@ export default class Workflows extends Command {
|
|
|
842
973
|
items = [item];
|
|
843
974
|
}
|
|
844
975
|
else {
|
|
845
|
-
this.error(
|
|
976
|
+
this.error('Upsert requires --file, --data, or --set flags');
|
|
846
977
|
}
|
|
847
978
|
const createEndpoint = ENDPOINTS[`create-${suffix}`];
|
|
848
979
|
const updateEndpoint = ENDPOINTS[`update-${suffix}`];
|
|
849
980
|
if (!createEndpoint || !updateEndpoint) {
|
|
850
|
-
this.error(`
|
|
981
|
+
this.error(`Upsert requires both create-${suffix} and update-${suffix} endpoints`);
|
|
851
982
|
}
|
|
852
983
|
// Build the base path with parent ID (first path param)
|
|
853
984
|
const firstParam = createEndpoint.pathParams[0];
|
package/dist/lib/api-client.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export declare function apiRequest<T = unknown>(method: string, path: string, op
|
|
|
49
49
|
contentType?: string;
|
|
50
50
|
contextName?: string;
|
|
51
51
|
data?: unknown;
|
|
52
|
+
headers?: Record<string, string>;
|
|
52
53
|
params?: Record<string, unknown>;
|
|
53
54
|
responseType?: 'arraybuffer' | 'json' | 'stream' | 'text';
|
|
54
55
|
}): Promise<ApiResponse<T>>;
|
package/dist/lib/api-client.js
CHANGED
|
@@ -132,6 +132,9 @@ export async function apiRequest(method, path, options = {}) {
|
|
|
132
132
|
if (options.params) {
|
|
133
133
|
config.params = options.params;
|
|
134
134
|
}
|
|
135
|
+
if (options.headers) {
|
|
136
|
+
config.headers = { ...config.headers, ...options.headers };
|
|
137
|
+
}
|
|
135
138
|
if (options.data) {
|
|
136
139
|
config.data = options.data;
|
|
137
140
|
// Auto-detect FormData and set appropriate headers
|
package/dist/lib/auth/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { clearSupportSession, getAuthType, getBaseUrls, getContext, getSupportSession, missingCredentialsMessage, saveCachedTenants, saveSupportSession, saveTokens, SESSION_EXPIRED_MESSAGE, unauthorizedMessage, } from '../config.js';
|
|
7
|
+
import { assertProductionAccess } from '../production-guard.js';
|
|
7
8
|
import { AuthError, TenantMismatchError } from './errors.js';
|
|
8
9
|
import { runBrowserFlow } from './flow.js';
|
|
9
10
|
import { requireOAuthContext } from './guards.js';
|
|
@@ -49,6 +50,7 @@ function withTenantAssertion(rounds, tenantId) {
|
|
|
49
50
|
}
|
|
50
51
|
export async function login(context, options = {}) {
|
|
51
52
|
requireOAuthContext(context, 'Browser login');
|
|
53
|
+
assertProductionAccess(context);
|
|
52
54
|
return runBrowserFlow(context, keycloakProvider, [{ prompt: options.prompt }], {
|
|
53
55
|
log: options.log,
|
|
54
56
|
openBrowser: options.openBrowser,
|
|
@@ -99,6 +101,9 @@ export async function getValidToken(contextName) {
|
|
|
99
101
|
*/
|
|
100
102
|
export async function getAuthHeaders(contextName) {
|
|
101
103
|
const context = requireContext(contextName);
|
|
104
|
+
// Every API request fetches its headers here, so production is refused before
|
|
105
|
+
// a token is read or refreshed. `login` guards the minting of live tokens.
|
|
106
|
+
assertProductionAccess(context);
|
|
102
107
|
if (getAuthType(context) === 'api_key') {
|
|
103
108
|
if (!context.api_key) {
|
|
104
109
|
throw new Error(missingCredentialsMessage(context));
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Context } from './config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Claude organisation of Aderis AG. From an aderis.com address, it is the
|
|
4
|
+
* only Claude account that may drive the `live` environment through this CLI.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ADERIS_CLAUDE_ORGANIZATION_UUID = "f5d2d8c1-7256-4628-89d9-45c029577670";
|
|
7
|
+
/** Staff addresses: the guard applies to these and to nobody else. */
|
|
8
|
+
export declare const ADERIS_EMAIL_DOMAIN = "aderis.com";
|
|
9
|
+
/** The Claude Code account that is running this process. */
|
|
10
|
+
export interface ClaudeAccount {
|
|
11
|
+
email?: string;
|
|
12
|
+
organizationUuid?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Thrown when a Claude account outside the Aderis organisation reaches for production. */
|
|
15
|
+
export declare class ProductionAccessError extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The Claude Code account driving this process, or `null` when no Claude Code
|
|
20
|
+
* session is (`CLAUDECODE` unset): a person at the terminal is not gated.
|
|
21
|
+
*
|
|
22
|
+
* Claude Code exports the account into the environment of every command it
|
|
23
|
+
* runs (`CLAUDE_CODE_USER_EMAIL`, `CLAUDE_CODE_ORGANIZATION_UUID`); whatever the
|
|
24
|
+
* environment lacks is filled in from the stored account file.
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectClaudeAccount(env?: NodeJS.ProcessEnv, homedir?: string): ClaudeAccount | null;
|
|
27
|
+
/** Whether an address belongs to Aderis staff (case-insensitive). */
|
|
28
|
+
export declare function isAderisAddress(email?: string): boolean;
|
|
29
|
+
/** The error shown when production is refused; names the account so the fix is obvious. */
|
|
30
|
+
export declare function productionRefusedMessage(context: Context, account: ClaudeAccount): string;
|
|
31
|
+
/**
|
|
32
|
+
* Refuses production for Aderis staff who drive the CLI from Claude Code with a
|
|
33
|
+
* Claude account outside the Aderis organisation, so no customer data passes
|
|
34
|
+
* through a personal Claude subscription. Fails exactly when all three hold:
|
|
35
|
+
* the context is `live`, the Claude account has an aderis.com address, and its
|
|
36
|
+
* organisation is not {@link ADERIS_CLAUDE_ORGANIZATION_UUID}.
|
|
37
|
+
*
|
|
38
|
+
* Runs before any token is read, refreshed or minted. It is a client-side
|
|
39
|
+
* tripwire against the accidental case, not a security boundary: the API
|
|
40
|
+
* cannot tell which Claude account made a call.
|
|
41
|
+
*/
|
|
42
|
+
export declare function assertProductionAccess(context: Context, account?: ClaudeAccount | null): void;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* The Claude organisation of Aderis AG. From an aderis.com address, it is the
|
|
6
|
+
* only Claude account that may drive the `live` environment through this CLI.
|
|
7
|
+
*/
|
|
8
|
+
export const ADERIS_CLAUDE_ORGANIZATION_UUID = 'f5d2d8c1-7256-4628-89d9-45c029577670';
|
|
9
|
+
/** Staff addresses: the guard applies to these and to nobody else. */
|
|
10
|
+
export const ADERIS_EMAIL_DOMAIN = 'aderis.com';
|
|
11
|
+
/** Thrown when a Claude account outside the Aderis organisation reaches for production. */
|
|
12
|
+
export class ProductionAccessError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ProductionAccessError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function nonEmpty(value) {
|
|
19
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Claude Code keeps the signed-in account in `.claude.json` under
|
|
23
|
+
* `oauthAccount`, in `$CLAUDE_CONFIG_DIR` or the home directory. Unreadable or
|
|
24
|
+
* malformed means "nothing known", never an error: the file is Claude's, not ours.
|
|
25
|
+
*/
|
|
26
|
+
function readStoredAccount(env, homedir) {
|
|
27
|
+
const dir = env.CLAUDE_CONFIG_DIR ? path.resolve(env.CLAUDE_CONFIG_DIR) : homedir;
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(dir, '.claude.json'), 'utf8'));
|
|
30
|
+
const account = parsed.oauthAccount;
|
|
31
|
+
if (!account || typeof account !== 'object')
|
|
32
|
+
return undefined;
|
|
33
|
+
return { email: nonEmpty(account.emailAddress), organizationUuid: nonEmpty(account.organizationUuid) };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The Claude Code account driving this process, or `null` when no Claude Code
|
|
41
|
+
* session is (`CLAUDECODE` unset): a person at the terminal is not gated.
|
|
42
|
+
*
|
|
43
|
+
* Claude Code exports the account into the environment of every command it
|
|
44
|
+
* runs (`CLAUDE_CODE_USER_EMAIL`, `CLAUDE_CODE_ORGANIZATION_UUID`); whatever the
|
|
45
|
+
* environment lacks is filled in from the stored account file.
|
|
46
|
+
*/
|
|
47
|
+
export function detectClaudeAccount(env = process.env, homedir = os.homedir()) {
|
|
48
|
+
if (!nonEmpty(env.CLAUDECODE))
|
|
49
|
+
return null;
|
|
50
|
+
const fromEnv = {
|
|
51
|
+
email: nonEmpty(env.CLAUDE_CODE_USER_EMAIL),
|
|
52
|
+
organizationUuid: nonEmpty(env.CLAUDE_CODE_ORGANIZATION_UUID),
|
|
53
|
+
};
|
|
54
|
+
if (fromEnv.email && fromEnv.organizationUuid)
|
|
55
|
+
return fromEnv;
|
|
56
|
+
const stored = readStoredAccount(env, homedir);
|
|
57
|
+
return {
|
|
58
|
+
email: fromEnv.email ?? stored?.email,
|
|
59
|
+
organizationUuid: fromEnv.organizationUuid ?? stored?.organizationUuid,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Whether an address belongs to Aderis staff (case-insensitive). */
|
|
63
|
+
export function isAderisAddress(email) {
|
|
64
|
+
return email?.trim().toLowerCase().endsWith(`@${ADERIS_EMAIL_DOMAIN}`) ?? false;
|
|
65
|
+
}
|
|
66
|
+
/** The error shown when production is refused; names the account so the fix is obvious. */
|
|
67
|
+
export function productionRefusedMessage(context, account) {
|
|
68
|
+
return (`Production access refused for context "${context.name}" (live): Claude Code is signed in as ` +
|
|
69
|
+
`${account.email} in Claude organisation ${account.organizationUuid ?? 'unknown'}, which is not the ` +
|
|
70
|
+
'Aderis organisation. Aderis staff may only reach production through a Claude account in the Aderis ' +
|
|
71
|
+
'organisation. Sign in to Claude Code with your Aderis Team account, or use a non-production context.');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Refuses production for Aderis staff who drive the CLI from Claude Code with a
|
|
75
|
+
* Claude account outside the Aderis organisation, so no customer data passes
|
|
76
|
+
* through a personal Claude subscription. Fails exactly when all three hold:
|
|
77
|
+
* the context is `live`, the Claude account has an aderis.com address, and its
|
|
78
|
+
* organisation is not {@link ADERIS_CLAUDE_ORGANIZATION_UUID}.
|
|
79
|
+
*
|
|
80
|
+
* Runs before any token is read, refreshed or minted. It is a client-side
|
|
81
|
+
* tripwire against the accidental case, not a security boundary: the API
|
|
82
|
+
* cannot tell which Claude account made a call.
|
|
83
|
+
*/
|
|
84
|
+
export function assertProductionAccess(context, account = detectClaudeAccount()) {
|
|
85
|
+
if (context.environment !== 'live')
|
|
86
|
+
return;
|
|
87
|
+
if (!account || !isAderisAddress(account.email))
|
|
88
|
+
return;
|
|
89
|
+
if (account.organizationUuid?.toLowerCase() === ADERIS_CLAUDE_ORGANIZATION_UUID)
|
|
90
|
+
return;
|
|
91
|
+
throw new ProductionAccessError(productionRefusedMessage(context, account));
|
|
92
|
+
}
|