UNPKG

@accounter/gmail-listener

Version:

A Gmail listener that listens for new emails, extracts financial documents, and sends them to the server

2,639 lines (2,634 loc) • 354 kB
// src/index.ts import { timingSafeEqual } from "crypto"; import { createServer } from "http"; // src/environment.ts import { config as dotenv } from "dotenv"; import zod from "zod"; dotenv({ path: [`.env`, `../../.env`] }); var AuthorizationModel = zod.object({ GMAIL_LISTENER_API_KEY: zod.string() }); var GmailModel = zod.object({ GMAIL_CLIENT_ID: zod.string(), GMAIL_CLIENT_SECRET: zod.string(), GMAIL_REFRESH_TOKEN: zod.string(), GMAIL_LABEL_PATH: zod.string().optional(), GOOGLE_CLOUD_PROJECT_ID: zod.string(), GOOGLE_APPLICATION_CREDENTIALS: zod.string(), PUBSUB_TOPIC: zod.string().optional(), PUBSUB_SUBSCRIPTION: zod.string().optional() }); var GeneralModel = zod.object({ SERVER_URL: zod.url(), PORT: zod.coerce.number().optional().default(3e3) }); var configs = { authorization: AuthorizationModel.safeParse(process.env), gmail: GmailModel.safeParse(process.env), general: GeneralModel.safeParse(process.env) }; var environmentErrors = []; for (const config of Object.values(configs)) { if (config.success === false) { environmentErrors.push(JSON.stringify(config.error.format(), null, 4)); } } if (environmentErrors.length) { const fullError = environmentErrors.join(` `); console.error("[env] Invalid environment variables:", fullError); process.exit(1); } function extractConfig(config) { if (!config.success) { throw new Error("Something went wrong."); } return config.data; } var authorization = extractConfig(configs.authorization); var gmail = extractConfig(configs.gmail); var general = extractConfig(configs.general); var env = { authorization: { apiKey: authorization.GMAIL_LISTENER_API_KEY }, gmail: { clientId: gmail.GMAIL_CLIENT_ID, clientSecret: gmail.GMAIL_CLIENT_SECRET, refreshToken: gmail.GMAIL_REFRESH_TOKEN, labelPath: gmail.GMAIL_LABEL_PATH?.replace(/\/$/, "") || "accounter/documents", // Default label if not specified cloudProjectId: gmail.GOOGLE_CLOUD_PROJECT_ID, appCredentials: gmail.GOOGLE_APPLICATION_CREDENTIALS, topicName: gmail.PUBSUB_TOPIC || "gmail-notifications", subscriptionName: gmail.PUBSUB_SUBSCRIPTION || "gmail-notifications-sub" }, general: { serverUrl: general.SERVER_URL, port: general.PORT } }; // src/gmail-service.ts import { google as google2 } from "googleapis"; import inlineCss from "inline-css"; import { chromium } from "playwright"; // src/server-requests.ts import { fetch as fetch2, FormData } from "@whatwg-node/fetch"; // src/gql/graphql.ts var TypedDocumentString = class extends String { __apiType; value; __meta__; constructor(value, __meta__) { super(value); this.value = value; this.__meta__ = __meta__; } toString() { return this.value; } }; var DepositTransactionFieldsFragmentDoc = new TypedDocumentString(` fragment DepositTransactionFields on Transaction { id eventDate chargeId amount { raw formatted currency } debitExchangeRates { aud cad eur gbp jpy sek usd date } eventExchangeRates { aud cad eur gbp jpy sek usd date } } `, { "fragmentName": "DepositTransactionFields" }); var BusinessTripsRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripsRowFields on BusinessTrip { id name accountantApproval } `, { "fragmentName": "BusinessTripsRowFields" }); var ClientIntegrationsSectionFragmentDoc = new TypedDocumentString(` fragment ClientIntegrationsSection on LtdFinancialEntity { id clientInfo { id integrations { id greenInvoiceInfo { businessId greenInvoiceId } hiveId linearId slackChannelKey notionId workflowyUrl } } } `, { "fragmentName": "ClientIntegrationsSection" }); var BusinessHeaderFragmentDoc = new TypedDocumentString(` fragment BusinessHeader on Business { __typename id name createdAt isActive ... on LtdFinancialEntity { governmentId adminInfo { id } clientInfo { id } } } `, { "fragmentName": "BusinessHeader" }); var BusinessContactSectionFragmentDoc = new TypedDocumentString(` fragment BusinessContactSection on Business { __typename id ... on LtdFinancialEntity { name hebrewName country { id code } governmentId address city zipCode email phoneNumber website clientInfo { id emails } } } `, { "fragmentName": "BusinessContactSection" }); var BusinessConfigurationSectionFragmentDoc = new TypedDocumentString(` fragment BusinessConfigurationSection on Business { __typename id pcn874RecordType irsCode isActive ownerId ... on LtdFinancialEntity { optionalVAT exemptDealer isReceiptEnough isDocumentsOptional sortCode { id key defaultIrsCode } taxCategory { id } suggestions { phrases emails tags { id } description emailListener { internalEmailLinks emailBody attachments } } clientInfo { id } } } `, { "fragmentName": "BusinessConfigurationSection" }); var BusinessAdminSectionFragmentDoc = new TypedDocumentString(` fragment BusinessAdminSection on Business { __typename id ... on LtdFinancialEntity { adminInfo { id registrationDate withholdingTaxAnnualIds { id year } withholdingTaxCompanyId socialSecurityEmployerIds { id year } socialSecurityDeductionsId taxAdvancesAnnualIds { id year } taxAdvancesRates { date rate } } } } `, { "fragmentName": "BusinessAdminSection" }); var BusinessPageFragmentDoc = new TypedDocumentString(` fragment BusinessPage on Business { id ... on LtdFinancialEntity { clientInfo { id } adminInfo { id } } ...ClientIntegrationsSection ...BusinessHeader ...BusinessContactSection ...BusinessConfigurationSection ...BusinessAdminSection } fragment BusinessAdminSection on Business { __typename id ... on LtdFinancialEntity { adminInfo { id registrationDate withholdingTaxAnnualIds { id year } withholdingTaxCompanyId socialSecurityEmployerIds { id year } socialSecurityDeductionsId taxAdvancesAnnualIds { id year } taxAdvancesRates { date rate } } } } fragment BusinessHeader on Business { __typename id name createdAt isActive ... on LtdFinancialEntity { governmentId adminInfo { id } clientInfo { id } } } fragment ClientIntegrationsSection on LtdFinancialEntity { id clientInfo { id integrations { id greenInvoiceInfo { businessId greenInvoiceId } hiveId linearId slackChannelKey notionId workflowyUrl } } } fragment BusinessConfigurationSection on Business { __typename id pcn874RecordType irsCode isActive ownerId ... on LtdFinancialEntity { optionalVAT exemptDealer isReceiptEnough isDocumentsOptional sortCode { id key defaultIrsCode } taxCategory { id } suggestions { phrases emails tags { id } description emailListener { internalEmailLinks emailBody attachments } } clientInfo { id } } } fragment BusinessContactSection on Business { __typename id ... on LtdFinancialEntity { name hebrewName country { id code } governmentId address city zipCode email phoneNumber website clientInfo { id emails } } }`, { "fragmentName": "BusinessPage" }); var ChargeMatchesTableFieldsFragmentDoc = new TypedDocumentString(` fragment ChargeMatchesTableFields on ChargeMatch { charge { id __typename minEventDate minDebitDate minDocumentsDate totalAmount { raw formatted } vat { raw formatted } counterparty { name id } userDescription tags { id name namePath } taxCategory { id name } } confidenceScore } `, { "fragmentName": "ChargeMatchesTableFields" }); var ChargesTableErrorsFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableErrorsFields on Charge { id errorsLedger: ledger { validate { errors } } } `, { "fragmentName": "ChargesTableErrorsFields" }); var TableDocumentsRowFieldsFragmentDoc = new TypedDocumentString(` fragment TableDocumentsRowFields on Document { id documentType image file description remarks charge { id } ... on FinancialDocument { amount { raw formatted currency } missingInfoSuggestions { amount { raw formatted currency } isIncome counterparty { id name } owner { id name } } date vat { raw formatted currency } serialNumber allocationNumber creditor { id name } debtor { id name } issuedDocumentInfo { id status originalDocument { income { description } } } } } `, { "fragmentName": "TableDocumentsRowFields" }); var TableDocumentsFieldsFragmentDoc = new TypedDocumentString(` fragment TableDocumentsFields on Charge { id additionalDocuments { id ...TableDocumentsRowFields } } fragment TableDocumentsRowFields on Document { id documentType image file description remarks charge { id } ... on FinancialDocument { amount { raw formatted currency } missingInfoSuggestions { amount { raw formatted currency } isIncome counterparty { id name } owner { id name } } date vat { raw formatted currency } serialNumber allocationNumber creditor { id name } debtor { id name } issuedDocumentInfo { id status originalDocument { income { description } } } } }`, { "fragmentName": "TableDocumentsFields" }); var LedgerRecordsTableFieldsFragmentDoc = new TypedDocumentString(` fragment LedgerRecordsTableFields on LedgerRecord { id creditAccount1 { __typename id name } creditAccount2 { __typename id name } debitAccount1 { __typename id name } debitAccount2 { __typename id name } creditAmount1 { formatted currency } creditAmount2 { formatted currency } debitAmount1 { formatted currency } debitAmount2 { formatted currency } localCurrencyCreditAmount1 { formatted raw } localCurrencyCreditAmount2 { formatted raw } localCurrencyDebitAmount1 { formatted raw } localCurrencyDebitAmount2 { formatted raw } invoiceDate valueDate description reference } `, { "fragmentName": "LedgerRecordsTableFields" }); var ChargeLedgerRecordsTableFieldsFragmentDoc = new TypedDocumentString(` fragment ChargeLedgerRecordsTableFields on Charge { id ledger { __typename records { id ...LedgerRecordsTableFields } ... on Ledger @defer { validate { ... on LedgerValidation @defer { matches differences { id ...LedgerRecordsTableFields } } } } } } fragment LedgerRecordsTableFields on LedgerRecord { id creditAccount1 { __typename id name } creditAccount2 { __typename id name } debitAccount1 { __typename id name } debitAccount2 { __typename id name } creditAmount1 { formatted currency } creditAmount2 { formatted currency } debitAmount1 { formatted currency } debitAmount2 { formatted currency } localCurrencyCreditAmount1 { formatted raw } localCurrencyCreditAmount2 { formatted raw } localCurrencyDebitAmount1 { formatted raw } localCurrencyDebitAmount2 { formatted raw } invoiceDate valueDate description reference }`, { "fragmentName": "ChargeLedgerRecordsTableFields" }); var TransactionForTransactionsTableFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionForTransactionsTableFields on Transaction { id isFee chargeId eventDate effectiveDate sourceEffectiveDate amount { raw formatted } cryptoExchangeRate { rate } account { id name type } sourceDescription referenceKey counterparty { name id } missingInfoSuggestions { business { id name } } } `, { "fragmentName": "TransactionForTransactionsTableFields" }); var ChargeTableTransactionsFieldsFragmentDoc = new TypedDocumentString(` fragment ChargeTableTransactionsFields on Charge { id transactions { id ...TransactionForTransactionsTableFields } } fragment TransactionForTransactionsTableFields on Transaction { id isFee chargeId eventDate effectiveDate sourceEffectiveDate amount { raw formatted } cryptoExchangeRate { rate } account { id name type } sourceDescription referenceKey counterparty { name id } missingInfoSuggestions { business { id name } } }`, { "fragmentName": "ChargeTableTransactionsFields" }); var ConversionChargeInfoFragmentDoc = new TypedDocumentString(` fragment ConversionChargeInfo on Charge { id __typename ... on ConversionCharge { eventRate { from to rate } officialRate { from to rate } } } `, { "fragmentName": "ConversionChargeInfo" }); var CreditcardBankChargeInfoFragmentDoc = new TypedDocumentString(` fragment CreditcardBankChargeInfo on Charge { id __typename ... on CreditcardBankCharge { creditCardTransactions { id ...TransactionForTransactionsTableFields } } } fragment TransactionForTransactionsTableFields on Transaction { id isFee chargeId eventDate effectiveDate sourceEffectiveDate amount { raw formatted } cryptoExchangeRate { rate } account { id name type } sourceDescription referenceKey counterparty { name id } missingInfoSuggestions { business { id name } } }`, { "fragmentName": "CreditcardBankChargeInfo" }); var ExchangeRatesInfoFragmentDoc = new TypedDocumentString(` fragment ExchangeRatesInfo on Charge { id __typename ... on FinancialCharge { exchangeRates { aud cad eur gbp ils jpy sek usd eth grt usdc } } } `, { "fragmentName": "ExchangeRatesInfo" }); var EditMiscExpenseFieldsFragmentDoc = new TypedDocumentString(` fragment EditMiscExpenseFields on MiscExpense { id amount { raw currency } description invoiceDate valueDate creditor { id } debtor { id } } `, { "fragmentName": "EditMiscExpenseFields" }); var TableMiscExpensesFieldsFragmentDoc = new TypedDocumentString(` fragment TableMiscExpensesFields on Charge { id miscExpenses { id amount { formatted } description invoiceDate valueDate creditor { id name } debtor { id name } chargeId ...EditMiscExpenseFields } } fragment EditMiscExpenseFields on MiscExpense { id amount { raw currency } description invoiceDate valueDate creditor { id } debtor { id } }`, { "fragmentName": "TableMiscExpensesFields" }); var TableSalariesFieldsFragmentDoc = new TypedDocumentString(` fragment TableSalariesFields on Charge { id __typename ... on SalaryCharge { salaryRecords { directAmount { formatted } baseAmount { formatted } employee { id name } pensionFund { id name } pensionEmployeeAmount { formatted } pensionEmployerAmount { formatted } compensationsAmount { formatted } trainingFund { id name } trainingFundEmployeeAmount { formatted } trainingFundEmployerAmount { formatted } socialSecurityEmployeeAmount { formatted } socialSecurityEmployerAmount { formatted } incomeTaxAmount { formatted } healthInsuranceAmount { formatted } } } } `, { "fragmentName": "TableSalariesFields" }); var MonthlyIncomeExpenseChartInfoFragmentDoc = new TypedDocumentString(` fragment MonthlyIncomeExpenseChartInfo on IncomeExpenseChart { monthlyData { income { formatted raw } expense { formatted raw } balance { formatted raw } date } } `, { "fragmentName": "MonthlyIncomeExpenseChartInfo" }); var BusinessTripAccountantApprovalFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripAccountantApprovalFields on BusinessTrip { id accountantApproval } `, { "fragmentName": "BusinessTripAccountantApprovalFields" }); var BusinessTripReportHeaderFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportHeaderFields on BusinessTrip { id name dates { start end } purpose destination { id name } ...BusinessTripAccountantApprovalFields } fragment BusinessTripAccountantApprovalFields on BusinessTrip { id accountantApproval }`, { "fragmentName": "BusinessTripReportHeaderFields" }); var BusinessTripReportSummaryFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportSummaryFields on BusinessTrip { id ... on BusinessTrip @defer { summary { excessExpenditure { formatted } excessTax rows { type totalForeignCurrency { formatted } totalLocalCurrency { formatted } taxableForeignCurrency { formatted } taxableLocalCurrency { formatted } maxTaxableForeignCurrency { formatted } maxTaxableLocalCurrency { formatted } excessExpenditure { formatted } } errors } } } `, { "fragmentName": "BusinessTripReportSummaryFields" }); var BusinessTripReportFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportFields on BusinessTrip { id ...BusinessTripReportHeaderFields ...BusinessTripReportSummaryFields } fragment BusinessTripAccountantApprovalFields on BusinessTrip { id accountantApproval } fragment BusinessTripReportHeaderFields on BusinessTrip { id name dates { start end } purpose destination { id name } ...BusinessTripAccountantApprovalFields } fragment BusinessTripReportSummaryFields on BusinessTrip { id ... on BusinessTrip @defer { summary { excessExpenditure { formatted } excessTax rows { type totalForeignCurrency { formatted } totalLocalCurrency { formatted } taxableForeignCurrency { formatted } taxableLocalCurrency { formatted } maxTaxableForeignCurrency { formatted } maxTaxableLocalCurrency { formatted } excessExpenditure { formatted } } errors } } }`, { "fragmentName": "BusinessTripReportFields" }); var BusinessTripReportCoreExpenseRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } `, { "fragmentName": "BusinessTripReportCoreExpenseRowFields" }); var BusinessTripReportAccommodationsRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportAccommodationsRowFields on BusinessTripAccommodationExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee country { id name } nightsCount attendeesStay { id attendee { id name } nightsCount } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportAccommodationsRowFields" }); var BusinessTripReportAccommodationsTableFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportAccommodationsTableFields on BusinessTripAccommodationExpense { id date ...BusinessTripReportAccommodationsRowFields } fragment BusinessTripReportAccommodationsRowFields on BusinessTripAccommodationExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee country { id name } nightsCount attendeesStay { id attendee { id name } nightsCount } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportAccommodationsTableFields" }); var BusinessTripReportAccommodationsFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportAccommodationsFields on BusinessTrip { id accommodationExpenses { id ...BusinessTripReportAccommodationsTableFields } } fragment BusinessTripReportAccommodationsRowFields on BusinessTripAccommodationExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee country { id name } nightsCount attendeesStay { id attendee { id name } nightsCount } } fragment BusinessTripReportAccommodationsTableFields on BusinessTripAccommodationExpense { id date ...BusinessTripReportAccommodationsRowFields } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportAccommodationsFields" }); var BusinessTripReportFlightsRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportFlightsRowFields on BusinessTripFlightExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields path class attendees { id name } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportFlightsRowFields" }); var BusinessTripReportFlightsTableFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportFlightsTableFields on BusinessTripFlightExpense { id date ...BusinessTripReportFlightsRowFields } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportFlightsRowFields on BusinessTripFlightExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields path class attendees { id name } }`, { "fragmentName": "BusinessTripReportFlightsTableFields" }); var BusinessTripReportAttendeeRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportAttendeeRowFields on BusinessTripAttendee { id name arrivalDate departureDate flights { id ...BusinessTripReportFlightsTableFields } accommodations { id ...BusinessTripReportAccommodationsTableFields } } fragment BusinessTripReportAccommodationsRowFields on BusinessTripAccommodationExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee country { id name } nightsCount attendeesStay { id attendee { id name } nightsCount } } fragment BusinessTripReportAccommodationsTableFields on BusinessTripAccommodationExpense { id date ...BusinessTripReportAccommodationsRowFields } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportFlightsRowFields on BusinessTripFlightExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields path class attendees { id name } } fragment BusinessTripReportFlightsTableFields on BusinessTripFlightExpense { id date ...BusinessTripReportFlightsRowFields }`, { "fragmentName": "BusinessTripReportAttendeeRowFields" }); var BusinessTripReportAttendeesFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportAttendeesFields on BusinessTrip { id attendees { id name ...BusinessTripReportAttendeeRowFields } } fragment BusinessTripReportAccommodationsRowFields on BusinessTripAccommodationExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee country { id name } nightsCount attendeesStay { id attendee { id name } nightsCount } } fragment BusinessTripReportAccommodationsTableFields on BusinessTripAccommodationExpense { id date ...BusinessTripReportAccommodationsRowFields } fragment BusinessTripReportAttendeeRowFields on BusinessTripAttendee { id name arrivalDate departureDate flights { id ...BusinessTripReportFlightsTableFields } accommodations { id ...BusinessTripReportAccommodationsTableFields } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportFlightsRowFields on BusinessTripFlightExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields path class attendees { id name } } fragment BusinessTripReportFlightsTableFields on BusinessTripFlightExpense { id date ...BusinessTripReportFlightsRowFields }`, { "fragmentName": "BusinessTripReportAttendeesFields" }); var BusinessTripReportCarRentalRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportCarRentalRowFields on BusinessTripCarRentalExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields days isFuelExpense } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportCarRentalRowFields" }); var BusinessTripReportCarRentalFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportCarRentalFields on BusinessTrip { id carRentalExpenses { id date ...BusinessTripReportCarRentalRowFields } } fragment BusinessTripReportCarRentalRowFields on BusinessTripCarRentalExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields days isFuelExpense } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportCarRentalFields" }); var BusinessTripReportFlightsFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportFlightsFields on BusinessTrip { id flightExpenses { id ...BusinessTripReportFlightsTableFields } attendees { id name } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportFlightsRowFields on BusinessTripFlightExpense { id payedByEmployee ...BusinessTripReportCoreExpenseRowFields path class attendees { id name } } fragment BusinessTripReportFlightsTableFields on BusinessTripFlightExpense { id date ...BusinessTripReportFlightsRowFields }`, { "fragmentName": "BusinessTripReportFlightsFields" }); var BusinessTripReportOtherRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportOtherRowFields on BusinessTripOtherExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee description deductibleExpense } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportOtherRowFields" }); var BusinessTripReportOtherFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportOtherFields on BusinessTrip { id otherExpenses { id date ...BusinessTripReportOtherRowFields } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportOtherRowFields on BusinessTripOtherExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee description deductibleExpense }`, { "fragmentName": "BusinessTripReportOtherFields" }); var BusinessTripReportTravelAndSubsistenceRowFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportTravelAndSubsistenceRowFields on BusinessTripTravelAndSubsistenceExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee expenseType } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } }`, { "fragmentName": "BusinessTripReportTravelAndSubsistenceRowFields" }); var BusinessTripReportTravelAndSubsistenceFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripReportTravelAndSubsistenceFields on BusinessTrip { id travelAndSubsistenceExpenses { id date ...BusinessTripReportTravelAndSubsistenceRowFields } } fragment BusinessTripReportCoreExpenseRowFields on BusinessTripExpense { id date valueDate amount { formatted raw currency } employee { id name } payedByEmployee charges { id } } fragment BusinessTripReportTravelAndSubsistenceRowFields on BusinessTripTravelAndSubsistenceExpense { id ...BusinessTripReportCoreExpenseRowFields payedByEmployee expenseType }`, { "fragmentName": "BusinessTripReportTravelAndSubsistenceFields" }); var TransactionsTableEventDateFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableEventDateFields on Transaction { id eventDate } `, { "fragmentName": "TransactionsTableEventDateFields" }); var TransactionsTableDebitDateFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableDebitDateFields on Transaction { id effectiveDate sourceEffectiveDate } `, { "fragmentName": "TransactionsTableDebitDateFields" }); var TransactionsTableAccountFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableAccountFields on Transaction { id account { id name type } } `, { "fragmentName": "TransactionsTableAccountFields" }); var TransactionsTableDescriptionFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableDescriptionFields on Transaction { id sourceDescription } `, { "fragmentName": "TransactionsTableDescriptionFields" }); var TransactionsTableSourceIdFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableSourceIDFields on Transaction { id referenceKey } `, { "fragmentName": "TransactionsTableSourceIDFields" }); var TransactionsTableEntityFieldsFragmentDoc = new TypedDocumentString(` fragment TransactionsTableEntityFields on Transaction { id counterparty { name id } sourceDescription missingInfoSuggestions { business { id name } } } `, { "fragmentName": "TransactionsTableEntityFields" }); var UncategorizedTransactionsTableAmountFieldsFragmentDoc = new TypedDocumentString(` fragment UncategorizedTransactionsTableAmountFields on UncategorizedTransaction { transaction { id amount { raw formatted } cryptoExchangeRate { rate } } categorizedAmount { raw formatted } errors } `, { "fragmentName": "UncategorizedTransactionsTableAmountFields" }); var BusinessTripUncategorizedTransactionsFieldsFragmentDoc = new TypedDocumentString(` fragment BusinessTripUncategorizedTransactionsFields on BusinessTrip { id uncategorizedTransactions { transaction { id eventDate chargeId amount { raw } ...TransactionsTableEventDateFields ...TransactionsTableDebitDateFields ...TransactionsTableAccountFields ...TransactionsTableDescriptionFields ...TransactionsTableSourceIDFields ...TransactionsTableEntityFields } ...UncategorizedTransactionsTableAmountFields } } fragment UncategorizedTransactionsTableAmountFields on UncategorizedTransaction { transaction { id amount { raw formatted } cryptoExchangeRate { rate } } categorizedAmount { raw formatted } errors } fragment TransactionsTableAccountFields on Transaction { id account { id name type } } fragment TransactionsTableEntityFields on Transaction { id counterparty { name id } sourceDescription missingInfoSuggestions { business { id name } } } fragment TransactionsTableDebitDateFields on Transaction { id effectiveDate sourceEffectiveDate } fragment TransactionsTableDescriptionFields on Transaction { id sourceDescription } fragment TransactionsTableEventDateFields on Transaction { id eventDate } fragment TransactionsTableSourceIDFields on Transaction { id referenceKey }`, { "fragmentName": "BusinessTripUncategorizedTransactionsFields" }); var DepreciationRecordRowFieldsFragmentDoc = new TypedDocumentString(` fragment DepreciationRecordRowFields on DepreciationRecord { id amount { currency formatted raw } activationDate category { id name percentage } type charge { id totalAmount { currency formatted raw } } } `, { "fragmentName": "DepreciationRecordRowFields" }); var EditTagFieldsFragmentDoc = new TypedDocumentString(` fragment EditTagFields on Tag { id name parent { id name } } `, { "fragmentName": "EditTagFields" }); var IssueDocumentClientFieldsFragmentDoc = new TypedDocumentString(` fragment IssueDocumentClientFields on Client { id originalBusiness { id address city zipCode country { id code } governmentId name phoneNumber } emails } `, { "fragmentName": "IssueDocumentClientFields" }); var NewDocumentDraftFragmentDoc = new TypedDocumentString(` fragment NewDocumentDraft on DocumentDraft { description remarks footer type date dueDate language currency vatType discount { amount type } rounding signed maxPayments client { id originalBusiness { id name } integrations { id } emails ...IssueDocumentClientFields } income { currency currencyRate description itemId price quantity vatRate vatType } payment { currency currencyRate date price type bankName bankBranch bankAccount chequeNum accountId transactionId cardType cardNum numPayments firstPayment } linkedDocumentIds linkedPaymentId } fragment IssueDocumentClientFields on Client { id originalBusiness { id address city zipCode country { id code } governmentId name phoneNumber } emails }`, { "fragmentName": "NewDocumentDraft" }); var SimilarChargesTableFragmentDoc = new TypedDocumentString(` fragment SimilarChargesTable on Charge { id __typename counterparty { name id } minEventDate minDebitDate minDocumentsDate totalAmount { raw formatted } vat { raw formatted } userDescription tags { id name } taxCategory { id name } ... on BusinessTripCharge { businessTrip { id name } } metadata { transactionsCount documentsCount ledgerCount miscExpensesCount } } `, { "fragmentName": "SimilarChargesTable" }); var NewFetchedDocumentFieldsFragmentDoc = new TypedDocumentString(` fragment NewFetchedDocumentFields on Document { id documentType charge { id userDescription counterparty { id name } } } `, { "fragmentName": "NewFetchedDocumentFields" }); var ContractForContractsTableFieldsFragmentDoc = new TypedDocumentString(` fragment ContractForContractsTableFields on Contract { id isActive client { id originalBusiness { id name } } purchaseOrders startDate endDate amount { raw formatted } billingCycle product plan operationsLimit msCloud } `, { "fragmentName": "ContractForContractsTableFields" }); var DocumentsGalleryFieldsFragmentDoc = new TypedDocumentString(` fragment DocumentsGalleryFields on Charge { id additionalDocuments { id image ... on FinancialDocument { documentType } } } `, { "fragmentName": "DocumentsGalleryFields" }); var CorporateTaxRulingReportRuleCellFieldsFragmentDoc = new TypedDocumentString(` fragment CorporateTaxRulingReportRuleCellFields on CorporateTaxRule { id rule percentage { formatted } isCompliant } `, { "fragmentName": "CorporateTaxRulingReportRuleCellFields" }); var ReportSubCommentaryTableFieldsFragmentDoc = new TypedDocumentString(` fragment ReportSubCommentaryTableFields on ReportCommentarySubRecord { financialEntity { id name } amount { formatted } } `, { "fragmentName": "ReportSubCommentaryTableFields" }); var ReportCommentaryTableFieldsFragmentDoc = new TypedDocumentString(` fragment ReportCommentaryTableFields on ReportCommentary { records { sortCode { id key name } amount { formatted } records { ...ReportSubCommentaryTableFields } } } fragment ReportSubCommentaryTableFields on ReportCommentarySubRecord { financialEntity { id name } amount { formatted } }`, { "fragmentName": "ReportCommentaryTableFields" }); var TrialBalanceTableFieldsFragmentDoc = new TypedDocumentString(` fragment TrialBalanceTableFields on BusinessTransactionsSumFromLedgerRecordsSuccessfulResult { businessTransactionsSum { business { id name sortCode { id key name } } credit { formatted raw } debit { formatted raw } total { formatted raw } } } `, { "fragmentName": "TrialBalanceTableFields" }); var ChargesTableAccountantApprovalFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableAccountantApprovalFields on Charge { id accountantApproval } `, { "fragmentName": "ChargesTableAccountantApprovalFields" }); var ChargesTableAmountFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableAmountFields on Charge { __typename id totalAmount { raw formatted } ... on CreditcardBankCharge { validCreditCardAmount } } `, { "fragmentName": "ChargesTableAmountFields" }); var ChargesTableBusinessTripFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableBusinessTripFields on Charge { id ... on BusinessTripCharge { businessTrip { id name } } } `, { "fragmentName": "ChargesTableBusinessTripFields" }); var ChargesTableDateFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableDateFields on Charge { id minEventDate minDebitDate minDocumentsDate maxEventDate maxDebitDate maxDocumentsDate } `, { "fragmentName": "ChargesTableDateFields" }); var ChargesTableDescriptionFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableDescriptionFields on Charge { id userDescription validationData { missingInfo } missingInfoSuggestions { description } } `, { "fragmentName": "ChargesTableDescriptionFields" }); var ChargesTableEntityFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableEntityFields on Charge { __typename id counterparty { name id } validationData { missingInfo } } `, { "fragmentName": "ChargesTableEntityFields" }); var ChargesTableMoreInfoFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableMoreInfoFields on Charge { __typename id metadata { transactionsCount documentsCount ledgerCount miscExpensesCount ... on ChargeMetadata @defer { invalidLedger } } validationData { missingInfo } } `, { "fragmentName": "ChargesTableMoreInfoFields" }); var ChargesTableTagsFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableTagsFields on Charge { id tags { id name namePath } validationData { ... on ValidationData { missingInfo } } missingInfoSuggestions { ... on ChargeSuggestions { tags { id name namePath } } } } `, { "fragmentName": "ChargesTableTagsFields" }); var ChargesTableTaxCategoryFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableTaxCategoryFields on Charge { __typename id taxCategory { id name } validationData { missingInfo } } `, { "fragmentName": "ChargesTableTaxCategoryFields" }); var ChargesTableTypeFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableTypeFields on Charge { __typename id } `, { "fragmentName": "ChargesTableTypeFields" }); var ChargesTableVatFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableVatFields on Charge { __typename id vat { raw formatted } totalAmount { raw currency } validationData { missingInfo } } `, { "fragmentName": "ChargesTableVatFields" }); var ChargesTableRowFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableRowFields on Charge { id __typename metadata { ... on ChargeMetadata @defer { documentsCount ledgerCount transactionsCount miscExpensesCount } } totalAmount { raw } ...ChargesTableAccountantApprovalFields ...ChargesTableAmountFields ...ChargesTableBusinessTripFields @defer ...ChargesTableDateFields ...ChargesTableDescriptionFields ...ChargesTableEntityFields @defer ...ChargesTableMoreInfoFields ...ChargesTableTagsFields @defer ...ChargesTableTaxCategoryFields @defer ...ChargesTableTypeFields ...ChargesTableVatFields } fragment ChargesTableAccountantApprovalFields on Charge { id accountantApproval } fragment ChargesTableAmountFields on Charge { __typename id totalAmount { raw formatted } ... on CreditcardBankCharge { validCreditCardAmount } } fragment ChargesTableBusinessTripFields on Charge { id ... on BusinessTripCharge { businessTrip { id name } } } fragment ChargesTableEntityFields on Charge { __typename id counterparty { name id } validationData { missingInfo } } fragment ChargesTableDateFields on Charge { id minEventDate minDebitDate minDocumentsDate maxEventDate maxDebitDate maxDocumentsDate } fragment ChargesTableDescriptionFields on Charge { id userDescription validationData { missingInfo } missingInfoSuggestions { description } } fragment ChargesTableMoreInfoFields on Charge { __typename id metadata { transactionsCount documentsCount ledgerCount miscExpensesCount ... on ChargeMetadata @defer { invalidLedger } } validationData { missingInfo } } fragment ChargesTableTagsFields on Charge { id tags { id name namePath } validationData { ... on ValidationData { missingInfo } } missingInfoSuggestions { ... on ChargeSuggestions { tags { id name namePath } } } } fragment ChargesTableTaxCategoryFields on Charge { __typename id taxCategory { id name } validationData { missingInfo } } fragment ChargesTableTypeFields on Charge { __typename id } fragment ChargesTableVatFields on Charge { __typename id vat { raw formatted } totalAmount { raw currency } validationData { missingInfo } }`, { "fragmentName": "ChargesTableRowFields", "deferredFields": { "ChargesTableBusinessTripFields": ["id"], "ChargesTableEntityFields": ["__typename", "id", "counterparty", "validationData"], "ChargesTableTagsFields": ["id", "tags", "validationData", "missingInfoSuggestions"], "ChargesTableTaxCategoryFields": ["__typename", "id", "taxCategory", "validationData"] } }); var ChargesTableFieldsFragmentDoc = new TypedDocumentString(` fragment ChargesTableFields on Charge { id owner { id } ...ChargesTableRowFields } fragment ChargesTableAccountantApprovalFields on Charge { id accountantApproval } fragment ChargesTableAmountFields on Charge { __typename id totalAmount { raw formatted } ... on CreditcardBankCharge { validCreditCardAmount } } fragment ChargesTableBusinessTripFields on Charge { id ... on BusinessTripCharge { businessTrip { id name } } } fragment ChargesTableEntityFields on Charge { __typename id counterparty { name id } validationData { missingInfo } } fragment ChargesTableDateFields on Charge { id minEventDate minDebitDate minDocumentsDate maxEventDate maxDebitDate maxDocumentsDate } fragment ChargesTableDescriptionFields on Charge { id userDescription validationData { missingInfo } missingInfoSuggestions { description } } fragment ChargesTableMoreInfoFields on Charge { __typename id metadata { transactionsCount documentsCount ledgerCount miscExpensesCount ... on ChargeMetadata @defer { invalidLedger } } validationData { missingInfo } } fragment ChargesTableTagsFields on Charge { id tags { id name namePath } validationData { ... on ValidationData { missingInfo } } missingInfoSuggestions { ... on ChargeSuggestions { tags { id name namePath } } } } fragment ChargesTableTaxCategoryFields on Charge { __typename id taxCategory { id name } validationData { missingInfo } } fragment ChargesTableTypeFields on Charge { __typename id } fragment ChargesTableVatFields on Charge { __typename id vat { raw formatted } totalAmount { raw currency } validationData { missingInfo } } fragment ChargesTableRowFields on Charge { id __typename metadata { ... on ChargeMetadata @defer { documentsCount ledgerCount transactionsCount miscExpensesCount } } totalAmount { raw } ...ChargesTableAccountantApprovalFields ...ChargesTableAmountFields ...ChargesTableBusinessTripFields @defer ...ChargesTableDateFields ...ChargesTableDescriptionFields ...ChargesTableEntityFields @defer ...ChargesTableMoreInfoFields ...ChargesTableTagsFields @defer ...ChargesTableTaxCategoryFields @defer ...ChargesTableTypeFields ...ChargesTableVatFields }`, { "fragmentName": "ChargesTableFields" }); var VatReportBusinessTripsFieldsFragmentDoc = new TypedDocumentString(` fragment VatReportBusinessTripsFields on VatReportResult { businessTrips { id ...ChargesTableFields } } fragment ChargesTableAccountantApprovalFields on Charge { id accountantApproval } fragment ChargesTableAmountFields on Charge { __typename id totalAmount { raw formatted } ... on CreditcardBankCharge { validCreditCardAmount } } fragment ChargesTableBusinessTripFields on Charge { id ... on BusinessTripCharge { businessTrip {