@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,11 +8,11 @@ const HAS_CAMT053 = false;
|
|
|
8
8
|
const NESTED_IMPORTS = [];
|
|
9
9
|
const SUBCOMMANDS = [...["list", "create", "get", "update", "delete"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
|
|
10
10
|
const ENDPOINTS = {
|
|
11
|
-
'list': { method: 'GET', path: '/v1/dunning-configs', summary: 'List all dunning run configs', pathParams: [], hasBody: false, isMultipart: false },
|
|
12
|
-
'create': { method: 'POST', path: '/v1/dunning-configs', summary: 'Create a new dunning run config', pathParams: [], hasBody: true, isMultipart: false },
|
|
13
|
-
'get': { method: 'GET', path: '/v1/dunning-configs/{id}', summary: 'Get a dunning run config by ID', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
14
|
-
'update': { method: 'PATCH', path: '/v1/dunning-configs/{id}', summary: 'Update a dunning run config', pathParams: ['id'], hasBody: true, isMultipart: false },
|
|
15
|
-
'delete': { method: 'DELETE', path: '/v1/dunning-configs/{id}', summary: 'Delete a dunning run config', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
11
|
+
'list': { method: 'GET', path: '/v1/dunning-configs', summary: 'List all dunning run configs', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
12
|
+
'create': { method: 'POST', path: '/v1/dunning-configs', summary: 'Create a new dunning run config', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
13
|
+
'get': { method: 'GET', path: '/v1/dunning-configs/{id}', summary: 'Get a dunning run config by ID', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
14
|
+
'update': { method: 'PATCH', path: '/v1/dunning-configs/{id}', summary: 'Update a dunning run config', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
15
|
+
'delete': { method: 'DELETE', path: '/v1/dunning-configs/{id}', summary: 'Delete a dunning run config', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
16
16
|
};
|
|
17
17
|
export default class DunningConfigs extends Command {
|
|
18
18
|
static description = 'Manage dunning configs';
|
|
@@ -81,11 +81,6 @@ export default class DunningConfigs extends Command {
|
|
|
81
81
|
const endpoint = ENDPOINTS[args.action];
|
|
82
82
|
if (!endpoint)
|
|
83
83
|
this.error(`Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
84
|
-
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
85
|
-
if (!context)
|
|
86
|
-
this.error('No context configured. Run: aderis auth login --new');
|
|
87
|
-
if (!context.tokens)
|
|
88
|
-
this.error('Not logged in. Run: aderis auth login');
|
|
89
84
|
let apiPath = endpoint.path;
|
|
90
85
|
for (let i = 0; i < endpoint.pathParams.length; i++) {
|
|
91
86
|
const param = endpoint.pathParams[i];
|
|
@@ -104,6 +99,11 @@ export default class DunningConfigs extends Command {
|
|
|
104
99
|
}
|
|
105
100
|
apiPath = apiPath.replace(`{${param}}`, String(value));
|
|
106
101
|
}
|
|
102
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
103
|
+
if (!context)
|
|
104
|
+
this.error('No context configured. Run: aderis auth login --new');
|
|
105
|
+
if (!context.tokens)
|
|
106
|
+
this.error('Not logged in. Run: aderis auth login');
|
|
107
107
|
const queryParams = {};
|
|
108
108
|
if (flags.page)
|
|
109
109
|
queryParams.page = flags.page;
|
|
@@ -130,15 +130,7 @@ export default class DunningConfigs extends Command {
|
|
|
130
130
|
if (eqIndex === -1)
|
|
131
131
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
132
132
|
const key = f.slice(0, eqIndex);
|
|
133
|
-
|
|
134
|
-
// Check for operator prefix (with or without $)
|
|
135
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
136
|
-
if (opMatch) {
|
|
137
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
value = `\$eq:${value}`;
|
|
141
|
-
}
|
|
133
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
142
134
|
const filterKey = `filter.${key}`;
|
|
143
135
|
if (filterKey in queryParams) {
|
|
144
136
|
// Multiple filters on same field: collect as array
|
|
@@ -171,7 +163,9 @@ export default class DunningConfigs extends Command {
|
|
|
171
163
|
data = form;
|
|
172
164
|
}
|
|
173
165
|
else if (endpoint.hasBody) {
|
|
174
|
-
|
|
166
|
+
// For binary-response endpoints, --file is the output path, not a JSON
|
|
167
|
+
// input file — skip the read-as-body branch.
|
|
168
|
+
if (flags.file && !endpoint.isBinaryResponse) {
|
|
175
169
|
const fsModule = await import('node:fs');
|
|
176
170
|
try {
|
|
177
171
|
data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
@@ -193,6 +187,7 @@ export default class DunningConfigs extends Command {
|
|
|
193
187
|
if (!data)
|
|
194
188
|
data = {};
|
|
195
189
|
const body = data;
|
|
190
|
+
const arrayFields = new Set(endpoint.bodyArrayFields);
|
|
196
191
|
for (const pair of flags.set) {
|
|
197
192
|
const eqIndex = pair.indexOf('=');
|
|
198
193
|
if (eqIndex === -1)
|
|
@@ -204,6 +199,19 @@ export default class DunningConfigs extends Command {
|
|
|
204
199
|
value = JSON.parse(value);
|
|
205
200
|
}
|
|
206
201
|
catch { /* keep as string */ }
|
|
202
|
+
// For top-level keys typed as array in the API schema, split bare
|
|
203
|
+
// comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
|
|
204
|
+
// wrap a lone scalar in a single-element array. Skips when --set
|
|
205
|
+
// already provided a JSON array.
|
|
206
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
207
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
208
|
+
if (typeof value === 'string') {
|
|
209
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
210
|
+
}
|
|
211
|
+
else if (value !== undefined && value !== null) {
|
|
212
|
+
value = [value];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
207
215
|
// Support nested keys like "address.city"
|
|
208
216
|
const keys = key.split('.');
|
|
209
217
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
@@ -254,6 +262,26 @@ export default class DunningConfigs extends Command {
|
|
|
254
262
|
process.stderr.write('\n');
|
|
255
263
|
}
|
|
256
264
|
try {
|
|
265
|
+
// Binary response: download to file
|
|
266
|
+
if (endpoint.isBinaryResponse) {
|
|
267
|
+
if (!flags.file) {
|
|
268
|
+
this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
|
|
269
|
+
}
|
|
270
|
+
const binResponse = await apiRequest(endpoint.method, apiPath, {
|
|
271
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
272
|
+
data,
|
|
273
|
+
contextName: flags.context,
|
|
274
|
+
binary: true,
|
|
275
|
+
});
|
|
276
|
+
const fsModule = await import('node:fs');
|
|
277
|
+
const binData = binResponse.data;
|
|
278
|
+
const buffer = Buffer.isBuffer(binData)
|
|
279
|
+
? binData
|
|
280
|
+
: Buffer.from(binData);
|
|
281
|
+
fsModule.writeFileSync(flags.file, buffer);
|
|
282
|
+
this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
257
285
|
const response = await apiRequest(endpoint.method, apiPath, {
|
|
258
286
|
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
259
287
|
data,
|
|
@@ -344,6 +372,7 @@ export default class DunningConfigs extends Command {
|
|
|
344
372
|
}
|
|
345
373
|
else if (flags.set && flags.set.length > 0) {
|
|
346
374
|
const item = {};
|
|
375
|
+
const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
|
|
347
376
|
for (const pair of flags.set) {
|
|
348
377
|
const eqIndex = pair.indexOf('=');
|
|
349
378
|
if (eqIndex === -1)
|
|
@@ -354,6 +383,15 @@ export default class DunningConfigs extends Command {
|
|
|
354
383
|
value = JSON.parse(value);
|
|
355
384
|
}
|
|
356
385
|
catch { /* keep as string */ }
|
|
386
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
387
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
388
|
+
if (typeof value === 'string') {
|
|
389
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
390
|
+
}
|
|
391
|
+
else if (value !== undefined && value !== null) {
|
|
392
|
+
value = [value];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
357
395
|
const keys = key.split('.');
|
|
358
396
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
359
397
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -503,14 +541,7 @@ export default class DunningConfigs extends Command {
|
|
|
503
541
|
if (eqIndex === -1)
|
|
504
542
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
505
543
|
const key = f.slice(0, eqIndex);
|
|
506
|
-
|
|
507
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
508
|
-
if (opMatch) {
|
|
509
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
value = `\$eq:${value}`;
|
|
513
|
-
}
|
|
544
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
514
545
|
const filterKey = `filter.${key}`;
|
|
515
546
|
if (filterKey in baseParams) {
|
|
516
547
|
const existing = baseParams[filterKey];
|
|
@@ -687,6 +718,7 @@ export default class DunningConfigs extends Command {
|
|
|
687
718
|
}
|
|
688
719
|
else if (flags.set && flags.set.length > 0) {
|
|
689
720
|
const item = {};
|
|
721
|
+
const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
|
|
690
722
|
for (const pair of flags.set) {
|
|
691
723
|
const eqIndex = pair.indexOf('=');
|
|
692
724
|
if (eqIndex === -1)
|
|
@@ -697,6 +729,15 @@ export default class DunningConfigs extends Command {
|
|
|
697
729
|
value = JSON.parse(value);
|
|
698
730
|
}
|
|
699
731
|
catch { /* keep as string */ }
|
|
732
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
733
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
734
|
+
if (typeof value === 'string') {
|
|
735
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
736
|
+
}
|
|
737
|
+
else if (value !== undefined && value !== null) {
|
|
738
|
+
value = [value];
|
|
739
|
+
}
|
|
740
|
+
}
|
|
700
741
|
const keys = key.split('.');
|
|
701
742
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
702
743
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -816,6 +857,21 @@ export default class DunningConfigs extends Command {
|
|
|
816
857
|
this.log('');
|
|
817
858
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
818
859
|
}
|
|
860
|
+
parseFilterValue(value) {
|
|
861
|
+
// Recognises the nestjs-paginate operator set (with or without the leading $)
|
|
862
|
+
// and recursively unwraps chained operators like 'not:null' -> '$not:$null'
|
|
863
|
+
// or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
|
|
864
|
+
// no operator prefix is present.
|
|
865
|
+
const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
|
|
866
|
+
const m = value.match(opRe);
|
|
867
|
+
if (!m)
|
|
868
|
+
return `\$eq:${value}`;
|
|
869
|
+
const op = m[1];
|
|
870
|
+
const rest = value.slice(m[0].length);
|
|
871
|
+
if (rest === '')
|
|
872
|
+
return `\$${op}`;
|
|
873
|
+
return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
|
|
874
|
+
}
|
|
819
875
|
filterFields(data, fields) {
|
|
820
876
|
const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
|
|
821
877
|
const pick = (obj, keys) => {
|
|
@@ -8,14 +8,14 @@ const HAS_CAMT053 = false;
|
|
|
8
8
|
const NESTED_IMPORTS = [];
|
|
9
9
|
const SUBCOMMANDS = [...["pending", "ongoing", "cancelled", "get", "update", "list", "approve", "cancel"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
|
|
10
10
|
const ENDPOINTS = {
|
|
11
|
-
'pending': { method: 'GET', path: '/v1/dunning-reminders/pending', summary: 'Get pending reminders (awaiting approval) with pagination', pathParams: [], hasBody: false, isMultipart: false },
|
|
12
|
-
'ongoing': { method: 'GET', path: '/v1/dunning-reminders/ongoing', summary: 'Get ongoing reminders (pending, sent, or failed) with pagination', pathParams: [], hasBody: false, isMultipart: false },
|
|
13
|
-
'cancelled': { method: 'GET', path: '/v1/dunning-reminders/cancelled', summary: 'Get cancelled reminders with pagination', pathParams: [], hasBody: false, isMultipart: false },
|
|
14
|
-
'get': { method: 'GET', path: '/v1/dunning-reminders/{id}', summary: 'Get a single dunning reminder by ID', pathParams: ['id'], hasBody: false, isMultipart: false },
|
|
15
|
-
'update': { method: 'PATCH', path: '/v1/dunning-reminders/{id}', summary: 'Update recipient or action on a dunning reminder', pathParams: ['id'], hasBody: true, isMultipart: false },
|
|
16
|
-
'list': { method: 'GET', path: '/v1/dunning-reminders', summary: 'Get all dunning reminders with pagination', pathParams: [], hasBody: false, isMultipart: false },
|
|
17
|
-
'approve': { method: 'POST', path: '/v1/dunning-reminders/{reminderId}/approve', summary: 'Approve a dunning reminder for sending', pathParams: ['reminderId'], hasBody: true, isMultipart: false },
|
|
18
|
-
'cancel': { method: 'POST', path: '/v1/dunning-reminders/{reminderId}/cancel', summary: 'Cancel a dunning reminder', pathParams: ['reminderId'], hasBody: true, isMultipart: false },
|
|
11
|
+
'pending': { method: 'GET', path: '/v1/dunning-reminders/pending', summary: 'Get pending reminders (awaiting approval) with pagination', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
12
|
+
'ongoing': { method: 'GET', path: '/v1/dunning-reminders/ongoing', summary: 'Get ongoing reminders (pending, sent, or failed) with pagination', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
13
|
+
'cancelled': { method: 'GET', path: '/v1/dunning-reminders/cancelled', summary: 'Get cancelled reminders with pagination', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
14
|
+
'get': { method: 'GET', path: '/v1/dunning-reminders/{id}', summary: 'Get a single dunning reminder by ID', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
15
|
+
'update': { method: 'PATCH', path: '/v1/dunning-reminders/{id}', summary: 'Update recipient or action on a dunning reminder', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
16
|
+
'list': { method: 'GET', path: '/v1/dunning-reminders', summary: 'Get all dunning reminders with pagination', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
17
|
+
'approve': { method: 'POST', path: '/v1/dunning-reminders/{reminderId}/approve', summary: 'Approve a dunning reminder for sending', pathParams: ['reminderId'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
18
|
+
'cancel': { method: 'POST', path: '/v1/dunning-reminders/{reminderId}/cancel', summary: 'Cancel a dunning reminder', pathParams: ['reminderId'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
19
19
|
};
|
|
20
20
|
export default class DunningReminders extends Command {
|
|
21
21
|
static description = 'Manage dunning reminders';
|
|
@@ -82,11 +82,6 @@ export default class DunningReminders extends Command {
|
|
|
82
82
|
const endpoint = ENDPOINTS[args.action];
|
|
83
83
|
if (!endpoint)
|
|
84
84
|
this.error(`Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
85
|
-
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
86
|
-
if (!context)
|
|
87
|
-
this.error('No context configured. Run: aderis auth login --new');
|
|
88
|
-
if (!context.tokens)
|
|
89
|
-
this.error('Not logged in. Run: aderis auth login');
|
|
90
85
|
let apiPath = endpoint.path;
|
|
91
86
|
for (let i = 0; i < endpoint.pathParams.length; i++) {
|
|
92
87
|
const param = endpoint.pathParams[i];
|
|
@@ -105,6 +100,11 @@ export default class DunningReminders extends Command {
|
|
|
105
100
|
}
|
|
106
101
|
apiPath = apiPath.replace(`{${param}}`, String(value));
|
|
107
102
|
}
|
|
103
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
104
|
+
if (!context)
|
|
105
|
+
this.error('No context configured. Run: aderis auth login --new');
|
|
106
|
+
if (!context.tokens)
|
|
107
|
+
this.error('Not logged in. Run: aderis auth login');
|
|
108
108
|
const queryParams = {};
|
|
109
109
|
if (flags.page)
|
|
110
110
|
queryParams.page = flags.page;
|
|
@@ -131,15 +131,7 @@ export default class DunningReminders extends Command {
|
|
|
131
131
|
if (eqIndex === -1)
|
|
132
132
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
133
133
|
const key = f.slice(0, eqIndex);
|
|
134
|
-
|
|
135
|
-
// Check for operator prefix (with or without $)
|
|
136
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
137
|
-
if (opMatch) {
|
|
138
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
value = `\$eq:${value}`;
|
|
142
|
-
}
|
|
134
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
143
135
|
const filterKey = `filter.${key}`;
|
|
144
136
|
if (filterKey in queryParams) {
|
|
145
137
|
// Multiple filters on same field: collect as array
|
|
@@ -172,7 +164,9 @@ export default class DunningReminders extends Command {
|
|
|
172
164
|
data = form;
|
|
173
165
|
}
|
|
174
166
|
else if (endpoint.hasBody) {
|
|
175
|
-
|
|
167
|
+
// For binary-response endpoints, --file is the output path, not a JSON
|
|
168
|
+
// input file — skip the read-as-body branch.
|
|
169
|
+
if (flags.file && !endpoint.isBinaryResponse) {
|
|
176
170
|
const fsModule = await import('node:fs');
|
|
177
171
|
try {
|
|
178
172
|
data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
@@ -194,6 +188,7 @@ export default class DunningReminders extends Command {
|
|
|
194
188
|
if (!data)
|
|
195
189
|
data = {};
|
|
196
190
|
const body = data;
|
|
191
|
+
const arrayFields = new Set(endpoint.bodyArrayFields);
|
|
197
192
|
for (const pair of flags.set) {
|
|
198
193
|
const eqIndex = pair.indexOf('=');
|
|
199
194
|
if (eqIndex === -1)
|
|
@@ -205,6 +200,19 @@ export default class DunningReminders extends Command {
|
|
|
205
200
|
value = JSON.parse(value);
|
|
206
201
|
}
|
|
207
202
|
catch { /* keep as string */ }
|
|
203
|
+
// For top-level keys typed as array in the API schema, split bare
|
|
204
|
+
// comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
|
|
205
|
+
// wrap a lone scalar in a single-element array. Skips when --set
|
|
206
|
+
// already provided a JSON array.
|
|
207
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
208
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
209
|
+
if (typeof value === 'string') {
|
|
210
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
211
|
+
}
|
|
212
|
+
else if (value !== undefined && value !== null) {
|
|
213
|
+
value = [value];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
208
216
|
// Support nested keys like "address.city"
|
|
209
217
|
const keys = key.split('.');
|
|
210
218
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
@@ -255,6 +263,26 @@ export default class DunningReminders extends Command {
|
|
|
255
263
|
process.stderr.write('\n');
|
|
256
264
|
}
|
|
257
265
|
try {
|
|
266
|
+
// Binary response: download to file
|
|
267
|
+
if (endpoint.isBinaryResponse) {
|
|
268
|
+
if (!flags.file) {
|
|
269
|
+
this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
|
|
270
|
+
}
|
|
271
|
+
const binResponse = await apiRequest(endpoint.method, apiPath, {
|
|
272
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
273
|
+
data,
|
|
274
|
+
contextName: flags.context,
|
|
275
|
+
binary: true,
|
|
276
|
+
});
|
|
277
|
+
const fsModule = await import('node:fs');
|
|
278
|
+
const binData = binResponse.data;
|
|
279
|
+
const buffer = Buffer.isBuffer(binData)
|
|
280
|
+
? binData
|
|
281
|
+
: Buffer.from(binData);
|
|
282
|
+
fsModule.writeFileSync(flags.file, buffer);
|
|
283
|
+
this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
258
286
|
const response = await apiRequest(endpoint.method, apiPath, {
|
|
259
287
|
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
260
288
|
data,
|
|
@@ -345,6 +373,7 @@ export default class DunningReminders extends Command {
|
|
|
345
373
|
}
|
|
346
374
|
else if (flags.set && flags.set.length > 0) {
|
|
347
375
|
const item = {};
|
|
376
|
+
const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
|
|
348
377
|
for (const pair of flags.set) {
|
|
349
378
|
const eqIndex = pair.indexOf('=');
|
|
350
379
|
if (eqIndex === -1)
|
|
@@ -355,6 +384,15 @@ export default class DunningReminders extends Command {
|
|
|
355
384
|
value = JSON.parse(value);
|
|
356
385
|
}
|
|
357
386
|
catch { /* keep as string */ }
|
|
387
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
388
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
389
|
+
if (typeof value === 'string') {
|
|
390
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
391
|
+
}
|
|
392
|
+
else if (value !== undefined && value !== null) {
|
|
393
|
+
value = [value];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
358
396
|
const keys = key.split('.');
|
|
359
397
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
360
398
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -504,14 +542,7 @@ export default class DunningReminders extends Command {
|
|
|
504
542
|
if (eqIndex === -1)
|
|
505
543
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
506
544
|
const key = f.slice(0, eqIndex);
|
|
507
|
-
|
|
508
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
509
|
-
if (opMatch) {
|
|
510
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
value = `\$eq:${value}`;
|
|
514
|
-
}
|
|
545
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
515
546
|
const filterKey = `filter.${key}`;
|
|
516
547
|
if (filterKey in baseParams) {
|
|
517
548
|
const existing = baseParams[filterKey];
|
|
@@ -688,6 +719,7 @@ export default class DunningReminders extends Command {
|
|
|
688
719
|
}
|
|
689
720
|
else if (flags.set && flags.set.length > 0) {
|
|
690
721
|
const item = {};
|
|
722
|
+
const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
|
|
691
723
|
for (const pair of flags.set) {
|
|
692
724
|
const eqIndex = pair.indexOf('=');
|
|
693
725
|
if (eqIndex === -1)
|
|
@@ -698,6 +730,15 @@ export default class DunningReminders extends Command {
|
|
|
698
730
|
value = JSON.parse(value);
|
|
699
731
|
}
|
|
700
732
|
catch { /* keep as string */ }
|
|
733
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
734
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
735
|
+
if (typeof value === 'string') {
|
|
736
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
737
|
+
}
|
|
738
|
+
else if (value !== undefined && value !== null) {
|
|
739
|
+
value = [value];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
701
742
|
const keys = key.split('.');
|
|
702
743
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
703
744
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -817,6 +858,21 @@ export default class DunningReminders extends Command {
|
|
|
817
858
|
this.log('');
|
|
818
859
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
819
860
|
}
|
|
861
|
+
parseFilterValue(value) {
|
|
862
|
+
// Recognises the nestjs-paginate operator set (with or without the leading $)
|
|
863
|
+
// and recursively unwraps chained operators like 'not:null' -> '$not:$null'
|
|
864
|
+
// or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
|
|
865
|
+
// no operator prefix is present.
|
|
866
|
+
const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
|
|
867
|
+
const m = value.match(opRe);
|
|
868
|
+
if (!m)
|
|
869
|
+
return `\$eq:${value}`;
|
|
870
|
+
const op = m[1];
|
|
871
|
+
const rest = value.slice(m[0].length);
|
|
872
|
+
if (rest === '')
|
|
873
|
+
return `\$${op}`;
|
|
874
|
+
return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
|
|
875
|
+
}
|
|
820
876
|
filterFields(data, fields) {
|
|
821
877
|
const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
|
|
822
878
|
const pick = (obj, keys) => {
|
|
@@ -8,7 +8,7 @@ const HAS_CAMT053 = false;
|
|
|
8
8
|
const NESTED_IMPORTS = [];
|
|
9
9
|
const SUBCOMMANDS = [...["trigger"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
|
|
10
10
|
const ENDPOINTS = {
|
|
11
|
-
'trigger': { method: 'POST', path: '/v1/dunning-runs/trigger', summary: 'Manually trigger a dunning run', pathParams: [], hasBody: true, isMultipart: false },
|
|
11
|
+
'trigger': { method: 'POST', path: '/v1/dunning-runs/trigger', summary: 'Manually trigger a dunning run', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
|
|
12
12
|
};
|
|
13
13
|
export default class DunningRuns extends Command {
|
|
14
14
|
static description = 'Manage dunning runs';
|
|
@@ -70,11 +70,6 @@ export default class DunningRuns extends Command {
|
|
|
70
70
|
const endpoint = ENDPOINTS[args.action];
|
|
71
71
|
if (!endpoint)
|
|
72
72
|
this.error(`Unknown action: ${args.action}. Available: ${SUBCOMMANDS.join(', ')}`);
|
|
73
|
-
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
74
|
-
if (!context)
|
|
75
|
-
this.error('No context configured. Run: aderis auth login --new');
|
|
76
|
-
if (!context.tokens)
|
|
77
|
-
this.error('Not logged in. Run: aderis auth login');
|
|
78
73
|
let apiPath = endpoint.path;
|
|
79
74
|
for (let i = 0; i < endpoint.pathParams.length; i++) {
|
|
80
75
|
const param = endpoint.pathParams[i];
|
|
@@ -93,6 +88,11 @@ export default class DunningRuns extends Command {
|
|
|
93
88
|
}
|
|
94
89
|
apiPath = apiPath.replace(`{${param}}`, String(value));
|
|
95
90
|
}
|
|
91
|
+
const context = flags.context ? getContext(flags.context) : getCurrentContext();
|
|
92
|
+
if (!context)
|
|
93
|
+
this.error('No context configured. Run: aderis auth login --new');
|
|
94
|
+
if (!context.tokens)
|
|
95
|
+
this.error('Not logged in. Run: aderis auth login');
|
|
96
96
|
const queryParams = {};
|
|
97
97
|
if (flags.page)
|
|
98
98
|
queryParams.page = flags.page;
|
|
@@ -119,15 +119,7 @@ export default class DunningRuns extends Command {
|
|
|
119
119
|
if (eqIndex === -1)
|
|
120
120
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
121
121
|
const key = f.slice(0, eqIndex);
|
|
122
|
-
|
|
123
|
-
// Check for operator prefix (with or without $)
|
|
124
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
125
|
-
if (opMatch) {
|
|
126
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
value = `\$eq:${value}`;
|
|
130
|
-
}
|
|
122
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
131
123
|
const filterKey = `filter.${key}`;
|
|
132
124
|
if (filterKey in queryParams) {
|
|
133
125
|
// Multiple filters on same field: collect as array
|
|
@@ -160,7 +152,9 @@ export default class DunningRuns extends Command {
|
|
|
160
152
|
data = form;
|
|
161
153
|
}
|
|
162
154
|
else if (endpoint.hasBody) {
|
|
163
|
-
|
|
155
|
+
// For binary-response endpoints, --file is the output path, not a JSON
|
|
156
|
+
// input file — skip the read-as-body branch.
|
|
157
|
+
if (flags.file && !endpoint.isBinaryResponse) {
|
|
164
158
|
const fsModule = await import('node:fs');
|
|
165
159
|
try {
|
|
166
160
|
data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
|
|
@@ -182,6 +176,7 @@ export default class DunningRuns extends Command {
|
|
|
182
176
|
if (!data)
|
|
183
177
|
data = {};
|
|
184
178
|
const body = data;
|
|
179
|
+
const arrayFields = new Set(endpoint.bodyArrayFields);
|
|
185
180
|
for (const pair of flags.set) {
|
|
186
181
|
const eqIndex = pair.indexOf('=');
|
|
187
182
|
if (eqIndex === -1)
|
|
@@ -193,6 +188,19 @@ export default class DunningRuns extends Command {
|
|
|
193
188
|
value = JSON.parse(value);
|
|
194
189
|
}
|
|
195
190
|
catch { /* keep as string */ }
|
|
191
|
+
// For top-level keys typed as array in the API schema, split bare
|
|
192
|
+
// comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
|
|
193
|
+
// wrap a lone scalar in a single-element array. Skips when --set
|
|
194
|
+
// already provided a JSON array.
|
|
195
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
196
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
197
|
+
if (typeof value === 'string') {
|
|
198
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
199
|
+
}
|
|
200
|
+
else if (value !== undefined && value !== null) {
|
|
201
|
+
value = [value];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
196
204
|
// Support nested keys like "address.city"
|
|
197
205
|
const keys = key.split('.');
|
|
198
206
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
@@ -243,6 +251,26 @@ export default class DunningRuns extends Command {
|
|
|
243
251
|
process.stderr.write('\n');
|
|
244
252
|
}
|
|
245
253
|
try {
|
|
254
|
+
// Binary response: download to file
|
|
255
|
+
if (endpoint.isBinaryResponse) {
|
|
256
|
+
if (!flags.file) {
|
|
257
|
+
this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
|
|
258
|
+
}
|
|
259
|
+
const binResponse = await apiRequest(endpoint.method, apiPath, {
|
|
260
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
261
|
+
data,
|
|
262
|
+
contextName: flags.context,
|
|
263
|
+
binary: true,
|
|
264
|
+
});
|
|
265
|
+
const fsModule = await import('node:fs');
|
|
266
|
+
const binData = binResponse.data;
|
|
267
|
+
const buffer = Buffer.isBuffer(binData)
|
|
268
|
+
? binData
|
|
269
|
+
: Buffer.from(binData);
|
|
270
|
+
fsModule.writeFileSync(flags.file, buffer);
|
|
271
|
+
this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
246
274
|
const response = await apiRequest(endpoint.method, apiPath, {
|
|
247
275
|
params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
248
276
|
data,
|
|
@@ -333,6 +361,7 @@ export default class DunningRuns extends Command {
|
|
|
333
361
|
}
|
|
334
362
|
else if (flags.set && flags.set.length > 0) {
|
|
335
363
|
const item = {};
|
|
364
|
+
const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
|
|
336
365
|
for (const pair of flags.set) {
|
|
337
366
|
const eqIndex = pair.indexOf('=');
|
|
338
367
|
if (eqIndex === -1)
|
|
@@ -343,6 +372,15 @@ export default class DunningRuns extends Command {
|
|
|
343
372
|
value = JSON.parse(value);
|
|
344
373
|
}
|
|
345
374
|
catch { /* keep as string */ }
|
|
375
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
376
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
377
|
+
if (typeof value === 'string') {
|
|
378
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
379
|
+
}
|
|
380
|
+
else if (value !== undefined && value !== null) {
|
|
381
|
+
value = [value];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
346
384
|
const keys = key.split('.');
|
|
347
385
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
348
386
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -492,14 +530,7 @@ export default class DunningRuns extends Command {
|
|
|
492
530
|
if (eqIndex === -1)
|
|
493
531
|
this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
|
|
494
532
|
const key = f.slice(0, eqIndex);
|
|
495
|
-
|
|
496
|
-
const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
|
|
497
|
-
if (opMatch) {
|
|
498
|
-
value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
value = `\$eq:${value}`;
|
|
502
|
-
}
|
|
533
|
+
const value = this.parseFilterValue(f.slice(eqIndex + 1));
|
|
503
534
|
const filterKey = `filter.${key}`;
|
|
504
535
|
if (filterKey in baseParams) {
|
|
505
536
|
const existing = baseParams[filterKey];
|
|
@@ -676,6 +707,7 @@ export default class DunningRuns extends Command {
|
|
|
676
707
|
}
|
|
677
708
|
else if (flags.set && flags.set.length > 0) {
|
|
678
709
|
const item = {};
|
|
710
|
+
const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
|
|
679
711
|
for (const pair of flags.set) {
|
|
680
712
|
const eqIndex = pair.indexOf('=');
|
|
681
713
|
if (eqIndex === -1)
|
|
@@ -686,6 +718,15 @@ export default class DunningRuns extends Command {
|
|
|
686
718
|
value = JSON.parse(value);
|
|
687
719
|
}
|
|
688
720
|
catch { /* keep as string */ }
|
|
721
|
+
const isArrayField = !key.includes('.') && arrayFields.has(key);
|
|
722
|
+
if (isArrayField && !Array.isArray(value)) {
|
|
723
|
+
if (typeof value === 'string') {
|
|
724
|
+
value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
|
|
725
|
+
}
|
|
726
|
+
else if (value !== undefined && value !== null) {
|
|
727
|
+
value = [value];
|
|
728
|
+
}
|
|
729
|
+
}
|
|
689
730
|
const keys = key.split('.');
|
|
690
731
|
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
|
|
691
732
|
this.error(`Invalid --set key: ${key}`);
|
|
@@ -805,6 +846,21 @@ export default class DunningRuns extends Command {
|
|
|
805
846
|
this.log('');
|
|
806
847
|
this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
|
|
807
848
|
}
|
|
849
|
+
parseFilterValue(value) {
|
|
850
|
+
// Recognises the nestjs-paginate operator set (with or without the leading $)
|
|
851
|
+
// and recursively unwraps chained operators like 'not:null' -> '$not:$null'
|
|
852
|
+
// or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
|
|
853
|
+
// no operator prefix is present.
|
|
854
|
+
const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
|
|
855
|
+
const m = value.match(opRe);
|
|
856
|
+
if (!m)
|
|
857
|
+
return `\$eq:${value}`;
|
|
858
|
+
const op = m[1];
|
|
859
|
+
const rest = value.slice(m[0].length);
|
|
860
|
+
if (rest === '')
|
|
861
|
+
return `\$${op}`;
|
|
862
|
+
return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
|
|
863
|
+
}
|
|
808
864
|
filterFields(data, fields) {
|
|
809
865
|
const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
|
|
810
866
|
const pick = (obj, keys) => {
|