/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { CodatBankFeedsCore } from "../core.js"; import { encodeJSON, encodeSimple } from "../lib/encodings.js"; import * as M from "../lib/matchers.js"; import { compactMap } from "../lib/primitives.js"; import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; import { CodatBankFeedsError } from "../sdk/models/errors/codatbankfeedserror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../sdk/models/errors/httpclienterrors.js"; import * as errors from "../sdk/models/errors/index.js"; import { ResponseValidationError } from "../sdk/models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../sdk/models/errors/sdkvalidationerror.js"; import * as operations from "../sdk/models/operations/index.js"; import * as shared from "../sdk/models/shared/index.js"; import { APICall, APIPromise } from "../sdk/types/async.js"; import { Result } from "../sdk/types/fp.js"; /** * Create bank feed account mapping * * @remarks * The *Create bank account mapping* endpoint creates a new mapping between a source bank account and a potential account in the accounting software (target account). * * A bank feed account mapping is a specified link between the source account (provided by the Codat user) and the target account (the end user's account in the underlying software). * * To find valid target account options, first call the [List bank feed account mappings](https://docs.codat.io//bank-feeds-api#/operations/get-bank-account-mapping) endpoint. * * > **For custom builds only** * > * > Only use this endpoint if you are building your own account management UI. * * #### Account mapping variability * * The method of mapping the source account to the target account varies depending on the accounting software your company uses. * * #### Mapping options: * * 1. **API Mapping**: Integrate the mapping journey directly into your application for a seamless user experience. * 2. **Codat UI Mapping**: If you prefer a quicker setup, you can utilize Codat's provided user interface for mapping. * 3. **Accounting Platform Mapping**: For some accounting software, the mapping process must be conducted within the software itself. * * ### Integration-specific behavior * * | Bank Feed Integration | API Mapping | Codat UI Mapping | Accounting Platform Mapping | * | --------------------- | ----------- | ---------------- | --------------------------- | * | Xero | ✅ | ✅ | | * | FreeAgent | ✅ | ✅ | | * | Oracle NetSuite | ✅ | ✅ | | * | Exact Online (NL) | ✅ | ✅ | | * | QuickBooks Online | | | ✅ | * | Sage | | | ✅ | */ export function accountMappingCreate( client: CodatBankFeedsCore, request: operations.CreateBankAccountMappingRequest, options?: RequestOptions, ): APIPromise< Result< shared.BankFeedAccountMappingResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: CodatBankFeedsCore, request: operations.CreateBankAccountMappingRequest, options?: RequestOptions, ): Promise< [ Result< shared.BankFeedAccountMappingResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => operations.CreateBankAccountMappingRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = encodeJSON("body", payload.BankFeedAccountMapping, { explode: true, }); const pathParams = { companyId: encodeSimple("companyId", payload.companyId, { explode: false, charEncoding: "percent", }), connectionId: encodeSimple("connectionId", payload.connectionId, { explode: false, charEncoding: "percent", }), }; const path = pathToFunc( "/companies/{companyId}/connections/{connectionId}/bankFeedAccounts/mapping", )(pathParams); const headers = new Headers(compactMap({ "Content-Type": "application/json", Accept: "application/json", })); const secConfig = await extractSecurity(client._options.authHeader); const securityInput = secConfig == null ? {} : { authHeader: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "create-bank-account-mapping", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: client._options.authHeader, retryConfig: options?.retries || client._options.retryConfig || { strategy: "backoff", backoff: { initialInterval: 500, maxInterval: 60000, exponent: 1.5, maxElapsedTime: 3600000, }, retryConnectionErrors: true, } || { strategy: "none" }, retryCodes: options?.retryCodes || ["408", "429", "5XX"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "POST", baseURL: options?.serverURL, path: path, headers: headers, body: body, userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return [requestRes, { status: "invalid" }]; } const req = requestRes.value; const doResult = await client._do(req, { context, errorCodes: [ "400", "401", "402", "403", "404", "429", "4XX", "500", "503", "5XX", ], retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return [doResult, { status: "request-error", request: req }]; } const response = doResult.value; const responseFields = { HttpMeta: { Response: response, Request: req }, }; const [result] = await M.match< shared.BankFeedAccountMappingResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(200, shared.BankFeedAccountMappingResponse$inboundSchema), M.jsonErr( [400, 401, 402, 403, 404, 429], errors.ErrorMessage$inboundSchema, ), M.jsonErr([500, 503], errors.ErrorMessage$inboundSchema), M.fail("4XX"), M.fail("5XX"), )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } return [result, { status: "complete", request: req, response }]; }