@aderis-erp/cli 1.0.2 → 1.0.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.
Files changed (191) hide show
  1. package/README.md +6 -0
  2. package/dist/commands/access-groups 3.d.ts +40 -0
  3. package/dist/commands/{access-groups 2.js → access-groups 3.js } +106 -40
  4. package/dist/commands/access-groups.d.ts +40 -0
  5. package/dist/commands/access-groups.js +1074 -0
  6. package/dist/commands/account-transactions.d.ts +42 -0
  7. package/dist/commands/account-transactions.js +1088 -0
  8. package/dist/commands/accounts 2.d.ts +41 -0
  9. package/dist/commands/accounts 2.js +1078 -0
  10. package/dist/commands/accounts.d.ts +41 -0
  11. package/dist/commands/accounts.js +1080 -0
  12. package/dist/commands/agent-runs.d.ts +40 -0
  13. package/dist/commands/agent-runs.js +1071 -0
  14. package/dist/commands/async-endpoints-internal 3.d.ts +40 -0
  15. package/dist/commands/{processing-logs.js → async-endpoints-internal 3.js } +110 -46
  16. package/dist/commands/async-endpoints-internal.d.ts +40 -0
  17. package/dist/commands/async-endpoints-internal.js +1064 -0
  18. package/dist/commands/audit-log 3.d.ts +40 -0
  19. package/dist/commands/audit-log 3.js +1066 -0
  20. package/dist/commands/audit-log.d.ts +40 -0
  21. package/dist/commands/audit-log.js +1068 -0
  22. package/dist/commands/auth/login.d.ts +14 -0
  23. package/dist/commands/auth/login.js +116 -0
  24. package/dist/commands/auth/logout.d.ts +10 -0
  25. package/dist/commands/auth/logout.js +58 -0
  26. package/dist/commands/auth/status.d.ts +12 -0
  27. package/dist/commands/auth/status.js +101 -0
  28. package/dist/commands/auth/tenant.d.ts +19 -0
  29. package/dist/commands/auth/tenant.js +184 -0
  30. package/dist/commands/auth.d.ts +37 -0
  31. package/dist/commands/auth.js +871 -0
  32. package/dist/commands/bank-accounts.d.ts +42 -0
  33. package/dist/commands/bank-accounts.js +1088 -0
  34. package/dist/commands/bank-integrations.d.ts +1 -0
  35. package/dist/commands/bank-integrations.js +122 -54
  36. package/dist/commands/business-partners 3.d.ts +41 -0
  37. package/dist/commands/business-partners 3.js +1078 -0
  38. package/dist/commands/business-partners---contacts 3.d.ts +42 -0
  39. package/dist/commands/business-partners---contacts 3.js +1072 -0
  40. package/dist/commands/business-partners---contacts.d.ts +1 -0
  41. package/dist/commands/business-partners---contacts.js +114 -46
  42. package/dist/commands/business-partners.d.ts +1 -0
  43. package/dist/commands/business-partners.js +114 -46
  44. package/dist/commands/config/add.d.ts +13 -0
  45. package/dist/commands/config/add.js +120 -0
  46. package/dist/commands/config/current.d.ts +9 -0
  47. package/dist/commands/config/current.js +43 -0
  48. package/dist/commands/config/delete.d.ts +12 -0
  49. package/dist/commands/config/delete.js +67 -0
  50. package/dist/commands/config/list.d.ts +9 -0
  51. package/dist/commands/config/list.js +50 -0
  52. package/dist/commands/config/use.d.ts +9 -0
  53. package/dist/commands/config/use.js +40 -0
  54. package/dist/commands/credit-card-accounts 3.d.ts +42 -0
  55. package/dist/commands/credit-card-accounts 3.js +1084 -0
  56. package/dist/commands/credit-card-accounts.d.ts +1 -0
  57. package/dist/commands/credit-card-accounts.js +119 -51
  58. package/dist/commands/documents.d.ts +1 -0
  59. package/dist/commands/documents.js +110 -42
  60. package/dist/commands/dunning-configs 3.d.ts +40 -0
  61. package/dist/commands/dunning-configs 3.js +1072 -0
  62. package/dist/commands/dunning-configs.d.ts +1 -0
  63. package/dist/commands/dunning-configs.js +109 -41
  64. package/dist/commands/dunning-reminders.d.ts +1 -0
  65. package/dist/commands/dunning-reminders.js +112 -44
  66. package/dist/commands/dunning-runs 3.d.ts +40 -0
  67. package/dist/commands/{pubsub.js → dunning-runs 3.js } +108 -43
  68. package/dist/commands/dunning-runs.d.ts +1 -0
  69. package/dist/commands/dunning-runs.js +105 -37
  70. package/dist/commands/employees.d.ts +1 -0
  71. package/dist/commands/employees.js +136 -68
  72. package/dist/commands/event-processor-mappings 3.d.ts +40 -0
  73. package/dist/commands/event-processor-mappings 3.js +1071 -0
  74. package/dist/commands/event-processor-mappings.d.ts +1 -0
  75. package/dist/commands/event-processor-mappings.js +109 -41
  76. package/dist/commands/files-internal 3.d.ts +40 -0
  77. package/dist/commands/files-internal 3.js +1073 -0
  78. package/dist/commands/files-internal.d.ts +1 -0
  79. package/dist/commands/files-internal.js +113 -45
  80. package/dist/commands/health 3.d.ts +40 -0
  81. package/dist/commands/health 3.js +1067 -0
  82. package/dist/commands/health.d.ts +1 -0
  83. package/dist/commands/health.js +109 -41
  84. package/dist/commands/{pubsub.d.ts → inbox 3.d.ts } +2 -1
  85. package/dist/commands/inbox 3.js +1065 -0
  86. package/dist/commands/inbox.d.ts +1 -0
  87. package/dist/commands/inbox.js +110 -40
  88. package/dist/commands/integrations 3.d.ts +41 -0
  89. package/dist/commands/integrations 3.js +1067 -0
  90. package/dist/commands/integrations.d.ts +1 -0
  91. package/dist/commands/integrations.js +107 -39
  92. package/dist/commands/item-categories 3.d.ts +40 -0
  93. package/dist/commands/item-categories 3.js +1072 -0
  94. package/dist/commands/item-categories.d.ts +1 -0
  95. package/dist/commands/item-categories.js +109 -41
  96. package/dist/commands/items 3.d.ts +40 -0
  97. package/dist/commands/items 3.js +1072 -0
  98. package/dist/commands/items.d.ts +1 -0
  99. package/dist/commands/items.js +109 -41
  100. package/dist/commands/journal-lines.d.ts +1 -0
  101. package/dist/commands/journal-lines.js +105 -37
  102. package/dist/commands/journals 3.d.ts +42 -0
  103. package/dist/commands/journals 3.js +1088 -0
  104. package/dist/commands/journals.d.ts +1 -0
  105. package/dist/commands/journals.js +123 -55
  106. package/dist/commands/ledgers.d.ts +1 -0
  107. package/dist/commands/ledgers.js +120 -52
  108. package/dist/commands/office-locations 3.d.ts +40 -0
  109. package/dist/commands/office-locations 3.js +1072 -0
  110. package/dist/commands/office-locations.d.ts +1 -0
  111. package/dist/commands/office-locations.js +109 -41
  112. package/dist/commands/payment-method-ledger-mappings 3.d.ts +41 -0
  113. package/dist/commands/payment-method-ledger-mappings 3.js +1066 -0
  114. package/dist/commands/payment-method-ledger-mappings.d.ts +1 -0
  115. package/dist/commands/payment-method-ledger-mappings.js +109 -41
  116. package/dist/commands/payment-methods 3.d.ts +40 -0
  117. package/dist/commands/payment-methods 3.js +1072 -0
  118. package/dist/commands/payment-methods.d.ts +1 -0
  119. package/dist/commands/payment-methods.js +109 -41
  120. package/dist/commands/payment-runs 3.d.ts +42 -0
  121. package/dist/commands/payment-runs 3.js +1087 -0
  122. package/dist/commands/payment-runs.d.ts +1 -0
  123. package/dist/commands/payment-runs.js +122 -54
  124. package/dist/commands/payment-terms 3.d.ts +40 -0
  125. package/dist/commands/payment-terms 3.js +1073 -0
  126. package/dist/commands/payment-terms.d.ts +1 -0
  127. package/dist/commands/payment-terms.js +110 -42
  128. package/dist/commands/price-lists 3.d.ts +41 -0
  129. package/dist/commands/price-lists 3.js +1078 -0
  130. package/dist/commands/price-lists.d.ts +1 -0
  131. package/dist/commands/price-lists.js +114 -46
  132. package/dist/commands/processor-mappings 2.d.ts +40 -0
  133. package/dist/commands/processor-mappings 2.js +1070 -0
  134. package/dist/commands/processor-mappings.d.ts +1 -0
  135. package/dist/commands/processor-mappings.js +108 -40
  136. package/dist/commands/processors.d.ts +1 -0
  137. package/dist/commands/processors.js +113 -45
  138. package/dist/commands/reconciliation 3.d.ts +40 -0
  139. package/dist/commands/reconciliation 3.js +1069 -0
  140. package/dist/commands/reconciliation.d.ts +1 -0
  141. package/dist/commands/reconciliation.js +110 -42
  142. package/dist/commands/reports.d.ts +1 -0
  143. package/dist/commands/reports.js +110 -39
  144. package/dist/commands/salary-types 3.d.ts +40 -0
  145. package/dist/commands/salary-types 3.js +1072 -0
  146. package/dist/commands/salary-types.d.ts +1 -0
  147. package/dist/commands/salary-types.js +1074 -0
  148. package/dist/commands/sales-invoices 3.d.ts +43 -0
  149. package/dist/commands/sales-invoices 3.js +1100 -0
  150. package/dist/commands/sales-invoices.d.ts +1 -0
  151. package/dist/commands/sales-invoices.js +134 -66
  152. package/dist/commands/sales-orders 3.d.ts +43 -0
  153. package/dist/commands/sales-orders 3.js +1098 -0
  154. package/dist/commands/sales-orders.d.ts +1 -0
  155. package/dist/commands/sales-orders.js +133 -64
  156. package/dist/commands/switch.d.ts +1 -0
  157. package/dist/commands/switch.js +58 -3
  158. package/dist/commands/{processing-logs.d.ts → tags 3.d.ts } +2 -1
  159. package/dist/commands/tags 3.js +1072 -0
  160. package/dist/commands/tags.d.ts +1 -0
  161. package/dist/commands/tags.js +109 -41
  162. package/dist/commands/tax-codes 3.d.ts +40 -0
  163. package/dist/commands/tax-codes 3.js +1075 -0
  164. package/dist/commands/tax-codes.d.ts +1 -0
  165. package/dist/commands/tax-codes.js +112 -44
  166. package/dist/commands/tax-matrix.d.ts +1 -0
  167. package/dist/commands/tax-matrix.js +109 -41
  168. package/dist/commands/tenants.d.ts +1 -0
  169. package/dist/commands/tenants.js +109 -41
  170. package/dist/commands/text-templates 3.d.ts +40 -0
  171. package/dist/commands/text-templates 3.js +1072 -0
  172. package/dist/commands/text-templates.d.ts +1 -0
  173. package/dist/commands/text-templates.js +109 -41
  174. package/dist/commands/tools.d.ts +1 -0
  175. package/dist/commands/tools.js +106 -38
  176. package/dist/commands/vendor-invoices.d.ts +1 -0
  177. package/dist/commands/vendor-invoices.js +139 -69
  178. package/dist/commands/webhooks 3.d.ts +40 -0
  179. package/dist/commands/webhooks 3.js +1074 -0
  180. package/dist/commands/webhooks.d.ts +1 -0
  181. package/dist/commands/webhooks.js +111 -43
  182. package/dist/commands/workflows.d.ts +1 -0
  183. package/dist/commands/workflows.js +107 -39
  184. package/dist/lib/api-client.d.ts +5 -1
  185. package/dist/lib/api-client.js +19 -5
  186. package/dist/lib/auth.d.ts +16 -1
  187. package/dist/lib/auth.js +170 -45
  188. package/dist/lib/config.d.ts +7 -0
  189. package/dist/lib/config.js +7 -1
  190. package/oclif.manifest.json +7464 -653
  191. package/package.json +2 -2
@@ -30,6 +30,7 @@ export default class Webhooks extends Command {
30
30
  private runExport;
31
31
  private runCamt053Import;
32
32
  private runNestedImport;
33
+ private parseFilterValue;
33
34
  private filterFields;
34
35
  private sanitizeOutput;
35
36
  private getColumns;
@@ -8,13 +8,13 @@ const HAS_CAMT053 = false;
8
8
  const NESTED_IMPORTS = [];
9
9
  const SUBCOMMANDS = [...["list", "create", "events", "events-relations", "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/webhooks', summary: 'List all webhook subscriptions', pathParams: [], hasBody: false, isMultipart: false },
12
- 'create': { method: 'POST', path: '/v1/webhooks', summary: 'Create a new webhook subscription', pathParams: [], hasBody: true, isMultipart: false },
13
- 'events': { method: 'GET', path: '/v1/webhooks/events', summary: 'Get available event types', pathParams: [], hasBody: false, isMultipart: false },
14
- 'events-relations': { method: 'GET', path: '/v1/webhooks/events/{eventType}/relations', summary: 'Get valid relations for an event type', pathParams: ['eventType'], hasBody: false, isMultipart: false },
15
- 'get': { method: 'GET', path: '/v1/webhooks/{id}', summary: 'Get a webhook subscription by ID', pathParams: ['id'], hasBody: false, isMultipart: false },
16
- 'update': { method: 'PATCH', path: '/v1/webhooks/{id}', summary: 'Update a webhook subscription', pathParams: ['id'], hasBody: true, isMultipart: false },
17
- 'delete': { method: 'DELETE', path: '/v1/webhooks/{id}', summary: 'Delete a webhook subscription', pathParams: ['id'], hasBody: false, isMultipart: false },
11
+ 'list': { method: 'GET', path: '/v1/webhooks', summary: 'List all webhook subscriptions', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
12
+ 'create': { method: 'POST', path: '/v1/webhooks', summary: 'Create a new webhook subscription', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: ['tenantIds'] },
13
+ 'events': { method: 'GET', path: '/v1/webhooks/events', summary: 'Get available event types', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
14
+ 'events-relations': { method: 'GET', path: '/v1/webhooks/events/{eventType}/relations', summary: 'Get valid relations for an event type', pathParams: ['eventType'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
15
+ 'get': { method: 'GET', path: '/v1/webhooks/{id}', summary: 'Get a webhook subscription by ID', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
16
+ 'update': { method: 'PATCH', path: '/v1/webhooks/{id}', summary: 'Update a webhook subscription', pathParams: ['id'], hasBody: true, isMultipart: false, isBinaryResponse: false, bodyArrayFields: ['tenantIds'] },
17
+ 'delete': { method: 'DELETE', path: '/v1/webhooks/{id}', summary: 'Delete a webhook subscription', pathParams: ['id'], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
18
18
  };
19
19
  export default class Webhooks extends Command {
20
20
  static description = 'Manage webhooks';
@@ -132,15 +132,7 @@ export default class Webhooks extends Command {
132
132
  if (eqIndex === -1)
133
133
  this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
134
134
  const key = f.slice(0, eqIndex);
135
- let value = f.slice(eqIndex + 1);
136
- // Check for operator prefix (with or without $)
137
- const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
138
- if (opMatch) {
139
- value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
140
- }
141
- else {
142
- value = `\$eq:${value}`;
143
- }
135
+ const value = this.parseFilterValue(f.slice(eqIndex + 1));
144
136
  const filterKey = `filter.${key}`;
145
137
  if (filterKey in queryParams) {
146
138
  // Multiple filters on same field: collect as array
@@ -173,7 +165,9 @@ export default class Webhooks extends Command {
173
165
  data = form;
174
166
  }
175
167
  else if (endpoint.hasBody) {
176
- if (flags.file) {
168
+ // For binary-response endpoints, --file is the output path, not a JSON
169
+ // input file — skip the read-as-body branch.
170
+ if (flags.file && !endpoint.isBinaryResponse) {
177
171
  const fsModule = await import('node:fs');
178
172
  try {
179
173
  data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
@@ -195,6 +189,7 @@ export default class Webhooks extends Command {
195
189
  if (!data)
196
190
  data = {};
197
191
  const body = data;
192
+ const arrayFields = new Set(endpoint.bodyArrayFields);
198
193
  for (const pair of flags.set) {
199
194
  const eqIndex = pair.indexOf('=');
200
195
  if (eqIndex === -1)
@@ -206,6 +201,19 @@ export default class Webhooks extends Command {
206
201
  value = JSON.parse(value);
207
202
  }
208
203
  catch { /* keep as string */ }
204
+ // For top-level keys typed as array in the API schema, split bare
205
+ // comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
206
+ // wrap a lone scalar in a single-element array. Skips when --set
207
+ // already provided a JSON array.
208
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
209
+ if (isArrayField && !Array.isArray(value)) {
210
+ if (typeof value === 'string') {
211
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
212
+ }
213
+ else if (value !== undefined && value !== null) {
214
+ value = [value];
215
+ }
216
+ }
209
217
  // Support nested keys like "address.city"
210
218
  const keys = key.split('.');
211
219
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
@@ -256,6 +264,26 @@ export default class Webhooks extends Command {
256
264
  process.stderr.write('\n');
257
265
  }
258
266
  try {
267
+ // Binary response: download to file
268
+ if (endpoint.isBinaryResponse) {
269
+ if (!flags.file) {
270
+ this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
271
+ }
272
+ const binResponse = await apiRequest(endpoint.method, apiPath, {
273
+ params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
274
+ data,
275
+ contextName: flags.context,
276
+ binary: true,
277
+ });
278
+ const fsModule = await import('node:fs');
279
+ const binData = binResponse.data;
280
+ const buffer = Buffer.isBuffer(binData)
281
+ ? binData
282
+ : Buffer.from(binData);
283
+ fsModule.writeFileSync(flags.file, buffer);
284
+ this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
285
+ return;
286
+ }
259
287
  const response = await apiRequest(endpoint.method, apiPath, {
260
288
  params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
261
289
  data,
@@ -346,6 +374,7 @@ export default class Webhooks extends Command {
346
374
  }
347
375
  else if (flags.set && flags.set.length > 0) {
348
376
  const item = {};
377
+ const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
349
378
  for (const pair of flags.set) {
350
379
  const eqIndex = pair.indexOf('=');
351
380
  if (eqIndex === -1)
@@ -356,6 +385,15 @@ export default class Webhooks extends Command {
356
385
  value = JSON.parse(value);
357
386
  }
358
387
  catch { /* keep as string */ }
388
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
389
+ if (isArrayField && !Array.isArray(value)) {
390
+ if (typeof value === 'string') {
391
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
392
+ }
393
+ else if (value !== undefined && value !== null) {
394
+ value = [value];
395
+ }
396
+ }
359
397
  const keys = key.split('.');
360
398
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
361
399
  this.error(`Invalid --set key: ${key}`);
@@ -505,14 +543,7 @@ export default class Webhooks extends Command {
505
543
  if (eqIndex === -1)
506
544
  this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
507
545
  const key = f.slice(0, eqIndex);
508
- let value = f.slice(eqIndex + 1);
509
- const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
510
- if (opMatch) {
511
- value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
512
- }
513
- else {
514
- value = `\$eq:${value}`;
515
- }
546
+ const value = this.parseFilterValue(f.slice(eqIndex + 1));
516
547
  const filterKey = `filter.${key}`;
517
548
  if (filterKey in baseParams) {
518
549
  const existing = baseParams[filterKey];
@@ -689,6 +720,7 @@ export default class Webhooks extends Command {
689
720
  }
690
721
  else if (flags.set && flags.set.length > 0) {
691
722
  const item = {};
723
+ const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
692
724
  for (const pair of flags.set) {
693
725
  const eqIndex = pair.indexOf('=');
694
726
  if (eqIndex === -1)
@@ -699,6 +731,15 @@ export default class Webhooks extends Command {
699
731
  value = JSON.parse(value);
700
732
  }
701
733
  catch { /* keep as string */ }
734
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
735
+ if (isArrayField && !Array.isArray(value)) {
736
+ if (typeof value === 'string') {
737
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
738
+ }
739
+ else if (value !== undefined && value !== null) {
740
+ value = [value];
741
+ }
742
+ }
702
743
  const keys = key.split('.');
703
744
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
704
745
  this.error(`Invalid --set key: ${key}`);
@@ -818,35 +859,62 @@ export default class Webhooks extends Command {
818
859
  this.log('');
819
860
  this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
820
861
  }
862
+ parseFilterValue(value) {
863
+ // Recognises the nestjs-paginate operator set (with or without the leading $)
864
+ // and recursively unwraps chained operators like 'not:null' -> '$not:$null'
865
+ // or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
866
+ // no operator prefix is present.
867
+ const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
868
+ const m = value.match(opRe);
869
+ if (!m)
870
+ return `\$eq:${value}`;
871
+ const op = m[1];
872
+ const rest = value.slice(m[0].length);
873
+ if (rest === '')
874
+ return `\$${op}`;
875
+ return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
876
+ }
821
877
  filterFields(data, fields) {
822
878
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
823
879
  const pick = (obj, keys) => {
824
- const result = {};
880
+ // Group keys by their first segment so sibling sub-paths
881
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
882
+ // and don't clobber each other on merge.
883
+ const directKeys = new Set();
884
+ const nestedKeys = new Map();
825
885
  for (const key of keys) {
826
886
  if (key.split('.').some(isUnsafeKey))
827
887
  continue;
828
888
  if (key.includes('.')) {
829
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
830
889
  const [first, ...rest] = key.split('.');
831
- const val = obj[first];
832
- if (val && typeof val === 'object') {
833
- const restKey = rest.join('.');
834
- if (Array.isArray(val)) {
835
- // Map over array elements (e.g., allocations[].salesInvoiceId)
836
- const existing = Array.isArray(result[first]) ? result[first] : [];
837
- result[first] = val.map((item, i) => ({
838
- ...(existing[i] || {}),
839
- ...pick(item, [restKey]),
840
- }));
841
- }
842
- else {
843
- const nested = pick(val, [restKey]);
844
- result[first] = { ...(result[first] || {}), ...nested };
845
- }
890
+ if (isUnsafeKey(first))
891
+ continue;
892
+ const list = nestedKeys.get(first);
893
+ if (list) {
894
+ list.push(rest.join('.'));
895
+ }
896
+ else {
897
+ nestedKeys.set(first, [rest.join('.')]);
846
898
  }
847
899
  }
848
- else if (key in obj) {
900
+ else {
901
+ directKeys.add(key);
902
+ }
903
+ }
904
+ const result = {};
905
+ for (const key of directKeys) {
906
+ if (key in obj)
849
907
  result[key] = obj[key];
908
+ }
909
+ for (const [first, restKeys] of nestedKeys) {
910
+ const val = obj[first];
911
+ if (!val || typeof val !== 'object')
912
+ continue;
913
+ if (Array.isArray(val)) {
914
+ result[first] = val.map(item => pick(item, restKeys));
915
+ }
916
+ else {
917
+ result[first] = pick(val, restKeys);
850
918
  }
851
919
  }
852
920
  return result;
@@ -30,6 +30,7 @@ export default class Workflows extends Command {
30
30
  private runExport;
31
31
  private runCamt053Import;
32
32
  private runNestedImport;
33
+ private parseFilterValue;
33
34
  private filterFields;
34
35
  private sanitizeOutput;
35
36
  private getColumns;
@@ -8,9 +8,9 @@ const HAS_CAMT053 = false;
8
8
  const NESTED_IMPORTS = [];
9
9
  const SUBCOMMANDS = [...["list", "status", "find"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
10
10
  const ENDPOINTS = {
11
- 'list': { method: 'GET', path: '/v1/workflows', summary: 'Get all workflows with their summary', pathParams: [], hasBody: false, isMultipart: false },
12
- 'status': { method: 'POST', path: '/v1/workflows/status', summary: 'Create a new workflow status update', pathParams: [], hasBody: true, isMultipart: false },
13
- 'find': { method: 'GET', path: '/v1/workflows/{workflowId}', summary: 'Get workflow details including status updates and entity changes', pathParams: ['workflowId'], hasBody: false, isMultipart: false },
11
+ 'list': { method: 'GET', path: '/v1/workflows', summary: 'Get all workflows with their summary', pathParams: [], hasBody: false, isMultipart: false, isBinaryResponse: false, bodyArrayFields: [] },
12
+ 'status': { method: 'POST', path: '/v1/workflows/status', summary: 'Create a new workflow status update', pathParams: [], hasBody: true, isMultipart: false, isBinaryResponse: 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, bodyArrayFields: [] },
14
14
  };
15
15
  export default class Workflows extends Command {
16
16
  static description = 'Manage workflows';
@@ -124,15 +124,7 @@ export default class Workflows extends Command {
124
124
  if (eqIndex === -1)
125
125
  this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
126
126
  const key = f.slice(0, eqIndex);
127
- let value = f.slice(eqIndex + 1);
128
- // Check for operator prefix (with or without $)
129
- const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
130
- if (opMatch) {
131
- value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
132
- }
133
- else {
134
- value = `\$eq:${value}`;
135
- }
127
+ const value = this.parseFilterValue(f.slice(eqIndex + 1));
136
128
  const filterKey = `filter.${key}`;
137
129
  if (filterKey in queryParams) {
138
130
  // Multiple filters on same field: collect as array
@@ -165,7 +157,9 @@ export default class Workflows extends Command {
165
157
  data = form;
166
158
  }
167
159
  else if (endpoint.hasBody) {
168
- if (flags.file) {
160
+ // For binary-response endpoints, --file is the output path, not a JSON
161
+ // input file — skip the read-as-body branch.
162
+ if (flags.file && !endpoint.isBinaryResponse) {
169
163
  const fsModule = await import('node:fs');
170
164
  try {
171
165
  data = JSON.parse(fsModule.readFileSync(flags.file, 'utf-8'));
@@ -187,6 +181,7 @@ export default class Workflows extends Command {
187
181
  if (!data)
188
182
  data = {};
189
183
  const body = data;
184
+ const arrayFields = new Set(endpoint.bodyArrayFields);
190
185
  for (const pair of flags.set) {
191
186
  const eqIndex = pair.indexOf('=');
192
187
  if (eqIndex === -1)
@@ -198,6 +193,19 @@ export default class Workflows extends Command {
198
193
  value = JSON.parse(value);
199
194
  }
200
195
  catch { /* keep as string */ }
196
+ // For top-level keys typed as array in the API schema, split bare
197
+ // comma-separated input (e.g. "1171,1170" -> ["1171","1170"]) and
198
+ // wrap a lone scalar in a single-element array. Skips when --set
199
+ // already provided a JSON array.
200
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
201
+ if (isArrayField && !Array.isArray(value)) {
202
+ if (typeof value === 'string') {
203
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
204
+ }
205
+ else if (value !== undefined && value !== null) {
206
+ value = [value];
207
+ }
208
+ }
201
209
  // Support nested keys like "address.city"
202
210
  const keys = key.split('.');
203
211
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
@@ -248,6 +256,26 @@ export default class Workflows extends Command {
248
256
  process.stderr.write('\n');
249
257
  }
250
258
  try {
259
+ // Binary response: download to file
260
+ if (endpoint.isBinaryResponse) {
261
+ if (!flags.file) {
262
+ this.error(`Endpoint returns a binary file. Specify the output path with -f / --file (e.g. -f report.xlsx).`);
263
+ }
264
+ const binResponse = await apiRequest(endpoint.method, apiPath, {
265
+ params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
266
+ data,
267
+ contextName: flags.context,
268
+ binary: true,
269
+ });
270
+ const fsModule = await import('node:fs');
271
+ const binData = binResponse.data;
272
+ const buffer = Buffer.isBuffer(binData)
273
+ ? binData
274
+ : Buffer.from(binData);
275
+ fsModule.writeFileSync(flags.file, buffer);
276
+ this.log(`Saved ${buffer.length} bytes to ${flags.file}`);
277
+ return;
278
+ }
251
279
  const response = await apiRequest(endpoint.method, apiPath, {
252
280
  params: Object.keys(queryParams).length > 0 ? queryParams : undefined,
253
281
  data,
@@ -338,6 +366,7 @@ export default class Workflows extends Command {
338
366
  }
339
367
  else if (flags.set && flags.set.length > 0) {
340
368
  const item = {};
369
+ const arrayFields = new Set(ENDPOINTS['create']?.bodyArrayFields ?? []);
341
370
  for (const pair of flags.set) {
342
371
  const eqIndex = pair.indexOf('=');
343
372
  if (eqIndex === -1)
@@ -348,6 +377,15 @@ export default class Workflows extends Command {
348
377
  value = JSON.parse(value);
349
378
  }
350
379
  catch { /* keep as string */ }
380
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
381
+ if (isArrayField && !Array.isArray(value)) {
382
+ if (typeof value === 'string') {
383
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
384
+ }
385
+ else if (value !== undefined && value !== null) {
386
+ value = [value];
387
+ }
388
+ }
351
389
  const keys = key.split('.');
352
390
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
353
391
  this.error(`Invalid --set key: ${key}`);
@@ -497,14 +535,7 @@ export default class Workflows extends Command {
497
535
  if (eqIndex === -1)
498
536
  this.error(`Invalid --filter format: ${f}. Use: --filter key=value`);
499
537
  const key = f.slice(0, eqIndex);
500
- let value = f.slice(eqIndex + 1);
501
- const opMatch = value.match(/^\$?(eq|ne|in|like|gt|gte|lt|lte|null):/);
502
- if (opMatch) {
503
- value = `\$${opMatch[1]}:${value.slice(opMatch[0].length)}`;
504
- }
505
- else {
506
- value = `\$eq:${value}`;
507
- }
538
+ const value = this.parseFilterValue(f.slice(eqIndex + 1));
508
539
  const filterKey = `filter.${key}`;
509
540
  if (filterKey in baseParams) {
510
541
  const existing = baseParams[filterKey];
@@ -681,6 +712,7 @@ export default class Workflows extends Command {
681
712
  }
682
713
  else if (flags.set && flags.set.length > 0) {
683
714
  const item = {};
715
+ const arrayFields = new Set(ENDPOINTS[`create-${suffix}`]?.bodyArrayFields ?? []);
684
716
  for (const pair of flags.set) {
685
717
  const eqIndex = pair.indexOf('=');
686
718
  if (eqIndex === -1)
@@ -691,6 +723,15 @@ export default class Workflows extends Command {
691
723
  value = JSON.parse(value);
692
724
  }
693
725
  catch { /* keep as string */ }
726
+ const isArrayField = !key.includes('.') && arrayFields.has(key);
727
+ if (isArrayField && !Array.isArray(value)) {
728
+ if (typeof value === 'string') {
729
+ value = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
730
+ }
731
+ else if (value !== undefined && value !== null) {
732
+ value = [value];
733
+ }
734
+ }
694
735
  const keys = key.split('.');
695
736
  if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
696
737
  this.error(`Invalid --set key: ${key}`);
@@ -810,35 +851,62 @@ export default class Workflows extends Command {
810
851
  this.log('');
811
852
  this.log(`Summary: ${created} created, ${updated} updated, ${errors.length} failed`);
812
853
  }
854
+ parseFilterValue(value) {
855
+ // Recognises the nestjs-paginate operator set (with or without the leading $)
856
+ // and recursively unwraps chained operators like 'not:null' -> '$not:$null'
857
+ // or 'not:like:John' -> '$not:$like:John'. Falls back to '$eq:<value>' when
858
+ // no operator prefix is present.
859
+ const opRe = /^\$?(and|or|not|eq|gt|gte|in|null|lt|lte|btw|ne|ilike|like|sw|contains)(?::|$)/;
860
+ const m = value.match(opRe);
861
+ if (!m)
862
+ return `\$eq:${value}`;
863
+ const op = m[1];
864
+ const rest = value.slice(m[0].length);
865
+ if (rest === '')
866
+ return `\$${op}`;
867
+ return opRe.test(rest) ? `\$${op}:${this.parseFilterValue(rest)}` : `\$${op}:${rest}`;
868
+ }
813
869
  filterFields(data, fields) {
814
870
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
815
871
  const pick = (obj, keys) => {
816
- const result = {};
872
+ // Group keys by their first segment so sibling sub-paths
873
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
874
+ // and don't clobber each other on merge.
875
+ const directKeys = new Set();
876
+ const nestedKeys = new Map();
817
877
  for (const key of keys) {
818
878
  if (key.split('.').some(isUnsafeKey))
819
879
  continue;
820
880
  if (key.includes('.')) {
821
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
822
881
  const [first, ...rest] = key.split('.');
823
- const val = obj[first];
824
- if (val && typeof val === 'object') {
825
- const restKey = rest.join('.');
826
- if (Array.isArray(val)) {
827
- // Map over array elements (e.g., allocations[].salesInvoiceId)
828
- const existing = Array.isArray(result[first]) ? result[first] : [];
829
- result[first] = val.map((item, i) => ({
830
- ...(existing[i] || {}),
831
- ...pick(item, [restKey]),
832
- }));
833
- }
834
- else {
835
- const nested = pick(val, [restKey]);
836
- result[first] = { ...(result[first] || {}), ...nested };
837
- }
882
+ if (isUnsafeKey(first))
883
+ continue;
884
+ const list = nestedKeys.get(first);
885
+ if (list) {
886
+ list.push(rest.join('.'));
887
+ }
888
+ else {
889
+ nestedKeys.set(first, [rest.join('.')]);
838
890
  }
839
891
  }
840
- else if (key in obj) {
892
+ else {
893
+ directKeys.add(key);
894
+ }
895
+ }
896
+ const result = {};
897
+ for (const key of directKeys) {
898
+ if (key in obj)
841
899
  result[key] = obj[key];
900
+ }
901
+ for (const [first, restKeys] of nestedKeys) {
902
+ const val = obj[first];
903
+ if (!val || typeof val !== 'object')
904
+ continue;
905
+ if (Array.isArray(val)) {
906
+ result[first] = val.map(item => pick(item, restKeys));
907
+ }
908
+ else {
909
+ result[first] = pick(val, restKeys);
842
910
  }
843
911
  }
844
912
  return result;
@@ -25,9 +25,13 @@ export declare class ApiError extends Error {
25
25
  data?: unknown | undefined;
26
26
  constructor(message: string, status: number, data?: unknown | undefined);
27
27
  }
28
- export declare function createApiClient(contextName?: string, acceptAny?: boolean): Promise<AxiosInstance>;
28
+ export declare function createApiClient(contextName?: string, options?: {
29
+ acceptAny?: boolean;
30
+ binary?: boolean;
31
+ } | boolean): Promise<AxiosInstance>;
29
32
  export declare function apiRequest<T = unknown>(method: string, path: string, options?: {
30
33
  acceptAny?: boolean;
34
+ binary?: boolean;
31
35
  contentType?: string;
32
36
  contextName?: string;
33
37
  data?: unknown;
@@ -11,7 +11,10 @@ export class ApiError extends Error {
11
11
  this.name = 'ApiError';
12
12
  }
13
13
  }
14
- export async function createApiClient(contextName, acceptAny = false) {
14
+ export async function createApiClient(contextName, options = false) {
15
+ // Backwards compatibility: a boolean argument means `acceptAny`.
16
+ const opts = typeof options === 'boolean' ? { acceptAny: options } : options;
17
+ const { acceptAny = false, binary = false } = opts;
15
18
  const context = contextName ? (await import('./config.js')).getContext(contextName) : getCurrentContext();
16
19
  if (!context) {
17
20
  throw new Error('No context configured. Run: aderis auth login --new');
@@ -21,14 +24,14 @@ export async function createApiClient(contextName, acceptAny = false) {
21
24
  const client = axios.create({
22
25
  baseURL,
23
26
  headers: {
24
- Accept: acceptAny ? '*/*' : 'application/json',
27
+ Accept: binary ? '*/*' : (acceptAny ? '*/*' : 'application/json'),
25
28
  Authorization: `Bearer ${token}`,
26
29
  'Content-Type': 'application/json',
27
30
  },
28
31
  // Serialize arrays as repeated params (key=v1&key=v2) instead of bracket format (key[]=v1)
29
32
  paramsSerializer: { indexes: null },
30
- // Allow any response type when acceptAny is true
31
- responseType: acceptAny ? 'text' : 'json',
33
+ // Binary downloads come back as raw bytes; otherwise honour acceptAny.
34
+ responseType: binary ? 'arraybuffer' : (acceptAny ? 'text' : 'json'),
32
35
  });
33
36
  // Response interceptor for error handling
34
37
  client.interceptors.response.use((response) => response, (error) => {
@@ -45,6 +48,14 @@ export async function createApiClient(contextName, acceptAny = false) {
45
48
  return client;
46
49
  }
47
50
  function extractErrorMessage(data) {
51
+ // Binary requests buffer the response as ArrayBuffer / Buffer / Uint8Array.
52
+ // Decode it before parsing so error payloads aren't reported as "Unknown error".
53
+ if (data instanceof ArrayBuffer) {
54
+ return extractErrorMessage(new TextDecoder().decode(new Uint8Array(data)));
55
+ }
56
+ if (data instanceof Uint8Array || (typeof Buffer !== 'undefined' && Buffer.isBuffer(data))) {
57
+ return extractErrorMessage(new TextDecoder().decode(data));
58
+ }
48
59
  // If data is a JSON string, try to parse it first
49
60
  if (typeof data === 'string') {
50
61
  try {
@@ -75,7 +86,10 @@ function extractErrorMessage(data) {
75
86
  return 'Unknown error';
76
87
  }
77
88
  export async function apiRequest(method, path, options = {}) {
78
- const client = await createApiClient(options.contextName, options.acceptAny);
89
+ const client = await createApiClient(options.contextName, {
90
+ acceptAny: options.acceptAny,
91
+ binary: options.binary,
92
+ });
79
93
  const config = {
80
94
  method,
81
95
  url: path,
@@ -1,5 +1,7 @@
1
1
  import { type Context, type TokenData } from './config.js';
2
- export declare function login(context: Context): Promise<TokenData>;
2
+ export declare function login(context: Context, options?: {
3
+ prompt?: 'login' | 'none';
4
+ }): Promise<TokenData>;
3
5
  export declare function refreshTokens(contextName: string): Promise<TokenData>;
4
6
  export declare function getValidToken(contextName: string): Promise<string>;
5
7
  export declare function testAuth(contextName: string): Promise<{
@@ -18,3 +20,16 @@ export declare function getCurrentTenant(contextName: string): Promise<null | {
18
20
  tenantId: string;
19
21
  }>;
20
22
  export declare function switchTenant(contextName: string, tenantId: string): Promise<TokenData>;
23
+ /**
24
+ * Combined login + tenant switch flow that uses a single browser tab.
25
+ *
26
+ * Two PKCE rounds run against one local callback server. After the first round
27
+ * completes (which gives us tokens we can use to PUT the new active tenant),
28
+ * the server responds with HTML that meta-refreshes the same browser tab to a
29
+ * second `/oauth/authorize` URL. The second round mints tokens scoped to the
30
+ * new active tenant.
31
+ *
32
+ * Used by `aderis switch` when the user's session is expired AND they want to
33
+ * end up on a different tenant — avoids the previous two-separate-tab UX.
34
+ */
35
+ export declare function loginAndSwitchTenant(context: Context, tenantId: string): Promise<TokenData>;