@aderis-erp/cli 1.0.3 → 1.0.7
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 +6 -0
- package/dist/commands/access-groups.d.ts +1 -0
- package/dist/commands/access-groups.js +84 -28
- package/dist/commands/{async-endpoints-internal.d.ts → account-transaction-allocations.d.ts} +3 -2
- package/dist/commands/{async-endpoints-internal.js → account-transaction-allocations.js} +93 -33
- package/dist/commands/account-transactions.d.ts +1 -0
- package/dist/commands/account-transactions.js +96 -40
- package/dist/commands/accounts.d.ts +1 -0
- package/dist/commands/accounts.js +89 -33
- package/dist/commands/agent-runs.d.ts +1 -0
- package/dist/commands/agent-runs.js +85 -27
- package/dist/commands/audit-log.d.ts +1 -0
- package/dist/commands/audit-log.js +82 -26
- package/dist/commands/auth/login.js +1 -2
- package/dist/commands/auth/tenant.d.ts +1 -1
- package/dist/commands/auth/tenant.js +11 -11
- package/dist/commands/auth.js +1 -1
- package/dist/commands/bank-accounts.d.ts +1 -0
- package/dist/commands/bank-accounts.js +96 -40
- package/dist/commands/bank-integrations.d.ts +1 -0
- package/dist/commands/bank-integrations.js +97 -41
- package/dist/commands/business-partners---contacts.d.ts +1 -0
- package/dist/commands/business-partners---contacts.js +89 -33
- package/dist/commands/business-partners.d.ts +1 -0
- package/dist/commands/business-partners.js +89 -33
- package/dist/commands/credit-card-accounts.d.ts +1 -0
- package/dist/commands/credit-card-accounts.js +94 -38
- package/dist/commands/documents.d.ts +1 -0
- package/dist/commands/documents.js +85 -29
- package/dist/commands/dunning-configs.d.ts +1 -0
- package/dist/commands/dunning-configs.js +84 -28
- package/dist/commands/dunning-reminders.d.ts +1 -0
- package/dist/commands/dunning-reminders.js +87 -31
- package/dist/commands/dunning-runs.d.ts +1 -0
- package/dist/commands/dunning-runs.js +80 -24
- package/dist/commands/employees.d.ts +1 -0
- package/dist/commands/employees.js +111 -55
- package/dist/commands/event-processor-mappings.d.ts +1 -0
- package/dist/commands/event-processor-mappings.js +84 -28
- package/dist/commands/files-internal.d.ts +1 -0
- package/dist/commands/files-internal.js +88 -32
- package/dist/commands/health.d.ts +1 -0
- package/dist/commands/health.js +84 -28
- package/dist/commands/inbox.d.ts +1 -0
- package/dist/commands/inbox.js +84 -28
- package/dist/commands/integrations.d.ts +1 -0
- package/dist/commands/integrations.js +82 -26
- package/dist/commands/item-categories.d.ts +1 -0
- package/dist/commands/item-categories.js +84 -28
- package/dist/commands/items.d.ts +1 -0
- package/dist/commands/items.js +84 -28
- package/dist/commands/journal-lines.d.ts +1 -0
- package/dist/commands/journal-lines.js +80 -24
- package/dist/commands/journals.d.ts +1 -0
- package/dist/commands/journals.js +98 -42
- package/dist/commands/ledgers.d.ts +1 -0
- package/dist/commands/ledgers.js +95 -39
- package/dist/commands/office-locations.d.ts +1 -0
- package/dist/commands/office-locations.js +84 -28
- package/dist/commands/payment-method-ledger-mappings.d.ts +1 -0
- package/dist/commands/payment-method-ledger-mappings.js +84 -28
- package/dist/commands/payment-methods.d.ts +1 -0
- package/dist/commands/payment-methods.js +84 -28
- package/dist/commands/payment-runs.d.ts +1 -0
- package/dist/commands/payment-runs.js +97 -41
- package/dist/commands/payment-terms.d.ts +1 -0
- package/dist/commands/payment-terms.js +85 -29
- package/dist/commands/price-lists.d.ts +1 -0
- package/dist/commands/price-lists.js +89 -33
- package/dist/commands/processor-mappings.d.ts +1 -0
- package/dist/commands/processor-mappings.js +83 -27
- package/dist/commands/processors.d.ts +1 -0
- package/dist/commands/processors.js +88 -32
- package/dist/commands/reconciliation.d.ts +1 -0
- package/dist/commands/reconciliation.js +85 -29
- package/dist/commands/reports.d.ts +1 -0
- package/dist/commands/reports.js +85 -26
- package/dist/commands/salary-types.d.ts +1 -0
- package/dist/commands/salary-types.js +84 -28
- package/dist/commands/sales-invoices.d.ts +1 -0
- package/dist/commands/sales-invoices.js +109 -53
- package/dist/commands/sales-orders.d.ts +1 -0
- package/dist/commands/sales-orders.js +107 -51
- package/dist/commands/tags.d.ts +1 -0
- package/dist/commands/tags.js +84 -28
- package/dist/commands/tax-codes.d.ts +1 -0
- package/dist/commands/tax-codes.js +87 -31
- package/dist/commands/tax-matrix.d.ts +1 -0
- package/dist/commands/tax-matrix.js +84 -28
- package/dist/commands/tenants.d.ts +1 -0
- package/dist/commands/tenants.js +84 -28
- package/dist/commands/text-templates.d.ts +1 -0
- package/dist/commands/text-templates.js +84 -28
- package/dist/commands/tools.d.ts +1 -0
- package/dist/commands/tools.js +81 -25
- package/dist/commands/vat-declaration.d.ts +41 -0
- package/dist/commands/vat-declaration.js +1079 -0
- package/dist/commands/vendor-invoices.d.ts +1 -0
- package/dist/commands/vendor-invoices.js +113 -57
- package/dist/commands/webhooks.d.ts +1 -0
- package/dist/commands/webhooks.js +86 -30
- package/dist/commands/workflows.d.ts +1 -0
- package/dist/commands/workflows.js +82 -26
- package/dist/lib/api-client.d.ts +6 -1
- package/dist/lib/api-client.js +23 -5
- package/dist/lib/auth.js +18 -0
- package/dist/lib/config.js +1 -1
- package/oclif.manifest.json +229 -52
- package/package.json +15 -13
- package/dist/index 2.js +0 -1
- package/dist/index.d 2.ts +0 -1
|
@@ -8,16 +8,16 @@ const HAS_CAMT053 = false;
|
|
|
8
8
|
const NESTED_IMPORTS = ["prices"];
|
|
9
9
|
const SUBCOMMANDS = [...["list", "create", "get", "update", "delete", "list-prices", "create-prices", "get-prices", "update-prices", "delete-prices"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
|
|
10
10
|
const ENDPOINTS = {
|
|
11
|
-
'list': { method: 'GET', path: '/v1/price-lists', summary: 'Get all price lists with pagination', pathParams: [], hasBody: false, isMultipart: false },
|
|
12
|
-
'create': { method: 'POST', path: '/v1/price-lists', summary: 'Create a new price list', pathParams: [], hasBody: true, isMultipart: false },
|
|
13
|
-
'get': { method: 'GET', path: '/v1/price-lists/{id}', summary: 'Get a price list by ID', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
14
|
-
'update': { method: 'PATCH', path: '/v1/price-lists/{id}', summary: 'Update a price list', pathParams: ['id'], hasBody: true, isMultipart: false },
|
|
15
|
-
'delete': { method: 'DELETE', path: '/v1/price-lists/{id}', summary: 'Delete a price list', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
16
|
-
'list-prices': { method: 'GET', path: '/v1/price-lists/{id}/prices', summary: 'Get all prices in a price list with pagination', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
17
|
-
'create-prices': { method: 'POST', path: '/v1/price-lists/{id}/prices', summary: 'Create a new price in a price list', pathParams: ['id'], hasBody: true, isMultipart: false },
|
|
18
|
-
'get-prices': { method: 'GET', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Get a price by ID', pathParams: ['id', 'priceId'], hasBody: false, isMultipart: false },
|
|
19
|
-
'update-prices': { method: 'PATCH', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Update a price', pathParams: ['id', 'priceId'], hasBody: true, isMultipart: false },
|
|
20
|
-
'delete-prices': { method: 'DELETE', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Delete a price', pathParams: ['id', 'priceId'], hasBody: false, isMultipart: false },
|
|
11
|
+
'list': { method: 'GET', path: '/v1/price-lists', summary: 'Get all price lists with pagination', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
12
|
+
'create': { method: 'POST', path: '/v1/price-lists', summary: 'Create a new price list', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
13
|
+
'get': { method: 'GET', path: '/v1/price-lists/{id}', summary: 'Get a price list by ID', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
14
|
+
'update': { method: 'PATCH', path: '/v1/price-lists/{id}', summary: 'Update a price list', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
15
|
+
'delete': { method: 'DELETE', path: '/v1/price-lists/{id}', summary: 'Delete a price list', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
16
|
+
'list-prices': { method: 'GET', path: '/v1/price-lists/{id}/prices', summary: 'Get all prices in a price list with pagination', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
17
|
+
'create-prices': { method: 'POST', path: '/v1/price-lists/{id}/prices', summary: 'Create a new price in a price list', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
18
|
+
'get-prices': { method: 'GET', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Get a price by ID', pathParams: ['id', 'priceId'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
19
|
+
'update-prices': { method: 'PATCH', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Update a price', pathParams: ['id', 'priceId'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
20
|
+
'delete-prices': { method: 'DELETE', path: '/v1/price-lists/{id}/prices/{priceId}', summary: 'Delete a price', pathParams: ['id', 'priceId'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
21
21
|
};
|
|
22
22
|
export default class PriceLists extends Command {
|
|
23
23
|
static description = 'Manage price lists';
|
|
@@ -87,11 +87,6 @@ export default class PriceLists extends Command {
|
|
|
87
87
|
const endpoint = ENDPOINTS[args.action];
|
|
88
88
|
if (!endpoint)
|
|
89
89
|
this.error(`Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
90
|
-
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
91
|
-
if (!context)
|
|
92
|
-
this.error('No context configured. Run: aderis auth login --new');
|
|
93
|
-
if (!context.tokens)
|
|
94
|
-
this.error('Not logged in. Run: aderis auth login');
|
|
95
90
|
let apiPath = endpoint.path;
|
|
96
91
|
for (let i = 0; i < endpoint.pathParams.length; i++) {
|
|
97
92
|
const param = endpoint.pathParams[i];
|
|
@@ -110,6 +105,11 @@ export default class PriceLists extends Command {
|
|
|
110
105
|
}
|
|
111
106
|
apiPath = apiPath.replace(`{${param}}`, String(value));
|
|
112
107
|
}
|
|
108
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
109
|
+
if (!context)
|
|
110
|
+
this.error('No context configured. Run: aderis auth login --new');
|
|
111
|
+
if (!context.tokens)
|
|
112
|
+
this.error('Not logged in. Run: aderis auth login');
|
|
113
113
|
const queryParams = {};
|
|
114
114
|
if (flags.page)
|
|
115
115
|
queryParams.page = flags.page;
|
|
@@ -136,15 +136,7 @@ export default class PriceLists extends Command {
|
|
|
136
136
|
if (eqIndex === -1)
|
|
137
137
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
138
138
|
const key = f.slice(0, eqIndex);
|
|
139
|
-
|
|
140
|
-
// Check for operator prefix (with or without $)
|
|
141
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
142
|
-
if (opMatch) {
|
|
143
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
value = `\$eq:${value}`;
|
|
147
|
-
}
|
|
139
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
148
140
|
const filterKey = `filter.${key}`;
|
|
149
141
|
if (filterKey in queryParams) {
|
|
150
142
|
// Multiple filters on same field: collect as array
|
|
@@ -177,7 +169,9 @@ export default class PriceLists extends Command {
|
|
|
177
169
|
data = form;
|
|
178
170
|
}
|
|
179
171
|
else if (endpoint.hasBody) {
|
|
180
|
-
|
|
172
|
+
// For binary-response endpoints, --file is the output path, not a JSON
|
|
173
|
+
// input file — skip the read-as-body branch.
|
|
174
|
+
if (flags.file && !endpoint.isBinaryResponse) {
|
|
181
175
|
const fsModule = await import('node:fs');
|
|
182
176
|
try {
|
|
183
177
|
data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
@@ -199,6 +193,7 @@ export default class PriceLists extends Command {
|
|
|
199
193
|
if (!data)
|
|
200
194
|
data = {};
|
|
201
195
|
const body = data;
|
|
196
|
+
const arrayFields = new Set(endpoint.bodyArrayFields);
|
|
202
197
|
for (const pair of flags.set) {
|
|
203
198
|
const eqIndex = pair.indexOf('=');
|
|
204
199
|
if (eqIndex === -1)
|
|
@@ -210,6 +205,19 @@ export default class PriceLists extends Command {
|
|
|
210
205
|
value = JSON.parse(value);
|
|
211
206
|
}
|
|
212
207
|
catch { /* keep as string */ }
|
|
208
|
+
// For top-level keys typed as array in the API schema, split bare
|
|
209
|
+
// comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
|
|
210
|
+
// wrap a lone scalar in a single-element array. Skips when --set
|
|
211
|
+
// already provided a JSON array.
|
|
212
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
213
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
214
|
+
if (typeof value === 'string') {
|
|
215
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
216
|
+
}
|
|
217
|
+
else if (value !== undefined && value !== null) {
|
|
218
|
+
value = [value];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
213
221
|
// Support nested keys like "address.city"
|
|
214
222
|
const keys = key.split('.');
|
|
215
223
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
@@ -260,6 +268,26 @@ export default class PriceLists extends Command {
|
|
|
260
268
|
process.stderr.write('\n');
|
|
261
269
|
}
|
|
262
270
|
try {
|
|
271
|
+
// Binary response: download to file
|
|
272
|
+
if (endpoint.isBinaryResponse) {
|
|
273
|
+
if (!flags.file) {
|
|
274
|
+
this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
|
|
275
|
+
}
|
|
276
|
+
const binResponse = await apiRequest(endpoint.method, apiPath, {
|
|
277
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
278
|
+
data,
|
|
279
|
+
contextName: flags.context,
|
|
280
|
+
binary: true,
|
|
281
|
+
});
|
|
282
|
+
const fsModule = await import('node:fs');
|
|
283
|
+
const binData = binResponse.data;
|
|
284
|
+
const buffer = Buffer.isBuffer(binData)
|
|
285
|
+
? binData
|
|
286
|
+
: Buffer.from(binData);
|
|
287
|
+
fsModule.writeFileSync(flags.file, buffer);
|
|
288
|
+
this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
263
291
|
const response = await apiRequest(endpoint.method, apiPath, {
|
|
264
292
|
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
265
293
|
data,
|
|
@@ -350,6 +378,7 @@ export default class PriceLists extends Command {
|
|
|
350
378
|
}
|
|
351
379
|
else if (flags.set && flags.set.length > 0) {
|
|
352
380
|
const item = {};
|
|
381
|
+
const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
|
|
353
382
|
for (const pair of flags.set) {
|
|
354
383
|
const eqIndex = pair.indexOf('=');
|
|
355
384
|
if (eqIndex === -1)
|
|
@@ -360,6 +389,15 @@ export default class PriceLists extends Command {
|
|
|
360
389
|
value = JSON.parse(value);
|
|
361
390
|
}
|
|
362
391
|
catch { /* keep as string */ }
|
|
392
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
393
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
394
|
+
if (typeof value === 'string') {
|
|
395
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
396
|
+
}
|
|
397
|
+
else if (value !== undefined && value !== null) {
|
|
398
|
+
value = [value];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
363
401
|
const keys = key.split('.');
|
|
364
402
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
365
403
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -509,14 +547,7 @@ export default class PriceLists extends Command {
|
|
|
509
547
|
if (eqIndex === -1)
|
|
510
548
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
511
549
|
const key = f.slice(0, eqIndex);
|
|
512
|
-
|
|
513
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
514
|
-
if (opMatch) {
|
|
515
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
value = `\$eq:${value}`;
|
|
519
|
-
}
|
|
550
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
520
551
|
const filterKey = `filter.${key}`;
|
|
521
552
|
if (filterKey in baseParams) {
|
|
522
553
|
const existing = baseParams[filterKey];
|
|
@@ -693,6 +724,7 @@ export default class PriceLists extends Command {
|
|
|
693
724
|
}
|
|
694
725
|
else if (flags.set && flags.set.length > 0) {
|
|
695
726
|
const item = {};
|
|
727
|
+
const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
|
|
696
728
|
for (const pair of flags.set) {
|
|
697
729
|
const eqIndex = pair.indexOf('=');
|
|
698
730
|
if (eqIndex === -1)
|
|
@@ -703,6 +735,15 @@ export default class PriceLists extends Command {
|
|
|
703
735
|
value = JSON.parse(value);
|
|
704
736
|
}
|
|
705
737
|
catch { /* keep as string */ }
|
|
738
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
739
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
740
|
+
if (typeof value === 'string') {
|
|
741
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
742
|
+
}
|
|
743
|
+
else if (value !== undefined && value !== null) {
|
|
744
|
+
value = [value];
|
|
745
|
+
}
|
|
746
|
+
}
|
|
706
747
|
const keys = key.split('.');
|
|
707
748
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
708
749
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -822,6 +863,21 @@ export default class PriceLists extends Command {
|
|
|
822
863
|
this.log('');
|
|
823
864
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
824
865
|
}
|
|
866
|
+
parseFilterValue(value) {
|
|
867
|
+
// Recognises the nestjs-paginate operator set (with or without the leading $)
|
|
868
|
+
// and recursively unwraps chained operators like 'not:null' -> '$not:$null'
|
|
869
|
+
// or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
|
|
870
|
+
// no operator prefix is present.
|
|
871
|
+
const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
|
|
872
|
+
const m = value.match(opRe);
|
|
873
|
+
if (!m)
|
|
874
|
+
return `\$eq:${value}`;
|
|
875
|
+
const op = m[1];
|
|
876
|
+
const rest = value.slice(m[0].length);
|
|
877
|
+
if (rest === '')
|
|
878
|
+
return `\$${op}`;
|
|
879
|
+
return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
|
|
880
|
+
}
|
|
825
881
|
filterFields(data, fields) {
|
|
826
882
|
const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
|
|
827
883
|
const pick = (obj, keys) => {
|
|
@@ -8,10 +8,10 @@ const HAS_CAMT053 = false;
|
|
|
8
8
|
const NESTED_IMPORTS = [];
|
|
9
9
|
const SUBCOMMANDS = [...["list", "create", "update", "delete"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
|
|
10
10
|
const ENDPOINTS = {
|
|
11
|
-
'list': { method: 'GET', path: '/v1/processor-mappings', summary: 'List all document type processor mappings for the tenant', pathParams: [], hasBody: false, isMultipart: false },
|
|
12
|
-
'create': { method: 'POST', path: '/v1/processor-mappings', summary: 'Create a new document type processor mapping', pathParams: [], hasBody: true, isMultipart: false },
|
|
13
|
-
'update': { method: 'PATCH', path: '/v1/processor-mappings/{id}', summary: 'Update a document type processor mapping', pathParams: ['id'], hasBody: true, isMultipart: false },
|
|
14
|
-
'delete': { method: 'DELETE', path: '/v1/processor-mappings/{id}', summary: 'Delete a document type processor mapping', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
11
|
+
'list': { method: 'GET', path: '/v1/processor-mappings', summary: 'List all document type processor mappings for the tenant', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
12
|
+
'create': { method: 'POST', path: '/v1/processor-mappings', summary: 'Create a new document type processor mapping', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: ['documentTypes'] },
|
|
13
|
+
'update': { method: 'PATCH', path: '/v1/processor-mappings/{id}', summary: 'Update a document type processor mapping', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: ['documentTypes'] },
|
|
14
|
+
'delete': { method: 'DELETE', path: '/v1/processor-mappings/{id}', summary: 'Delete a document type processor mapping', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
15
15
|
};
|
|
16
16
|
export default class ProcessorMappings extends Command {
|
|
17
17
|
static description = 'Manage processor mappings';
|
|
@@ -79,11 +79,6 @@ export default class ProcessorMappings extends Command {
|
|
|
79
79
|
const endpoint = ENDPOINTS[args.action];
|
|
80
80
|
if (!endpoint)
|
|
81
81
|
this.error(`Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
82
|
-
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
83
|
-
if (!context)
|
|
84
|
-
this.error('No context configured. Run: aderis auth login --new');
|
|
85
|
-
if (!context.tokens)
|
|
86
|
-
this.error('Not logged in. Run: aderis auth login');
|
|
87
82
|
let apiPath = endpoint.path;
|
|
88
83
|
for (let i = 0; i < endpoint.pathParams.length; i++) {
|
|
89
84
|
const param = endpoint.pathParams[i];
|
|
@@ -102,6 +97,11 @@ export default class ProcessorMappings extends Command {
|
|
|
102
97
|
}
|
|
103
98
|
apiPath = apiPath.replace(`{${param}}`, String(value));
|
|
104
99
|
}
|
|
100
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
101
|
+
if (!context)
|
|
102
|
+
this.error('No context configured. Run: aderis auth login --new');
|
|
103
|
+
if (!context.tokens)
|
|
104
|
+
this.error('Not logged in. Run: aderis auth login');
|
|
105
105
|
const queryParams = {};
|
|
106
106
|
if (flags.page)
|
|
107
107
|
queryParams.page = flags.page;
|
|
@@ -128,15 +128,7 @@ export default class ProcessorMappings extends Command {
|
|
|
128
128
|
if (eqIndex === -1)
|
|
129
129
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
130
130
|
const key = f.slice(0, eqIndex);
|
|
131
|
-
|
|
132
|
-
// Check for operator prefix (with or without $)
|
|
133
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
134
|
-
if (opMatch) {
|
|
135
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
value = `\$eq:${value}`;
|
|
139
|
-
}
|
|
131
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
140
132
|
const filterKey = `filter.${key}`;
|
|
141
133
|
if (filterKey in queryParams) {
|
|
142
134
|
// Multiple filters on same field: collect as array
|
|
@@ -169,7 +161,9 @@ export default class ProcessorMappings extends Command {
|
|
|
169
161
|
data = form;
|
|
170
162
|
}
|
|
171
163
|
else if (endpoint.hasBody) {
|
|
172
|
-
|
|
164
|
+
// For binary-response endpoints, --file is the output path, not a JSON
|
|
165
|
+
// input file — skip the read-as-body branch.
|
|
166
|
+
if (flags.file && !endpoint.isBinaryResponse) {
|
|
173
167
|
const fsModule = await import('node:fs');
|
|
174
168
|
try {
|
|
175
169
|
data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
@@ -191,6 +185,7 @@ export default class ProcessorMappings extends Command {
|
|
|
191
185
|
if (!data)
|
|
192
186
|
data = {};
|
|
193
187
|
const body = data;
|
|
188
|
+
const arrayFields = new Set(endpoint.bodyArrayFields);
|
|
194
189
|
for (const pair of flags.set) {
|
|
195
190
|
const eqIndex = pair.indexOf('=');
|
|
196
191
|
if (eqIndex === -1)
|
|
@@ -202,6 +197,19 @@ export default class ProcessorMappings extends Command {
|
|
|
202
197
|
value = JSON.parse(value);
|
|
203
198
|
}
|
|
204
199
|
catch { /* keep as string */ }
|
|
200
|
+
// For top-level keys typed as array in the API schema, split bare
|
|
201
|
+
// comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
|
|
202
|
+
// wrap a lone scalar in a single-element array. Skips when --set
|
|
203
|
+
// already provided a JSON array.
|
|
204
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
205
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
206
|
+
if (typeof value === 'string') {
|
|
207
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
208
|
+
}
|
|
209
|
+
else if (value !== undefined && value !== null) {
|
|
210
|
+
value = [value];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
205
213
|
// Support nested keys like "address.city"
|
|
206
214
|
const keys = key.split('.');
|
|
207
215
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
@@ -252,6 +260,26 @@ export default class ProcessorMappings extends Command {
|
|
|
252
260
|
process.stderr.write('\n');
|
|
253
261
|
}
|
|
254
262
|
try {
|
|
263
|
+
// Binary response: download to file
|
|
264
|
+
if (endpoint.isBinaryResponse) {
|
|
265
|
+
if (!flags.file) {
|
|
266
|
+
this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
|
|
267
|
+
}
|
|
268
|
+
const binResponse = await apiRequest(endpoint.method, apiPath, {
|
|
269
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
270
|
+
data,
|
|
271
|
+
contextName: flags.context,
|
|
272
|
+
binary: true,
|
|
273
|
+
});
|
|
274
|
+
const fsModule = await import('node:fs');
|
|
275
|
+
const binData = binResponse.data;
|
|
276
|
+
const buffer = Buffer.isBuffer(binData)
|
|
277
|
+
? binData
|
|
278
|
+
: Buffer.from(binData);
|
|
279
|
+
fsModule.writeFileSync(flags.file, buffer);
|
|
280
|
+
this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
255
283
|
const response = await apiRequest(endpoint.method, apiPath, {
|
|
256
284
|
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
257
285
|
data,
|
|
@@ -342,6 +370,7 @@ export default class ProcessorMappings extends Command {
|
|
|
342
370
|
}
|
|
343
371
|
else if (flags.set && flags.set.length > 0) {
|
|
344
372
|
const item = {};
|
|
373
|
+
const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
|
|
345
374
|
for (const pair of flags.set) {
|
|
346
375
|
const eqIndex = pair.indexOf('=');
|
|
347
376
|
if (eqIndex === -1)
|
|
@@ -352,6 +381,15 @@ export default class ProcessorMappings extends Command {
|
|
|
352
381
|
value = JSON.parse(value);
|
|
353
382
|
}
|
|
354
383
|
catch { /* keep as string */ }
|
|
384
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
385
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
386
|
+
if (typeof value === 'string') {
|
|
387
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
388
|
+
}
|
|
389
|
+
else if (value !== undefined && value !== null) {
|
|
390
|
+
value = [value];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
355
393
|
const keys = key.split('.');
|
|
356
394
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
357
395
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -501,14 +539,7 @@ export default class ProcessorMappings extends Command {
|
|
|
501
539
|
if (eqIndex === -1)
|
|
502
540
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
503
541
|
const key = f.slice(0, eqIndex);
|
|
504
|
-
|
|
505
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
506
|
-
if (opMatch) {
|
|
507
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
value = `\$eq:${value}`;
|
|
511
|
-
}
|
|
542
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
512
543
|
const filterKey = `filter.${key}`;
|
|
513
544
|
if (filterKey in baseParams) {
|
|
514
545
|
const existing = baseParams[filterKey];
|
|
@@ -685,6 +716,7 @@ export default class ProcessorMappings extends Command {
|
|
|
685
716
|
}
|
|
686
717
|
else if (flags.set && flags.set.length > 0) {
|
|
687
718
|
const item = {};
|
|
719
|
+
const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
|
|
688
720
|
for (const pair of flags.set) {
|
|
689
721
|
const eqIndex = pair.indexOf('=');
|
|
690
722
|
if (eqIndex === -1)
|
|
@@ -695,6 +727,15 @@ export default class ProcessorMappings extends Command {
|
|
|
695
727
|
value = JSON.parse(value);
|
|
696
728
|
}
|
|
697
729
|
catch { /* keep as string */ }
|
|
730
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
731
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
732
|
+
if (typeof value === 'string') {
|
|
733
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
734
|
+
}
|
|
735
|
+
else if (value !== undefined && value !== null) {
|
|
736
|
+
value = [value];
|
|
737
|
+
}
|
|
738
|
+
}
|
|
698
739
|
const keys = key.split('.');
|
|
699
740
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
700
741
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -814,6 +855,21 @@ export default class ProcessorMappings extends Command {
|
|
|
814
855
|
this.log('');
|
|
815
856
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
816
857
|
}
|
|
858
|
+
parseFilterValue(value) {
|
|
859
|
+
// Recognises the nestjs-paginate operator set (with or without the leading $)
|
|
860
|
+
// and recursively unwraps chained operators like 'not:null' -> '$not:$null'
|
|
861
|
+
// or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
|
|
862
|
+
// no operator prefix is present.
|
|
863
|
+
const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
|
|
864
|
+
const m = value.match(opRe);
|
|
865
|
+
if (!m)
|
|
866
|
+
return `\$eq:${value}`;
|
|
867
|
+
const op = m[1];
|
|
868
|
+
const rest = value.slice(m[0].length);
|
|
869
|
+
if (rest === '')
|
|
870
|
+
return `\$${op}`;
|
|
871
|
+
return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
|
|
872
|
+
}
|
|
817
873
|
filterFields(data, fields) {
|
|
818
874
|
const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
|
|
819
875
|
const pick = (obj, keys) => {
|