@aderis-erp/cli 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/access-groups.js +36 -22
  3. package/dist/commands/account-transactions.js +30 -18
  4. package/dist/commands/accounts.js +30 -18
  5. package/dist/commands/agent-runs.js +33 -21
  6. package/dist/commands/{processing-logs.d.ts → async-endpoints-internal.d.ts} +2 -2
  7. package/dist/commands/{processing-logs.js → async-endpoints-internal.js} +39 -28
  8. package/dist/commands/audit-log.js +30 -18
  9. package/dist/commands/auth/tenant.d.ts +1 -0
  10. package/dist/commands/auth/tenant.js +23 -7
  11. package/dist/commands/bank-accounts.js +30 -18
  12. package/dist/commands/bank-integrations.d.ts +2 -0
  13. package/dist/commands/bank-integrations.js +41 -19
  14. package/dist/commands/business-partners---contacts.js +30 -18
  15. package/dist/commands/business-partners.js +30 -18
  16. package/dist/commands/credit-card-accounts.js +30 -18
  17. package/dist/commands/documents.js +36 -22
  18. package/dist/commands/dunning-configs.js +30 -18
  19. package/dist/commands/dunning-reminders.js +30 -18
  20. package/dist/commands/dunning-runs.js +30 -18
  21. package/dist/commands/employees.js +30 -18
  22. package/dist/commands/event-processor-mappings.js +30 -18
  23. package/dist/commands/files-internal.js +30 -18
  24. package/dist/commands/health.js +30 -18
  25. package/dist/commands/inbox.js +34 -20
  26. package/dist/commands/integrations.js +30 -18
  27. package/dist/commands/item-categories.js +30 -18
  28. package/dist/commands/items.js +30 -18
  29. package/dist/commands/journal-lines.js +30 -18
  30. package/dist/commands/journals.js +30 -18
  31. package/dist/commands/ledgers.js +30 -18
  32. package/dist/commands/office-locations.js +30 -18
  33. package/dist/commands/payment-method-ledger-mappings.js +30 -18
  34. package/dist/commands/payment-methods.js +30 -18
  35. package/dist/commands/payment-runs.js +30 -18
  36. package/dist/commands/payment-terms.js +30 -18
  37. package/dist/commands/price-lists.js +30 -18
  38. package/dist/commands/processor-mappings.js +30 -18
  39. package/dist/commands/processors.js +31 -19
  40. package/dist/commands/reconciliation.js +30 -18
  41. package/dist/commands/reports.js +30 -18
  42. package/dist/commands/salary-types.js +30 -18
  43. package/dist/commands/sales-invoices.js +32 -19
  44. package/dist/commands/sales-orders.js +33 -19
  45. package/dist/commands/switch.d.ts +1 -0
  46. package/dist/commands/switch.js +58 -3
  47. package/dist/commands/tags.js +30 -18
  48. package/dist/commands/tax-codes.js +30 -18
  49. package/dist/commands/tax-matrix.js +30 -18
  50. package/dist/commands/tenants.js +30 -18
  51. package/dist/commands/text-templates.js +30 -18
  52. package/dist/commands/tools.js +30 -18
  53. package/dist/commands/vendor-invoices.js +33 -19
  54. package/dist/commands/webhooks.js +30 -18
  55. package/dist/commands/workflows.js +30 -18
  56. package/dist/index 2.js +1 -0
  57. package/dist/index.d 2.ts +1 -0
  58. package/dist/lib/auth.d.ts +16 -1
  59. package/dist/lib/auth.js +167 -50
  60. package/dist/lib/config.d.ts +7 -0
  61. package/dist/lib/config.js +6 -0
  62. package/oclif.manifest.json +65 -385
  63. package/package.json +2 -2
  64. package/dist/commands/account-statement-runs.d.ts +0 -40
  65. package/dist/commands/account-statement-runs.js +0 -1004
  66. package/dist/commands/bank-statements.d.ts +0 -40
  67. package/dist/commands/bank-statements.js +0 -998
@@ -818,32 +818,44 @@ export default class EventProcessorMappings extends Command {
818
818
  filterFields(data, fields) {
819
819
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
820
820
  const pick = (obj, keys) => {
821
- const result = {};
821
+ // Group keys by their first segment so sibling sub-paths
822
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
823
+ // and don't clobber each other on merge.
824
+ const directKeys = new Set();
825
+ const nestedKeys = new Map();
822
826
  for (const key of keys) {
823
827
  if (key.split('.').some(isUnsafeKey))
824
828
  continue;
825
829
  if (key.includes('.')) {
826
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
827
830
  const [first, ...rest] = key.split('.');
828
- const val = obj[first];
829
- if (val && typeof val === 'object') {
830
- const restKey = rest.join('.');
831
- if (Array.isArray(val)) {
832
- // Map over array elements (e.g., allocations[].salesInvoiceId)
833
- const existing = Array.isArray(result[first]) ? result[first] : [];
834
- result[first] = val.map((item, i) => ({
835
- ...(existing[i] || {}),
836
- ...pick(item, [restKey]),
837
- }));
838
- }
839
- else {
840
- const nested = pick(val, [restKey]);
841
- result[first] = { ...(result[first] || {}), ...nested };
842
- }
831
+ if (isUnsafeKey(first))
832
+ continue;
833
+ const list = nestedKeys.get(first);
834
+ if (list) {
835
+ list.push(rest.join('.'));
843
836
  }
837
+ else {
838
+ nestedKeys.set(first, [rest.join('.')]);
839
+ }
840
+ }
841
+ else {
842
+ directKeys.add(key);
844
843
  }
845
- else if (key in obj) {
844
+ }
845
+ const result = {};
846
+ for (const key of directKeys) {
847
+ if (key in obj)
846
848
  result[key] = obj[key];
849
+ }
850
+ for (const [first, restKeys] of nestedKeys) {
851
+ const val = obj[first];
852
+ if (!val || typeof val !== 'object')
853
+ continue;
854
+ if (Array.isArray(val)) {
855
+ result[first] = val.map(item => pick(item, restKeys));
856
+ }
857
+ else {
858
+ result[first] = pick(val, restKeys);
847
859
  }
848
860
  }
849
861
  return result;
@@ -820,32 +820,44 @@ export default class FilesInternal extends Command {
820
820
  filterFields(data, fields) {
821
821
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
822
822
  const pick = (obj, keys) => {
823
- const result = {};
823
+ // Group keys by their first segment so sibling sub-paths
824
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
825
+ // and don't clobber each other on merge.
826
+ const directKeys = new Set();
827
+ const nestedKeys = new Map();
824
828
  for (const key of keys) {
825
829
  if (key.split('.').some(isUnsafeKey))
826
830
  continue;
827
831
  if (key.includes('.')) {
828
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
829
832
  const [first, ...rest] = key.split('.');
830
- const val = obj[first];
831
- if (val && typeof val === 'object') {
832
- const restKey = rest.join('.');
833
- if (Array.isArray(val)) {
834
- // Map over array elements (e.g., allocations[].salesInvoiceId)
835
- const existing = Array.isArray(result[first]) ? result[first] : [];
836
- result[first] = val.map((item, i) => ({
837
- ...(existing[i] || {}),
838
- ...pick(item, [restKey]),
839
- }));
840
- }
841
- else {
842
- const nested = pick(val, [restKey]);
843
- result[first] = { ...(result[first] || {}), ...nested };
844
- }
833
+ if (isUnsafeKey(first))
834
+ continue;
835
+ const list = nestedKeys.get(first);
836
+ if (list) {
837
+ list.push(rest.join('.'));
845
838
  }
839
+ else {
840
+ nestedKeys.set(first, [rest.join('.')]);
841
+ }
842
+ }
843
+ else {
844
+ directKeys.add(key);
846
845
  }
847
- else if (key in obj) {
846
+ }
847
+ const result = {};
848
+ for (const key of directKeys) {
849
+ if (key in obj)
848
850
  result[key] = obj[key];
851
+ }
852
+ for (const [first, restKeys] of nestedKeys) {
853
+ const val = obj[first];
854
+ if (!val || typeof val !== 'object')
855
+ continue;
856
+ if (Array.isArray(val)) {
857
+ result[first] = val.map(item => pick(item, restKeys));
858
+ }
859
+ else {
860
+ result[first] = pick(val, restKeys);
849
861
  }
850
862
  }
851
863
  return result;
@@ -814,32 +814,44 @@ export default class Health extends Command {
814
814
  filterFields(data, fields) {
815
815
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
816
816
  const pick = (obj, keys) => {
817
- const result = {};
817
+ // Group keys by their first segment so sibling sub-paths
818
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
819
+ // and don't clobber each other on merge.
820
+ const directKeys = new Set();
821
+ const nestedKeys = new Map();
818
822
  for (const key of keys) {
819
823
  if (key.split('.').some(isUnsafeKey))
820
824
  continue;
821
825
  if (key.includes('.')) {
822
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
823
826
  const [first, ...rest] = key.split('.');
824
- const val = obj[first];
825
- if (val && typeof val === 'object') {
826
- const restKey = rest.join('.');
827
- if (Array.isArray(val)) {
828
- // Map over array elements (e.g., allocations[].salesInvoiceId)
829
- const existing = Array.isArray(result[first]) ? result[first] : [];
830
- result[first] = val.map((item, i) => ({
831
- ...(existing[i] || {}),
832
- ...pick(item, [restKey]),
833
- }));
834
- }
835
- else {
836
- const nested = pick(val, [restKey]);
837
- result[first] = { ...(result[first] || {}), ...nested };
838
- }
827
+ if (isUnsafeKey(first))
828
+ continue;
829
+ const list = nestedKeys.get(first);
830
+ if (list) {
831
+ list.push(rest.join('.'));
839
832
  }
833
+ else {
834
+ nestedKeys.set(first, [rest.join('.')]);
835
+ }
836
+ }
837
+ else {
838
+ directKeys.add(key);
840
839
  }
841
- else if (key in obj) {
840
+ }
841
+ const result = {};
842
+ for (const key of directKeys) {
843
+ if (key in obj)
842
844
  result[key] = obj[key];
845
+ }
846
+ for (const [first, restKeys] of nestedKeys) {
847
+ const val = obj[first];
848
+ if (!val || typeof val !== 'object')
849
+ continue;
850
+ if (Array.isArray(val)) {
851
+ result[first] = val.map(item => pick(item, restKeys));
852
+ }
853
+ else {
854
+ result[first] = pick(val, restKeys);
843
855
  }
844
856
  }
845
857
  return result;
@@ -6,11 +6,13 @@ const HAS_IMPORT = false;
6
6
  const HAS_EXPORT = false;
7
7
  const HAS_CAMT053 = false;
8
8
  const NESTED_IMPORTS = [];
9
- const SUBCOMMANDS = [...["upload", "email-webhook", "document-types"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
9
+ const SUBCOMMANDS = [...["upload", "email-webhook", "document-types", "list-processing-logs", "processing-logs"], ...(HAS_IMPORT ? ['import'] : []), ...(HAS_EXPORT ? ['export'] : []), ...NESTED_IMPORTS.map(n => `import-${n}`)];
10
10
  const ENDPOINTS = {
11
- 'upload': { method: 'POST', path: '/v1/inbox/upload', summary: 'Upload document(s) to inbox for processing', pathParams: [], hasBody: false, isMultipart: false },
11
+ 'upload': { method: 'POST', path: '/v1/inbox/upload', summary: 'Upload document(s) to inbox for processing', pathParams: [], hasBody: false, isMultipart: true },
12
12
  'email-webhook': { method: 'POST', path: '/v1/inbox/email-webhook/{secret}', summary: 'Email webhook for document ingestion (SendGrid inbound-parse)', pathParams: ['secret'], hasBody: false, isMultipart: false },
13
13
  'document-types': { method: 'GET', path: '/v1/inbox/document-types', summary: 'Get available document types and per-parent allowed types', pathParams: [], hasBody: false, isMultipart: false },
14
+ 'list-processing-logs': { method: 'GET', path: '/v1/inbox/processing-logs', summary: 'List recent inbox processing logs (newest first)', pathParams: [], hasBody: false, isMultipart: false },
15
+ 'processing-logs': { method: 'GET', path: '/v1/inbox/processing-logs/{processingId}', summary: 'Get a processing run by its processing identifier', pathParams: ['processingId'], hasBody: false, isMultipart: false },
14
16
  };
15
17
  export default class Inbox extends Command {
16
18
  static description = 'Manage inbox';
@@ -810,32 +812,44 @@ export default class Inbox extends Command {
810
812
  filterFields(data, fields) {
811
813
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
812
814
  const pick = (obj, keys) => {
813
- const result = {};
815
+ // Group keys by their first segment so sibling sub-paths
816
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
817
+ // and don't clobber each other on merge.
818
+ const directKeys = new Set();
819
+ const nestedKeys = new Map();
814
820
  for (const key of keys) {
815
821
  if (key.split('.').some(isUnsafeKey))
816
822
  continue;
817
823
  if (key.includes('.')) {
818
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
819
824
  const [first, ...rest] = key.split('.');
820
- const val = obj[first];
821
- if (val && typeof val === 'object') {
822
- const restKey = rest.join('.');
823
- if (Array.isArray(val)) {
824
- // Map over array elements (e.g., allocations[].salesInvoiceId)
825
- const existing = Array.isArray(result[first]) ? result[first] : [];
826
- result[first] = val.map((item, i) => ({
827
- ...(existing[i] || {}),
828
- ...pick(item, [restKey]),
829
- }));
830
- }
831
- else {
832
- const nested = pick(val, [restKey]);
833
- result[first] = { ...(result[first] || {}), ...nested };
834
- }
825
+ if (isUnsafeKey(first))
826
+ continue;
827
+ const list = nestedKeys.get(first);
828
+ if (list) {
829
+ list.push(rest.join('.'));
835
830
  }
831
+ else {
832
+ nestedKeys.set(first, [rest.join('.')]);
833
+ }
834
+ }
835
+ else {
836
+ directKeys.add(key);
836
837
  }
837
- else if (key in obj) {
838
+ }
839
+ const result = {};
840
+ for (const key of directKeys) {
841
+ if (key in obj)
838
842
  result[key] = obj[key];
843
+ }
844
+ for (const [first, restKeys] of nestedKeys) {
845
+ const val = obj[first];
846
+ if (!val || typeof val !== 'object')
847
+ continue;
848
+ if (Array.isArray(val)) {
849
+ result[first] = val.map(item => pick(item, restKeys));
850
+ }
851
+ else {
852
+ result[first] = pick(val, restKeys);
839
853
  }
840
854
  }
841
855
  return result;
@@ -814,32 +814,44 @@ export default class Integrations extends Command {
814
814
  filterFields(data, fields) {
815
815
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
816
816
  const pick = (obj, keys) => {
817
- const result = {};
817
+ // Group keys by their first segment so sibling sub-paths
818
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
819
+ // and don't clobber each other on merge.
820
+ const directKeys = new Set();
821
+ const nestedKeys = new Map();
818
822
  for (const key of keys) {
819
823
  if (key.split('.').some(isUnsafeKey))
820
824
  continue;
821
825
  if (key.includes('.')) {
822
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
823
826
  const [first, ...rest] = key.split('.');
824
- const val = obj[first];
825
- if (val && typeof val === 'object') {
826
- const restKey = rest.join('.');
827
- if (Array.isArray(val)) {
828
- // Map over array elements (e.g., allocations[].salesInvoiceId)
829
- const existing = Array.isArray(result[first]) ? result[first] : [];
830
- result[first] = val.map((item, i) => ({
831
- ...(existing[i] || {}),
832
- ...pick(item, [restKey]),
833
- }));
834
- }
835
- else {
836
- const nested = pick(val, [restKey]);
837
- result[first] = { ...(result[first] || {}), ...nested };
838
- }
827
+ if (isUnsafeKey(first))
828
+ continue;
829
+ const list = nestedKeys.get(first);
830
+ if (list) {
831
+ list.push(rest.join('.'));
839
832
  }
833
+ else {
834
+ nestedKeys.set(first, [rest.join('.')]);
835
+ }
836
+ }
837
+ else {
838
+ directKeys.add(key);
840
839
  }
841
- else if (key in obj) {
840
+ }
841
+ const result = {};
842
+ for (const key of directKeys) {
843
+ if (key in obj)
842
844
  result[key] = obj[key];
845
+ }
846
+ for (const [first, restKeys] of nestedKeys) {
847
+ const val = obj[first];
848
+ if (!val || typeof val !== 'object')
849
+ continue;
850
+ if (Array.isArray(val)) {
851
+ result[first] = val.map(item => pick(item, restKeys));
852
+ }
853
+ else {
854
+ result[first] = pick(val, restKeys);
843
855
  }
844
856
  }
845
857
  return result;
@@ -819,32 +819,44 @@ export default class ItemCategories extends Command {
819
819
  filterFields(data, fields) {
820
820
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
821
821
  const pick = (obj, keys) => {
822
- const result = {};
822
+ // Group keys by their first segment so sibling sub-paths
823
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
824
+ // and don't clobber each other on merge.
825
+ const directKeys = new Set();
826
+ const nestedKeys = new Map();
823
827
  for (const key of keys) {
824
828
  if (key.split('.').some(isUnsafeKey))
825
829
  continue;
826
830
  if (key.includes('.')) {
827
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
828
831
  const [first, ...rest] = key.split('.');
829
- const val = obj[first];
830
- if (val && typeof val === 'object') {
831
- const restKey = rest.join('.');
832
- if (Array.isArray(val)) {
833
- // Map over array elements (e.g., allocations[].salesInvoiceId)
834
- const existing = Array.isArray(result[first]) ? result[first] : [];
835
- result[first] = val.map((item, i) => ({
836
- ...(existing[i] || {}),
837
- ...pick(item, [restKey]),
838
- }));
839
- }
840
- else {
841
- const nested = pick(val, [restKey]);
842
- result[first] = { ...(result[first] || {}), ...nested };
843
- }
832
+ if (isUnsafeKey(first))
833
+ continue;
834
+ const list = nestedKeys.get(first);
835
+ if (list) {
836
+ list.push(rest.join('.'));
844
837
  }
838
+ else {
839
+ nestedKeys.set(first, [rest.join('.')]);
840
+ }
841
+ }
842
+ else {
843
+ directKeys.add(key);
845
844
  }
846
- else if (key in obj) {
845
+ }
846
+ const result = {};
847
+ for (const key of directKeys) {
848
+ if (key in obj)
847
849
  result[key] = obj[key];
850
+ }
851
+ for (const [first, restKeys] of nestedKeys) {
852
+ const val = obj[first];
853
+ if (!val || typeof val !== 'object')
854
+ continue;
855
+ if (Array.isArray(val)) {
856
+ result[first] = val.map(item => pick(item, restKeys));
857
+ }
858
+ else {
859
+ result[first] = pick(val, restKeys);
848
860
  }
849
861
  }
850
862
  return result;
@@ -819,32 +819,44 @@ export default class Items extends Command {
819
819
  filterFields(data, fields) {
820
820
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
821
821
  const pick = (obj, keys) => {
822
- const result = {};
822
+ // Group keys by their first segment so sibling sub-paths
823
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
824
+ // and don't clobber each other on merge.
825
+ const directKeys = new Set();
826
+ const nestedKeys = new Map();
823
827
  for (const key of keys) {
824
828
  if (key.split('.').some(isUnsafeKey))
825
829
  continue;
826
830
  if (key.includes('.')) {
827
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
828
831
  const [first, ...rest] = key.split('.');
829
- const val = obj[first];
830
- if (val && typeof val === 'object') {
831
- const restKey = rest.join('.');
832
- if (Array.isArray(val)) {
833
- // Map over array elements (e.g., allocations[].salesInvoiceId)
834
- const existing = Array.isArray(result[first]) ? result[first] : [];
835
- result[first] = val.map((item, i) => ({
836
- ...(existing[i] || {}),
837
- ...pick(item, [restKey]),
838
- }));
839
- }
840
- else {
841
- const nested = pick(val, [restKey]);
842
- result[first] = { ...(result[first] || {}), ...nested };
843
- }
832
+ if (isUnsafeKey(first))
833
+ continue;
834
+ const list = nestedKeys.get(first);
835
+ if (list) {
836
+ list.push(rest.join('.'));
844
837
  }
838
+ else {
839
+ nestedKeys.set(first, [rest.join('.')]);
840
+ }
841
+ }
842
+ else {
843
+ directKeys.add(key);
845
844
  }
846
- else if (key in obj) {
845
+ }
846
+ const result = {};
847
+ for (const key of directKeys) {
848
+ if (key in obj)
847
849
  result[key] = obj[key];
850
+ }
851
+ for (const [first, restKeys] of nestedKeys) {
852
+ const val = obj[first];
853
+ if (!val || typeof val !== 'object')
854
+ continue;
855
+ if (Array.isArray(val)) {
856
+ result[first] = val.map(item => pick(item, restKeys));
857
+ }
858
+ else {
859
+ result[first] = pick(val, restKeys);
848
860
  }
849
861
  }
850
862
  return result;
@@ -811,32 +811,44 @@ export default class JournalLines extends Command {
811
811
  filterFields(data, fields) {
812
812
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
813
813
  const pick = (obj, keys) => {
814
- const result = {};
814
+ // Group keys by their first segment so sibling sub-paths
815
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
816
+ // and don't clobber each other on merge.
817
+ const directKeys = new Set();
818
+ const nestedKeys = new Map();
815
819
  for (const key of keys) {
816
820
  if (key.split('.').some(isUnsafeKey))
817
821
  continue;
818
822
  if (key.includes('.')) {
819
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
820
823
  const [first, ...rest] = key.split('.');
821
- const val = obj[first];
822
- if (val && typeof val === 'object') {
823
- const restKey = rest.join('.');
824
- if (Array.isArray(val)) {
825
- // Map over array elements (e.g., allocations[].salesInvoiceId)
826
- const existing = Array.isArray(result[first]) ? result[first] : [];
827
- result[first] = val.map((item, i) => ({
828
- ...(existing[i] || {}),
829
- ...pick(item, [restKey]),
830
- }));
831
- }
832
- else {
833
- const nested = pick(val, [restKey]);
834
- result[first] = { ...(result[first] || {}), ...nested };
835
- }
824
+ if (isUnsafeKey(first))
825
+ continue;
826
+ const list = nestedKeys.get(first);
827
+ if (list) {
828
+ list.push(rest.join('.'));
836
829
  }
830
+ else {
831
+ nestedKeys.set(first, [rest.join('.')]);
832
+ }
833
+ }
834
+ else {
835
+ directKeys.add(key);
837
836
  }
838
- else if (key in obj) {
837
+ }
838
+ const result = {};
839
+ for (const key of directKeys) {
840
+ if (key in obj)
839
841
  result[key] = obj[key];
842
+ }
843
+ for (const [first, restKeys] of nestedKeys) {
844
+ const val = obj[first];
845
+ if (!val || typeof val !== 'object')
846
+ continue;
847
+ if (Array.isArray(val)) {
848
+ result[first] = val.map(item => pick(item, restKeys));
849
+ }
850
+ else {
851
+ result[first] = pick(val, restKeys);
840
852
  }
841
853
  }
842
854
  return result;
@@ -835,32 +835,44 @@ export default class Journals extends Command {
835
835
  filterFields(data, fields) {
836
836
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
837
837
  const pick = (obj, keys) => {
838
- const result = {};
838
+ // Group keys by their first segment so sibling sub-paths
839
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
840
+ // and don't clobber each other on merge.
841
+ const directKeys = new Set();
842
+ const nestedKeys = new Map();
839
843
  for (const key of keys) {
840
844
  if (key.split('.').some(isUnsafeKey))
841
845
  continue;
842
846
  if (key.includes('.')) {
843
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
844
847
  const [first, ...rest] = key.split('.');
845
- const val = obj[first];
846
- if (val && typeof val === 'object') {
847
- const restKey = rest.join('.');
848
- if (Array.isArray(val)) {
849
- // Map over array elements (e.g., allocations[].salesInvoiceId)
850
- const existing = Array.isArray(result[first]) ? result[first] : [];
851
- result[first] = val.map((item, i) => ({
852
- ...(existing[i] || {}),
853
- ...pick(item, [restKey]),
854
- }));
855
- }
856
- else {
857
- const nested = pick(val, [restKey]);
858
- result[first] = { ...(result[first] || {}), ...nested };
859
- }
848
+ if (isUnsafeKey(first))
849
+ continue;
850
+ const list = nestedKeys.get(first);
851
+ if (list) {
852
+ list.push(rest.join('.'));
860
853
  }
854
+ else {
855
+ nestedKeys.set(first, [rest.join('.')]);
856
+ }
857
+ }
858
+ else {
859
+ directKeys.add(key);
861
860
  }
862
- else if (key in obj) {
861
+ }
862
+ const result = {};
863
+ for (const key of directKeys) {
864
+ if (key in obj)
863
865
  result[key] = obj[key];
866
+ }
867
+ for (const [first, restKeys] of nestedKeys) {
868
+ const val = obj[first];
869
+ if (!val || typeof val !== 'object')
870
+ continue;
871
+ if (Array.isArray(val)) {
872
+ result[first] = val.map(item => pick(item, restKeys));
873
+ }
874
+ else {
875
+ result[first] = pick(val, restKeys);
864
876
  }
865
877
  }
866
878
  return result;
@@ -832,32 +832,44 @@ export default class Ledgers extends Command {
832
832
  filterFields(data, fields) {
833
833
  const isUnsafeKey = (k) => k === '__proto__' || k === 'constructor' || k === 'prototype';
834
834
  const pick = (obj, keys) => {
835
- const result = {};
835
+ // Group keys by their first segment so sibling sub-paths
836
+ // (e.g. 'items.amount' + 'items._type') resolve in one recursive pass
837
+ // and don't clobber each other on merge.
838
+ const directKeys = new Set();
839
+ const nestedKeys = new Map();
836
840
  for (const key of keys) {
837
841
  if (key.split('.').some(isUnsafeKey))
838
842
  continue;
839
843
  if (key.includes('.')) {
840
- // Handle nested fields like 'customer.name' or 'allocations.salesInvoiceId'
841
844
  const [first, ...rest] = key.split('.');
842
- const val = obj[first];
843
- if (val && typeof val === 'object') {
844
- const restKey = rest.join('.');
845
- if (Array.isArray(val)) {
846
- // Map over array elements (e.g., allocations[].salesInvoiceId)
847
- const existing = Array.isArray(result[first]) ? result[first] : [];
848
- result[first] = val.map((item, i) => ({
849
- ...(existing[i] || {}),
850
- ...pick(item, [restKey]),
851
- }));
852
- }
853
- else {
854
- const nested = pick(val, [restKey]);
855
- result[first] = { ...(result[first] || {}), ...nested };
856
- }
845
+ if (isUnsafeKey(first))
846
+ continue;
847
+ const list = nestedKeys.get(first);
848
+ if (list) {
849
+ list.push(rest.join('.'));
857
850
  }
851
+ else {
852
+ nestedKeys.set(first, [rest.join('.')]);
853
+ }
854
+ }
855
+ else {
856
+ directKeys.add(key);
858
857
  }
859
- else if (key in obj) {
858
+ }
859
+ const result = {};
860
+ for (const key of directKeys) {
861
+ if (key in obj)
860
862
  result[key] = obj[key];
863
+ }
864
+ for (const [first, restKeys] of nestedKeys) {
865
+ const val = obj[first];
866
+ if (!val || typeof val !== 'object')
867
+ continue;
868
+ if (Array.isArray(val)) {
869
+ result[first] = val.map(item => pick(item, restKeys));
870
+ }
871
+ else {
872
+ result[first] = pick(val, restKeys);
861
873
  }
862
874
  }
863
875
  return result;