import {z} from 'zod' export type IntegrationSort = {orderBy?: 'ID' | undefined, direction?: ('ASC' | 'DESC') | undefined}; export type OrdinalStatusListFilter = {in?: (Array<'ACTIVE' | 'INACTIVE' | 'REMOVED'>) | undefined, notIn?: (Array<'ACTIVE' | 'INACTIVE' | 'REMOVED'>) | undefined, equal?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, notEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, greaterThan?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, greaterThanEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, lessThan?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, lessThanEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined}; export type ApiNameListFilter = {in?: (Array<'BOX' | 'CLOVER' | 'STRIPE' | 'PLAID' | 'KNOX' | 'UBER' | 'FRESHBOOKS' | 'HARVEST' | 'KW' | 'FRESHBOOKS2' | 'CAPITAL_ONE' | 'SQUARE' | 'DOTLOOP' | 'REALOGY' | 'UPWORK' | 'SHOPIFY' | 'DEDUCTR' | 'ENTERPRISE' | 'MOXIWORKS' | 'APPDIRECT' | 'LONEWOLF' | 'LONEWOLF_TRANSACTIONDESK' | 'SAMPLE_BANK' | 'TAXBOT' | 'GUSTO' | 'XERO' | 'UNIT' | 'MOOV' | 'QBO' | 'QUALPAY' | 'BENCH' | 'PARTNER_IMPLEMENTATION' | 'CHECK' | 'RUTTER' | 'WAVE' | 'MANUAL_ENTRY' | 'CSV_IMPORT' | 'ADYEN' | 'PAYABLI'>) | undefined, notIn?: (Array<'BOX' | 'CLOVER' | 'STRIPE' | 'PLAID' | 'KNOX' | 'UBER' | 'FRESHBOOKS' | 'HARVEST' | 'KW' | 'FRESHBOOKS2' | 'CAPITAL_ONE' | 'SQUARE' | 'DOTLOOP' | 'REALOGY' | 'UPWORK' | 'SHOPIFY' | 'DEDUCTR' | 'ENTERPRISE' | 'MOXIWORKS' | 'APPDIRECT' | 'LONEWOLF' | 'LONEWOLF_TRANSACTIONDESK' | 'SAMPLE_BANK' | 'TAXBOT' | 'GUSTO' | 'XERO' | 'UNIT' | 'MOOV' | 'QBO' | 'QUALPAY' | 'BENCH' | 'PARTNER_IMPLEMENTATION' | 'CHECK' | 'RUTTER' | 'WAVE' | 'MANUAL_ENTRY' | 'CSV_IMPORT' | 'ADYEN' | 'PAYABLI'>) | undefined, equal?: ('BOX' | 'CLOVER' | 'STRIPE' | 'PLAID' | 'KNOX' | 'UBER' | 'FRESHBOOKS' | 'HARVEST' | 'KW' | 'FRESHBOOKS2' | 'CAPITAL_ONE' | 'SQUARE' | 'DOTLOOP' | 'REALOGY' | 'UPWORK' | 'SHOPIFY' | 'DEDUCTR' | 'ENTERPRISE' | 'MOXIWORKS' | 'APPDIRECT' | 'LONEWOLF' | 'LONEWOLF_TRANSACTIONDESK' | 'SAMPLE_BANK' | 'TAXBOT' | 'GUSTO' | 'XERO' | 'UNIT' | 'MOOV' | 'QBO' | 'QUALPAY' | 'BENCH' | 'PARTNER_IMPLEMENTATION' | 'CHECK' | 'RUTTER' | 'WAVE' | 'MANUAL_ENTRY' | 'CSV_IMPORT' | 'ADYEN' | 'PAYABLI') | undefined, notEqual?: ('BOX' | 'CLOVER' | 'STRIPE' | 'PLAID' | 'KNOX' | 'UBER' | 'FRESHBOOKS' | 'HARVEST' | 'KW' | 'FRESHBOOKS2' | 'CAPITAL_ONE' | 'SQUARE' | 'DOTLOOP' | 'REALOGY' | 'UPWORK' | 'SHOPIFY' | 'DEDUCTR' | 'ENTERPRISE' | 'MOXIWORKS' | 'APPDIRECT' | 'LONEWOLF' | 'LONEWOLF_TRANSACTIONDESK' | 'SAMPLE_BANK' | 'TAXBOT' | 'GUSTO' | 'XERO' | 'UNIT' | 'MOOV' | 'QBO' | 'QUALPAY' | 'BENCH' | 'PARTNER_IMPLEMENTATION' | 'CHECK' | 'RUTTER' | 'WAVE' | 'MANUAL_ENTRY' | 'CSV_IMPORT' | 'ADYEN' | 'PAYABLI') | undefined}; export type IntegrationFilterParam = {status?: OrdinalStatusListFilter | undefined, apiName?: ApiNameListFilter | undefined}; export type IntegrationQueryParam = {cursor?: (string | null) | undefined, limit?: number | undefined, sort?: IntegrationSort | undefined, filter?: IntegrationFilterParam | undefined}; export type CreateApiV6IntegrationsQueryArgs = {body: IntegrationQueryParam}; export type CreateApiV6IntegrationsQueryOptions = {baseUrl?: string | undefined, EmbedToken?: string | undefined, fetch?: typeof fetch | undefined}; export const integrationGetDto = z.object({id: z.string(), status: z.enum(["ACTIVE", "INACTIVE", "REMOVED"]), apiName: z.enum(["BOX", "CLOVER", "STRIPE", "PLAID", "KNOX", "UBER", "FRESHBOOKS", "HARVEST", "KW", "FRESHBOOKS2", "CAPITAL_ONE", "SQUARE", "DOTLOOP", "REALOGY", "UPWORK", "SHOPIFY", "DEDUCTR", "ENTERPRISE", "MOXIWORKS", "APPDIRECT", "LONEWOLF", "LONEWOLF_TRANSACTIONDESK", "SAMPLE_BANK", "TAXBOT", "GUSTO", "XERO", "UNIT", "MOOV", "QBO", "QUALPAY", "BENCH", "PARTNER_IMPLEMENTATION", "CHECK", "RUTTER", "WAVE", "MANUAL_ENTRY", "CSV_IMPORT", "ADYEN", "PAYABLI"]), iconUrl: z.string().nullable(), apiUsername: z.string().nullable().optional(), lastSyncedDate: z.string().nullable().optional(), apiAccessToken: z.string(), apiInstitutionId: z.string().nullable().optional(), apiInstitutionName: z.string().nullable().optional(), apiErrorType: z.string().nullable().optional(), apiErrorCode: z.string().nullable().optional(), additionalConsentRequired: z.boolean()}); export const responseCursor = z.object({after: z.string().optional(), before: z.string().optional()}); export const paginatedResponseIntegrationGetDto = z.object({result: z.enum(["SUCCESS", "FAILURE"]).optional(), data: z.array(integrationGetDto).optional(), cursor: responseCursor.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Query Integrations * * POST /v6/integrations/query */ export const createApiV6IntegrationsQuery = async (args: CreateApiV6IntegrationsQueryArgs, options?: CreateApiV6IntegrationsQueryOptions) => { const {baseUrl = "https://sandbox.tight.com", fetch: fetchFn = fetch, EmbedToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (EmbedToken !== undefined) headers.set('authorization', `Bearer ${EmbedToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v6/integrations/query${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedResponseIntegrationGetDto, await res.json()) };