/* * 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 { APICall, APIPromise } from "../sdk/types/async.js"; import { Result } from "../sdk/types/fp.js"; /** * Create source accounts * * @remarks * The _Batch create source accounts_ endpoint allows you to create multiple representations of your SMB's bank accounts within Codat's domain. The company can then map the source account to an existing or new target account in their accounting software. * * > ### Versioning * > If you are integrating the Bank Feeds solution with Codat after August 1, 2024, please use the v2 version of the API, as detailed in the schema below. For integrations completed before August 1, 2024, select the v1 version from the schema dropdown below. */ export function sourceAccountsCreateBatch( client: CodatBankFeedsCore, request: operations.CreateBatchSourceAccountRequest, options?: RequestOptions, ): APIPromise< Result< operations.CreateBatchSourceAccountResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: CodatBankFeedsCore, request: operations.CreateBatchSourceAccountRequest, options?: RequestOptions, ): Promise< [ Result< operations.CreateBatchSourceAccountResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => operations.CreateBatchSourceAccountRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = encodeJSON("body", payload.RequestBody, { 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}/connectionInfo/bankFeedAccounts/batch", )(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-batch-source-account", 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", "409", "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< operations.CreateBatchSourceAccountResponse, | errors.ErrorMessage | CodatBankFeedsError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(201, operations.CreateBatchSourceAccountResponse$inboundSchema), M.json(207, operations.CreateBatchSourceAccountResponse$inboundSchema), M.jsonErr( [400, 401, 402, 403, 404, 429], errors.ErrorMessage$inboundSchema, ), M.jsonErr([500, 503], errors.ErrorMessage$inboundSchema), M.fail([409, "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 }]; }