{"version":3,"sources":["../../../../src/accounting/invoices/__tests__/links.test.ts","../../../../src/common/instance/operations.ts","../../../../src/accounting/attachments/requests.ts","../../../../src/accounting/contacts/links.ts","../../../../src/utils/properties.ts","../../../../src/accounting/invoices/lineItems.ts","../../../../src/accounting/invoices/links.ts","../../../../src/accounting/journals/links.ts","../../../../src/projects/timeEntries.ts"],"sourcesContent":["import { Invoice } from 'xero-node';\r\n\r\nimport { getInvoiceLink } from '../../../index';\r\n\r\ndescribe('invoices/links', () => {\r\n  describe('getInvoiceLink()', () => {\r\n    it('returns a null indicator if passed undefined', () => {\r\n      // @ts-expect-error - This is an invalid type for the function.\r\n      expect(getInvoiceLink()).toBe(\r\n        'https://invoicing.xero.com/view/null-or-empty-invoice-id',\r\n      );\r\n    });\r\n\r\n    it('returns a null indicator if passed null', () => {\r\n      // @ts-expect-error - This is an invalid type for the function.\r\n      expect(getInvoiceLink(null)).toBe(\r\n        'https://invoicing.xero.com/view/null-or-empty-invoice-id',\r\n      );\r\n    });\r\n\r\n    it('returns a null indicator if passed an empty string', () => {\r\n      expect(getInvoiceLink('')).toBe(\r\n        'https://invoicing.xero.com/view/null-or-empty-invoice-id',\r\n      );\r\n    });\r\n\r\n    it('returns the correct URL for an invoice object with an invoiceID property', () => {\r\n      const invoice = new Invoice();\r\n      /* eslint-disable functional/immutable-data */\r\n      invoice.invoiceID = '25OR6TO4';\r\n      /* eslint-enable functional/immutable-data */\r\n      expect(getInvoiceLink(invoice)).toBe(\r\n        'https://invoicing.xero.com/view/25OR6TO4',\r\n      );\r\n    });\r\n\r\n    it('returns the correct URL for a string invoice ID', () => {\r\n      expect(getInvoiceLink('kooolaid-9086-t728')).toBe(\r\n        'https://invoicing.xero.com/view/kooolaid-9086-t728',\r\n      );\r\n    });\r\n\r\n    it('should work with an object that matches the interface for having a invoiceID property', () => {\r\n      const invoice = { invoiceID: '25OR6TO4' };\r\n      expect(getInvoiceLink(invoice)).toBe(\r\n        'https://invoicing.xero.com/view/25OR6TO4',\r\n      );\r\n    });\r\n  });\r\n});\r\n","import { isObject } from 'deep-cuts';\r\n\r\nexport const deepClone = <T extends object>(instance: T): T => {\r\n  if (instance && isObject(instance)) {\r\n    const { constructor } = instance;\r\n    // @ts-expect-error - This is not passing for TypeScript, bit will for any Xero class.\r\n    const clone = new constructor();\r\n    /* eslint-disable guard-for-in, functional/immutable-data */\r\n    for (const key in instance) {\r\n      clone[key] = deepClone(instance[key] as object);\r\n    }\r\n    /* eslint-enable guard-for-in, functional/immutable-data */\r\n\r\n    return clone;\r\n  }\r\n\r\n  return instance;\r\n};\r\n","import type { ReadStream } from 'node:fs';\r\nimport type http from 'node:http';\r\n\r\nimport { bufferToStream } from 'tranquil-stream';\r\nimport type { Attachments, XeroClient } from 'xero-node';\r\n\r\ntype ICreateInvoiceAttachmentParameters = {\r\n  contents: Buffer;\r\n  filename: string;\r\n  invoiceId: string;\r\n};\r\n\r\nexport const createInvoiceAttachment = async (\r\n  client: XeroClient,\r\n  tenantId: string,\r\n  { invoiceId, filename, contents }: ICreateInvoiceAttachmentParameters,\r\n): Promise<{\r\n  body: Attachments;\r\n  response: http.IncomingMessage;\r\n}> => {\r\n  return client.accountingApi.createInvoiceAttachmentByFileName(\r\n    tenantId,\r\n    invoiceId,\r\n    filename,\r\n    bufferToStream(contents) as unknown as ReadStream,\r\n  );\r\n};\r\n","import qs from 'qs';\r\nimport type { Contact } from 'xero-node';\r\n\r\nimport { hasProperty } from '../../utils/properties';\r\n\r\nexport const getContactLink = (contact: Contact | string): string => {\r\n  return `https://go.xero.com/Contacts/View.aspx?${qs.stringify({\r\n    contactID:\r\n      (hasProperty(contact, 'contactID')\r\n        ? (contact as Contact).contactID\r\n        : contact) || 'null-or-empty-contact-id',\r\n  })}`;\r\n};\r\n","export const hasProperty = (object: any, property: string): boolean => {\r\n  if (Boolean(object) && typeof object === 'object') {\r\n    return property in object;\r\n  }\r\n\r\n  return false;\r\n};\r\n","import { isNil } from 'deep-cuts';\r\nimport type { LineItem } from 'xero-node';\r\n\r\nimport type { DecisionFunction } from '../../types';\r\n\r\nexport const filterInvoiceLineItems = (\r\n  lineItems: LineItem[],\r\n  minCode: DecisionFunction<LineItem> | string | number,\r\n  maxCode?: string | number,\r\n): LineItem[] => {\r\n  if (typeof minCode === 'function') {\r\n    return (lineItems || []).filter(minCode);\r\n  }\r\n\r\n  const parsedMinCode = isNil(minCode)\r\n    ? minCode\r\n    : Number.parseInt(minCode as string, 10);\r\n  const parsedMaxCode = isNil(maxCode)\r\n    ? maxCode\r\n    : Number.parseInt(maxCode as string, 10);\r\n  if (parsedMinCode || parsedMaxCode) {\r\n    return (lineItems || []).filter(({ itemCode }) => {\r\n      const parsedItemCode = isNil(itemCode)\r\n        ? itemCode\r\n        : Number.parseInt(itemCode as string, 10);\r\n      if (parsedItemCode) {\r\n        const greaterThanOrEqualToMinCode = isNil(parsedMinCode)\r\n          ? true\r\n          : parsedItemCode >= parsedMinCode;\r\n        const lessThanOrEqualToMaxCode = isNil(parsedMaxCode)\r\n          ? true\r\n          : parsedItemCode <= (parsedMaxCode || 0);\r\n        return greaterThanOrEqualToMinCode && lessThanOrEqualToMaxCode;\r\n      }\r\n\r\n      return false;\r\n    });\r\n  }\r\n\r\n  return lineItems || [];\r\n};\r\n","import type { Invoice } from 'xero-node';\r\n\r\nimport { hasProperty } from '../../utils/properties';\r\n\r\nexport const getInvoiceLink = (invoice: Invoice | string): string => {\r\n  return `https://invoicing.xero.com/view/${\r\n    (hasProperty(invoice, 'invoiceID')\r\n      ? (invoice as Invoice).invoiceID\r\n      : invoice) || 'null-or-empty-invoice-id'\r\n  }`;\r\n};\r\n","import qs from 'qs';\r\nimport type { ManualJournal } from 'xero-node';\r\n\r\nimport { hasProperty } from '../../utils/properties';\r\n\r\nexport const getManualJournalLink = (\r\n  manualJournal: ManualJournal | string,\r\n): string => {\r\n  return `https://go.xero.com/Journal/View.aspx?${qs.stringify({\r\n    invoiceID:\r\n      (hasProperty(manualJournal, 'manualJournalID')\r\n        ? (manualJournal as ManualJournal).manualJournalID\r\n        : manualJournal) || 'null-or-empty-manual-journal-id',\r\n  })}`;\r\n};\r\n","import { roundToNearestFraction } from 'deep-cuts';\r\n\r\nimport type { TimeEntry } from './shimTypes';\r\n\r\nexport const hoursFromTimeEntries = (\r\n  timeEntries: TimeEntry[],\r\n  denominator: number = 4,\r\n  maxDecimalPlaces: number = 2,\r\n): number | undefined => {\r\n  const totalMinutes = timeEntries.reduce((totalMinutes, timeEntry) => {\r\n    const duration = timeEntry.duration || 0;\r\n    return totalMinutes + duration;\r\n  }, 0);\r\n  return roundToNearestFraction(\r\n    totalMinutes / 60,\r\n    denominator,\r\n    maxDecimalPlaces,\r\n  );\r\n};\r\n"],"mappings":";AAAA,SAAS,eAAe;;;ACAxB,SAAS,gBAAgB;;;ACGzB,SAAS,sBAAsB;;;ACH/B,OAAO,QAAQ;;;ACAR,IAAM,cAAc,CAAC,QAAa,aAA8B;AACrE,MAAI,QAAQ,MAAM,KAAK,OAAO,WAAW,UAAU;AACjD,WAAO,YAAY;AAAA,EACrB;AAEA,SAAO;AACT;;;ACNA,SAAS,aAAa;;;ACIf,IAAM,iBAAiB,CAAC,YAAsC;AACnE,SAAO,oCACJ,YAAY,SAAS,WAAW,IAC5B,QAAoB,YACrB,YAAY,0BAClB;AACF;;;ACVA,OAAOA,SAAQ;;;ACAf,SAAS,8BAA8B;;;ARIvC,SAAS,kBAAkB,MAAM;AAC/B,WAAS,oBAAoB,MAAM;AACjC,OAAG,gDAAgD,MAAM;AAEvD,aAAO,eAAe,CAAC,EAAE;AAAA,QACvB;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,2CAA2C,MAAM;AAElD,aAAO,eAAe,IAAI,CAAC,EAAE;AAAA,QAC3B;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,sDAAsD,MAAM;AAC7D,aAAO,eAAe,EAAE,CAAC,EAAE;AAAA,QACzB;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,4EAA4E,MAAM;AACnF,YAAM,UAAU,IAAI,QAAQ;AAE5B,cAAQ,YAAY;AAEpB,aAAO,eAAe,OAAO,CAAC,EAAE;AAAA,QAC9B;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,mDAAmD,MAAM;AAC1D,aAAO,eAAe,oBAAoB,CAAC,EAAE;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,yFAAyF,MAAM;AAChG,YAAM,UAAU,EAAE,WAAW,WAAW;AACxC,aAAO,eAAe,OAAO,CAAC,EAAE;AAAA,QAC9B;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":["qs"]}