diff --git a/.npmignore b/.npmignore index 6db0876..383dd36 100644 --- a/.npmignore +++ b/.npmignore @@ -6,4 +6,5 @@ tests .fernignore .prettierrc.yml tsconfig.json -yarn.lock \ No newline at end of file +yarn.lock +pnpm-lock.yaml \ No newline at end of file diff --git a/README.md b/README.md index 0c9ce27..0c4269b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ npm i -s @monite/node-client ## Reference -A full reference for this library is available [here](./reference.md). +A full reference for this library is available [here](https://github.com/team-monite/monite-node-client/blob/HEAD/./reference.md). ## Usage @@ -83,6 +83,18 @@ const response = await client.products.create(..., { }); ``` +### Additional Query String Parameters + +If you would like to send additional query string parameters as part of the request, use the `queryParams` request option. + +```typescript +const response = await client.products.create(..., { + queryParams: { + 'customQueryParamKey': 'custom query param value' + } +}); +``` + ### Retries The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long @@ -139,8 +151,7 @@ console.log(rawResponse.headers['X-My-Header']); ### Runtime Compatibility -The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following -runtimes: +The SDK works in the following runtimes: - Node.js 18+ - Vercel @@ -172,3 +183,393 @@ a proof of concept, but know that we will not be able to merge it as-is. We sugg an issue first to discuss with us! On the other hand, contributions to the README are always very welcome! + +## Binary Response + +You can consume binary data from endpoints using the `BinaryResponse` type which lets you choose how to consume the data: + +```typescript +const response = await client.pdfTemplates.previewById(...); +const stream: ReadableStream = response.stream(); +// const arrayBuffer: ArrayBuffer = await response.arrayBuffer(); +// const blob: Blob = response.blob(); +// const bytes: Uint8Array = response.bytes(); +// You can only use the response body once, so you must choose one of the above methods. +// If you want to check if the response body has been used, you can use the following property. +const bodyUsed = response.bodyUsed; +``` + +
+Save binary response to a file + +
+
+Node.js + +
+
+ReadableStream (most-efficient) + +```ts +import { createWriteStream } from 'fs'; +import { Readable } from 'stream'; +import { pipeline } from 'stream/promises'; + +const response = await client.pdfTemplates.previewById(...); + +const stream = response.stream(); +const nodeStream = Readable.fromWeb(stream); +const writeStream = createWriteStream('path/to/file'); + +await pipeline(nodeStream, writeStream); +``` + +
+
+ +
+
+ArrayBuffer + +```ts +import { writeFile } from 'fs/promises'; + +const response = await client.pdfTemplates.previewById(...); + +const arrayBuffer = await response.arrayBuffer(); +await writeFile('path/to/file', Buffer.from(arrayBuffer)); +``` + +
+
+ +
+
+Blob + +```ts +import { writeFile } from 'fs/promises'; + +const response = await client.pdfTemplates.previewById(...); + +const blob = await response.blob(); +const arrayBuffer = await blob.arrayBuffer(); +await writeFile('output.bin', Buffer.from(arrayBuffer)); +``` + +
+
+ +
+
+Bytes (UIntArray8) + +```ts +import { writeFile } from 'fs/promises'; + +const response = await client.pdfTemplates.previewById(...); + +const bytes = await response.bytes(); +await writeFile('path/to/file', bytes); +``` + +
+
+ +
+
+ +
+
+Bun + +
+
+ReadableStream (most-efficient) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const stream = response.stream(); +await Bun.write('path/to/file', stream); +``` + +
+
+ +
+
+ArrayBuffer + +```ts +const response = await client.pdfTemplates.previewById(...); + +const arrayBuffer = await response.arrayBuffer(); +await Bun.write('path/to/file', arrayBuffer); +``` + +
+
+ +
+
+Blob + +```ts +const response = await client.pdfTemplates.previewById(...); + +const blob = await response.blob(); +await Bun.write('path/to/file', blob); +``` + +
+
+ +
+
+Bytes (UIntArray8) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const bytes = await response.bytes(); +await Bun.write('path/to/file', bytes); +``` + +
+
+ +
+
+ +
+
+Deno + +
+
+ReadableStream (most-efficient) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const stream = response.stream(); +const file = await Deno.open('path/to/file', { write: true, create: true }); +await stream.pipeTo(file.writable); +``` + +
+
+ +
+
+ArrayBuffer + +```ts +const response = await client.pdfTemplates.previewById(...); + +const arrayBuffer = await response.arrayBuffer(); +await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer)); +``` + +
+
+ +
+
+Blob + +```ts +const response = await client.pdfTemplates.previewById(...); + +const blob = await response.blob(); +const arrayBuffer = await blob.arrayBuffer(); +await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer)); +``` + +
+
+ +
+
+Bytes (UIntArray8) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const bytes = await response.bytes(); +await Deno.writeFile('path/to/file', bytes); +``` + +
+
+ +
+
+ +
+
+Browser + +
+
+Blob (most-efficient) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const blob = await response.blob(); +const url = URL.createObjectURL(blob); + +// trigger download +const a = document.createElement('a'); +a.href = url; +a.download = 'filename'; +a.click(); +URL.revokeObjectURL(url); +``` + +
+
+ +
+
+ReadableStream + +```ts +const response = await client.pdfTemplates.previewById(...); + +const stream = response.stream(); +const reader = stream.getReader(); +const chunks = []; + +while (true) { + const { done, value } = await reader.read(); + if (done) break; + chunks.push(value); +} + +const blob = new Blob(chunks); +const url = URL.createObjectURL(blob); + +// trigger download +const a = document.createElement('a'); +a.href = url; +a.download = 'filename'; +a.click(); +URL.revokeObjectURL(url); +``` + +
+
+ +
+
+ArrayBuffer + +```ts +const response = await client.pdfTemplates.previewById(...); + +const arrayBuffer = await response.arrayBuffer(); +const blob = new Blob([arrayBuffer]); +const url = URL.createObjectURL(blob); + +// trigger download +const a = document.createElement('a'); +a.href = url; +a.download = 'filename'; +a.click(); +URL.revokeObjectURL(url); +``` + +
+
+ +
+
+Bytes (UIntArray8) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const bytes = await response.bytes(); +const blob = new Blob([bytes]); +const url = URL.createObjectURL(blob); + +// trigger download +const a = document.createElement('a'); +a.href = url; +a.download = 'filename'; +a.click(); +URL.revokeObjectURL(url); +``` + +
+
+ +
+
+ +
+ + +
+Convert binary response to text + +
+
+ReadableStream + +```ts +const response = await client.pdfTemplates.previewById(...); + +const stream = response.stream(); +const text = await new Response(stream).text(); +``` + +
+
+ +
+
+ArrayBuffer + +```ts +const response = await client.pdfTemplates.previewById(...); + +const arrayBuffer = await response.arrayBuffer(); +const text = new TextDecoder().decode(arrayBuffer); +``` + +
+
+ +
+
+Blob + +```ts +const response = await client.pdfTemplates.previewById(...); + +const blob = await response.blob(); +const text = await blob.text(); +``` + +
+
+ +
+
+Bytes (UIntArray8) + +```ts +const response = await client.pdfTemplates.previewById(...); + +const bytes = await response.bytes(); +const text = new TextDecoder().decode(bytes); +``` + +
+
+ +
diff --git a/jest.config.mjs b/jest.config.mjs index c724821..b692700 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -2,7 +2,41 @@ export default { preset: "ts-jest", testEnvironment: "node", - moduleNameMapper: { - "(.+)\.js$": "$1", - }, + projects: [ + { + displayName: "unit", + preset: "ts-jest", + testEnvironment: "node", + moduleNameMapper: { + "^(\.{1,2}/.*)\.js$": "$1", + }, + roots: ["/tests"], + testPathIgnorePatterns: ["\.browser\.(spec|test)\.[jt]sx?$", "/tests/wire/"], + setupFilesAfterEnv: [], + }, + { + displayName: "browser", + preset: "ts-jest", + testEnvironment: "/tests/BrowserTestEnvironment.ts", + moduleNameMapper: { + "^(\.{1,2}/.*)\.js$": "$1", + }, + roots: ["/tests"], + testMatch: ["/tests/unit/**/?(*.)+(browser).(spec|test).[jt]s?(x)"], + setupFilesAfterEnv: [], + }, + , + { + displayName: "wire", + preset: "ts-jest", + testEnvironment: "node", + moduleNameMapper: { + "^(\.{1,2}/.*)\.js$": "$1", + }, + roots: ["/tests/wire"], + setupFilesAfterEnv: ["/tests/mock-server/setup.ts"], + }, + ], + workerThreads: false, + passWithNoTests: true, }; diff --git a/package.json b/package.json index b39fcca..f116c70 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,53 @@ { "name": "@monite/node-client", - "version": "0.3.3", + "version": "0.3.4", "private": false, - "repository": "https://github.com/team-monite/monite-node-client", + "repository": "github:team-monite/monite-node-client", "license": "MIT", - "main": "./index.js", - "types": "./index.d.ts", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.mjs", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "types": "./dist/cjs/index.d.ts", + "import": { + "types": "./dist/esm/index.d.mts", + "default": "./dist/esm/index.mjs" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "default": "./dist/cjs/index.js" + }, + "./package.json": "./package.json" + }, + "files": [ + "dist", + "reference.md", + "README.md", + "LICENSE" + ], "scripts": { "format": "prettier . --write --ignore-unknown", - "build": "tsc", - "prepack": "cp -rv dist/. .", - "test": "jest" - }, - "dependencies": { - "url-join": "4.0.1", - "form-data": "^4.0.0", - "formdata-node": "^6.0.3", - "node-fetch": "^2.7.0", - "qs": "^6.13.1", - "readable-stream": "^4.5.2", - "js-base64": "3.7.7", - "form-data-encoder": "^4.0.2" + "build": "yarn build:cjs && yarn build:esm", + "build:cjs": "tsc --project ./tsconfig.cjs.json", + "build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm", + "test": "jest --config jest.config.mjs", + "test:unit": "jest --selectProjects unit", + "test:browser": "jest --selectProjects browser", + "test:wire": "jest --selectProjects wire" }, "devDependencies": { - "@types/url-join": "4.0.1", - "@types/qs": "^6.9.17", - "@types/node-fetch": "^2.6.12", - "@types/readable-stream": "^4.0.18", "webpack": "^5.97.1", "ts-loader": "^9.5.1", "jest": "^29.7.0", + "@jest/globals": "^29.7.0", "@types/jest": "^29.5.14", - "ts-jest": "^29.1.1", + "ts-jest": "^29.3.4", "jest-environment-jsdom": "^29.7.0", + "msw": "^2.8.4", "@types/node": "^18.19.70", "prettier": "^3.4.2", "typescript": "~5.7.2" @@ -40,7 +55,12 @@ "browser": { "fs": false, "os": false, - "path": false + "path": false, + "stream": false + }, + "packageManager": "yarn@1.22.22", + "engines": { + "node": ">=18.0.0" }, - "packageManager": "yarn@1.22.22" + "sideEffects": false } diff --git a/reference.md b/reference.md index da5fe71..07cc1b8 100644 --- a/reference.md +++ b/reference.md @@ -921,8 +921,8 @@ Create a new access token based on client ID and client secret. ```typescript await client.accessTokens.create({ - client_id: "client_id", - client_secret: "client_secret", + client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", grant_type: "client_credentials", }); ``` @@ -1730,7 +1730,7 @@ await client.counterpartEInvoicingCredentials.getCounterpartsIdEinvoicingCredent ```typescript await client.counterpartEInvoicingCredentials.postCounterpartsIdEinvoicingCredentials("counterpart_id", { - counterpart_vat_id_id: "counterpart_vat_id_id", + counterpart_vat_id_id: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", }); ``` @@ -1959,6 +1959,256 @@ await client.counterpartEInvoicingCredentials.patchCounterpartsIdEinvoicingCrede +## Custom VAT rates + +
client.customVatRates.getCustomVatRates() -> Monite.CustomVatRateResponseList +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.customVatRates.getCustomVatRates(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**requestOptions:** `CustomVatRates.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.customVatRates.postCustomVatRates({ ...params }) -> Monite.CustomVatRateResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.customVatRates.postCustomVatRates({ + components: [ + { + name: "name", + value: 1.1, + }, + ], + name: "name", +}); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.CustomVatRateRequest` + +
+
+ +
+
+ +**requestOptions:** `CustomVatRates.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.customVatRates.getCustomVatRatesId(customVatRateId) -> Monite.CustomVatRateResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.customVatRates.getCustomVatRatesId("custom_vat_rate_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**customVatRateId:** `string` + +
+
+ +
+
+ +**requestOptions:** `CustomVatRates.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.customVatRates.deleteCustomVatRatesId(customVatRateId) -> void +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.customVatRates.deleteCustomVatRatesId("custom_vat_rate_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**customVatRateId:** `string` + +
+
+ +
+
+ +**requestOptions:** `CustomVatRates.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.customVatRates.patchCustomVatRatesId(customVatRateId, { ...params }) -> Monite.CustomVatRateResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.customVatRates.patchCustomVatRatesId("custom_vat_rate_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**customVatRateId:** `string` + +
+
+ +
+
+ +**request:** `Monite.CustomVatRateUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `CustomVatRates.RequestOptions` + +
+
+
+
+ +
+
+
+ ## DataExports
client.dataExports.get({ ...params }) -> Monite.AllDocumentExportResponseSchema @@ -2249,29 +2499,23 @@ await client.deliveryNotes.getDeliveryNotes(); ```typescript await client.deliveryNotes.postDeliveryNotes({ - counterpart_address_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", - counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", - delivery_date: "2025-01-01", - delivery_number: "102-2025-0987", + counterpart_address_id: "9a0282e1-bae7-49c9-a6f3-152dbe6fe6b8", + counterpart_id: "18a45457-377e-4b7c-b9a1-7b2e7f264d46", + delivery_date: "2025-07-01", + delivery_number: "INV-042", display_signature_placeholder: true, line_items: [ { - product_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + product: { + name: "LG WH1000XM Monitor", + }, quantity: 10, }, { - product: { - description: "Description of product 2", - measure_unit: { - description: "pieces", - name: "pcs", - }, - name: "Product 2", - }, - quantity: 20, + product_id: "e0c21d00-6556-4536-8390-830c4d3cf4ca", + quantity: 5, }, ], - memo: "This is a memo", }); ``` @@ -2763,13 +3007,13 @@ await client.pdfTemplates.makeDefaultById("document_template_id");
-## E-invoicing connections +## E-invoicing search -
client.eInvoicingConnections.getEinvoicingConnections() -> Monite.EInvoicingRetrieveListData +
client.eInvoicingSearch.getEinvoiceSearch({ ...params }) -> Monite.CounterpartEinvoicingCredentialExistenceResponse
-#### πŸ”Œ Usage +#### πŸ“ Description
@@ -2777,16 +3021,20 @@ await client.pdfTemplates.makeDefaultById("document_template_id");
-```typescript -await client.eInvoicingConnections.getEinvoicingConnections(); -``` +Checks if the specified VAT number or business number is registered on the PEPPOL network as a receiver. For example, you can use this endpoint to check if an entity's counterparts are registered in PEPPOL before creating e-invoices for those counterparts. + +The lookup is powered by PEPPOL SMPs (Service Metadata Publishers) so it also includes registrations that are not visible in the public PEPPOL directory. + +Both partner tokens and entity user tokens can be used for authentication. + +Production and sandbox lookups are separate.
-#### βš™οΈ Parameters +#### πŸ”Œ Usage
@@ -2794,23 +3042,93 @@ await client.eInvoicingConnections.getEinvoicingConnections();
-**requestOptions:** `EInvoicingConnections.RequestOptions` +```typescript +await client.eInvoicingSearch.getEinvoiceSearch({ + network_identifier: "DE010101010", + network_schema: "DE:VAT", +}); +```
-
-
-
+#### βš™οΈ Parameters -
client.eInvoicingConnections.postEinvoicingConnections({ ...params }) -> Monite.EinvoicingConnectionResponse
-#### πŸ”Œ Usage - +
+
+ +**request:** `Monite.GetEinvoiceSearchRequest` + +
+
+ +
+
+ +**requestOptions:** `EInvoicingSearch.RequestOptions` + +
+
+
+
+ + + +
+ +## E-invoicing connections + +
client.eInvoicingConnections.getEinvoicingConnections() -> Monite.EInvoicingRetrieveListData +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.eInvoicingConnections.getEinvoicingConnections(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**requestOptions:** `EInvoicingConnections.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.eInvoicingConnections.postEinvoicingConnections({ ...params }) -> Monite.EinvoicingConnectionResponse +
+
+ +#### πŸ”Œ Usage +
@@ -2956,6 +3274,62 @@ await client.eInvoicingConnections.deleteEinvoicingConnectionsId("einvoicing_con
+
client.eInvoicingConnections.patchEinvoicingConnectionsId(einvoicingConnectionId, { ...params }) -> Monite.EinvoicingConnectionResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.eInvoicingConnections.patchEinvoicingConnectionsId("einvoicing_connection_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**einvoicingConnectionId:** `string` + +
+
+ +
+
+ +**request:** `Monite.EinvoicingConnectionUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `EInvoicingConnections.RequestOptions` + +
+
+
+
+ +
+
+
+
client.eInvoicingConnections.postEinvoicingConnectionsIdNetworkCredentials(einvoicingConnectionId, { ...params }) -> Monite.EinvoicingNetworkCredentialsResponse
@@ -3282,12 +3656,19 @@ await client.entities.patchEntitiesMe({});
-Retrieve an entity by its ID. +Returns entity information for the specified entity ID. -
-
-
-
+This endpoint requires a partner access token and can be used to get any of the partner's entities. + +To get entity information by using an entity user token, use [`GET /entity_users/my_entity`](https://docs.monite.com/api/entities/get-entity-users-my-entity) instead. + +Related endpoints: + +- [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) + + + + #### πŸ”Œ Usage @@ -3345,12 +3726,20 @@ await client.entities.getById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5");
-Change the specified fields with the provided values. +Update entity information for the specified entity ID. -
-
- - +This endpoint requires a partner access token and can be used to update any of the partner's entities. + +To update an entity by using an entity user token, use [`PATCH /entity_users/my_entity`](https://docs.monite.com/api/entities/patch-entity-users-my-entity) instead. + +Related endpoints: + +- [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) +- [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) + + + + #### πŸ”Œ Usage @@ -3530,7 +3919,7 @@ await client.entities.postEntitiesIdDeactivate("ea837e28-509b-4b6a-a600-d54b6aa0
-
client.entities.uploadLogoById(file, entityId) -> Monite.FileSchema2 +
client.entities.uploadLogoById(entityId, { ...params }) -> Monite.FileSchema2
@@ -3544,6 +3933,8 @@ await client.entities.postEntitiesIdDeactivate("ea837e28-509b-4b6a-a600-d54b6aa0 Entity logo can be PNG, JPG, or GIF, up to 10 MB in size. The logo is used, for example, in PDF documents created by this entity. +Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. +
@@ -3558,7 +3949,9 @@ Entity logo can be PNG, JPG, or GIF, up to 10 MB in size. The logo is used, for
```typescript -await client.entities.uploadLogoById(fs.createReadStream("/path/to/your/file"), "ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); +await client.entities.uploadLogoById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5", { + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -3574,7 +3967,7 @@ await client.entities.uploadLogoById(fs.createReadStream("/path/to/your/file"),
-**file:** `File | fs.ReadStream | Blob` +**entityId:** `string`
@@ -3582,7 +3975,7 @@ await client.entities.uploadLogoById(fs.createReadStream("/path/to/your/file"),
-**entityId:** `string` +**request:** `Monite.BodyPutEntitiesIdLogo`
@@ -3605,6 +3998,21 @@ await client.entities.uploadLogoById(fs.createReadStream("/path/to/your/file"),
+#### πŸ“ Description + +
+
+ +
+
+ +Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -3799,12 +4207,18 @@ await client.entities.updatePartnerMetadataById("entity_id", {
-Retrieve all settings for this entity. +Entity settings include configuration options for accounts payable, accounts receivable, accounting integration, and other functionality. -
-
-
-
+Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.read` permission. + +Related endpoints: + +- [Get next document numbers](https://docs.monite.com/api/entities/get-entities-id-settings-next-document-numbers) +- [Get partner settings](https://docs.monite.com/api/partner-settings/get-settings) + + + + #### πŸ”Œ Usage @@ -3862,12 +4276,19 @@ await client.entities.getSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5");
-Change the specified fields with the provided values. +Entity settings include configuration options for accounts payable, accounts receivable, accounting integration, and other functionality. -
-
- - +Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. + +Related endpoints: + +- [Update an entity](https://docs.monite.com/api/entities/patch-entities-id) +- [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) +- [Update partner settings](https://docs.monite.com/api/partner-settings/patch-settings) + + + + #### πŸ”Œ Usage @@ -3921,6 +4342,73 @@ await client.entities.updateSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5")
+
client.entities.getEntitiesIdSettingsNextDocumentNumbers(entityId) -> Monite.NextDocumentNumbers +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Returns the next sequence number for various document types - invoices, quotes, credit notes, and others. For example, if the last issued invoice is `INV-00042`, the next invoice number is 43. + +To set the next document numbers, use `PATCH /entities/{entity_id}/settings`. + +For more information, see [Document number customization](https://docs.monite.com/advanced/document-number-customization). + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.entities.getEntitiesIdSettingsNextDocumentNumbers("entity_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**entityId:** `string` β€” Unique ID of the entity + +
+
+ +
+
+ +**requestOptions:** `Entities.RequestOptions` + +
+
+
+
+ +
+
+
+
client.entities.uploadOnboardingDocuments({ ...params }) -> void
@@ -4182,7 +4670,7 @@ await client.entityUsers.create({
-Retrieve an entity user by its ID. +The user ID is inferred fron the `Authorization` header, which must contain a user-level access token.
@@ -4237,7 +4725,7 @@ await client.entityUsers.getCurrent();
-Change the specified fields with provided values. +The user ID is inferred fron the `Authorization` header, which must contain a user-level access token.
@@ -4300,12 +4788,17 @@ await client.entityUsers.updateCurrent();
-Retrieves information of an entity, which this entity user belongs to. +Returns the entity to which the authenticated user belongs. This endpoint requires an [entity user access token](https://docs.monite.com/api/concepts/authentication#entity-user-token). The user must have a role with the `entity.read` permission. -
-
-
-
+To get an entity by using a partner access token, use [`GET /entities/{entity_id}`](https://docs.monite.com/api/entities/get-entities-id) instead. + +Related endpoints: + +- [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) + + + + #### πŸ”Œ Usage @@ -4355,12 +4848,20 @@ await client.entityUsers.getCurrentEntity();
-Update information of an entity, which this entity user belongs to. +Update the entity to which the authenticated user belongs. -
-
- - +This endpoint requires an [entity user access token](https://docs.monite.com/api/concepts/authentication#entity-user-token). The user must have a role with the `entity.update` permission. + +This endpoint does not use the `X-Monite-Entity-Id` header. The entity ID is inferred from the access token. + +Related endpoints: + +- [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) +- [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) + + + + #### πŸ”Œ Usage @@ -4781,7 +5282,7 @@ await client.events.getById("event_id");
-#### πŸ”Œ Usage +#### πŸ“ Description
@@ -4789,16 +5290,23 @@ await client.events.getById("event_id");
-```typescript -await client.files.get(); -``` +The `/files` endpoint provides access to an entity's files hosted on Monite's servers. This includes both files uploaded by the entity and files that were automatically created by Monite (such as PDF versions of invoices). + +`GET /files` requires at least one query parameter, either `id__in` or `file_type`. You can use this operation to: + +- Bulk fetch multiple files by IDs. +- Get all files with the given purpose (for example, invoice attachments). + +If no files matching the query parameters were found, the response contains an empty `data` array. + +Both partner tokens and entity user tokens can be used for authentication.
-#### βš™οΈ Parameters +#### πŸ”Œ Usage
@@ -4806,8 +5314,25 @@ await client.files.get();
-**request:** `Monite.FilesGetRequest` - +```typescript +await client.files.get(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.FilesGetRequest` +
@@ -4825,11 +5350,11 @@ await client.files.get();
-
client.files.upload(file, { ...params }) -> Monite.FileResponse +
client.files.upload({ ...params }) -> Monite.FileResponse
-#### πŸ”Œ Usage +#### πŸ“ Description
@@ -4837,18 +5362,21 @@ await client.files.get();
-```typescript -await client.files.upload(fs.createReadStream("/path/to/your/file"), { - file_type: "ocr_results", -}); -``` +Upload files for use as: + +- supplementary attachments for invoices, quotes, and credit notes, +- [entity verification documents](https://docs.monite.com/payments/onboarding/via-api/documents) for payments onboarding. + +Maximum file size is 15 MB. Each uploaded file is assigned a unique `id` that you can use to reference this file elsewhere. + +Both partner tokens and entity user tokens can be used for authentication.
-#### βš™οΈ Parameters +#### πŸ”Œ Usage
@@ -4856,10 +5384,22 @@ await client.files.upload(fs.createReadStream("/path/to/your/file"), {
-**file:** `File | fs.ReadStream | Blob` +```typescript +await client.files.upload({ + file: fs.createReadStream("/path/to/your/file"), + file_type: "ocr_results", +}); +```
+
+
+ +#### βš™οΈ Parameters + +
+
@@ -4887,6 +5427,23 @@ await client.files.upload(fs.createReadStream("/path/to/your/file"), {
+#### πŸ“ Description + +
+
+ +
+
+ +Returns the details of an existing file. To bulk fetch multiple files by their IDs, use `GET /files?id__in=&id__in=`. + +Both partner tokens and entity user tokens can be used for authentication. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -4935,6 +5492,29 @@ await client.files.getById("file_id");
+#### πŸ“ Description + +
+
+ +
+
+ +Delete a file with the specified ID. + +**Note:** This endpoint does not check if the specified file is in use. Use with caution. + +Both partner tokens and entity user tokens can be used for authentication. + +#### Considerations for invoice attachments + +Deleting a file does not delete it from the `attachments` list of accounts receivable invoices, quotes, and credit notes because these documents contain an inline copy of all referenced resources. To delete a file from attachments, call `PATCH /receivables/{receivable_id}` and update the `attachments` list to exclude the deleted file. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -4960,7 +5540,7 @@ await client.files.delete("file_id");
-**fileId:** `string` +**fileId:** `string` β€” ID of the file you want to delete.
@@ -6584,7 +7164,7 @@ await client.ocr.postOcrTasks({
-
client.ocr.postOcrTasksUploadFromFile(file, { ...params }) -> Monite.OcrTaskResponseSchema +
client.ocr.postOcrTasksUploadFromFile({ ...params }) -> Monite.OcrTaskResponseSchema
@@ -6597,7 +7177,9 @@ await client.ocr.postOcrTasks({
```typescript -await client.ocr.postOcrTasksUploadFromFile(fs.createReadStream("/path/to/your/file"), {}); +await client.ocr.postOcrTasksUploadFromFile({ + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -6613,14 +7195,6 @@ await client.ocr.postOcrTasksUploadFromFile(fs.createReadStream("/path/to/your/f
-**file:** `File | fs.ReadStream | Blob` - -
-
- -
-
- **request:** `Monite.OcrFileUpload`
@@ -7033,7 +7607,7 @@ await client.creditNotes.postPayableCreditNotes({
-
client.creditNotes.postPayableCreditNotesUploadFromFile(file) -> Monite.CreditNoteResponse +
client.creditNotes.postPayableCreditNotesUploadFromFile({ ...params }) -> Monite.CreditNoteResponse
@@ -7045,7 +7619,7 @@ await client.creditNotes.postPayableCreditNotes({
-Upload an incoming credit note (payable) in PDF, PNG, JPEG, or TIFF format and scan its contents. The maximum file size is 10MB. +Upload an incoming credit note (payable) in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB.
@@ -7061,7 +7635,9 @@ Upload an incoming credit note (payable) in PDF, PNG, JPEG, or TIFF format and s
```typescript -await client.creditNotes.postPayableCreditNotesUploadFromFile(fs.createReadStream("/path/to/your/file")); +await client.creditNotes.postPayableCreditNotesUploadFromFile({ + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -7077,7 +7653,7 @@ await client.creditNotes.postPayableCreditNotesUploadFromFile(fs.createReadStrea
-**file:** `File | fs.ReadStream | Blob` +**request:** `Monite.CreditNoteUploadFile`
@@ -8797,7 +9373,7 @@ await client.payables.getAnalytics();
-
client.payables.uploadFromFile(file) -> Monite.PayableResponseSchema +
client.payables.uploadFromFile({ ...params }) -> Monite.PayableResponseSchema
@@ -8809,7 +9385,7 @@ await client.payables.getAnalytics();
-Upload an incoming invoice (payable) in PDF, PNG, JPEG, or TIFF format and scan its contents. The maximum file size is 10MB. +Upload an incoming invoice (payable) in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB.
@@ -8825,7 +9401,9 @@ Upload an incoming invoice (payable) in PDF, PNG, JPEG, or TIFF format and scan
```typescript -await client.payables.uploadFromFile(fs.createReadStream("/path/to/your/file")); +await client.payables.uploadFromFile({ + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -8841,7 +9419,7 @@ await client.payables.uploadFromFile(fs.createReadStream("/path/to/your/file"));
-**file:** `File | fs.ReadStream | Blob` +**request:** `Monite.PayableUploadFile`
@@ -9047,7 +9625,7 @@ await client.payables.resetValidations();
-Get a list of placeholders allowed to insert into an email template for customization +Returns a list of placeholders that can be used to personalize email templates related to payables. These include payables attributes such as `currency`, `customer_name`, `document_id`, `due_date`, `invoice_id`, `total_amount`, and `uploaded_username`.
@@ -9350,7 +9928,7 @@ await client.payables.approvePaymentById("payable_id");
-
client.payables.attachFileById(file, payableId) -> Monite.PayableResponseSchema +
client.payables.attachFileById(payableId, { ...params }) -> Monite.PayableResponseSchema
@@ -9378,7 +9956,9 @@ Attach file to payable without existing attachment.
```typescript -await client.payables.attachFileById(fs.createReadStream("/path/to/your/file"), "payable_id"); +await client.payables.attachFileById("payable_id", { + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -9394,7 +9974,7 @@ await client.payables.attachFileById(fs.createReadStream("/path/to/your/file"),
-**file:** `File | fs.ReadStream | Blob` +**payableId:** `string`
@@ -9402,7 +9982,7 @@ await client.payables.attachFileById(fs.createReadStream("/path/to/your/file"),
-**payableId:** `string` +**request:** `Monite.PayableAttachFile`
@@ -9547,6 +10127,77 @@ await client.payables.postPayablesIdCancelOcr("payable_id");
+
client.payables.getPayablesIdHistory(payableId, { ...params }) -> Monite.PayableHistoryPaginationResponse +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Returns a chronological list of events related to the specified payable. This includes changes in status, updates to data, comments, and actions taken by users or automation rules. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.payables.getPayablesIdHistory("payable_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**payableId:** `string` β€” The unique identifier of the payable whose history you want to retrieve. + +
+
+ +
+
+ +**request:** `Monite.GetPayablesIdHistoryRequest` + +
+
+ +
+
+ +**requestOptions:** `Payables.RequestOptions` + +
+
+
+
+ +
+
+
+
client.payables.markAsPaidById(payableId, { ...params }) -> Monite.PayableResponseSchema
@@ -9812,7 +10463,7 @@ await client.payables.rejectById("payable_id");
-Reset payable state from rejected to new. +Moves payables in the `rejected` or `waiting_to_be_paid` statuses back to `new`, allowing further actions such as editing, approval, or payment. The
@@ -9844,7 +10495,7 @@ await client.payables.reopenById("payable_id");
-**payableId:** `string` +**payableId:** `string` β€” The unique identifier of the payable you want to reopen.
@@ -9926,7 +10577,7 @@ await client.payables.submitForApprovalById("payable_id");
-
client.payables.validateById(payableId) -> Monite.PayableValidationResponse +
client.payables.getPayablesIdSuggestions(payableId) -> Monite.SuggestedResponse
@@ -9938,7 +10589,13 @@ await client.payables.submitForApprovalById("payable_id");
-Check the invoice for compliance with the requirements for movement from draft to new status. +Retrieves the most likely matching counterpart for a given payable, based on an AI-powered analysis of the payable's data. + +When a user uploads a payable, Monite automatically compares key fieldsβ€”such as `name`, `address`, `VAT ID`, and bank `account`β€”against existing counterparts. If a sufficiently similar match is found, this endpoint will return a suggested counterpart. + +If no suitable match is identified, the response will be empty. + +**Note:** Suggestions are automatically generated during payable upload. This endpoint simply retrieves the existing suggestion for a specific payable.
@@ -9954,7 +10611,7 @@ Check the invoice for compliance with the requirements for movement from draft t
```typescript -await client.payables.validateById("payable_id"); +await client.payables.getPayablesIdSuggestions("payable_id"); ```
@@ -9970,7 +10627,7 @@ await client.payables.validateById("payable_id");
-**payableId:** `string` +**payableId:** `string` β€” The unique identifier of the payable you want to find matching suggestions for.
@@ -9989,12 +10646,25 @@ await client.payables.validateById("payable_id");
-## Payment intents +
client.payables.deletePayablesIdSuggestions(payableId) -> unknown +
+
+ +#### πŸ“ Description + +
+
-
client.paymentIntents.get({ ...params }) -> Monite.PaymentIntentsListResponse
+Deletes the automatically generated counterpart suggestion for a specific payable. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -10004,7 +10674,7 @@ await client.payables.validateById("payable_id");
```typescript -await client.paymentIntents.get(); +await client.payables.deletePayablesIdSuggestions("payable_id"); ```
@@ -10020,7 +10690,7 @@ await client.paymentIntents.get();
-**request:** `Monite.PaymentIntentsGetRequest` +**payableId:** `string` β€” The unique identifier of the payable whose suggestions you want to delete.
@@ -10028,7 +10698,7 @@ await client.paymentIntents.get();
-**requestOptions:** `PaymentIntents.RequestOptions` +**requestOptions:** `Payables.RequestOptions`
@@ -10039,10 +10709,25 @@ await client.paymentIntents.get();
-
client.paymentIntents.getById(paymentIntentId) -> Monite.PaymentIntentResponse +
client.payables.validateById(payableId) -> Monite.PayableValidationResponse +
+
+ +#### πŸ“ Description + +
+
+
+Check the invoice for compliance with the requirements for movement from draft to new status. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -10052,7 +10737,7 @@ await client.paymentIntents.get();
```typescript -await client.paymentIntents.getById("payment_intent_id"); +await client.payables.validateById("payable_id"); ```
@@ -10068,7 +10753,7 @@ await client.paymentIntents.getById("payment_intent_id");
-**paymentIntentId:** `string` +**payableId:** `string`
@@ -10076,7 +10761,7 @@ await client.paymentIntents.getById("payment_intent_id");
-**requestOptions:** `PaymentIntents.RequestOptions` +**requestOptions:** `Payables.RequestOptions`
@@ -10087,7 +10772,9 @@ await client.paymentIntents.getById("payment_intent_id");
-
client.paymentIntents.updateById(paymentIntentId, { ...params }) -> Monite.PaymentIntentResponse +## Payment intents + +
client.paymentIntents.get({ ...params }) -> Monite.PaymentIntentsListResponse
@@ -10100,9 +10787,7 @@ await client.paymentIntents.getById("payment_intent_id");
```typescript -await client.paymentIntents.updateById("payment_intent_id", { - amount: 1, -}); +await client.paymentIntents.get(); ```
@@ -10118,15 +10803,7 @@ await client.paymentIntents.updateById("payment_intent_id", {
-**paymentIntentId:** `string` - -
-
- -
-
- -**request:** `Monite.UpdatePaymentIntentPayload` +**request:** `Monite.PaymentIntentsGetRequest`
@@ -10145,7 +10822,7 @@ await client.paymentIntents.updateById("payment_intent_id", {
-
client.paymentIntents.getHistoryById(paymentIntentId) -> Monite.PaymentIntentHistoryResponse +
client.paymentIntents.getById(paymentIntentId) -> Monite.PaymentIntentResponse
@@ -10158,7 +10835,7 @@ await client.paymentIntents.updateById("payment_intent_id", {
```typescript -await client.paymentIntents.getHistoryById("payment_intent_id"); +await client.paymentIntents.getById("payment_intent_id"); ```
@@ -10193,9 +10870,7 @@ await client.paymentIntents.getHistoryById("payment_intent_id");
-## Payment links - -
client.paymentLinks.create({ ...params }) -> Monite.PublicPaymentLinkResponse +
client.paymentIntents.updateById(paymentIntentId, { ...params }) -> Monite.PaymentIntentResponse
@@ -10208,12 +10883,8 @@ await client.paymentIntents.getHistoryById("payment_intent_id");
```typescript -await client.paymentLinks.create({ - payment_methods: ["sepa_credit"], - recipient: { - id: "id", - type: "entity", - }, +await client.paymentIntents.updateById("payment_intent_id", { + amount: 1, }); ``` @@ -10230,7 +10901,7 @@ await client.paymentLinks.create({
-**request:** `Monite.CreatePaymentLinkRequest` +**paymentIntentId:** `string`
@@ -10238,7 +10909,15 @@ await client.paymentLinks.create({
-**requestOptions:** `PaymentLinks.RequestOptions` +**request:** `Monite.UpdatePaymentIntentPayload` + +
+
+ +
+
+ +**requestOptions:** `PaymentIntents.RequestOptions`
@@ -10249,7 +10928,7 @@ await client.paymentLinks.create({
-
client.paymentLinks.getById(paymentLinkId) -> Monite.PublicPaymentLinkResponse +
client.paymentIntents.getHistoryById(paymentIntentId) -> Monite.PaymentIntentHistoryResponse
@@ -10262,7 +10941,7 @@ await client.paymentLinks.create({
```typescript -await client.paymentLinks.getById("payment_link_id"); +await client.paymentIntents.getHistoryById("payment_intent_id"); ```
@@ -10278,7 +10957,131 @@ await client.paymentLinks.getById("payment_link_id");
-**paymentLinkId:** `string` +**paymentIntentId:** `string` + +
+
+ +
+
+ +**requestOptions:** `PaymentIntents.RequestOptions` + +
+
+ +
+ + + +
+ +## Payment links + +
client.paymentLinks.create({ ...params }) -> Monite.PublicPaymentLinkResponse +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Create a new [payment link](https://docs.monite.com/payments/payment-links) for an accounts payble invoice (to be paid by the entity) or an accounts receivable invoice (to be sent to the counterpart). + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.paymentLinks.create({ + object: { + id: "5940eb3a-de95-4e7e-b5e7-8a4ad0ea341b", + type: "payable", + }, + payment_methods: ["sepa_credit"], + recipient: { + id: "6296af34-6feb-43c1-b567-83e3bf45050c", + type: "counterpart", + }, + return_url: "https://example.com/where-to-redirect-after-payment", +}); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.CreatePaymentLinkRequest` + +
+
+ +
+
+ +**requestOptions:** `PaymentLinks.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.paymentLinks.getById(paymentLinkId) -> Monite.PublicPaymentLinkResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.paymentLinks.getById("payment_link_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**paymentLinkId:** `string`
@@ -10415,7 +11218,6 @@ await client.paymentRecords.create({ id: "id", type: "receivable", }, - payment_intent_id: "payment_intent_id", }); ``` @@ -11025,9 +11827,10 @@ await client.paymentTerms.get(); ```typescript await client.paymentTerms.create({ - name: "name", + description: "Payment is due within 30 days after the invoice issue date", + name: "Net 30", term_final: { - number_of_days: 1, + number_of_days: 30, }, }); ``` @@ -11795,93 +12598,12 @@ await client.projects.updateById("project_id");
-## Receivables - -
client.receivables.get({ ...params }) -> Monite.ReceivablePaginationResponse -
-
- -#### πŸ“ Description - -
-
+## Receipts +
client.receipts.getReceipts({ ...params }) -> Monite.ReceiptPaginationResponse
-Returns a list of [accounts receivable](https://docs.monite.com/accounts-receivable/index) documents - invoices, quotes, and credit notes - of the specified entity. - -Results can be filtered by amount, counterpart, due date, and other criteria. Multiple filters are combined using logical AND unless specified otherwise. If no documents matching the search criteria are found, the endpoint returns a successful response with an empty `data` array. - -This endpoint supports [pagination](https://docs.monite.com/api/concepts/pagination-sorting-filtering) and sorting. By default, results are sorted by the creation date in ascending order (from oldest to newest). - -#### Examples - -##### Invoices - -- Get all overdue invoices: - - ``` - GET /receivables?type=invoice&status=overdue - ``` - -- Get all invoices created for the counterpart named "Solarwind" (case-insensitive): - - ``` - GET /receivables?type=invoice?counterpart_name__icontains=Solarwind - ``` - -- Get invoices whose total amount starts from 500 EUR: - - ``` - GET /receivables?type=invoice&total_amount__gte=50000 - ``` - -- Get invoices that are due for payment in September 2024: - - ``` - GET /receivables?type=invoice&due_date__gte=2024-09-01T00:00:00Z&due_date__lt=2024-10-01T00:00:00Z - ``` - -- Get invoices created on or after September 1, 2024: - - ``` - GET /receivables?type=invoice&created_at__gte=2024-09-01T00:00:00Z - ``` - -- Find an invoice created from a specific quote: - - ``` - GET /receivables?type=invoice?based_on=QUOTE_ID - ``` - -##### Quotes - -- Get the latest created quote: - - ``` - GET /receivables?type=quote&sort=created_at&order=desc&limit=1 - ``` - -- Get the latest issued quote: - - ``` - GET /receivables?type=quote&sort=issue_date&order=desc&limit=1 - ``` - -##### Credit notes - -- Find all credit notes created for a specific invoice: - - ``` - GET /receivables?type=credit_note?based_on=INVOICE_ID - ``` - -
-
-
-
- #### πŸ”Œ Usage
@@ -11891,7 +12613,7 @@ This endpoint supports [pagination](https://docs.monite.com/api/concepts/paginat
```typescript -await client.receivables.get(); +await client.receipts.getReceipts(); ```
@@ -11907,7 +12629,7 @@ await client.receivables.get();
-**request:** `Monite.ReceivablesGetRequest` +**request:** `Monite.GetReceiptsRequest`
@@ -11915,7 +12637,7 @@ await client.receivables.get();
-**requestOptions:** `Receivables.RequestOptions` +**requestOptions:** `Receipts.RequestOptions`
@@ -11926,7 +12648,7 @@ await client.receivables.get();
-
client.receivables.create({ ...params }) -> Monite.ReceivableResponse +
client.receipts.postReceipts({ ...params }) -> Monite.ReceiptResponseSchema
@@ -11939,17 +12661,7 @@ await client.receivables.get();
```typescript -await client.receivables.create({ - counterpart_billing_address_id: "counterpart_billing_address_id", - counterpart_id: "counterpart_id", - currency: "AED", - line_items: [ - { - quantity: 1.1, - }, - ], - type: "quote", -}); +await client.receipts.postReceipts(); ```
@@ -11965,7 +12677,7 @@ await client.receivables.create({
-**request:** `Monite.ReceivableFacadeCreatePayload` +**request:** `Monite.ReceiptCreateSchema`
@@ -11973,7 +12685,7 @@ await client.receivables.create({
-**requestOptions:** `Receivables.RequestOptions` +**requestOptions:** `Receipts.RequestOptions`
@@ -11984,7 +12696,7 @@ await client.receivables.create({
-
client.receivables.getReceivablesRequiredFields({ ...params }) -> Monite.ReceivableRequiredFields +
client.receipts.postReceiptsUploadFromFile({ ...params }) -> Monite.ReceiptResponseSchema
@@ -11996,7 +12708,7 @@ await client.receivables.create({
-Get field requirements for invoice creation given the entity and counterpart details. +Upload an incoming receipt in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB.
@@ -12012,7 +12724,9 @@ Get field requirements for invoice creation given the entity and counterpart det
```typescript -await client.receivables.getReceivablesRequiredFields(); +await client.receipts.postReceiptsUploadFromFile({ + file: fs.createReadStream("/path/to/your/file"), +}); ```
@@ -12028,7 +12742,7 @@ await client.receivables.getReceivablesRequiredFields();
-**request:** `Monite.GetReceivablesRequiredFieldsRequest` +**request:** `Monite.ReceiptUploadFile`
@@ -12036,7 +12750,7 @@ await client.receivables.getReceivablesRequiredFields();
-**requestOptions:** `Receivables.RequestOptions` +**requestOptions:** `Receipts.RequestOptions`
@@ -12047,11 +12761,11 @@ await client.receivables.getReceivablesRequiredFields();
-
client.receivables.getVariables() -> Monite.ReceivableTemplatesVariablesObjectList +
client.receipts.getReceiptsId(receiptId) -> Monite.ReceiptResponseSchema
-#### πŸ“ Description +#### πŸ”Œ Usage
@@ -12059,14 +12773,16 @@ await client.receivables.getReceivablesRequiredFields();
-Get a list of placeholders that can be used in email templates for customization. +```typescript +await client.receipts.getReceiptsId("receipt_id"); +```
-#### πŸ”Œ Usage +#### βš™οΈ Parameters
@@ -12074,24 +12790,15 @@ Get a list of placeholders that can be used in email templates for customization
-```typescript -await client.receivables.getVariables(); -``` +**receiptId:** `string`
-
-
- -#### βš™οΈ Parameters - -
-
-**requestOptions:** `Receivables.RequestOptions` +**requestOptions:** `Receipts.RequestOptions`
@@ -12102,7 +12809,7 @@ await client.receivables.getVariables();
-
client.receivables.getById(receivableId) -> Monite.ReceivableResponse +
client.receipts.deleteReceiptsId(receiptId) -> void
@@ -12115,7 +12822,7 @@ await client.receivables.getVariables();
```typescript -await client.receivables.getById("receivable_id"); +await client.receipts.deleteReceiptsId("receipt_id"); ```
@@ -12131,7 +12838,7 @@ await client.receivables.getById("receivable_id");
-**receivableId:** `string` +**receiptId:** `string`
@@ -12139,7 +12846,7 @@ await client.receivables.getById("receivable_id");
-**requestOptions:** `Receivables.RequestOptions` +**requestOptions:** `Receipts.RequestOptions`
@@ -12150,7 +12857,7 @@ await client.receivables.getById("receivable_id");
-
client.receivables.deleteById(receivableId) -> void +
client.receipts.patchReceiptsId(receiptId, { ...params }) -> Monite.ReceiptResponseSchema
@@ -12163,7 +12870,7 @@ await client.receivables.getById("receivable_id");
```typescript -await client.receivables.deleteById("receivable_id"); +await client.receipts.patchReceiptsId("receipt_id"); ```
@@ -12179,7 +12886,7 @@ await client.receivables.deleteById("receivable_id");
-**receivableId:** `string` +**receiptId:** `string`
@@ -12187,13 +12894,807 @@ await client.receivables.deleteById("receivable_id");
-**requestOptions:** `Receivables.RequestOptions` +**request:** `Monite.ReceiptUpdateSchema`
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` +
- + +
+ + + +
+ +
client.receipts.postReceiptsIdAttachFile(receiptId, { ...params }) -> Monite.ReceiptResponseSchema +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Attach file to receipt without existing attachment. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receipts.postReceiptsIdAttachFile("receipt_id", { + file: fs.createReadStream("/path/to/your/file"), +}); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receiptId:** `string` + +
+
+ +
+
+ +**request:** `Monite.ReceiptAttachFile` + +
+
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receipts.getReceiptsIdLineItems(receiptId, { ...params }) -> Monite.ReceiptLineItemsPaginationResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receipts.getReceiptsIdLineItems("receipt_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receiptId:** `string` + +
+
+ +
+
+ +**request:** `Monite.GetReceiptsIdLineItemsRequest` + +
+
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receipts.postReceiptsIdLineItems(receiptId, { ...params }) -> Monite.ReceiptLineItemResponseSchema +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receipts.postReceiptsIdLineItems("receipt_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receiptId:** `string` + +
+
+ +
+
+ +**request:** `Monite.ReceiptLineItemCreateSchema` + +
+
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receipts.deleteReceiptsIdLineItemsId(receiptId, lineItemId) -> void +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receipts.deleteReceiptsIdLineItemsId("receipt_id", "line_item_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receiptId:** `string` + +
+
+ +
+
+ +**lineItemId:** `string` + +
+
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receipts.patchReceiptsIdLineItemsId(receiptId, lineItemId, { ...params }) -> Monite.ReceiptLineItemResponseSchema +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receipts.patchReceiptsIdLineItemsId("receipt_id", "line_item_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receiptId:** `string` + +
+
+ +
+
+ +**lineItemId:** `string` + +
+
+ +
+
+ +**request:** `Monite.ReceiptLineItemUpdateSchema` + +
+
+ +
+
+ +**requestOptions:** `Receipts.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Receivables + +
client.receivables.get({ ...params }) -> Monite.ReceivablePaginationResponse +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Returns a list of [accounts receivable](https://docs.monite.com/accounts-receivable/index) documents - invoices, quotes, and credit notes - of the specified entity. + +Results can be filtered by amount, counterpart, due date, and other criteria. Multiple filters are combined using logical AND unless specified otherwise. If no documents matching the search criteria are found, the endpoint returns a successful response with an empty `data` array. + +This endpoint supports [pagination](https://docs.monite.com/api/concepts/pagination-sorting-filtering) and sorting. By default, results are sorted by the creation date in ascending order (from oldest to newest). + +#### Examples + +##### Invoices + +- Get all overdue invoices: + + ``` + GET /receivables?type=invoice&status=overdue + ``` + +- Get all invoices created for the counterpart named "Solarwind" (case-insensitive): + + ``` + GET /receivables?type=invoice?counterpart_name__icontains=Solarwind + ``` + +- Get invoices whose total amount starts from 500 EUR: + + ``` + GET /receivables?type=invoice&total_amount__gte=50000 + ``` + +- Get invoices that are due for payment in September 2024: + + ``` + GET /receivables?type=invoice&due_date__gte=2024-09-01T00:00:00Z&due_date__lt=2024-10-01T00:00:00Z + ``` + +- Get invoices created on or after September 1, 2024: + + ``` + GET /receivables?type=invoice&created_at__gte=2024-09-01T00:00:00Z + ``` + +- Find an invoice created from a specific quote: + + ``` + GET /receivables?type=invoice?based_on=QUOTE_ID + ``` + +##### Quotes + +- Get the latest created quote: + + ``` + GET /receivables?type=quote&sort=created_at&order=desc&limit=1 + ``` + +- Get the latest issued quote: + + ``` + GET /receivables?type=quote&sort=issue_date&order=desc&limit=1 + ``` + +##### Credit notes + +- Find all credit notes created for a specific invoice: + + ``` + GET /receivables?type=credit_note?based_on=INVOICE_ID + ``` + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.get(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.ReceivablesGetRequest` + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.create({ ...params }) -> Monite.ReceivableResponse +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.create({ + based_on: "based_on", + type: "invoice", +}); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.ReceivableFacadeCreatePayload` + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.getReceivablesRequiredFields({ ...params }) -> Monite.ReceivableRequiredFields +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Get field requirements for invoice creation given the entity and counterpart details. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.getReceivablesRequiredFields(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.GetReceivablesRequiredFieldsRequest` + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.postReceivablesSearch({ ...params }) -> Monite.ReceivablePaginationResponse +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +This is a POST version of the `GET /receivables` endpoint. Use it to send search and filter parameters in the request body instead of the URL query string in case the query is too long and exceeds the URL length limit of your HTTP client. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.postReceivablesSearch({ + status: "draft", + type: "invoice", +}); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**request:** `Monite.ReceivablesSearchRequest` + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.getVariables() -> Monite.ReceivableTemplatesVariablesObjectList +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Get a list of placeholders that can be used in email templates for customization. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.getVariables(); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.getById(receivableId) -> Monite.ReceivableResponse +
+
+ +#### πŸ“ Description + +
+
+ +
+
+ +Returns the details of an existing accounts receivable invoice, quote, or credit note with the specified ID. + +The response fields vary depending on the document type. Use the `type` field to distinguish between different document types. + +Entity users with the `receivable.read.allowed_for_own` permission (rather than `allowed`) can access only documents that they created themselves. + +
+
+
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.getById("receivable_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receivableId:** `string` β€” ID of an existing invoice, quote, or credit note that you want to retrieve. + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.receivables.deleteById(receivableId) -> void +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.receivables.deleteById("receivable_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**receivableId:** `string` + +
+
+ +
+
+ +**requestOptions:** `Receivables.RequestOptions` + +
+
+
+
+
@@ -12260,6 +13761,23 @@ await client.receivables.updateById("receivable_id", {
+#### πŸ“ Description + +
+
+ +
+
+ +Only quotes in the `issued` status can be accepted. + +When a quote is accepted, Monite automatically creates a draft invoice based on this quote. To find the newly created invoice, use `GET /receivables?based_on=QUOTE_ID`. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -12269,7 +13787,13 @@ await client.receivables.updateById("receivable_id", {
```typescript -await client.receivables.acceptById("receivable_id"); +await client.receivables.acceptById("receivable_id", { + signature: { + email: "theo@example.com", + full_name: "Theo Quinn", + signature_image: "iVBORw0KGgoAAAANSUhEUg.....AAABJRU5ErkJggg==", + }, +}); ```
@@ -12364,6 +13888,29 @@ await client.receivables.cancelById("receivable_id");
+#### πŸ“ Description + +
+
+ +
+
+ +Creates a copy of an existing accounts receivable invoice or quote. The original document can be in any status. The cloned document will have the `draft` status. + +Cloning a document requires that all of the referenced resource IDs (counterpart ID, product IDs, and others) still exist. + +Most of the original document's data is copied as is, with a few exceptions: + +- Some fields are not copied: `attachments`, `document_id`, `issue_date`, quote `expiry_date`. +- Counterpart details, entity bank account details, and entity VAT number are fetched anew from their corresponding IDs. +This means, for example, that if the counterpart details have been changed since the original invoice or quote was created, +the cloned document will use the current counterpart details rather than the old details from the original document. +
+
+
+
+ #### πŸ”Œ Usage
@@ -12389,7 +13936,7 @@ await client.receivables.cloneById("receivable_id");
-**receivableId:** `string` +**receivableId:** `string` β€” ID of an existing invoice or quote that you want to clone.
@@ -12412,6 +13959,21 @@ await client.receivables.cloneById("receivable_id");
+#### πŸ“ Description + +
+
+ +
+
+ +Only quotes in the `issued` status can be declined. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -13082,6 +14644,25 @@ await client.receivables.getPdfLinkById("receivable_id");
+#### πŸ“ Description + +
+
+ +
+
+ +You can preview emails only for documents in the following statuses: + +- Invoices: `draft`, `issued`, `overdue`, `partially_paid`, `paid`. + In the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance): also `canceled`. +- Quotes: `draft`, `issued`. +- Credit notes: `draft`, `issued`. +
+
+
+
+ #### πŸ”Œ Usage
@@ -13141,6 +14722,30 @@ await client.receivables.previewById("receivable_id", {
+#### πŸ“ Description + +
+
+ +
+
+ +Only documents in the following statuses can be sent via email: + +- Invoices: `draft`, `issued`, `overdue`, `partially_paid`, `paid`. + In the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance): also `canceled`. +- Quotes: `draft`, `issued`. +- Credit notes: `draft`, `issued`. + +Draft documents are automatically moved to the `issued` status before sending. + +For more information, see [Send an invoice via email](https://docs.monite.com/accounts-receivable/invoices/create#send-via-email). + +
+
+
+
+ #### πŸ”Œ Usage
@@ -13304,7 +14909,7 @@ await client.receivables.verifyById("receivable_id"); ## Recurrences -
client.recurrences.get() -> Monite.GetAllRecurrences +
client.recurrences.get() -> Monite.RecurrenceResponseList
@@ -13344,7 +14949,7 @@ await client.recurrences.get();
-
client.recurrences.create({ ...params }) -> Monite.Recurrence +
client.recurrences.create({ ...params }) -> Monite.RecurrenceResponse
@@ -13358,12 +14963,7 @@ await client.recurrences.get(); ```typescript await client.recurrences.create({ - day_of_month: "first_day", - end_month: 1, - end_year: 1, invoice_id: "invoice_id", - start_month: 1, - start_year: 1, }); ``` @@ -13399,7 +14999,7 @@ await client.recurrences.create({
-
client.recurrences.getById(recurrenceId) -> Monite.Recurrence +
client.recurrences.getById(recurrenceId) -> Monite.RecurrenceResponse
@@ -13447,7 +15047,7 @@ await client.recurrences.getById("recurrence_id");
-
client.recurrences.updateById(recurrenceId, { ...params }) -> Monite.Recurrence +
client.recurrences.updateById(recurrenceId, { ...params }) -> Monite.RecurrenceResponse
@@ -13551,6 +15151,102 @@ await client.recurrences.cancelById("recurrence_id");
+
client.recurrences.postRecurrencesIdPause(recurrenceId) -> unknown +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.recurrences.postRecurrencesIdPause("recurrence_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**recurrenceId:** `string` + +
+
+ +
+
+ +**requestOptions:** `Recurrences.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.recurrences.postRecurrencesIdResume(recurrenceId) -> unknown +
+
+ +#### πŸ”Œ Usage + +
+
+ +
+
+ +```typescript +await client.recurrences.postRecurrencesIdResume("recurrence_id"); +``` + +
+
+
+
+ +#### βš™οΈ Parameters + +
+
+ +
+
+ +**recurrenceId:** `string` + +
+
+ +
+
+ +**requestOptions:** `Recurrences.RequestOptions` + +
+
+
+
+ +
+
+
+ ## Roles
client.roles.get({ ...params }) -> Monite.RolePaginationResponse @@ -13878,12 +15574,15 @@ await client.roles.updateById("role_id");
-Retrieve all settings for this partner. +Partner-level settings apply to all entities of that partner. -
-
-
-
+See also: + +- [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) +
+
+
+
#### πŸ”Œ Usage @@ -13933,12 +15632,15 @@ await client.partnerSettings.get();
-Change the specified fields with the provided values. +Partner-level settings apply to all entities of that partner. -
-
-
-
+See also: + +- [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) +
+
+ + #### πŸ”Œ Usage @@ -14716,6 +16418,31 @@ await client.textTemplates.makeDefaultById("text_template_id");
+#### πŸ“ Description + +
+
+ +
+
+ +Monite maintains a catalog of VAT and sales tax rates for [select countries](https://docs.monite.com/accounts-receivable/vat-rates#supported-countries). + +To query the applicable VAT/tax rates for an invoice or quote, use: + +`GET /vat_rates?counterpart_id=<...>&entity_vat_id_id=<...>` + +Or if the entity does not have a VAT ID: + +`GET /vat_rates?counterpart_id=<...>` + +**Note:** Entities from countries [not on the list](https://docs.monite.com/accounts-receivable/vat-rates#supported-countries) should not use this endpoint. Instead, those entities can either create custom VAT/tax rates or use the invoice field `line_items[].tax_rate_value` to specify the VAT/tax rates directly. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -14835,6 +16562,21 @@ await client.webhookDeliveries.get();
+#### πŸ“ Description + +
+
+ +
+
+ +Returns a list of all [webhook](https://docs.monite.com/references/webhooks/index) subscriptions (both active and disabled). + +
+
+
+
+ #### πŸ”Œ Usage
@@ -14883,6 +16625,21 @@ await client.webhookSubscriptions.get();
+#### πŸ“ Description + +
+
+ +
+
+ +Related guide: [Webhooks](https://docs.monite.com/references/webhooks/index). + +
+
+
+
+ #### πŸ”Œ Usage
@@ -14893,8 +16650,9 @@ await client.webhookSubscriptions.get(); ```typescript await client.webhookSubscriptions.create({ - object_type: "account", - url: "url", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "entity", + url: "https://example.com/your-webhook-listener", }); ``` @@ -14934,6 +16692,23 @@ await client.webhookSubscriptions.create({
+#### πŸ“ Description + +
+
+ +
+
+ +Returns the details of the webhook subscription with the specified ID. + +The response does not include the [webhook signing secret](https://docs.monite.com/references/webhooks/signatures). If you lost the secret, you can [regenerate it](https://docs.monite.com/api/webhook-subscriptions/post-webhook-subscriptions-id-regenerate-secret). + +
+
+
+
+ #### πŸ”Œ Usage
@@ -14959,7 +16734,7 @@ await client.webhookSubscriptions.getById("webhook_subscription_id");
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -15007,7 +16782,7 @@ await client.webhookSubscriptions.deleteById("webhook_subscription_id");
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -15030,6 +16805,21 @@ await client.webhookSubscriptions.deleteById("webhook_subscription_id");
+#### πŸ“ Description + +
+
+ +
+
+ +You can update the webhook listener URL or the event list. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -15055,7 +16845,7 @@ await client.webhookSubscriptions.updateById("webhook_subscription_id");
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -15111,7 +16901,7 @@ await client.webhookSubscriptions.disableById("webhook_subscription_id");
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -15159,7 +16949,7 @@ await client.webhookSubscriptions.enableById("webhook_subscription_id");
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -15182,6 +16972,21 @@ await client.webhookSubscriptions.enableById("webhook_subscription_id");
+#### πŸ“ Description + +
+
+ +
+
+ +The webhook signing secret lets you [verify webhook signatures](https://docs.monite.com/references/webhooks/signatures). If you lost the original secret generated for any of your webhook subscriptions, you can regenerate it. + +
+
+
+
+ #### πŸ”Œ Usage
@@ -15207,7 +17012,7 @@ await client.webhookSubscriptions.regenerateSecretById("webhook_subscription_id"
-**webhookSubscriptionId:** `string` +**webhookSubscriptionId:** `string` β€” ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks.
@@ -18115,8 +19920,14 @@ For other countries: ```typescript await client.entities.bankAccounts.create({ - country: "AF", - currency: "AED", + account_holder_name: "Tobias Weingart", + bank_name: "DEUTSCHE BANK AG", + bic: "DEUTDEFFXXX", + country: "DE", + currency: "EUR", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, }); ``` @@ -18611,7 +20422,10 @@ Set which payment methods should be enabled.
```typescript -await client.entities.paymentMethods.set("entity_id"); +await client.entities.paymentMethods.set("entity_id", { + payment_methods_receive: ["card", "sepa_credit", "sepa_debit"], + payment_methods_send: ["sepa_credit"], +}); ```
diff --git a/scripts/rename-to-esm-files.js b/scripts/rename-to-esm-files.js index 81dac6a..dc1df1c 100644 --- a/scripts/rename-to-esm-files.js +++ b/scripts/rename-to-esm-files.js @@ -50,8 +50,16 @@ async function updateFileContents(file) { let newContent = content; // Update each extension type defined in the map for (const [oldExt, newExt] of Object.entries(extensionMap)) { - const regex = new RegExp(`(import|export)(.+from\\s+['"])(\\.\\.?\\/[^'"]+)(\\${oldExt})(['"])`, "g"); - newContent = newContent.replace(regex, `$1$2$3${newExt}$5`); + // Handle static imports/exports + const staticRegex = new RegExp(`(import|export)(.+from\\s+['"])(\\.\\.?\\/[^'"]+)(\\${oldExt})(['"])`, "g"); + newContent = newContent.replace(staticRegex, `$1$2$3${newExt}$5`); + + // Handle dynamic imports (yield import, await import, regular import()) + const dynamicRegex = new RegExp( + `(yield\\s+import|await\\s+import|import)\\s*\\(\\s*['"](\\.\\.\?\\/[^'"]+)(\\${oldExt})['"]\\s*\\)`, + "g", + ); + newContent = newContent.replace(dynamicRegex, `$1("$2${newExt}")`); } if (content !== newContent) { diff --git a/src/Client.ts b/src/Client.ts index 8b242e1..55ae3f2 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -2,50 +2,54 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "./environments"; -import * as core from "./core"; -import { Analytics } from "./api/resources/analytics/client/Client"; -import { ApprovalPolicies } from "./api/resources/approvalPolicies/client/Client"; -import { ApprovalRequests } from "./api/resources/approvalRequests/client/Client"; -import { AccessTokens } from "./api/resources/accessTokens/client/Client"; -import { Comments } from "./api/resources/comments/client/Client"; -import { Counterparts } from "./api/resources/counterparts/client/Client"; -import { CounterpartEInvoicingCredentials } from "./api/resources/counterpartEInvoicingCredentials/client/Client"; -import { DataExports } from "./api/resources/dataExports/client/Client"; -import { DeliveryNotes } from "./api/resources/deliveryNotes/client/Client"; -import { PdfTemplates } from "./api/resources/pdfTemplates/client/Client"; -import { EInvoicingConnections } from "./api/resources/eInvoicingConnections/client/Client"; -import { Entities } from "./api/resources/entities/client/Client"; -import { EntityUsers } from "./api/resources/entityUsers/client/Client"; -import { Events } from "./api/resources/events/client/Client"; -import { Files } from "./api/resources/files/client/Client"; -import { Financing } from "./api/resources/financing/client/Client"; -import { MailTemplates } from "./api/resources/mailTemplates/client/Client"; -import { MailboxDomains } from "./api/resources/mailboxDomains/client/Client"; -import { Mailboxes } from "./api/resources/mailboxes/client/Client"; -import { MeasureUnits } from "./api/resources/measureUnits/client/Client"; -import { Ocr } from "./api/resources/ocr/client/Client"; -import { OverdueReminders } from "./api/resources/overdueReminders/client/Client"; -import { CreditNotes } from "./api/resources/creditNotes/client/Client"; -import { PurchaseOrders } from "./api/resources/purchaseOrders/client/Client"; -import { Payables } from "./api/resources/payables/client/Client"; -import { PaymentIntents } from "./api/resources/paymentIntents/client/Client"; -import { PaymentLinks } from "./api/resources/paymentLinks/client/Client"; -import { PaymentRecords } from "./api/resources/paymentRecords/client/Client"; -import { PaymentReminders } from "./api/resources/paymentReminders/client/Client"; -import { PaymentTerms } from "./api/resources/paymentTerms/client/Client"; -import { Products } from "./api/resources/products/client/Client"; -import { Projects } from "./api/resources/projects/client/Client"; -import { Receivables } from "./api/resources/receivables/client/Client"; -import { Recurrences } from "./api/resources/recurrences/client/Client"; -import { Roles } from "./api/resources/roles/client/Client"; -import { PartnerSettings } from "./api/resources/partnerSettings/client/Client"; -import { Tags } from "./api/resources/tags/client/Client"; -import { TextTemplates } from "./api/resources/textTemplates/client/Client"; -import { VatRates } from "./api/resources/vatRates/client/Client"; -import { WebhookDeliveries } from "./api/resources/webhookDeliveries/client/Client"; -import { WebhookSubscriptions } from "./api/resources/webhookSubscriptions/client/Client"; -import { Accounting } from "./api/resources/accounting/client/Client"; +import * as environments from "./environments.js"; +import * as core from "./core/index.js"; +import { mergeHeaders } from "./core/headers.js"; +import { Analytics } from "./api/resources/analytics/client/Client.js"; +import { ApprovalPolicies } from "./api/resources/approvalPolicies/client/Client.js"; +import { ApprovalRequests } from "./api/resources/approvalRequests/client/Client.js"; +import { AccessTokens } from "./api/resources/accessTokens/client/Client.js"; +import { Comments } from "./api/resources/comments/client/Client.js"; +import { Counterparts } from "./api/resources/counterparts/client/Client.js"; +import { CounterpartEInvoicingCredentials } from "./api/resources/counterpartEInvoicingCredentials/client/Client.js"; +import { CustomVatRates } from "./api/resources/customVatRates/client/Client.js"; +import { DataExports } from "./api/resources/dataExports/client/Client.js"; +import { DeliveryNotes } from "./api/resources/deliveryNotes/client/Client.js"; +import { PdfTemplates } from "./api/resources/pdfTemplates/client/Client.js"; +import { EInvoicingSearch } from "./api/resources/eInvoicingSearch/client/Client.js"; +import { EInvoicingConnections } from "./api/resources/eInvoicingConnections/client/Client.js"; +import { Entities } from "./api/resources/entities/client/Client.js"; +import { EntityUsers } from "./api/resources/entityUsers/client/Client.js"; +import { Events } from "./api/resources/events/client/Client.js"; +import { Files } from "./api/resources/files/client/Client.js"; +import { Financing } from "./api/resources/financing/client/Client.js"; +import { MailTemplates } from "./api/resources/mailTemplates/client/Client.js"; +import { MailboxDomains } from "./api/resources/mailboxDomains/client/Client.js"; +import { Mailboxes } from "./api/resources/mailboxes/client/Client.js"; +import { MeasureUnits } from "./api/resources/measureUnits/client/Client.js"; +import { Ocr } from "./api/resources/ocr/client/Client.js"; +import { OverdueReminders } from "./api/resources/overdueReminders/client/Client.js"; +import { CreditNotes } from "./api/resources/creditNotes/client/Client.js"; +import { PurchaseOrders } from "./api/resources/purchaseOrders/client/Client.js"; +import { Payables } from "./api/resources/payables/client/Client.js"; +import { PaymentIntents } from "./api/resources/paymentIntents/client/Client.js"; +import { PaymentLinks } from "./api/resources/paymentLinks/client/Client.js"; +import { PaymentRecords } from "./api/resources/paymentRecords/client/Client.js"; +import { PaymentReminders } from "./api/resources/paymentReminders/client/Client.js"; +import { PaymentTerms } from "./api/resources/paymentTerms/client/Client.js"; +import { Products } from "./api/resources/products/client/Client.js"; +import { Projects } from "./api/resources/projects/client/Client.js"; +import { Receipts } from "./api/resources/receipts/client/Client.js"; +import { Receivables } from "./api/resources/receivables/client/Client.js"; +import { Recurrences } from "./api/resources/recurrences/client/Client.js"; +import { Roles } from "./api/resources/roles/client/Client.js"; +import { PartnerSettings } from "./api/resources/partnerSettings/client/Client.js"; +import { Tags } from "./api/resources/tags/client/Client.js"; +import { TextTemplates } from "./api/resources/textTemplates/client/Client.js"; +import { VatRates } from "./api/resources/vatRates/client/Client.js"; +import { WebhookDeliveries } from "./api/resources/webhookDeliveries/client/Client.js"; +import { WebhookSubscriptions } from "./api/resources/webhookSubscriptions/client/Client.js"; +import { Accounting } from "./api/resources/accounting/client/Client.js"; export declare namespace MoniteClient { export interface Options { @@ -57,6 +61,8 @@ export declare namespace MoniteClient { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -71,12 +77,15 @@ export declare namespace MoniteClient { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class MoniteClient { + protected readonly _options: MoniteClient.Options; protected _analytics: Analytics | undefined; protected _approvalPolicies: ApprovalPolicies | undefined; protected _approvalRequests: ApprovalRequests | undefined; @@ -84,9 +93,11 @@ export class MoniteClient { protected _comments: Comments | undefined; protected _counterparts: Counterparts | undefined; protected _counterpartEInvoicingCredentials: CounterpartEInvoicingCredentials | undefined; + protected _customVatRates: CustomVatRates | undefined; protected _dataExports: DataExports | undefined; protected _deliveryNotes: DeliveryNotes | undefined; protected _pdfTemplates: PdfTemplates | undefined; + protected _eInvoicingSearch: EInvoicingSearch | undefined; protected _eInvoicingConnections: EInvoicingConnections | undefined; protected _entities: Entities | undefined; protected _entityUsers: EntityUsers | undefined; @@ -109,6 +120,7 @@ export class MoniteClient { protected _paymentTerms: PaymentTerms | undefined; protected _products: Products | undefined; protected _projects: Projects | undefined; + protected _receipts: Receipts | undefined; protected _receivables: Receivables | undefined; protected _recurrences: Recurrences | undefined; protected _roles: Roles | undefined; @@ -120,7 +132,24 @@ export class MoniteClient { protected _webhookSubscriptions: WebhookSubscriptions | undefined; protected _accounting: Accounting | undefined; - constructor(protected readonly _options: MoniteClient.Options) {} + constructor(_options: MoniteClient.Options) { + this._options = { + ..._options, + headers: mergeHeaders( + { + "x-monite-version": _options?.moniteVersion, + "x-monite-entity-id": _options?.moniteEntityId, + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@monite/node-client", + "X-Fern-SDK-Version": "0.3.4", + "User-Agent": "@monite/node-client/0.3.4", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + }, + _options?.headers, + ), + }; + } public get analytics(): Analytics { return (this._analytics ??= new Analytics(this._options)); @@ -150,6 +179,10 @@ export class MoniteClient { return (this._counterpartEInvoicingCredentials ??= new CounterpartEInvoicingCredentials(this._options)); } + public get customVatRates(): CustomVatRates { + return (this._customVatRates ??= new CustomVatRates(this._options)); + } + public get dataExports(): DataExports { return (this._dataExports ??= new DataExports(this._options)); } @@ -162,6 +195,10 @@ export class MoniteClient { return (this._pdfTemplates ??= new PdfTemplates(this._options)); } + public get eInvoicingSearch(): EInvoicingSearch { + return (this._eInvoicingSearch ??= new EInvoicingSearch(this._options)); + } + public get eInvoicingConnections(): EInvoicingConnections { return (this._eInvoicingConnections ??= new EInvoicingConnections(this._options)); } @@ -250,6 +287,10 @@ export class MoniteClient { return (this._projects ??= new Projects(this._options)); } + public get receipts(): Receipts { + return (this._receipts ??= new Receipts(this._options)); + } + public get receivables(): Receivables { return (this._receivables ??= new Receivables(this._options)); } diff --git a/src/api/errors/BadRequestError.ts b/src/api/errors/BadRequestError.ts index b867a90..276464d 100644 --- a/src/api/errors/BadRequestError.ts +++ b/src/api/errors/BadRequestError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class BadRequestError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/ConflictError.ts b/src/api/errors/ConflictError.ts index 7a36dce..d2ed4b3 100644 --- a/src/api/errors/ConflictError.ts +++ b/src/api/errors/ConflictError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class ConflictError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/ContentTooLargeError.ts b/src/api/errors/ContentTooLargeError.ts index 70df937..c2690ac 100644 --- a/src/api/errors/ContentTooLargeError.ts +++ b/src/api/errors/ContentTooLargeError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class ContentTooLargeError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/FailedDependencyError.ts b/src/api/errors/FailedDependencyError.ts index 2cb0b45..119dd23 100644 --- a/src/api/errors/FailedDependencyError.ts +++ b/src/api/errors/FailedDependencyError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class FailedDependencyError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/ForbiddenError.ts b/src/api/errors/ForbiddenError.ts index c80a942..6513072 100644 --- a/src/api/errors/ForbiddenError.ts +++ b/src/api/errors/ForbiddenError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class ForbiddenError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/InternalServerError.ts b/src/api/errors/InternalServerError.ts deleted file mode 100644 index cbe2d83..0000000 --- a/src/api/errors/InternalServerError.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as errors from "../../errors/index"; -import * as core from "../../core"; - -export class InternalServerError extends errors.MoniteError { - constructor(body?: unknown, rawResponse?: core.RawResponse) { - super({ - message: "InternalServerError", - statusCode: 500, - body: body, - rawResponse: rawResponse, - }); - Object.setPrototypeOf(this, InternalServerError.prototype); - } -} diff --git a/src/api/errors/MisdirectedRequestError.ts b/src/api/errors/MisdirectedRequestError.ts index cf875ef..f1acdac 100644 --- a/src/api/errors/MisdirectedRequestError.ts +++ b/src/api/errors/MisdirectedRequestError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class MisdirectedRequestError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/NotAcceptableError.ts b/src/api/errors/NotAcceptableError.ts index b44d727..5a2acd5 100644 --- a/src/api/errors/NotAcceptableError.ts +++ b/src/api/errors/NotAcceptableError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class NotAcceptableError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/NotFoundError.ts b/src/api/errors/NotFoundError.ts index 08a9428..aee3e2e 100644 --- a/src/api/errors/NotFoundError.ts +++ b/src/api/errors/NotFoundError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class NotFoundError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/TooManyRequestsError.ts b/src/api/errors/TooManyRequestsError.ts new file mode 100644 index 0000000..9cc0507 --- /dev/null +++ b/src/api/errors/TooManyRequestsError.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; + +export class TooManyRequestsError extends errors.MoniteError { + constructor(body?: unknown, rawResponse?: core.RawResponse) { + super({ + message: "TooManyRequestsError", + statusCode: 429, + body: body, + rawResponse: rawResponse, + }); + Object.setPrototypeOf(this, TooManyRequestsError.prototype); + } +} diff --git a/src/api/errors/UnauthorizedError.ts b/src/api/errors/UnauthorizedError.ts index f49064f..421b519 100644 --- a/src/api/errors/UnauthorizedError.ts +++ b/src/api/errors/UnauthorizedError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class UnauthorizedError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/UnprocessableEntityError.ts b/src/api/errors/UnprocessableEntityError.ts index ae07122..5be08fd 100644 --- a/src/api/errors/UnprocessableEntityError.ts +++ b/src/api/errors/UnprocessableEntityError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class UnprocessableEntityError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/UnsupportedMediaTypeError.ts b/src/api/errors/UnsupportedMediaTypeError.ts index 307adab..32e8a86 100644 --- a/src/api/errors/UnsupportedMediaTypeError.ts +++ b/src/api/errors/UnsupportedMediaTypeError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as errors from "../../errors/index"; -import * as core from "../../core"; +import * as errors from "../../errors/index.js"; +import * as core from "../../core/index.js"; export class UnsupportedMediaTypeError extends errors.MoniteError { constructor(body?: unknown, rawResponse?: core.RawResponse) { diff --git a/src/api/errors/index.ts b/src/api/errors/index.ts index 2835a3c..d769ec7 100644 --- a/src/api/errors/index.ts +++ b/src/api/errors/index.ts @@ -1,12 +1,12 @@ -export * from "./UnprocessableEntityError"; -export * from "./InternalServerError"; -export * from "./UnauthorizedError"; -export * from "./ForbiddenError"; -export * from "./BadRequestError"; -export * from "./ConflictError"; -export * from "./NotFoundError"; -export * from "./NotAcceptableError"; -export * from "./ContentTooLargeError"; -export * from "./UnsupportedMediaTypeError"; -export * from "./MisdirectedRequestError"; -export * from "./FailedDependencyError"; +export * from "./UnauthorizedError.js"; +export * from "./UnprocessableEntityError.js"; +export * from "./TooManyRequestsError.js"; +export * from "./ForbiddenError.js"; +export * from "./BadRequestError.js"; +export * from "./ConflictError.js"; +export * from "./NotFoundError.js"; +export * from "./NotAcceptableError.js"; +export * from "./ContentTooLargeError.js"; +export * from "./UnsupportedMediaTypeError.js"; +export * from "./MisdirectedRequestError.js"; +export * from "./FailedDependencyError.js"; diff --git a/src/api/index.ts b/src/api/index.ts index 3006072..72cddbe 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,3 +1,3 @@ -export * from "./resources"; -export * from "./types"; -export * from "./errors"; +export * from "./resources/index.js"; +export * from "./types/index.js"; +export * from "./errors/index.js"; diff --git a/src/api/resources/accessTokens/client/Client.ts b/src/api/resources/accessTokens/client/Client.ts index 2d3b25f..308e074 100644 --- a/src/api/resources/accessTokens/client/Client.ts +++ b/src/api/resources/accessTokens/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace AccessTokens { export interface Options { @@ -18,6 +18,8 @@ export declare namespace AccessTokens { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace AccessTokens { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class AccessTokens { - constructor(protected readonly _options: AccessTokens.Options) {} + protected readonly _options: AccessTokens.Options; + + constructor(_options: AccessTokens.Options) { + this._options = _options; + } /** * Revoke an existing token immediately. @@ -46,8 +54,9 @@ export class AccessTokens { * @param {Monite.RevokeTokenPayload} request * @param {AccessTokens.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accessTokens.revoke({ @@ -67,30 +76,26 @@ export class AccessTokens { request: Monite.RevokeTokenPayload, requestOptions?: AccessTokens.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "auth/revoke", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -103,10 +108,12 @@ export class AccessTokens { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -139,16 +146,24 @@ export class AccessTokens { * @param {Monite.ObtainTokenPayload} request * @param {AccessTokens.RequestOptions} requestOptions - Request-specific configuration. * - * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.BadRequestError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accessTokens.create({ - * client_id: "client_id", - * client_secret: "client_secret", + * client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + * client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", * grant_type: "client_credentials" * }) + * + * @example + * await client.accessTokens.create({ + * client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + * client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", + * entity_user_id: "7abd8744-507c-40e6-a5ca-34aa480b3991", + * grant_type: "entity_user" + * }) */ public create( request: Monite.ObtainTokenPayload, @@ -161,30 +176,26 @@ export class AccessTokens { request: Monite.ObtainTokenPayload, requestOptions?: AccessTokens.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "auth/token", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -197,12 +208,12 @@ export class AccessTokens { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { - case 401: - throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accessTokens/client/index.ts b/src/api/resources/accessTokens/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accessTokens/client/index.ts +++ b/src/api/resources/accessTokens/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accessTokens/client/requests/ObtainTokenPayload.ts b/src/api/resources/accessTokens/client/requests/ObtainTokenPayload.ts index 7469ff3..aa6e1da 100644 --- a/src/api/resources/accessTokens/client/requests/ObtainTokenPayload.ts +++ b/src/api/resources/accessTokens/client/requests/ObtainTokenPayload.ts @@ -2,19 +2,36 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * { - * client_id: "client_id", - * client_secret: "client_secret", + * client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + * client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", * grant_type: "client_credentials" * } + * + * @example + * { + * client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + * client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", + * entity_user_id: "7abd8744-507c-40e6-a5ca-34aa480b3991", + * grant_type: "entity_user" + * } */ export interface ObtainTokenPayload { + /** Your partner [client ID](https://docs.monite.com/get-started/credentials#get-credentials) obtained from the "API Credentials" section of Monite Partner Portal. Note that the sandbox and production environment use different client IDs. */ client_id: string; + /** Your partner [client secret](https://docs.monite.com/get-started/credentials#get-credentials) obtained from the "API Credentials" section of Monite Partner Portal. Note that the sandbox and production environment use different client secrets. */ client_secret: string; + /** ID of the entity user to generate the access token for. Used only if `grant_type` is `entity_user`. */ entity_user_id?: string; + /** + * The type of the access token to generate: + * + * * `client_credentials` - partner-level access token, + * * `entity_user` - entity user token. + */ grant_type: Monite.GrantType; } diff --git a/src/api/resources/accessTokens/client/requests/RevokeTokenPayload.ts b/src/api/resources/accessTokens/client/requests/RevokeTokenPayload.ts index 4517fc1..48e60e9 100644 --- a/src/api/resources/accessTokens/client/requests/RevokeTokenPayload.ts +++ b/src/api/resources/accessTokens/client/requests/RevokeTokenPayload.ts @@ -11,7 +11,10 @@ * } */ export interface RevokeTokenPayload { + /** Your partner [client ID](https://docs.monite.com/get-started/credentials#get-credentials) obtained from the "API Credentials" section of Monite Partner Portal. Note that the sandbox and production environment use different client IDs. */ client_id: string; + /** Your partner [client secret](https://docs.monite.com/get-started/credentials#get-credentials) obtained from the "API Credentials" section of Monite Partner Portal. Note that the sandbox and production environment use different client secrets. */ client_secret: string; + /** The token to revoke. */ token: string; } diff --git a/src/api/resources/accessTokens/client/requests/index.ts b/src/api/resources/accessTokens/client/requests/index.ts index bcdd0bc..737ab6f 100644 --- a/src/api/resources/accessTokens/client/requests/index.ts +++ b/src/api/resources/accessTokens/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type RevokeTokenPayload } from "./RevokeTokenPayload"; -export { type ObtainTokenPayload } from "./ObtainTokenPayload"; +export { type RevokeTokenPayload } from "./RevokeTokenPayload.js"; +export { type ObtainTokenPayload } from "./ObtainTokenPayload.js"; diff --git a/src/api/resources/accessTokens/index.ts b/src/api/resources/accessTokens/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accessTokens/index.ts +++ b/src/api/resources/accessTokens/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/client/Client.ts b/src/api/resources/accounting/client/Client.ts index 6a9cd6c..b7709c4 100644 --- a/src/api/resources/accounting/client/Client.ts +++ b/src/api/resources/accounting/client/Client.ts @@ -2,14 +2,14 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import { Payables } from "../resources/payables/client/Client"; -import { Receivables } from "../resources/receivables/client/Client"; -import { Connections } from "../resources/connections/client/Client"; -import { SyncedRecords } from "../resources/syncedRecords/client/Client"; -import { TaxRates } from "../resources/taxRates/client/Client"; -import { LedgerAccounts } from "../resources/ledgerAccounts/client/Client"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import { Payables } from "../resources/payables/client/Client.js"; +import { Receivables } from "../resources/receivables/client/Client.js"; +import { Connections } from "../resources/connections/client/Client.js"; +import { SyncedRecords } from "../resources/syncedRecords/client/Client.js"; +import { TaxRates } from "../resources/taxRates/client/Client.js"; +import { LedgerAccounts } from "../resources/ledgerAccounts/client/Client.js"; export declare namespace Accounting { export interface Options { @@ -21,11 +21,14 @@ export declare namespace Accounting { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } } export class Accounting { + protected readonly _options: Accounting.Options; protected _payables: Payables | undefined; protected _receivables: Receivables | undefined; protected _connections: Connections | undefined; @@ -33,7 +36,9 @@ export class Accounting { protected _taxRates: TaxRates | undefined; protected _ledgerAccounts: LedgerAccounts | undefined; - constructor(protected readonly _options: Accounting.Options) {} + constructor(_options: Accounting.Options) { + this._options = _options; + } public get payables(): Payables { return (this._payables ??= new Payables(this._options)); diff --git a/src/api/resources/accounting/index.ts b/src/api/resources/accounting/index.ts index 33a87f1..9eb1192 100644 --- a/src/api/resources/accounting/index.ts +++ b/src/api/resources/accounting/index.ts @@ -1,2 +1,2 @@ -export * from "./client"; -export * from "./resources"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/accounting/resources/connections/client/Client.ts b/src/api/resources/accounting/resources/connections/client/Client.ts index cc99b6a..d2b80e2 100644 --- a/src/api/resources/accounting/resources/connections/client/Client.ts +++ b/src/api/resources/accounting/resources/connections/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Connections { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Connections { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,21 +34,28 @@ export declare namespace Connections { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Connections { - constructor(protected readonly _options: Connections.Options) {} + protected readonly _options: Connections.Options; + + constructor(_options: Connections.Options) { + this._options = _options; + } /** * Get all connections * * @param {Connections.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.connections.get() @@ -58,31 +67,25 @@ export class Connections { private async __get( requestOptions?: Connections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting_connections", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -93,10 +96,12 @@ export class Connections { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -128,8 +133,9 @@ export class Connections { * * @param {Connections.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.connections.create() @@ -143,31 +149,25 @@ export class Connections { private async __create( requestOptions?: Connections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting_connections", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -178,10 +178,12 @@ export class Connections { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -214,8 +216,9 @@ export class Connections { * @param {string} connectionId * @param {Connections.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.connections.getById("connection_id") @@ -231,31 +234,25 @@ export class Connections { connectionId: string, requestOptions?: Connections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_connections/${encodeURIComponent(connectionId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -266,10 +263,12 @@ export class Connections { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -304,8 +303,9 @@ export class Connections { * @param {string} connectionId * @param {Connections.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.connections.disconnectById("connection_id") @@ -321,31 +321,25 @@ export class Connections { connectionId: string, requestOptions?: Connections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_connections/${encodeURIComponent(connectionId)}/disconnect`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -356,10 +350,12 @@ export class Connections { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -392,8 +388,9 @@ export class Connections { * @param {string} connectionId * @param {Connections.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.connections.syncById("connection_id") @@ -409,31 +406,25 @@ export class Connections { connectionId: string, requestOptions?: Connections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_connections/${encodeURIComponent(connectionId)}/sync`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -444,10 +435,12 @@ export class Connections { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/connections/index.ts b/src/api/resources/accounting/resources/connections/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/connections/index.ts +++ b/src/api/resources/accounting/resources/connections/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/resources/index.ts b/src/api/resources/accounting/resources/index.ts index 5afd189..1bacbda 100644 --- a/src/api/resources/accounting/resources/index.ts +++ b/src/api/resources/accounting/resources/index.ts @@ -1,11 +1,11 @@ -export * as payables from "./payables"; -export * as receivables from "./receivables"; -export * as connections from "./connections"; -export * as syncedRecords from "./syncedRecords"; -export * as taxRates from "./taxRates"; -export * as ledgerAccounts from "./ledgerAccounts"; -export * from "./payables/client/requests"; -export * from "./receivables/client/requests"; -export * from "./syncedRecords/client/requests"; -export * from "./taxRates/client/requests"; -export * from "./ledgerAccounts/client/requests"; +export * as payables from "./payables/index.js"; +export * as receivables from "./receivables/index.js"; +export * as connections from "./connections/index.js"; +export * as syncedRecords from "./syncedRecords/index.js"; +export * as taxRates from "./taxRates/index.js"; +export * as ledgerAccounts from "./ledgerAccounts/index.js"; +export * from "./payables/client/requests/index.js"; +export * from "./receivables/client/requests/index.js"; +export * from "./syncedRecords/client/requests/index.js"; +export * from "./taxRates/client/requests/index.js"; +export * from "./ledgerAccounts/client/requests/index.js"; diff --git a/src/api/resources/accounting/resources/ledgerAccounts/client/Client.ts b/src/api/resources/accounting/resources/ledgerAccounts/client/Client.ts index e870b26..d356833 100644 --- a/src/api/resources/accounting/resources/ledgerAccounts/client/Client.ts +++ b/src/api/resources/accounting/resources/ledgerAccounts/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace LedgerAccounts { export interface Options { @@ -18,6 +18,8 @@ export declare namespace LedgerAccounts { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace LedgerAccounts { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class LedgerAccounts { - constructor(protected readonly _options: LedgerAccounts.Options) {} + protected readonly _options: LedgerAccounts.Options; + + constructor(_options: LedgerAccounts.Options) { + this._options = _options; + } /** * Get all ledger accounts @@ -46,8 +54,9 @@ export class LedgerAccounts { * @param {Monite.accounting.LedgerAccountsGetRequest} request * @param {LedgerAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.ledgerAccounts.get() @@ -81,32 +90,25 @@ export class LedgerAccounts { _queryParams["sort"] = sort; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "ledger_accounts", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -117,10 +119,12 @@ export class LedgerAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -153,8 +157,9 @@ export class LedgerAccounts { * @param {string} ledgerAccountId * @param {LedgerAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.ledgerAccounts.getById("ledger_account_id") @@ -170,31 +175,25 @@ export class LedgerAccounts { ledgerAccountId: string, requestOptions?: LedgerAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `ledger_accounts/${encodeURIComponent(ledgerAccountId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -205,10 +204,12 @@ export class LedgerAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/ledgerAccounts/client/index.ts b/src/api/resources/accounting/resources/ledgerAccounts/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accounting/resources/ledgerAccounts/client/index.ts +++ b/src/api/resources/accounting/resources/ledgerAccounts/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accounting/resources/ledgerAccounts/client/requests/LedgerAccountsGetRequest.ts b/src/api/resources/accounting/resources/ledgerAccounts/client/requests/LedgerAccountsGetRequest.ts index bfb948f..3dd8377 100644 --- a/src/api/resources/accounting/resources/ledgerAccounts/client/requests/LedgerAccountsGetRequest.ts +++ b/src/api/resources/accounting/resources/ledgerAccounts/client/requests/LedgerAccountsGetRequest.ts @@ -2,29 +2,27 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example * {} */ export interface LedgerAccountsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. + * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. + * + * When using pagination with a non-default `limit`, you must provide the `limit` value alongside `pagination_token` in all subsequent pagination requests. Unlike other query parameters, `limit` is not inferred from `pagination_token`. */ limit?: number; /** - * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters except `limit` are ignored and inferred from the initial query. * * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.LedgerAccountCursorFields; } diff --git a/src/api/resources/accounting/resources/ledgerAccounts/client/requests/index.ts b/src/api/resources/accounting/resources/ledgerAccounts/client/requests/index.ts index f70a0ef..a691c74 100644 --- a/src/api/resources/accounting/resources/ledgerAccounts/client/requests/index.ts +++ b/src/api/resources/accounting/resources/ledgerAccounts/client/requests/index.ts @@ -1 +1 @@ -export { type LedgerAccountsGetRequest } from "./LedgerAccountsGetRequest"; +export { type LedgerAccountsGetRequest } from "./LedgerAccountsGetRequest.js"; diff --git a/src/api/resources/accounting/resources/ledgerAccounts/index.ts b/src/api/resources/accounting/resources/ledgerAccounts/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/ledgerAccounts/index.ts +++ b/src/api/resources/accounting/resources/ledgerAccounts/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/resources/payables/client/Client.ts b/src/api/resources/accounting/resources/payables/client/Client.ts index e37a53f..f3a94a8 100644 --- a/src/api/resources/accounting/resources/payables/client/Client.ts +++ b/src/api/resources/accounting/resources/payables/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Payables { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Payables { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Payables { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Payables { - constructor(protected readonly _options: Payables.Options) {} + protected readonly _options: Payables.Options; + + constructor(_options: Payables.Options) { + this._options = _options; + } /** * Returns a list of accounts payable invoices (bills) that exist in the entity's accounting system. This requires that an accounting connection has been previously established. Refer to the [Accounting integration guide](https://docs.monite.com/accounting/integration/index) for details. @@ -50,8 +58,9 @@ export class Payables { * @param {Monite.accounting.PayablesGetRequest} request * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.payables.get() @@ -77,32 +86,25 @@ export class Payables { _queryParams["offset"] = offset.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting/payables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -113,10 +115,12 @@ export class Payables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -149,8 +153,9 @@ export class Payables { * @param {string} payableId - An internal ID of the payable invoice (bill) in the accounting system. You can get these IDs from `GET /accounting/payables`. * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.payables.getById("payable_id") @@ -166,31 +171,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting/payables/${encodeURIComponent(payableId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -201,10 +200,12 @@ export class Payables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/payables/client/index.ts b/src/api/resources/accounting/resources/payables/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accounting/resources/payables/client/index.ts +++ b/src/api/resources/accounting/resources/payables/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accounting/resources/payables/client/requests/PayablesGetRequest.ts b/src/api/resources/accounting/resources/payables/client/requests/PayablesGetRequest.ts index 9434b0e..63973a9 100644 --- a/src/api/resources/accounting/resources/payables/client/requests/PayablesGetRequest.ts +++ b/src/api/resources/accounting/resources/payables/client/requests/PayablesGetRequest.ts @@ -7,12 +7,8 @@ * {} */ export interface PayablesGetRequest { - /** - * Number of results per page. - */ + /** Number of results per page. */ limit?: number; - /** - * Number of results to skip before selecting items to return. - */ + /** Number of results to skip before selecting items to return. */ offset?: number; } diff --git a/src/api/resources/accounting/resources/payables/client/requests/index.ts b/src/api/resources/accounting/resources/payables/client/requests/index.ts index ac4bf74..5f4b0a6 100644 --- a/src/api/resources/accounting/resources/payables/client/requests/index.ts +++ b/src/api/resources/accounting/resources/payables/client/requests/index.ts @@ -1 +1 @@ -export { type PayablesGetRequest } from "./PayablesGetRequest"; +export { type PayablesGetRequest } from "./PayablesGetRequest.js"; diff --git a/src/api/resources/accounting/resources/payables/index.ts b/src/api/resources/accounting/resources/payables/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/payables/index.ts +++ b/src/api/resources/accounting/resources/payables/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/resources/receivables/client/Client.ts b/src/api/resources/accounting/resources/receivables/client/Client.ts index e5657c7..d24c2d1 100644 --- a/src/api/resources/accounting/resources/receivables/client/Client.ts +++ b/src/api/resources/accounting/resources/receivables/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Receivables { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Receivables { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Receivables { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Receivables { - constructor(protected readonly _options: Receivables.Options) {} + protected readonly _options: Receivables.Options; + + constructor(_options: Receivables.Options) { + this._options = _options; + } /** * Returns a list of invoices that exist in the entity's accounting system. This requires that an accounting connection has been previously established. Refer to the [Accounting integration guide](https://docs.monite.com/accounting/integration/index) for details. @@ -50,8 +58,9 @@ export class Receivables { * @param {Monite.accounting.ReceivablesGetRequest} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.receivables.get() @@ -77,32 +86,25 @@ export class Receivables { _queryParams["offset"] = offset.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting/receivables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -113,10 +115,12 @@ export class Receivables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -149,8 +153,9 @@ export class Receivables { * @param {string} invoiceId - An internal ID of the invoice in the accounting system. You can get these IDs from `GET /accounting/receivables`. * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.receivables.getById("invoice_id") @@ -166,31 +171,25 @@ export class Receivables { invoiceId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting/receivables/${encodeURIComponent(invoiceId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -201,10 +200,12 @@ export class Receivables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/receivables/client/index.ts b/src/api/resources/accounting/resources/receivables/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accounting/resources/receivables/client/index.ts +++ b/src/api/resources/accounting/resources/receivables/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accounting/resources/receivables/client/requests/ReceivablesGetRequest.ts b/src/api/resources/accounting/resources/receivables/client/requests/ReceivablesGetRequest.ts index 8d1bbfa..612c8b7 100644 --- a/src/api/resources/accounting/resources/receivables/client/requests/ReceivablesGetRequest.ts +++ b/src/api/resources/accounting/resources/receivables/client/requests/ReceivablesGetRequest.ts @@ -7,12 +7,8 @@ * {} */ export interface ReceivablesGetRequest { - /** - * Number of results per page. - */ + /** Number of results per page. */ limit?: number; - /** - * Number of results to skip before selecting items to return. - */ + /** Number of results to skip before selecting items to return. */ offset?: number; } diff --git a/src/api/resources/accounting/resources/receivables/client/requests/index.ts b/src/api/resources/accounting/resources/receivables/client/requests/index.ts index 3a6d011..7dedeb3 100644 --- a/src/api/resources/accounting/resources/receivables/client/requests/index.ts +++ b/src/api/resources/accounting/resources/receivables/client/requests/index.ts @@ -1 +1 @@ -export { type ReceivablesGetRequest } from "./ReceivablesGetRequest"; +export { type ReceivablesGetRequest } from "./ReceivablesGetRequest.js"; diff --git a/src/api/resources/accounting/resources/receivables/index.ts b/src/api/resources/accounting/resources/receivables/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/receivables/index.ts +++ b/src/api/resources/accounting/resources/receivables/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/resources/syncedRecords/client/Client.ts b/src/api/resources/accounting/resources/syncedRecords/client/Client.ts index 9b746b4..fd2509f 100644 --- a/src/api/resources/accounting/resources/syncedRecords/client/Client.ts +++ b/src/api/resources/accounting/resources/syncedRecords/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace SyncedRecords { export interface Options { @@ -18,6 +18,8 @@ export declare namespace SyncedRecords { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace SyncedRecords { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class SyncedRecords { - constructor(protected readonly _options: SyncedRecords.Options) {} + protected readonly _options: SyncedRecords.Options; + + constructor(_options: SyncedRecords.Options) { + this._options = _options; + } /** * Get synchronized records @@ -46,8 +54,9 @@ export class SyncedRecords { * @param {Monite.accounting.SyncedRecordsGetRequest} request * @param {SyncedRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.syncedRecords.get({ @@ -144,32 +153,25 @@ export class SyncedRecords { _queryParams["updated_at__lte"] = updatedAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting_synced_records", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -180,10 +182,12 @@ export class SyncedRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -216,8 +220,9 @@ export class SyncedRecords { * @param {string} syncedRecordId * @param {SyncedRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.syncedRecords.getById("synced_record_id") @@ -233,31 +238,25 @@ export class SyncedRecords { syncedRecordId: string, requestOptions?: SyncedRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_synced_records/${encodeURIComponent(syncedRecordId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -268,10 +267,12 @@ export class SyncedRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -306,8 +307,9 @@ export class SyncedRecords { * @param {string} syncedRecordId * @param {SyncedRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.syncedRecords.pushById("synced_record_id") @@ -323,31 +325,25 @@ export class SyncedRecords { syncedRecordId: string, requestOptions?: SyncedRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_synced_records/${encodeURIComponent(syncedRecordId)}/push`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -358,10 +354,12 @@ export class SyncedRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/syncedRecords/client/index.ts b/src/api/resources/accounting/resources/syncedRecords/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accounting/resources/syncedRecords/client/index.ts +++ b/src/api/resources/accounting/resources/syncedRecords/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accounting/resources/syncedRecords/client/requests/SyncedRecordsGetRequest.ts b/src/api/resources/accounting/resources/syncedRecords/client/requests/SyncedRecordsGetRequest.ts index 3990d8c..0eb3ca7 100644 --- a/src/api/resources/accounting/resources/syncedRecords/client/requests/SyncedRecordsGetRequest.ts +++ b/src/api/resources/accounting/resources/syncedRecords/client/requests/SyncedRecordsGetRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example @@ -12,23 +12,21 @@ import * as Monite from "../../../../../../index"; */ export interface SyncedRecordsGetRequest { object_type: Monite.ObjectMatchTypes; - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. + * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. + * + * When using pagination with a non-default `limit`, you must provide the `limit` value alongside `pagination_token` in all subsequent pagination requests. Unlike other query parameters, `limit` is not inferred from `pagination_token`. */ limit?: number; /** - * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters except `limit` are ignored and inferred from the initial query. * * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.SyncRecordCursorFields; object_id?: string; object_id__in?: string | string[]; diff --git a/src/api/resources/accounting/resources/syncedRecords/client/requests/index.ts b/src/api/resources/accounting/resources/syncedRecords/client/requests/index.ts index 8bd3725..04e671a 100644 --- a/src/api/resources/accounting/resources/syncedRecords/client/requests/index.ts +++ b/src/api/resources/accounting/resources/syncedRecords/client/requests/index.ts @@ -1 +1 @@ -export { type SyncedRecordsGetRequest } from "./SyncedRecordsGetRequest"; +export { type SyncedRecordsGetRequest } from "./SyncedRecordsGetRequest.js"; diff --git a/src/api/resources/accounting/resources/syncedRecords/index.ts b/src/api/resources/accounting/resources/syncedRecords/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/syncedRecords/index.ts +++ b/src/api/resources/accounting/resources/syncedRecords/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/accounting/resources/taxRates/client/Client.ts b/src/api/resources/accounting/resources/taxRates/client/Client.ts index 23afaeb..2a918a7 100644 --- a/src/api/resources/accounting/resources/taxRates/client/Client.ts +++ b/src/api/resources/accounting/resources/taxRates/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace TaxRates { export interface Options { @@ -18,6 +18,8 @@ export declare namespace TaxRates { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace TaxRates { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class TaxRates { - constructor(protected readonly _options: TaxRates.Options) {} + protected readonly _options: TaxRates.Options; + + constructor(_options: TaxRates.Options) { + this._options = _options; + } /** * Get all tax rate accounts @@ -46,8 +54,9 @@ export class TaxRates { * @param {Monite.accounting.TaxRatesGetRequest} request * @param {TaxRates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.taxRates.get() @@ -81,32 +90,25 @@ export class TaxRates { _queryParams["sort"] = sort; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "accounting_tax_rates", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -117,10 +119,12 @@ export class TaxRates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -153,8 +157,9 @@ export class TaxRates { * @param {string} taxRateId * @param {TaxRates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.accounting.taxRates.getById("tax_rate_id") @@ -170,31 +175,25 @@ export class TaxRates { taxRateId: string, requestOptions?: TaxRates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `accounting_tax_rates/${encodeURIComponent(taxRateId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -205,10 +204,12 @@ export class TaxRates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/accounting/resources/taxRates/client/index.ts b/src/api/resources/accounting/resources/taxRates/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/accounting/resources/taxRates/client/index.ts +++ b/src/api/resources/accounting/resources/taxRates/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/accounting/resources/taxRates/client/requests/TaxRatesGetRequest.ts b/src/api/resources/accounting/resources/taxRates/client/requests/TaxRatesGetRequest.ts index 321f13f..a82e17e 100644 --- a/src/api/resources/accounting/resources/taxRates/client/requests/TaxRatesGetRequest.ts +++ b/src/api/resources/accounting/resources/taxRates/client/requests/TaxRatesGetRequest.ts @@ -2,29 +2,27 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example * {} */ export interface TaxRatesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. + * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. + * + * When using pagination with a non-default `limit`, you must provide the `limit` value alongside `pagination_token` in all subsequent pagination requests. Unlike other query parameters, `limit` is not inferred from `pagination_token`. */ limit?: number; /** - * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters except `limit` are ignored and inferred from the initial query. * * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.TaxRateAccountCursorFields; } diff --git a/src/api/resources/accounting/resources/taxRates/client/requests/index.ts b/src/api/resources/accounting/resources/taxRates/client/requests/index.ts index 4f12a9a..15252ec 100644 --- a/src/api/resources/accounting/resources/taxRates/client/requests/index.ts +++ b/src/api/resources/accounting/resources/taxRates/client/requests/index.ts @@ -1 +1 @@ -export { type TaxRatesGetRequest } from "./TaxRatesGetRequest"; +export { type TaxRatesGetRequest } from "./TaxRatesGetRequest.js"; diff --git a/src/api/resources/accounting/resources/taxRates/index.ts b/src/api/resources/accounting/resources/taxRates/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/accounting/resources/taxRates/index.ts +++ b/src/api/resources/accounting/resources/taxRates/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/analytics/client/Client.ts b/src/api/resources/analytics/client/Client.ts index 96156fd..f74c9d4 100644 --- a/src/api/resources/analytics/client/Client.ts +++ b/src/api/resources/analytics/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Analytics { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Analytics { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Analytics { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Analytics { - constructor(protected readonly _options: Analytics.Options) {} + protected readonly _options: Analytics.Options; + + constructor(_options: Analytics.Options) { + this._options = _options; + } /** * Retrieve aggregated statistics for payables with different breakdowns. @@ -49,7 +57,7 @@ export class Analytics { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.analytics.getAnalyticsCreditNotes({ @@ -262,32 +270,25 @@ export class Analytics { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "analytics/credit_notes", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -304,8 +305,8 @@ export class Analytics { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -341,7 +342,7 @@ export class Analytics { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.analytics.getAnalyticsPayables({ @@ -411,6 +412,7 @@ export class Analytics { project_id__in: projectIdIn, tag_ids: tagIds, tag_ids__not_in: tagIdsNotIn, + has_tags: hasTags, origin, has_file: hasFile, } = request; @@ -629,6 +631,10 @@ export class Analytics { } } + if (hasTags != null) { + _queryParams["has_tags"] = hasTags.toString(); + } + if (origin != null) { _queryParams["origin"] = origin; } @@ -637,32 +643,25 @@ export class Analytics { _queryParams["has_file"] = hasFile.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "analytics/payables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -679,8 +678,8 @@ export class Analytics { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -717,7 +716,7 @@ export class Analytics { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.analytics.getAnalyticsReceivables({ @@ -774,6 +773,11 @@ export class Analytics { total_amount__lt: totalAmountLt, total_amount__gte: totalAmountGte, total_amount__lte: totalAmountLte, + discounted_subtotal: discountedSubtotal, + discounted_subtotal__gt: discountedSubtotalGt, + discounted_subtotal__lt: discountedSubtotalLt, + discounted_subtotal__gte: discountedSubtotalGte, + discounted_subtotal__lte: discountedSubtotalLte, status, entity_user_id: entityUserId, based_on: basedOn, @@ -958,6 +962,26 @@ export class Analytics { _queryParams["total_amount__lte"] = totalAmountLte.toString(); } + if (discountedSubtotal != null) { + _queryParams["discounted_subtotal"] = discountedSubtotal.toString(); + } + + if (discountedSubtotalGt != null) { + _queryParams["discounted_subtotal__gt"] = discountedSubtotalGt.toString(); + } + + if (discountedSubtotalLt != null) { + _queryParams["discounted_subtotal__lt"] = discountedSubtotalLt.toString(); + } + + if (discountedSubtotalGte != null) { + _queryParams["discounted_subtotal__gte"] = discountedSubtotalGte.toString(); + } + + if (discountedSubtotalLte != null) { + _queryParams["discounted_subtotal__lte"] = discountedSubtotalLte.toString(); + } + if (status != null) { _queryParams["status"] = status; } @@ -990,32 +1014,25 @@ export class Analytics { _queryParams["project_id"] = projectId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "analytics/receivables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1034,8 +1051,8 @@ export class Analytics { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/analytics/client/index.ts b/src/api/resources/analytics/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/analytics/client/index.ts +++ b/src/api/resources/analytics/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/analytics/client/requests/GetAnalyticsCreditNotesRequest.ts b/src/api/resources/analytics/client/requests/GetAnalyticsCreditNotesRequest.ts index 0e8b59e..1545af0 100644 --- a/src/api/resources/analytics/client/requests/GetAnalyticsCreditNotesRequest.ts +++ b/src/api/resources/analytics/client/requests/GetAnalyticsCreditNotesRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -16,9 +16,7 @@ export interface GetAnalyticsCreditNotesRequest { metric: Monite.CreditNoteMetricEnum; aggregation_function: Monite.AggregationFunctionEnum; date_dimension_breakdown?: Monite.DateDimensionBreakdownEnum; - /** - * The number of items (0 .. 400) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 400) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/analytics/client/requests/GetAnalyticsPayablesRequest.ts b/src/api/resources/analytics/client/requests/GetAnalyticsPayablesRequest.ts index 51434e1..7283665 100644 --- a/src/api/resources/analytics/client/requests/GetAnalyticsPayablesRequest.ts +++ b/src/api/resources/analytics/client/requests/GetAnalyticsPayablesRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -16,25 +16,15 @@ export interface GetAnalyticsPayablesRequest { metric: Monite.PayableMetricEnum; aggregation_function: Monite.AggregationFunctionEnum; date_dimension_breakdown?: Monite.DateDimensionBreakdownEnum; - /** - * The number of items (0 .. 400) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 400) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; - /** - * Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. - */ + /** Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. */ created_at__gt?: string; - /** - * Return only payables created in Monite before the specified date and time. - */ + /** Return only payables created in Monite before the specified date and time. */ created_at__lt?: string; - /** - * Return only payables created in Monite on or after the specified date and time. - */ + /** Return only payables created in Monite on or after the specified date and time. */ created_at__gte?: string; - /** - * Return only payables created in Monite before or on the specified date and time. - */ + /** Return only payables created in Monite before or on the specified date and time. */ created_at__lte?: string; /** * Return only payables that have the specified [status](https://docs.monite.com/accounts-payable/payables/index). @@ -54,49 +44,27 @@ export interface GetAnalyticsPayablesRequest { * To specify multiple IDs, repeat this parameter for each value: `id__in=&id__in=` */ id__in?: string | string[]; - /** - * Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. - */ + /** Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. */ total_amount?: number; - /** - * Return only payables whose total amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose total amount (in minor units) exceeds the specified value. */ total_amount__gt?: number; - /** - * Return only payables whose total amount (in minor units) is less than the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than the specified value. */ total_amount__lt?: number; - /** - * Return only payables whose total amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is greater than or equal to the specified value. */ total_amount__gte?: number; - /** - * Return only payables whose total amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than or equal to the specified value. */ total_amount__lte?: number; - /** - * Return only payables with the specified amount. - */ + /** Return only payables with the specified amount. */ amount?: number; - /** - * Return only payables whose amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose amount (in minor units) exceeds the specified value. */ amount__gt?: number; - /** - * Return only payables whose amount (in minor units) is less than the specified value. - */ + /** Return only payables whose amount (in minor units) is less than the specified value. */ amount__lt?: number; - /** - * Return only payables whose amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is greater than or equal to the specified value. */ amount__gte?: number; - /** - * Return only payables whose amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is less than or equal to the specified value. */ amount__lte?: number; - /** - * Return only payables that use the specified currency. - */ + /** Return only payables that use the specified currency. */ currency?: Monite.CurrencyEnum; /** * Return only payables received from counterparts with the specified name (exact match, case-sensitive). @@ -104,57 +72,31 @@ export interface GetAnalyticsPayablesRequest { * For counterparts of `type = individual`, the full name is formatted as `first_name last_name`. */ counterpart_name?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-sensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-sensitive). */ counterpart_name__contains?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-insensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-insensitive). */ counterpart_name__icontains?: string; - /** - * Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. - */ + /** Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. */ search_text?: string; - /** - * Return payables that are due on the specified date (YYYY-MM-DD) - */ + /** Return payables that are due on the specified date (YYYY-MM-DD) */ due_date?: string; - /** - * Return payables that are due after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due after the specified date (exclusive, YYYY-MM-DD). */ due_date__gt?: string; - /** - * Return payables that are due before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due before the specified date (exclusive, YYYY-MM-DD). */ due_date__lt?: string; - /** - * Return payables that are due on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are due on or after the specified date (YYYY-MM-DD). */ due_date__gte?: string; - /** - * Return payables that are due before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are due before or on the specified date (YYYY-MM-DD). */ due_date__lte?: string; - /** - * Return payables that are issued at the specified date (YYYY-MM-DD) - */ + /** Return payables that are issued at the specified date (YYYY-MM-DD) */ issued_at?: string; - /** - * Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). */ issued_at__gt?: string; - /** - * Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). */ issued_at__lt?: string; - /** - * Return payables that are issued on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued on or after the specified date (YYYY-MM-DD). */ issued_at__gte?: string; - /** - * Return payables that are issued before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued before or on the specified date (YYYY-MM-DD). */ issued_at__lte?: string; /** * Return a payable with the exact specified document number (case-sensitive). @@ -162,17 +104,11 @@ export interface GetAnalyticsPayablesRequest { * The `document_id` is the user-facing document number such as INV-00042, not to be confused with Monite resource IDs (`id`). */ document_id?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). */ document_id__contains?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). */ document_id__icontains?: string; - /** - * Return only payables created in Monite by the entity user with the specified ID. - */ + /** Return only payables created in Monite by the entity user with the specified ID. */ was_created_by_user_id?: string; /** * Return only payables received from the counterpart with the specified ID. @@ -182,21 +118,13 @@ export interface GetAnalyticsPayablesRequest { * If the specified counterpart ID does not exist and never existed, no results are returned. */ counterpart_id?: string; - /** - * Return only payables coming from the specified source. - */ + /** Return only payables coming from the specified source. */ source_of_payable_data?: Monite.SourceOfPayableDataEnum; - /** - * Return only payables with specific OCR statuses. - */ + /** Return only payables with specific OCR statuses. */ ocr_status?: Monite.OcrStatusEnum; - /** - * Search for a payable by the identifier of the line item associated with it. - */ + /** Search for a payable by the identifier of the line item associated with it. */ line_item_id?: string; - /** - * Search for a payable by the identifier of the purchase order associated with it. - */ + /** Search for a payable by the identifier of the purchase order associated with it. */ purchase_order_id?: string; /** * Return only payables assigned to the project with the specified ID. @@ -204,24 +132,16 @@ export interface GetAnalyticsPayablesRequest { * Valid but nonexistent project IDs do not raise errors but return no results. */ project_id?: string; - /** - * Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. - */ + /** Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ project_id__in?: string | string[]; - /** - * Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. - */ + /** Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. */ tag_ids?: string | string[]; - /** - * Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. - */ + /** Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. */ tag_ids__not_in?: string | string[]; - /** - * Return only payables from a given origin ['einvoice', 'upload', 'email'] - */ + /** Filter objects based on whether they have tags. If true, only objects with tags are returned. If false, only objects without tags are returned. */ + has_tags?: boolean; + /** Return only payables from a given origin ['einvoice', 'upload', 'email'] */ origin?: Monite.PayableOriginEnum; - /** - * Return only payables with or without attachments (files) - */ + /** Return only payables with or without attachments (files) */ has_file?: boolean; } diff --git a/src/api/resources/analytics/client/requests/GetAnalyticsReceivablesRequest.ts b/src/api/resources/analytics/client/requests/GetAnalyticsReceivablesRequest.ts index 2d5af3d..d64d38b 100644 --- a/src/api/resources/analytics/client/requests/GetAnalyticsReceivablesRequest.ts +++ b/src/api/resources/analytics/client/requests/GetAnalyticsReceivablesRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -16,9 +16,7 @@ export interface GetAnalyticsReceivablesRequest { metric: Monite.ReceivableMetricEnum; aggregation_function: Monite.AggregationFunctionEnum; date_dimension_breakdown?: Monite.DateDimensionBreakdownEnum; - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; /** * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. @@ -57,9 +55,7 @@ export interface GetAnalyticsReceivablesRequest { * IDs of deleted users will still produce results here if those users had associated receivables. Valid but nonexistent user IDs do not raise errors but produce no results. */ entity_user_id__in?: string | string[]; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ReceivableCursorFields; /** * Return only receivables whose [tags](https://docs.monite.com/common/tags) include at least one of the tags with the specified IDs. @@ -125,9 +121,7 @@ export interface GetAnalyticsReceivablesRequest { * `product_ids=&product_ids=` will return receivables 3 and 5. */ product_ids?: string | string[]; - /** - * Return only receivables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. - */ + /** Return only receivables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ project_id__in?: string | string[]; type?: Monite.ReceivableType; document_id?: string; @@ -150,6 +144,11 @@ export interface GetAnalyticsReceivablesRequest { total_amount__lt?: number; total_amount__gte?: number; total_amount__lte?: number; + discounted_subtotal?: number; + discounted_subtotal__gt?: number; + discounted_subtotal__lt?: number; + discounted_subtotal__gte?: number; + discounted_subtotal__lte?: number; status?: Monite.GetAnalyticsReceivablesRequestStatus; entity_user_id?: string; based_on?: string; diff --git a/src/api/resources/analytics/client/requests/index.ts b/src/api/resources/analytics/client/requests/index.ts index ec6e37a..dd2a956 100644 --- a/src/api/resources/analytics/client/requests/index.ts +++ b/src/api/resources/analytics/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type GetAnalyticsCreditNotesRequest } from "./GetAnalyticsCreditNotesRequest"; -export { type GetAnalyticsPayablesRequest } from "./GetAnalyticsPayablesRequest"; -export { type GetAnalyticsReceivablesRequest } from "./GetAnalyticsReceivablesRequest"; +export { type GetAnalyticsCreditNotesRequest } from "./GetAnalyticsCreditNotesRequest.js"; +export { type GetAnalyticsPayablesRequest } from "./GetAnalyticsPayablesRequest.js"; +export { type GetAnalyticsReceivablesRequest } from "./GetAnalyticsReceivablesRequest.js"; diff --git a/src/api/resources/analytics/index.ts b/src/api/resources/analytics/index.ts index c9240f8..f095e14 100644 --- a/src/api/resources/analytics/index.ts +++ b/src/api/resources/analytics/index.ts @@ -1,2 +1,2 @@ -export * from "./types"; -export * from "./client"; +export * from "./types/index.js"; +export * from "./client/index.js"; diff --git a/src/api/resources/analytics/types/index.ts b/src/api/resources/analytics/types/index.ts index dd5cd2b..2337336 100644 --- a/src/api/resources/analytics/types/index.ts +++ b/src/api/resources/analytics/types/index.ts @@ -1,2 +1,2 @@ -export * from "./GetAnalyticsReceivablesRequestStatusInItem"; -export * from "./GetAnalyticsReceivablesRequestStatus"; +export * from "./GetAnalyticsReceivablesRequestStatusInItem.js"; +export * from "./GetAnalyticsReceivablesRequestStatus.js"; diff --git a/src/api/resources/approvalPolicies/client/Client.ts b/src/api/resources/approvalPolicies/client/Client.ts index 3fb52c7..56cd9dd 100644 --- a/src/api/resources/approvalPolicies/client/Client.ts +++ b/src/api/resources/approvalPolicies/client/Client.ts @@ -2,12 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; -import { Processes } from "../resources/processes/client/Client"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; +import { Processes } from "../resources/processes/client/Client.js"; export declare namespace ApprovalPolicies { export interface Options { @@ -19,6 +19,8 @@ export declare namespace ApprovalPolicies { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -33,15 +35,20 @@ export declare namespace ApprovalPolicies { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class ApprovalPolicies { + protected readonly _options: ApprovalPolicies.Options; protected _processes: Processes | undefined; - constructor(protected readonly _options: ApprovalPolicies.Options) {} + constructor(_options: ApprovalPolicies.Options) { + this._options = _options; + } public get processes(): Processes { return (this._processes ??= new Processes(this._options)); @@ -56,7 +63,7 @@ export class ApprovalPolicies { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.get() @@ -183,32 +190,25 @@ export class ApprovalPolicies { _queryParams["updated_at__lte"] = updatedAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "approval_policies", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -225,8 +225,8 @@ export class ApprovalPolicies { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -263,7 +263,7 @@ export class ApprovalPolicies { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.create({ @@ -282,30 +282,26 @@ export class ApprovalPolicies { request: Monite.ApprovalPolicyCreate, requestOptions?: ApprovalPolicies.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "approval_policies", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -326,8 +322,8 @@ export class ApprovalPolicies { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -364,7 +360,7 @@ export class ApprovalPolicies { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.getById("approval_policy_id") @@ -380,31 +376,25 @@ export class ApprovalPolicies { approvalPolicyId: string, requestOptions?: ApprovalPolicies.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -423,8 +413,8 @@ export class ApprovalPolicies { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -463,7 +453,7 @@ export class ApprovalPolicies { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.deleteById("approval_policy_id") @@ -479,31 +469,25 @@ export class ApprovalPolicies { approvalPolicyId: string, requestOptions?: ApprovalPolicies.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -522,8 +506,8 @@ export class ApprovalPolicies { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -564,7 +548,7 @@ export class ApprovalPolicies { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.updateById("approval_policy_id") @@ -582,30 +566,26 @@ export class ApprovalPolicies { request: Monite.ApprovalPolicyUpdate = {}, requestOptions?: ApprovalPolicies.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -628,8 +608,8 @@ export class ApprovalPolicies { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/approvalPolicies/client/index.ts b/src/api/resources/approvalPolicies/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/approvalPolicies/client/index.ts +++ b/src/api/resources/approvalPolicies/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/approvalPolicies/client/requests/ApprovalPoliciesGetRequest.ts b/src/api/resources/approvalPolicies/client/requests/ApprovalPoliciesGetRequest.ts index 8055362..2eba7e6 100644 --- a/src/api/resources/approvalPolicies/client/requests/ApprovalPoliciesGetRequest.ts +++ b/src/api/resources/approvalPolicies/client/requests/ApprovalPoliciesGetRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -10,13 +10,9 @@ import * as Monite from "../../../../index"; */ export interface ApprovalPoliciesGetRequest { process_id?: string; - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -24,9 +20,7 @@ export interface ApprovalPoliciesGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ApprovalPolicyCursorFields; id__in?: string | string[]; status?: Monite.ApprovalPoliciesGetRequestStatus; diff --git a/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyCreate.ts b/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyCreate.ts index 568c3d5..b79d601 100644 --- a/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyCreate.ts +++ b/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyCreate.ts @@ -2,8 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; - /** * @example * { @@ -18,10 +16,25 @@ export interface ApprovalPolicyCreate { ends_at?: string; /** The name of the approval policy. */ name: string; + /** The priority controls which approval policy takes precedence when a payable matches multiple approval policies. A higher value mean higher priority. */ + priority?: number; /** A list of JSON objects that represents the approval policy script. The script contains the logic that determines whether an action should be sent to approval. This field is required, and it should contain at least one script object. */ - script: Monite.ApprovalPolicyCreateScriptItem[]; + script: ApprovalPolicyCreate.Script.Item[]; /** The date and time (in the ISO 8601 format) when the approval policy becomes active. Only payables submitted for approval during the policy's active period will trigger this policy. If omitted or `null`, the policy is effective immediately. The value will be converted to UTC. */ starts_at?: string; /** A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. */ - trigger?: Monite.ApprovalPolicyCreateTrigger; + trigger?: ApprovalPolicyCreate.Trigger; +} + +export namespace ApprovalPolicyCreate { + export type Script = Script.Item[]; + + export namespace Script { + export type Item = boolean | number | string | unknown[] | Record; + } + + /** + * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. + */ + export type Trigger = boolean | number | string | unknown[] | Record; } diff --git a/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyUpdate.ts b/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyUpdate.ts index 6a6b168..aef3f11 100644 --- a/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyUpdate.ts +++ b/src/api/resources/approvalPolicies/client/requests/ApprovalPolicyUpdate.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -15,12 +15,27 @@ export interface ApprovalPolicyUpdate { ends_at?: string; /** The name of the approval policy. */ name?: string; + /** The priority controls which approval policy takes precedence when a payable matches multiple approval policies. A higher value mean higher priority. */ + priority?: number; /** A list of JSON objects that represents the approval policy script. The script contains the logic that determines whether an action should be sent to approval. This field is required, and it should contain at least one script object. */ - script?: Monite.ApprovalPolicyUpdateScriptItem[]; + script?: ApprovalPolicyUpdate.Script.Item[]; /** The date and time (in the ISO 8601 format) when the approval policy becomes active. Only payables submitted for approval during the policy's active period will trigger this policy. If omitted or `null`, the policy is effective immediately. The value will be converted to UTC. */ starts_at?: string; /** A string that represents the current status of the approval policy. */ status?: Monite.ApprovalPolicyStatus; /** A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. */ - trigger?: Monite.ApprovalPolicyUpdateTrigger; + trigger?: ApprovalPolicyUpdate.Trigger; +} + +export namespace ApprovalPolicyUpdate { + export type Script = Script.Item[]; + + export namespace Script { + export type Item = boolean | number | string | unknown[] | Record; + } + + /** + * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. + */ + export type Trigger = boolean | number | string | unknown[] | Record; } diff --git a/src/api/resources/approvalPolicies/client/requests/index.ts b/src/api/resources/approvalPolicies/client/requests/index.ts index ea52561..9cd3379 100644 --- a/src/api/resources/approvalPolicies/client/requests/index.ts +++ b/src/api/resources/approvalPolicies/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type ApprovalPoliciesGetRequest } from "./ApprovalPoliciesGetRequest"; -export { type ApprovalPolicyCreate } from "./ApprovalPolicyCreate"; -export { type ApprovalPolicyUpdate } from "./ApprovalPolicyUpdate"; +export { type ApprovalPoliciesGetRequest } from "./ApprovalPoliciesGetRequest.js"; +export { type ApprovalPolicyCreate } from "./ApprovalPolicyCreate.js"; +export { type ApprovalPolicyUpdate } from "./ApprovalPolicyUpdate.js"; diff --git a/src/api/resources/approvalPolicies/index.ts b/src/api/resources/approvalPolicies/index.ts index 848e75a..31ac50a 100644 --- a/src/api/resources/approvalPolicies/index.ts +++ b/src/api/resources/approvalPolicies/index.ts @@ -1,3 +1,3 @@ -export * from "./types"; -export * from "./client"; -export * from "./resources"; +export * from "./types/index.js"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/approvalPolicies/resources/index.ts b/src/api/resources/approvalPolicies/resources/index.ts index 148fe85..0d56be9 100644 --- a/src/api/resources/approvalPolicies/resources/index.ts +++ b/src/api/resources/approvalPolicies/resources/index.ts @@ -1 +1 @@ -export * as processes from "./processes"; +export * as processes from "./processes/index.js"; diff --git a/src/api/resources/approvalPolicies/resources/processes/client/Client.ts b/src/api/resources/approvalPolicies/resources/processes/client/Client.ts index 65d1c21..f37f6c2 100644 --- a/src/api/resources/approvalPolicies/resources/processes/client/Client.ts +++ b/src/api/resources/approvalPolicies/resources/processes/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Processes { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Processes { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Processes { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Processes { - constructor(protected readonly _options: Processes.Options) {} + protected readonly _options: Processes.Options; + + constructor(_options: Processes.Options) { + this._options = _options; + } /** * Retrieve a list of all approval policy processes. @@ -50,7 +58,7 @@ export class Processes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.processes.get("approval_policy_id") @@ -66,31 +74,25 @@ export class Processes { approvalPolicyId: string, requestOptions?: Processes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}/processes`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -109,8 +111,8 @@ export class Processes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -150,7 +152,7 @@ export class Processes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.processes.getById("approval_policy_id", "process_id") @@ -168,31 +170,25 @@ export class Processes { processId: string, requestOptions?: Processes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}/processes/${encodeURIComponent(processId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -211,8 +207,8 @@ export class Processes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -252,7 +248,7 @@ export class Processes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.processes.cancelById("approval_policy_id", "process_id") @@ -270,31 +266,25 @@ export class Processes { processId: string, requestOptions?: Processes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}/processes/${encodeURIComponent(processId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -313,8 +303,8 @@ export class Processes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -354,7 +344,7 @@ export class Processes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalPolicies.processes.getSteps("approval_policy_id", "process_id") @@ -372,31 +362,25 @@ export class Processes { processId: string, requestOptions?: Processes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_policies/${encodeURIComponent(approvalPolicyId)}/processes/${encodeURIComponent(processId)}/steps`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -418,8 +402,8 @@ export class Processes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/approvalPolicies/resources/processes/index.ts b/src/api/resources/approvalPolicies/resources/processes/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/approvalPolicies/resources/processes/index.ts +++ b/src/api/resources/approvalPolicies/resources/processes/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateScriptItem.ts b/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateScriptItem.ts deleted file mode 100644 index 7317ce5..0000000 --- a/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateScriptItem.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type ApprovalPolicyCreateScriptItem = boolean | number | string | unknown[] | Record; diff --git a/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateTrigger.ts b/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateTrigger.ts deleted file mode 100644 index 29dda8f..0000000 --- a/src/api/resources/approvalPolicies/types/ApprovalPolicyCreateTrigger.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. - */ -export type ApprovalPolicyCreateTrigger = boolean | number | string | unknown[] | Record; diff --git a/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateScriptItem.ts b/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateScriptItem.ts deleted file mode 100644 index ca820cb..0000000 --- a/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateScriptItem.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type ApprovalPolicyUpdateScriptItem = boolean | number | string | unknown[] | Record; diff --git a/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateTrigger.ts b/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateTrigger.ts deleted file mode 100644 index 8296072..0000000 --- a/src/api/resources/approvalPolicies/types/ApprovalPolicyUpdateTrigger.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. - */ -export type ApprovalPolicyUpdateTrigger = boolean | number | string | unknown[] | Record; diff --git a/src/api/resources/approvalPolicies/types/index.ts b/src/api/resources/approvalPolicies/types/index.ts index fd8bc1d..c7a87da 100644 --- a/src/api/resources/approvalPolicies/types/index.ts +++ b/src/api/resources/approvalPolicies/types/index.ts @@ -1,6 +1,2 @@ -export * from "./ApprovalPoliciesGetRequestStatus"; -export * from "./ApprovalPoliciesGetRequestStatusInItem"; -export * from "./ApprovalPolicyCreateScriptItem"; -export * from "./ApprovalPolicyCreateTrigger"; -export * from "./ApprovalPolicyUpdateScriptItem"; -export * from "./ApprovalPolicyUpdateTrigger"; +export * from "./ApprovalPoliciesGetRequestStatus.js"; +export * from "./ApprovalPoliciesGetRequestStatusInItem.js"; diff --git a/src/api/resources/approvalRequests/client/Client.ts b/src/api/resources/approvalRequests/client/Client.ts index 6b6634d..b2e2086 100644 --- a/src/api/resources/approvalRequests/client/Client.ts +++ b/src/api/resources/approvalRequests/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace ApprovalRequests { export interface Options { @@ -18,6 +18,8 @@ export declare namespace ApprovalRequests { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace ApprovalRequests { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class ApprovalRequests { - constructor(protected readonly _options: ApprovalRequests.Options) {} + protected readonly _options: ApprovalRequests.Options; + + constructor(_options: ApprovalRequests.Options) { + this._options = _options; + } /** * @param {Monite.ApprovalRequestsGetRequest} request @@ -49,7 +57,7 @@ export class ApprovalRequests { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.get() @@ -185,32 +193,25 @@ export class ApprovalRequests { _queryParams["created_by"] = createdBy; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "approval_requests", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -231,8 +232,8 @@ export class ApprovalRequests { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -269,7 +270,7 @@ export class ApprovalRequests { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.create({ @@ -290,30 +291,26 @@ export class ApprovalRequests { request: Monite.ApprovalRequestCreateRequest, requestOptions?: ApprovalRequests.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "approval_requests", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -341,8 +338,8 @@ export class ApprovalRequests { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -379,7 +376,7 @@ export class ApprovalRequests { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.getById("approval_request_id") @@ -395,31 +392,25 @@ export class ApprovalRequests { approvalRequestId: string, requestOptions?: ApprovalRequests.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_requests/${encodeURIComponent(approvalRequestId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -445,8 +436,8 @@ export class ApprovalRequests { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -485,7 +476,7 @@ export class ApprovalRequests { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.approveById("approval_request_id") @@ -501,31 +492,25 @@ export class ApprovalRequests { approvalRequestId: string, requestOptions?: ApprovalRequests.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_requests/${encodeURIComponent(approvalRequestId)}/approve`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -551,8 +536,8 @@ export class ApprovalRequests { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -591,7 +576,7 @@ export class ApprovalRequests { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.cancelById("approval_request_id") @@ -607,31 +592,25 @@ export class ApprovalRequests { approvalRequestId: string, requestOptions?: ApprovalRequests.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_requests/${encodeURIComponent(approvalRequestId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -657,8 +636,8 @@ export class ApprovalRequests { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -697,7 +676,7 @@ export class ApprovalRequests { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.approvalRequests.rejectById("approval_request_id") @@ -713,31 +692,25 @@ export class ApprovalRequests { approvalRequestId: string, requestOptions?: ApprovalRequests.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `approval_requests/${encodeURIComponent(approvalRequestId)}/reject`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -763,8 +736,8 @@ export class ApprovalRequests { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/approvalRequests/client/index.ts b/src/api/resources/approvalRequests/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/approvalRequests/client/index.ts +++ b/src/api/resources/approvalRequests/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/approvalRequests/client/requests/ApprovalRequestsGetRequest.ts b/src/api/resources/approvalRequests/client/requests/ApprovalRequestsGetRequest.ts index bdedacf..ee017f5 100644 --- a/src/api/resources/approvalRequests/client/requests/ApprovalRequestsGetRequest.ts +++ b/src/api/resources/approvalRequests/client/requests/ApprovalRequestsGetRequest.ts @@ -2,28 +2,24 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ApprovalRequestsGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ApprovalRequestCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/approvalRequests/client/requests/index.ts b/src/api/resources/approvalRequests/client/requests/index.ts index 884f342..8669052 100644 --- a/src/api/resources/approvalRequests/client/requests/index.ts +++ b/src/api/resources/approvalRequests/client/requests/index.ts @@ -1 +1 @@ -export { type ApprovalRequestsGetRequest } from "./ApprovalRequestsGetRequest"; +export { type ApprovalRequestsGetRequest } from "./ApprovalRequestsGetRequest.js"; diff --git a/src/api/resources/approvalRequests/index.ts b/src/api/resources/approvalRequests/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/approvalRequests/index.ts +++ b/src/api/resources/approvalRequests/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/comments/client/Client.ts b/src/api/resources/comments/client/Client.ts index ebf5afe..c59e02c 100644 --- a/src/api/resources/comments/client/Client.ts +++ b/src/api/resources/comments/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Comments { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Comments { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Comments { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Comments { - constructor(protected readonly _options: Comments.Options) {} + protected readonly _options: Comments.Options; + + constructor(_options: Comments.Options) { + this._options = _options; + } /** * Get comments @@ -47,10 +55,11 @@ export class Comments { * @param {Comments.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.comments.get({ @@ -116,32 +125,25 @@ export class Comments { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "comments", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -154,14 +156,16 @@ export class Comments { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -195,11 +199,12 @@ export class Comments { * @param {Comments.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.comments.create({ @@ -219,30 +224,26 @@ export class Comments { request: Monite.CommentCreateRequest, requestOptions?: Comments.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "comments", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -257,6 +258,8 @@ export class Comments { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -265,8 +268,8 @@ export class Comments { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -300,11 +303,12 @@ export class Comments { * @param {Comments.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.comments.getById("comment_id") @@ -320,31 +324,25 @@ export class Comments { commentId: string, requestOptions?: Comments.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `comments/${encodeURIComponent(commentId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -357,6 +355,8 @@ export class Comments { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -365,8 +365,8 @@ export class Comments { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -400,11 +400,12 @@ export class Comments { * @param {Comments.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.comments.deleteById("comment_id") @@ -417,31 +418,25 @@ export class Comments { commentId: string, requestOptions?: Comments.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `comments/${encodeURIComponent(commentId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -454,6 +449,8 @@ export class Comments { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -462,8 +459,8 @@ export class Comments { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -498,11 +495,12 @@ export class Comments { * @param {Comments.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.comments.updateById("comment_id") @@ -520,30 +518,26 @@ export class Comments { request: Monite.CommentUpdateRequest = {}, requestOptions?: Comments.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `comments/${encodeURIComponent(commentId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -558,6 +552,8 @@ export class Comments { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -566,8 +562,8 @@ export class Comments { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/comments/client/index.ts b/src/api/resources/comments/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/comments/client/index.ts +++ b/src/api/resources/comments/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/comments/client/requests/CommentsGetRequest.ts b/src/api/resources/comments/client/requests/CommentsGetRequest.ts index e2e4987..beca9c9 100644 --- a/src/api/resources/comments/client/requests/CommentsGetRequest.ts +++ b/src/api/resources/comments/client/requests/CommentsGetRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -14,21 +14,17 @@ import * as Monite from "../../../../index"; export interface CommentsGetRequest { object_type: Monite.ObjectTypeAvailableComment; object_id: string; - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CommentCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/comments/client/requests/index.ts b/src/api/resources/comments/client/requests/index.ts index abd2be4..c775b9e 100644 --- a/src/api/resources/comments/client/requests/index.ts +++ b/src/api/resources/comments/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type CommentsGetRequest } from "./CommentsGetRequest"; -export { type CommentCreateRequest } from "./CommentCreateRequest"; -export { type CommentUpdateRequest } from "./CommentUpdateRequest"; +export { type CommentsGetRequest } from "./CommentsGetRequest.js"; +export { type CommentCreateRequest } from "./CommentCreateRequest.js"; +export { type CommentUpdateRequest } from "./CommentUpdateRequest.js"; diff --git a/src/api/resources/comments/index.ts b/src/api/resources/comments/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/comments/index.ts +++ b/src/api/resources/comments/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/counterpartEInvoicingCredentials/client/Client.ts b/src/api/resources/counterpartEInvoicingCredentials/client/Client.ts index b7e104a..d30b986 100644 --- a/src/api/resources/counterpartEInvoicingCredentials/client/Client.ts +++ b/src/api/resources/counterpartEInvoicingCredentials/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace CounterpartEInvoicingCredentials { export interface Options { @@ -18,6 +18,8 @@ export declare namespace CounterpartEInvoicingCredentials { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,21 +34,28 @@ export declare namespace CounterpartEInvoicingCredentials { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class CounterpartEInvoicingCredentials { - constructor(protected readonly _options: CounterpartEInvoicingCredentials.Options) {} + protected readonly _options: CounterpartEInvoicingCredentials.Options; + + constructor(_options: CounterpartEInvoicingCredentials.Options) { + this._options = _options; + } /** * @param {string} counterpartId * @param {CounterpartEInvoicingCredentials.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterpartEInvoicingCredentials.getCounterpartsIdEinvoicingCredentials("counterpart_id") @@ -64,31 +73,25 @@ export class CounterpartEInvoicingCredentials { counterpartId: string, requestOptions?: CounterpartEInvoicingCredentials.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/einvoicing_credentials`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -102,12 +105,14 @@ export class CounterpartEInvoicingCredentials { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -141,13 +146,20 @@ export class CounterpartEInvoicingCredentials { * @param {Monite.CreateCounterpartEinvoicingCredentialPayload} request * @param {CounterpartEInvoicingCredentials.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterpartEInvoicingCredentials.postCounterpartsIdEinvoicingCredentials("counterpart_id", { - * counterpart_vat_id_id: "counterpart_vat_id_id" + * counterpart_vat_id_id: "14c84a34-282b-4fd8-8af6-86b5b5f2c212" + * }) + * + * @example + * await client.counterpartEInvoicingCredentials.postCounterpartsIdEinvoicingCredentials("counterpart_id", { + * network_identifier: "DE087095777", + * network_schema: "DE:VAT" * }) */ public postCounterpartsIdEinvoicingCredentials( @@ -165,30 +177,26 @@ export class CounterpartEInvoicingCredentials { request: Monite.CreateCounterpartEinvoicingCredentialPayload, requestOptions?: CounterpartEInvoicingCredentials.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/einvoicing_credentials`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -204,12 +212,14 @@ export class CounterpartEInvoicingCredentials { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -243,9 +253,10 @@ export class CounterpartEInvoicingCredentials { * @param {string} counterpartId * @param {CounterpartEInvoicingCredentials.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterpartEInvoicingCredentials.getCounterpartsIdEinvoicingCredentialsId("credential_id", "counterpart_id") @@ -265,31 +276,25 @@ export class CounterpartEInvoicingCredentials { counterpartId: string, requestOptions?: CounterpartEInvoicingCredentials.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/einvoicing_credentials/${encodeURIComponent(credentialId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -303,12 +308,14 @@ export class CounterpartEInvoicingCredentials { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -342,9 +349,10 @@ export class CounterpartEInvoicingCredentials { * @param {string} counterpartId * @param {CounterpartEInvoicingCredentials.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterpartEInvoicingCredentials.deleteCounterpartsIdEinvoicingCredentialsId("credential_id", "counterpart_id") @@ -364,31 +372,25 @@ export class CounterpartEInvoicingCredentials { counterpartId: string, requestOptions?: CounterpartEInvoicingCredentials.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/einvoicing_credentials/${encodeURIComponent(credentialId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -399,12 +401,14 @@ export class CounterpartEInvoicingCredentials { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -439,9 +443,10 @@ export class CounterpartEInvoicingCredentials { * @param {Monite.UpdateCounterpartEinvoicingCredentialSchema} request * @param {CounterpartEInvoicingCredentials.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterpartEInvoicingCredentials.patchCounterpartsIdEinvoicingCredentialsId("credential_id", "counterpart_id") @@ -463,30 +468,26 @@ export class CounterpartEInvoicingCredentials { request: Monite.UpdateCounterpartEinvoicingCredentialSchema = {}, requestOptions?: CounterpartEInvoicingCredentials.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/einvoicing_credentials/${encodeURIComponent(credentialId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -502,12 +503,14 @@ export class CounterpartEInvoicingCredentials { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterpartEInvoicingCredentials/client/index.ts b/src/api/resources/counterpartEInvoicingCredentials/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterpartEInvoicingCredentials/client/index.ts +++ b/src/api/resources/counterpartEInvoicingCredentials/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterpartEInvoicingCredentials/client/requests/UpdateCounterpartEinvoicingCredentialSchema.ts b/src/api/resources/counterpartEInvoicingCredentials/client/requests/UpdateCounterpartEinvoicingCredentialSchema.ts index a56001b..ce16f3a 100644 --- a/src/api/resources/counterpartEInvoicingCredentials/client/requests/UpdateCounterpartEinvoicingCredentialSchema.ts +++ b/src/api/resources/counterpartEInvoicingCredentials/client/requests/UpdateCounterpartEinvoicingCredentialSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/counterpartEInvoicingCredentials/client/requests/index.ts b/src/api/resources/counterpartEInvoicingCredentials/client/requests/index.ts index 1aab20e..c3fd85b 100644 --- a/src/api/resources/counterpartEInvoicingCredentials/client/requests/index.ts +++ b/src/api/resources/counterpartEInvoicingCredentials/client/requests/index.ts @@ -1 +1 @@ -export { type UpdateCounterpartEinvoicingCredentialSchema } from "./UpdateCounterpartEinvoicingCredentialSchema"; +export { type UpdateCounterpartEinvoicingCredentialSchema } from "./UpdateCounterpartEinvoicingCredentialSchema.js"; diff --git a/src/api/resources/counterpartEInvoicingCredentials/index.ts b/src/api/resources/counterpartEInvoicingCredentials/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/counterpartEInvoicingCredentials/index.ts +++ b/src/api/resources/counterpartEInvoicingCredentials/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/counterparts/client/Client.ts b/src/api/resources/counterparts/client/Client.ts index c573c69..2d8ab2e 100644 --- a/src/api/resources/counterparts/client/Client.ts +++ b/src/api/resources/counterparts/client/Client.ts @@ -2,15 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; -import { Addresses } from "../resources/addresses/client/Client"; -import { BankAccounts } from "../resources/bankAccounts/client/Client"; -import { Contacts } from "../resources/contacts/client/Client"; -import { VatIds } from "../resources/vatIds/client/Client"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; +import { Addresses } from "../resources/addresses/client/Client.js"; +import { BankAccounts } from "../resources/bankAccounts/client/Client.js"; +import { Contacts } from "../resources/contacts/client/Client.js"; +import { VatIds } from "../resources/vatIds/client/Client.js"; export declare namespace Counterparts { export interface Options { @@ -22,6 +22,8 @@ export declare namespace Counterparts { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -36,18 +38,23 @@ export declare namespace Counterparts { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Counterparts { + protected readonly _options: Counterparts.Options; protected _addresses: Addresses | undefined; protected _bankAccounts: BankAccounts | undefined; protected _contacts: Contacts | undefined; protected _vatIds: VatIds | undefined; - constructor(protected readonly _options: Counterparts.Options) {} + constructor(_options: Counterparts.Options) { + this._options = _options; + } public get addresses(): Addresses { return (this._addresses ??= new Addresses(this._options)); @@ -69,9 +76,10 @@ export class Counterparts { * @param {Monite.CounterpartsGetRequest} request * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.get({ @@ -255,32 +263,25 @@ export class Counterparts { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "counterparts", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -291,12 +292,14 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -327,8 +330,9 @@ export class Counterparts { * @param {Monite.CounterpartCreatePayload} request * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.create({ @@ -357,30 +361,26 @@ export class Counterparts { request: Monite.CounterpartCreatePayload, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "counterparts", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -393,10 +393,12 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -427,9 +429,10 @@ export class Counterparts { * @param {string} counterpartId * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.getById("counterpart_id") @@ -445,31 +448,25 @@ export class Counterparts { counterpartId: string, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -480,12 +477,14 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -518,9 +517,10 @@ export class Counterparts { * @param {string} counterpartId * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.deleteById("counterpart_id") @@ -536,31 +536,25 @@ export class Counterparts { counterpartId: string, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -571,12 +565,14 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -610,9 +606,10 @@ export class Counterparts { * @param {Monite.CounterpartUpdatePayload} request * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.updateById("counterpart_id", { @@ -632,30 +629,26 @@ export class Counterparts { request: Monite.CounterpartUpdatePayload, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -668,12 +661,14 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -706,8 +701,9 @@ export class Counterparts { * @param {string} counterpartId * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.getPartnerMetadataById("counterpart_id") @@ -723,31 +719,25 @@ export class Counterparts { counterpartId: string, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/partner_metadata`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -758,10 +748,12 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -795,8 +787,9 @@ export class Counterparts { * @param {Monite.PartnerMetadata} request * @param {Counterparts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.updatePartnerMetadataById("counterpart_id", { @@ -820,30 +813,26 @@ export class Counterparts { request: Monite.PartnerMetadata, requestOptions?: Counterparts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/partner_metadata`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -856,10 +845,12 @@ export class Counterparts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterparts/client/index.ts b/src/api/resources/counterparts/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterparts/client/index.ts +++ b/src/api/resources/counterparts/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterparts/client/requests/CounterpartsGetRequest.ts b/src/api/resources/counterparts/client/requests/CounterpartsGetRequest.ts index f71fcb0..dc1f47d 100644 --- a/src/api/resources/counterparts/client/requests/CounterpartsGetRequest.ts +++ b/src/api/resources/counterparts/client/requests/CounterpartsGetRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -11,37 +11,21 @@ import * as Monite from "../../../../index"; * } */ export interface CounterpartsGetRequest { - /** - * The IBAN of the counterpart's bank account. - */ + /** The IBAN of the counterpart's bank account. */ iban?: string; - /** - * The bank's sort code. - */ + /** The bank's sort code. */ sort_code?: string; - /** - * The bank account number. Required for US bank accounts to accept ACH payments. US account numbers contain 9 to 12 digits. UK account numbers typically contain 8 digits. - */ + /** The bank account number. Required for US bank accounts to accept ACH payments. US account numbers contain 9 to 12 digits. UK account numbers typically contain 8 digits. */ account_number?: string; - /** - * The tax ID of the counterpart. - */ + /** The tax ID of the counterpart. */ tax_id?: string; - /** - * The VAT ID of the counterpart. - */ + /** The VAT ID of the counterpart. */ vat_id?: string; - /** - * A list of counterpart IDs to search through. - */ + /** A list of counterpart IDs to search through. */ id__in?: string | string[]; - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -49,9 +33,7 @@ export interface CounterpartsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CounterpartCursorFields; type?: Monite.CounterpartType; counterpart_name?: string; diff --git a/src/api/resources/counterparts/client/requests/index.ts b/src/api/resources/counterparts/client/requests/index.ts index 1243c04..2aa7061 100644 --- a/src/api/resources/counterparts/client/requests/index.ts +++ b/src/api/resources/counterparts/client/requests/index.ts @@ -1 +1 @@ -export { type CounterpartsGetRequest } from "./CounterpartsGetRequest"; +export { type CounterpartsGetRequest } from "./CounterpartsGetRequest.js"; diff --git a/src/api/resources/counterparts/index.ts b/src/api/resources/counterparts/index.ts index 33a87f1..9eb1192 100644 --- a/src/api/resources/counterparts/index.ts +++ b/src/api/resources/counterparts/index.ts @@ -1,2 +1,2 @@ -export * from "./client"; -export * from "./resources"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/counterparts/resources/addresses/client/Client.ts b/src/api/resources/counterparts/resources/addresses/client/Client.ts index 5a81c60..e1b3c2f 100644 --- a/src/api/resources/counterparts/resources/addresses/client/Client.ts +++ b/src/api/resources/counterparts/resources/addresses/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Addresses { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Addresses { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,21 +34,28 @@ export declare namespace Addresses { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Addresses { - constructor(protected readonly _options: Addresses.Options) {} + protected readonly _options: Addresses.Options; + + constructor(_options: Addresses.Options) { + this._options = _options; + } /** * @param {string} counterpartId * @param {Addresses.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.addresses.get("counterpart_id") @@ -62,31 +71,25 @@ export class Addresses { counterpartId: string, requestOptions?: Addresses.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/addresses`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -100,12 +103,14 @@ export class Addresses { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -139,9 +144,10 @@ export class Addresses { * @param {Monite.CounterpartAddress} request * @param {Addresses.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.addresses.create("counterpart_id", { @@ -164,30 +170,26 @@ export class Addresses { request: Monite.CounterpartAddress, requestOptions?: Addresses.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/addresses`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -203,12 +205,14 @@ export class Addresses { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -242,9 +246,10 @@ export class Addresses { * @param {string} counterpartId * @param {Addresses.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.addresses.getById("address_id", "counterpart_id") @@ -262,31 +267,25 @@ export class Addresses { counterpartId: string, requestOptions?: Addresses.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/addresses/${encodeURIComponent(addressId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -300,12 +299,14 @@ export class Addresses { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -339,9 +340,10 @@ export class Addresses { * @param {string} counterpartId * @param {Addresses.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.addresses.deleteById("address_id", "counterpart_id") @@ -359,31 +361,25 @@ export class Addresses { counterpartId: string, requestOptions?: Addresses.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/addresses/${encodeURIComponent(addressId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -394,12 +390,14 @@ export class Addresses { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -434,9 +432,10 @@ export class Addresses { * @param {Monite.counterparts.CounterpartUpdateAddress} request * @param {Addresses.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.addresses.updateById("address_id", "counterpart_id") @@ -458,30 +457,26 @@ export class Addresses { request: Monite.counterparts.CounterpartUpdateAddress = {}, requestOptions?: Addresses.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/addresses/${encodeURIComponent(addressId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -497,12 +492,14 @@ export class Addresses { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterparts/resources/addresses/client/index.ts b/src/api/resources/counterparts/resources/addresses/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterparts/resources/addresses/client/index.ts +++ b/src/api/resources/counterparts/resources/addresses/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterparts/resources/addresses/client/requests/CounterpartUpdateAddress.ts b/src/api/resources/counterparts/resources/addresses/client/requests/CounterpartUpdateAddress.ts index 375e2f0..6c6bac3 100644 --- a/src/api/resources/counterparts/resources/addresses/client/requests/CounterpartUpdateAddress.ts +++ b/src/api/resources/counterparts/resources/addresses/client/requests/CounterpartUpdateAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/addresses/client/requests/index.ts b/src/api/resources/counterparts/resources/addresses/client/requests/index.ts index 99b2e21..b978143 100644 --- a/src/api/resources/counterparts/resources/addresses/client/requests/index.ts +++ b/src/api/resources/counterparts/resources/addresses/client/requests/index.ts @@ -1 +1 @@ -export { type CounterpartUpdateAddress } from "./CounterpartUpdateAddress"; +export { type CounterpartUpdateAddress } from "./CounterpartUpdateAddress.js"; diff --git a/src/api/resources/counterparts/resources/addresses/index.ts b/src/api/resources/counterparts/resources/addresses/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/counterparts/resources/addresses/index.ts +++ b/src/api/resources/counterparts/resources/addresses/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/counterparts/resources/bankAccounts/client/Client.ts b/src/api/resources/counterparts/resources/bankAccounts/client/Client.ts index fb65ea5..ee24c04 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/client/Client.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace BankAccounts { export interface Options { @@ -18,6 +18,8 @@ export declare namespace BankAccounts { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace BankAccounts { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class BankAccounts { - constructor(protected readonly _options: BankAccounts.Options) {} + protected readonly _options: BankAccounts.Options; + + constructor(_options: BankAccounts.Options) { + this._options = _options; + } /** * @param {string} counterpartId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.get("counterpart_id") @@ -61,31 +70,25 @@ export class BankAccounts { counterpartId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -99,10 +102,12 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -136,9 +141,10 @@ export class BankAccounts { * @param {Monite.counterparts.CreateCounterpartBankAccount} request * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.create("counterpart_id", { @@ -159,30 +165,26 @@ export class BankAccounts { request: Monite.counterparts.CreateCounterpartBankAccount, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -198,12 +200,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -237,9 +241,10 @@ export class BankAccounts { * @param {string} counterpartId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.getById("bank_account_id", "counterpart_id") @@ -257,31 +262,25 @@ export class BankAccounts { counterpartId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -295,12 +294,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -334,9 +335,10 @@ export class BankAccounts { * @param {string} counterpartId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.deleteById("bank_account_id", "counterpart_id") @@ -354,31 +356,25 @@ export class BankAccounts { counterpartId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -389,12 +385,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -429,9 +427,10 @@ export class BankAccounts { * @param {Monite.counterparts.UpdateCounterpartBankAccount} request * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.updateById("bank_account_id", "counterpart_id") @@ -453,30 +452,26 @@ export class BankAccounts { request: Monite.counterparts.UpdateCounterpartBankAccount = {}, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -492,12 +487,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -531,8 +528,9 @@ export class BankAccounts { * @param {string} counterpartId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.bankAccounts.makeDefaultById("bank_account_id", "counterpart_id") @@ -552,31 +550,25 @@ export class BankAccounts { counterpartId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/bank_accounts/${encodeURIComponent(bankAccountId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -587,10 +579,12 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterparts/resources/bankAccounts/client/index.ts b/src/api/resources/counterparts/resources/bankAccounts/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/client/index.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterparts/resources/bankAccounts/client/requests/CreateCounterpartBankAccount.ts b/src/api/resources/counterparts/resources/bankAccounts/client/requests/CreateCounterpartBankAccount.ts index fd236d5..05dd103 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/client/requests/CreateCounterpartBankAccount.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/client/requests/CreateCounterpartBankAccount.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/bankAccounts/client/requests/UpdateCounterpartBankAccount.ts b/src/api/resources/counterparts/resources/bankAccounts/client/requests/UpdateCounterpartBankAccount.ts index c5cea4e..60d7f07 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/client/requests/UpdateCounterpartBankAccount.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/client/requests/UpdateCounterpartBankAccount.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/bankAccounts/client/requests/index.ts b/src/api/resources/counterparts/resources/bankAccounts/client/requests/index.ts index a99d6fa..84e7cd6 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/client/requests/index.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type CreateCounterpartBankAccount } from "./CreateCounterpartBankAccount"; -export { type UpdateCounterpartBankAccount } from "./UpdateCounterpartBankAccount"; +export { type CreateCounterpartBankAccount } from "./CreateCounterpartBankAccount.js"; +export { type UpdateCounterpartBankAccount } from "./UpdateCounterpartBankAccount.js"; diff --git a/src/api/resources/counterparts/resources/bankAccounts/index.ts b/src/api/resources/counterparts/resources/bankAccounts/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/counterparts/resources/bankAccounts/index.ts +++ b/src/api/resources/counterparts/resources/bankAccounts/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/counterparts/resources/contacts/client/Client.ts b/src/api/resources/counterparts/resources/contacts/client/Client.ts index cd34f7b..b32c96c 100644 --- a/src/api/resources/counterparts/resources/contacts/client/Client.ts +++ b/src/api/resources/counterparts/resources/contacts/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Contacts { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Contacts { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace Contacts { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Contacts { - constructor(protected readonly _options: Contacts.Options) {} + protected readonly _options: Contacts.Options; + + constructor(_options: Contacts.Options) { + this._options = _options; + } /** * @param {string} counterpartId * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.get("counterpart_id") @@ -61,31 +70,25 @@ export class Contacts { counterpartId: string, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -99,10 +102,12 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -136,9 +141,10 @@ export class Contacts { * @param {Monite.counterparts.CreateCounterpartContactPayload} request * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.create("counterpart_id", { @@ -165,30 +171,26 @@ export class Contacts { request: Monite.counterparts.CreateCounterpartContactPayload, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -201,12 +203,14 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -240,9 +244,10 @@ export class Contacts { * @param {string} counterpartId * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.getById("contact_id", "counterpart_id") @@ -260,31 +265,25 @@ export class Contacts { counterpartId: string, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts/${encodeURIComponent(contactId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -295,12 +294,14 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -334,9 +335,10 @@ export class Contacts { * @param {string} counterpartId * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.deleteById("contact_id", "counterpart_id") @@ -354,31 +356,25 @@ export class Contacts { counterpartId: string, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts/${encodeURIComponent(contactId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -389,12 +385,14 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -429,9 +427,10 @@ export class Contacts { * @param {Monite.counterparts.UpdateCounterpartContactPayload} request * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.updateById("contact_id", "counterpart_id") @@ -453,30 +452,26 @@ export class Contacts { request: Monite.counterparts.UpdateCounterpartContactPayload = {}, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts/${encodeURIComponent(contactId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -489,12 +484,14 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -528,9 +525,10 @@ export class Contacts { * @param {string} counterpartId * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.contacts.makeDefaultById("contact_id", "counterpart_id") @@ -548,31 +546,25 @@ export class Contacts { counterpartId: string, requestOptions?: Contacts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/contacts/${encodeURIComponent(contactId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -583,12 +575,14 @@ export class Contacts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterparts/resources/contacts/client/index.ts b/src/api/resources/counterparts/resources/contacts/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterparts/resources/contacts/client/index.ts +++ b/src/api/resources/counterparts/resources/contacts/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterparts/resources/contacts/client/requests/CreateCounterpartContactPayload.ts b/src/api/resources/counterparts/resources/contacts/client/requests/CreateCounterpartContactPayload.ts index 2db3fba..0cef85e 100644 --- a/src/api/resources/counterparts/resources/contacts/client/requests/CreateCounterpartContactPayload.ts +++ b/src/api/resources/counterparts/resources/contacts/client/requests/CreateCounterpartContactPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/contacts/client/requests/UpdateCounterpartContactPayload.ts b/src/api/resources/counterparts/resources/contacts/client/requests/UpdateCounterpartContactPayload.ts index dc71dbd..5cc83dd 100644 --- a/src/api/resources/counterparts/resources/contacts/client/requests/UpdateCounterpartContactPayload.ts +++ b/src/api/resources/counterparts/resources/contacts/client/requests/UpdateCounterpartContactPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/contacts/client/requests/index.ts b/src/api/resources/counterparts/resources/contacts/client/requests/index.ts index af0868f..0ca8c11 100644 --- a/src/api/resources/counterparts/resources/contacts/client/requests/index.ts +++ b/src/api/resources/counterparts/resources/contacts/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type CreateCounterpartContactPayload } from "./CreateCounterpartContactPayload"; -export { type UpdateCounterpartContactPayload } from "./UpdateCounterpartContactPayload"; +export { type CreateCounterpartContactPayload } from "./CreateCounterpartContactPayload.js"; +export { type UpdateCounterpartContactPayload } from "./UpdateCounterpartContactPayload.js"; diff --git a/src/api/resources/counterparts/resources/contacts/index.ts b/src/api/resources/counterparts/resources/contacts/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/counterparts/resources/contacts/index.ts +++ b/src/api/resources/counterparts/resources/contacts/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/counterparts/resources/index.ts b/src/api/resources/counterparts/resources/index.ts index 0464014..14dc706 100644 --- a/src/api/resources/counterparts/resources/index.ts +++ b/src/api/resources/counterparts/resources/index.ts @@ -1,8 +1,8 @@ -export * as addresses from "./addresses"; -export * as bankAccounts from "./bankAccounts"; -export * as contacts from "./contacts"; -export * as vatIds from "./vatIds"; -export * from "./addresses/client/requests"; -export * from "./bankAccounts/client/requests"; -export * from "./contacts/client/requests"; -export * from "./vatIds/client/requests"; +export * as addresses from "./addresses/index.js"; +export * as bankAccounts from "./bankAccounts/index.js"; +export * as contacts from "./contacts/index.js"; +export * as vatIds from "./vatIds/index.js"; +export * from "./addresses/client/requests/index.js"; +export * from "./bankAccounts/client/requests/index.js"; +export * from "./contacts/client/requests/index.js"; +export * from "./vatIds/client/requests/index.js"; diff --git a/src/api/resources/counterparts/resources/vatIds/client/Client.ts b/src/api/resources/counterparts/resources/vatIds/client/Client.ts index eec20a0..54a8e33 100644 --- a/src/api/resources/counterparts/resources/vatIds/client/Client.ts +++ b/src/api/resources/counterparts/resources/vatIds/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace VatIds { export interface Options { @@ -18,6 +18,8 @@ export declare namespace VatIds { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace VatIds { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class VatIds { - constructor(protected readonly _options: VatIds.Options) {} + protected readonly _options: VatIds.Options; + + constructor(_options: VatIds.Options) { + this._options = _options; + } /** * @param {string} counterpartId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.vatIds.get("counterpart_id") @@ -61,31 +70,25 @@ export class VatIds { counterpartId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/vat_ids`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -96,10 +99,12 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -133,9 +138,10 @@ export class VatIds { * @param {Monite.counterparts.CounterpartVatId} request * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.vatIds.create("counterpart_id", { @@ -155,30 +161,26 @@ export class VatIds { request: Monite.counterparts.CounterpartVatId, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/vat_ids`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -191,12 +193,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -230,9 +234,10 @@ export class VatIds { * @param {string} counterpartId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.vatIds.getById("vat_id", "counterpart_id") @@ -250,31 +255,25 @@ export class VatIds { counterpartId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/vat_ids/${encodeURIComponent(vatId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -285,12 +284,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -324,9 +325,10 @@ export class VatIds { * @param {string} counterpartId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.vatIds.deleteById("vat_id", "counterpart_id") @@ -344,31 +346,25 @@ export class VatIds { counterpartId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/vat_ids/${encodeURIComponent(vatId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -379,12 +375,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -419,9 +417,10 @@ export class VatIds { * @param {Monite.counterparts.CounterpartUpdateVatId} request * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.counterparts.vatIds.updateById("vat_id", "counterpart_id") @@ -441,30 +440,26 @@ export class VatIds { request: Monite.counterparts.CounterpartUpdateVatId = {}, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `counterparts/${encodeURIComponent(counterpartId)}/vat_ids/${encodeURIComponent(vatId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -477,12 +472,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/counterparts/resources/vatIds/client/index.ts b/src/api/resources/counterparts/resources/vatIds/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/counterparts/resources/vatIds/client/index.ts +++ b/src/api/resources/counterparts/resources/vatIds/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartUpdateVatId.ts b/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartUpdateVatId.ts index b9d39e4..7407a4d 100644 --- a/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartUpdateVatId.ts +++ b/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartUpdateVatId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartVatId.ts b/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartVatId.ts index c0d38c5..b3e43fe 100644 --- a/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartVatId.ts +++ b/src/api/resources/counterparts/resources/vatIds/client/requests/CounterpartVatId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/counterparts/resources/vatIds/client/requests/index.ts b/src/api/resources/counterparts/resources/vatIds/client/requests/index.ts index 21c9ada..c47b459 100644 --- a/src/api/resources/counterparts/resources/vatIds/client/requests/index.ts +++ b/src/api/resources/counterparts/resources/vatIds/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type CounterpartVatId } from "./CounterpartVatId"; -export { type CounterpartUpdateVatId } from "./CounterpartUpdateVatId"; +export { type CounterpartVatId } from "./CounterpartVatId.js"; +export { type CounterpartUpdateVatId } from "./CounterpartUpdateVatId.js"; diff --git a/src/api/resources/counterparts/resources/vatIds/index.ts b/src/api/resources/counterparts/resources/vatIds/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/counterparts/resources/vatIds/index.ts +++ b/src/api/resources/counterparts/resources/vatIds/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/creditNotes/client/Client.ts b/src/api/resources/creditNotes/client/Client.ts index 24c30c4..c1e7ee6 100644 --- a/src/api/resources/creditNotes/client/Client.ts +++ b/src/api/resources/creditNotes/client/Client.ts @@ -2,13 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; import * as fs from "fs"; -import { Blob } from "buffer"; export declare namespace CreditNotes { export interface Options { @@ -20,6 +19,8 @@ export declare namespace CreditNotes { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -34,13 +35,19 @@ export declare namespace CreditNotes { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class CreditNotes { - constructor(protected readonly _options: CreditNotes.Options) {} + protected readonly _options: CreditNotes.Options; + + constructor(_options: CreditNotes.Options) { + this._options = _options; + } /** * @param {Monite.GetPayableCreditNotesRequest} request @@ -51,7 +58,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotes() @@ -262,32 +269,25 @@ export class CreditNotes { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -308,8 +308,8 @@ export class CreditNotes { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -344,7 +344,7 @@ export class CreditNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotes({ @@ -363,30 +363,26 @@ export class CreditNotes { request: Monite.CreditNoteCreateRequest, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -407,8 +403,8 @@ export class CreditNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -436,9 +432,9 @@ export class CreditNotes { } /** - * Upload an incoming credit note (payable) in PDF, PNG, JPEG, or TIFF format and scan its contents. The maximum file size is 10MB. + * Upload an incoming credit note (payable) in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB. * - * @param {File | fs.ReadStream | Blob} file + * @param {Monite.CreditNoteUploadFile} request * @param {CreditNotes.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} @@ -446,49 +442,50 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.creditNotes.postPayableCreditNotesUploadFromFile(fs.createReadStream("/path/to/your/file")) + * import { createReadStream } from "fs"; + * await client.creditNotes.postPayableCreditNotesUploadFromFile({ + * file: fs.createReadStream("/path/to/your/file") + * }) */ public postPayableCreditNotesUploadFromFile( - file: File | fs.ReadStream | Blob, + request: Monite.CreditNoteUploadFile, requestOptions?: CreditNotes.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__postPayableCreditNotesUploadFromFile(file, requestOptions)); + return core.HttpResponsePromise.fromPromise( + this.__postPayableCreditNotesUploadFromFile(request, requestOptions), + ); } private async __postPayableCreditNotesUploadFromFile( - file: File | fs.ReadStream | Blob, + request: Monite.CreditNoteUploadFile, requestOptions?: CreditNotes.RequestOptions, ): Promise> { const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes/upload_from_file", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, + headers: _headers, + queryParameters: requestOptions?.queryParams, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -512,8 +509,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -551,7 +548,7 @@ export class CreditNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotesValidations() @@ -565,31 +562,25 @@ export class CreditNotes { private async __getPayableCreditNotesValidations( requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes/validations", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -608,8 +599,8 @@ export class CreditNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -648,7 +639,7 @@ export class CreditNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.putPayableCreditNotesValidations({ @@ -666,30 +657,26 @@ export class CreditNotes { request: Monite.CreditNoteValidationsResource, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes/validations", ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -710,8 +697,8 @@ export class CreditNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -749,7 +736,7 @@ export class CreditNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesValidationsReset() @@ -763,31 +750,25 @@ export class CreditNotes { private async __postPayableCreditNotesValidationsReset( requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_credit_notes/validations/reset", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -806,8 +787,8 @@ export class CreditNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -844,7 +825,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotesId("credit_note_id") @@ -860,31 +841,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -903,8 +878,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -942,7 +917,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.deletePayableCreditNotesId("credit_note_id") @@ -958,31 +933,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1003,8 +972,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1042,7 +1011,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.patchPayableCreditNotesId("credit_note_id") @@ -1062,30 +1031,26 @@ export class CreditNotes { request: Monite.CreditNoteUpdateRequest = {}, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1106,8 +1071,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1147,7 +1112,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdApprove("credit_note_id") @@ -1165,31 +1130,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/approve`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1210,8 +1169,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1251,7 +1210,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdCancel("credit_note_id") @@ -1269,31 +1228,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1314,8 +1267,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1356,7 +1309,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdCancelOcr("credit_note_id") @@ -1374,31 +1327,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/cancel_ocr`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1421,8 +1368,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1460,7 +1407,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotesIdLineItems("credit_note_id") @@ -1703,32 +1650,25 @@ export class CreditNotes { _queryParams["source_id"] = sourceId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1750,8 +1690,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1789,7 +1729,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdLineItems("credit_note_id", {}) @@ -1809,30 +1749,26 @@ export class CreditNotes { request: Monite.CreditNoteLineItemCreateRequest, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1853,8 +1789,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1892,7 +1828,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.putPayableCreditNotesIdLineItems("credit_note_id", { @@ -1914,30 +1850,26 @@ export class CreditNotes { request: Monite.CreditNoteLineItemReplaceRequest, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1961,8 +1893,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2000,7 +1932,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotesIdLineItemsId("credit_note_id", "line_item_id") @@ -2020,31 +1952,25 @@ export class CreditNotes { lineItemId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2063,8 +1989,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2102,7 +2028,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.deletePayableCreditNotesIdLineItemsId("credit_note_id", "line_item_id") @@ -2122,31 +2048,25 @@ export class CreditNotes { lineItemId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2168,8 +2088,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2208,7 +2128,7 @@ export class CreditNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.patchPayableCreditNotesIdLineItemsId("credit_note_id", "line_item_id") @@ -2230,30 +2150,26 @@ export class CreditNotes { request: Monite.CreditNoteLineItemUpdateRequest = {}, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2274,8 +2190,8 @@ export class CreditNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2315,7 +2231,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdReject("credit_note_id") @@ -2333,31 +2249,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/reject`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2378,8 +2288,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2419,7 +2329,7 @@ export class CreditNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.postPayableCreditNotesIdSubmitForApproval("credit_note_id") @@ -2437,31 +2347,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/submit_for_approval`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2482,8 +2386,8 @@ export class CreditNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2520,7 +2424,7 @@ export class CreditNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.creditNotes.getPayableCreditNotesIdValidate("credit_note_id") @@ -2538,31 +2442,25 @@ export class CreditNotes { creditNoteId: string, requestOptions?: CreditNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_credit_notes/${encodeURIComponent(creditNoteId)}/validate`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2581,8 +2479,8 @@ export class CreditNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/creditNotes/client/index.ts b/src/api/resources/creditNotes/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/creditNotes/client/index.ts +++ b/src/api/resources/creditNotes/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/creditNotes/client/requests/CreditNoteCreateRequest.ts b/src/api/resources/creditNotes/client/requests/CreditNoteCreateRequest.ts index 45e277f..7871c6f 100644 --- a/src/api/resources/creditNotes/client/requests/CreditNoteCreateRequest.ts +++ b/src/api/resources/creditNotes/client/requests/CreditNoteCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/creditNotes/client/requests/CreditNoteLineItemReplaceRequest.ts b/src/api/resources/creditNotes/client/requests/CreditNoteLineItemReplaceRequest.ts index 106cab7..c094036 100644 --- a/src/api/resources/creditNotes/client/requests/CreditNoteLineItemReplaceRequest.ts +++ b/src/api/resources/creditNotes/client/requests/CreditNoteLineItemReplaceRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/creditNotes/client/requests/CreditNoteUpdateRequest.ts b/src/api/resources/creditNotes/client/requests/CreditNoteUpdateRequest.ts index c8c3a07..e13434d 100644 --- a/src/api/resources/creditNotes/client/requests/CreditNoteUpdateRequest.ts +++ b/src/api/resources/creditNotes/client/requests/CreditNoteUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/creditNotes/client/requests/CreditNoteUploadFile.ts b/src/api/resources/creditNotes/client/requests/CreditNoteUploadFile.ts index 84e0c30..9b78265 100644 --- a/src/api/resources/creditNotes/client/requests/CreditNoteUploadFile.ts +++ b/src/api/resources/creditNotes/client/requests/CreditNoteUploadFile.ts @@ -2,8 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + /** * @example - * {} + * { + * file: fs.createReadStream("/path/to/your/file") + * } */ -export interface CreditNoteUploadFile {} +export interface CreditNoteUploadFile { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesIdLineItemsRequest.ts b/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesIdLineItemsRequest.ts index f854201..ac77260 100644 --- a/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesIdLineItemsRequest.ts +++ b/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesIdLineItemsRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface GetPayableCreditNotesIdLineItemsRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface GetPayableCreditNotesIdLineItemsRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CreditNoteLineItemCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesRequest.ts b/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesRequest.ts index 110a242..9da465a 100644 --- a/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesRequest.ts +++ b/src/api/resources/creditNotes/client/requests/GetPayableCreditNotesRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface GetPayableCreditNotesRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface GetPayableCreditNotesRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CreditNoteCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/creditNotes/client/requests/index.ts b/src/api/resources/creditNotes/client/requests/index.ts index b5326e3..ef03428 100644 --- a/src/api/resources/creditNotes/client/requests/index.ts +++ b/src/api/resources/creditNotes/client/requests/index.ts @@ -1,7 +1,7 @@ -export { type GetPayableCreditNotesRequest } from "./GetPayableCreditNotesRequest"; -export { type CreditNoteCreateRequest } from "./CreditNoteCreateRequest"; -export { type CreditNoteUploadFile } from "./CreditNoteUploadFile"; -export { type CreditNoteUpdateRequest } from "./CreditNoteUpdateRequest"; -export { type GetPayableCreditNotesIdLineItemsRequest } from "./GetPayableCreditNotesIdLineItemsRequest"; -export { type CreditNoteLineItemReplaceRequest } from "./CreditNoteLineItemReplaceRequest"; -export { type CreditNoteLineItemUpdateRequest } from "./CreditNoteLineItemUpdateRequest"; +export { type GetPayableCreditNotesRequest } from "./GetPayableCreditNotesRequest.js"; +export { type CreditNoteCreateRequest } from "./CreditNoteCreateRequest.js"; +export { type CreditNoteUploadFile } from "./CreditNoteUploadFile.js"; +export { type CreditNoteUpdateRequest } from "./CreditNoteUpdateRequest.js"; +export { type GetPayableCreditNotesIdLineItemsRequest } from "./GetPayableCreditNotesIdLineItemsRequest.js"; +export { type CreditNoteLineItemReplaceRequest } from "./CreditNoteLineItemReplaceRequest.js"; +export { type CreditNoteLineItemUpdateRequest } from "./CreditNoteLineItemUpdateRequest.js"; diff --git a/src/api/resources/creditNotes/index.ts b/src/api/resources/creditNotes/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/creditNotes/index.ts +++ b/src/api/resources/creditNotes/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/customVatRates/client/Client.ts b/src/api/resources/customVatRates/client/Client.ts new file mode 100644 index 0000000..e1a496e --- /dev/null +++ b/src/api/resources/customVatRates/client/Client.ts @@ -0,0 +1,533 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; + +export declare namespace CustomVatRates { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token?: core.Supplier; + /** Override the x-monite-version header */ + moniteVersion: core.Supplier; + /** Override the x-monite-entity-id header */ + moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Override the x-monite-version header */ + moniteVersion?: string; + /** Override the x-monite-entity-id header */ + moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; + /** Additional headers to include in the request. */ + headers?: Record | undefined>; + } +} + +export class CustomVatRates { + protected readonly _options: CustomVatRates.Options; + + constructor(_options: CustomVatRates.Options) { + this._options = _options; + } + + /** + * @param {CustomVatRates.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.customVatRates.getCustomVatRates() + */ + public getCustomVatRates( + requestOptions?: CustomVatRates.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getCustomVatRates(requestOptions)); + } + + private async __getCustomVatRates( + requestOptions?: CustomVatRates.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "custom_vat_rates", + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.CustomVatRateResponseList, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /custom_vat_rates."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {Monite.CustomVatRateRequest} request + * @param {CustomVatRates.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.customVatRates.postCustomVatRates({ + * components: [{ + * name: "name", + * value: 1.1 + * }], + * name: "name" + * }) + */ + public postCustomVatRates( + request: Monite.CustomVatRateRequest, + requestOptions?: CustomVatRates.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postCustomVatRates(request, requestOptions)); + } + + private async __postCustomVatRates( + request: Monite.CustomVatRateRequest, + requestOptions?: CustomVatRates.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "custom_vat_rates", + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.CustomVatRateResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling POST /custom_vat_rates."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} customVatRateId + * @param {CustomVatRates.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.customVatRates.getCustomVatRatesId("custom_vat_rate_id") + */ + public getCustomVatRatesId( + customVatRateId: string, + requestOptions?: CustomVatRates.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getCustomVatRatesId(customVatRateId, requestOptions)); + } + + private async __getCustomVatRatesId( + customVatRateId: string, + requestOptions?: CustomVatRates.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `custom_vat_rates/${encodeURIComponent(customVatRateId)}`, + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.CustomVatRateResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling GET /custom_vat_rates/{custom_vat_rate_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} customVatRateId + * @param {CustomVatRates.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.customVatRates.deleteCustomVatRatesId("custom_vat_rate_id") + */ + public deleteCustomVatRatesId( + customVatRateId: string, + requestOptions?: CustomVatRates.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deleteCustomVatRatesId(customVatRateId, requestOptions)); + } + + private async __deleteCustomVatRatesId( + customVatRateId: string, + requestOptions?: CustomVatRates.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `custom_vat_rates/${encodeURIComponent(customVatRateId)}`, + ), + method: "DELETE", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling DELETE /custom_vat_rates/{custom_vat_rate_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} customVatRateId + * @param {Monite.CustomVatRateUpdateRequest} request + * @param {CustomVatRates.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.customVatRates.patchCustomVatRatesId("custom_vat_rate_id") + */ + public patchCustomVatRatesId( + customVatRateId: string, + request: Monite.CustomVatRateUpdateRequest = {}, + requestOptions?: CustomVatRates.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__patchCustomVatRatesId(customVatRateId, request, requestOptions), + ); + } + + private async __patchCustomVatRatesId( + customVatRateId: string, + request: Monite.CustomVatRateUpdateRequest = {}, + requestOptions?: CustomVatRates.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `custom_vat_rates/${encodeURIComponent(customVatRateId)}`, + ), + method: "PATCH", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.CustomVatRateResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling PATCH /custom_vat_rates/{custom_vat_rate_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } +} diff --git a/src/api/resources/customVatRates/client/index.ts b/src/api/resources/customVatRates/client/index.ts new file mode 100644 index 0000000..82648c6 --- /dev/null +++ b/src/api/resources/customVatRates/client/index.ts @@ -0,0 +1,2 @@ +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/customVatRates/client/requests/CustomVatRateRequest.ts b/src/api/resources/customVatRates/client/requests/CustomVatRateRequest.ts new file mode 100644 index 0000000..7057c6a --- /dev/null +++ b/src/api/resources/customVatRates/client/requests/CustomVatRateRequest.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * { + * components: [{ + * name: "name", + * value: 1.1 + * }], + * name: "name" + * } + */ +export interface CustomVatRateRequest { + /** Sub-taxes included in the Custom VAT. */ + components: Monite.VatRateComponent[]; + /** Display name of the Custom VAT. */ + name: string; +} diff --git a/src/api/resources/customVatRates/client/requests/CustomVatRateUpdateRequest.ts b/src/api/resources/customVatRates/client/requests/CustomVatRateUpdateRequest.ts new file mode 100644 index 0000000..b5506e3 --- /dev/null +++ b/src/api/resources/customVatRates/client/requests/CustomVatRateUpdateRequest.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface CustomVatRateUpdateRequest { + /** Sub-taxes included in the Custom VAT. */ + components?: Monite.VatRateComponent[]; + /** Display name of the Custom VAT. */ + name?: string; +} diff --git a/src/api/resources/customVatRates/client/requests/index.ts b/src/api/resources/customVatRates/client/requests/index.ts new file mode 100644 index 0000000..b504077 --- /dev/null +++ b/src/api/resources/customVatRates/client/requests/index.ts @@ -0,0 +1,2 @@ +export { type CustomVatRateRequest } from "./CustomVatRateRequest.js"; +export { type CustomVatRateUpdateRequest } from "./CustomVatRateUpdateRequest.js"; diff --git a/src/api/resources/customVatRates/index.ts b/src/api/resources/customVatRates/index.ts new file mode 100644 index 0000000..914b8c3 --- /dev/null +++ b/src/api/resources/customVatRates/index.ts @@ -0,0 +1 @@ +export * from "./client/index.js"; diff --git a/src/api/resources/dataExports/client/Client.ts b/src/api/resources/dataExports/client/Client.ts index a8df7eb..a62a1dc 100644 --- a/src/api/resources/dataExports/client/Client.ts +++ b/src/api/resources/dataExports/client/Client.ts @@ -2,12 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; -import { ExtraData } from "../resources/extraData/client/Client"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; +import { ExtraData } from "../resources/extraData/client/Client.js"; export declare namespace DataExports { export interface Options { @@ -19,6 +19,8 @@ export declare namespace DataExports { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -33,15 +35,20 @@ export declare namespace DataExports { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class DataExports { + protected readonly _options: DataExports.Options; protected _extraData: ExtraData | undefined; - constructor(protected readonly _options: DataExports.Options) {} + constructor(_options: DataExports.Options) { + this._options = _options; + } public get extraData(): ExtraData { return (this._extraData ??= new ExtraData(this._options)); @@ -56,7 +63,7 @@ export class DataExports { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.get() @@ -120,32 +127,25 @@ export class DataExports { _queryParams["created_by_entity_user_id"] = createdByEntityUserId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "data_exports", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -169,8 +169,8 @@ export class DataExports { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -209,7 +209,7 @@ export class DataExports { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.create({ @@ -233,30 +233,26 @@ export class DataExports { request: Monite.ExportPayloadSchema, requestOptions?: DataExports.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "data_exports", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -284,8 +280,8 @@ export class DataExports { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -315,8 +311,9 @@ export class DataExports { /** * @param {DataExports.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.getSupportedFormats() @@ -330,31 +327,25 @@ export class DataExports { private async __getSupportedFormats( requestOptions?: DataExports.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "data_exports/supported_formats", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -365,10 +356,12 @@ export class DataExports { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -406,7 +399,7 @@ export class DataExports { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.getById("document_export_id") @@ -422,31 +415,25 @@ export class DataExports { documentExportId: string, requestOptions?: DataExports.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `data_exports/${encodeURIComponent(documentExportId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -467,8 +454,8 @@ export class DataExports { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/dataExports/client/index.ts b/src/api/resources/dataExports/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/dataExports/client/index.ts +++ b/src/api/resources/dataExports/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/dataExports/client/requests/DataExportsGetRequest.ts b/src/api/resources/dataExports/client/requests/DataExportsGetRequest.ts index 843f4e9..87dbabb 100644 --- a/src/api/resources/dataExports/client/requests/DataExportsGetRequest.ts +++ b/src/api/resources/dataExports/client/requests/DataExportsGetRequest.ts @@ -2,28 +2,24 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface DataExportsGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.DataExportCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/dataExports/client/requests/ExportPayloadSchema.ts b/src/api/resources/dataExports/client/requests/ExportPayloadSchema.ts index c02373d..305524b 100644 --- a/src/api/resources/dataExports/client/requests/ExportPayloadSchema.ts +++ b/src/api/resources/dataExports/client/requests/ExportPayloadSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/dataExports/client/requests/index.ts b/src/api/resources/dataExports/client/requests/index.ts index c27373e..0565fcf 100644 --- a/src/api/resources/dataExports/client/requests/index.ts +++ b/src/api/resources/dataExports/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type DataExportsGetRequest } from "./DataExportsGetRequest"; -export { type ExportPayloadSchema } from "./ExportPayloadSchema"; +export { type DataExportsGetRequest } from "./DataExportsGetRequest.js"; +export { type ExportPayloadSchema } from "./ExportPayloadSchema.js"; diff --git a/src/api/resources/dataExports/index.ts b/src/api/resources/dataExports/index.ts index 33a87f1..9eb1192 100644 --- a/src/api/resources/dataExports/index.ts +++ b/src/api/resources/dataExports/index.ts @@ -1,2 +1,2 @@ -export * from "./client"; -export * from "./resources"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/dataExports/resources/extraData/client/Client.ts b/src/api/resources/dataExports/resources/extraData/client/Client.ts index 09e2018..95d0a46 100644 --- a/src/api/resources/dataExports/resources/extraData/client/Client.ts +++ b/src/api/resources/dataExports/resources/extraData/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace ExtraData { export interface Options { @@ -18,6 +18,8 @@ export declare namespace ExtraData { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace ExtraData { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class ExtraData { - constructor(protected readonly _options: ExtraData.Options) {} + protected readonly _options: ExtraData.Options; + + constructor(_options: ExtraData.Options) { + this._options = _options; + } /** * @param {Monite.dataExports.ExtraDataGetRequest} request @@ -47,7 +55,7 @@ export class ExtraData { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.extraData.get() @@ -141,32 +149,25 @@ export class ExtraData { _queryParams["field_value"] = fieldValue; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "data_exports/extra_data", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -183,8 +184,8 @@ export class ExtraData { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -219,7 +220,7 @@ export class ExtraData { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.extraData.create({ @@ -239,30 +240,26 @@ export class ExtraData { request: Monite.dataExports.ExtraDataCreateRequest, requestOptions?: ExtraData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "data_exports/extra_data", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: { ...request, object_type: "counterpart" }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -283,8 +280,8 @@ export class ExtraData { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -319,7 +316,7 @@ export class ExtraData { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.extraData.getById("extra_data_id") @@ -335,31 +332,25 @@ export class ExtraData { extraDataId: string, requestOptions?: ExtraData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `data_exports/extra_data/${encodeURIComponent(extraDataId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -378,8 +369,8 @@ export class ExtraData { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -416,7 +407,7 @@ export class ExtraData { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.extraData.deleteById("extra_data_id") @@ -432,31 +423,25 @@ export class ExtraData { extraDataId: string, requestOptions?: ExtraData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `data_exports/extra_data/${encodeURIComponent(extraDataId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -475,8 +460,8 @@ export class ExtraData { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -515,7 +500,7 @@ export class ExtraData { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.dataExports.extraData.updateById("extra_data_id") @@ -533,30 +518,26 @@ export class ExtraData { request: Monite.dataExports.ExtraDataUpdateRequest = {}, requestOptions?: ExtraData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `data_exports/extra_data/${encodeURIComponent(extraDataId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -579,8 +560,8 @@ export class ExtraData { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/dataExports/resources/extraData/client/index.ts b/src/api/resources/dataExports/resources/extraData/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/dataExports/resources/extraData/client/index.ts +++ b/src/api/resources/dataExports/resources/extraData/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataCreateRequest.ts b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataCreateRequest.ts index 7ced08e..30de792 100644 --- a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataCreateRequest.ts +++ b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataGetRequest.ts b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataGetRequest.ts index 859d50b..606b0b6 100644 --- a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataGetRequest.ts +++ b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataGetRequest.ts @@ -2,28 +2,24 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example * {} */ export interface ExtraDataGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ExportSettingCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataUpdateRequest.ts b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataUpdateRequest.ts index 8893401..7d5395f 100644 --- a/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataUpdateRequest.ts +++ b/src/api/resources/dataExports/resources/extraData/client/requests/ExtraDataUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/dataExports/resources/extraData/client/requests/index.ts b/src/api/resources/dataExports/resources/extraData/client/requests/index.ts index e0f9cfe..fa7a5d1 100644 --- a/src/api/resources/dataExports/resources/extraData/client/requests/index.ts +++ b/src/api/resources/dataExports/resources/extraData/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type ExtraDataGetRequest } from "./ExtraDataGetRequest"; -export { type ExtraDataCreateRequest } from "./ExtraDataCreateRequest"; -export { type ExtraDataUpdateRequest } from "./ExtraDataUpdateRequest"; +export { type ExtraDataGetRequest } from "./ExtraDataGetRequest.js"; +export { type ExtraDataCreateRequest } from "./ExtraDataCreateRequest.js"; +export { type ExtraDataUpdateRequest } from "./ExtraDataUpdateRequest.js"; diff --git a/src/api/resources/dataExports/resources/extraData/index.ts b/src/api/resources/dataExports/resources/extraData/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/dataExports/resources/extraData/index.ts +++ b/src/api/resources/dataExports/resources/extraData/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/dataExports/resources/index.ts b/src/api/resources/dataExports/resources/index.ts index 075edd4..7aa37e2 100644 --- a/src/api/resources/dataExports/resources/index.ts +++ b/src/api/resources/dataExports/resources/index.ts @@ -1,2 +1,2 @@ -export * as extraData from "./extraData"; -export * from "./extraData/client/requests"; +export * as extraData from "./extraData/index.js"; +export * from "./extraData/client/requests/index.js"; diff --git a/src/api/resources/deliveryNotes/client/Client.ts b/src/api/resources/deliveryNotes/client/Client.ts index f7a3ae7..1477720 100644 --- a/src/api/resources/deliveryNotes/client/Client.ts +++ b/src/api/resources/deliveryNotes/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace DeliveryNotes { export interface Options { @@ -18,6 +18,8 @@ export declare namespace DeliveryNotes { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace DeliveryNotes { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class DeliveryNotes { - constructor(protected readonly _options: DeliveryNotes.Options) {} + protected readonly _options: DeliveryNotes.Options; + + constructor(_options: DeliveryNotes.Options) { + this._options = _options; + } /** * Get all delivery notes with filtering and pagination. @@ -50,7 +58,7 @@ export class DeliveryNotes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.getDeliveryNotes() @@ -197,32 +205,25 @@ export class DeliveryNotes { _queryParams["delivery_date__lte"] = deliveryDateLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "delivery_notes", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -241,8 +242,8 @@ export class DeliveryNotes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -279,30 +280,29 @@ export class DeliveryNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.postDeliveryNotes({ - * counterpart_address_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", - * counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", - * delivery_date: "2025-01-01", - * delivery_number: "102-2025-0987", + * counterpart_address_id: "9a0282e1-bae7-49c9-a6f3-152dbe6fe6b8", + * counterpart_id: "18a45457-377e-4b7c-b9a1-7b2e7f264d46", + * delivery_date: "2025-07-01", + * delivery_number: "INV-042", * display_signature_placeholder: true, * line_items: [{ - * product_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", - * quantity: 10 - * }, { * product: { - * description: "Description of product 2", - * measure_unit: { - * description: "pieces", - * name: "pcs" - * }, - * name: "Product 2" + * name: "LG WH1000XM Monitor" * }, - * quantity: 20 - * }], - * memo: "This is a memo" + * quantity: 10 + * }, { + * product_id: "e0c21d00-6556-4536-8390-830c4d3cf4ca", + * quantity: 5 + * }] + * }) + * + * @example + * await client.deliveryNotes.postDeliveryNotes({ + * based_on: "e78de69c-c789-44ef-80bf-474b9e63b91d" * }) */ public postDeliveryNotes( @@ -316,30 +316,26 @@ export class DeliveryNotes { request: Monite.Payload, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "delivery_notes", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -364,8 +360,8 @@ export class DeliveryNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -401,7 +397,7 @@ export class DeliveryNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.getDeliveryNotesId("delivery_note_id") @@ -417,31 +413,25 @@ export class DeliveryNotes { deliveryNoteId: string, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `delivery_notes/${encodeURIComponent(deliveryNoteId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -462,8 +452,8 @@ export class DeliveryNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -501,7 +491,7 @@ export class DeliveryNotes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.deleteDeliveryNotesId("delivery_note_id") @@ -517,31 +507,25 @@ export class DeliveryNotes { deliveryNoteId: string, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `delivery_notes/${encodeURIComponent(deliveryNoteId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -562,8 +546,8 @@ export class DeliveryNotes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -603,7 +587,7 @@ export class DeliveryNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.patchDeliveryNotesId("delivery_note_id") @@ -623,30 +607,26 @@ export class DeliveryNotes { request: Monite.DeliveryNoteUpdateRequest = {}, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `delivery_notes/${encodeURIComponent(deliveryNoteId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -671,8 +651,8 @@ export class DeliveryNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -711,7 +691,7 @@ export class DeliveryNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.postDeliveryNotesIdCancel("delivery_note_id") @@ -727,31 +707,25 @@ export class DeliveryNotes { deliveryNoteId: string, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `delivery_notes/${encodeURIComponent(deliveryNoteId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -774,8 +748,8 @@ export class DeliveryNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -814,7 +788,7 @@ export class DeliveryNotes { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.deliveryNotes.postDeliveryNotesIdMarkAsDelivered("delivery_note_id") @@ -832,31 +806,25 @@ export class DeliveryNotes { deliveryNoteId: string, requestOptions?: DeliveryNotes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `delivery_notes/${encodeURIComponent(deliveryNoteId)}/mark_as_delivered`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -879,8 +847,8 @@ export class DeliveryNotes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/deliveryNotes/client/index.ts b/src/api/resources/deliveryNotes/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/deliveryNotes/client/index.ts +++ b/src/api/resources/deliveryNotes/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/deliveryNotes/client/requests/DeliveryNoteUpdateRequest.ts b/src/api/resources/deliveryNotes/client/requests/DeliveryNoteUpdateRequest.ts index 174a632..0769c3c 100644 --- a/src/api/resources/deliveryNotes/client/requests/DeliveryNoteUpdateRequest.ts +++ b/src/api/resources/deliveryNotes/client/requests/DeliveryNoteUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -21,6 +21,6 @@ export interface DeliveryNoteUpdateRequest { display_signature_placeholder?: boolean; /** List of line items in the delivery note */ line_items?: Monite.DeliveryNoteCreateLineItem[]; - /** Additional information regarding the delivery note */ + /** An optional note for the customer, displayed above the line items table in the PDF. */ memo?: string; } diff --git a/src/api/resources/deliveryNotes/client/requests/GetDeliveryNotesRequest.ts b/src/api/resources/deliveryNotes/client/requests/GetDeliveryNotesRequest.ts index 0ecac46..487f3b1 100644 --- a/src/api/resources/deliveryNotes/client/requests/GetDeliveryNotesRequest.ts +++ b/src/api/resources/deliveryNotes/client/requests/GetDeliveryNotesRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface GetDeliveryNotesRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface GetDeliveryNotesRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.DeliveryNoteCursorFields; id__in?: string | string[]; status?: Monite.DeliveryNoteStatusEnum; diff --git a/src/api/resources/deliveryNotes/client/requests/index.ts b/src/api/resources/deliveryNotes/client/requests/index.ts index 8b86a5b..a91aed2 100644 --- a/src/api/resources/deliveryNotes/client/requests/index.ts +++ b/src/api/resources/deliveryNotes/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type GetDeliveryNotesRequest } from "./GetDeliveryNotesRequest"; -export { type DeliveryNoteUpdateRequest } from "./DeliveryNoteUpdateRequest"; +export { type GetDeliveryNotesRequest } from "./GetDeliveryNotesRequest.js"; +export { type DeliveryNoteUpdateRequest } from "./DeliveryNoteUpdateRequest.js"; diff --git a/src/api/resources/deliveryNotes/index.ts b/src/api/resources/deliveryNotes/index.ts index c9240f8..f095e14 100644 --- a/src/api/resources/deliveryNotes/index.ts +++ b/src/api/resources/deliveryNotes/index.ts @@ -1,2 +1,2 @@ -export * from "./types"; -export * from "./client"; +export * from "./types/index.js"; +export * from "./client/index.js"; diff --git a/src/api/resources/deliveryNotes/types/Payload.ts b/src/api/resources/deliveryNotes/types/Payload.ts index 4e933e9..e395554 100644 --- a/src/api/resources/deliveryNotes/types/Payload.ts +++ b/src/api/resources/deliveryNotes/types/Payload.ts @@ -2,6 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../index"; +import * as Monite from "../../../index.js"; export type Payload = Monite.DeliveryNoteCreateRequest | Monite.DeliveryNoteCreateBasedOnRequest; diff --git a/src/api/resources/deliveryNotes/types/index.ts b/src/api/resources/deliveryNotes/types/index.ts index 25d8d88..f1d64d3 100644 --- a/src/api/resources/deliveryNotes/types/index.ts +++ b/src/api/resources/deliveryNotes/types/index.ts @@ -1 +1 @@ -export * from "./Payload"; +export * from "./Payload.js"; diff --git a/src/api/resources/eInvoicingConnections/client/Client.ts b/src/api/resources/eInvoicingConnections/client/Client.ts index a5198a4..96edf41 100644 --- a/src/api/resources/eInvoicingConnections/client/Client.ts +++ b/src/api/resources/eInvoicingConnections/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace EInvoicingConnections { export interface Options { @@ -18,6 +18,8 @@ export declare namespace EInvoicingConnections { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace EInvoicingConnections { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class EInvoicingConnections { - constructor(protected readonly _options: EInvoicingConnections.Options) {} + protected readonly _options: EInvoicingConnections.Options; + + constructor(_options: EInvoicingConnections.Options) { + this._options = _options; + } /** * @param {EInvoicingConnections.RequestOptions} requestOptions - Request-specific configuration. @@ -47,7 +55,7 @@ export class EInvoicingConnections { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.eInvoicingConnections.getEinvoicingConnections() @@ -61,31 +69,25 @@ export class EInvoicingConnections { private async __getEinvoicingConnections( requestOptions?: EInvoicingConnections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "einvoicing_connections", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -104,8 +106,8 @@ export class EInvoicingConnections { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -141,7 +143,7 @@ export class EInvoicingConnections { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.eInvoicingConnections.postEinvoicingConnections({ @@ -164,30 +166,26 @@ export class EInvoicingConnections { request: Monite.EinvoicingConnectionCreateRequest, requestOptions?: EInvoicingConnections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "einvoicing_connections", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -210,8 +208,8 @@ export class EInvoicingConnections { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -247,7 +245,7 @@ export class EInvoicingConnections { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.eInvoicingConnections.getEinvoicingConnectionsId("einvoicing_connection_id") @@ -265,31 +263,25 @@ export class EInvoicingConnections { einvoicingConnectionId: string, requestOptions?: EInvoicingConnections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `einvoicing_connections/${encodeURIComponent(einvoicingConnectionId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -310,8 +302,8 @@ export class EInvoicingConnections { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -349,7 +341,7 @@ export class EInvoicingConnections { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.eInvoicingConnections.deleteEinvoicingConnectionsId("einvoicing_connection_id") @@ -367,37 +359,134 @@ export class EInvoicingConnections { einvoicingConnectionId: string, requestOptions?: EInvoicingConnections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `einvoicing_connections/${encodeURIComponent(einvoicingConnectionId)}`, ), method: "DELETE", - headers: { + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling DELETE /einvoicing_connections/{einvoicing_connection_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} einvoicingConnectionId + * @param {Monite.EinvoicingConnectionUpdateRequest} request + * @param {EInvoicingConnections.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.eInvoicingConnections.patchEinvoicingConnectionsId("einvoicing_connection_id") + */ + public patchEinvoicingConnectionsId( + einvoicingConnectionId: string, + request: Monite.EinvoicingConnectionUpdateRequest = {}, + requestOptions?: EInvoicingConnections.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__patchEinvoicingConnectionsId(einvoicingConnectionId, request, requestOptions), + ); + } + + private async __patchEinvoicingConnectionsId( + einvoicingConnectionId: string, + request: Monite.EinvoicingConnectionUpdateRequest = {}, + requestOptions?: EInvoicingConnections.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `einvoicing_connections/${encodeURIComponent(einvoicingConnectionId)}`, + ), + method: "PATCH", + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", + body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: undefined, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.EinvoicingConnectionResponse, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { @@ -410,10 +499,12 @@ export class EInvoicingConnections { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -432,7 +523,7 @@ export class EInvoicingConnections { }); case "timeout": throw new errors.MoniteTimeoutError( - "Timeout exceeded when calling DELETE /einvoicing_connections/{einvoicing_connection_id}.", + "Timeout exceeded when calling PATCH /einvoicing_connections/{einvoicing_connection_id}.", ); case "unknown": throw new errors.MoniteError({ @@ -453,7 +544,7 @@ export class EInvoicingConnections { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.eInvoicingConnections.postEinvoicingConnectionsIdNetworkCredentials("einvoicing_connection_id", { @@ -476,30 +567,26 @@ export class EInvoicingConnections { request: Monite.EinvoicingNetworkCredentialsCreateRequest, requestOptions?: EInvoicingConnections.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `einvoicing_connections/${encodeURIComponent(einvoicingConnectionId)}/network_credentials`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -527,8 +614,8 @@ export class EInvoicingConnections { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/eInvoicingConnections/client/index.ts b/src/api/resources/eInvoicingConnections/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/eInvoicingConnections/client/index.ts +++ b/src/api/resources/eInvoicingConnections/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionCreateRequest.ts b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionCreateRequest.ts index 5398316..a5961d1 100644 --- a/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionCreateRequest.ts +++ b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -20,4 +20,8 @@ export interface EinvoicingConnectionCreateRequest { address: Monite.EinvoicingAddress; /** Entity VAT ID identifier for the integration */ entity_vat_id_id?: string; + /** Set to `true` if the entity needs to receive e-invoices. */ + is_receiver?: boolean; + /** Set to `true` if the entity needs to send e-invoices. Either `is_sender` or `is_receiver` or both must be `true`. */ + is_sender?: boolean; } diff --git a/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionUpdateRequest.ts b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionUpdateRequest.ts new file mode 100644 index 0000000..6430ff7 --- /dev/null +++ b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingConnectionUpdateRequest.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface EinvoicingConnectionUpdateRequest { + /** Integration Address */ + address?: Monite.UpdateEinvoicingAddress; + /** Set to `true` if the entity needs to receive e-invoices. */ + is_receiver?: boolean; + /** Set to `true` if the entity needs to send e-invoices. Either `is_sender` or `is_receiver` or both must be `true`. */ + is_sender?: boolean; +} diff --git a/src/api/resources/eInvoicingConnections/client/requests/EinvoicingNetworkCredentialsCreateRequest.ts b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingNetworkCredentialsCreateRequest.ts index 4f3b185..5031b68 100644 --- a/src/api/resources/eInvoicingConnections/client/requests/EinvoicingNetworkCredentialsCreateRequest.ts +++ b/src/api/resources/eInvoicingConnections/client/requests/EinvoicingNetworkCredentialsCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/eInvoicingConnections/client/requests/index.ts b/src/api/resources/eInvoicingConnections/client/requests/index.ts index 334ddeb..7056dd6 100644 --- a/src/api/resources/eInvoicingConnections/client/requests/index.ts +++ b/src/api/resources/eInvoicingConnections/client/requests/index.ts @@ -1,2 +1,3 @@ -export { type EinvoicingConnectionCreateRequest } from "./EinvoicingConnectionCreateRequest"; -export { type EinvoicingNetworkCredentialsCreateRequest } from "./EinvoicingNetworkCredentialsCreateRequest"; +export { type EinvoicingConnectionCreateRequest } from "./EinvoicingConnectionCreateRequest.js"; +export { type EinvoicingConnectionUpdateRequest } from "./EinvoicingConnectionUpdateRequest.js"; +export { type EinvoicingNetworkCredentialsCreateRequest } from "./EinvoicingNetworkCredentialsCreateRequest.js"; diff --git a/src/api/resources/eInvoicingConnections/index.ts b/src/api/resources/eInvoicingConnections/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/eInvoicingConnections/index.ts +++ b/src/api/resources/eInvoicingConnections/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/eInvoicingSearch/client/Client.ts b/src/api/resources/eInvoicingSearch/client/Client.ts new file mode 100644 index 0000000..772b3d8 --- /dev/null +++ b/src/api/resources/eInvoicingSearch/client/Client.ts @@ -0,0 +1,160 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; + +export declare namespace EInvoicingSearch { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token?: core.Supplier; + /** Override the x-monite-version header */ + moniteVersion: core.Supplier; + /** Override the x-monite-entity-id header */ + moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Override the x-monite-version header */ + moniteVersion?: string; + /** Override the x-monite-entity-id header */ + moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; + /** Additional headers to include in the request. */ + headers?: Record | undefined>; + } +} + +export class EInvoicingSearch { + protected readonly _options: EInvoicingSearch.Options; + + constructor(_options: EInvoicingSearch.Options) { + this._options = _options; + } + + /** + * Checks if the specified VAT number or business number is registered on the PEPPOL network as a receiver. For example, you can use this endpoint to check if an entity's counterparts are registered in PEPPOL before creating e-invoices for those counterparts. + * + * The lookup is powered by PEPPOL SMPs (Service Metadata Publishers) so it also includes registrations that are not visible in the public PEPPOL directory. + * + * Both partner tokens and entity user tokens can be used for authentication. + * + * Production and sandbox lookups are separate. + * + * @param {Monite.GetEinvoiceSearchRequest} request + * @param {EInvoicingSearch.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.eInvoicingSearch.getEinvoiceSearch({ + * network_identifier: "DE010101010", + * network_schema: "DE:VAT" + * }) + */ + public getEinvoiceSearch( + request: Monite.GetEinvoiceSearchRequest, + requestOptions?: EInvoicingSearch.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getEinvoiceSearch(request, requestOptions)); + } + + private async __getEinvoiceSearch( + request: Monite.GetEinvoiceSearchRequest, + requestOptions?: EInvoicingSearch.RequestOptions, + ): Promise> { + const { network_identifier: networkIdentifier, network_schema: networkSchema } = request; + const _queryParams: Record = {}; + _queryParams["network_identifier"] = networkIdentifier; + _queryParams["network_schema"] = networkSchema; + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "einvoice_search", + ), + method: "GET", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: _response.body as Monite.CounterpartEinvoicingCredentialExistenceResponse, + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /einvoice_search."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } +} diff --git a/src/api/resources/eInvoicingSearch/client/index.ts b/src/api/resources/eInvoicingSearch/client/index.ts new file mode 100644 index 0000000..82648c6 --- /dev/null +++ b/src/api/resources/eInvoicingSearch/client/index.ts @@ -0,0 +1,2 @@ +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/eInvoicingSearch/client/requests/GetEinvoiceSearchRequest.ts b/src/api/resources/eInvoicingSearch/client/requests/GetEinvoiceSearchRequest.ts new file mode 100644 index 0000000..01db263 --- /dev/null +++ b/src/api/resources/eInvoicingSearch/client/requests/GetEinvoiceSearchRequest.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * { + * network_identifier: "DE010101010", + * network_schema: "DE:VAT" + * } + */ +export interface GetEinvoiceSearchRequest { + /** + * VAT number or business number, depending on the `network_schema` used. VAT numbers must include the country prefix, for example, use `DE010101010` not `10101010`. + * + * **Note:** This endpoint does not validate the format of VAT numbers and business numbers (such as the length or characters used). Invalid values will return `{"exists": false}`. + */ + network_identifier: string; + /** [PEPPOL scheme](https://docs.monite.com/e-invoicing/peppol-ids#schemes) name. */ + network_schema: Monite.EinvoiceSchemaTypeEnum; +} diff --git a/src/api/resources/eInvoicingSearch/client/requests/index.ts b/src/api/resources/eInvoicingSearch/client/requests/index.ts new file mode 100644 index 0000000..f1ab8e3 --- /dev/null +++ b/src/api/resources/eInvoicingSearch/client/requests/index.ts @@ -0,0 +1 @@ +export { type GetEinvoiceSearchRequest } from "./GetEinvoiceSearchRequest.js"; diff --git a/src/api/resources/eInvoicingSearch/index.ts b/src/api/resources/eInvoicingSearch/index.ts new file mode 100644 index 0000000..914b8c3 --- /dev/null +++ b/src/api/resources/eInvoicingSearch/index.ts @@ -0,0 +1 @@ +export * from "./client/index.js"; diff --git a/src/api/resources/entities/client/Client.ts b/src/api/resources/entities/client/Client.ts index 7f8555e..5616853 100644 --- a/src/api/resources/entities/client/Client.ts +++ b/src/api/resources/entities/client/Client.ts @@ -2,18 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; import * as fs from "fs"; -import { Blob } from "buffer"; -import { BankAccounts } from "../resources/bankAccounts/client/Client"; -import { OnboardingData } from "../resources/onboardingData/client/Client"; -import { PaymentMethods } from "../resources/paymentMethods/client/Client"; -import { VatIds } from "../resources/vatIds/client/Client"; -import { Persons } from "../resources/persons/client/Client"; +import { BankAccounts } from "../resources/bankAccounts/client/Client.js"; +import { OnboardingData } from "../resources/onboardingData/client/Client.js"; +import { PaymentMethods } from "../resources/paymentMethods/client/Client.js"; +import { VatIds } from "../resources/vatIds/client/Client.js"; +import { Persons } from "../resources/persons/client/Client.js"; export declare namespace Entities { export interface Options { @@ -25,6 +24,8 @@ export declare namespace Entities { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -39,19 +40,24 @@ export declare namespace Entities { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Entities { + protected readonly _options: Entities.Options; protected _bankAccounts: BankAccounts | undefined; protected _onboardingData: OnboardingData | undefined; protected _paymentMethods: PaymentMethods | undefined; protected _vatIds: VatIds | undefined; protected _persons: Persons | undefined; - constructor(protected readonly _options: Entities.Options) {} + constructor(_options: Entities.Options) { + this._options = _options; + } public get bankAccounts(): BankAccounts { return (this._bankAccounts ??= new BankAccounts(this._options)); @@ -84,7 +90,7 @@ export class Entities { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.get() @@ -194,32 +200,25 @@ export class Entities { _queryParams["status"] = status; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entities", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -240,8 +239,8 @@ export class Entities { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -275,8 +274,10 @@ export class Entities { * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.create({ @@ -301,30 +302,26 @@ export class Entities { request: Monite.CreateEntityRequest, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entities", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -339,10 +336,14 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -375,8 +376,9 @@ export class Entities { * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.getEntitiesMe() @@ -388,31 +390,25 @@ export class Entities { private async __getEntitiesMe( requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entities/me", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -425,10 +421,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -462,8 +460,9 @@ export class Entities { * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.patchEntitiesMe({}) @@ -479,30 +478,26 @@ export class Entities { request: Monite.UpdateEntityRequest, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entities/me", ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -517,10 +512,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -548,14 +545,23 @@ export class Entities { } /** - * Retrieve an entity by its ID. + * Returns entity information for the specified entity ID. + * + * This endpoint requires a partner access token and can be used to get any of the partner's entities. + * + * To get entity information by using an entity user token, use [`GET /entity_users/my_entity`](https://docs.monite.com/api/entities/get-entity-users-my-entity) instead. + * + * Related endpoints: + * + * * [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) * * @param {string} entityId - A unique ID to specify the entity. * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.getById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -571,31 +577,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -608,10 +608,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -639,15 +641,26 @@ export class Entities { } /** - * Change the specified fields with the provided values. + * Update entity information for the specified entity ID. + * + * This endpoint requires a partner access token and can be used to update any of the partner's entities. + * + * To update an entity by using an entity user token, use [`PATCH /entity_users/my_entity`](https://docs.monite.com/api/entities/patch-entity-users-my-entity) instead. + * + * Related endpoints: + * + * * [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) + * * [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) * * @param {string} entityId - A unique ID to specify the entity. * @param {Monite.UpdateEntityRequest} request * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.updateById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5", {}) @@ -665,30 +678,26 @@ export class Entities { request: Monite.UpdateEntityRequest, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -703,10 +712,14 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -740,8 +753,10 @@ export class Entities { * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.postEntitiesIdActivate("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -757,31 +772,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/activate`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -794,10 +803,14 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -833,8 +846,10 @@ export class Entities { * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.postEntitiesIdDeactivate("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -850,31 +865,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/deactivate`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -887,10 +896,14 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -922,57 +935,59 @@ export class Entities { /** * Entity logo can be PNG, JPG, or GIF, up to 10 MB in size. The logo is used, for example, in PDF documents created by this entity. * - * @param {File | fs.ReadStream | Blob} file + * Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. + * * @param {string} entityId + * @param {Monite.BodyPutEntitiesIdLogo} request * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.entities.uploadLogoById(fs.createReadStream("/path/to/your/file"), "ea837e28-509b-4b6a-a600-d54b6aa0b1f5") + * import { createReadStream } from "fs"; + * await client.entities.uploadLogoById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5", { + * file: fs.createReadStream("/path/to/your/file") + * }) */ public uploadLogoById( - file: File | fs.ReadStream | Blob, entityId: string, + request: Monite.BodyPutEntitiesIdLogo, requestOptions?: Entities.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__uploadLogoById(file, entityId, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__uploadLogoById(entityId, request, requestOptions)); } private async __uploadLogoById( - file: File | fs.ReadStream | Blob, entityId: string, + request: Monite.BodyPutEntitiesIdLogo, requestOptions?: Entities.RequestOptions, ): Promise> { const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/logo`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, + headers: _headers, + queryParameters: requestOptions?.queryParams, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -988,10 +1003,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1019,12 +1036,15 @@ export class Entities { } /** + * Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. + * * @param {string} entityId - A unique ID to specify the entity. * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.deleteLogoById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -1037,31 +1057,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/logo`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1072,12 +1086,14 @@ export class Entities { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1110,8 +1126,9 @@ export class Entities { * @param {string} entityId * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.getPartnerMetadataById("entity_id") @@ -1127,31 +1144,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/partner_metadata`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1162,10 +1173,12 @@ export class Entities { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1201,8 +1214,9 @@ export class Entities { * @param {Monite.PartnerMetadata} request * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.updatePartnerMetadataById("entity_id", { @@ -1226,30 +1240,26 @@ export class Entities { request: Monite.PartnerMetadata, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/partner_metadata`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1262,10 +1272,12 @@ export class Entities { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1295,14 +1307,22 @@ export class Entities { } /** - * Retrieve all settings for this entity. + * Entity settings include configuration options for accounts payable, accounts receivable, accounting integration, and other functionality. + * + * Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.read` permission. + * + * Related endpoints: + * + * * [Get next document numbers](https://docs.monite.com/api/entities/get-entities-id-settings-next-document-numbers) + * * [Get partner settings](https://docs.monite.com/api/partner-settings/get-settings) * * @param {string} entityId - A unique ID to specify the entity. * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.getSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -1318,31 +1338,25 @@ export class Entities { entityId: string, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/settings`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1355,10 +1369,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1388,15 +1404,24 @@ export class Entities { } /** - * Change the specified fields with the provided values. + * Entity settings include configuration options for accounts payable, accounts receivable, accounting integration, and other functionality. + * + * Both partner tokens and entity user tokens can be used for authentication. Entity users must have a role with the `entity.update` permission. + * + * Related endpoints: + * + * * [Update an entity](https://docs.monite.com/api/entities/patch-entities-id) + * * [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) + * * [Update partner settings](https://docs.monite.com/api/partner-settings/patch-settings) * * @param {string} entityId - A unique ID to specify the entity. * @param {Monite.PatchSettingsPayload} request * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.updateSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5") @@ -1414,30 +1439,26 @@ export class Entities { request: Monite.PatchSettingsPayload = {}, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/settings`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1452,10 +1473,12 @@ export class Entities { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1484,14 +1507,114 @@ export class Entities { } } + /** + * Returns the next sequence number for various document types - invoices, quotes, credit notes, and others. For example, if the last issued invoice is `INV-00042`, the next invoice number is 43. + * + * To set the next document numbers, use `PATCH /entities/{entity_id}/settings`. + * + * For more information, see [Document number customization](https://docs.monite.com/advanced/document-number-customization). + * + * @param {string} entityId - Unique ID of the entity + * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.entities.getEntitiesIdSettingsNextDocumentNumbers("entity_id") + */ + public getEntitiesIdSettingsNextDocumentNumbers( + entityId: string, + requestOptions?: Entities.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__getEntitiesIdSettingsNextDocumentNumbers(entityId, requestOptions), + ); + } + + private async __getEntitiesIdSettingsNextDocumentNumbers( + entityId: string, + requestOptions?: Entities.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `entities/${encodeURIComponent(entityId)}/settings/next_document_numbers`, + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.NextDocumentNumbers, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling GET /entities/{entity_id}/settings/next_document_numbers.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + /** * Provide files for entity onboarding verification * * @param {Monite.EntityOnboardingDocumentsPayload} request * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.uploadOnboardingDocuments() @@ -1507,30 +1630,26 @@ export class Entities { request: Monite.EntityOnboardingDocumentsPayload = {}, requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "onboarding_documents", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1543,10 +1662,12 @@ export class Entities { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1578,8 +1699,9 @@ export class Entities { * * @param {Entities.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.getOnboardingRequirements() @@ -1593,31 +1715,25 @@ export class Entities { private async __getOnboardingRequirements( requestOptions?: Entities.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "onboarding_requirements", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1631,10 +1747,12 @@ export class Entities { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/client/index.ts b/src/api/resources/entities/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/client/index.ts +++ b/src/api/resources/entities/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/client/requests/BodyPutEntitiesIdLogo.ts b/src/api/resources/entities/client/requests/BodyPutEntitiesIdLogo.ts new file mode 100644 index 0000000..4f48d55 --- /dev/null +++ b/src/api/resources/entities/client/requests/BodyPutEntitiesIdLogo.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + +/** + * @example + * { + * file: fs.createReadStream("/path/to/your/file") + * } + */ +export interface BodyPutEntitiesIdLogo { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/entities/client/requests/CreateEntityRequest.ts b/src/api/resources/entities/client/requests/CreateEntityRequest.ts index ffe6927..fbec67e 100644 --- a/src/api/resources/entities/client/requests/CreateEntityRequest.ts +++ b/src/api/resources/entities/client/requests/CreateEntityRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -22,20 +22,20 @@ export interface CreateEntityRequest { address: Monite.EntityAddressSchema; /** An official email address of the entity */ email: string; - /** The contact phone number of the entity. Required for US organizations to use payments. */ - phone?: string; - /** A website of the entity */ - website?: string; - /** A set of meta data describing the organization */ - organization?: Monite.OrganizationSchema; /** A set of meta data describing the individual */ individual?: Monite.IndividualSchema; - /** The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered. */ - tax_id?: string; - /** (Germany only) The entity's commercial register number (_Handelsregisternummer_) in the German Commercial Register, if available. */ - registration_number?: string; + /** A set of meta data describing the organization */ + organization?: Monite.OrganizationSchema; + /** The contact phone number of the entity. Required for US organizations to use payments. */ + phone?: string; /** (Germany only) The name of the local district court (_Amtsgericht_) where the entity is registered. Required if `registration_number` is provided. */ registration_authority?: string; + /** (Germany only) The entity's commercial register number (_Handelsregisternummer_) in the German Commercial Register, if available. */ + registration_number?: string; + /** The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered. */ + tax_id?: string; /** A type for an entity */ type: Monite.EntityTypeEnum; + /** A website of the entity */ + website?: string; } diff --git a/src/api/resources/entities/client/requests/EntitiesGetRequest.ts b/src/api/resources/entities/client/requests/EntitiesGetRequest.ts index b1aebbe..c544ad2 100644 --- a/src/api/resources/entities/client/requests/EntitiesGetRequest.ts +++ b/src/api/resources/entities/client/requests/EntitiesGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface EntitiesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface EntitiesGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.EntityCursorFields; type?: Monite.EntityTypeEnum; created_at__gt?: string; diff --git a/src/api/resources/entities/client/requests/EntityLogoUploadRequest.ts b/src/api/resources/entities/client/requests/EntityLogoUploadRequest.ts deleted file mode 100644 index 8c638b6..0000000 --- a/src/api/resources/entities/client/requests/EntityLogoUploadRequest.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * @example - * {} - */ -export interface EntityLogoUploadRequest {} diff --git a/src/api/resources/entities/client/requests/PatchSettingsPayload.ts b/src/api/resources/entities/client/requests/PatchSettingsPayload.ts index d614582..edcf7bf 100644 --- a/src/api/resources/entities/client/requests/PatchSettingsPayload.ts +++ b/src/api/resources/entities/client/requests/PatchSettingsPayload.ts @@ -2,41 +2,50 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PatchSettingsPayload { - language?: Monite.LanguageCodeEnum; - currency?: Monite.CurrencySettingsInput; - reminder?: Monite.RemindersSettings; - /** Defines whether the prices of products in receivables will already include VAT or not. */ - vat_mode?: Monite.VatModeEnum; - /** Defines whether the amount discounts (for percentage discounts it does not matter) on VAT inclusive invoices will be applied on amounts including VAT or excluding VAT. */ - vat_inclusive_discount_mode?: Monite.VatModeEnum; - /** Payment preferences for entity to automate calculating suggested payment date based on payment terms and entity preferences. */ - payment_priority?: Monite.PaymentPriorityEnum; + accounting?: Monite.AccountingSettings; /** Automatically attempt to find a corresponding purchase order for all incoming payables. */ allow_purchase_order_autolinking?: boolean; - receivable_edit_flow?: Monite.ReceivableEditFlow; + currency?: Monite.CurrencySettingsInput; document_ids?: Monite.DocumentIDsSettingsRequest; - /** Auto tagging settings for all incoming OCR payable documents. */ - payables_ocr_auto_tagging?: Monite.OcrAutoTaggingSettingsRequest[]; - /** Sets the default behavior of whether a signature is required to accept quotes. */ - quote_signature_required?: boolean; + /** Settings for rendering documents in PDF format. */ + document_rendering?: Monite.DocumentRenderingSettingsInput; /** - * This setting affects how PDF is generated for paid accounts receivable invoices. If set to `true`, once an invoice is fully paid its PDF version is updated to display the amount paid and the payment-related features are removed. + * This setting affects how PDF is generated for accounts receivable invoices that are paid, partially paid, or have credit notes applied. + * If this setting is `true`: * - * The PDF file gets regenerated at the moment when an invoice becomes paid. It is not issued as a separate document, and the original PDF invoice is no longer available. + * * The totals block in the PDF invoice will include a list of all payments made and credit notes issued. + * * Once an invoice becomes fully paid, the payment link and QR code are removed. * - * This field is deprecated and will be replaced by `document_rendering.invoice.generate_paid_invoice_pdf`. + * The PDF invoice gets regenerated at the moment when an invoice payment is recorded or a credit note is issued. This PDF is not issued as a separate document, and the original PDF invoice is no longer available. */ generate_paid_invoice_pdf?: boolean; - accounting?: Monite.AccountingSettings; + language?: Monite.LanguageCodeEnum; + /** Auto tagging settings for all incoming OCR payable documents. */ + payables_ocr_auto_tagging?: Monite.OcrAutoTaggingSettingsRequest[]; /** If enabled, the approval policy will be skipped and the payable will be moved to `waiting_to_be_paid` status. */ payables_skip_approval_flow?: boolean; - /** Settings for rendering documents in PDF format. */ - document_rendering?: Monite.DocumentRenderingSettings; + /** Payment preferences for entity to automate calculating suggested payment date based on payment terms and entity preferences. */ + payment_priority?: Monite.PaymentPriorityEnum; + /** Sets the default behavior of whether a signature is required to accept quotes. */ + quote_signature_required?: boolean; + /** + * [Invoice compliance mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance) for accounts receivable. Possible values: + * + * * `compliant` - invoices cannot be edited once issued. + * * `non_compliant` - issued invoices can still be edited. + * * `partially_compliant` - deprecated mode, should not be used. + */ + receivable_edit_flow?: Monite.ReceivableEditFlow; + reminder?: Monite.RemindersSettings; + /** Defines whether the amount discounts (for percentage discounts it does not matter) on VAT inclusive invoices will be applied on amounts including VAT or excluding VAT. */ + vat_inclusive_discount_mode?: Monite.VatModeEnum; + /** Defines whether the prices of products in receivables will already include VAT or not. */ + vat_mode?: Monite.VatModeEnum; } diff --git a/src/api/resources/entities/client/requests/index.ts b/src/api/resources/entities/client/requests/index.ts index aa4d51e..9e465b5 100644 --- a/src/api/resources/entities/client/requests/index.ts +++ b/src/api/resources/entities/client/requests/index.ts @@ -1,5 +1,5 @@ -export { type EntitiesGetRequest } from "./EntitiesGetRequest"; -export { type CreateEntityRequest } from "./CreateEntityRequest"; -export { type EntityLogoUploadRequest } from "./EntityLogoUploadRequest"; -export { type PatchSettingsPayload } from "./PatchSettingsPayload"; -export { type EntityOnboardingDocumentsPayload } from "./EntityOnboardingDocumentsPayload"; +export { type EntitiesGetRequest } from "./EntitiesGetRequest.js"; +export { type CreateEntityRequest } from "./CreateEntityRequest.js"; +export { type BodyPutEntitiesIdLogo } from "./BodyPutEntitiesIdLogo.js"; +export { type PatchSettingsPayload } from "./PatchSettingsPayload.js"; +export { type EntityOnboardingDocumentsPayload } from "./EntityOnboardingDocumentsPayload.js"; diff --git a/src/api/resources/entities/index.ts b/src/api/resources/entities/index.ts index 33a87f1..9eb1192 100644 --- a/src/api/resources/entities/index.ts +++ b/src/api/resources/entities/index.ts @@ -1,2 +1,2 @@ -export * from "./client"; -export * from "./resources"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/entities/resources/bankAccounts/client/Client.ts b/src/api/resources/entities/resources/bankAccounts/client/Client.ts index 414fe2b..2617377 100644 --- a/src/api/resources/entities/resources/bankAccounts/client/Client.ts +++ b/src/api/resources/entities/resources/bankAccounts/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace BankAccounts { export interface Options { @@ -18,6 +18,8 @@ export declare namespace BankAccounts { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,22 +34,29 @@ export declare namespace BankAccounts { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class BankAccounts { - constructor(protected readonly _options: BankAccounts.Options) {} + protected readonly _options: BankAccounts.Options; + + constructor(_options: BankAccounts.Options) { + this._options = _options; + } /** * Get all bank accounts of this entity. * * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.get() @@ -61,31 +70,25 @@ export class BankAccounts { private async __get( requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "bank_accounts", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -99,12 +102,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -150,14 +155,47 @@ export class BankAccounts { * @param {Monite.entities.CreateEntityBankAccountRequest} request * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.create({ - * country: "AF", - * currency: "AED" + * account_holder_name: "Tobias Weingart", + * bank_name: "DEUTSCHE BANK AG", + * bic: "DEUTDEFFXXX", + * country: "DE", + * currency: "EUR", + * display_name: "Primary account", + * iban: "DE74500700100100000900", + * is_default_for_currency: true + * }) + * + * @example + * await client.entities.bankAccounts.create({ + * account_holder_name: "Esther Walsh", + * account_number: "12345678", + * bank_name: "HSBC UK BANK PLC", + * bic: "HBUKGB4B", + * country: "GB", + * currency: "GBP", + * display_name: "Primary account", + * iban: "GB15HBUK40312412345678", + * is_default_for_currency: true, + * sort_code: "123456" + * }) + * + * @example + * await client.entities.bankAccounts.create({ + * account_holder_name: "Bob Jones", + * account_number: "2571714302", + * bank_name: "WELLS FARGO", + * country: "US", + * currency: "USD", + * display_name: "Primary account", + * is_default_for_currency: true, + * routing_number: "061000227" * }) */ public create( @@ -171,30 +209,26 @@ export class BankAccounts { request: Monite.entities.CreateEntityBankAccountRequest, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "bank_accounts", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -207,12 +241,14 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -245,10 +281,11 @@ export class BankAccounts { * @param {string} bankAccountId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.getById("bank_account_id") @@ -264,31 +301,25 @@ export class BankAccounts { bankAccountId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -299,14 +330,16 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -341,10 +374,11 @@ export class BankAccounts { * @param {string} bankAccountId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.deleteById("bank_account_id") @@ -360,31 +394,25 @@ export class BankAccounts { bankAccountId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -395,14 +423,16 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -438,10 +468,11 @@ export class BankAccounts { * @param {Monite.entities.UpdateEntityBankAccountRequest} request * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.updateById("bank_account_id") @@ -459,30 +490,26 @@ export class BankAccounts { request: Monite.entities.UpdateEntityBankAccountRequest = {}, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `bank_accounts/${encodeURIComponent(bankAccountId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -495,14 +522,16 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -537,10 +566,11 @@ export class BankAccounts { * @param {string} bankAccountId * @param {BankAccounts.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.bankAccounts.makeDefaultById("bank_account_id") @@ -556,31 +586,25 @@ export class BankAccounts { bankAccountId: string, requestOptions?: BankAccounts.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `bank_accounts/${encodeURIComponent(bankAccountId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -591,14 +615,16 @@ export class BankAccounts { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/resources/bankAccounts/client/index.ts b/src/api/resources/entities/resources/bankAccounts/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/resources/bankAccounts/client/index.ts +++ b/src/api/resources/entities/resources/bankAccounts/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/resources/bankAccounts/client/requests/CreateEntityBankAccountRequest.ts b/src/api/resources/entities/resources/bankAccounts/client/requests/CreateEntityBankAccountRequest.ts index 66cd92e..5816acf 100644 --- a/src/api/resources/entities/resources/bankAccounts/client/requests/CreateEntityBankAccountRequest.ts +++ b/src/api/resources/entities/resources/bankAccounts/client/requests/CreateEntityBankAccountRequest.ts @@ -2,13 +2,45 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example * { - * country: "AF", - * currency: "AED" + * account_holder_name: "Tobias Weingart", + * bank_name: "DEUTSCHE BANK AG", + * bic: "DEUTDEFFXXX", + * country: "DE", + * currency: "EUR", + * display_name: "Primary account", + * iban: "DE74500700100100000900", + * is_default_for_currency: true + * } + * + * @example + * { + * account_holder_name: "Esther Walsh", + * account_number: "12345678", + * bank_name: "HSBC UK BANK PLC", + * bic: "HBUKGB4B", + * country: "GB", + * currency: "GBP", + * display_name: "Primary account", + * iban: "GB15HBUK40312412345678", + * is_default_for_currency: true, + * sort_code: "123456" + * } + * + * @example + * { + * account_holder_name: "Bob Jones", + * account_number: "2571714302", + * bank_name: "WELLS FARGO", + * country: "US", + * currency: "USD", + * display_name: "Primary account", + * is_default_for_currency: true, + * routing_number: "061000227" * } */ export interface CreateEntityBankAccountRequest { diff --git a/src/api/resources/entities/resources/bankAccounts/client/requests/index.ts b/src/api/resources/entities/resources/bankAccounts/client/requests/index.ts index adfed84..dd9efde 100644 --- a/src/api/resources/entities/resources/bankAccounts/client/requests/index.ts +++ b/src/api/resources/entities/resources/bankAccounts/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type CreateEntityBankAccountRequest } from "./CreateEntityBankAccountRequest"; -export { type UpdateEntityBankAccountRequest } from "./UpdateEntityBankAccountRequest"; +export { type CreateEntityBankAccountRequest } from "./CreateEntityBankAccountRequest.js"; +export { type UpdateEntityBankAccountRequest } from "./UpdateEntityBankAccountRequest.js"; diff --git a/src/api/resources/entities/resources/bankAccounts/index.ts b/src/api/resources/entities/resources/bankAccounts/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entities/resources/bankAccounts/index.ts +++ b/src/api/resources/entities/resources/bankAccounts/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/entities/resources/index.ts b/src/api/resources/entities/resources/index.ts index 791b011..61becf1 100644 --- a/src/api/resources/entities/resources/index.ts +++ b/src/api/resources/entities/resources/index.ts @@ -1,10 +1,10 @@ -export * as bankAccounts from "./bankAccounts"; -export * as onboardingData from "./onboardingData"; -export * as paymentMethods from "./paymentMethods"; -export * as vatIds from "./vatIds"; -export * as persons from "./persons"; -export * from "./bankAccounts/client/requests"; -export * from "./onboardingData/client/requests"; -export * from "./paymentMethods/client/requests"; -export * from "./vatIds/client/requests"; -export * from "./persons/client/requests"; +export * as bankAccounts from "./bankAccounts/index.js"; +export * as onboardingData from "./onboardingData/index.js"; +export * as paymentMethods from "./paymentMethods/index.js"; +export * as vatIds from "./vatIds/index.js"; +export * as persons from "./persons/index.js"; +export * from "./bankAccounts/client/requests/index.js"; +export * from "./onboardingData/client/requests/index.js"; +export * from "./paymentMethods/client/requests/index.js"; +export * from "./vatIds/client/requests/index.js"; +export * from "./persons/client/requests/index.js"; diff --git a/src/api/resources/entities/resources/onboardingData/client/Client.ts b/src/api/resources/entities/resources/onboardingData/client/Client.ts index d46999e..ee662d4 100644 --- a/src/api/resources/entities/resources/onboardingData/client/Client.ts +++ b/src/api/resources/entities/resources/onboardingData/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace OnboardingData { export interface Options { @@ -18,6 +18,8 @@ export declare namespace OnboardingData { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,22 +34,29 @@ export declare namespace OnboardingData { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class OnboardingData { - constructor(protected readonly _options: OnboardingData.Options) {} + protected readonly _options: OnboardingData.Options; + + constructor(_options: OnboardingData.Options) { + this._options = _options; + } /** * @param {string} entityId * @param {OnboardingData.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.onboardingData.get("entity_id") @@ -63,31 +72,25 @@ export class OnboardingData { entityId: string, requestOptions?: OnboardingData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/onboarding_data`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -98,14 +101,16 @@ export class OnboardingData { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -139,10 +144,11 @@ export class OnboardingData { * @param {Monite.entities.EntityOnboardingDataRequest} request * @param {OnboardingData.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.onboardingData.update("entity_id") @@ -160,30 +166,26 @@ export class OnboardingData { request: Monite.entities.EntityOnboardingDataRequest = {}, requestOptions?: OnboardingData.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/onboarding_data`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -196,14 +198,16 @@ export class OnboardingData { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/resources/onboardingData/client/index.ts b/src/api/resources/entities/resources/onboardingData/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/resources/onboardingData/client/index.ts +++ b/src/api/resources/entities/resources/onboardingData/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/resources/onboardingData/client/requests/EntityOnboardingDataRequest.ts b/src/api/resources/entities/resources/onboardingData/client/requests/EntityOnboardingDataRequest.ts index a9e5dd7..bf0cc6c 100644 --- a/src/api/resources/entities/resources/onboardingData/client/requests/EntityOnboardingDataRequest.ts +++ b/src/api/resources/entities/resources/onboardingData/client/requests/EntityOnboardingDataRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example @@ -15,4 +15,6 @@ export interface EntityOnboardingDataRequest { ownership_declaration?: Monite.OwnershipDeclarationInput; /** Details on the entity's acceptance of the service agreement. */ tos_acceptance?: Monite.TermsOfServiceAcceptanceInput; + /** Details on the entity's acceptance of the Stripe Treasury service agreement. */ + treasury_tos_acceptance?: Monite.TermsOfServiceAcceptanceInput; } diff --git a/src/api/resources/entities/resources/onboardingData/client/requests/index.ts b/src/api/resources/entities/resources/onboardingData/client/requests/index.ts index d7bd248..490264c 100644 --- a/src/api/resources/entities/resources/onboardingData/client/requests/index.ts +++ b/src/api/resources/entities/resources/onboardingData/client/requests/index.ts @@ -1 +1 @@ -export { type EntityOnboardingDataRequest } from "./EntityOnboardingDataRequest"; +export { type EntityOnboardingDataRequest } from "./EntityOnboardingDataRequest.js"; diff --git a/src/api/resources/entities/resources/onboardingData/index.ts b/src/api/resources/entities/resources/onboardingData/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entities/resources/onboardingData/index.ts +++ b/src/api/resources/entities/resources/onboardingData/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/entities/resources/paymentMethods/client/Client.ts b/src/api/resources/entities/resources/paymentMethods/client/Client.ts index 2167582..15ad229 100644 --- a/src/api/resources/entities/resources/paymentMethods/client/Client.ts +++ b/src/api/resources/entities/resources/paymentMethods/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace PaymentMethods { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentMethods { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace PaymentMethods { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentMethods { - constructor(protected readonly _options: PaymentMethods.Options) {} + protected readonly _options: PaymentMethods.Options; + + constructor(_options: PaymentMethods.Options) { + this._options = _options; + } /** * Get all enabled payment methods. @@ -46,8 +54,9 @@ export class PaymentMethods { * @param {string} entityId * @param {PaymentMethods.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.paymentMethods.get("entity_id") @@ -63,31 +72,25 @@ export class PaymentMethods { entityId: string, requestOptions?: PaymentMethods.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/payment_methods`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,10 +104,12 @@ export class PaymentMethods { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -140,11 +145,20 @@ export class PaymentMethods { * @param {Monite.entities.EnabledPaymentMethods} request * @param {PaymentMethods.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.entities.paymentMethods.set("entity_id", { + * payment_methods_receive: ["card", "sepa_credit", "sepa_debit"], + * payment_methods_send: ["sepa_credit"] + * }) * * @example - * await client.entities.paymentMethods.set("entity_id") + * await client.entities.paymentMethods.set("entity_id", { + * payment_methods_receive: ["card", "us_ach", "affirm", "klarna"] + * }) */ public set( entityId: string, @@ -159,30 +173,26 @@ export class PaymentMethods { request: Monite.entities.EnabledPaymentMethods = {}, requestOptions?: PaymentMethods.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/payment_methods`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -198,10 +208,12 @@ export class PaymentMethods { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/resources/paymentMethods/client/index.ts b/src/api/resources/entities/resources/paymentMethods/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/resources/paymentMethods/client/index.ts +++ b/src/api/resources/entities/resources/paymentMethods/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/resources/paymentMethods/client/requests/EnabledPaymentMethods.ts b/src/api/resources/entities/resources/paymentMethods/client/requests/EnabledPaymentMethods.ts index fdfe195..7bf56c8 100644 --- a/src/api/resources/entities/resources/paymentMethods/client/requests/EnabledPaymentMethods.ts +++ b/src/api/resources/entities/resources/paymentMethods/client/requests/EnabledPaymentMethods.ts @@ -2,17 +2,35 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example - * {} + * { + * payment_methods_receive: ["card", "sepa_credit", "sepa_debit"], + * payment_methods_send: ["sepa_credit"] + * } + * + * @example + * { + * payment_methods_receive: ["card", "us_ach", "affirm", "klarna"] + * } */ export interface EnabledPaymentMethods { - /** Deprecated. Use payment_methods_receive instead. */ + /** Deprecated. Replaced by `payment_methods_receive`. */ payment_methods?: Monite.MoniteAllPaymentMethodsTypes[]; - /** Enable payment methods to receive money. */ + /** + * Payment methods to receive money from customers. Supported payment methods [vary per country](https://docs.monite.com/payments/payment-methods). + * + * `card` includes card payments, Apple Pay, and Google Pay. The values `applepay` and `googlepay` are deprecated and unused. + * + * `sofort` is deprecated and replaced by `klarna`. + */ payment_methods_receive?: Monite.MoniteAllPaymentMethodsTypes[]; - /** Enable payment methods to send money. */ + /** + * Only for entities in the EU and UK. Payment methods used to make payments to vendors. + * + * Currently only `sepa_credit` is supported for making payments. + */ payment_methods_send?: Monite.MoniteAllPaymentMethodsTypes[]; } diff --git a/src/api/resources/entities/resources/paymentMethods/client/requests/index.ts b/src/api/resources/entities/resources/paymentMethods/client/requests/index.ts index 21557a9..82c9454 100644 --- a/src/api/resources/entities/resources/paymentMethods/client/requests/index.ts +++ b/src/api/resources/entities/resources/paymentMethods/client/requests/index.ts @@ -1 +1 @@ -export { type EnabledPaymentMethods } from "./EnabledPaymentMethods"; +export { type EnabledPaymentMethods } from "./EnabledPaymentMethods.js"; diff --git a/src/api/resources/entities/resources/paymentMethods/index.ts b/src/api/resources/entities/resources/paymentMethods/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entities/resources/paymentMethods/index.ts +++ b/src/api/resources/entities/resources/paymentMethods/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/entities/resources/persons/client/Client.ts b/src/api/resources/entities/resources/persons/client/Client.ts index b6b9493..48b9625 100644 --- a/src/api/resources/entities/resources/persons/client/Client.ts +++ b/src/api/resources/entities/resources/persons/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace Persons { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Persons { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,19 +34,26 @@ export declare namespace Persons { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Persons { - constructor(protected readonly _options: Persons.Options) {} + protected readonly _options: Persons.Options; + + constructor(_options: Persons.Options) { + this._options = _options; + } /** * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.get() @@ -56,31 +65,25 @@ export class Persons { private async __get( requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "persons", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -91,10 +94,12 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -125,9 +130,10 @@ export class Persons { * @param {Monite.entities.PersonRequest} request * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.create({ @@ -148,30 +154,26 @@ export class Persons { request: Monite.entities.PersonRequest, requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "persons", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -184,12 +186,14 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -220,9 +224,10 @@ export class Persons { * @param {string} personId * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.getById("person_id") @@ -238,31 +243,25 @@ export class Persons { personId: string, requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `persons/${encodeURIComponent(personId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -273,12 +272,14 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -309,10 +310,11 @@ export class Persons { * @param {string} personId * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.deleteById("person_id") @@ -325,31 +327,25 @@ export class Persons { personId: string, requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `persons/${encodeURIComponent(personId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -360,14 +356,16 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -399,10 +397,11 @@ export class Persons { * @param {Monite.entities.OptionalPersonRequest} request * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.updateById("person_id") @@ -420,30 +419,26 @@ export class Persons { request: Monite.entities.OptionalPersonRequest = {}, requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `persons/${encodeURIComponent(personId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -456,14 +451,16 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -497,8 +494,9 @@ export class Persons { * @param {Monite.entities.PersonOnboardingDocumentsPayload} request * @param {Persons.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.persons.uploadOnboardingDocuments("person_id") @@ -518,30 +516,26 @@ export class Persons { request: Monite.entities.PersonOnboardingDocumentsPayload = {}, requestOptions?: Persons.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `persons/${encodeURIComponent(personId)}/onboarding_documents`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -554,10 +548,12 @@ export class Persons { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/resources/persons/client/index.ts b/src/api/resources/entities/resources/persons/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/resources/persons/client/index.ts +++ b/src/api/resources/entities/resources/persons/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/resources/persons/client/requests/OptionalPersonRequest.ts b/src/api/resources/entities/resources/persons/client/requests/OptionalPersonRequest.ts index 2e92bc3..ef0c08c 100644 --- a/src/api/resources/entities/resources/persons/client/requests/OptionalPersonRequest.ts +++ b/src/api/resources/entities/resources/persons/client/requests/OptionalPersonRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/entities/resources/persons/client/requests/PersonRequest.ts b/src/api/resources/entities/resources/persons/client/requests/PersonRequest.ts index 5a2d3e5..7e02c62 100644 --- a/src/api/resources/entities/resources/persons/client/requests/PersonRequest.ts +++ b/src/api/resources/entities/resources/persons/client/requests/PersonRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/entities/resources/persons/client/requests/index.ts b/src/api/resources/entities/resources/persons/client/requests/index.ts index e4f56a0..90f625c 100644 --- a/src/api/resources/entities/resources/persons/client/requests/index.ts +++ b/src/api/resources/entities/resources/persons/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type PersonRequest } from "./PersonRequest"; -export { type OptionalPersonRequest } from "./OptionalPersonRequest"; -export { type PersonOnboardingDocumentsPayload } from "./PersonOnboardingDocumentsPayload"; +export { type PersonRequest } from "./PersonRequest.js"; +export { type OptionalPersonRequest } from "./OptionalPersonRequest.js"; +export { type PersonOnboardingDocumentsPayload } from "./PersonOnboardingDocumentsPayload.js"; diff --git a/src/api/resources/entities/resources/persons/index.ts b/src/api/resources/entities/resources/persons/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entities/resources/persons/index.ts +++ b/src/api/resources/entities/resources/persons/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/entities/resources/vatIds/client/Client.ts b/src/api/resources/entities/resources/vatIds/client/Client.ts index f8ad8c4..393a5ea 100644 --- a/src/api/resources/entities/resources/vatIds/client/Client.ts +++ b/src/api/resources/entities/resources/vatIds/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace VatIds { export interface Options { @@ -18,6 +18,8 @@ export declare namespace VatIds { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace VatIds { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class VatIds { - constructor(protected readonly _options: VatIds.Options) {} + protected readonly _options: VatIds.Options; + + constructor(_options: VatIds.Options) { + this._options = _options; + } /** * @param {string} entityId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.vatIds.get("entity_id") @@ -61,31 +70,25 @@ export class VatIds { entityId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/vat_ids`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -96,10 +99,12 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -131,9 +136,10 @@ export class VatIds { * @param {Monite.entities.EntityVatId} request * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.vatIds.create("entity_id", { @@ -154,30 +160,26 @@ export class VatIds { request: Monite.entities.EntityVatId, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/vat_ids`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -190,12 +192,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -229,9 +233,10 @@ export class VatIds { * @param {string} entityId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.vatIds.getById("id", "entity_id") @@ -249,31 +254,25 @@ export class VatIds { entityId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/vat_ids/${encodeURIComponent(id)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -284,12 +283,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -323,9 +324,10 @@ export class VatIds { * @param {string} entityId * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.vatIds.deleteById("id", "entity_id") @@ -343,31 +345,25 @@ export class VatIds { entityId: string, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/vat_ids/${encodeURIComponent(id)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -378,12 +374,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -418,9 +416,10 @@ export class VatIds { * @param {Monite.entities.EntityUpdateVatId} request * @param {VatIds.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entities.vatIds.updateById("id", "entity_id") @@ -440,30 +439,26 @@ export class VatIds { request: Monite.entities.EntityUpdateVatId = {}, requestOptions?: VatIds.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entities/${encodeURIComponent(entityId)}/vat_ids/${encodeURIComponent(id)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -476,12 +471,14 @@ export class VatIds { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entities/resources/vatIds/client/index.ts b/src/api/resources/entities/resources/vatIds/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entities/resources/vatIds/client/index.ts +++ b/src/api/resources/entities/resources/vatIds/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entities/resources/vatIds/client/requests/EntityUpdateVatId.ts b/src/api/resources/entities/resources/vatIds/client/requests/EntityUpdateVatId.ts index 2395e79..87d9c44 100644 --- a/src/api/resources/entities/resources/vatIds/client/requests/EntityUpdateVatId.ts +++ b/src/api/resources/entities/resources/vatIds/client/requests/EntityUpdateVatId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/entities/resources/vatIds/client/requests/EntityVatId.ts b/src/api/resources/entities/resources/vatIds/client/requests/EntityVatId.ts index 96b5334..6516098 100644 --- a/src/api/resources/entities/resources/vatIds/client/requests/EntityVatId.ts +++ b/src/api/resources/entities/resources/vatIds/client/requests/EntityVatId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/entities/resources/vatIds/client/requests/index.ts b/src/api/resources/entities/resources/vatIds/client/requests/index.ts index bde42db..d334e05 100644 --- a/src/api/resources/entities/resources/vatIds/client/requests/index.ts +++ b/src/api/resources/entities/resources/vatIds/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type EntityVatId } from "./EntityVatId"; -export { type EntityUpdateVatId } from "./EntityUpdateVatId"; +export { type EntityVatId } from "./EntityVatId.js"; +export { type EntityUpdateVatId } from "./EntityUpdateVatId.js"; diff --git a/src/api/resources/entities/resources/vatIds/index.ts b/src/api/resources/entities/resources/vatIds/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entities/resources/vatIds/index.ts +++ b/src/api/resources/entities/resources/vatIds/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/entityUsers/client/Client.ts b/src/api/resources/entityUsers/client/Client.ts index f495d9a..4ca5f72 100644 --- a/src/api/resources/entityUsers/client/Client.ts +++ b/src/api/resources/entityUsers/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace EntityUsers { export interface Options { @@ -18,6 +18,8 @@ export declare namespace EntityUsers { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace EntityUsers { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class EntityUsers { - constructor(protected readonly _options: EntityUsers.Options) {} + protected readonly _options: EntityUsers.Options; + + constructor(_options: EntityUsers.Options) { + this._options = _options; + } /** * Retrieve a list of all entity users. @@ -51,7 +59,7 @@ export class EntityUsers { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.get() @@ -162,32 +170,25 @@ export class EntityUsers { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -208,8 +209,8 @@ export class EntityUsers { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -243,8 +244,9 @@ export class EntityUsers { * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.create({ @@ -263,30 +265,26 @@ export class EntityUsers { request: Monite.CreateEntityUserRequest, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -301,10 +299,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -332,13 +332,14 @@ export class EntityUsers { } /** - * Retrieve an entity user by its ID. + * The user ID is inferred fron the `Authorization` header, which must contain a user-level access token. * * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.getCurrent() @@ -352,31 +353,25 @@ export class EntityUsers { private async __getCurrent( requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users/me", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -389,10 +384,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -420,14 +417,15 @@ export class EntityUsers { } /** - * Change the specified fields with provided values. + * The user ID is inferred fron the `Authorization` header, which must contain a user-level access token. * * @param {Monite.UpdateMeEntityUserRequest} request * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.updateCurrent() @@ -443,30 +441,26 @@ export class EntityUsers { request: Monite.UpdateMeEntityUserRequest = {}, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users/me", ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -481,10 +475,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -512,13 +508,20 @@ export class EntityUsers { } /** - * Retrieves information of an entity, which this entity user belongs to. + * Returns the entity to which the authenticated user belongs. This endpoint requires an [entity user access token](https://docs.monite.com/api/concepts/authentication#entity-user-token). The user must have a role with the `entity.read` permission. + * + * To get an entity by using a partner access token, use [`GET /entities/{entity_id}`](https://docs.monite.com/api/entities/get-entities-id) instead. + * + * Related endpoints: + * + * * [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) * * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.getCurrentEntity() @@ -532,31 +535,25 @@ export class EntityUsers { private async __getCurrentEntity( requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users/my_entity", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -569,10 +566,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -600,14 +599,24 @@ export class EntityUsers { } /** - * Update information of an entity, which this entity user belongs to. + * Update the entity to which the authenticated user belongs. + * + * This endpoint requires an [entity user access token](https://docs.monite.com/api/concepts/authentication#entity-user-token). The user must have a role with the `entity.update` permission. + * + * This endpoint does not use the `X-Monite-Entity-Id` header. The entity ID is inferred from the access token. + * + * Related endpoints: + * + * * [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) + * * [Update entity logo](https://docs.monite.com/api/entities/put-entities-id-logo) * * @param {Monite.UpdateEntityRequest} request * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.updateCurrentEntity({}) @@ -623,30 +632,26 @@ export class EntityUsers { request: Monite.UpdateEntityRequest, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users/my_entity", ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -661,10 +666,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -696,8 +703,9 @@ export class EntityUsers { * * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.getCurrentRole() @@ -709,31 +717,25 @@ export class EntityUsers { private async __getCurrentRole( requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "entity_users/my_role", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -744,10 +746,12 @@ export class EntityUsers { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -781,8 +785,9 @@ export class EntityUsers { * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.getById("entity_user_id") @@ -798,31 +803,25 @@ export class EntityUsers { entityUserId: string, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entity_users/${encodeURIComponent(entityUserId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -835,10 +834,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -872,8 +873,9 @@ export class EntityUsers { * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.deleteById("entity_user_id") @@ -889,31 +891,25 @@ export class EntityUsers { entityUserId: string, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entity_users/${encodeURIComponent(entityUserId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -926,10 +922,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -966,8 +964,9 @@ export class EntityUsers { * @param {EntityUsers.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.entityUsers.updateById("entity_user_id") @@ -985,30 +984,26 @@ export class EntityUsers { request: Monite.UpdateEntityUserRequest = {}, requestOptions?: EntityUsers.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `entity_users/${encodeURIComponent(entityUserId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1023,10 +1018,12 @@ export class EntityUsers { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/entityUsers/client/index.ts b/src/api/resources/entityUsers/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/entityUsers/client/index.ts +++ b/src/api/resources/entityUsers/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/entityUsers/client/requests/CreateEntityUserRequest.ts b/src/api/resources/entityUsers/client/requests/CreateEntityUserRequest.ts index f7e3aff..abe5731 100644 --- a/src/api/resources/entityUsers/client/requests/CreateEntityUserRequest.ts +++ b/src/api/resources/entityUsers/client/requests/CreateEntityUserRequest.ts @@ -10,17 +10,22 @@ * } */ export interface CreateEntityUserRequest { - /** An entity user business email */ + /** The user's business email address. */ email?: string; - /** First name */ + /** The user's first name. */ first_name: string; - /** Last name */ + /** The user's last name. */ last_name?: string; + /** + * The username assigned to this user. Usernames must be unique within the entity. + * + * The `login` value is not used by Monite but may be used by partner applications, for example, to map the users between the partner's platform and Monite. + */ login: string; - /** An entity user phone number in the international format */ + /** The user's phone number. */ phone?: string; - /** UUID of the role assigned to this entity user */ + /** ID of the role to assign to this user. The role defines the user's [access permissions](https://docs.monite.com/api/concepts/authentication#permissions) within the entity. Each user has just one role. */ role_id?: string; - /** Title */ + /** The user's job title. */ title?: string; } diff --git a/src/api/resources/entityUsers/client/requests/EntityUsersGetRequest.ts b/src/api/resources/entityUsers/client/requests/EntityUsersGetRequest.ts index eaa72b6..2221b21 100644 --- a/src/api/resources/entityUsers/client/requests/EntityUsersGetRequest.ts +++ b/src/api/resources/entityUsers/client/requests/EntityUsersGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface EntityUsersGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface EntityUsersGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.EntityUserCursorFields; id__in?: string | string[]; id__not_in?: string | string[]; diff --git a/src/api/resources/entityUsers/client/requests/UpdateEntityUserRequest.ts b/src/api/resources/entityUsers/client/requests/UpdateEntityUserRequest.ts index 9138171..c3cc4fa 100644 --- a/src/api/resources/entityUsers/client/requests/UpdateEntityUserRequest.ts +++ b/src/api/resources/entityUsers/client/requests/UpdateEntityUserRequest.ts @@ -7,18 +7,18 @@ * {} */ export interface UpdateEntityUserRequest { - /** An entity user business email */ + /** The user's business email address. */ email?: string; - /** First name */ + /** The user's first name. */ first_name?: string; - /** Last name */ + /** The user's last name. */ last_name?: string; - /** Login */ + /** The new username for this user. Must be unique within the entity. */ login?: string; - /** An entity user phone number in the international format */ + /** The user's phone number. */ phone?: string; - /** UUID of the role assigned to this entity user */ + /** ID of the new role to assign to this user. The new role takes effect immediately, existing access tokens of this user are not invalidated. */ role_id?: string; - /** Title */ + /** The user's job title. */ title?: string; } diff --git a/src/api/resources/entityUsers/client/requests/UpdateMeEntityUserRequest.ts b/src/api/resources/entityUsers/client/requests/UpdateMeEntityUserRequest.ts index 1f5b86b..818a157 100644 --- a/src/api/resources/entityUsers/client/requests/UpdateMeEntityUserRequest.ts +++ b/src/api/resources/entityUsers/client/requests/UpdateMeEntityUserRequest.ts @@ -7,14 +7,14 @@ * {} */ export interface UpdateMeEntityUserRequest { - /** An entity user business email */ + /** The user's business email address. */ email?: string; - /** First name */ + /** The user's first name. */ first_name?: string; - /** Last name */ + /** The user's last name. */ last_name?: string; - /** An entity user phone number in the international format */ + /** The user's phone number. */ phone?: string; - /** Title */ + /** The user's job title. */ title?: string; } diff --git a/src/api/resources/entityUsers/client/requests/index.ts b/src/api/resources/entityUsers/client/requests/index.ts index 57e3126..a9e0e7b 100644 --- a/src/api/resources/entityUsers/client/requests/index.ts +++ b/src/api/resources/entityUsers/client/requests/index.ts @@ -1,4 +1,4 @@ -export { type EntityUsersGetRequest } from "./EntityUsersGetRequest"; -export { type CreateEntityUserRequest } from "./CreateEntityUserRequest"; -export { type UpdateMeEntityUserRequest } from "./UpdateMeEntityUserRequest"; -export { type UpdateEntityUserRequest } from "./UpdateEntityUserRequest"; +export { type EntityUsersGetRequest } from "./EntityUsersGetRequest.js"; +export { type CreateEntityUserRequest } from "./CreateEntityUserRequest.js"; +export { type UpdateMeEntityUserRequest } from "./UpdateMeEntityUserRequest.js"; +export { type UpdateEntityUserRequest } from "./UpdateEntityUserRequest.js"; diff --git a/src/api/resources/entityUsers/index.ts b/src/api/resources/entityUsers/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/entityUsers/index.ts +++ b/src/api/resources/entityUsers/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/events/client/Client.ts b/src/api/resources/events/client/Client.ts index 0209507..75d9442 100644 --- a/src/api/resources/events/client/Client.ts +++ b/src/api/resources/events/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Events { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Events { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Events { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Events { - constructor(protected readonly _options: Events.Options) {} + protected readonly _options: Events.Options; + + constructor(_options: Events.Options) { + this._options = _options; + } /** * Returns all webhook events that were triggered for the specified entity based on your enabled webhook subscriptions. These are the same events that were sent to your configured webhook listener endpoints, aggregated into a single list. Results can be filtered by the related object type or time period. @@ -50,8 +58,9 @@ export class Events { * @param {Monite.EventsGetRequest} request * @param {Events.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.events.get() @@ -115,32 +124,25 @@ export class Events { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "events", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -151,10 +153,12 @@ export class Events { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -187,8 +191,9 @@ export class Events { * @param {string} eventId - ID of the webhook event. This is the `id` value you might have received in a webhook or retrieved from `GET /events`. * @param {Events.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.events.getById("event_id") @@ -204,31 +209,25 @@ export class Events { eventId: string, requestOptions?: Events.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `events/${encodeURIComponent(eventId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -239,10 +238,12 @@ export class Events { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/events/client/index.ts b/src/api/resources/events/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/events/client/index.ts +++ b/src/api/resources/events/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/events/client/requests/EventsGetRequest.ts b/src/api/resources/events/client/requests/EventsGetRequest.ts index 116ecf2..52c8e2a 100644 --- a/src/api/resources/events/client/requests/EventsGetRequest.ts +++ b/src/api/resources/events/client/requests/EventsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface EventsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface EventsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.EventCursorFields; object_type?: Monite.WebhookObjectType; created_at__gt?: string; diff --git a/src/api/resources/events/client/requests/index.ts b/src/api/resources/events/client/requests/index.ts index 757bafd..6ea0be4 100644 --- a/src/api/resources/events/client/requests/index.ts +++ b/src/api/resources/events/client/requests/index.ts @@ -1 +1 @@ -export { type EventsGetRequest } from "./EventsGetRequest"; +export { type EventsGetRequest } from "./EventsGetRequest.js"; diff --git a/src/api/resources/events/index.ts b/src/api/resources/events/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/events/index.ts +++ b/src/api/resources/events/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/files/client/Client.ts b/src/api/resources/files/client/Client.ts index 272ddd3..188082a 100644 --- a/src/api/resources/files/client/Client.ts +++ b/src/api/resources/files/client/Client.ts @@ -2,13 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; import * as fs from "fs"; -import { Blob } from "buffer"; export declare namespace Files { export interface Options { @@ -20,6 +19,8 @@ export declare namespace Files { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -34,20 +35,38 @@ export declare namespace Files { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Files { - constructor(protected readonly _options: Files.Options) {} + protected readonly _options: Files.Options; + + constructor(_options: Files.Options) { + this._options = _options; + } /** + * The `/files` endpoint provides access to an entity's files hosted on Monite's servers. This includes both files uploaded by the entity and files that were automatically created by Monite (such as PDF versions of invoices). + * + * `GET /files` requires at least one query parameter, either `id__in` or `file_type`. You can use this operation to: + * + * * Bulk fetch multiple files by IDs. + * * Get all files with the given purpose (for example, invoice attachments). + * + * If no files matching the query parameters were found, the response contains an empty `data` array. + * + * Both partner tokens and entity user tokens can be used for authentication. + * * @param {Monite.FilesGetRequest} request * @param {Files.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.files.get() @@ -63,7 +82,7 @@ export class Files { request: Monite.FilesGetRequest = {}, requestOptions?: Files.RequestOptions, ): Promise> { - const { id__in: idIn } = request; + const { id__in: idIn, file_type: fileType } = request; const _queryParams: Record = {}; if (idIn != null) { if (Array.isArray(idIn)) { @@ -73,32 +92,29 @@ export class Files { } } + if (fileType != null) { + _queryParams["file_type"] = fileType; + } + + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "files", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -109,10 +125,12 @@ export class Files { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -140,59 +158,64 @@ export class Files { } /** - * @param {File | fs.ReadStream | Blob} file + * Upload files for use as: + * + * * supplementary attachments for invoices, quotes, and credit notes, + * * [entity verification documents](https://docs.monite.com/payments/onboarding/via-api/documents) for payments onboarding. + * + * Maximum file size is 15 MB. Each uploaded file is assigned a unique `id` that you can use to reference this file elsewhere. + * + * Both partner tokens and entity user tokens can be used for authentication. + * * @param {Monite.UploadFile} request * @param {Files.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.files.upload(fs.createReadStream("/path/to/your/file"), { + * import { createReadStream } from "fs"; + * await client.files.upload({ + * file: fs.createReadStream("/path/to/your/file"), * file_type: "ocr_results" * }) */ public upload( - file: File | fs.ReadStream | Blob, request: Monite.UploadFile, requestOptions?: Files.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__upload(file, request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__upload(request, requestOptions)); } private async __upload( - file: File | fs.ReadStream | Blob, request: Monite.UploadFile, requestOptions?: Files.RequestOptions, ): Promise> { const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); _request.append("file_type", request.file_type); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "files", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, + headers: _headers, + queryParameters: requestOptions?.queryParams, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -206,10 +229,12 @@ export class Files { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -237,11 +262,17 @@ export class Files { } /** + * Returns the details of an existing file. To bulk fetch multiple files by their IDs, use `GET /files?id__in=&id__in=`. + * + * Both partner tokens and entity user tokens can be used for authentication. + * * @param {string} fileId * @param {Files.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.files.getById("file_id") @@ -257,31 +288,25 @@ export class Files { fileId: string, requestOptions?: Files.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `files/${encodeURIComponent(fileId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -292,10 +317,14 @@ export class Files { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -323,11 +352,21 @@ export class Files { } /** - * @param {string} fileId + * Delete a file with the specified ID. + * + * **Note:** This endpoint does not check if the specified file is in use. Use with caution. + * + * Both partner tokens and entity user tokens can be used for authentication. + * #### Considerations for invoice attachments + * Deleting a file does not delete it from the `attachments` list of accounts receivable invoices, quotes, and credit notes because these documents contain an inline copy of all referenced resources. To delete a file from attachments, call `PATCH /receivables/{receivable_id}` and update the `attachments` list to exclude the deleted file. + * + * @param {string} fileId - ID of the file you want to delete. * @param {Files.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.files.delete("file_id") @@ -337,31 +376,25 @@ export class Files { } private async __delete(fileId: string, requestOptions?: Files.RequestOptions): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `files/${encodeURIComponent(fileId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -372,10 +405,14 @@ export class Files { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/files/client/index.ts b/src/api/resources/files/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/files/client/index.ts +++ b/src/api/resources/files/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/files/client/requests/FilesGetRequest.ts b/src/api/resources/files/client/requests/FilesGetRequest.ts index 66ec636..9963a87 100644 --- a/src/api/resources/files/client/requests/FilesGetRequest.ts +++ b/src/api/resources/files/client/requests/FilesGetRequest.ts @@ -2,10 +2,32 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as Monite from "../../../../index.js"; + /** * @example * {} */ export interface FilesGetRequest { + /** + * Return only files with specified IDs. Valid but nonexistent IDs do not raise errors but produce no results. + * + * To specify multiple IDs, repeat this parameter for each value: `id__in=&id__in=` + */ id__in?: string | string[]; + /** + * Return only files with the given purpose. Possible values: + * + * * `additional_identity_documents` and `identity_documents` - [entity verification documents](https://docs.monite.com/payments/onboarding/via-api/documents) uploaded for payments onboarding. + * * `attachments` - supplementary attachments for accounts receivable invoices, quotes, and credit notes. + * * `delivery_notes` - auto-generated PDF versions of delivery notes. + * * `einvoices_xml` - e-invoice XML generated when sending e-invoices. + * * `payables` - payables (bills) received via email or uploaded via API. + * * `receivable_signatures` - images of customer signatures provided during quote acceptance. + * * `receivables` - auto-generated PDF versions of invoices, quotes, and credit notes. + * * `zip` - data export archives created by `POST /data_exports`. + * + * Other values are unused. + */ + file_type?: Monite.AllowedFileTypes; } diff --git a/src/api/resources/files/client/requests/UploadFile.ts b/src/api/resources/files/client/requests/UploadFile.ts index acef852..fffaab0 100644 --- a/src/api/resources/files/client/requests/UploadFile.ts +++ b/src/api/resources/files/client/requests/UploadFile.ts @@ -2,14 +2,28 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; +import * as Monite from "../../../../index.js"; /** * @example * { + * file: fs.createReadStream("/path/to/your/file"), * file_type: "ocr_results" * } */ export interface UploadFile { + /** The file to upload. */ + file: core.file.Uploadable.FileLike; + /** + * The intended purpose of the file. Possible values: + * + * * `attachments` - supplemental attachments for accounts receivable invoices, quotes, and credit notes. + * * `identity_documents` - company registration documents or a person's identity documents for payments onboarding. + * * `additional_identity_documents` - documents that verify a person's address. + * + * Other enum values are not supposed to be used directly. + */ file_type: Monite.AllowedFileTypes; } diff --git a/src/api/resources/files/client/requests/index.ts b/src/api/resources/files/client/requests/index.ts index 0f18cae..f7d8388 100644 --- a/src/api/resources/files/client/requests/index.ts +++ b/src/api/resources/files/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type FilesGetRequest } from "./FilesGetRequest"; -export { type UploadFile } from "./UploadFile"; +export { type FilesGetRequest } from "./FilesGetRequest.js"; +export { type UploadFile } from "./UploadFile.js"; diff --git a/src/api/resources/files/index.ts b/src/api/resources/files/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/files/index.ts +++ b/src/api/resources/files/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/financing/client/Client.ts b/src/api/resources/financing/client/Client.ts index 3903a4d..41b0366 100644 --- a/src/api/resources/financing/client/Client.ts +++ b/src/api/resources/financing/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Financing { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Financing { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Financing { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Financing { - constructor(protected readonly _options: Financing.Options) {} + protected readonly _options: Financing.Options; + + constructor(_options: Financing.Options) { + this._options = _options; + } /** * Returns a list of invoices requested for financing @@ -46,8 +54,9 @@ export class Financing { * @param {Monite.GetFinancingInvoicesRequest} request * @param {Financing.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.financing.getFinancingInvoices() @@ -227,32 +236,25 @@ export class Financing { _queryParams["total_amount__lte"] = totalAmountLte.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "financing_invoices", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -263,10 +265,12 @@ export class Financing { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -299,8 +303,9 @@ export class Financing { * @param {Monite.FinancingPushInvoicesRequest} request * @param {Financing.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.financing.postFinancingInvoices({ @@ -321,30 +326,26 @@ export class Financing { request: Monite.FinancingPushInvoicesRequest, requestOptions?: Financing.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "financing_invoices", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -357,10 +358,12 @@ export class Financing { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -392,8 +395,9 @@ export class Financing { * * @param {Financing.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.financing.getFinancingOffers() @@ -407,31 +411,25 @@ export class Financing { private async __getFinancingOffers( requestOptions?: Financing.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "financing_offers", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -442,10 +440,12 @@ export class Financing { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -477,8 +477,9 @@ export class Financing { * * @param {Financing.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.financing.postFinancingTokens() @@ -492,31 +493,25 @@ export class Financing { private async __postFinancingTokens( requestOptions?: Financing.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "financing_tokens", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -527,10 +522,12 @@ export class Financing { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/financing/client/index.ts b/src/api/resources/financing/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/financing/client/index.ts +++ b/src/api/resources/financing/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/financing/client/requests/FinancingPushInvoicesRequest.ts b/src/api/resources/financing/client/requests/FinancingPushInvoicesRequest.ts index 90795b6..260e129 100644 --- a/src/api/resources/financing/client/requests/FinancingPushInvoicesRequest.ts +++ b/src/api/resources/financing/client/requests/FinancingPushInvoicesRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/financing/client/requests/GetFinancingInvoicesRequest.ts b/src/api/resources/financing/client/requests/GetFinancingInvoicesRequest.ts index a07879e..5152cd1 100644 --- a/src/api/resources/financing/client/requests/GetFinancingInvoicesRequest.ts +++ b/src/api/resources/financing/client/requests/GetFinancingInvoicesRequest.ts @@ -2,127 +2,73 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface GetFinancingInvoicesRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.FinancingInvoiceCursorFields; - /** - * ID of a payable or receivable invoice. - */ + /** ID of a payable or receivable invoice. */ invoice_id?: string; - /** - * List of invoice IDs. - */ + /** List of invoice IDs. */ invoice_id__in?: string | string[]; - /** - * Status of the invoice. - */ + /** Status of the invoice. */ status?: Monite.WcInvoiceStatus; - /** - * List of invoice statuses. - */ + /** List of invoice statuses. */ status__in?: Monite.WcInvoiceStatus | Monite.WcInvoiceStatus[]; - /** - * Type of the invoice. payable or receivable. - */ + /** Type of the invoice. payable or receivable. */ type?: Monite.FinancingInvoiceType; - /** - * List of invoice types. - */ + /** List of invoice types. */ type__in?: Monite.FinancingInvoiceType | Monite.FinancingInvoiceType[]; - /** - * Document ID of the invoice. - */ + /** Document ID of the invoice. */ document_id?: string; - /** - * List of document IDs. - */ + /** List of document IDs. */ document_id__in?: string | string[]; - /** - * Issue date greater than. - */ + /** Issue date greater than. */ issue_date__gt?: string; - /** - * Issue date less than. - */ + /** Issue date less than. */ issue_date__lt?: string; - /** - * Issue date greater than or equal. - */ + /** Issue date greater than or equal. */ issue_date__gte?: string; - /** - * Issue date less than or equal. - */ + /** Issue date less than or equal. */ issue_date__lte?: string; - /** - * Due date greater than. - */ + /** Due date greater than. */ due_date__gt?: string; - /** - * Due date less than. - */ + /** Due date less than. */ due_date__lt?: string; - /** - * Due date greater than or equal. - */ + /** Due date greater than or equal. */ due_date__gte?: string; - /** - * Due date less than or equal. - */ + /** Due date less than or equal. */ due_date__lte?: string; - /** - * Created date greater than. - */ + /** Created date greater than. */ created_at__gt?: string; - /** - * Created date less than. - */ + /** Created date less than. */ created_at__lt?: string; - /** - * Created date greater than or equal. - */ + /** Created date greater than or equal. */ created_at__gte?: string; - /** - * Created date less than or equal. - */ + /** Created date less than or equal. */ created_at__lte?: string; - /** - * Total amount of the invoice in minor units. - */ + /** Total amount of the invoice in minor units. */ total_amount?: number; - /** - * Total amount greater than. - */ + /** Total amount greater than. */ total_amount__gt?: number; - /** - * Total amount less than. - */ + /** Total amount less than. */ total_amount__lt?: number; - /** - * Total amount greater than or equal. - */ + /** Total amount greater than or equal. */ total_amount__gte?: number; - /** - * Total amount less than or equal. - */ + /** Total amount less than or equal. */ total_amount__lte?: number; } diff --git a/src/api/resources/financing/client/requests/index.ts b/src/api/resources/financing/client/requests/index.ts index c5d90c1..ed704b7 100644 --- a/src/api/resources/financing/client/requests/index.ts +++ b/src/api/resources/financing/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type GetFinancingInvoicesRequest } from "./GetFinancingInvoicesRequest"; -export { type FinancingPushInvoicesRequest } from "./FinancingPushInvoicesRequest"; +export { type GetFinancingInvoicesRequest } from "./GetFinancingInvoicesRequest.js"; +export { type FinancingPushInvoicesRequest } from "./FinancingPushInvoicesRequest.js"; diff --git a/src/api/resources/financing/index.ts b/src/api/resources/financing/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/financing/index.ts +++ b/src/api/resources/financing/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 4f439b9..11043bc 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -1,87 +1,92 @@ -export * as analytics from "./analytics"; -export * from "./analytics/types"; -export * as approvalPolicies from "./approvalPolicies"; -export * from "./approvalPolicies/types"; -export * as deliveryNotes from "./deliveryNotes"; -export * from "./deliveryNotes/types"; -export * as paymentRecords from "./paymentRecords"; -export * from "./paymentRecords/types"; -export * as receivables from "./receivables"; -export * from "./receivables/types"; -export * as approvalRequests from "./approvalRequests"; -export * as accessTokens from "./accessTokens"; -export * as comments from "./comments"; -export * as counterparts from "./counterparts"; -export * as counterpartEInvoicingCredentials from "./counterpartEInvoicingCredentials"; -export * as dataExports from "./dataExports"; -export * as pdfTemplates from "./pdfTemplates"; -export * as eInvoicingConnections from "./eInvoicingConnections"; -export * as entities from "./entities"; -export * as entityUsers from "./entityUsers"; -export * as events from "./events"; -export * as files from "./files"; -export * as financing from "./financing"; -export * as mailTemplates from "./mailTemplates"; -export * as mailboxDomains from "./mailboxDomains"; -export * as mailboxes from "./mailboxes"; -export * as measureUnits from "./measureUnits"; -export * as ocr from "./ocr"; -export * as overdueReminders from "./overdueReminders"; -export * as creditNotes from "./creditNotes"; -export * as purchaseOrders from "./purchaseOrders"; -export * as payables from "./payables"; -export * as paymentIntents from "./paymentIntents"; -export * as paymentLinks from "./paymentLinks"; -export * as paymentReminders from "./paymentReminders"; -export * as paymentTerms from "./paymentTerms"; -export * as products from "./products"; -export * as projects from "./projects"; -export * as recurrences from "./recurrences"; -export * as roles from "./roles"; -export * as partnerSettings from "./partnerSettings"; -export * as tags from "./tags"; -export * as textTemplates from "./textTemplates"; -export * as vatRates from "./vatRates"; -export * as webhookDeliveries from "./webhookDeliveries"; -export * as webhookSubscriptions from "./webhookSubscriptions"; -export * as accounting from "./accounting"; -export * from "./analytics/client/requests"; -export * from "./approvalPolicies/client/requests"; -export * from "./approvalRequests/client/requests"; -export * from "./accessTokens/client/requests"; -export * from "./comments/client/requests"; -export * from "./counterparts/client/requests"; -export * from "./counterpartEInvoicingCredentials/client/requests"; -export * from "./dataExports/client/requests"; -export * from "./deliveryNotes/client/requests"; -export * from "./eInvoicingConnections/client/requests"; -export * from "./entities/client/requests"; -export * from "./entityUsers/client/requests"; -export * from "./events/client/requests"; -export * from "./files/client/requests"; -export * from "./financing/client/requests"; -export * from "./mailTemplates/client/requests"; -export * from "./mailboxDomains/client/requests"; -export * from "./mailboxes/client/requests"; -export * from "./measureUnits/client/requests"; -export * from "./ocr/client/requests"; -export * from "./overdueReminders/client/requests"; -export * from "./creditNotes/client/requests"; -export * from "./purchaseOrders/client/requests"; -export * from "./payables/client/requests"; -export * from "./paymentIntents/client/requests"; -export * from "./paymentLinks/client/requests"; -export * from "./paymentRecords/client/requests"; -export * from "./paymentReminders/client/requests"; -export * from "./paymentTerms/client/requests"; -export * from "./products/client/requests"; -export * from "./projects/client/requests"; -export * from "./receivables/client/requests"; -export * from "./recurrences/client/requests"; -export * from "./roles/client/requests"; -export * from "./partnerSettings/client/requests"; -export * from "./tags/client/requests"; -export * from "./textTemplates/client/requests"; -export * from "./vatRates/client/requests"; -export * from "./webhookDeliveries/client/requests"; -export * from "./webhookSubscriptions/client/requests"; +export * as analytics from "./analytics/index.js"; +export * from "./analytics/types/index.js"; +export * as approvalPolicies from "./approvalPolicies/index.js"; +export * from "./approvalPolicies/types/index.js"; +export * as deliveryNotes from "./deliveryNotes/index.js"; +export * from "./deliveryNotes/types/index.js"; +export * as receivables from "./receivables/index.js"; +export * from "./receivables/types/index.js"; +export * as approvalRequests from "./approvalRequests/index.js"; +export * as accessTokens from "./accessTokens/index.js"; +export * as comments from "./comments/index.js"; +export * as counterparts from "./counterparts/index.js"; +export * as counterpartEInvoicingCredentials from "./counterpartEInvoicingCredentials/index.js"; +export * as customVatRates from "./customVatRates/index.js"; +export * as dataExports from "./dataExports/index.js"; +export * as pdfTemplates from "./pdfTemplates/index.js"; +export * as eInvoicingSearch from "./eInvoicingSearch/index.js"; +export * as eInvoicingConnections from "./eInvoicingConnections/index.js"; +export * as entities from "./entities/index.js"; +export * as entityUsers from "./entityUsers/index.js"; +export * as events from "./events/index.js"; +export * as files from "./files/index.js"; +export * as financing from "./financing/index.js"; +export * as mailTemplates from "./mailTemplates/index.js"; +export * as mailboxDomains from "./mailboxDomains/index.js"; +export * as mailboxes from "./mailboxes/index.js"; +export * as measureUnits from "./measureUnits/index.js"; +export * as ocr from "./ocr/index.js"; +export * as overdueReminders from "./overdueReminders/index.js"; +export * as creditNotes from "./creditNotes/index.js"; +export * as purchaseOrders from "./purchaseOrders/index.js"; +export * as payables from "./payables/index.js"; +export * as paymentIntents from "./paymentIntents/index.js"; +export * as paymentLinks from "./paymentLinks/index.js"; +export * as paymentRecords from "./paymentRecords/index.js"; +export * as paymentReminders from "./paymentReminders/index.js"; +export * as paymentTerms from "./paymentTerms/index.js"; +export * as products from "./products/index.js"; +export * as projects from "./projects/index.js"; +export * as receipts from "./receipts/index.js"; +export * as recurrences from "./recurrences/index.js"; +export * as roles from "./roles/index.js"; +export * as partnerSettings from "./partnerSettings/index.js"; +export * as tags from "./tags/index.js"; +export * as textTemplates from "./textTemplates/index.js"; +export * as vatRates from "./vatRates/index.js"; +export * as webhookDeliveries from "./webhookDeliveries/index.js"; +export * as webhookSubscriptions from "./webhookSubscriptions/index.js"; +export * as accounting from "./accounting/index.js"; +export * from "./analytics/client/requests/index.js"; +export * from "./approvalPolicies/client/requests/index.js"; +export * from "./approvalRequests/client/requests/index.js"; +export * from "./accessTokens/client/requests/index.js"; +export * from "./comments/client/requests/index.js"; +export * from "./counterparts/client/requests/index.js"; +export * from "./counterpartEInvoicingCredentials/client/requests/index.js"; +export * from "./customVatRates/client/requests/index.js"; +export * from "./dataExports/client/requests/index.js"; +export * from "./deliveryNotes/client/requests/index.js"; +export * from "./eInvoicingSearch/client/requests/index.js"; +export * from "./eInvoicingConnections/client/requests/index.js"; +export * from "./entities/client/requests/index.js"; +export * from "./entityUsers/client/requests/index.js"; +export * from "./events/client/requests/index.js"; +export * from "./files/client/requests/index.js"; +export * from "./financing/client/requests/index.js"; +export * from "./mailTemplates/client/requests/index.js"; +export * from "./mailboxDomains/client/requests/index.js"; +export * from "./mailboxes/client/requests/index.js"; +export * from "./measureUnits/client/requests/index.js"; +export * from "./ocr/client/requests/index.js"; +export * from "./overdueReminders/client/requests/index.js"; +export * from "./creditNotes/client/requests/index.js"; +export * from "./purchaseOrders/client/requests/index.js"; +export * from "./payables/client/requests/index.js"; +export * from "./paymentIntents/client/requests/index.js"; +export * from "./paymentLinks/client/requests/index.js"; +export * from "./paymentRecords/client/requests/index.js"; +export * from "./paymentReminders/client/requests/index.js"; +export * from "./paymentTerms/client/requests/index.js"; +export * from "./products/client/requests/index.js"; +export * from "./projects/client/requests/index.js"; +export * from "./receipts/client/requests/index.js"; +export * from "./receivables/client/requests/index.js"; +export * from "./recurrences/client/requests/index.js"; +export * from "./roles/client/requests/index.js"; +export * from "./partnerSettings/client/requests/index.js"; +export * from "./tags/client/requests/index.js"; +export * from "./textTemplates/client/requests/index.js"; +export * from "./vatRates/client/requests/index.js"; +export * from "./webhookDeliveries/client/requests/index.js"; +export * from "./webhookSubscriptions/client/requests/index.js"; diff --git a/src/api/resources/mailTemplates/client/Client.ts b/src/api/resources/mailTemplates/client/Client.ts index c35f145..d3612a2 100644 --- a/src/api/resources/mailTemplates/client/Client.ts +++ b/src/api/resources/mailTemplates/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace MailTemplates { export interface Options { @@ -18,6 +18,8 @@ export declare namespace MailTemplates { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace MailTemplates { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class MailTemplates { - constructor(protected readonly _options: MailTemplates.Options) {} + protected readonly _options: MailTemplates.Options; + + constructor(_options: MailTemplates.Options) { + this._options = _options; + } /** * Get all custom templates @@ -46,8 +54,9 @@ export class MailTemplates { * @param {Monite.MailTemplatesGetRequest} request * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.get() @@ -134,32 +143,25 @@ export class MailTemplates { _queryParams["name__icontains"] = nameIcontains; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mail_templates", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -173,10 +175,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -209,8 +213,9 @@ export class MailTemplates { * @param {Monite.AddCustomTemplateSchema} request * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.create({ @@ -231,30 +236,26 @@ export class MailTemplates { request: Monite.AddCustomTemplateSchema, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mail_templates", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -267,10 +268,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -303,8 +306,9 @@ export class MailTemplates { * @param {Monite.PreviewTemplateRequest} request * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.preview({ @@ -325,30 +329,26 @@ export class MailTemplates { request: Monite.PreviewTemplateRequest, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mail_templates/preview", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -361,10 +361,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -396,8 +398,9 @@ export class MailTemplates { * * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.getSystem() @@ -409,31 +412,25 @@ export class MailTemplates { private async __getSystem( requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mail_templates/system", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -444,10 +441,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -480,8 +479,9 @@ export class MailTemplates { * @param {string} templateId * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.getById("template_id") @@ -497,31 +497,25 @@ export class MailTemplates { templateId: string, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mail_templates/${encodeURIComponent(templateId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -532,10 +526,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -568,8 +564,9 @@ export class MailTemplates { * @param {string} templateId * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.deleteById("template_id") @@ -585,31 +582,25 @@ export class MailTemplates { templateId: string, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mail_templates/${encodeURIComponent(templateId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -620,10 +611,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -659,8 +652,9 @@ export class MailTemplates { * @param {Monite.UpdateCustomTemplateSchemaRequest} request * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.updateById("template_id") @@ -678,30 +672,26 @@ export class MailTemplates { request: Monite.UpdateCustomTemplateSchemaRequest = {}, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mail_templates/${encodeURIComponent(templateId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -714,10 +704,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -752,8 +744,9 @@ export class MailTemplates { * @param {string} templateId * @param {MailTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailTemplates.makeDefaultById("template_id") @@ -769,31 +762,25 @@ export class MailTemplates { templateId: string, requestOptions?: MailTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mail_templates/${encodeURIComponent(templateId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -804,10 +791,12 @@ export class MailTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/mailTemplates/client/index.ts b/src/api/resources/mailTemplates/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/mailTemplates/client/index.ts +++ b/src/api/resources/mailTemplates/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/mailTemplates/client/requests/AddCustomTemplateSchema.ts b/src/api/resources/mailTemplates/client/requests/AddCustomTemplateSchema.ts index 3fa01f5..54cc0cc 100644 --- a/src/api/resources/mailTemplates/client/requests/AddCustomTemplateSchema.ts +++ b/src/api/resources/mailTemplates/client/requests/AddCustomTemplateSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/mailTemplates/client/requests/MailTemplatesGetRequest.ts b/src/api/resources/mailTemplates/client/requests/MailTemplatesGetRequest.ts index 20c1efc..37e8ca6 100644 --- a/src/api/resources/mailTemplates/client/requests/MailTemplatesGetRequest.ts +++ b/src/api/resources/mailTemplates/client/requests/MailTemplatesGetRequest.ts @@ -2,28 +2,20 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface MailTemplatesGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** Max is 100 */ limit?: number; - /** - * A token, obtained from previous page. Prior over other filters - */ + /** A token, obtained from previous page. Prior over other filters */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CustomTemplatesCursorFields; type?: Monite.DocumentObjectTypeRequestEnum; type__in?: Monite.DocumentObjectTypeRequestEnum | Monite.DocumentObjectTypeRequestEnum[]; diff --git a/src/api/resources/mailTemplates/client/requests/PreviewTemplateRequest.ts b/src/api/resources/mailTemplates/client/requests/PreviewTemplateRequest.ts index 17308d5..e2bd41c 100644 --- a/src/api/resources/mailTemplates/client/requests/PreviewTemplateRequest.ts +++ b/src/api/resources/mailTemplates/client/requests/PreviewTemplateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/mailTemplates/client/requests/UpdateCustomTemplateSchemaRequest.ts b/src/api/resources/mailTemplates/client/requests/UpdateCustomTemplateSchemaRequest.ts index fcc9742..af57034 100644 --- a/src/api/resources/mailTemplates/client/requests/UpdateCustomTemplateSchemaRequest.ts +++ b/src/api/resources/mailTemplates/client/requests/UpdateCustomTemplateSchemaRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/mailTemplates/client/requests/index.ts b/src/api/resources/mailTemplates/client/requests/index.ts index e1ca7ec..9085dba 100644 --- a/src/api/resources/mailTemplates/client/requests/index.ts +++ b/src/api/resources/mailTemplates/client/requests/index.ts @@ -1,4 +1,4 @@ -export { type MailTemplatesGetRequest } from "./MailTemplatesGetRequest"; -export { type AddCustomTemplateSchema } from "./AddCustomTemplateSchema"; -export { type PreviewTemplateRequest } from "./PreviewTemplateRequest"; -export { type UpdateCustomTemplateSchemaRequest } from "./UpdateCustomTemplateSchemaRequest"; +export { type MailTemplatesGetRequest } from "./MailTemplatesGetRequest.js"; +export { type AddCustomTemplateSchema } from "./AddCustomTemplateSchema.js"; +export { type PreviewTemplateRequest } from "./PreviewTemplateRequest.js"; +export { type UpdateCustomTemplateSchemaRequest } from "./UpdateCustomTemplateSchemaRequest.js"; diff --git a/src/api/resources/mailTemplates/index.ts b/src/api/resources/mailTemplates/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/mailTemplates/index.ts +++ b/src/api/resources/mailTemplates/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/mailboxDomains/client/Client.ts b/src/api/resources/mailboxDomains/client/Client.ts index 13fc186..85ae661 100644 --- a/src/api/resources/mailboxDomains/client/Client.ts +++ b/src/api/resources/mailboxDomains/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace MailboxDomains { export interface Options { @@ -18,6 +18,8 @@ export declare namespace MailboxDomains { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace MailboxDomains { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class MailboxDomains { - constructor(protected readonly _options: MailboxDomains.Options) {} + protected readonly _options: MailboxDomains.Options; + + constructor(_options: MailboxDomains.Options) { + this._options = _options; + } /** * Get all domains owned by partner_id @@ -48,7 +56,7 @@ export class MailboxDomains { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxDomains.get() @@ -60,31 +68,25 @@ export class MailboxDomains { private async __get( requestOptions?: MailboxDomains.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mailbox_domains", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,8 +103,8 @@ export class MailboxDomains { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -140,7 +142,7 @@ export class MailboxDomains { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxDomains.create({ @@ -158,30 +160,26 @@ export class MailboxDomains { request: Monite.DomainRequest, requestOptions?: MailboxDomains.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mailbox_domains", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -204,8 +202,8 @@ export class MailboxDomains { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -242,7 +240,7 @@ export class MailboxDomains { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxDomains.deleteById("domain_id") @@ -258,31 +256,25 @@ export class MailboxDomains { domainId: string, requestOptions?: MailboxDomains.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mailbox_domains/${encodeURIComponent(domainId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -301,8 +293,8 @@ export class MailboxDomains { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -343,7 +335,7 @@ export class MailboxDomains { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxDomains.verifyById("domain_id") @@ -359,31 +351,25 @@ export class MailboxDomains { domainId: string, requestOptions?: MailboxDomains.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mailbox_domains/${encodeURIComponent(domainId)}/verify`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -406,8 +392,8 @@ export class MailboxDomains { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/mailboxDomains/client/index.ts b/src/api/resources/mailboxDomains/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/mailboxDomains/client/index.ts +++ b/src/api/resources/mailboxDomains/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/mailboxDomains/client/requests/index.ts b/src/api/resources/mailboxDomains/client/requests/index.ts index 6a6caec..8cbece4 100644 --- a/src/api/resources/mailboxDomains/client/requests/index.ts +++ b/src/api/resources/mailboxDomains/client/requests/index.ts @@ -1 +1 @@ -export { type DomainRequest } from "./DomainRequest"; +export { type DomainRequest } from "./DomainRequest.js"; diff --git a/src/api/resources/mailboxDomains/index.ts b/src/api/resources/mailboxDomains/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/mailboxDomains/index.ts +++ b/src/api/resources/mailboxDomains/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/mailboxes/client/Client.ts b/src/api/resources/mailboxes/client/Client.ts index e7af79b..e4a1c1a 100644 --- a/src/api/resources/mailboxes/client/Client.ts +++ b/src/api/resources/mailboxes/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Mailboxes { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Mailboxes { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Mailboxes { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Mailboxes { - constructor(protected readonly _options: Mailboxes.Options) {} + protected readonly _options: Mailboxes.Options; + + constructor(_options: Mailboxes.Options) { + this._options = _options; + } /** * Get all mailboxes owned by Entity @@ -48,7 +56,7 @@ export class Mailboxes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxes.get() @@ -60,31 +68,25 @@ export class Mailboxes { private async __get( requestOptions?: Mailboxes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mailboxes", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,8 +103,8 @@ export class Mailboxes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -139,7 +141,7 @@ export class Mailboxes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxes.create({ @@ -159,32 +161,28 @@ export class Mailboxes { request: Monite.MailboxDomainRequest, requestOptions?: Mailboxes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mailboxes", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", - body: { ...request, related_object_type: "payable" }, + body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -203,8 +201,8 @@ export class Mailboxes { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -240,7 +238,7 @@ export class Mailboxes { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxes.search({ @@ -258,30 +256,26 @@ export class Mailboxes { request: Monite.MailboxMultipleEntitiesRequest, requestOptions?: Mailboxes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "mailboxes/search", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -300,8 +294,8 @@ export class Mailboxes { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -338,7 +332,7 @@ export class Mailboxes { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.mailboxes.deleteById("mailbox_id") @@ -351,31 +345,25 @@ export class Mailboxes { mailboxId: string, requestOptions?: Mailboxes.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `mailboxes/${encodeURIComponent(mailboxId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -394,8 +382,8 @@ export class Mailboxes { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/mailboxes/client/index.ts b/src/api/resources/mailboxes/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/mailboxes/client/index.ts +++ b/src/api/resources/mailboxes/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/mailboxes/client/requests/MailboxDomainRequest.ts b/src/api/resources/mailboxes/client/requests/MailboxDomainRequest.ts index 03304fe..ee81071 100644 --- a/src/api/resources/mailboxes/client/requests/MailboxDomainRequest.ts +++ b/src/api/resources/mailboxes/client/requests/MailboxDomainRequest.ts @@ -2,6 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as Monite from "../../../../index.js"; + /** * @example * { @@ -13,4 +15,6 @@ export interface MailboxDomainRequest { mailbox_domain_id: string; mailbox_name: string; + /** Related object type: payable and so on */ + related_object_type: Monite.MailboxObjectTypeEnum; } diff --git a/src/api/resources/mailboxes/client/requests/index.ts b/src/api/resources/mailboxes/client/requests/index.ts index e68e9e3..01f6872 100644 --- a/src/api/resources/mailboxes/client/requests/index.ts +++ b/src/api/resources/mailboxes/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type MailboxDomainRequest } from "./MailboxDomainRequest"; -export { type MailboxMultipleEntitiesRequest } from "./MailboxMultipleEntitiesRequest"; +export { type MailboxDomainRequest } from "./MailboxDomainRequest.js"; +export { type MailboxMultipleEntitiesRequest } from "./MailboxMultipleEntitiesRequest.js"; diff --git a/src/api/resources/mailboxes/index.ts b/src/api/resources/mailboxes/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/mailboxes/index.ts +++ b/src/api/resources/mailboxes/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/measureUnits/client/Client.ts b/src/api/resources/measureUnits/client/Client.ts index 65ea522..2d4e1ed 100644 --- a/src/api/resources/measureUnits/client/Client.ts +++ b/src/api/resources/measureUnits/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace MeasureUnits { export interface Options { @@ -18,6 +18,8 @@ export declare namespace MeasureUnits { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace MeasureUnits { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class MeasureUnits { - constructor(protected readonly _options: MeasureUnits.Options) {} + protected readonly _options: MeasureUnits.Options; + + constructor(_options: MeasureUnits.Options) { + this._options = _options; + } /** * @param {MeasureUnits.RequestOptions} requestOptions - Request-specific configuration. @@ -47,7 +55,7 @@ export class MeasureUnits { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.measureUnits.get() @@ -59,31 +67,25 @@ export class MeasureUnits { private async __get( requestOptions?: MeasureUnits.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "measure_units", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -102,8 +104,8 @@ export class MeasureUnits { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -138,7 +140,7 @@ export class MeasureUnits { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.measureUnits.create({ @@ -156,30 +158,26 @@ export class MeasureUnits { request: Monite.UnitRequest, requestOptions?: MeasureUnits.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "measure_units", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -200,8 +198,8 @@ export class MeasureUnits { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -237,7 +235,7 @@ export class MeasureUnits { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.measureUnits.getById("unit_id") @@ -253,31 +251,25 @@ export class MeasureUnits { unitId: string, requestOptions?: MeasureUnits.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `measure_units/${encodeURIComponent(unitId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -298,8 +290,8 @@ export class MeasureUnits { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -335,7 +327,7 @@ export class MeasureUnits { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.measureUnits.deleteById("unit_id") @@ -348,31 +340,25 @@ export class MeasureUnits { unitId: string, requestOptions?: MeasureUnits.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `measure_units/${encodeURIComponent(unitId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -393,8 +379,8 @@ export class MeasureUnits { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -431,7 +417,7 @@ export class MeasureUnits { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.measureUnits.updateById("unit_id") @@ -449,30 +435,26 @@ export class MeasureUnits { request: Monite.UnitUpdate = {}, requestOptions?: MeasureUnits.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `measure_units/${encodeURIComponent(unitId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -495,8 +477,8 @@ export class MeasureUnits { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/measureUnits/client/index.ts b/src/api/resources/measureUnits/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/measureUnits/client/index.ts +++ b/src/api/resources/measureUnits/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/measureUnits/client/requests/index.ts b/src/api/resources/measureUnits/client/requests/index.ts index 0159256..356f823 100644 --- a/src/api/resources/measureUnits/client/requests/index.ts +++ b/src/api/resources/measureUnits/client/requests/index.ts @@ -1 +1 @@ -export { type UnitUpdate } from "./UnitUpdate"; +export { type UnitUpdate } from "./UnitUpdate.js"; diff --git a/src/api/resources/measureUnits/index.ts b/src/api/resources/measureUnits/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/measureUnits/index.ts +++ b/src/api/resources/measureUnits/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/ocr/client/Client.ts b/src/api/resources/ocr/client/Client.ts index 8985881..0081eb9 100644 --- a/src/api/resources/ocr/client/Client.ts +++ b/src/api/resources/ocr/client/Client.ts @@ -2,13 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; import * as fs from "fs"; -import { Blob } from "buffer"; export declare namespace Ocr { export interface Options { @@ -20,6 +19,8 @@ export declare namespace Ocr { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -34,21 +35,28 @@ export declare namespace Ocr { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Ocr { - constructor(protected readonly _options: Ocr.Options) {} + protected readonly _options: Ocr.Options; + + constructor(_options: Ocr.Options) { + this._options = _options; + } /** * @param {Monite.GetOcrTasksRequest} request * @param {Ocr.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.ocr.getOcrTasks() @@ -126,32 +134,25 @@ export class Ocr { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "ocr_tasks", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -162,12 +163,14 @@ export class Ocr { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -199,12 +202,13 @@ export class Ocr { * @param {Ocr.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ContentTooLargeError} * @throws {@link Monite.UnsupportedMediaTypeError} * @throws {@link Monite.MisdirectedRequestError} * @throws {@link Monite.UnprocessableEntityError} * @throws {@link Monite.FailedDependencyError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.ocr.postOcrTasks({ @@ -222,30 +226,26 @@ export class Ocr { request: Monite.CreateOcrRequestPayload, requestOptions?: Ocr.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "ocr_tasks", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -260,6 +260,8 @@ export class Ocr { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 413: throw new Monite.ContentTooLargeError(_response.error.body as unknown, _response.rawResponse); case 415: @@ -270,8 +272,8 @@ export class Ocr { throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); case 424: throw new Monite.FailedDependencyError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -299,29 +301,30 @@ export class Ocr { } /** - * @param {File | fs.ReadStream | Blob} file * @param {Monite.OcrFileUpload} request * @param {Ocr.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ContentTooLargeError} * @throws {@link Monite.UnsupportedMediaTypeError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.ocr.postOcrTasksUploadFromFile(fs.createReadStream("/path/to/your/file"), {}) + * import { createReadStream } from "fs"; + * await client.ocr.postOcrTasksUploadFromFile({ + * file: fs.createReadStream("/path/to/your/file") + * }) */ public postOcrTasksUploadFromFile( - file: File | fs.ReadStream | Blob, request: Monite.OcrFileUpload, requestOptions?: Ocr.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__postOcrTasksUploadFromFile(file, request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__postOcrTasksUploadFromFile(request, requestOptions)); } private async __postOcrTasksUploadFromFile( - file: File | fs.ReadStream | Blob, request: Monite.OcrFileUpload, requestOptions?: Ocr.RequestOptions, ): Promise> { @@ -331,33 +334,28 @@ export class Ocr { } const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "ocr_tasks/upload_from_file", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, - queryParameters: _queryParams, + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -373,14 +371,16 @@ export class Ocr { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 413: throw new Monite.ContentTooLargeError(_response.error.body as unknown, _response.rawResponse); case 415: throw new Monite.UnsupportedMediaTypeError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -411,9 +411,10 @@ export class Ocr { * @param {string} taskId * @param {Ocr.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.ocr.getOcrTasksId("task_id") @@ -429,31 +430,25 @@ export class Ocr { taskId: string, requestOptions?: Ocr.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `ocr_tasks/${encodeURIComponent(taskId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -464,12 +459,14 @@ export class Ocr { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/ocr/client/index.ts b/src/api/resources/ocr/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/ocr/client/index.ts +++ b/src/api/resources/ocr/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/ocr/client/requests/CreateOcrRequestPayload.ts b/src/api/resources/ocr/client/requests/CreateOcrRequestPayload.ts index 1f2f4c6..0ab5b9f 100644 --- a/src/api/resources/ocr/client/requests/CreateOcrRequestPayload.ts +++ b/src/api/resources/ocr/client/requests/CreateOcrRequestPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/ocr/client/requests/GetOcrTasksRequest.ts b/src/api/resources/ocr/client/requests/GetOcrTasksRequest.ts index 1342741..0a794a4 100644 --- a/src/api/resources/ocr/client/requests/GetOcrTasksRequest.ts +++ b/src/api/resources/ocr/client/requests/GetOcrTasksRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface GetOcrTasksRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,33 +19,19 @@ export interface GetOcrTasksRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.CursorFields; - /** - * Return only ocr tasks created after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. - */ + /** Return only ocr tasks created after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. */ created_at__gt?: string; - /** - * Return only ocr tasks created in Monite before the specified date and time. - */ + /** Return only ocr tasks created in Monite before the specified date and time. */ created_at__lt?: string; - /** - * Return only ocr tasks created on or after the specified date and time. - */ + /** Return only ocr tasks created on or after the specified date and time. */ created_at__gte?: string; - /** - * Return only ocr tasks created before or on the specified date and time. - */ + /** Return only ocr tasks created before or on the specified date and time. */ created_at__lte?: string; - /** - * Return only ocr tasks that have the specified status. - */ + /** Return only ocr tasks that have the specified status. */ status?: Monite.OcrTaskStatus; - /** - * Return only OCR tasks related to documents of a specific type. - */ + /** Return only OCR tasks related to documents of a specific type. */ document_type?: Monite.OcrDocumentTypeEnum; /** * Return only ocr tasks with specified IDs. Valid but nonexistent IDs do not raise errors but produce no results. diff --git a/src/api/resources/ocr/client/requests/OcrFileUpload.ts b/src/api/resources/ocr/client/requests/OcrFileUpload.ts index f18df1c..7442ca2 100644 --- a/src/api/resources/ocr/client/requests/OcrFileUpload.ts +++ b/src/api/resources/ocr/client/requests/OcrFileUpload.ts @@ -2,12 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as fs from "fs"; +import * as Monite from "../../../../index.js"; +import * as core from "../../../../../core/index.js"; /** * @example - * {} + * { + * file: fs.createReadStream("/path/to/your/file") + * } */ export interface OcrFileUpload { document_type?: Monite.OcrDocumentTypeEnum; + file: core.file.Uploadable.FileLike; } diff --git a/src/api/resources/ocr/client/requests/index.ts b/src/api/resources/ocr/client/requests/index.ts index ec49e80..52a7ef8 100644 --- a/src/api/resources/ocr/client/requests/index.ts +++ b/src/api/resources/ocr/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type GetOcrTasksRequest } from "./GetOcrTasksRequest"; -export { type CreateOcrRequestPayload } from "./CreateOcrRequestPayload"; -export { type OcrFileUpload } from "./OcrFileUpload"; +export { type GetOcrTasksRequest } from "./GetOcrTasksRequest.js"; +export { type CreateOcrRequestPayload } from "./CreateOcrRequestPayload.js"; +export { type OcrFileUpload } from "./OcrFileUpload.js"; diff --git a/src/api/resources/ocr/index.ts b/src/api/resources/ocr/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/ocr/index.ts +++ b/src/api/resources/ocr/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/overdueReminders/client/Client.ts b/src/api/resources/overdueReminders/client/Client.ts index 36d7fcd..fc69e2f 100644 --- a/src/api/resources/overdueReminders/client/Client.ts +++ b/src/api/resources/overdueReminders/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace OverdueReminders { export interface Options { @@ -18,6 +18,8 @@ export declare namespace OverdueReminders { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace OverdueReminders { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class OverdueReminders { - constructor(protected readonly _options: OverdueReminders.Options) {} + protected readonly _options: OverdueReminders.Options; + + constructor(_options: OverdueReminders.Options) { + this._options = _options; + } /** * @param {OverdueReminders.RequestOptions} requestOptions - Request-specific configuration. @@ -46,7 +54,7 @@ export class OverdueReminders { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.overdueReminders.get() @@ -60,31 +68,25 @@ export class OverdueReminders { private async __get( requestOptions?: OverdueReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "overdue_reminders", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,8 +103,8 @@ export class OverdueReminders { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -137,7 +139,7 @@ export class OverdueReminders { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.overdueReminders.create({ @@ -155,30 +157,26 @@ export class OverdueReminders { request: Monite.OverdueReminderRequest, requestOptions?: OverdueReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "overdue_reminders", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -199,8 +197,8 @@ export class OverdueReminders { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -235,7 +233,7 @@ export class OverdueReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.overdueReminders.getById("overdue_reminder_id") @@ -251,31 +249,25 @@ export class OverdueReminders { overdueReminderId: string, requestOptions?: OverdueReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `overdue_reminders/${encodeURIComponent(overdueReminderId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -294,8 +286,8 @@ export class OverdueReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -333,7 +325,7 @@ export class OverdueReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.overdueReminders.deleteById("overdue_reminder_id") @@ -349,31 +341,25 @@ export class OverdueReminders { overdueReminderId: string, requestOptions?: OverdueReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `overdue_reminders/${encodeURIComponent(overdueReminderId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -394,8 +380,8 @@ export class OverdueReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -434,7 +420,7 @@ export class OverdueReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.overdueReminders.updateById("overdue_reminder_id") @@ -452,30 +438,26 @@ export class OverdueReminders { request: Monite.OverdueReminderUpdateRequest = {}, requestOptions?: OverdueReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `overdue_reminders/${encodeURIComponent(overdueReminderId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -498,8 +480,8 @@ export class OverdueReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/overdueReminders/client/index.ts b/src/api/resources/overdueReminders/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/overdueReminders/client/index.ts +++ b/src/api/resources/overdueReminders/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/overdueReminders/client/requests/OverdueReminderRequest.ts b/src/api/resources/overdueReminders/client/requests/OverdueReminderRequest.ts index 9089364..f691dc5 100644 --- a/src/api/resources/overdueReminders/client/requests/OverdueReminderRequest.ts +++ b/src/api/resources/overdueReminders/client/requests/OverdueReminderRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/overdueReminders/client/requests/OverdueReminderUpdateRequest.ts b/src/api/resources/overdueReminders/client/requests/OverdueReminderUpdateRequest.ts index e3f9577..aa07ebf 100644 --- a/src/api/resources/overdueReminders/client/requests/OverdueReminderUpdateRequest.ts +++ b/src/api/resources/overdueReminders/client/requests/OverdueReminderUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/overdueReminders/client/requests/index.ts b/src/api/resources/overdueReminders/client/requests/index.ts index 7f92a07..e2e1823 100644 --- a/src/api/resources/overdueReminders/client/requests/index.ts +++ b/src/api/resources/overdueReminders/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type OverdueReminderRequest } from "./OverdueReminderRequest"; -export { type OverdueReminderUpdateRequest } from "./OverdueReminderUpdateRequest"; +export { type OverdueReminderRequest } from "./OverdueReminderRequest.js"; +export { type OverdueReminderUpdateRequest } from "./OverdueReminderUpdateRequest.js"; diff --git a/src/api/resources/overdueReminders/index.ts b/src/api/resources/overdueReminders/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/overdueReminders/index.ts +++ b/src/api/resources/overdueReminders/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/partnerSettings/client/Client.ts b/src/api/resources/partnerSettings/client/Client.ts index d78ae19..d51379a 100644 --- a/src/api/resources/partnerSettings/client/Client.ts +++ b/src/api/resources/partnerSettings/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PartnerSettings { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PartnerSettings { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,22 +34,35 @@ export declare namespace PartnerSettings { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PartnerSettings { - constructor(protected readonly _options: PartnerSettings.Options) {} + protected readonly _options: PartnerSettings.Options; + + constructor(_options: PartnerSettings.Options) { + this._options = _options; + } /** - * Retrieve all settings for this partner. + * Partner-level settings apply to all entities of that partner. + * + * See also: + * + * * [Get entity settings](https://docs.monite.com/api/entities/get-entities-id-settings) * * @param {PartnerSettings.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.partnerSettings.get() @@ -61,31 +76,25 @@ export class PartnerSettings { private async __get( requestOptions?: PartnerSettings.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "settings", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,10 +110,16 @@ export class PartnerSettings { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -132,14 +147,21 @@ export class PartnerSettings { } /** - * Change the specified fields with the provided values. + * Partner-level settings apply to all entities of that partner. + * + * See also: + * + * * [Update entity settings](https://docs.monite.com/api/entities/patch-entities-id-settings) * * @param {Monite.PartnerProjectSettingsPayloadInput} request * @param {PartnerSettings.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.partnerSettings.update() @@ -155,30 +177,26 @@ export class PartnerSettings { request: Monite.PartnerProjectSettingsPayloadInput = {}, requestOptions?: PartnerSettings.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "settings", ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -196,10 +214,16 @@ export class PartnerSettings { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/partnerSettings/client/index.ts b/src/api/resources/partnerSettings/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/partnerSettings/client/index.ts +++ b/src/api/resources/partnerSettings/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/partnerSettings/client/requests/PartnerProjectSettingsPayloadInput.ts b/src/api/resources/partnerSettings/client/requests/PartnerProjectSettingsPayloadInput.ts index c095d8a..cbd18bd 100644 --- a/src/api/resources/partnerSettings/client/requests/PartnerProjectSettingsPayloadInput.ts +++ b/src/api/resources/partnerSettings/client/requests/PartnerProjectSettingsPayloadInput.ts @@ -2,30 +2,36 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PartnerProjectSettingsPayloadInput { + /** Default API version for partner. */ + api_version?: Monite.ApiVersion; + /** Unused. To specify commercial conditions for invoices and quotes, use the `commercial_condition_description` field in those documents. */ + commercial_conditions?: string[]; /** Custom currency exchange rates. */ currency?: Monite.CurrencySettingsInput; - /** Settings for the payables module. */ - payable?: Monite.PayableSettings; - /** Settings for the receivables module. */ - receivable?: Monite.ReceivableSettings; - /** Settings for email and mailboxes. */ - mail?: Monite.MailSettings; - /** Commercial conditions for receivables. */ - commercial_conditions?: string[]; - /** Measurement units. */ - units?: Monite.Unit[]; - website?: string; /** A default role to provision upon new entity creation. */ default_role?: Record; + /** + * Settings for outgoing email. Used by: + * + * * accounts receivable emails, for example, emails sent by `POST /recevables/{receivable_id}/send`, + * * accounts payable approval notifications. + */ + mail?: Monite.MailSettings; + /** Settings for accounts payable. */ + payable?: Monite.PayableSettings; /** Settings for the payments module. */ payments?: Monite.PaymentsSettingsInput; - /** Default API version for partner. */ - api_version?: Monite.ApiVersion; + /** Settings for accounts receivable. */ + receivable?: Monite.ReceivableSettings; + /** Unused. To manage the [measure units](https://docs.monite.com/accounts-receivable/products#manage-measure-units) for your entities, use the `/measure_units` endpoints. */ + units?: Monite.Unit[]; + /** The URL of the partner's website. Must be an HTTPS URL. Required if the partner's entities use [payment links](https://docs.monite.com/payments/payment-links). The "Powered by" badge in the payment page footer will link to this website. */ + website?: string; } diff --git a/src/api/resources/partnerSettings/client/requests/index.ts b/src/api/resources/partnerSettings/client/requests/index.ts index 9bffb12..e934bea 100644 --- a/src/api/resources/partnerSettings/client/requests/index.ts +++ b/src/api/resources/partnerSettings/client/requests/index.ts @@ -1 +1 @@ -export { type PartnerProjectSettingsPayloadInput } from "./PartnerProjectSettingsPayloadInput"; +export { type PartnerProjectSettingsPayloadInput } from "./PartnerProjectSettingsPayloadInput.js"; diff --git a/src/api/resources/partnerSettings/index.ts b/src/api/resources/partnerSettings/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/partnerSettings/index.ts +++ b/src/api/resources/partnerSettings/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/payables/client/Client.ts b/src/api/resources/payables/client/Client.ts index e907398..5be627c 100644 --- a/src/api/resources/payables/client/Client.ts +++ b/src/api/resources/payables/client/Client.ts @@ -2,14 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; import * as fs from "fs"; -import { Blob } from "buffer"; -import { LineItems } from "../resources/lineItems/client/Client"; +import { LineItems } from "../resources/lineItems/client/Client.js"; export declare namespace Payables { export interface Options { @@ -21,6 +20,8 @@ export declare namespace Payables { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -35,15 +36,20 @@ export declare namespace Payables { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Payables { + protected readonly _options: Payables.Options; protected _lineItems: LineItems | undefined; - constructor(protected readonly _options: Payables.Options) {} + constructor(_options: Payables.Options) { + this._options = _options; + } public get lineItems(): LineItems { return (this._lineItems ??= new LineItems(this._options)); @@ -91,7 +97,7 @@ export class Payables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.get() @@ -157,6 +163,7 @@ export class Payables { project_id__in: projectIdIn, tag_ids: tagIds, tag_ids__not_in: tagIdsNotIn, + has_tags: hasTags, origin, has_file: hasFile, } = request; @@ -377,6 +384,10 @@ export class Payables { } } + if (hasTags != null) { + _queryParams["has_tags"] = hasTags.toString(); + } + if (origin != null) { _queryParams["origin"] = origin; } @@ -385,32 +396,25 @@ export class Payables { _queryParams["has_file"] = hasFile.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -431,8 +435,8 @@ export class Payables { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -475,7 +479,7 @@ export class Payables { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.create() @@ -491,30 +495,26 @@ export class Payables { request: Monite.PayableUploadWithDataSchema = {}, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -535,8 +535,8 @@ export class Payables { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -574,7 +574,7 @@ export class Payables { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.getAnalytics() @@ -636,6 +636,7 @@ export class Payables { project_id__in: projectIdIn, tag_ids: tagIds, tag_ids__not_in: tagIdsNotIn, + has_tags: hasTags, origin, has_file: hasFile, } = request; @@ -840,6 +841,10 @@ export class Payables { } } + if (hasTags != null) { + _queryParams["has_tags"] = hasTags.toString(); + } + if (origin != null) { _queryParams["origin"] = origin; } @@ -848,32 +853,25 @@ export class Payables { _queryParams["has_file"] = hasFile.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/analytics", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -890,8 +888,8 @@ export class Payables { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -919,9 +917,9 @@ export class Payables { } /** - * Upload an incoming invoice (payable) in PDF, PNG, JPEG, or TIFF format and scan its contents. The maximum file size is 10MB. + * Upload an incoming invoice (payable) in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB. * - * @param {File | fs.ReadStream | Blob} file + * @param {Monite.PayableUploadFile} request * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} @@ -929,49 +927,48 @@ export class Payables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.payables.uploadFromFile(fs.createReadStream("/path/to/your/file")) + * import { createReadStream } from "fs"; + * await client.payables.uploadFromFile({ + * file: fs.createReadStream("/path/to/your/file") + * }) */ public uploadFromFile( - file: File | fs.ReadStream | Blob, + request: Monite.PayableUploadFile, requestOptions?: Payables.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__uploadFromFile(file, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__uploadFromFile(request, requestOptions)); } private async __uploadFromFile( - file: File | fs.ReadStream | Blob, + request: Monite.PayableUploadFile, requestOptions?: Payables.RequestOptions, ): Promise> { const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/upload_from_file", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, + headers: _headers, + queryParameters: requestOptions?.queryParams, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -995,8 +992,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1032,7 +1029,7 @@ export class Payables { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.getValidations() @@ -1046,31 +1043,25 @@ export class Payables { private async __getValidations( requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/validations", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1089,8 +1080,8 @@ export class Payables { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1127,7 +1118,7 @@ export class Payables { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.updateValidations({ @@ -1145,30 +1136,26 @@ export class Payables { request: Monite.PayableValidationsUpdateRequest, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/validations", ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1189,8 +1176,8 @@ export class Payables { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1226,7 +1213,7 @@ export class Payables { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.resetValidations() @@ -1240,31 +1227,25 @@ export class Payables { private async __resetValidations( requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/validations/reset", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1283,8 +1264,8 @@ export class Payables { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1312,13 +1293,14 @@ export class Payables { } /** - * Get a list of placeholders allowed to insert into an email template for customization + * Returns a list of placeholders that can be used to personalize email templates related to payables. These include payables attributes such as `currency`, `customer_name`, `document_id`, `due_date`, `invoice_id`, `total_amount`, and `uploaded_username`. * * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.getVariables() @@ -1332,31 +1314,25 @@ export class Payables { private async __getVariables( requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payables/variables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1370,12 +1346,14 @@ export class Payables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1413,7 +1391,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.getById("payable_id") @@ -1429,31 +1407,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1474,8 +1446,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1513,7 +1485,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.deleteById("payable_id") @@ -1526,31 +1498,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1571,8 +1537,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1607,11 +1573,12 @@ export class Payables { * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.updateById("payable_id") @@ -1629,30 +1596,26 @@ export class Payables { request: Monite.PayableUpdateSchema = {}, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1667,6 +1630,8 @@ export class Payables { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -1675,8 +1640,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1715,7 +1680,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.approvePaymentById("payable_id") @@ -1731,31 +1696,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/approve_payment_operation`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1778,8 +1737,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1811,60 +1770,60 @@ export class Payables { /** * Attach file to payable without existing attachment. * - * @param {File | fs.ReadStream | Blob} file * @param {string} payableId + * @param {Monite.PayableAttachFile} request * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example - * await client.payables.attachFileById(fs.createReadStream("/path/to/your/file"), "payable_id") + * import { createReadStream } from "fs"; + * await client.payables.attachFileById("payable_id", { + * file: fs.createReadStream("/path/to/your/file") + * }) */ public attachFileById( - file: File | fs.ReadStream | Blob, payableId: string, + request: Monite.PayableAttachFile, requestOptions?: Payables.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__attachFileById(file, payableId, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__attachFileById(payableId, request, requestOptions)); } private async __attachFileById( - file: File | fs.ReadStream | Blob, payableId: string, + request: Monite.PayableAttachFile, requestOptions?: Payables.RequestOptions, ): Promise> { const _request = await core.newFormData(); - await _request.appendFile("file", file); + await _request.appendFile("file", request.file); const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/attach_file`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ..._maybeEncodedRequest.headers, - ...requestOptions?.headers, - }, + headers: _headers, + queryParameters: requestOptions?.queryParams, requestType: "file", duplex: _maybeEncodedRequest.duplex, body: _maybeEncodedRequest.body, @@ -1880,6 +1839,8 @@ export class Payables { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -1888,8 +1849,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1930,7 +1891,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.cancelById("payable_id") @@ -1946,31 +1907,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1993,8 +1948,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2035,7 +1990,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.postPayablesIdCancelOcr("payable_id") @@ -2051,31 +2006,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/cancel_ocr`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2098,8 +2047,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2128,6 +2077,169 @@ export class Payables { } } + /** + * Returns a chronological list of events related to the specified payable. This includes changes in status, updates to data, comments, and actions taken by users or automation rules. + * + * @param {string} payableId - The unique identifier of the payable whose history you want to retrieve. + * @param {Monite.GetPayablesIdHistoryRequest} request + * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.payables.getPayablesIdHistory("payable_id") + */ + public getPayablesIdHistory( + payableId: string, + request: Monite.GetPayablesIdHistoryRequest = {}, + requestOptions?: Payables.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getPayablesIdHistory(payableId, request, requestOptions)); + } + + private async __getPayablesIdHistory( + payableId: string, + request: Monite.GetPayablesIdHistoryRequest = {}, + requestOptions?: Payables.RequestOptions, + ): Promise> { + const { + order, + limit, + pagination_token: paginationToken, + sort, + event_type__in: eventTypeIn, + entity_user_id__in: entityUserIdIn, + timestamp__gt: timestampGt, + timestamp__lt: timestampLt, + timestamp__gte: timestampGte, + timestamp__lte: timestampLte, + } = request; + const _queryParams: Record = {}; + if (order != null) { + _queryParams["order"] = order; + } + + if (limit != null) { + _queryParams["limit"] = limit.toString(); + } + + if (paginationToken != null) { + _queryParams["pagination_token"] = paginationToken; + } + + if (sort != null) { + _queryParams["sort"] = sort; + } + + if (eventTypeIn != null) { + if (Array.isArray(eventTypeIn)) { + _queryParams["event_type__in"] = eventTypeIn.map((item) => item); + } else { + _queryParams["event_type__in"] = eventTypeIn; + } + } + + if (entityUserIdIn != null) { + if (Array.isArray(entityUserIdIn)) { + _queryParams["entity_user_id__in"] = entityUserIdIn.map((item) => item); + } else { + _queryParams["entity_user_id__in"] = entityUserIdIn; + } + } + + if (timestampGt != null) { + _queryParams["timestamp__gt"] = timestampGt; + } + + if (timestampLt != null) { + _queryParams["timestamp__lt"] = timestampLt; + } + + if (timestampGte != null) { + _queryParams["timestamp__gte"] = timestampGte; + } + + if (timestampLte != null) { + _queryParams["timestamp__lte"] = timestampLte; + } + + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `payables/${encodeURIComponent(payableId)}/history`, + ), + method: "GET", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: _response.body as Monite.PayableHistoryPaginationResponse, + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling GET /payables/{payable_id}/history.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + /** * Mark a payable as paid. * @@ -2162,7 +2274,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.markAsPaidById("payable_id") @@ -2180,30 +2292,26 @@ export class Payables { request: Monite.CommentPayload = {}, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/mark_as_paid`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2228,8 +2336,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2294,7 +2402,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.markAsPartiallyPaidById("payable_id", { @@ -2314,30 +2422,26 @@ export class Payables { request: Monite.PartiallyPaidPayload, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/mark_as_partially_paid`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2362,8 +2466,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2404,7 +2508,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.rejectById("payable_id") @@ -2420,31 +2524,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/reject`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2467,8 +2565,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2498,9 +2596,9 @@ export class Payables { } /** - * Reset payable state from rejected to new. + * Moves payables in the `rejected` or `waiting_to_be_paid` statuses back to `new`, allowing further actions such as editing, approval, or payment. The * - * @param {string} payableId + * @param {string} payableId - The unique identifier of the payable you want to reopen. * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} @@ -2509,7 +2607,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.reopenById("payable_id") @@ -2525,31 +2623,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/reopen`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2572,8 +2664,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2614,7 +2706,7 @@ export class Payables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.submitForApprovalById("payable_id") @@ -2630,31 +2722,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/submit_for_approval`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2677,8 +2763,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2707,6 +2793,198 @@ export class Payables { } } + /** + * Retrieves the most likely matching counterpart for a given payable, based on an AI-powered analysis of the payable's data. + * + * When a user uploads a payable, Monite automatically compares key fieldsβ€”such as `name`, `address`, `VAT ID`, and bank `account`β€”against existing counterparts. If a sufficiently similar match is found, this endpoint will return a suggested counterpart. + * + * If no suitable match is identified, the response will be empty. + * + * **Note:** Suggestions are automatically generated during payable upload. This endpoint simply retrieves the existing suggestion for a specific payable. + * + * @param {string} payableId - The unique identifier of the payable you want to find matching suggestions for. + * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.payables.getPayablesIdSuggestions("payable_id") + */ + public getPayablesIdSuggestions( + payableId: string, + requestOptions?: Payables.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getPayablesIdSuggestions(payableId, requestOptions)); + } + + private async __getPayablesIdSuggestions( + payableId: string, + requestOptions?: Payables.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `payables/${encodeURIComponent(payableId)}/suggestions`, + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.SuggestedResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling GET /payables/{payable_id}/suggestions.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Deletes the automatically generated counterpart suggestion for a specific payable. + * + * @param {string} payableId - The unique identifier of the payable whose suggestions you want to delete. + * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.payables.deletePayablesIdSuggestions("payable_id") + */ + public deletePayablesIdSuggestions( + payableId: string, + requestOptions?: Payables.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deletePayablesIdSuggestions(payableId, requestOptions)); + } + + private async __deletePayablesIdSuggestions( + payableId: string, + requestOptions?: Payables.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `payables/${encodeURIComponent(payableId)}/suggestions`, + ), + method: "DELETE", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling DELETE /payables/{payable_id}/suggestions.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + /** * Check the invoice for compliance with the requirements for movement from draft to new status. * @@ -2714,11 +2992,12 @@ export class Payables { * @param {Payables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.validateById("payable_id") @@ -2734,31 +3013,25 @@ export class Payables { payableId: string, requestOptions?: Payables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/validate`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2771,6 +3044,8 @@ export class Payables { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -2779,8 +3054,8 @@ export class Payables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/payables/client/index.ts b/src/api/resources/payables/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/payables/client/index.ts +++ b/src/api/resources/payables/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/payables/client/requests/GetPayablesIdHistoryRequest.ts b/src/api/resources/payables/client/requests/GetPayablesIdHistoryRequest.ts new file mode 100644 index 0000000..3e8601b --- /dev/null +++ b/src/api/resources/payables/client/requests/GetPayablesIdHistoryRequest.ts @@ -0,0 +1,39 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface GetPayablesIdHistoryRequest { + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ + order?: Monite.OrderEnum; + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ + limit?: number; + /** + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. + */ + pagination_token?: string; + /** The field to sort the results by. Typically used together with the `order` parameter. */ + sort?: Monite.PayableHistoryCursorFields; + /** Return only the specified event types */ + event_type__in?: Monite.PayableHistoryEventTypeEnum | Monite.PayableHistoryEventTypeEnum[]; + /** + * Return only events caused by the entity users with the specified IDs. To specify multiple user IDs, repeat this parameter for each ID: + * `entity_user_id__in=&entity_user_id__in=` + */ + entity_user_id__in?: string | string[]; + /** Return only events that occurred after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ + timestamp__gt?: string; + /** Return only events that occurred before the specified date and time. */ + timestamp__lt?: string; + /** Return only events that occurred on or after the specified date and time. */ + timestamp__gte?: string; + /** Return only events that occurred before or on the specified date and time. */ + timestamp__lte?: string; +} diff --git a/src/api/resources/payables/client/requests/PayableAttachFile.ts b/src/api/resources/payables/client/requests/PayableAttachFile.ts index 468109b..796802b 100644 --- a/src/api/resources/payables/client/requests/PayableAttachFile.ts +++ b/src/api/resources/payables/client/requests/PayableAttachFile.ts @@ -2,8 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + /** * @example - * {} + * { + * file: fs.createReadStream("/path/to/your/file") + * } */ -export interface PayableAttachFile {} +export interface PayableAttachFile { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/payables/client/requests/PayableUpdateSchema.ts b/src/api/resources/payables/client/requests/PayableUpdateSchema.ts index 7a795d8..3720034 100644 --- a/src/api/resources/payables/client/requests/PayableUpdateSchema.ts +++ b/src/api/resources/payables/client/requests/PayableUpdateSchema.ts @@ -2,13 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PayableUpdateSchema { + /** How much was paid on the invoice (in minor units). */ + amount_paid?: number; /** The ID of counterpart address object stored in counterparts service */ counterpart_address_id?: string; /** The ID of counterpart bank account object stored in counterparts service */ diff --git a/src/api/resources/payables/client/requests/PayableUploadFile.ts b/src/api/resources/payables/client/requests/PayableUploadFile.ts index 562ec39..a819813 100644 --- a/src/api/resources/payables/client/requests/PayableUploadFile.ts +++ b/src/api/resources/payables/client/requests/PayableUploadFile.ts @@ -2,8 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + /** * @example - * {} + * { + * file: fs.createReadStream("/path/to/your/file") + * } */ -export interface PayableUploadFile {} +export interface PayableUploadFile { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/payables/client/requests/PayableUploadWithDataSchema.ts b/src/api/resources/payables/client/requests/PayableUploadWithDataSchema.ts index e349894..244e8ff 100644 --- a/src/api/resources/payables/client/requests/PayableUploadWithDataSchema.ts +++ b/src/api/resources/payables/client/requests/PayableUploadWithDataSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/payables/client/requests/PayableValidationsUpdateRequest.ts b/src/api/resources/payables/client/requests/PayableValidationsUpdateRequest.ts index aa0c600..2e6012b 100644 --- a/src/api/resources/payables/client/requests/PayableValidationsUpdateRequest.ts +++ b/src/api/resources/payables/client/requests/PayableValidationsUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/payables/client/requests/PayablesGetAnalyticsRequest.ts b/src/api/resources/payables/client/requests/PayablesGetAnalyticsRequest.ts index 15dccd9..641aeab 100644 --- a/src/api/resources/payables/client/requests/PayablesGetAnalyticsRequest.ts +++ b/src/api/resources/payables/client/requests/PayablesGetAnalyticsRequest.ts @@ -2,28 +2,20 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PayablesGetAnalyticsRequest { - /** - * Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. - */ + /** Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. */ created_at__gt?: string; - /** - * Return only payables created in Monite before the specified date and time. - */ + /** Return only payables created in Monite before the specified date and time. */ created_at__lt?: string; - /** - * Return only payables created in Monite on or after the specified date and time. - */ + /** Return only payables created in Monite on or after the specified date and time. */ created_at__gte?: string; - /** - * Return only payables created in Monite before or on the specified date and time. - */ + /** Return only payables created in Monite before or on the specified date and time. */ created_at__lte?: string; /** * Return only payables that have the specified [status](https://docs.monite.com/accounts-payable/payables/index). @@ -43,49 +35,27 @@ export interface PayablesGetAnalyticsRequest { * To specify multiple IDs, repeat this parameter for each value: `id__in=&id__in=` */ id__in?: string | string[]; - /** - * Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. - */ + /** Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. */ total_amount?: number; - /** - * Return only payables whose total amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose total amount (in minor units) exceeds the specified value. */ total_amount__gt?: number; - /** - * Return only payables whose total amount (in minor units) is less than the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than the specified value. */ total_amount__lt?: number; - /** - * Return only payables whose total amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is greater than or equal to the specified value. */ total_amount__gte?: number; - /** - * Return only payables whose total amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than or equal to the specified value. */ total_amount__lte?: number; - /** - * Return only payables with the specified amount. - */ + /** Return only payables with the specified amount. */ amount?: number; - /** - * Return only payables whose amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose amount (in minor units) exceeds the specified value. */ amount__gt?: number; - /** - * Return only payables whose amount (in minor units) is less than the specified value. - */ + /** Return only payables whose amount (in minor units) is less than the specified value. */ amount__lt?: number; - /** - * Return only payables whose amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is greater than or equal to the specified value. */ amount__gte?: number; - /** - * Return only payables whose amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is less than or equal to the specified value. */ amount__lte?: number; - /** - * Return only payables that use the specified currency. - */ + /** Return only payables that use the specified currency. */ currency?: Monite.CurrencyEnum; /** * Return only payables received from counterparts with the specified name (exact match, case-sensitive). @@ -93,57 +63,31 @@ export interface PayablesGetAnalyticsRequest { * For counterparts of `type = individual`, the full name is formatted as `first_name last_name`. */ counterpart_name?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-sensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-sensitive). */ counterpart_name__contains?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-insensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-insensitive). */ counterpart_name__icontains?: string; - /** - * Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. - */ + /** Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. */ search_text?: string; - /** - * Return payables that are due on the specified date (YYYY-MM-DD) - */ + /** Return payables that are due on the specified date (YYYY-MM-DD) */ due_date?: string; - /** - * Return payables that are due after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due after the specified date (exclusive, YYYY-MM-DD). */ due_date__gt?: string; - /** - * Return payables that are due before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due before the specified date (exclusive, YYYY-MM-DD). */ due_date__lt?: string; - /** - * Return payables that are due on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are due on or after the specified date (YYYY-MM-DD). */ due_date__gte?: string; - /** - * Return payables that are due before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are due before or on the specified date (YYYY-MM-DD). */ due_date__lte?: string; - /** - * Return payables that are issued at the specified date (YYYY-MM-DD) - */ + /** Return payables that are issued at the specified date (YYYY-MM-DD) */ issued_at?: string; - /** - * Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). */ issued_at__gt?: string; - /** - * Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). */ issued_at__lt?: string; - /** - * Return payables that are issued on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued on or after the specified date (YYYY-MM-DD). */ issued_at__gte?: string; - /** - * Return payables that are issued before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued before or on the specified date (YYYY-MM-DD). */ issued_at__lte?: string; /** * Return a payable with the exact specified document number (case-sensitive). @@ -151,17 +95,11 @@ export interface PayablesGetAnalyticsRequest { * The `document_id` is the user-facing document number such as INV-00042, not to be confused with Monite resource IDs (`id`). */ document_id?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). */ document_id__contains?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). */ document_id__icontains?: string; - /** - * Return only payables created in Monite by the entity user with the specified ID. - */ + /** Return only payables created in Monite by the entity user with the specified ID. */ was_created_by_user_id?: string; /** * Return only payables received from the counterpart with the specified ID. @@ -171,21 +109,13 @@ export interface PayablesGetAnalyticsRequest { * If the specified counterpart ID does not exist and never existed, no results are returned. */ counterpart_id?: string; - /** - * Return only payables coming from the specified source. - */ + /** Return only payables coming from the specified source. */ source_of_payable_data?: Monite.SourceOfPayableDataEnum; - /** - * Return only payables with specific OCR statuses. - */ + /** Return only payables with specific OCR statuses. */ ocr_status?: Monite.OcrStatusEnum; - /** - * Search for a payable by the identifier of the line item associated with it. - */ + /** Search for a payable by the identifier of the line item associated with it. */ line_item_id?: string; - /** - * Search for a payable by the identifier of the purchase order associated with it. - */ + /** Search for a payable by the identifier of the purchase order associated with it. */ purchase_order_id?: string; /** * Return only payables assigned to the project with the specified ID. @@ -193,24 +123,16 @@ export interface PayablesGetAnalyticsRequest { * Valid but nonexistent project IDs do not raise errors but return no results. */ project_id?: string; - /** - * Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. - */ + /** Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ project_id__in?: string | string[]; - /** - * Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. - */ + /** Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. */ tag_ids?: string | string[]; - /** - * Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. - */ + /** Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. */ tag_ids__not_in?: string | string[]; - /** - * Return only payables from a given origin ['einvoice', 'upload', 'email'] - */ + /** Filter objects based on whether they have tags. If true, only objects with tags are returned. If false, only objects without tags are returned. */ + has_tags?: boolean; + /** Return only payables from a given origin ['einvoice', 'upload', 'email'] */ origin?: Monite.PayableOriginEnum; - /** - * Return only payables with or without attachments (files) - */ + /** Return only payables with or without attachments (files) */ has_file?: boolean; } diff --git a/src/api/resources/payables/client/requests/PayablesGetRequest.ts b/src/api/resources/payables/client/requests/PayablesGetRequest.ts index fedb119..98d10f4 100644 --- a/src/api/resources/payables/client/requests/PayablesGetRequest.ts +++ b/src/api/resources/payables/client/requests/PayablesGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PayablesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,25 +19,15 @@ export interface PayablesGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.PayableCursorFields; - /** - * Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. - */ + /** Return only payables created in Monite after the specified date and time. The value must be in the ISO 8601 format YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]. */ created_at__gt?: string; - /** - * Return only payables created in Monite before the specified date and time. - */ + /** Return only payables created in Monite before the specified date and time. */ created_at__lt?: string; - /** - * Return only payables created in Monite on or after the specified date and time. - */ + /** Return only payables created in Monite on or after the specified date and time. */ created_at__gte?: string; - /** - * Return only payables created in Monite before or on the specified date and time. - */ + /** Return only payables created in Monite before or on the specified date and time. */ created_at__lte?: string; /** * Return only payables that have the specified [status](https://docs.monite.com/accounts-payable/payables/index). @@ -61,49 +47,27 @@ export interface PayablesGetRequest { * To specify multiple IDs, repeat this parameter for each value: `id__in=&id__in=` */ id__in?: string | string[]; - /** - * Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. - */ + /** Return only payables with the exact specified total amount. The amount must be specified in the minor units of currency. For example, $12.5 is represented as 1250. */ total_amount?: number; - /** - * Return only payables whose total amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose total amount (in minor units) exceeds the specified value. */ total_amount__gt?: number; - /** - * Return only payables whose total amount (in minor units) is less than the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than the specified value. */ total_amount__lt?: number; - /** - * Return only payables whose total amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is greater than or equal to the specified value. */ total_amount__gte?: number; - /** - * Return only payables whose total amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose total amount (in minor units) is less than or equal to the specified value. */ total_amount__lte?: number; - /** - * Return only payables with the specified amount. - */ + /** Return only payables with the specified amount. */ amount?: number; - /** - * Return only payables whose amount (in minor units) exceeds the specified value. - */ + /** Return only payables whose amount (in minor units) exceeds the specified value. */ amount__gt?: number; - /** - * Return only payables whose amount (in minor units) is less than the specified value. - */ + /** Return only payables whose amount (in minor units) is less than the specified value. */ amount__lt?: number; - /** - * Return only payables whose amount (in minor units) is greater than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is greater than or equal to the specified value. */ amount__gte?: number; - /** - * Return only payables whose amount (in minor units) is less than or equal to the specified value. - */ + /** Return only payables whose amount (in minor units) is less than or equal to the specified value. */ amount__lte?: number; - /** - * Return only payables that use the specified currency. - */ + /** Return only payables that use the specified currency. */ currency?: Monite.CurrencyEnum; /** * Return only payables received from counterparts with the specified name (exact match, case-sensitive). @@ -111,57 +75,31 @@ export interface PayablesGetRequest { * For counterparts of `type = individual`, the full name is formatted as `first_name last_name`. */ counterpart_name?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-sensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-sensitive). */ counterpart_name__contains?: string; - /** - * Return only payables received from counterparts whose name contains the specified string (case-insensitive). - */ + /** Return only payables received from counterparts whose name contains the specified string (case-insensitive). */ counterpart_name__icontains?: string; - /** - * Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. - */ + /** Apply the `icontains` condition to search for the specified text in the `document_id` and `counterpart_name` fields in the payables. */ search_text?: string; - /** - * Return payables that are due on the specified date (YYYY-MM-DD) - */ + /** Return payables that are due on the specified date (YYYY-MM-DD) */ due_date?: string; - /** - * Return payables that are due after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due after the specified date (exclusive, YYYY-MM-DD). */ due_date__gt?: string; - /** - * Return payables that are due before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are due before the specified date (exclusive, YYYY-MM-DD). */ due_date__lt?: string; - /** - * Return payables that are due on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are due on or after the specified date (YYYY-MM-DD). */ due_date__gte?: string; - /** - * Return payables that are due before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are due before or on the specified date (YYYY-MM-DD). */ due_date__lte?: string; - /** - * Return payables that are issued at the specified date (YYYY-MM-DD) - */ + /** Return payables that are issued at the specified date (YYYY-MM-DD) */ issued_at?: string; - /** - * Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued after the specified date (exclusive, YYYY-MM-DD). */ issued_at__gt?: string; - /** - * Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). - */ + /** Return payables that are issued before the specified date (exclusive, YYYY-MM-DD). */ issued_at__lt?: string; - /** - * Return payables that are issued on or after the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued on or after the specified date (YYYY-MM-DD). */ issued_at__gte?: string; - /** - * Return payables that are issued before or on the specified date (YYYY-MM-DD). - */ + /** Return payables that are issued before or on the specified date (YYYY-MM-DD). */ issued_at__lte?: string; /** * Return a payable with the exact specified document number (case-sensitive). @@ -169,17 +107,11 @@ export interface PayablesGetRequest { * The `document_id` is the user-facing document number such as INV-00042, not to be confused with Monite resource IDs (`id`). */ document_id?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-sensitive). */ document_id__contains?: string; - /** - * Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). - */ + /** Return only payables whose document number (`document_id`) contains the specified string (case-insensitive). */ document_id__icontains?: string; - /** - * Return only payables created in Monite by the entity user with the specified ID. - */ + /** Return only payables created in Monite by the entity user with the specified ID. */ was_created_by_user_id?: string; /** * Return only payables received from the counterpart with the specified ID. @@ -189,21 +121,13 @@ export interface PayablesGetRequest { * If the specified counterpart ID does not exist and never existed, no results are returned. */ counterpart_id?: string; - /** - * Return only payables coming from the specified source. - */ + /** Return only payables coming from the specified source. */ source_of_payable_data?: Monite.SourceOfPayableDataEnum; - /** - * Return only payables with specific OCR statuses. - */ + /** Return only payables with specific OCR statuses. */ ocr_status?: Monite.OcrStatusEnum; - /** - * Search for a payable by the identifier of the line item associated with it. - */ + /** Search for a payable by the identifier of the line item associated with it. */ line_item_id?: string; - /** - * Search for a payable by the identifier of the purchase order associated with it. - */ + /** Search for a payable by the identifier of the purchase order associated with it. */ purchase_order_id?: string; /** * Return only payables assigned to the project with the specified ID. @@ -211,24 +135,16 @@ export interface PayablesGetRequest { * Valid but nonexistent project IDs do not raise errors but return no results. */ project_id?: string; - /** - * Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. - */ + /** Return only payables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ project_id__in?: string | string[]; - /** - * Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. - */ + /** Return only payables whose `tags` include at least one of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce no results. */ tag_ids?: string | string[]; - /** - * Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. - */ + /** Return only payables whose `tags` do not include any of the tags with the specified IDs. Valid but nonexistent tag IDs do not raise errors but produce the results. */ tag_ids__not_in?: string | string[]; - /** - * Return only payables from a given origin ['einvoice', 'upload', 'email'] - */ + /** Filter objects based on whether they have tags. If true, only objects with tags are returned. If false, only objects without tags are returned. */ + has_tags?: boolean; + /** Return only payables from a given origin ['einvoice', 'upload', 'email'] */ origin?: Monite.PayableOriginEnum; - /** - * Return only payables with or without attachments (files) - */ + /** Return only payables with or without attachments (files) */ has_file?: boolean; } diff --git a/src/api/resources/payables/client/requests/index.ts b/src/api/resources/payables/client/requests/index.ts index bbdf792..24ffc8e 100644 --- a/src/api/resources/payables/client/requests/index.ts +++ b/src/api/resources/payables/client/requests/index.ts @@ -1,9 +1,10 @@ -export { type PayablesGetRequest } from "./PayablesGetRequest"; -export { type PayableUploadWithDataSchema } from "./PayableUploadWithDataSchema"; -export { type PayablesGetAnalyticsRequest } from "./PayablesGetAnalyticsRequest"; -export { type PayableUploadFile } from "./PayableUploadFile"; -export { type PayableValidationsUpdateRequest } from "./PayableValidationsUpdateRequest"; -export { type PayableUpdateSchema } from "./PayableUpdateSchema"; -export { type PayableAttachFile } from "./PayableAttachFile"; -export { type CommentPayload } from "./CommentPayload"; -export { type PartiallyPaidPayload } from "./PartiallyPaidPayload"; +export { type PayablesGetRequest } from "./PayablesGetRequest.js"; +export { type PayableUploadWithDataSchema } from "./PayableUploadWithDataSchema.js"; +export { type PayablesGetAnalyticsRequest } from "./PayablesGetAnalyticsRequest.js"; +export { type PayableUploadFile } from "./PayableUploadFile.js"; +export { type PayableValidationsUpdateRequest } from "./PayableValidationsUpdateRequest.js"; +export { type PayableUpdateSchema } from "./PayableUpdateSchema.js"; +export { type PayableAttachFile } from "./PayableAttachFile.js"; +export { type GetPayablesIdHistoryRequest } from "./GetPayablesIdHistoryRequest.js"; +export { type CommentPayload } from "./CommentPayload.js"; +export { type PartiallyPaidPayload } from "./PartiallyPaidPayload.js"; diff --git a/src/api/resources/payables/index.ts b/src/api/resources/payables/index.ts index 33a87f1..9eb1192 100644 --- a/src/api/resources/payables/index.ts +++ b/src/api/resources/payables/index.ts @@ -1,2 +1,2 @@ -export * from "./client"; -export * from "./resources"; +export * from "./client/index.js"; +export * from "./resources/index.js"; diff --git a/src/api/resources/payables/resources/index.ts b/src/api/resources/payables/resources/index.ts index 020e0d8..1b5354b 100644 --- a/src/api/resources/payables/resources/index.ts +++ b/src/api/resources/payables/resources/index.ts @@ -1,2 +1,2 @@ -export * as lineItems from "./lineItems"; -export * from "./lineItems/client/requests"; +export * as lineItems from "./lineItems/index.js"; +export * from "./lineItems/client/requests/index.js"; diff --git a/src/api/resources/payables/resources/lineItems/client/Client.ts b/src/api/resources/payables/resources/lineItems/client/Client.ts index a779647..ab23c84 100644 --- a/src/api/resources/payables/resources/lineItems/client/Client.ts +++ b/src/api/resources/payables/resources/lineItems/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../../../environments"; -import * as core from "../../../../../../core"; -import * as Monite from "../../../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../../../errors/index"; +import * as environments from "../../../../../../environments.js"; +import * as core from "../../../../../../core/index.js"; +import * as Monite from "../../../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; export declare namespace LineItems { export interface Options { @@ -18,6 +18,8 @@ export declare namespace LineItems { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace LineItems { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class LineItems { - constructor(protected readonly _options: LineItems.Options) {} + protected readonly _options: LineItems.Options; + + constructor(_options: LineItems.Options) { + this._options = _options; + } /** * Get a list of all line items related to a specific payable. @@ -59,7 +67,7 @@ export class LineItems { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.get("payable_id") @@ -105,32 +113,25 @@ export class LineItems { _queryParams["was_created_by_user_id"] = wasCreatedByUserId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -151,8 +152,8 @@ export class LineItems { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -206,7 +207,7 @@ export class LineItems { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.create("payable_id", {}) @@ -224,30 +225,26 @@ export class LineItems { request: Monite.LineItemRequest, requestOptions?: LineItems.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -272,8 +269,8 @@ export class LineItems { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -324,7 +321,7 @@ export class LineItems { * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.replace("payable_id", { @@ -344,30 +341,26 @@ export class LineItems { request: Monite.payables.LineItemsReplaceRequest, requestOptions?: LineItems.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -394,8 +387,8 @@ export class LineItems { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -445,7 +438,7 @@ export class LineItems { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.getById("line_item_id", "payable_id") @@ -463,31 +456,25 @@ export class LineItems { payableId: string, requestOptions?: LineItems.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -510,8 +497,8 @@ export class LineItems { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -556,11 +543,12 @@ export class LineItems { * @param {LineItems.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.deleteById("line_item_id", "payable_id") @@ -578,31 +566,25 @@ export class LineItems { payableId: string, requestOptions?: LineItems.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -615,6 +597,8 @@ export class LineItems { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -623,8 +607,8 @@ export class LineItems { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -675,7 +659,7 @@ export class LineItems { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.payables.lineItems.updateById("line_item_id", "payable_id", {}) @@ -695,30 +679,26 @@ export class LineItems { request: Monite.LineItemRequest, requestOptions?: LineItems.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payables/${encodeURIComponent(payableId)}/line_items/${encodeURIComponent(lineItemId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -743,8 +723,8 @@ export class LineItems { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/payables/resources/lineItems/client/index.ts b/src/api/resources/payables/resources/lineItems/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/payables/resources/lineItems/client/index.ts +++ b/src/api/resources/payables/resources/lineItems/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/payables/resources/lineItems/client/requests/LineItemsGetRequest.ts b/src/api/resources/payables/resources/lineItems/client/requests/LineItemsGetRequest.ts index 658b9c9..fada99b 100644 --- a/src/api/resources/payables/resources/lineItems/client/requests/LineItemsGetRequest.ts +++ b/src/api/resources/payables/resources/lineItems/client/requests/LineItemsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example * {} */ export interface LineItemsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface LineItemsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.LineItemCursorFields; was_created_by_user_id?: string; } diff --git a/src/api/resources/payables/resources/lineItems/client/requests/LineItemsReplaceRequest.ts b/src/api/resources/payables/resources/lineItems/client/requests/LineItemsReplaceRequest.ts index bcf9259..b6c4d25 100644 --- a/src/api/resources/payables/resources/lineItems/client/requests/LineItemsReplaceRequest.ts +++ b/src/api/resources/payables/resources/lineItems/client/requests/LineItemsReplaceRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../../../index"; +import * as Monite from "../../../../../../index.js"; /** * @example diff --git a/src/api/resources/payables/resources/lineItems/client/requests/index.ts b/src/api/resources/payables/resources/lineItems/client/requests/index.ts index db3449c..fbfea1a 100644 --- a/src/api/resources/payables/resources/lineItems/client/requests/index.ts +++ b/src/api/resources/payables/resources/lineItems/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type LineItemsGetRequest } from "./LineItemsGetRequest"; -export { type LineItemsReplaceRequest } from "./LineItemsReplaceRequest"; +export { type LineItemsGetRequest } from "./LineItemsGetRequest.js"; +export { type LineItemsReplaceRequest } from "./LineItemsReplaceRequest.js"; diff --git a/src/api/resources/payables/resources/lineItems/index.ts b/src/api/resources/payables/resources/lineItems/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/payables/resources/lineItems/index.ts +++ b/src/api/resources/payables/resources/lineItems/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/paymentIntents/client/Client.ts b/src/api/resources/paymentIntents/client/Client.ts index 4763614..8330097 100644 --- a/src/api/resources/paymentIntents/client/Client.ts +++ b/src/api/resources/paymentIntents/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PaymentIntents { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentIntents { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace PaymentIntents { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentIntents { - constructor(protected readonly _options: PaymentIntents.Options) {} + protected readonly _options: PaymentIntents.Options; + + constructor(_options: PaymentIntents.Options) { + this._options = _options; + } /** * @param {Monite.PaymentIntentsGetRequest} request * @param {PaymentIntents.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentIntents.get() @@ -98,32 +107,25 @@ export class PaymentIntents { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_intents", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -134,10 +136,12 @@ export class PaymentIntents { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -168,8 +172,9 @@ export class PaymentIntents { * @param {string} paymentIntentId * @param {PaymentIntents.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentIntents.getById("payment_intent_id") @@ -185,31 +190,25 @@ export class PaymentIntents { paymentIntentId: string, requestOptions?: PaymentIntents.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_intents/${encodeURIComponent(paymentIntentId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -220,10 +219,12 @@ export class PaymentIntents { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -257,8 +258,9 @@ export class PaymentIntents { * @param {Monite.UpdatePaymentIntentPayload} request * @param {PaymentIntents.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentIntents.updateById("payment_intent_id", { @@ -278,30 +280,26 @@ export class PaymentIntents { request: Monite.UpdatePaymentIntentPayload, requestOptions?: PaymentIntents.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_intents/${encodeURIComponent(paymentIntentId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -314,10 +312,12 @@ export class PaymentIntents { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -350,8 +350,9 @@ export class PaymentIntents { * @param {string} paymentIntentId * @param {PaymentIntents.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentIntents.getHistoryById("payment_intent_id") @@ -367,31 +368,25 @@ export class PaymentIntents { paymentIntentId: string, requestOptions?: PaymentIntents.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_intents/${encodeURIComponent(paymentIntentId)}/history`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -402,10 +397,12 @@ export class PaymentIntents { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/paymentIntents/client/index.ts b/src/api/resources/paymentIntents/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/paymentIntents/client/index.ts +++ b/src/api/resources/paymentIntents/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/paymentIntents/client/requests/PaymentIntentsGetRequest.ts b/src/api/resources/paymentIntents/client/requests/PaymentIntentsGetRequest.ts index d590f83..cec8e3d 100644 --- a/src/api/resources/paymentIntents/client/requests/PaymentIntentsGetRequest.ts +++ b/src/api/resources/paymentIntents/client/requests/PaymentIntentsGetRequest.ts @@ -2,35 +2,27 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PaymentIntentsGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** - * A token, obtained from previous page. Prior over other filters + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.PaymentIntentCursorFields; - /** - * ID of a payable or receivable invoice. If provided, returns only payment intents associated with the specified invoice. - */ + /** ID of a payable or receivable invoice. If provided, returns only payment intents associated with the specified invoice. */ object_id?: string; - /** - * A list of payable IDs and/or receivable IDs. If provided, returns only payment intents associated with the specified payable and receivable invoices. Valid but nonexistent IDs do not raise errors but produce no results. - */ + /** A list of payable IDs and/or receivable IDs. If provided, returns only payment intents associated with the specified payable and receivable invoices. Valid but nonexistent IDs do not raise errors but produce no results. */ object_id__in?: string | string[]; } diff --git a/src/api/resources/paymentIntents/client/requests/index.ts b/src/api/resources/paymentIntents/client/requests/index.ts index a54c95c..0eafb7b 100644 --- a/src/api/resources/paymentIntents/client/requests/index.ts +++ b/src/api/resources/paymentIntents/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type PaymentIntentsGetRequest } from "./PaymentIntentsGetRequest"; -export { type UpdatePaymentIntentPayload } from "./UpdatePaymentIntentPayload"; +export { type PaymentIntentsGetRequest } from "./PaymentIntentsGetRequest.js"; +export { type UpdatePaymentIntentPayload } from "./UpdatePaymentIntentPayload.js"; diff --git a/src/api/resources/paymentIntents/index.ts b/src/api/resources/paymentIntents/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/paymentIntents/index.ts +++ b/src/api/resources/paymentIntents/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/paymentLinks/client/Client.ts b/src/api/resources/paymentLinks/client/Client.ts index 19ba99a..19faafe 100644 --- a/src/api/resources/paymentLinks/client/Client.ts +++ b/src/api/resources/paymentLinks/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PaymentLinks { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentLinks { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,28 +34,116 @@ export declare namespace PaymentLinks { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentLinks { - constructor(protected readonly _options: PaymentLinks.Options) {} + protected readonly _options: PaymentLinks.Options; + + constructor(_options: PaymentLinks.Options) { + this._options = _options; + } /** + * Create a new [payment link](https://docs.monite.com/payments/payment-links) for an accounts payble invoice (to be paid by the entity) or an accounts receivable invoice (to be sent to the counterpart). + * * @param {Monite.CreatePaymentLinkRequest} request * @param {PaymentLinks.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.paymentLinks.create({ + * object: { + * id: "5940eb3a-de95-4e7e-b5e7-8a4ad0ea341b", + * type: "payable" + * }, + * payment_methods: ["sepa_credit"], + * recipient: { + * id: "6296af34-6feb-43c1-b567-83e3bf45050c", + * type: "counterpart" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * }) * * @example * await client.paymentLinks.create({ + * amount: 12500, + * currency: "EUR", + * expires_at: "2025-08-30T23:59:59Z", + * invoice: { + * due_date: "2025-07-31", + * file: { + * mimetype: "application/pdf", + * name: "invoice.pdf", + * url: "https://example.com/path/to/invoice.pdf" + * }, + * issue_date: "2025-07-01" + * }, * payment_methods: ["sepa_credit"], + * payment_reference: "INV/2025/0042", + * recipient: { + * id: "6296af34-6feb-43c1-b567-83e3bf45050c", + * type: "counterpart" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * }) + * + * @example + * await client.paymentLinks.create({ + * object: { + * id: "419f4b6a-0e87-4b07-87fc-5047fe3328c8", + * type: "receivable" + * }, + * payment_methods: ["card", "eps", "ideal", "sepa_credit", "sepa_debit"], + * recipient: { + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", + * type: "entity" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * }) + * + * @example + * await client.paymentLinks.create({ + * object: { + * id: "419f4b6a-0e87-4b07-87fc-5047fe3328c8", + * type: "receivable" + * }, + * payment_methods: ["card", "us_ach", "affirm", "klarna"], * recipient: { - * id: "id", + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", * type: "entity" - * } + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * }) + * + * @example + * await client.paymentLinks.create({ + * amount: 12500, + * currency: "EUR", + * expires_at: "2025-08-30T23:59:59Z", + * invoice: { + * due_date: "2025-07-31", + * file: { + * mimetype: "application/pdf", + * name: "invoice.pdf", + * url: "https://example.com/path/to/invoice.pdf" + * }, + * issue_date: "2025-07-01" + * }, + * payment_methods: ["card", "eps", "ideal", "sepa_credit", "sepa_debit"], + * payment_reference: "INV/2025/0042", + * recipient: { + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", + * type: "entity" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" * }) */ public create( @@ -67,30 +157,26 @@ export class PaymentLinks { request: Monite.CreatePaymentLinkRequest, requestOptions?: PaymentLinks.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_links", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -103,10 +189,12 @@ export class PaymentLinks { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -137,8 +225,9 @@ export class PaymentLinks { * @param {string} paymentLinkId * @param {PaymentLinks.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentLinks.getById("payment_link_id") @@ -154,31 +243,25 @@ export class PaymentLinks { paymentLinkId: string, requestOptions?: PaymentLinks.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_links/${encodeURIComponent(paymentLinkId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -189,10 +272,12 @@ export class PaymentLinks { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -225,8 +310,9 @@ export class PaymentLinks { * @param {string} paymentLinkId * @param {PaymentLinks.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentLinks.expireById("payment_link_id") @@ -242,31 +328,25 @@ export class PaymentLinks { paymentLinkId: string, requestOptions?: PaymentLinks.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_links/${encodeURIComponent(paymentLinkId)}/expire`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -277,10 +357,12 @@ export class PaymentLinks { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/paymentLinks/client/index.ts b/src/api/resources/paymentLinks/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/paymentLinks/client/index.ts +++ b/src/api/resources/paymentLinks/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/paymentLinks/client/requests/CreatePaymentLinkRequest.ts b/src/api/resources/paymentLinks/client/requests/CreatePaymentLinkRequest.ts index 64ca561..c4c41dd 100644 --- a/src/api/resources/paymentLinks/client/requests/CreatePaymentLinkRequest.ts +++ b/src/api/resources/paymentLinks/client/requests/CreatePaymentLinkRequest.ts @@ -2,31 +2,134 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * { + * object: { + * id: "5940eb3a-de95-4e7e-b5e7-8a4ad0ea341b", + * type: "payable" + * }, * payment_methods: ["sepa_credit"], * recipient: { - * id: "id", + * id: "6296af34-6feb-43c1-b567-83e3bf45050c", + * type: "counterpart" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * } + * + * @example + * { + * amount: 12500, + * currency: "EUR", + * expires_at: "2025-08-30T23:59:59Z", + * invoice: { + * due_date: "2025-07-31", + * file: { + * mimetype: "application/pdf", + * name: "invoice.pdf", + * url: "https://example.com/path/to/invoice.pdf" + * }, + * issue_date: "2025-07-01" + * }, + * payment_methods: ["sepa_credit"], + * payment_reference: "INV/2025/0042", + * recipient: { + * id: "6296af34-6feb-43c1-b567-83e3bf45050c", + * type: "counterpart" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * } + * + * @example + * { + * object: { + * id: "419f4b6a-0e87-4b07-87fc-5047fe3328c8", + * type: "receivable" + * }, + * payment_methods: ["card", "eps", "ideal", "sepa_credit", "sepa_debit"], + * recipient: { + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", + * type: "entity" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * } + * + * @example + * { + * object: { + * id: "419f4b6a-0e87-4b07-87fc-5047fe3328c8", + * type: "receivable" + * }, + * payment_methods: ["card", "us_ach", "affirm", "klarna"], + * recipient: { + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", + * type: "entity" + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" + * } + * + * @example + * { + * amount: 12500, + * currency: "EUR", + * expires_at: "2025-08-30T23:59:59Z", + * invoice: { + * due_date: "2025-07-31", + * file: { + * mimetype: "application/pdf", + * name: "invoice.pdf", + * url: "https://example.com/path/to/invoice.pdf" + * }, + * issue_date: "2025-07-01" + * }, + * payment_methods: ["card", "eps", "ideal", "sepa_credit", "sepa_debit"], + * payment_reference: "INV/2025/0042", + * recipient: { + * id: "274b995b-1906-4d8a-b7fe-e8d822d731b0", * type: "entity" - * } + * }, + * return_url: "https://example.com/where-to-redirect-after-payment" * } */ export interface CreatePaymentLinkRequest { - /** The payment amount in [minor units](https://docs.monite.com/references/currencies#minor-units). Required if `object` is not specified. */ + /** + * The payment amount in [minor units](https://docs.monite.com/references/currencies#minor-units). The usage of the `amount` field depends on the type of the payment link you are creating: + * + * * If the `invoice` object is specified (that is, when creating a payment link for an external invoice), + * `amount` is required. + * * If `object` is specified: + * * If `object.type` is `payable`, `amount` must not be specified since it's taken from the payable. + * * If `object.type` is `receivable`, you can provide a custom `amount` value to create a partial payment link. + * In this case, the `amount` value must not exceed the invoice's `amount_to_pay` minus all active payment links. + */ amount?: number; - /** The payment currency. Required if `object` is not specified. */ + /** The payment currency. Mutually exclusive with `object`. */ currency?: Monite.CurrencyEnum; + /** + * Date and time (in the ISO 8601 format) when this payment link will expire. Can be up to 70 days from the current date and time. + * If omitted: + * + * * Payment links for payables and receivables expire 30 days after the invoice due date. + * * Payment links for external invoices expire 30 days after the link creation time. + * + * For more information, see [Payment link expiration](https://docs.monite.com/payments/payment-links#expiration). + */ expires_at?: string; - /** An object containing information about the invoice being paid. Used only if `object` is not specified. */ + /** An object containing information about an external invoice to be paid. Mutually exclusive with `object`. */ invoice?: Monite.Invoice; /** If the invoice being paid is a payable or receivable stored in Monite, provide the `object` object containing the invoice type and ID. Otherwise, use the `amount`, `currency`, `payment_reference`, and (optionally) `invoice` fields to specify the invoice-related data. */ object?: Monite.PaymentObject; + /** + * Payment methods to be displayed on the payment page. These payment methods must already be enabled for the entity. + * + * **Note:** Available payment methods vary per country, transaction type (B2B or B2C), and the payment link type (entity pays a bill or entity generates an invoice payment link for its counterpart). For more information, see [Payment methods](https://docs.monite.com/payments/payment-methods). + */ payment_methods: Monite.MoniteAllPaymentMethodsTypes[]; - /** A payment reference number that the recipient can use to identify the payer or purpose of the transaction. Required if `object` is not specified. */ + /** A payment reference number that the recipient can use to identify the payer or purpose of the transaction. Mutually exclusive with `object`. */ payment_reference?: string; + /** Specifies the invoice vendor - entity or counterpart. This is the payee, or the recipient of the payment. */ recipient: Monite.PaymentAccountObject; /** The URL where to redirect the payer after the payment. If `return_url` is specified, then after the payment is completed the payment page will display the "Return to platform" link that navigates to this URL. */ return_url?: string; diff --git a/src/api/resources/paymentLinks/client/requests/index.ts b/src/api/resources/paymentLinks/client/requests/index.ts index 5219eed..d49eafd 100644 --- a/src/api/resources/paymentLinks/client/requests/index.ts +++ b/src/api/resources/paymentLinks/client/requests/index.ts @@ -1 +1 @@ -export { type CreatePaymentLinkRequest } from "./CreatePaymentLinkRequest"; +export { type CreatePaymentLinkRequest } from "./CreatePaymentLinkRequest.js"; diff --git a/src/api/resources/paymentLinks/index.ts b/src/api/resources/paymentLinks/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/paymentLinks/index.ts +++ b/src/api/resources/paymentLinks/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/paymentRecords/client/Client.ts b/src/api/resources/paymentRecords/client/Client.ts index cb81a3f..227a0e3 100644 --- a/src/api/resources/paymentRecords/client/Client.ts +++ b/src/api/resources/paymentRecords/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PaymentRecords { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentRecords { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,27 @@ export declare namespace PaymentRecords { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentRecords { - constructor(protected readonly _options: PaymentRecords.Options) {} + protected readonly _options: PaymentRecords.Options; + + constructor(_options: PaymentRecords.Options) { + this._options = _options; + } /** * @param {Monite.PaymentRecordsGetRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.get() @@ -68,6 +77,7 @@ export class PaymentRecords { sort, is_external: isExternal, object_id: objectId, + object_id__in: objectIdIn, object_type: objectType, created_at__gt: createdAtGt, created_at__lt: createdAtLt, @@ -109,6 +119,14 @@ export class PaymentRecords { _queryParams["object_id"] = objectId; } + if (objectIdIn != null) { + if (Array.isArray(objectIdIn)) { + _queryParams["object_id__in"] = objectIdIn.map((item) => item); + } else { + _queryParams["object_id__in"] = objectIdIn; + } + } + if (objectType != null) { _queryParams["object_type"] = objectType; } @@ -169,32 +187,25 @@ export class PaymentRecords { _queryParams["payment_method"] = paymentMethod; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_records", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -205,10 +216,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -239,8 +252,9 @@ export class PaymentRecords { * @param {Monite.PaymentRecordRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.create({ @@ -249,8 +263,7 @@ export class PaymentRecords { * object: { * id: "id", * type: "receivable" - * }, - * payment_intent_id: "payment_intent_id" + * } * }) */ public create( @@ -264,30 +277,26 @@ export class PaymentRecords { request: Monite.PaymentRecordRequest, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_records", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -300,10 +309,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -334,8 +345,9 @@ export class PaymentRecords { * @param {string} paymentRecordId * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.getById("payment_record_id") @@ -351,31 +363,25 @@ export class PaymentRecords { paymentRecordId: string, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_records/${encodeURIComponent(paymentRecordId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -386,10 +392,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -423,8 +431,9 @@ export class PaymentRecords { * @param {Monite.PaymentRecordUpdateRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.patchPaymentRecordsId("payment_record_id") @@ -444,30 +453,26 @@ export class PaymentRecords { request: Monite.PaymentRecordUpdateRequest = {}, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_records/${encodeURIComponent(paymentRecordId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -480,10 +485,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -517,8 +524,9 @@ export class PaymentRecords { * @param {Monite.PaymentRecordStatusUpdateRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.postPaymentRecordsIdCancel("payment_record_id", {}) @@ -538,30 +546,26 @@ export class PaymentRecords { request: Monite.PaymentRecordStatusUpdateRequest, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_records/${encodeURIComponent(paymentRecordId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -574,10 +578,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -611,8 +617,9 @@ export class PaymentRecords { * @param {Monite.PaymentRecordMarkAsSucceededRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.postPaymentRecordsIdMarkAsSucceeded("payment_record_id", { @@ -634,30 +641,26 @@ export class PaymentRecords { request: Monite.PaymentRecordMarkAsSucceededRequest, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_records/${encodeURIComponent(paymentRecordId)}/mark_as_succeeded`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -670,10 +673,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -707,8 +712,9 @@ export class PaymentRecords { * @param {Monite.PaymentRecordStatusUpdateRequest} request * @param {PaymentRecords.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentRecords.postPaymentRecordsIdStartProcessing("payment_record_id", {}) @@ -728,30 +734,26 @@ export class PaymentRecords { request: Monite.PaymentRecordStatusUpdateRequest, requestOptions?: PaymentRecords.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_records/${encodeURIComponent(paymentRecordId)}/start_processing`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -764,10 +766,12 @@ export class PaymentRecords { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/paymentRecords/client/index.ts b/src/api/resources/paymentRecords/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/paymentRecords/client/index.ts +++ b/src/api/resources/paymentRecords/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/paymentRecords/client/requests/PaymentRecordRequest.ts b/src/api/resources/paymentRecords/client/requests/PaymentRecordRequest.ts index 6b4d200..d5a8cf7 100644 --- a/src/api/resources/paymentRecords/client/requests/PaymentRecordRequest.ts +++ b/src/api/resources/paymentRecords/client/requests/PaymentRecordRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -12,8 +12,7 @@ import * as Monite from "../../../../index"; * object: { * id: "id", * type: "receivable" - * }, - * payment_intent_id: "payment_intent_id" + * } * } */ export interface PaymentRecordRequest { @@ -28,7 +27,7 @@ export interface PaymentRecordRequest { /** Timestamp marking when the payment was executed. Null if payment hasn't occurred yet. */ paid_at?: string; /** Identifier for an payment intent. */ - payment_intent_id: string; + payment_intent_id?: string; /** Raw status string of the external payment intent. */ payment_intent_status?: string; /** Payment method used or planned for the transaction. */ @@ -36,5 +35,17 @@ export interface PaymentRecordRequest { /** Scheduled date for future payments, required when the payment is planned but not yet executed. */ planned_payment_date?: string; /** Status of the payment record indicating its current stage (e.g., created, processing, succeeded). */ - status?: Monite.PaymentRecordRequestStatus; + status?: PaymentRecordRequest.Status; +} + +export namespace PaymentRecordRequest { + /** + * Status of the payment record indicating its current stage (e.g., created, processing, succeeded). + */ + export type Status = "created" | "processing" | "succeeded"; + export const Status = { + Created: "created", + Processing: "processing", + Succeeded: "succeeded", + } as const; } diff --git a/src/api/resources/paymentRecords/client/requests/PaymentRecordUpdateRequest.ts b/src/api/resources/paymentRecords/client/requests/PaymentRecordUpdateRequest.ts index 78e24a4..190d57e 100644 --- a/src/api/resources/paymentRecords/client/requests/PaymentRecordUpdateRequest.ts +++ b/src/api/resources/paymentRecords/client/requests/PaymentRecordUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/paymentRecords/client/requests/PaymentRecordsGetRequest.ts b/src/api/resources/paymentRecords/client/requests/PaymentRecordsGetRequest.ts index b13df38..3cc5733 100644 --- a/src/api/resources/paymentRecords/client/requests/PaymentRecordsGetRequest.ts +++ b/src/api/resources/paymentRecords/client/requests/PaymentRecordsGetRequest.ts @@ -2,95 +2,55 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PaymentRecordsGetRequest { - /** - * Order by - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * Max is 100 - */ + /** Max is 100 */ limit?: number; - /** - * A token, obtained from previous page. Prior over other filters - */ + /** A token, obtained from previous page. Prior over other filters */ pagination_token?: string; - /** - * Allowed sort fields - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.PaymentRecordCursorFields; - /** - * Identifies whether payment is from our rails or external system - */ + /** Identifies whether payment is from our rails or external system */ is_external?: boolean; - /** - * ID of the object, that is connected to payment - */ + /** ID of the object, that is connected to payment */ object_id?: string; - /** - * Type of an object, which is connected with payment - */ + /** List of IDs of the objects, that are connected to payments */ + object_id__in?: string | string[]; + /** Type of an object, which is connected with payment */ object_type?: Monite.ObjectTypeEnum; - /** - * Created after this datetime (exclusive) - */ + /** Created after this datetime (exclusive) */ created_at__gt?: string; - /** - * Created before this datetime (exclusive) - */ + /** Created before this datetime (exclusive) */ created_at__lt?: string; - /** - * Updated after this datetime (exclusive) - */ + /** Updated after this datetime (exclusive) */ updated_at__gt?: string; - /** - * Updated before this datetime (exclusive) - */ + /** Updated before this datetime (exclusive) */ updated_at__lt?: string; - /** - * Paid after this datetime (exclusive) - */ + /** Paid after this datetime (exclusive) */ paid_at__gt?: string; - /** - * Paid before this datetime (exclusive) - */ + /** Paid before this datetime (exclusive) */ paid_at__lt?: string; - /** - * Optional date of the upcoming payment (equality) - */ + /** Optional date of the upcoming payment (equality) */ planned_payment_date?: string; - /** - * Planned after this date (exclusive) - */ + /** Planned after this date (exclusive) */ planned_payment_date__gt?: string; - /** - * Planned before this date (exclusive) - */ + /** Planned before this date (exclusive) */ planned_payment_date__lt?: string; - /** - * Planned at or after this date (inclusive) - */ + /** Planned at or after this date (inclusive) */ planned_payment_date__gte?: string; - /** - * Planned at or before this date (inclusive) - */ + /** Planned at or before this date (inclusive) */ planned_payment_date__lte?: string; - /** - * One of the payment record statuses - */ + /** One of the payment record statuses */ status?: Monite.PaymentRecordStatusEnum; - /** - * Payment intent status as a raw string - */ + /** Payment intent status as a raw string */ payment_intent_status?: string; - /** - * Payment method used for the transaction - */ + /** Payment method used for the transaction */ payment_method?: string; } diff --git a/src/api/resources/paymentRecords/client/requests/index.ts b/src/api/resources/paymentRecords/client/requests/index.ts index 4144d6a..a16274f 100644 --- a/src/api/resources/paymentRecords/client/requests/index.ts +++ b/src/api/resources/paymentRecords/client/requests/index.ts @@ -1,4 +1,4 @@ -export { type PaymentRecordsGetRequest } from "./PaymentRecordsGetRequest"; -export { type PaymentRecordRequest } from "./PaymentRecordRequest"; -export { type PaymentRecordUpdateRequest } from "./PaymentRecordUpdateRequest"; -export { type PaymentRecordMarkAsSucceededRequest } from "./PaymentRecordMarkAsSucceededRequest"; +export { type PaymentRecordsGetRequest } from "./PaymentRecordsGetRequest.js"; +export { type PaymentRecordRequest } from "./PaymentRecordRequest.js"; +export { type PaymentRecordUpdateRequest } from "./PaymentRecordUpdateRequest.js"; +export { type PaymentRecordMarkAsSucceededRequest } from "./PaymentRecordMarkAsSucceededRequest.js"; diff --git a/src/api/resources/paymentRecords/index.ts b/src/api/resources/paymentRecords/index.ts index c9240f8..914b8c3 100644 --- a/src/api/resources/paymentRecords/index.ts +++ b/src/api/resources/paymentRecords/index.ts @@ -1,2 +1 @@ -export * from "./types"; -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/paymentRecords/types/PaymentRecordRequestStatus.ts b/src/api/resources/paymentRecords/types/PaymentRecordRequestStatus.ts deleted file mode 100644 index bf018a5..0000000 --- a/src/api/resources/paymentRecords/types/PaymentRecordRequestStatus.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * Status of the payment record indicating its current stage (e.g., created, processing, succeeded). - */ -export type PaymentRecordRequestStatus = "created" | "processing" | "succeeded"; -export const PaymentRecordRequestStatus = { - Created: "created", - Processing: "processing", - Succeeded: "succeeded", -} as const; diff --git a/src/api/resources/paymentRecords/types/index.ts b/src/api/resources/paymentRecords/types/index.ts deleted file mode 100644 index 6013d21..0000000 --- a/src/api/resources/paymentRecords/types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./PaymentRecordRequestStatus"; diff --git a/src/api/resources/paymentReminders/client/Client.ts b/src/api/resources/paymentReminders/client/Client.ts index 98e5364..afdeceb 100644 --- a/src/api/resources/paymentReminders/client/Client.ts +++ b/src/api/resources/paymentReminders/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PaymentReminders { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentReminders { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace PaymentReminders { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentReminders { - constructor(protected readonly _options: PaymentReminders.Options) {} + protected readonly _options: PaymentReminders.Options; + + constructor(_options: PaymentReminders.Options) { + this._options = _options; + } /** * @param {PaymentReminders.RequestOptions} requestOptions - Request-specific configuration. @@ -46,7 +54,7 @@ export class PaymentReminders { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentReminders.get() @@ -60,31 +68,25 @@ export class PaymentReminders { private async __get( requestOptions?: PaymentReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_reminders", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,8 +103,8 @@ export class PaymentReminders { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -137,7 +139,7 @@ export class PaymentReminders { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentReminders.create({ @@ -155,30 +157,26 @@ export class PaymentReminders { request: Monite.PaymentReminder, requestOptions?: PaymentReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_reminders", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -199,8 +197,8 @@ export class PaymentReminders { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -235,7 +233,7 @@ export class PaymentReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentReminders.getById("payment_reminder_id") @@ -251,31 +249,25 @@ export class PaymentReminders { paymentReminderId: string, requestOptions?: PaymentReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_reminders/${encodeURIComponent(paymentReminderId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -294,8 +286,8 @@ export class PaymentReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -333,7 +325,7 @@ export class PaymentReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentReminders.deleteById("payment_reminder_id") @@ -349,31 +341,25 @@ export class PaymentReminders { paymentReminderId: string, requestOptions?: PaymentReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_reminders/${encodeURIComponent(paymentReminderId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -394,8 +380,8 @@ export class PaymentReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -434,7 +420,7 @@ export class PaymentReminders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentReminders.updateById("payment_reminder_id") @@ -452,30 +438,26 @@ export class PaymentReminders { request: Monite.PaymentReminderUpdateRequest = {}, requestOptions?: PaymentReminders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_reminders/${encodeURIComponent(paymentReminderId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -498,8 +480,8 @@ export class PaymentReminders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/paymentReminders/client/index.ts b/src/api/resources/paymentReminders/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/paymentReminders/client/index.ts +++ b/src/api/resources/paymentReminders/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/paymentReminders/client/requests/PaymentReminder.ts b/src/api/resources/paymentReminders/client/requests/PaymentReminder.ts index 4e52460..44836e2 100644 --- a/src/api/resources/paymentReminders/client/requests/PaymentReminder.ts +++ b/src/api/resources/paymentReminders/client/requests/PaymentReminder.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/paymentReminders/client/requests/PaymentReminderUpdateRequest.ts b/src/api/resources/paymentReminders/client/requests/PaymentReminderUpdateRequest.ts index a875af7..d727a97 100644 --- a/src/api/resources/paymentReminders/client/requests/PaymentReminderUpdateRequest.ts +++ b/src/api/resources/paymentReminders/client/requests/PaymentReminderUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/paymentReminders/client/requests/index.ts b/src/api/resources/paymentReminders/client/requests/index.ts index 18adbb3..e2565cb 100644 --- a/src/api/resources/paymentReminders/client/requests/index.ts +++ b/src/api/resources/paymentReminders/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type PaymentReminder } from "./PaymentReminder"; -export { type PaymentReminderUpdateRequest } from "./PaymentReminderUpdateRequest"; +export { type PaymentReminder } from "./PaymentReminder.js"; +export { type PaymentReminderUpdateRequest } from "./PaymentReminderUpdateRequest.js"; diff --git a/src/api/resources/paymentReminders/index.ts b/src/api/resources/paymentReminders/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/paymentReminders/index.ts +++ b/src/api/resources/paymentReminders/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/paymentTerms/client/Client.ts b/src/api/resources/paymentTerms/client/Client.ts index 79be21d..36c4d65 100644 --- a/src/api/resources/paymentTerms/client/Client.ts +++ b/src/api/resources/paymentTerms/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PaymentTerms { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PaymentTerms { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace PaymentTerms { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PaymentTerms { - constructor(protected readonly _options: PaymentTerms.Options) {} + protected readonly _options: PaymentTerms.Options; + + constructor(_options: PaymentTerms.Options) { + this._options = _options; + } /** * @param {PaymentTerms.RequestOptions} requestOptions - Request-specific configuration. @@ -46,7 +54,7 @@ export class PaymentTerms { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentTerms.get() @@ -60,31 +68,25 @@ export class PaymentTerms { private async __get( requestOptions?: PaymentTerms.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_terms", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -101,8 +103,8 @@ export class PaymentTerms { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -137,13 +139,44 @@ export class PaymentTerms { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.paymentTerms.create({ + * description: "Payment is due within 30 days after the invoice issue date", + * name: "Net 30", + * term_final: { + * number_of_days: 30 + * } + * }) + * + * @example + * await client.paymentTerms.create({ + * description: "The invoice must be paid within 30 days. 1% discount if paid within the first 15 days.", + * name: "1/15, Net 30", + * term_1: { + * discount: 100, + * number_of_days: 15 + * }, + * term_final: { + * number_of_days: 30 + * } + * }) * * @example * await client.paymentTerms.create({ - * name: "name", + * description: "The invoice must be paid within 30 days. 2% discount if paid within the first 10 days, 1% discount if paid within 20 days.", + * name: "2/10, 1/20, Net 30", + * term_1: { + * discount: 200, + * number_of_days: 10 + * }, + * term_2: { + * discount: 100, + * number_of_days: 20 + * }, * term_final: { - * number_of_days: 1 + * number_of_days: 30 * } * }) */ @@ -158,30 +191,26 @@ export class PaymentTerms { request: Monite.PaymentTermsCreatePayload, requestOptions?: PaymentTerms.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payment_terms", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -202,8 +231,8 @@ export class PaymentTerms { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -238,7 +267,7 @@ export class PaymentTerms { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentTerms.getById("payment_terms_id") @@ -254,31 +283,25 @@ export class PaymentTerms { paymentTermsId: string, requestOptions?: PaymentTerms.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_terms/${encodeURIComponent(paymentTermsId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -297,8 +320,8 @@ export class PaymentTerms { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -336,7 +359,7 @@ export class PaymentTerms { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentTerms.deleteById("payment_terms_id") @@ -352,31 +375,25 @@ export class PaymentTerms { paymentTermsId: string, requestOptions?: PaymentTerms.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_terms/${encodeURIComponent(paymentTermsId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -397,8 +414,8 @@ export class PaymentTerms { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -437,7 +454,7 @@ export class PaymentTerms { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.paymentTerms.updateById("payment_terms_id") @@ -455,30 +472,26 @@ export class PaymentTerms { request: Monite.PaymentTermsUpdatePayload = {}, requestOptions?: PaymentTerms.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payment_terms/${encodeURIComponent(paymentTermsId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -501,8 +514,8 @@ export class PaymentTerms { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/paymentTerms/client/index.ts b/src/api/resources/paymentTerms/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/paymentTerms/client/index.ts +++ b/src/api/resources/paymentTerms/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/paymentTerms/client/requests/PaymentTermsCreatePayload.ts b/src/api/resources/paymentTerms/client/requests/PaymentTermsCreatePayload.ts index 8233657..efe9050 100644 --- a/src/api/resources/paymentTerms/client/requests/PaymentTermsCreatePayload.ts +++ b/src/api/resources/paymentTerms/client/requests/PaymentTermsCreatePayload.ts @@ -2,14 +2,45 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * { - * name: "name", + * description: "Payment is due within 30 days after the invoice issue date", + * name: "Net 30", * term_final: { - * number_of_days: 1 + * number_of_days: 30 + * } + * } + * + * @example + * { + * description: "The invoice must be paid within 30 days. 1% discount if paid within the first 15 days.", + * name: "1/15, Net 30", + * term_1: { + * discount: 100, + * number_of_days: 15 + * }, + * term_final: { + * number_of_days: 30 + * } + * } + * + * @example + * { + * description: "The invoice must be paid within 30 days. 2% discount if paid within the first 10 days, 1% discount if paid within 20 days.", + * name: "2/10, 1/20, Net 30", + * term_1: { + * discount: 200, + * number_of_days: 10 + * }, + * term_2: { + * discount: 100, + * number_of_days: 20 + * }, + * term_final: { + * number_of_days: 30 * } * } */ @@ -17,9 +48,9 @@ export interface PaymentTermsCreatePayload { description?: string; name: string; /** The first tier of the payment term. Represents the terms of the first early discount. */ - term_1?: Monite.PaymentTermDiscount; + term_1?: Monite.TermDiscountDays; /** The second tier of the payment term. Defines the terms of the second early discount. */ - term_2?: Monite.PaymentTermDiscount; + term_2?: Monite.TermDiscountDays; /** The final tier of the payment term. Defines the invoice due date. */ - term_final: Monite.PaymentTerm; + term_final: Monite.TermFinalDays; } diff --git a/src/api/resources/paymentTerms/client/requests/PaymentTermsUpdatePayload.ts b/src/api/resources/paymentTerms/client/requests/PaymentTermsUpdatePayload.ts index 2619870..39ad9a1 100644 --- a/src/api/resources/paymentTerms/client/requests/PaymentTermsUpdatePayload.ts +++ b/src/api/resources/paymentTerms/client/requests/PaymentTermsUpdatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -12,9 +12,9 @@ export interface PaymentTermsUpdatePayload { description?: string; name?: string; /** The first tier of the payment term. Represents the terms of the first early discount. */ - term_1?: Monite.PaymentTermDiscount; + term_1?: Monite.TermDiscountDays; /** The second tier of the payment term. Defines the terms of the second early discount. */ - term_2?: Monite.PaymentTermDiscount; + term_2?: Monite.TermDiscountDays; /** The final tier of the payment term. Defines the invoice due date. */ - term_final?: Monite.PaymentTerm; + term_final?: Monite.TermFinalDays; } diff --git a/src/api/resources/paymentTerms/client/requests/index.ts b/src/api/resources/paymentTerms/client/requests/index.ts index 5b11436..6924785 100644 --- a/src/api/resources/paymentTerms/client/requests/index.ts +++ b/src/api/resources/paymentTerms/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type PaymentTermsCreatePayload } from "./PaymentTermsCreatePayload"; -export { type PaymentTermsUpdatePayload } from "./PaymentTermsUpdatePayload"; +export { type PaymentTermsCreatePayload } from "./PaymentTermsCreatePayload.js"; +export { type PaymentTermsUpdatePayload } from "./PaymentTermsUpdatePayload.js"; diff --git a/src/api/resources/paymentTerms/index.ts b/src/api/resources/paymentTerms/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/paymentTerms/index.ts +++ b/src/api/resources/paymentTerms/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/pdfTemplates/client/Client.ts b/src/api/resources/pdfTemplates/client/Client.ts index e5fd9ab..b1ca6a6 100644 --- a/src/api/resources/pdfTemplates/client/Client.ts +++ b/src/api/resources/pdfTemplates/client/Client.ts @@ -2,12 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; -import * as stream from "stream"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PdfTemplates { export interface Options { @@ -19,6 +18,8 @@ export declare namespace PdfTemplates { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -33,21 +34,28 @@ export declare namespace PdfTemplates { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PdfTemplates { - constructor(protected readonly _options: PdfTemplates.Options) {} + protected readonly _options: PdfTemplates.Options; + + constructor(_options: PdfTemplates.Options) { + this._options = _options; + } /** * This API call returns all supported templates with language codes. * * @param {PdfTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.pdfTemplates.get() @@ -59,31 +67,25 @@ export class PdfTemplates { private async __get( requestOptions?: PdfTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "document_templates", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -94,10 +96,12 @@ export class PdfTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -129,8 +133,9 @@ export class PdfTemplates { * * @param {PdfTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.pdfTemplates.getSystem() @@ -144,31 +149,25 @@ export class PdfTemplates { private async __getSystem( requestOptions?: PdfTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "document_templates/system", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -179,10 +178,12 @@ export class PdfTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -213,8 +214,9 @@ export class PdfTemplates { * @param {string} documentTemplateId * @param {PdfTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.pdfTemplates.getById("document_template_id") @@ -230,31 +232,25 @@ export class PdfTemplates { documentTemplateId: string, requestOptions?: PdfTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `document_templates/${encodeURIComponent(documentTemplateId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -265,10 +261,12 @@ export class PdfTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -301,8 +299,9 @@ export class PdfTemplates { * @param {string} documentTemplateId * @param {PdfTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.pdfTemplates.makeDefaultById("document_template_id") @@ -318,31 +317,25 @@ export class PdfTemplates { documentTemplateId: string, requestOptions?: PdfTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `document_templates/${encodeURIComponent(documentTemplateId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -353,10 +346,12 @@ export class PdfTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -387,46 +382,41 @@ export class PdfTemplates { /** * Returns a sample PDF invoice generated using the specified template. + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} */ public previewById( documentTemplateId: string, requestOptions?: PdfTemplates.RequestOptions, - ): core.HttpResponsePromise { + ): core.HttpResponsePromise { return core.HttpResponsePromise.fromPromise(this.__previewById(documentTemplateId, requestOptions)); } private async __previewById( documentTemplateId: string, requestOptions?: PdfTemplates.RequestOptions, - ): Promise> { - const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `document_templates/${encodeURIComponent(documentTemplateId)}/preview`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", - responseType: "streaming", + headers: _headers, + queryParameters: requestOptions?.queryParams, + responseType: "binary-response", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -437,10 +427,12 @@ export class PdfTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/pdfTemplates/index.ts b/src/api/resources/pdfTemplates/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/pdfTemplates/index.ts +++ b/src/api/resources/pdfTemplates/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/products/client/Client.ts b/src/api/resources/products/client/Client.ts index 2c8dc20..77c8fe6 100644 --- a/src/api/resources/products/client/Client.ts +++ b/src/api/resources/products/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Products { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Products { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Products { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Products { - constructor(protected readonly _options: Products.Options) {} + protected readonly _options: Products.Options; + + constructor(_options: Products.Options) { + this._options = _options; + } /** * @param {Monite.ProductsGetRequest} request @@ -48,7 +56,7 @@ export class Products { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.products.get() @@ -180,32 +188,25 @@ export class Products { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "products", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -227,8 +228,8 @@ export class Products { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -263,7 +264,7 @@ export class Products { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.products.create({ @@ -281,30 +282,26 @@ export class Products { request: Monite.ProductServiceRequest, requestOptions?: Products.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "products", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -325,8 +322,8 @@ export class Products { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -362,7 +359,7 @@ export class Products { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.products.getById("product_id") @@ -378,31 +375,25 @@ export class Products { productId: string, requestOptions?: Products.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `products/${encodeURIComponent(productId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -423,8 +414,8 @@ export class Products { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -460,7 +451,7 @@ export class Products { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.products.deleteById("product_id") @@ -473,31 +464,25 @@ export class Products { productId: string, requestOptions?: Products.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `products/${encodeURIComponent(productId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -518,8 +503,8 @@ export class Products { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -556,7 +541,7 @@ export class Products { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.products.updateById("product_id") @@ -574,30 +559,26 @@ export class Products { request: Monite.ProductServiceUpdate = {}, requestOptions?: Products.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `products/${encodeURIComponent(productId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -620,8 +601,8 @@ export class Products { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/products/client/index.ts b/src/api/resources/products/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/products/client/index.ts +++ b/src/api/resources/products/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/products/client/requests/ProductServiceRequest.ts b/src/api/resources/products/client/requests/ProductServiceRequest.ts index d87e8c6..ddaff96 100644 --- a/src/api/resources/products/client/requests/ProductServiceRequest.ts +++ b/src/api/resources/products/client/requests/ProductServiceRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -13,6 +13,8 @@ import * as Monite from "../../../../index"; export interface ProductServiceRequest { /** Description of the product. */ description?: string; + /** A user-defined identifier of the product. For example, an internal product code or SKU (stock keeping unit). Client applications can use this field to map the products in Monite to an external product catalog. */ + external_reference?: string; ledger_account_id?: string; /** The unique ID reference of the unit used to measure the quantity of this product (e.g. items, meters, kilograms). */ measure_unit_id?: string; diff --git a/src/api/resources/products/client/requests/ProductServiceUpdate.ts b/src/api/resources/products/client/requests/ProductServiceUpdate.ts index 94f6545..1cb8437 100644 --- a/src/api/resources/products/client/requests/ProductServiceUpdate.ts +++ b/src/api/resources/products/client/requests/ProductServiceUpdate.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -11,6 +11,8 @@ import * as Monite from "../../../../index"; export interface ProductServiceUpdate { /** Description of the product. */ description?: string; + /** A user-defined identifier of the product. For example, an internal product code or SKU (stock keeping unit). Client applications can use this field to map the products in Monite to an external product catalog. */ + external_reference?: string; ledger_account_id?: string; /** The unique ID reference of the unit used to measure the quantity of this product (e.g. items, meters, kilograms). */ measure_unit_id?: string; diff --git a/src/api/resources/products/client/requests/ProductsGetRequest.ts b/src/api/resources/products/client/requests/ProductsGetRequest.ts index c9cd81e..5aaad45 100644 --- a/src/api/resources/products/client/requests/ProductsGetRequest.ts +++ b/src/api/resources/products/client/requests/ProductsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ProductsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface ProductsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ProductCursorFields; id__in?: string | string[]; name?: string; diff --git a/src/api/resources/products/client/requests/index.ts b/src/api/resources/products/client/requests/index.ts index 27f3d75..2349d74 100644 --- a/src/api/resources/products/client/requests/index.ts +++ b/src/api/resources/products/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type ProductsGetRequest } from "./ProductsGetRequest"; -export { type ProductServiceRequest } from "./ProductServiceRequest"; -export { type ProductServiceUpdate } from "./ProductServiceUpdate"; +export { type ProductsGetRequest } from "./ProductsGetRequest.js"; +export { type ProductServiceRequest } from "./ProductServiceRequest.js"; +export { type ProductServiceUpdate } from "./ProductServiceUpdate.js"; diff --git a/src/api/resources/products/index.ts b/src/api/resources/products/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/products/index.ts +++ b/src/api/resources/products/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/projects/client/Client.ts b/src/api/resources/projects/client/Client.ts index 9ff9a36..422a2a4 100644 --- a/src/api/resources/projects/client/Client.ts +++ b/src/api/resources/projects/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Projects { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Projects { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Projects { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Projects { - constructor(protected readonly _options: Projects.Options) {} + protected readonly _options: Projects.Options; + + constructor(_options: Projects.Options) { + this._options = _options; + } /** * Get all projects for an entity @@ -52,7 +60,7 @@ export class Projects { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.projects.get() @@ -191,32 +199,25 @@ export class Projects { _queryParams["created_by_entity_user_id"] = createdByEntityUserId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "projects", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -239,8 +240,8 @@ export class Projects { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -277,7 +278,7 @@ export class Projects { * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.projects.create({ @@ -295,30 +296,26 @@ export class Projects { request: Monite.ProjectCreateRequest, requestOptions?: Projects.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "projects", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -339,8 +336,8 @@ export class Projects { throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -378,7 +375,7 @@ export class Projects { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.projects.getById("project_id") @@ -394,31 +391,25 @@ export class Projects { projectId: string, requestOptions?: Projects.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `projects/${encodeURIComponent(projectId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -439,8 +430,8 @@ export class Projects { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -478,7 +469,7 @@ export class Projects { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.projects.deleteById("project_id") @@ -491,31 +482,25 @@ export class Projects { projectId: string, requestOptions?: Projects.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `projects/${encodeURIComponent(projectId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -536,8 +521,8 @@ export class Projects { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -576,7 +561,7 @@ export class Projects { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.projects.updateById("project_id") @@ -594,30 +579,26 @@ export class Projects { request: Monite.ProjectUpdateRequest = {}, requestOptions?: Projects.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `projects/${encodeURIComponent(projectId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -640,8 +621,8 @@ export class Projects { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/projects/client/index.ts b/src/api/resources/projects/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/projects/client/index.ts +++ b/src/api/resources/projects/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/projects/client/requests/ProjectCreateRequest.ts b/src/api/resources/projects/client/requests/ProjectCreateRequest.ts index fdadf05..63f6952 100644 --- a/src/api/resources/projects/client/requests/ProjectCreateRequest.ts +++ b/src/api/resources/projects/client/requests/ProjectCreateRequest.ts @@ -9,21 +9,21 @@ * } */ export interface ProjectCreateRequest { - /** Project code */ + /** A user-defined identifier of this project. */ code?: string; - /** Project color */ + /** Project color as a [CSS-compatible](https://developer.mozilla.org/en-US/docs/Web/CSS/color) value. Client applications can use this to color-code the projects or project-related data. */ color?: string; - /** Description of project */ + /** A user-defined description of the project. */ description?: string; - /** Project end date */ + /** Project end date. If specified, must be later than or equal to the start date. */ end_date?: string; /** The project name. */ name: string; - /** Parent project ID */ + /** Unused. Reserved for future use. */ parent_id?: string; - /** Project metadata */ + /** [Metadata](https://docs.monite.com/common/metadata) for partner needs. */ partner_metadata?: Record; - /** Project start date */ + /** Project start date. */ start_date?: string; /** A list of IDs of user-defined tags (labels) assigned to this project. */ tag_ids?: string[]; diff --git a/src/api/resources/projects/client/requests/ProjectUpdateRequest.ts b/src/api/resources/projects/client/requests/ProjectUpdateRequest.ts index b87c58b..ce04b16 100644 --- a/src/api/resources/projects/client/requests/ProjectUpdateRequest.ts +++ b/src/api/resources/projects/client/requests/ProjectUpdateRequest.ts @@ -7,21 +7,21 @@ * {} */ export interface ProjectUpdateRequest { - /** Project code */ + /** A user-defined identifier of this project. */ code?: string; - /** Project color */ + /** Project color as a [CSS-compatible](https://developer.mozilla.org/en-US/docs/Web/CSS/color) value. Client applications can use this to color-code the projects or project-related data. */ color?: string; - /** Description of project */ + /** A user-defined description of the project. */ description?: string; - /** Project end date */ + /** Project end date. If specified, must be later than or equal to the start date. */ end_date?: string; /** The project name. */ name?: string; - /** Parent project ID */ + /** Unused. Reserved for future use. */ parent_id?: string; - /** Project metadata */ + /** [Metadata](https://docs.monite.com/common/metadata) for partner needs. */ partner_metadata?: Record; - /** Project start date */ + /** Project start date. */ start_date?: string; /** A list of IDs of user-defined tags (labels) assigned to this project. */ tag_ids?: string[]; diff --git a/src/api/resources/projects/client/requests/ProjectsGetRequest.ts b/src/api/resources/projects/client/requests/ProjectsGetRequest.ts index 1766161..8f75925 100644 --- a/src/api/resources/projects/client/requests/ProjectsGetRequest.ts +++ b/src/api/resources/projects/client/requests/ProjectsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ProjectsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface ProjectsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ProjectCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/projects/client/requests/index.ts b/src/api/resources/projects/client/requests/index.ts index 928294e..a8b8d13 100644 --- a/src/api/resources/projects/client/requests/index.ts +++ b/src/api/resources/projects/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type ProjectsGetRequest } from "./ProjectsGetRequest"; -export { type ProjectCreateRequest } from "./ProjectCreateRequest"; -export { type ProjectUpdateRequest } from "./ProjectUpdateRequest"; +export { type ProjectsGetRequest } from "./ProjectsGetRequest.js"; +export { type ProjectCreateRequest } from "./ProjectCreateRequest.js"; +export { type ProjectUpdateRequest } from "./ProjectUpdateRequest.js"; diff --git a/src/api/resources/projects/index.ts b/src/api/resources/projects/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/projects/index.ts +++ b/src/api/resources/projects/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/purchaseOrders/client/Client.ts b/src/api/resources/purchaseOrders/client/Client.ts index 7ad5b6f..defb9df 100644 --- a/src/api/resources/purchaseOrders/client/Client.ts +++ b/src/api/resources/purchaseOrders/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace PurchaseOrders { export interface Options { @@ -18,6 +18,8 @@ export declare namespace PurchaseOrders { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,22 +34,29 @@ export declare namespace PurchaseOrders { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class PurchaseOrders { - constructor(protected readonly _options: PurchaseOrders.Options) {} + protected readonly _options: PurchaseOrders.Options; + + constructor(_options: PurchaseOrders.Options) { + this._options = _options; + } /** * @param {Monite.PurchaseOrdersGetRequest} request * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.get() @@ -208,32 +217,25 @@ export class PurchaseOrders { _queryParams["project_id"] = projectId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_purchase_orders", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -249,12 +251,14 @@ export class PurchaseOrders { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -286,9 +290,10 @@ export class PurchaseOrders { * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.create({ @@ -317,30 +322,26 @@ export class PurchaseOrders { request: Monite.PurchaseOrderPayloadSchema, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_purchase_orders", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -355,12 +356,14 @@ export class PurchaseOrders { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -392,9 +395,10 @@ export class PurchaseOrders { * * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.getVariables() @@ -408,31 +412,25 @@ export class PurchaseOrders { private async __getVariables( requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "payable_purchase_orders/variables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -443,12 +441,14 @@ export class PurchaseOrders { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -482,9 +482,10 @@ export class PurchaseOrders { * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.getById("purchase_order_id") @@ -500,31 +501,25 @@ export class PurchaseOrders { purchaseOrderId: string, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_purchase_orders/${encodeURIComponent(purchaseOrderId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -537,12 +532,14 @@ export class PurchaseOrders { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -576,9 +573,10 @@ export class PurchaseOrders { * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.deleteById("purchase_order_id") @@ -594,31 +592,25 @@ export class PurchaseOrders { purchaseOrderId: string, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_purchase_orders/${encodeURIComponent(purchaseOrderId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -631,12 +623,14 @@ export class PurchaseOrders { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -671,9 +665,10 @@ export class PurchaseOrders { * @param {PurchaseOrders.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.updateById("purchase_order_id") @@ -691,30 +686,26 @@ export class PurchaseOrders { request: Monite.UpdatePurchaseOrderPayloadSchema = {}, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_purchase_orders/${encodeURIComponent(purchaseOrderId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -729,12 +720,14 @@ export class PurchaseOrders { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -773,7 +766,7 @@ export class PurchaseOrders { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.previewById("purchase_order_id", { @@ -794,30 +787,26 @@ export class PurchaseOrders { request: Monite.PurchaseOrderEmailPreviewRequest, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_purchase_orders/${encodeURIComponent(purchaseOrderId)}/preview`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -843,8 +832,8 @@ export class PurchaseOrders { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -884,7 +873,7 @@ export class PurchaseOrders { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.purchaseOrders.sendById("purchase_order_id", { @@ -905,30 +894,26 @@ export class PurchaseOrders { request: Monite.SendPurchaseOrderViaEmailRequest, requestOptions?: PurchaseOrders.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `payable_purchase_orders/${encodeURIComponent(purchaseOrderId)}/send`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -956,8 +941,8 @@ export class PurchaseOrders { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/purchaseOrders/client/index.ts b/src/api/resources/purchaseOrders/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/purchaseOrders/client/index.ts +++ b/src/api/resources/purchaseOrders/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/purchaseOrders/client/requests/PurchaseOrderPayloadSchema.ts b/src/api/resources/purchaseOrders/client/requests/PurchaseOrderPayloadSchema.ts index c30dd99..1265092 100644 --- a/src/api/resources/purchaseOrders/client/requests/PurchaseOrderPayloadSchema.ts +++ b/src/api/resources/purchaseOrders/client/requests/PurchaseOrderPayloadSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/purchaseOrders/client/requests/PurchaseOrdersGetRequest.ts b/src/api/resources/purchaseOrders/client/requests/PurchaseOrdersGetRequest.ts index d413e1d..c3157a7 100644 --- a/src/api/resources/purchaseOrders/client/requests/PurchaseOrdersGetRequest.ts +++ b/src/api/resources/purchaseOrders/client/requests/PurchaseOrdersGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface PurchaseOrdersGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface PurchaseOrdersGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.PurchaseOrderCursorFields; created_at__gt?: string; created_at__lt?: string; diff --git a/src/api/resources/purchaseOrders/client/requests/UpdatePurchaseOrderPayloadSchema.ts b/src/api/resources/purchaseOrders/client/requests/UpdatePurchaseOrderPayloadSchema.ts index 9c7600d..e08c5d3 100644 --- a/src/api/resources/purchaseOrders/client/requests/UpdatePurchaseOrderPayloadSchema.ts +++ b/src/api/resources/purchaseOrders/client/requests/UpdatePurchaseOrderPayloadSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/purchaseOrders/client/requests/index.ts b/src/api/resources/purchaseOrders/client/requests/index.ts index b38d4e1..ae68aa2 100644 --- a/src/api/resources/purchaseOrders/client/requests/index.ts +++ b/src/api/resources/purchaseOrders/client/requests/index.ts @@ -1,5 +1,5 @@ -export { type PurchaseOrdersGetRequest } from "./PurchaseOrdersGetRequest"; -export { type PurchaseOrderPayloadSchema } from "./PurchaseOrderPayloadSchema"; -export { type UpdatePurchaseOrderPayloadSchema } from "./UpdatePurchaseOrderPayloadSchema"; -export { type PurchaseOrderEmailPreviewRequest } from "./PurchaseOrderEmailPreviewRequest"; -export { type SendPurchaseOrderViaEmailRequest } from "./SendPurchaseOrderViaEmailRequest"; +export { type PurchaseOrdersGetRequest } from "./PurchaseOrdersGetRequest.js"; +export { type PurchaseOrderPayloadSchema } from "./PurchaseOrderPayloadSchema.js"; +export { type UpdatePurchaseOrderPayloadSchema } from "./UpdatePurchaseOrderPayloadSchema.js"; +export { type PurchaseOrderEmailPreviewRequest } from "./PurchaseOrderEmailPreviewRequest.js"; +export { type SendPurchaseOrderViaEmailRequest } from "./SendPurchaseOrderViaEmailRequest.js"; diff --git a/src/api/resources/purchaseOrders/index.ts b/src/api/resources/purchaseOrders/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/purchaseOrders/index.ts +++ b/src/api/resources/purchaseOrders/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/receipts/client/Client.ts b/src/api/resources/receipts/client/Client.ts new file mode 100644 index 0000000..b1698b5 --- /dev/null +++ b/src/api/resources/receipts/client/Client.ts @@ -0,0 +1,1317 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; +import * as fs from "fs"; + +export declare namespace Receipts { + export interface Options { + environment?: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + token?: core.Supplier; + /** Override the x-monite-version header */ + moniteVersion: core.Supplier; + /** Override the x-monite-entity-id header */ + moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; + fetcher?: core.FetchFunction; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Override the x-monite-version header */ + moniteVersion?: string; + /** Override the x-monite-entity-id header */ + moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; + /** Additional headers to include in the request. */ + headers?: Record | undefined>; + } +} + +export class Receipts { + protected readonly _options: Receipts.Options; + + constructor(_options: Receipts.Options) { + this._options = _options; + } + + /** + * @param {Monite.GetReceiptsRequest} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.getReceipts() + */ + public getReceipts( + request: Monite.GetReceiptsRequest = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getReceipts(request, requestOptions)); + } + + private async __getReceipts( + request: Monite.GetReceiptsRequest = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + const { + order, + limit, + pagination_token: paginationToken, + sort, + created_at__gt: createdAtGt, + created_at__lt: createdAtLt, + created_at__gte: createdAtGte, + created_at__lte: createdAtLte, + id__in: idIn, + currency, + document_id: documentId, + document_id__contains: documentIdContains, + document_id__icontains: documentIdIcontains, + total_amount__gt: totalAmountGt, + total_amount__lt: totalAmountLt, + total_amount__gte: totalAmountGte, + total_amount__lte: totalAmountLte, + has_file: hasFile, + has_transaction: hasTransaction, + } = request; + const _queryParams: Record = {}; + if (order != null) { + _queryParams["order"] = order; + } + + if (limit != null) { + _queryParams["limit"] = limit.toString(); + } + + if (paginationToken != null) { + _queryParams["pagination_token"] = paginationToken; + } + + if (sort != null) { + _queryParams["sort"] = sort; + } + + if (createdAtGt != null) { + _queryParams["created_at__gt"] = createdAtGt; + } + + if (createdAtLt != null) { + _queryParams["created_at__lt"] = createdAtLt; + } + + if (createdAtGte != null) { + _queryParams["created_at__gte"] = createdAtGte; + } + + if (createdAtLte != null) { + _queryParams["created_at__lte"] = createdAtLte; + } + + if (idIn != null) { + if (Array.isArray(idIn)) { + _queryParams["id__in"] = idIn.map((item) => item); + } else { + _queryParams["id__in"] = idIn; + } + } + + if (currency != null) { + _queryParams["currency"] = currency; + } + + if (documentId != null) { + _queryParams["document_id"] = documentId; + } + + if (documentIdContains != null) { + _queryParams["document_id__contains"] = documentIdContains; + } + + if (documentIdIcontains != null) { + _queryParams["document_id__icontains"] = documentIdIcontains; + } + + if (totalAmountGt != null) { + _queryParams["total_amount__gt"] = totalAmountGt.toString(); + } + + if (totalAmountLt != null) { + _queryParams["total_amount__lt"] = totalAmountLt.toString(); + } + + if (totalAmountGte != null) { + _queryParams["total_amount__gte"] = totalAmountGte.toString(); + } + + if (totalAmountLte != null) { + _queryParams["total_amount__lte"] = totalAmountLte.toString(); + } + + if (hasFile != null) { + _queryParams["has_file"] = hasFile.toString(); + } + + if (hasTransaction != null) { + _queryParams["has_transaction"] = hasTransaction.toString(); + } + + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "receipts", + ), + method: "GET", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptPaginationResponse, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /receipts."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {Monite.ReceiptCreateSchema} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.postReceipts() + */ + public postReceipts( + request: Monite.ReceiptCreateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postReceipts(request, requestOptions)); + } + + private async __postReceipts( + request: Monite.ReceiptCreateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "receipts", + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling POST /receipts."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Upload an incoming receipt in PDF, PNG, or JPEG format and scan its contents. The maximum file size is 20MB. + * + * @param {Monite.ReceiptUploadFile} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * import { createReadStream } from "fs"; + * await client.receipts.postReceiptsUploadFromFile({ + * file: fs.createReadStream("/path/to/your/file") + * }) + */ + public postReceiptsUploadFromFile( + request: Monite.ReceiptUploadFile, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postReceiptsUploadFromFile(request, requestOptions)); + } + + private async __postReceiptsUploadFromFile( + request: Monite.ReceiptUploadFile, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + const _request = await core.newFormData(); + await _request.appendFile("file", request.file); + const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "receipts/upload_from_file", + ), + method: "POST", + headers: _headers, + queryParameters: requestOptions?.queryParams, + requestType: "file", + duplex: _maybeEncodedRequest.duplex, + body: _maybeEncodedRequest.body, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling POST /receipts/upload_from_file."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.getReceiptsId("receipt_id") + */ + public getReceiptsId( + receiptId: string, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getReceiptsId(receiptId, requestOptions)); + } + + private async __getReceiptsId( + receiptId: string, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}`, + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /receipts/{receipt_id}."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.deleteReceiptsId("receipt_id") + */ + public deleteReceiptsId( + receiptId: string, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__deleteReceiptsId(receiptId, requestOptions)); + } + + private async __deleteReceiptsId( + receiptId: string, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}`, + ), + method: "DELETE", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling DELETE /receipts/{receipt_id}."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {Monite.ReceiptUpdateSchema} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.patchReceiptsId("receipt_id") + */ + public patchReceiptsId( + receiptId: string, + request: Monite.ReceiptUpdateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__patchReceiptsId(receiptId, request, requestOptions)); + } + + private async __patchReceiptsId( + receiptId: string, + request: Monite.ReceiptUpdateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}`, + ), + method: "PATCH", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling PATCH /receipts/{receipt_id}."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Attach file to receipt without existing attachment. + * + * @param {string} receiptId + * @param {Monite.ReceiptAttachFile} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * import { createReadStream } from "fs"; + * await client.receipts.postReceiptsIdAttachFile("receipt_id", { + * file: fs.createReadStream("/path/to/your/file") + * }) + */ + public postReceiptsIdAttachFile( + receiptId: string, + request: Monite.ReceiptAttachFile, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__postReceiptsIdAttachFile(receiptId, request, requestOptions), + ); + } + + private async __postReceiptsIdAttachFile( + receiptId: string, + request: Monite.ReceiptAttachFile, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + const _request = await core.newFormData(); + await _request.appendFile("file", request.file); + const _maybeEncodedRequest = await _request.getRequest(); + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + ..._maybeEncodedRequest.headers, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}/attach_file`, + ), + method: "POST", + headers: _headers, + queryParameters: requestOptions?.queryParams, + requestType: "file", + duplex: _maybeEncodedRequest.duplex, + body: _maybeEncodedRequest.body, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling POST /receipts/{receipt_id}/attach_file.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {Monite.GetReceiptsIdLineItemsRequest} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.getReceiptsIdLineItems("receipt_id") + */ + public getReceiptsIdLineItems( + receiptId: string, + request: Monite.GetReceiptsIdLineItemsRequest = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__getReceiptsIdLineItems(receiptId, request, requestOptions)); + } + + private async __getReceiptsIdLineItems( + receiptId: string, + request: Monite.GetReceiptsIdLineItemsRequest = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + const { + order, + limit, + pagination_token: paginationToken, + sort, + created_at__gt: createdAtGt, + created_at__lt: createdAtLt, + created_at__gte: createdAtGte, + created_at__lte: createdAtLte, + name, + name__iexact: nameIexact, + name__contains: nameContains, + name__icontains: nameIcontains, + total__gt: totalGt, + total__lt: totalLt, + total__gte: totalGte, + total__lte: totalLte, + created_by_user_id: createdByUserId, + } = request; + const _queryParams: Record = {}; + if (order != null) { + _queryParams["order"] = order; + } + + if (limit != null) { + _queryParams["limit"] = limit.toString(); + } + + if (paginationToken != null) { + _queryParams["pagination_token"] = paginationToken; + } + + if (sort != null) { + _queryParams["sort"] = sort; + } + + if (createdAtGt != null) { + _queryParams["created_at__gt"] = createdAtGt; + } + + if (createdAtLt != null) { + _queryParams["created_at__lt"] = createdAtLt; + } + + if (createdAtGte != null) { + _queryParams["created_at__gte"] = createdAtGte; + } + + if (createdAtLte != null) { + _queryParams["created_at__lte"] = createdAtLte; + } + + if (name != null) { + _queryParams["name"] = name; + } + + if (nameIexact != null) { + _queryParams["name__iexact"] = nameIexact; + } + + if (nameContains != null) { + _queryParams["name__contains"] = nameContains; + } + + if (nameIcontains != null) { + _queryParams["name__icontains"] = nameIcontains; + } + + if (totalGt != null) { + _queryParams["total__gt"] = totalGt.toString(); + } + + if (totalLt != null) { + _queryParams["total__lt"] = totalLt.toString(); + } + + if (totalGte != null) { + _queryParams["total__gte"] = totalGte.toString(); + } + + if (totalLte != null) { + _queryParams["total__lte"] = totalLte.toString(); + } + + if (createdByUserId != null) { + _queryParams["created_by_user_id"] = createdByUserId; + } + + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}/line_items`, + ), + method: "GET", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: _response.body as Monite.ReceiptLineItemsPaginationResponse, + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling GET /receipts/{receipt_id}/line_items.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {Monite.ReceiptLineItemCreateSchema} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.postReceiptsIdLineItems("receipt_id") + */ + public postReceiptsIdLineItems( + receiptId: string, + request: Monite.ReceiptLineItemCreateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postReceiptsIdLineItems(receiptId, request, requestOptions)); + } + + private async __postReceiptsIdLineItems( + receiptId: string, + request: Monite.ReceiptLineItemCreateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}/line_items`, + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptLineItemResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling POST /receipts/{receipt_id}/line_items.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {string} lineItemId + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.deleteReceiptsIdLineItemsId("receipt_id", "line_item_id") + */ + public deleteReceiptsIdLineItemsId( + receiptId: string, + lineItemId: string, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__deleteReceiptsIdLineItemsId(receiptId, lineItemId, requestOptions), + ); + } + + private async __deleteReceiptsIdLineItemsId( + receiptId: string, + lineItemId: string, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}/line_items/${encodeURIComponent(lineItemId)}`, + ), + method: "DELETE", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling DELETE /receipts/{receipt_id}/line_items/{line_item_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} receiptId + * @param {string} lineItemId + * @param {Monite.ReceiptLineItemUpdateSchema} request + * @param {Receipts.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receipts.patchReceiptsIdLineItemsId("receipt_id", "line_item_id") + */ + public patchReceiptsIdLineItemsId( + receiptId: string, + lineItemId: string, + request: Monite.ReceiptLineItemUpdateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__patchReceiptsIdLineItemsId(receiptId, lineItemId, request, requestOptions), + ); + } + + private async __patchReceiptsIdLineItemsId( + receiptId: string, + lineItemId: string, + request: Monite.ReceiptLineItemUpdateSchema = {}, + requestOptions?: Receipts.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `receipts/${encodeURIComponent(receiptId)}/line_items/${encodeURIComponent(lineItemId)}`, + ), + method: "PATCH", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceiptLineItemResponseSchema, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling PATCH /receipts/{receipt_id}/line_items/{line_item_id}.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } +} diff --git a/src/api/resources/receipts/client/index.ts b/src/api/resources/receipts/client/index.ts new file mode 100644 index 0000000..82648c6 --- /dev/null +++ b/src/api/resources/receipts/client/index.ts @@ -0,0 +1,2 @@ +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/receipts/client/requests/GetReceiptsIdLineItemsRequest.ts b/src/api/resources/receipts/client/requests/GetReceiptsIdLineItemsRequest.ts new file mode 100644 index 0000000..4a8dc78 --- /dev/null +++ b/src/api/resources/receipts/client/requests/GetReceiptsIdLineItemsRequest.ts @@ -0,0 +1,37 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface GetReceiptsIdLineItemsRequest { + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ + order?: Monite.OrderEnum; + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ + limit?: number; + /** + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. + */ + pagination_token?: string; + /** The field to sort the results by. Typically used together with the `order` parameter. */ + sort?: Monite.ReceiptLineItemCursorFields; + created_at__gt?: string; + created_at__lt?: string; + created_at__gte?: string; + created_at__lte?: string; + name?: string; + name__iexact?: string; + name__contains?: string; + name__icontains?: string; + total__gt?: number; + total__lt?: number; + total__gte?: number; + total__lte?: number; + created_by_user_id?: string; +} diff --git a/src/api/resources/receipts/client/requests/GetReceiptsRequest.ts b/src/api/resources/receipts/client/requests/GetReceiptsRequest.ts new file mode 100644 index 0000000..f1822c1 --- /dev/null +++ b/src/api/resources/receipts/client/requests/GetReceiptsRequest.ts @@ -0,0 +1,39 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface GetReceiptsRequest { + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ + order?: Monite.OrderEnum; + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ + limit?: number; + /** + * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. + */ + pagination_token?: string; + /** The field to sort the results by. Typically used together with the `order` parameter. */ + sort?: Monite.ReceiptCursorFields; + created_at__gt?: string; + created_at__lt?: string; + created_at__gte?: string; + created_at__lte?: string; + id__in?: string | string[]; + currency?: Monite.CurrencyEnum; + document_id?: string; + document_id__contains?: string; + document_id__icontains?: string; + total_amount__gt?: number; + total_amount__lt?: number; + total_amount__gte?: number; + total_amount__lte?: number; + has_file?: boolean; + has_transaction?: boolean; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptAttachFile.ts b/src/api/resources/receipts/client/requests/ReceiptAttachFile.ts new file mode 100644 index 0000000..c1bb1d7 --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptAttachFile.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + +/** + * @example + * { + * file: fs.createReadStream("/path/to/your/file") + * } + */ +export interface ReceiptAttachFile { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptCreateSchema.ts b/src/api/resources/receipts/client/requests/ReceiptCreateSchema.ts new file mode 100644 index 0000000..57596f0 --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptCreateSchema.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface ReceiptCreateSchema { + /** Base64-encoded contents of the original receipt file. */ + base64_encoded_file?: string; + /** Currency code used in the receipt. */ + currency?: Monite.CurrencyEnum; + /** Unique receipt number assigned by the issuer. */ + document_id?: string; + /** Receipt issued date and time. */ + issued_at?: string; + /** Location of the merchant. */ + merchant_location?: string; + /** Name of the merchant. */ + merchant_name?: string; + /** Total amount for the receipt in minor units (e.g. cents). */ + total_amount?: number; + /** Transaction ID. */ + transaction_id?: string; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptLineItemCreateSchema.ts b/src/api/resources/receipts/client/requests/ReceiptLineItemCreateSchema.ts new file mode 100644 index 0000000..660f061 --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptLineItemCreateSchema.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * {} + */ +export interface ReceiptLineItemCreateSchema { + /** Accounting tax rate ID. */ + accounting_tax_rate_id?: string; + /** Cost center ID. */ + cost_center_id?: string; + /** General ledger ID. */ + general_ledger_id?: string; + /** Line item name/description. */ + name?: string; + /** Line item total in minor units. */ + total?: number; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptLineItemUpdateSchema.ts b/src/api/resources/receipts/client/requests/ReceiptLineItemUpdateSchema.ts new file mode 100644 index 0000000..e1f8b23 --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptLineItemUpdateSchema.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * @example + * {} + */ +export interface ReceiptLineItemUpdateSchema { + /** Accounting tax rate ID. */ + accounting_tax_rate_id?: string; + /** Cost center ID. */ + cost_center_id?: string; + /** General ledger ID. */ + general_ledger_id?: string; + /** Line item name/description. */ + name?: string; + /** Line item total in minor units. */ + total?: number; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptUpdateSchema.ts b/src/api/resources/receipts/client/requests/ReceiptUpdateSchema.ts new file mode 100644 index 0000000..324402b --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptUpdateSchema.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * {} + */ +export interface ReceiptUpdateSchema { + /** Base64-encoded file contents. */ + base64_encoded_file?: string; + /** Currency code. */ + currency?: Monite.CurrencyEnum; + /** Receipt number. */ + document_id?: string; + /** Date when the receipt was issued. */ + issued_at?: string; + /** Merchant location. */ + merchant_location?: string; + /** Merchant name. */ + merchant_name?: string; + /** Total amount. */ + total_amount?: number; + /** Transaction ID. */ + transaction_id?: string; +} diff --git a/src/api/resources/receipts/client/requests/ReceiptUploadFile.ts b/src/api/resources/receipts/client/requests/ReceiptUploadFile.ts new file mode 100644 index 0000000..0abab65 --- /dev/null +++ b/src/api/resources/receipts/client/requests/ReceiptUploadFile.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as fs from "fs"; +import * as core from "../../../../../core/index.js"; + +/** + * @example + * { + * file: fs.createReadStream("/path/to/your/file") + * } + */ +export interface ReceiptUploadFile { + file: core.file.Uploadable.FileLike; +} diff --git a/src/api/resources/receipts/client/requests/index.ts b/src/api/resources/receipts/client/requests/index.ts new file mode 100644 index 0000000..64b1c6f --- /dev/null +++ b/src/api/resources/receipts/client/requests/index.ts @@ -0,0 +1,8 @@ +export { type GetReceiptsRequest } from "./GetReceiptsRequest.js"; +export { type ReceiptCreateSchema } from "./ReceiptCreateSchema.js"; +export { type ReceiptUploadFile } from "./ReceiptUploadFile.js"; +export { type ReceiptUpdateSchema } from "./ReceiptUpdateSchema.js"; +export { type ReceiptAttachFile } from "./ReceiptAttachFile.js"; +export { type GetReceiptsIdLineItemsRequest } from "./GetReceiptsIdLineItemsRequest.js"; +export { type ReceiptLineItemCreateSchema } from "./ReceiptLineItemCreateSchema.js"; +export { type ReceiptLineItemUpdateSchema } from "./ReceiptLineItemUpdateSchema.js"; diff --git a/src/api/resources/receipts/index.ts b/src/api/resources/receipts/index.ts new file mode 100644 index 0000000..914b8c3 --- /dev/null +++ b/src/api/resources/receipts/index.ts @@ -0,0 +1 @@ +export * from "./client/index.js"; diff --git a/src/api/resources/receivables/client/Client.ts b/src/api/resources/receivables/client/Client.ts index 9c8d43c..fb56e62 100644 --- a/src/api/resources/receivables/client/Client.ts +++ b/src/api/resources/receivables/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Receivables { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Receivables { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Receivables { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Receivables { - constructor(protected readonly _options: Receivables.Options) {} + protected readonly _options: Receivables.Options; + + constructor(_options: Receivables.Options) { + this._options = _options; + } /** * Returns a list of [accounts receivable](https://docs.monite.com/accounts-receivable/index) documents - invoices, quotes, and credit notes - of the specified entity. @@ -112,11 +120,12 @@ export class Receivables { * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.get() @@ -166,6 +175,11 @@ export class Receivables { total_amount__lt: totalAmountLt, total_amount__gte: totalAmountGte, total_amount__lte: totalAmountLte, + discounted_subtotal: discountedSubtotal, + discounted_subtotal__gt: discountedSubtotalGt, + discounted_subtotal__lt: discountedSubtotalLt, + discounted_subtotal__gte: discountedSubtotalGte, + discounted_subtotal__lte: discountedSubtotalLte, status, entity_user_id: entityUserId, based_on: basedOn, @@ -340,6 +354,26 @@ export class Receivables { _queryParams["total_amount__lte"] = totalAmountLte.toString(); } + if (discountedSubtotal != null) { + _queryParams["discounted_subtotal"] = discountedSubtotal.toString(); + } + + if (discountedSubtotalGt != null) { + _queryParams["discounted_subtotal__gt"] = discountedSubtotalGt.toString(); + } + + if (discountedSubtotalLt != null) { + _queryParams["discounted_subtotal__lt"] = discountedSubtotalLt.toString(); + } + + if (discountedSubtotalGte != null) { + _queryParams["discounted_subtotal__gte"] = discountedSubtotalGte.toString(); + } + + if (discountedSubtotalLte != null) { + _queryParams["discounted_subtotal__lte"] = discountedSubtotalLte.toString(); + } + if (status != null) { _queryParams["status"] = status; } @@ -372,32 +406,25 @@ export class Receivables { _queryParams["project_id"] = projectId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "receivables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -410,6 +437,8 @@ export class Receivables { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 406: @@ -418,8 +447,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -456,18 +485,51 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.create({ - * counterpart_billing_address_id: "counterpart_billing_address_id", - * counterpart_id: "counterpart_id", - * currency: "AED", + * based_on: "based_on", + * type: "invoice" + * }) + * + * @example + * await client.receivables.create({ + * counterpart_billing_address_id: "1323853c-0837-4a5c-8dc4-f7cb57a3efaa", + * counterpart_id: "34fab7ce-8cca-432a-a8a6-7e8a522e3351", + * counterpart_vat_id_id: "8cf9c135-8e27-4212-ad16-defed9222697", + * currency: "EUR", + * entity_bank_account_id: "5090ecd6-b0ab-40e5-a93e-4d966a3c6f3f", + * entity_vat_id_id: "439ea658-7096-49c8-8716-d62e8c2a2ed9", + * expiry_date: "2024-08-30", * line_items: [{ - * quantity: 1.1 + * product: { + * measure_unit: { + * name: "pcs." + * }, + * name: "LG WH1000XM Monitor", + * price: { + * currency: "EUR", + * value: 25000 + * } + * }, + * quantity: 5, + * vat_rate_id: "83908278-841d-4d47-bcd5-97e989201409" * }], * type: "quote" * }) + * + * @example + * await client.receivables.create({ + * based_on: "e78de69c-c789-44ef-80bf-474b9e63b91d", + * type: "invoice" + * }) + * + * @example + * await client.receivables.create({ + * based_on: "e977db242-e7d5-4d2e-83cf-a1f5051ed40a", + * type: "credit_note" + * }) */ public create( request: Monite.ReceivableFacadeCreatePayload, @@ -480,30 +542,26 @@ export class Receivables { request: Monite.ReceivableFacadeCreatePayload, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "receivables", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -528,8 +586,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -562,8 +620,9 @@ export class Receivables { * @param {Monite.GetReceivablesRequiredFieldsRequest} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getReceivablesRequiredFields() @@ -612,46 +671,144 @@ export class Receivables { _queryParams["counterpart_vat_id_id"] = counterpartVatIdId; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "receivables/required_fields", ), method: "GET", - headers: { + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body as Monite.ReceivableRequiredFields, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /receivables/required_fields."); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * This is a POST version of the `GET /receivables` endpoint. Use it to send search and filter parameters in the request body instead of the URL query string in case the query is too long and exceeds the URL length limit of your HTTP client. + * + * @param {Monite.ReceivablesSearchRequest} request + * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotAcceptableError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receivables.postReceivablesSearch({ + * status: "draft", + * type: "invoice" + * }) + */ + public postReceivablesSearch( + request: Monite.ReceivablesSearchRequest = {}, + requestOptions?: Receivables.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postReceivablesSearch(request, requestOptions)); + } + + private async __postReceivablesSearch( + request: Monite.ReceivablesSearchRequest = {}, + requestOptions?: Receivables.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + "receivables/search", + ), + method: "POST", + headers: _headers, contentType: "application/json", - queryParameters: _queryParams, + queryParameters: requestOptions?.queryParams, requestType: "json", + body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Monite.ReceivableRequiredFields, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.ReceivablePaginationResponse, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 406: + throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -669,7 +826,7 @@ export class Receivables { rawResponse: _response.rawResponse, }); case "timeout": - throw new errors.MoniteTimeoutError("Timeout exceeded when calling GET /receivables/required_fields."); + throw new errors.MoniteTimeoutError("Timeout exceeded when calling POST /receivables/search."); case "unknown": throw new errors.MoniteError({ message: _response.error.errorMessage, @@ -683,10 +840,11 @@ export class Receivables { * * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getVariables() @@ -700,31 +858,25 @@ export class Receivables { private async __getVariables( requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "receivables/variables", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -738,14 +890,16 @@ export class Receivables { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -773,7 +927,13 @@ export class Receivables { } /** - * @param {string} receivableId + * Returns the details of an existing accounts receivable invoice, quote, or credit note with the specified ID. + * + * The response fields vary depending on the document type. Use the `type` field to distinguish between different document types. + * + * Entity users with the `receivable.read.allowed_for_own` permission (rather than `allowed`) can access only documents that they created themselves. + * + * @param {string} receivableId - ID of an existing invoice, quote, or credit note that you want to retrieve. * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} @@ -781,7 +941,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getById("receivable_id") @@ -797,31 +957,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -842,8 +996,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -880,7 +1034,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.deleteById("receivable_id") @@ -896,31 +1050,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -943,8 +1091,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -984,7 +1132,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.updateById("receivable_id", { @@ -1004,30 +1152,26 @@ export class Receivables { request: Monite.ReceivableUpdatePayload, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1052,8 +1196,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1083,6 +1227,10 @@ export class Receivables { } /** + * Only quotes in the `issued` status can be accepted. + * + * When a quote is accepted, Monite automatically creates a draft invoice based on this quote. To find the newly created invoice, use `GET /receivables?based_on=QUOTE_ID`. + * * @param {string} receivableId * @param {Monite.QuoteAcceptRequest} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. @@ -1093,7 +1241,16 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.receivables.acceptById("receivable_id", { + * signature: { + * email: "theo@example.com", + * full_name: "Theo Quinn", + * signature_image: "iVBORw0KGgoAAAANSUhEUg.....AAABJRU5ErkJggg==" + * } + * }) * * @example * await client.receivables.acceptById("receivable_id") @@ -1111,30 +1268,26 @@ export class Receivables { request: Monite.QuoteAcceptRequest = {}, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/accept`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1159,8 +1312,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1199,7 +1352,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.cancelById("receivable_id") @@ -1215,31 +1368,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1262,8 +1409,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1293,7 +1440,18 @@ export class Receivables { } /** - * @param {string} receivableId + * Creates a copy of an existing accounts receivable invoice or quote. The original document can be in any status. The cloned document will have the `draft` status. + * + * Cloning a document requires that all of the referenced resource IDs (counterpart ID, product IDs, and others) still exist. + * + * Most of the original document's data is copied as is, with a few exceptions: + * + * * Some fields are not copied: `attachments`, `document_id`, `issue_date`, quote `expiry_date`. + * * Counterpart details, entity bank account details, and entity VAT number are fetched anew from their corresponding IDs. + * This means, for example, that if the counterpart details have been changed since the original invoice or quote was created, + * the cloned document will use the current counterpart details rather than the old details from the original document. + * + * @param {string} receivableId - ID of an existing invoice or quote that you want to clone. * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} @@ -1302,7 +1460,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.cloneById("receivable_id") @@ -1318,31 +1476,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/clone`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1365,8 +1517,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1396,6 +1548,8 @@ export class Receivables { } /** + * Only quotes in the `issued` status can be declined. + * * @param {string} receivableId * @param {Monite.ReceivableDeclinePayload} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. @@ -1406,7 +1560,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.declineById("receivable_id") @@ -1424,30 +1578,26 @@ export class Receivables { request: Monite.ReceivableDeclinePayload = {}, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/decline`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1472,8 +1622,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1516,7 +1666,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getHistory("receivable_id") @@ -1595,32 +1745,25 @@ export class Receivables { _queryParams["timestamp__lte"] = timestampLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/history`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1644,8 +1787,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1686,7 +1829,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getHistoryById("receivable_history_id", "receivable_id") @@ -1706,31 +1849,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/history/${encodeURIComponent(receivableHistoryId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1751,8 +1888,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1791,7 +1928,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.issueById("receivable_id") @@ -1807,31 +1944,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/issue`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1854,8 +1985,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -1897,7 +2028,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.updateLineItemsById("receivable_id", { @@ -1919,30 +2050,26 @@ export class Receivables { request: Monite.UpdateLineItems, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/line_items`, ), method: "PUT", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1967,8 +2094,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2007,7 +2134,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getMails("receivable_id") @@ -2082,32 +2209,25 @@ export class Receivables { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/mails`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2131,8 +2251,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2171,7 +2291,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getMailById("receivable_id", "mail_id") @@ -2189,31 +2309,25 @@ export class Receivables { mailId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/mails/${encodeURIComponent(mailId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2234,8 +2348,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2275,7 +2389,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.markAsPaidById("receivable_id") @@ -2293,30 +2407,26 @@ export class Receivables { request: Monite.ReceivablePaidPayload = {}, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/mark_as_paid`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2341,8 +2451,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2384,7 +2494,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.markAsPartiallyPaidById("receivable_id", { @@ -2406,30 +2516,26 @@ export class Receivables { request: Monite.ReceivablePartiallyPaidPayload, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/mark_as_partially_paid`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2454,8 +2560,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2495,7 +2601,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.markAsUncollectibleById("receivable_id") @@ -2515,30 +2621,26 @@ export class Receivables { request: Monite.ReceivableUncollectiblePayload = {}, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/mark_as_uncollectible`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2563,8 +2665,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2602,7 +2704,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.getPdfLinkById("receivable_id") @@ -2618,31 +2720,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/pdf_link`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -2663,8 +2759,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2694,6 +2790,13 @@ export class Receivables { } /** + * You can preview emails only for documents in the following statuses: + * + * * Invoices: `draft`, `issued`, `overdue`, `partially_paid`, `paid`. + * In the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance): also `canceled`. + * * Quotes: `draft`, `issued`. + * * Credit notes: `draft`, `issued`. + * * @param {string} receivableId * @param {Monite.ReceivablePreviewRequest} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. @@ -2703,7 +2806,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.previewById("receivable_id", { @@ -2724,30 +2827,26 @@ export class Receivables { request: Monite.ReceivablePreviewRequest, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/preview`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2770,8 +2869,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2801,6 +2900,17 @@ export class Receivables { } /** + * Only documents in the following statuses can be sent via email: + * + * * Invoices: `draft`, `issued`, `overdue`, `partially_paid`, `paid`. + * In the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance): also `canceled`. + * * Quotes: `draft`, `issued`. + * * Credit notes: `draft`, `issued`. + * + * Draft documents are automatically moved to the `issued` status before sending. + * + * For more information, see [Send an invoice via email](https://docs.monite.com/accounts-receivable/invoices/create#send-via-email). + * * @param {string} receivableId * @param {Monite.ReceivableSendRequest} request * @param {Receivables.RequestOptions} requestOptions - Request-specific configuration. @@ -2811,7 +2921,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.sendById("receivable_id", { @@ -2832,30 +2942,26 @@ export class Receivables { request: Monite.ReceivableSendRequest, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/send`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2880,8 +2986,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -2921,7 +3027,7 @@ export class Receivables { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.sendTestReminderById("receivable_id", { @@ -2941,30 +3047,26 @@ export class Receivables { request: Monite.ReceivableSendTestReminderPayload, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/send_test_reminder`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -2989,8 +3091,8 @@ export class Receivables { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -3028,7 +3130,7 @@ export class Receivables { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.receivables.verifyById("receivable_id") @@ -3044,31 +3146,25 @@ export class Receivables { receivableId: string, requestOptions?: Receivables.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `receivables/${encodeURIComponent(receivableId)}/verify`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -3089,8 +3185,8 @@ export class Receivables { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/receivables/client/index.ts b/src/api/resources/receivables/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/receivables/client/index.ts +++ b/src/api/resources/receivables/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/receivables/client/requests/GetReceivablesRequiredFieldsRequest.ts b/src/api/resources/receivables/client/requests/GetReceivablesRequiredFieldsRequest.ts index e793646..d310b31 100644 --- a/src/api/resources/receivables/client/requests/GetReceivablesRequiredFieldsRequest.ts +++ b/src/api/resources/receivables/client/requests/GetReceivablesRequiredFieldsRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/receivables/client/requests/QuoteAcceptRequest.ts b/src/api/resources/receivables/client/requests/QuoteAcceptRequest.ts index 108cb57..1b34943 100644 --- a/src/api/resources/receivables/client/requests/QuoteAcceptRequest.ts +++ b/src/api/resources/receivables/client/requests/QuoteAcceptRequest.ts @@ -2,13 +2,22 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** + * @example + * { + * signature: { + * email: "theo@example.com", + * full_name: "Theo Quinn", + * signature_image: "iVBORw0KGgoAAAANSUhEUg.....AAABJRU5ErkJggg==" + * } + * } + * * @example * {} */ export interface QuoteAcceptRequest { - /** A digital signature, if required for quote acceptance */ + /** The counterpart's signature. Required if the quote field `signature_required` is `true`. */ signature?: Monite.Signature; } diff --git a/src/api/resources/receivables/client/requests/ReceivablePreviewRequest.ts b/src/api/resources/receivables/client/requests/ReceivablePreviewRequest.ts index ca7b7d5..a457aed 100644 --- a/src/api/resources/receivables/client/requests/ReceivablePreviewRequest.ts +++ b/src/api/resources/receivables/client/requests/ReceivablePreviewRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/receivables/client/requests/ReceivableSendRequest.ts b/src/api/resources/receivables/client/requests/ReceivableSendRequest.ts index f3d4e9c..e9e0198 100644 --- a/src/api/resources/receivables/client/requests/ReceivableSendRequest.ts +++ b/src/api/resources/receivables/client/requests/ReceivableSendRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/receivables/client/requests/ReceivableSendTestReminderPayload.ts b/src/api/resources/receivables/client/requests/ReceivableSendTestReminderPayload.ts index 8c29b4c..ee271db 100644 --- a/src/api/resources/receivables/client/requests/ReceivableSendTestReminderPayload.ts +++ b/src/api/resources/receivables/client/requests/ReceivableSendTestReminderPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/receivables/client/requests/ReceivablesGetHistoryRequest.ts b/src/api/resources/receivables/client/requests/ReceivablesGetHistoryRequest.ts index 8ee3f87..cd7c898 100644 --- a/src/api/resources/receivables/client/requests/ReceivablesGetHistoryRequest.ts +++ b/src/api/resources/receivables/client/requests/ReceivablesGetHistoryRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ReceivablesGetHistoryRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface ReceivablesGetHistoryRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ReceivableHistoryCursorFields; /** * Return only the specified [event types](https://docs.monite.com/accounts-receivable/document-history#event-types). To include multiple types, repeat this parameter for each value: @@ -37,20 +31,12 @@ export interface ReceivablesGetHistoryRequest { * `entity_user_id__in=&entity_user_id__in=` */ entity_user_id__in?: string | string[]; - /** - * Return only events that occurred after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. - */ + /** Return only events that occurred after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ timestamp__gt?: string; - /** - * Return only events that occurred before the specified date and time. - */ + /** Return only events that occurred before the specified date and time. */ timestamp__lt?: string; - /** - * Return only events that occurred on or after the specified date and time. - */ + /** Return only events that occurred on or after the specified date and time. */ timestamp__gte?: string; - /** - * Return only events that occurred before or on the specified date and time. - */ + /** Return only events that occurred before or on the specified date and time. */ timestamp__lte?: string; } diff --git a/src/api/resources/receivables/client/requests/ReceivablesGetMailsRequest.ts b/src/api/resources/receivables/client/requests/ReceivablesGetMailsRequest.ts index 437ca9d..fc55d09 100644 --- a/src/api/resources/receivables/client/requests/ReceivablesGetMailsRequest.ts +++ b/src/api/resources/receivables/client/requests/ReceivablesGetMailsRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ReceivablesGetMailsRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface ReceivablesGetMailsRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ReceivableMailCursorFields; status?: Monite.ReceivableMailStatusEnum; status__in?: Monite.ReceivableMailStatusEnum | Monite.ReceivableMailStatusEnum[]; diff --git a/src/api/resources/receivables/client/requests/ReceivablesGetRequest.ts b/src/api/resources/receivables/client/requests/ReceivablesGetRequest.ts index a675ec8..74c9419 100644 --- a/src/api/resources/receivables/client/requests/ReceivablesGetRequest.ts +++ b/src/api/resources/receivables/client/requests/ReceivablesGetRequest.ts @@ -2,16 +2,14 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface ReceivablesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; /** * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. @@ -48,9 +46,7 @@ export interface ReceivablesGetRequest { * IDs of deleted users will still produce results here if those users had associated receivables. Valid but nonexistent user IDs do not raise errors but produce no results. */ entity_user_id__in?: string | string[]; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.ReceivableCursorFields; /** * Return only receivables whose [tags](https://docs.monite.com/common/tags) include at least one of the tags with the specified IDs. @@ -116,37 +112,114 @@ export interface ReceivablesGetRequest { * `product_ids=&product_ids=` will return receivables 3 and 5. */ product_ids?: string | string[]; - /** - * Return only receivables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. - */ + /** Return only receivables whose `project_id` include at least one of the project_id with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ project_id__in?: string | string[]; + /** Return only receivables of the specified type. Use this parameter to get only invoices, or only quotes, or only credit notes. */ type?: Monite.ReceivableType; + /** Return a receivable with the exact specified document number (case-sensitive). The `document_id` is the user-facing document number such as INV-00042, not to be confused with Monite resource IDs (`id`). */ document_id?: string; + /** Return only receivables whose document number (`document_id`) contains the specified string (case-sensitive). */ document_id__contains?: string; + /** Return only receivables whose document number (`document_id`) contains the specified string (case-insensitive). */ document_id__icontains?: string; + /** Return only non-draft receivables that were issued after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ issue_date__gt?: string; + /** Return only non-draft receivables that were issued before the specified date and time. */ issue_date__lt?: string; + /** Return only non-draft receivables that were issued on or after the specified date and time. */ issue_date__gte?: string; + /** Return only non-draft receivables that were issued before or on the specified date and time. */ issue_date__lte?: string; + /** Return only receivables created after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ created_at__gt?: string; + /** Return only receivables created before the specified date and time. */ created_at__lt?: string; + /** Return only receivables created on or after the specified date and time. */ created_at__gte?: string; + /** Return only receivables created before or on the specified date and time. */ created_at__lte?: string; + /** + * Return only receivables created for the counterpart with the specified ID. + * + * Counterparts that have been deleted but have associated receivables will still return results here because the receivables contain a frozen copy of the counterpart data. + * + * If the specified counterpart ID does not exist and never existed, no results are returned. + */ counterpart_id?: string; + /** Return only receivables created for counterparts with the specified name (exact match, case-sensitive). For counterparts of `type` = `individual`, the full name is formatted as `first_name last_name`. */ counterpart_name?: string; + /** Return only receivables created for counterparts whose name contains the specified string (case-sensitive). */ counterpart_name__contains?: string; + /** Return only receivables created for counterparts whose name contains the specified string (case-insensitive). */ counterpart_name__icontains?: string; + /** Return only receivables with the exact specified total amount. The amount must be specified in the [minor units](https://docs.monite.com/references/currencies#minor-units) of currency. For example, $12.5 is represented as 1250." */ total_amount?: number; + /** Return only receivables whose total amount (in minor units) exceeds the specified value. */ total_amount__gt?: number; + /** Return only receivables whose total amount (in minor units) is less than the specified value. */ total_amount__lt?: number; + /** Return only receivables whose total amount (in minor units) is greater than or equal to the specified value. */ total_amount__gte?: number; + /** Return only receivables whose total amount (in minor units) is less than or equal to the specified value. */ total_amount__lte?: number; + /** Return only receivables with the exact specified discounted subtotal. The amount must be specified in the [minor units](https://docs.monite.com/references/currencies#minor-units) of currency. For example, $12.5 is represented as 1250. */ + discounted_subtotal?: number; + /** Return only receivables whose discounted subtotal (in minor units) is greater than the specified value. */ + discounted_subtotal__gt?: number; + /** Return only receivables whose discounted subtotal (in minor units) is less than the specified value. */ + discounted_subtotal__lt?: number; + /** Return only receivables whose discounted subtotal (in minor units) is greater than or equal to the specified value. */ + discounted_subtotal__gte?: number; + /** Return only receivables whose discounted subtotal (in minor units) is less than or equal to the specified value. */ + discounted_subtotal__lte?: number; + /** + * Return only receivables that have the specified status. See the applicable [invoice statuses](https://docs.monite.com/accounts-receivable/invoices/index), [quote statuses](https://docs.monite.com/accounts-receivable/quotes/index), and [credit note statuses](https://docs.monite.com/accounts-receivable/credit-notes#credit-note-lifecycle). + * + * To query multiple statuses at once, use the `status__in` parameter instead. + */ status?: Monite.ReceivablesGetRequestStatus; + /** + * Return only receivables created by the entity users with the specified IDs. To specify multiple user IDs, repeat this parameter for each ID: + * `entity_user_id__in=&entity_user_id__in=` + * + * If the request is authenticated using an entity user token, this user must have the `receivable.read.allowed` (rather than `allowed_for_own`) permission to be able to query receivables created by other users. + * + * IDs of deleted users will still produce results here if those users had associated receivables. Valid but nonexistent user IDs do not raise errors but produce no results. + */ entity_user_id?: string; + /** + * This parameter accepts a quote ID or an invoice ID. + * + * * Specify a quote ID to find invoices created from this quote. + * * Specify an invoice ID to find credit notes created for this invoice or find recurring invoices created from a base invoice. + * + * Valid but nonexistent IDs do not raise errors but produce no results. + */ based_on?: string; + /** + * Return invoices that are due after the specified date (exclusive, `YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ due_date__gt?: string; + /** + * Return invoices that are due before the specified date (exclusive, `YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ due_date__lt?: string; + /** + * Return invoices that are due on or after the specified date (`YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ due_date__gte?: string; + /** + * Return invoices that are due before or on the specified date (`YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ due_date__lte?: string; + /** Return only receivables assigned to the project with the specified ID. Valid but nonexistent project IDs do not raise errors but return no results. */ project_id?: string; } diff --git a/src/api/resources/receivables/client/requests/ReceivablesSearchRequest.ts b/src/api/resources/receivables/client/requests/ReceivablesSearchRequest.ts new file mode 100644 index 0000000..1baa056 --- /dev/null +++ b/src/api/resources/receivables/client/requests/ReceivablesSearchRequest.ts @@ -0,0 +1,251 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../../../../index.js"; + +/** + * @example + * { + * status: "draft", + * type: "invoice" + * } + */ +export interface ReceivablesSearchRequest { + /** + * This parameter accepts a quote ID or an invoice ID. + * + * * Specify a quote ID to find invoices created from this quote. + * * Specify an invoice ID to find credit notes created for this invoice. + * + * Valid but nonexistent IDs do not raise errors but produce no results. + */ + based_on?: string; + /** + * Return only receivables created for the counterpart with the specified ID. + * + * Counterparts that have been deleted but have associated receivables will still return results here because the receivables contain a frozen copy of the counterpart data. + * + * If the specified counterpart ID does not exist and never existed, no results are returned. + */ + counterpart_id?: string; + /** Return only receivables created for counterparts with the specified name (exact match, case-sensitive). For counterparts of `type` = `individual`, the full name is formatted as `first_name last_name`. */ + counterpart_name?: string; + /** Return only receivables created for counterparts whose name contains the specified string (case-sensitive). */ + counterpart_name__contains?: string; + /** Return only receivables created for counterparts whose name contains the specified string (case-insensitive). */ + counterpart_name__icontains?: string; + /** Return only receivables created after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ + created_at__gt?: string; + /** Return only receivables created on or after the specified date and time. */ + created_at__gte?: string; + /** Return only receivables created before the specified date and time. */ + created_at__lt?: string; + /** Return only receivables created before or on the specified date and time. */ + created_at__lte?: string; + /** Return only receivables with the exact specified discounted subtotal. The amount must be specified in the [minor units](https://docs.monite.com/references/currencies#minor-units) of currency. For example, $12.5 is represented as 1250. */ + discounted_subtotal?: number; + /** Return only receivables whose discounted subtotal (in minor units) is greater than the specified value. */ + discounted_subtotal__gt?: number; + /** Return only receivables whose discounted subtotal (in minor units) is greater than or equal to the specified value. */ + discounted_subtotal__gte?: number; + /** Return only receivables whose discounted subtotal (in minor units) is less than the specified value. */ + discounted_subtotal__lt?: number; + /** Return only receivables whose discounted subtotal (in minor units) is less than or equal to the specified value. */ + discounted_subtotal__lte?: number; + /** Return a receivable with the exact specified document number (case-sensitive). The `document_id` is the user-facing document number such as INV-00042, not to be confused with Monite resource IDs (`id`). */ + document_id?: string; + /** Return only receivables whose document number (`document_id`) contains the specified string (case-sensitive). */ + document_id__contains?: string; + /** Return only receivables whose document number (`document_id`) contains the specified string (case-insensitive). */ + document_id__icontains?: string; + /** + * Return invoices that are due after the specified date (exclusive, `YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ + due_date__gt?: string; + /** + * Return invoices that are due on or after the specified date (`YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ + due_date__gte?: string; + /** + * Return invoices that are due before the specified date (exclusive, `YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ + due_date__lt?: string; + /** + * Return invoices that are due before or on the specified date (`YYYY-MM-DD`). + * + * This filter excludes quotes, credit notes, and draft invoices. + */ + due_date__lte?: string; + /** + * Return only receivables created by the entity user with the specified ID. To query receivables by multiple user IDs at once, use the `entity_user_id__in` parameter instead. + * + * If the request is authenticated using an entity user token, this user must have the `receivable.read.allowed` (rather than `allowed_for_own`) permission to be able to query receivables created by other users. + * + * IDs of deleted users will still produce results here if those users had associated receivables. Valid but nonexistent user IDs do not raise errors but produce no results. + */ + entity_user_id?: string; + /** + * Return only receivables created by the entity users with the specified IDs. + * + * If the request is authenticated using an entity user token, this user must have the `receivable.read.allowed` (rather than `allowed_for_own`) permission to be able to query receivables created by other users. + * + * IDs of deleted users will still produce results here if those users had associated receivables. Valid but nonexistent user IDs do not raise errors but produce no results. + */ + entity_user_id__in?: string[]; + /** Return only receivables with the specified IDs. Valid but nonexistent IDs do not raise errors but produce no results. */ + id__in?: string[]; + /** Return only non-draft receivables that were issued after the specified date and time. The value must be in the ISO 8601 format `YYYY-MM-DDThh:mm[:ss[.ffffff]][Z|Β±hh:mm]`. */ + issue_date__gt?: string; + /** Return only non-draft receivables that were issued on or after the specified date and time. */ + issue_date__gte?: string; + /** Return only non-draft receivables that were issued before the specified date and time. */ + issue_date__lt?: string; + /** Return only non-draft receivables that were issued before or on the specified date and time. */ + issue_date__lte?: string; + /** + * The number of items (0 .. 250) to return in a single page of the response. Default is 100. The response may contain fewer items if it is the last or only page. + * + * When using pagination with a non-default limit, you must provide the `limit` value alongside `pagination_token` in all subsequent pagination requests. Unlike other pagination parameters, `limit` is not inferred from `pagination_token`. + */ + limit?: number; + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ + order?: Monite.OrderEnum; + /** + * A pagination token obtained from a previous call to `GET /receivables` or `POST /receivables/search`. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other parameters except `limit` are ignored and inferred from the initial query. + * + * If not specified, the first page of results will be returned. + */ + pagination_token?: string; + /** + * Return only receivables with line items containing all of the products with the specified IDs and optionally other products that are not specified. + * + * For example, given receivables that contain the following products: + * + * 1. productA + * 2. productB + * 3. productA, productB + * 4. productC + * 5. productA, productB, productC + * + * `product_ids` = `[productA, productB]` will return receivables 3 and 5. + * + * Valid but nonexistent product IDs do not raise errors but produce no results. + */ + product_ids?: string[]; + /** + * Return only receivables with line items containing at least one of the products with the specified IDs. + * + * For example, given receivables that contain the following products: + * + * 1. productA + * 2. productB + * 3. productA, productB + * 4. productC + * 5. productB, productC + * + * `product_ids__in` = `[productA, productB]` will return receivables 1, 2, 3, and 5. + * + * Valid but nonexistent product IDs do not raise errors but produce no results. + */ + product_ids__in?: string[]; + /** Return only receivables assigned to the project with the specified ID. Valid but nonexistent project IDs do not raise errors but return no results. */ + project_id?: string; + /** Return only receivables that belong to one of the projects with the specified IDs. Valid but nonexistent project IDs do not raise errors but produce no results. */ + project_id__in?: string[]; + /** The field to sort the results by. Typically used together with the `order` parameter. */ + sort?: Monite.ReceivableCursorFields2; + /** + * Return only receivables that have the specified status. See the applicable [invoice statuses](https://docs.monite.com/accounts-receivable/invoices/index), [quote statuses](https://docs.monite.com/accounts-receivable/quotes/index), and [credit note statuses](https://docs.monite.com/accounts-receivable/credit-notes#credit-note-lifecycle). + * + * To query multiple statuses at once, use the `status__in` parameter instead. + */ + status?: ReceivablesSearchRequest.Status; + /** Return only receivables that have the specified statuses. See the applicable [invoice statuses](https://docs.monite.com/accounts-receivable/invoices/index), [quote statuses](https://docs.monite.com/accounts-receivable/quotes/index), and [credit note statuses](https://docs.monite.com/accounts-receivable/credit-notes#credit-note-lifecycle). */ + status__in?: string[]; + /** + * Return only receivables whose [tags](https://docs.monite.com/common/tags) include all of the tags with the specified IDs and optionally other tags that are not specified. + * + * For example, given receivables with the following tags: + * + * 1. tagA + * 2. tagB + * 3. tagA, tagB + * 4. tagC + * 5. tagA, tagB, tagC + * + * `tag_ids` = `[tagA, tagB]` will return receivables 3 and 5. + */ + tag_ids?: string[]; + /** + * Return only receivables whose [tags](https://docs.monite.com/common/tags) include at least one of the tags with the specified IDs. + * + * For example, given receivables with the following tags: + * + * 1. tagA + * 2. tagB + * 3. tagA, tagB + * 4. tagC + * 5. tagB, tagC + * + * `tag_ids__in` = `[tagA, tagB]` will return receivables 1, 2, 3, and 5. + * + * Valid but nonexistent tag IDs do not raise errors but produce no results. + */ + tag_ids__in?: string[]; + /** Return only receivables with the exact specified total amount. The amount must be specified in the [minor units](https://docs.monite.com/references/currencies#minor-units) of currency. For example, $12.5 is represented as 1250. */ + total_amount?: number; + /** Return only receivables whose total amount (in minor units) exceeds the specified value. */ + total_amount__gt?: number; + /** Return only receivables whose total amount (in minor units) is greater than or equal to the specified value. */ + total_amount__gte?: number; + /** Return only receivables whose total amount (in minor units) is less than the specified value. */ + total_amount__lt?: number; + /** Return only receivables whose total amount (in minor units) is less than or equal to the specified value. */ + total_amount__lte?: number; + /** Return only receivables of the specified type. Use this parameter to get only invoices, or only quotes, or only credit notes. */ + type?: Monite.ReceivableType; +} + +export namespace ReceivablesSearchRequest { + /** + * Return only receivables that have the specified status. See the applicable [invoice statuses](https://docs.monite.com/accounts-receivable/invoices/index), [quote statuses](https://docs.monite.com/accounts-receivable/quotes/index), and [credit note statuses](https://docs.monite.com/accounts-receivable/credit-notes#credit-note-lifecycle). + * + * To query multiple statuses at once, use the `status__in` parameter instead. + */ + export type Status = + | "draft" + | "issuing" + | "issued" + | "failed" + | "accepted" + | "expired" + | "declined" + | "recurring" + | "partially_paid" + | "paid" + | "overdue" + | "uncollectible" + | "canceled"; + export const Status = { + Draft: "draft", + Issuing: "issuing", + Issued: "issued", + Failed: "failed", + Accepted: "accepted", + Expired: "expired", + Declined: "declined", + Recurring: "recurring", + PartiallyPaid: "partially_paid", + Paid: "paid", + Overdue: "overdue", + Uncollectible: "uncollectible", + Canceled: "canceled", + } as const; +} diff --git a/src/api/resources/receivables/client/requests/UpdateLineItems.ts b/src/api/resources/receivables/client/requests/UpdateLineItems.ts index 4051ca2..2bc0160 100644 --- a/src/api/resources/receivables/client/requests/UpdateLineItems.ts +++ b/src/api/resources/receivables/client/requests/UpdateLineItems.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/receivables/client/requests/index.ts b/src/api/resources/receivables/client/requests/index.ts index a213e8a..2be9f61 100644 --- a/src/api/resources/receivables/client/requests/index.ts +++ b/src/api/resources/receivables/client/requests/index.ts @@ -1,13 +1,14 @@ -export { type ReceivablesGetRequest } from "./ReceivablesGetRequest"; -export { type GetReceivablesRequiredFieldsRequest } from "./GetReceivablesRequiredFieldsRequest"; -export { type QuoteAcceptRequest } from "./QuoteAcceptRequest"; -export { type ReceivableDeclinePayload } from "./ReceivableDeclinePayload"; -export { type ReceivablesGetHistoryRequest } from "./ReceivablesGetHistoryRequest"; -export { type UpdateLineItems } from "./UpdateLineItems"; -export { type ReceivablesGetMailsRequest } from "./ReceivablesGetMailsRequest"; -export { type ReceivablePaidPayload } from "./ReceivablePaidPayload"; -export { type ReceivablePartiallyPaidPayload } from "./ReceivablePartiallyPaidPayload"; -export { type ReceivableUncollectiblePayload } from "./ReceivableUncollectiblePayload"; -export { type ReceivablePreviewRequest } from "./ReceivablePreviewRequest"; -export { type ReceivableSendRequest } from "./ReceivableSendRequest"; -export { type ReceivableSendTestReminderPayload } from "./ReceivableSendTestReminderPayload"; +export { type ReceivablesGetRequest } from "./ReceivablesGetRequest.js"; +export { type GetReceivablesRequiredFieldsRequest } from "./GetReceivablesRequiredFieldsRequest.js"; +export { type ReceivablesSearchRequest } from "./ReceivablesSearchRequest.js"; +export { type QuoteAcceptRequest } from "./QuoteAcceptRequest.js"; +export { type ReceivableDeclinePayload } from "./ReceivableDeclinePayload.js"; +export { type ReceivablesGetHistoryRequest } from "./ReceivablesGetHistoryRequest.js"; +export { type UpdateLineItems } from "./UpdateLineItems.js"; +export { type ReceivablesGetMailsRequest } from "./ReceivablesGetMailsRequest.js"; +export { type ReceivablePaidPayload } from "./ReceivablePaidPayload.js"; +export { type ReceivablePartiallyPaidPayload } from "./ReceivablePartiallyPaidPayload.js"; +export { type ReceivableUncollectiblePayload } from "./ReceivableUncollectiblePayload.js"; +export { type ReceivablePreviewRequest } from "./ReceivablePreviewRequest.js"; +export { type ReceivableSendRequest } from "./ReceivableSendRequest.js"; +export { type ReceivableSendTestReminderPayload } from "./ReceivableSendTestReminderPayload.js"; diff --git a/src/api/resources/receivables/index.ts b/src/api/resources/receivables/index.ts index c9240f8..f095e14 100644 --- a/src/api/resources/receivables/index.ts +++ b/src/api/resources/receivables/index.ts @@ -1,2 +1,2 @@ -export * from "./types"; -export * from "./client"; +export * from "./types/index.js"; +export * from "./client/index.js"; diff --git a/src/api/resources/receivables/types/index.ts b/src/api/resources/receivables/types/index.ts index 8522221..4ea201b 100644 --- a/src/api/resources/receivables/types/index.ts +++ b/src/api/resources/receivables/types/index.ts @@ -1,2 +1,2 @@ -export * from "./ReceivablesGetRequestStatusInItem"; -export * from "./ReceivablesGetRequestStatus"; +export * from "./ReceivablesGetRequestStatusInItem.js"; +export * from "./ReceivablesGetRequestStatus.js"; diff --git a/src/api/resources/recurrences/client/Client.ts b/src/api/resources/recurrences/client/Client.ts index 7e92a60..d55fe35 100644 --- a/src/api/resources/recurrences/client/Client.ts +++ b/src/api/resources/recurrences/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Recurrences { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Recurrences { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Recurrences { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Recurrences { - constructor(protected readonly _options: Recurrences.Options) {} + protected readonly _options: Recurrences.Options; + + constructor(_options: Recurrences.Options) { + this._options = _options; + } /** * @param {Recurrences.RequestOptions} requestOptions - Request-specific configuration. @@ -48,49 +56,43 @@ export class Recurrences { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.recurrences.get() */ - public get(requestOptions?: Recurrences.RequestOptions): core.HttpResponsePromise { + public get(requestOptions?: Recurrences.RequestOptions): core.HttpResponsePromise { return core.HttpResponsePromise.fromPromise(this.__get(requestOptions)); } private async __get( requestOptions?: Recurrences.RequestOptions, - ): Promise> { + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "recurrences", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Monite.GetAllRecurrences, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.RecurrenceResponseList, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { @@ -105,8 +107,8 @@ export class Recurrences { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -142,53 +144,44 @@ export class Recurrences { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.recurrences.create({ - * day_of_month: "first_day", - * end_month: 1, - * end_year: 1, - * invoice_id: "invoice_id", - * start_month: 1, - * start_year: 1 + * invoice_id: "invoice_id" * }) */ public create( request: Monite.CreateRecurrencePayload, requestOptions?: Recurrences.RequestOptions, - ): core.HttpResponsePromise { + ): core.HttpResponsePromise { return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions)); } private async __create( request: Monite.CreateRecurrencePayload, requestOptions?: Recurrences.RequestOptions, - ): Promise> { + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "recurrences", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -196,7 +189,7 @@ export class Recurrences { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Monite.Recurrence, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.RecurrenceResponse, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { @@ -211,8 +204,8 @@ export class Recurrences { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -248,7 +241,7 @@ export class Recurrences { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.recurrences.getById("recurrence_id") @@ -256,45 +249,39 @@ export class Recurrences { public getById( recurrenceId: string, requestOptions?: Recurrences.RequestOptions, - ): core.HttpResponsePromise { + ): core.HttpResponsePromise { return core.HttpResponsePromise.fromPromise(this.__getById(recurrenceId, requestOptions)); } private async __getById( recurrenceId: string, requestOptions?: Recurrences.RequestOptions, - ): Promise> { + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `recurrences/${encodeURIComponent(recurrenceId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Monite.Recurrence, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.RecurrenceResponse, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { @@ -309,8 +296,8 @@ export class Recurrences { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -347,7 +334,7 @@ export class Recurrences { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.recurrences.updateById("recurrence_id") @@ -356,7 +343,7 @@ export class Recurrences { recurrenceId: string, request: Monite.UpdateRecurrencePayload = {}, requestOptions?: Recurrences.RequestOptions, - ): core.HttpResponsePromise { + ): core.HttpResponsePromise { return core.HttpResponsePromise.fromPromise(this.__updateById(recurrenceId, request, requestOptions)); } @@ -364,31 +351,27 @@ export class Recurrences { recurrenceId: string, request: Monite.UpdateRecurrencePayload = {}, requestOptions?: Recurrences.RequestOptions, - ): Promise> { + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `recurrences/${encodeURIComponent(recurrenceId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -396,7 +379,7 @@ export class Recurrences { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Monite.Recurrence, rawResponse: _response.rawResponse }; + return { data: _response.body as Monite.RecurrenceResponse, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { @@ -411,8 +394,8 @@ export class Recurrences { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -451,7 +434,7 @@ export class Recurrences { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.recurrences.cancelById("recurrence_id") @@ -467,31 +450,25 @@ export class Recurrences { recurrenceId: string, requestOptions?: Recurrences.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `recurrences/${encodeURIComponent(recurrenceId)}/cancel`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -514,8 +491,8 @@ export class Recurrences { throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -544,6 +521,200 @@ export class Recurrences { } } + /** + * @param {string} recurrenceId + * @param {Recurrences.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.recurrences.postRecurrencesIdPause("recurrence_id") + */ + public postRecurrencesIdPause( + recurrenceId: string, + requestOptions?: Recurrences.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postRecurrencesIdPause(recurrenceId, requestOptions)); + } + + private async __postRecurrencesIdPause( + recurrenceId: string, + requestOptions?: Recurrences.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `recurrences/${encodeURIComponent(recurrenceId)}/pause`, + ), + method: "POST", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling POST /recurrences/{recurrence_id}/pause.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * @param {string} recurrenceId + * @param {Recurrences.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.ForbiddenError} + * @throws {@link Monite.NotFoundError} + * @throws {@link Monite.ConflictError} + * @throws {@link Monite.UnprocessableEntityError} + * @throws {@link Monite.TooManyRequestsError} + * + * @example + * await client.recurrences.postRecurrencesIdResume("recurrence_id") + */ + public postRecurrencesIdResume( + recurrenceId: string, + requestOptions?: Recurrences.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__postRecurrencesIdResume(recurrenceId, requestOptions)); + } + + private async __postRecurrencesIdResume( + recurrenceId: string, + requestOptions?: Recurrences.RequestOptions, + ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.MoniteEnvironment.Sandbox, + `recurrences/${encodeURIComponent(recurrenceId)}/resume`, + ), + method: "POST", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: _response.body, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 403: + throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); + case 409: + throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); + case 422: + throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); + default: + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.MoniteError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.MoniteTimeoutError( + "Timeout exceeded when calling POST /recurrences/{recurrence_id}/resume.", + ); + case "unknown": + throw new errors.MoniteError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + protected async _getAuthorizationHeader(): Promise { const bearer = await core.Supplier.get(this._options.token); if (bearer != null) { diff --git a/src/api/resources/recurrences/client/index.ts b/src/api/resources/recurrences/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/recurrences/client/index.ts +++ b/src/api/resources/recurrences/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/recurrences/client/requests/CreateRecurrencePayload.ts b/src/api/resources/recurrences/client/requests/CreateRecurrencePayload.ts index 1cef007..27e46a4 100644 --- a/src/api/resources/recurrences/client/requests/CreateRecurrencePayload.ts +++ b/src/api/resources/recurrences/client/requests/CreateRecurrencePayload.ts @@ -2,17 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * { - * day_of_month: "first_day", - * end_month: 1, - * end_year: 1, - * invoice_id: "invoice_id", - * start_month: 1, - * start_year: 1 + * invoice_id: "invoice_id" * } */ export interface CreateRecurrencePayload { @@ -27,13 +22,32 @@ export interface CreateRecurrencePayload { * Note: When using "issue_and_send", both subject_text and body_text must be provided. */ automation_level?: Monite.AutomationLevel; + /** The body text for the email that will be sent with the recurring invoice. */ body_text?: string; - day_of_month: Monite.DayOfMonth; - end_month: number; - end_year: number; + /** Deprecated, use `start_date` instead */ + day_of_month?: Monite.DayOfMonth; + /** The end date of the recurring invoice, in the `yyyy-mm-dd` format. The end date is inclusive, that is, the last invoice will be created on this date if the last occurrence falls on this date. `end_date` is mutually exclusive with `max_occurrences`. Either `end_date` or `max_occurrences` must be specified. */ + end_date?: string; + /** Deprecated, use `end_date` instead */ + end_month?: number; + /** Deprecated, use `end_date` instead */ + end_year?: number; + /** How often the invoice will be created. */ + frequency?: Monite.RecurrenceFrequency; + /** The interval between each occurrence of the invoice. For example, when using monthly frequency, an interval of 1 means invoices will be created every month, an interval of 2 means invoices will be created every 2 months. */ + interval?: number; + /** ID of the base invoice that will be used as a template for creating recurring invoices. */ invoice_id: string; + /** How many times the recurring invoice will be created. The recurrence will stop after this number is reached. `max_occurrences` is mutually exclusive with `end_date`. Either `max_occurrences` or `end_date` must be specified. */ + max_occurrences?: number; + /** An object containing the recipients (To, CC, BCC) of the recurring invoices. Can be omitted if the base invoice has the counterpart contact email specified in the `counterpart_contact.email` field. */ recipients?: Monite.Recipients; - start_month: number; - start_year: number; + /** The date when the first invoice will be created, in the `yyyy-mm-dd` format. Cannot be a past date. Subsequent invoice dates will be calculated based on `start_date`, `frequency`, and `interval`. */ + start_date?: string; + /** Deprecated, use `start_date` instead */ + start_month?: number; + /** Deprecated, use `start_date` instead */ + start_year?: number; + /** The subject for the email that will be sent with the recurring invoice. */ subject_text?: string; } diff --git a/src/api/resources/recurrences/client/requests/UpdateRecurrencePayload.ts b/src/api/resources/recurrences/client/requests/UpdateRecurrencePayload.ts index 8005efe..608b6ac 100644 --- a/src/api/resources/recurrences/client/requests/UpdateRecurrencePayload.ts +++ b/src/api/resources/recurrences/client/requests/UpdateRecurrencePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -20,10 +20,26 @@ export interface UpdateRecurrencePayload { * Note: When using "issue_and_send", both subject_text and body_text must be provided. */ automation_level?: Monite.AutomationLevel; + /** The body text for the email that will be sent with the recurring invoice. */ body_text?: string; + /** Deprecated, use `start_date` instead */ day_of_month?: Monite.DayOfMonth; + /** The end date of the recurring invoice, in the `yyyy-mm-dd` format. The end date is inclusive, that is, the last invoice will be created on this date if the last occurrence falls on this date. `end_date` is mutually exclusive with `max_occurrences`. Either `end_date` or `max_occurrences` must be specified. */ + end_date?: string; + /** Deprecated, use `end_date` instead */ end_month?: number; + /** Deprecated, use `end_date` instead */ end_year?: number; + /** How often the invoice will be created. */ + frequency?: Monite.RecurrenceFrequency; + /** The interval between each occurrence of the invoice. For example, when using monthly frequency, an interval of 1 means invoices will be created every month, an interval of 2 means invoices will be created every 2 months. */ + interval?: number; + /** How many times the recurring invoice will be created. The recurrence will stop after this number is reached. `max_occurrences` is mutually exclusive with `end_date`. Either `max_occurrences` or `end_date` must be specified. */ + max_occurrences?: number; + /** An object containing the recipients (To, CC, BCC) of the recurring invoices. Can be omitted if the base invoice has the counterpart contact email specified in the `counterpart_contact.email` field. */ recipients?: Monite.Recipients; + /** The date when the first invoice will be created, in the `yyyy-mm-dd` format. Cannot be a past date. Subsequent invoice dates will be calculated based on `start_date`, `frequency`, and `interval`. */ + start_date?: string; + /** The subject for the email that will be sent with the recurring invoice. */ subject_text?: string; } diff --git a/src/api/resources/recurrences/client/requests/index.ts b/src/api/resources/recurrences/client/requests/index.ts index 5d38bf5..6ec615e 100644 --- a/src/api/resources/recurrences/client/requests/index.ts +++ b/src/api/resources/recurrences/client/requests/index.ts @@ -1,2 +1,2 @@ -export { type CreateRecurrencePayload } from "./CreateRecurrencePayload"; -export { type UpdateRecurrencePayload } from "./UpdateRecurrencePayload"; +export { type CreateRecurrencePayload } from "./CreateRecurrencePayload.js"; +export { type UpdateRecurrencePayload } from "./UpdateRecurrencePayload.js"; diff --git a/src/api/resources/recurrences/index.ts b/src/api/resources/recurrences/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/recurrences/index.ts +++ b/src/api/resources/recurrences/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/roles/client/Client.ts b/src/api/resources/roles/client/Client.ts index 0719dd3..59e1e83 100644 --- a/src/api/resources/roles/client/Client.ts +++ b/src/api/resources/roles/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Roles { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Roles { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Roles { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Roles { - constructor(protected readonly _options: Roles.Options) {} + protected readonly _options: Roles.Options; + + constructor(_options: Roles.Options) { + this._options = _options; + } /** * Find all roles that match the search criteria. @@ -51,7 +59,7 @@ export class Roles { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.roles.get() @@ -129,32 +137,25 @@ export class Roles { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "roles", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -175,8 +176,8 @@ export class Roles { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -210,8 +211,9 @@ export class Roles { * @param {Roles.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.roles.create({ @@ -230,30 +232,26 @@ export class Roles { request: Monite.CreateRoleRequest, requestOptions?: Roles.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "roles", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -268,10 +266,12 @@ export class Roles { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -303,8 +303,9 @@ export class Roles { * @param {Roles.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.roles.getById("role_id") @@ -320,31 +321,25 @@ export class Roles { roleId: string, requestOptions?: Roles.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `roles/${encodeURIComponent(roleId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -357,10 +352,12 @@ export class Roles { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -394,10 +391,11 @@ export class Roles { * @param {Roles.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.ConflictError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.roles.deleteRolesId("role_id") @@ -410,31 +408,25 @@ export class Roles { roleId: string, requestOptions?: Roles.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `roles/${encodeURIComponent(roleId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -447,14 +439,16 @@ export class Roles { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 404: throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 409: throw new Monite.ConflictError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -489,8 +483,9 @@ export class Roles { * @param {Roles.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.roles.updateById("role_id") @@ -508,30 +503,26 @@ export class Roles { request: Monite.UpdateRoleRequest = {}, requestOptions?: Roles.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `roles/${encodeURIComponent(roleId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -546,10 +537,12 @@ export class Roles { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/roles/client/index.ts b/src/api/resources/roles/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/roles/client/index.ts +++ b/src/api/resources/roles/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/roles/client/requests/CreateRoleRequest.ts b/src/api/resources/roles/client/requests/CreateRoleRequest.ts index 4cc8348..f49beb2 100644 --- a/src/api/resources/roles/client/requests/CreateRoleRequest.ts +++ b/src/api/resources/roles/client/requests/CreateRoleRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example @@ -12,7 +12,7 @@ import * as Monite from "../../../../index"; * } */ export interface CreateRoleRequest { - /** Role name */ + /** The role name is case-sensitive and must be unique. */ name: string; /** Access permissions */ permissions: Monite.BizObjectsSchemaInput; diff --git a/src/api/resources/roles/client/requests/RolesGetRequest.ts b/src/api/resources/roles/client/requests/RolesGetRequest.ts index e8cea05..9f8c1da 100644 --- a/src/api/resources/roles/client/requests/RolesGetRequest.ts +++ b/src/api/resources/roles/client/requests/RolesGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface RolesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface RolesGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.RoleCursorFields; id__in?: string | string[]; name?: string; diff --git a/src/api/resources/roles/client/requests/UpdateRoleRequest.ts b/src/api/resources/roles/client/requests/UpdateRoleRequest.ts index 844e438..6210360 100644 --- a/src/api/resources/roles/client/requests/UpdateRoleRequest.ts +++ b/src/api/resources/roles/client/requests/UpdateRoleRequest.ts @@ -2,14 +2,14 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface UpdateRoleRequest { - /** Role name */ + /** The new name for this role. Case-sensitive and must be unique. */ name?: string; /** Access permissions */ permissions?: Monite.BizObjectsSchemaInput; diff --git a/src/api/resources/roles/client/requests/index.ts b/src/api/resources/roles/client/requests/index.ts index 2226656..e92118a 100644 --- a/src/api/resources/roles/client/requests/index.ts +++ b/src/api/resources/roles/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type RolesGetRequest } from "./RolesGetRequest"; -export { type CreateRoleRequest } from "./CreateRoleRequest"; -export { type UpdateRoleRequest } from "./UpdateRoleRequest"; +export { type RolesGetRequest } from "./RolesGetRequest.js"; +export { type CreateRoleRequest } from "./CreateRoleRequest.js"; +export { type UpdateRoleRequest } from "./UpdateRoleRequest.js"; diff --git a/src/api/resources/roles/index.ts b/src/api/resources/roles/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/roles/index.ts +++ b/src/api/resources/roles/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/tags/client/Client.ts b/src/api/resources/tags/client/Client.ts index 8976bae..9189949 100644 --- a/src/api/resources/tags/client/Client.ts +++ b/src/api/resources/tags/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace Tags { export interface Options { @@ -18,6 +18,8 @@ export declare namespace Tags { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace Tags { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class Tags { - constructor(protected readonly _options: Tags.Options) {} + protected readonly _options: Tags.Options; + + constructor(_options: Tags.Options) { + this._options = _options; + } /** * Get a list of all tags. Tags can be assigned to resources to assist with searching and filtering. @@ -52,7 +60,7 @@ export class Tags { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.tags.get() @@ -114,32 +122,25 @@ export class Tags { } } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "tags", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -160,8 +161,8 @@ export class Tags { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -205,7 +206,7 @@ export class Tags { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.tags.create({ @@ -223,30 +224,26 @@ export class Tags { request: Monite.TagCreateSchema, requestOptions?: Tags.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "tags", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -271,8 +268,8 @@ export class Tags { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -311,7 +308,7 @@ export class Tags { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.tags.getById("tag_id") @@ -327,31 +324,25 @@ export class Tags { tagId: string, requestOptions?: Tags.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `tags/${encodeURIComponent(tagId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -374,8 +365,8 @@ export class Tags { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -409,11 +400,12 @@ export class Tags { * @param {Tags.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Monite.BadRequestError} + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.tags.deleteById("tag_id") @@ -426,31 +418,25 @@ export class Tags { tagId: string, requestOptions?: Tags.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `tags/${encodeURIComponent(tagId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -463,6 +449,8 @@ export class Tags { switch (_response.error.statusCode) { case 400: throw new Monite.BadRequestError(_response.error.body as unknown, _response.rawResponse); + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 403: throw new Monite.ForbiddenError(_response.error.body as unknown, _response.rawResponse); case 404: @@ -471,8 +459,8 @@ export class Tags { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -513,7 +501,7 @@ export class Tags { * @throws {@link Monite.NotFoundError} * @throws {@link Monite.NotAcceptableError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.tags.updateById("tag_id") @@ -531,30 +519,26 @@ export class Tags { request: Monite.TagUpdateSchema = {}, requestOptions?: Tags.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `tags/${encodeURIComponent(tagId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -579,8 +563,8 @@ export class Tags { throw new Monite.NotAcceptableError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/tags/client/index.ts b/src/api/resources/tags/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/tags/client/index.ts +++ b/src/api/resources/tags/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/tags/client/requests/TagCreateSchema.ts b/src/api/resources/tags/client/requests/TagCreateSchema.ts index 7431b1d..4a67aa4 100644 --- a/src/api/resources/tags/client/requests/TagCreateSchema.ts +++ b/src/api/resources/tags/client/requests/TagCreateSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/tags/client/requests/TagUpdateSchema.ts b/src/api/resources/tags/client/requests/TagUpdateSchema.ts index 47e0dcd..9bc689e 100644 --- a/src/api/resources/tags/client/requests/TagUpdateSchema.ts +++ b/src/api/resources/tags/client/requests/TagUpdateSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/tags/client/requests/TagsGetRequest.ts b/src/api/resources/tags/client/requests/TagsGetRequest.ts index 90f01f0..f9d79f0 100644 --- a/src/api/resources/tags/client/requests/TagsGetRequest.ts +++ b/src/api/resources/tags/client/requests/TagsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface TagsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface TagsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.TagCursorFields; created_by_entity_user_id?: string; name__in?: string | string[]; diff --git a/src/api/resources/tags/client/requests/index.ts b/src/api/resources/tags/client/requests/index.ts index 5fc8dfa..92cacfd 100644 --- a/src/api/resources/tags/client/requests/index.ts +++ b/src/api/resources/tags/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type TagsGetRequest } from "./TagsGetRequest"; -export { type TagCreateSchema } from "./TagCreateSchema"; -export { type TagUpdateSchema } from "./TagUpdateSchema"; +export { type TagsGetRequest } from "./TagsGetRequest.js"; +export { type TagCreateSchema } from "./TagCreateSchema.js"; +export { type TagUpdateSchema } from "./TagUpdateSchema.js"; diff --git a/src/api/resources/tags/index.ts b/src/api/resources/tags/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/tags/index.ts +++ b/src/api/resources/tags/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/textTemplates/client/Client.ts b/src/api/resources/textTemplates/client/Client.ts index 2ab9ffd..f14dc98 100644 --- a/src/api/resources/textTemplates/client/Client.ts +++ b/src/api/resources/textTemplates/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace TextTemplates { export interface Options { @@ -18,6 +18,8 @@ export declare namespace TextTemplates { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace TextTemplates { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class TextTemplates { - constructor(protected readonly _options: TextTemplates.Options) {} + protected readonly _options: TextTemplates.Options; + + constructor(_options: TextTemplates.Options) { + this._options = _options; + } /** * Get text templates @@ -46,8 +54,9 @@ export class TextTemplates { * @param {Monite.TextTemplatesGetRequest} request * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.get() @@ -77,32 +86,25 @@ export class TextTemplates { _queryParams["is_default"] = isDefault.toString(); } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "text_templates", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -113,10 +115,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -149,8 +153,9 @@ export class TextTemplates { * @param {Monite.CreateTextTemplatePayload} request * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.create({ @@ -171,30 +176,26 @@ export class TextTemplates { request: Monite.CreateTextTemplatePayload, requestOptions?: TextTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "text_templates", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -207,10 +208,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -243,8 +246,9 @@ export class TextTemplates { * @param {string} textTemplateId * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.getById("text_template_id") @@ -260,31 +264,25 @@ export class TextTemplates { textTemplateId: string, requestOptions?: TextTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `text_templates/${encodeURIComponent(textTemplateId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -295,10 +293,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -333,8 +333,9 @@ export class TextTemplates { * @param {string} textTemplateId - UUID text_template ID * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.deleteById("text_template_id") @@ -350,31 +351,25 @@ export class TextTemplates { textTemplateId: string, requestOptions?: TextTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `text_templates/${encodeURIComponent(textTemplateId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -385,10 +380,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -424,8 +421,9 @@ export class TextTemplates { * @param {Monite.UpdateTextTemplatePayload} request * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.updateById("text_template_id") @@ -443,30 +441,26 @@ export class TextTemplates { request: Monite.UpdateTextTemplatePayload = {}, requestOptions?: TextTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `text_templates/${encodeURIComponent(textTemplateId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -479,10 +473,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -517,8 +513,9 @@ export class TextTemplates { * @param {string} textTemplateId - UUID text_template ID * @param {TextTemplates.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.textTemplates.makeDefaultById("text_template_id") @@ -534,31 +531,25 @@ export class TextTemplates { textTemplateId: string, requestOptions?: TextTemplates.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `text_templates/${encodeURIComponent(textTemplateId)}/make_default`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -569,10 +560,12 @@ export class TextTemplates { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/textTemplates/client/index.ts b/src/api/resources/textTemplates/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/textTemplates/client/index.ts +++ b/src/api/resources/textTemplates/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/textTemplates/client/requests/CreateTextTemplatePayload.ts b/src/api/resources/textTemplates/client/requests/CreateTextTemplatePayload.ts index 5470a6a..0cbb67c 100644 --- a/src/api/resources/textTemplates/client/requests/CreateTextTemplatePayload.ts +++ b/src/api/resources/textTemplates/client/requests/CreateTextTemplatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/textTemplates/client/requests/TextTemplatesGetRequest.ts b/src/api/resources/textTemplates/client/requests/TextTemplatesGetRequest.ts index 6a284cf..12b0f0f 100644 --- a/src/api/resources/textTemplates/client/requests/TextTemplatesGetRequest.ts +++ b/src/api/resources/textTemplates/client/requests/TextTemplatesGetRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example diff --git a/src/api/resources/textTemplates/client/requests/index.ts b/src/api/resources/textTemplates/client/requests/index.ts index e61936b..8e1441d 100644 --- a/src/api/resources/textTemplates/client/requests/index.ts +++ b/src/api/resources/textTemplates/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type TextTemplatesGetRequest } from "./TextTemplatesGetRequest"; -export { type CreateTextTemplatePayload } from "./CreateTextTemplatePayload"; -export { type UpdateTextTemplatePayload } from "./UpdateTextTemplatePayload"; +export { type TextTemplatesGetRequest } from "./TextTemplatesGetRequest.js"; +export { type CreateTextTemplatePayload } from "./CreateTextTemplatePayload.js"; +export { type UpdateTextTemplatePayload } from "./UpdateTextTemplatePayload.js"; diff --git a/src/api/resources/textTemplates/index.ts b/src/api/resources/textTemplates/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/textTemplates/index.ts +++ b/src/api/resources/textTemplates/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/vatRates/client/Client.ts b/src/api/resources/vatRates/client/Client.ts index 07e8d30..fcbee1e 100644 --- a/src/api/resources/vatRates/client/Client.ts +++ b/src/api/resources/vatRates/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace VatRates { export interface Options { @@ -18,6 +18,8 @@ export declare namespace VatRates { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,15 +34,33 @@ export declare namespace VatRates { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class VatRates { - constructor(protected readonly _options: VatRates.Options) {} + protected readonly _options: VatRates.Options; + + constructor(_options: VatRates.Options) { + this._options = _options; + } /** + * Monite maintains a catalog of VAT and sales tax rates for [select countries](https://docs.monite.com/accounts-receivable/vat-rates#supported-countries). + * + * To query the applicable VAT/tax rates for an invoice or quote, use: + * + * `GET /vat_rates?counterpart_id=<...>&entity_vat_id_id=<...>` + * + * Or if the entity does not have a VAT ID: + * + * `GET /vat_rates?counterpart_id=<...>` + * + * **Note:** Entities from countries [not on the list](https://docs.monite.com/accounts-receivable/vat-rates#supported-countries) should not use this endpoint. Instead, those entities can either create custom VAT/tax rates or use the invoice field `line_items[].tax_rate_value` to specify the VAT/tax rates directly. + * * @param {Monite.VatRatesGetRequest} request * @param {VatRates.RequestOptions} requestOptions - Request-specific configuration. * @@ -49,7 +69,7 @@ export class VatRates { * @throws {@link Monite.ForbiddenError} * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.vatRates.get() @@ -93,32 +113,25 @@ export class VatRates { _queryParams["product_type"] = productType; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "vat_rates", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -139,8 +152,8 @@ export class VatRates { throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/vatRates/client/index.ts b/src/api/resources/vatRates/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/vatRates/client/index.ts +++ b/src/api/resources/vatRates/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/vatRates/client/requests/VatRatesGetRequest.ts b/src/api/resources/vatRates/client/requests/VatRatesGetRequest.ts index fa8f5b1..57b8186 100644 --- a/src/api/resources/vatRates/client/requests/VatRatesGetRequest.ts +++ b/src/api/resources/vatRates/client/requests/VatRatesGetRequest.ts @@ -2,16 +2,21 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface VatRatesGetRequest { + /** Unused. Reserved for future use. */ counterpart_address_id?: string; + /** ID of the counterpart that will be invoiced. */ counterpart_id?: string; + /** Unused. Reserved for future use. */ counterpart_vat_id_id?: string; + /** ID of the entity's VAT number (if any) used for the sales transaction. */ entity_vat_id_id?: string; + /** Unused. Reserved for future use. */ product_type?: Monite.ProductServiceTypeEnum; } diff --git a/src/api/resources/vatRates/client/requests/index.ts b/src/api/resources/vatRates/client/requests/index.ts index 93d6ce1..fb16f4d 100644 --- a/src/api/resources/vatRates/client/requests/index.ts +++ b/src/api/resources/vatRates/client/requests/index.ts @@ -1 +1 @@ -export { type VatRatesGetRequest } from "./VatRatesGetRequest"; +export { type VatRatesGetRequest } from "./VatRatesGetRequest.js"; diff --git a/src/api/resources/vatRates/index.ts b/src/api/resources/vatRates/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/vatRates/index.ts +++ b/src/api/resources/vatRates/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/webhookDeliveries/client/Client.ts b/src/api/resources/webhookDeliveries/client/Client.ts index 643ec56..e237590 100644 --- a/src/api/resources/webhookDeliveries/client/Client.ts +++ b/src/api/resources/webhookDeliveries/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace WebhookDeliveries { export interface Options { @@ -18,6 +18,8 @@ export declare namespace WebhookDeliveries { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,13 +34,19 @@ export declare namespace WebhookDeliveries { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class WebhookDeliveries { - constructor(protected readonly _options: WebhookDeliveries.Options) {} + protected readonly _options: WebhookDeliveries.Options; + + constructor(_options: WebhookDeliveries.Options) { + this._options = _options; + } /** * Returns an aggregated log of webhook delivery attempts. The data contains a list of triggered webhook events, how many times Monite tried to send each event to your server, the last HTTP status code returned by your webhook listener endpoint, and whether the final attempt to deliver that event was successful. @@ -50,8 +58,9 @@ export class WebhookDeliveries { * @param {Monite.WebhookDeliveriesGetRequest} request * @param {WebhookDeliveries.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookDeliveries.get() @@ -125,32 +134,25 @@ export class WebhookDeliveries { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "webhook_deliveries", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -164,10 +166,12 @@ export class WebhookDeliveries { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/webhookDeliveries/client/index.ts b/src/api/resources/webhookDeliveries/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/webhookDeliveries/client/index.ts +++ b/src/api/resources/webhookDeliveries/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/webhookDeliveries/client/requests/WebhookDeliveriesGetRequest.ts b/src/api/resources/webhookDeliveries/client/requests/WebhookDeliveriesGetRequest.ts index 09bf828..a2b7d95 100644 --- a/src/api/resources/webhookDeliveries/client/requests/WebhookDeliveriesGetRequest.ts +++ b/src/api/resources/webhookDeliveries/client/requests/WebhookDeliveriesGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface WebhookDeliveriesGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,9 +19,7 @@ export interface WebhookDeliveriesGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.WebhookDeliveryCursorFields; event_id?: string; object_type?: Monite.WebhookObjectType; diff --git a/src/api/resources/webhookDeliveries/client/requests/index.ts b/src/api/resources/webhookDeliveries/client/requests/index.ts index 339df60..4249683 100644 --- a/src/api/resources/webhookDeliveries/client/requests/index.ts +++ b/src/api/resources/webhookDeliveries/client/requests/index.ts @@ -1 +1 @@ -export { type WebhookDeliveriesGetRequest } from "./WebhookDeliveriesGetRequest"; +export { type WebhookDeliveriesGetRequest } from "./WebhookDeliveriesGetRequest.js"; diff --git a/src/api/resources/webhookDeliveries/index.ts b/src/api/resources/webhookDeliveries/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/webhookDeliveries/index.ts +++ b/src/api/resources/webhookDeliveries/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/resources/webhookSubscriptions/client/Client.ts b/src/api/resources/webhookSubscriptions/client/Client.ts index 6a49c9c..509d8f9 100644 --- a/src/api/resources/webhookSubscriptions/client/Client.ts +++ b/src/api/resources/webhookSubscriptions/client/Client.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as environments from "../../../../environments"; -import * as core from "../../../../core"; -import * as Monite from "../../../index"; -import urlJoin from "url-join"; -import * as errors from "../../../../errors/index"; +import * as environments from "../../../../environments.js"; +import * as core from "../../../../core/index.js"; +import * as Monite from "../../../index.js"; +import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as errors from "../../../../errors/index.js"; export declare namespace WebhookSubscriptions { export interface Options { @@ -18,6 +18,8 @@ export declare namespace WebhookSubscriptions { moniteVersion: core.Supplier; /** Override the x-monite-entity-id header */ moniteEntityId?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record | undefined>; fetcher?: core.FetchFunction; } @@ -32,20 +34,29 @@ export declare namespace WebhookSubscriptions { moniteVersion?: string; /** Override the x-monite-entity-id header */ moniteEntityId?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ - headers?: Record; + headers?: Record | undefined>; } } export class WebhookSubscriptions { - constructor(protected readonly _options: WebhookSubscriptions.Options) {} + protected readonly _options: WebhookSubscriptions.Options; + + constructor(_options: WebhookSubscriptions.Options) { + this._options = _options; + } /** + * Returns a list of all [webhook](https://docs.monite.com/references/webhooks/index) subscriptions (both active and disabled). + * * @param {Monite.WebhookSubscriptionsGetRequest} request * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.get() @@ -109,32 +120,25 @@ export class WebhookSubscriptions { _queryParams["created_at__lte"] = createdAtLte; } + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "webhook_subscriptions", ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - queryParameters: _queryParams, - requestType: "json", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -148,10 +152,12 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -179,16 +185,20 @@ export class WebhookSubscriptions { } /** + * Related guide: [Webhooks](https://docs.monite.com/references/webhooks/index). + * * @param {Monite.CreateWebhookSubscriptionRequest} request * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.create({ - * object_type: "account", - * url: "url" + * event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + * object_type: "entity", + * url: "https://example.com/your-webhook-listener" * }) */ public create( @@ -202,30 +212,26 @@ export class WebhookSubscriptions { request: Monite.CreateWebhookSubscriptionRequest, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, "webhook_subscriptions", ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -241,10 +247,12 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -272,11 +280,17 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * Returns the details of the webhook subscription with the specified ID. + * + * The response does not include the [webhook signing secret](https://docs.monite.com/references/webhooks/signatures). If you lost the secret, you can [regenerate it](https://docs.monite.com/api/webhook-subscriptions/post-webhook-subscriptions-id-regenerate-secret). + * + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.getById("webhook_subscription_id") @@ -292,31 +306,25 @@ export class WebhookSubscriptions { webhookSubscriptionId: string, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}`, ), method: "GET", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -327,10 +335,14 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -360,11 +372,13 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.deleteById("webhook_subscription_id") @@ -380,31 +394,25 @@ export class WebhookSubscriptions { webhookSubscriptionId: string, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}`, ), method: "DELETE", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -415,10 +423,14 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -448,12 +460,16 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * You can update the webhook listener URL or the event list. + * + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {Monite.UpdateWebhookSubscriptionRequest} request * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.updateById("webhook_subscription_id") @@ -471,30 +487,26 @@ export class WebhookSubscriptions { request: Monite.UpdateWebhookSubscriptionRequest = {}, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}`, ), method: "PATCH", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, + headers: _headers, contentType: "application/json", + queryParameters: requestOptions?.queryParams, requestType: "json", body: request, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -507,10 +519,14 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -540,11 +556,12 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.disableById("webhook_subscription_id") @@ -560,31 +577,25 @@ export class WebhookSubscriptions { webhookSubscriptionId: string, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}/disable`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -595,10 +606,12 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -628,11 +641,12 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.enableById("webhook_subscription_id") @@ -648,31 +662,25 @@ export class WebhookSubscriptions { webhookSubscriptionId: string, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}/enable`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -683,10 +691,12 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, @@ -716,11 +726,15 @@ export class WebhookSubscriptions { } /** - * @param {string} webhookSubscriptionId + * The webhook signing secret lets you [verify webhook signatures](https://docs.monite.com/references/webhooks/signatures). If you lost the original secret generated for any of your webhook subscriptions, you can regenerate it. + * + * @param {string} webhookSubscriptionId - ID of the webhook subscription. This is the same value as the `webhook_subscription_id` you receive in webhooks. * @param {WebhookSubscriptions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Monite.UnauthorizedError} + * @throws {@link Monite.NotFoundError} * @throws {@link Monite.UnprocessableEntityError} - * @throws {@link Monite.InternalServerError} + * @throws {@link Monite.TooManyRequestsError} * * @example * await client.webhookSubscriptions.regenerateSecretById("webhook_subscription_id") @@ -736,31 +750,25 @@ export class WebhookSubscriptions { webhookSubscriptionId: string, requestOptions?: WebhookSubscriptions.RequestOptions, ): Promise> { + var _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-monite-version": requestOptions?.moniteVersion, + "x-monite-entity-id": requestOptions?.moniteEntityId, + }), + requestOptions?.headers, + ); const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( + url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.MoniteEnvironment.Sandbox, `webhook_subscriptions/${encodeURIComponent(webhookSubscriptionId)}/regenerate_secret`, ), method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "x-monite-version": await core.Supplier.get(this._options.moniteVersion), - "x-monite-entity-id": - (await core.Supplier.get(this._options.moniteEntityId)) != null - ? await core.Supplier.get(this._options.moniteEntityId) - : undefined, - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@monite/node-client", - "X-Fern-SDK-Version": "0.3.3", - "User-Agent": "@monite/node-client/0.3.3", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - ...requestOptions?.headers, - }, - contentType: "application/json", - requestType: "json", + headers: _headers, + queryParameters: requestOptions?.queryParams, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -774,10 +782,14 @@ export class WebhookSubscriptions { if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 401: + throw new Monite.UnauthorizedError(_response.error.body as unknown, _response.rawResponse); + case 404: + throw new Monite.NotFoundError(_response.error.body as unknown, _response.rawResponse); case 422: throw new Monite.UnprocessableEntityError(_response.error.body as unknown, _response.rawResponse); - case 500: - throw new Monite.InternalServerError(_response.error.body as unknown, _response.rawResponse); + case 429: + throw new Monite.TooManyRequestsError(_response.error.body as unknown, _response.rawResponse); default: throw new errors.MoniteError({ statusCode: _response.error.statusCode, diff --git a/src/api/resources/webhookSubscriptions/client/index.ts b/src/api/resources/webhookSubscriptions/client/index.ts index 415726b..82648c6 100644 --- a/src/api/resources/webhookSubscriptions/client/index.ts +++ b/src/api/resources/webhookSubscriptions/client/index.ts @@ -1 +1,2 @@ -export * from "./requests"; +export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/webhookSubscriptions/client/requests/CreateWebhookSubscriptionRequest.ts b/src/api/resources/webhookSubscriptions/client/requests/CreateWebhookSubscriptionRequest.ts index 6487fa9..dbed51b 100644 --- a/src/api/resources/webhookSubscriptions/client/requests/CreateWebhookSubscriptionRequest.ts +++ b/src/api/resources/webhookSubscriptions/client/requests/CreateWebhookSubscriptionRequest.ts @@ -2,17 +2,29 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * { - * object_type: "account", - * url: "url" + * event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + * object_type: "entity", + * url: "https://example.com/your-webhook-listener" * } */ export interface CreateWebhookSubscriptionRequest { + /** A list of [events](https://docs.monite.com/references/webhooks/index#events) to subscribe to. If set to an empty array, the subscription includes all events triggered by the specified `object_type`. */ event_types?: string[]; + /** + * The [object type](https://docs.monite.com/references/webhooks/index#events) to whose events you want to subscribe. + * + * To subscribe to events from multiple object types, create a separate subscription for each object type. + */ object_type: Monite.WebhookObjectType; + /** + * An HTTPS URL to which Monite will send webhooks. This URL must be accessible over the public Internet, accept POST requests, and respond with status code 200. It must be a direct URL (no redirects). + * + * The same URL can be used by multiple webhook subscriptions. + */ url: string; } diff --git a/src/api/resources/webhookSubscriptions/client/requests/UpdateWebhookSubscriptionRequest.ts b/src/api/resources/webhookSubscriptions/client/requests/UpdateWebhookSubscriptionRequest.ts index 8d1df65..df78c66 100644 --- a/src/api/resources/webhookSubscriptions/client/requests/UpdateWebhookSubscriptionRequest.ts +++ b/src/api/resources/webhookSubscriptions/client/requests/UpdateWebhookSubscriptionRequest.ts @@ -2,14 +2,25 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface UpdateWebhookSubscriptionRequest { + /** A list of [events](https://docs.monite.com/references/webhooks/index#events) to subscribe to. If set to an empty array, the subscription includes all events triggered by the specified `object_type`. */ event_types?: string[]; + /** + * The [object type](https://docs.monite.com/references/webhooks/index#events) to whose events you want to subscribe. + * + * To subscribe to events from multiple object types, create a separate subscription for each object type. + */ object_type?: Monite.WebhookObjectType; + /** + * An HTTPS URL to which Monite will send webhooks. This URL must be accessible over the public Internet, accept POST requests, and respond with status code 200. It must be a direct URL (no redirects). + * + * The same URL can be used by multiple webhook subscriptions. + */ url?: string; } diff --git a/src/api/resources/webhookSubscriptions/client/requests/WebhookSubscriptionsGetRequest.ts b/src/api/resources/webhookSubscriptions/client/requests/WebhookSubscriptionsGetRequest.ts index 9b79e51..8237a58 100644 --- a/src/api/resources/webhookSubscriptions/client/requests/WebhookSubscriptionsGetRequest.ts +++ b/src/api/resources/webhookSubscriptions/client/requests/WebhookSubscriptionsGetRequest.ts @@ -2,20 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../../../../index"; +import * as Monite from "../../../../index.js"; /** * @example * {} */ export interface WebhookSubscriptionsGetRequest { - /** - * Sort order (ascending by default). Typically used together with the `sort` parameter. - */ + /** Sort order (ascending by default). Typically used together with the `sort` parameter. */ order?: Monite.OrderEnum; - /** - * The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. - */ + /** The number of items (0 .. 100) to return in a single page of the response. The response may contain fewer items if it is the last or only page. */ limit?: number; /** * A pagination token obtained from a previous call to this endpoint. Use it to get the next or previous page of results for your initial query. If `pagination_token` is specified, all other query parameters are ignored and inferred from the initial query. @@ -23,13 +19,15 @@ export interface WebhookSubscriptionsGetRequest { * If not specified, the first page of results will be returned. */ pagination_token?: string; - /** - * The field to sort the results by. Typically used together with the `order` parameter. - */ + /** The field to sort the results by. Typically used together with the `order` parameter. */ sort?: Monite.WebhookSubscriptionCursorFields; object_type?: Monite.WebhookObjectType; + /** Return only subscriptions created after the specified date and time. */ created_at__gt?: string; + /** Return only subscriptions created before the specified date and time. */ created_at__lt?: string; + /** Return only subscriptions created on or after the specified date and time. */ created_at__gte?: string; + /** Return only subscriptions created before or on the specified date and time. */ created_at__lte?: string; } diff --git a/src/api/resources/webhookSubscriptions/client/requests/index.ts b/src/api/resources/webhookSubscriptions/client/requests/index.ts index 8c230a7..664b64e 100644 --- a/src/api/resources/webhookSubscriptions/client/requests/index.ts +++ b/src/api/resources/webhookSubscriptions/client/requests/index.ts @@ -1,3 +1,3 @@ -export { type WebhookSubscriptionsGetRequest } from "./WebhookSubscriptionsGetRequest"; -export { type CreateWebhookSubscriptionRequest } from "./CreateWebhookSubscriptionRequest"; -export { type UpdateWebhookSubscriptionRequest } from "./UpdateWebhookSubscriptionRequest"; +export { type WebhookSubscriptionsGetRequest } from "./WebhookSubscriptionsGetRequest.js"; +export { type CreateWebhookSubscriptionRequest } from "./CreateWebhookSubscriptionRequest.js"; +export { type UpdateWebhookSubscriptionRequest } from "./UpdateWebhookSubscriptionRequest.js"; diff --git a/src/api/resources/webhookSubscriptions/index.ts b/src/api/resources/webhookSubscriptions/index.ts index 5ec7692..914b8c3 100644 --- a/src/api/resources/webhookSubscriptions/index.ts +++ b/src/api/resources/webhookSubscriptions/index.ts @@ -1 +1 @@ -export * from "./client"; +export * from "./client/index.js"; diff --git a/src/api/types/AccessTokenResponse.ts b/src/api/types/AccessTokenResponse.ts index ff093d2..fc531aa 100644 --- a/src/api/types/AccessTokenResponse.ts +++ b/src/api/types/AccessTokenResponse.ts @@ -3,7 +3,10 @@ */ export interface AccessTokenResponse { + /** The access token. Send it in the `Authorization: Bearer ACCESS_TOKEN` header in subsequent API calls. */ access_token: string; + /** The token expiration time, in seconds. */ expires_in: number; + /** Always "Bearer". */ token_type: string; } diff --git a/src/api/types/AccountingConnectionList.ts b/src/api/types/AccountingConnectionList.ts index 79c1cf6..f9b9d7a 100644 --- a/src/api/types/AccountingConnectionList.ts +++ b/src/api/types/AccountingConnectionList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingConnectionList { data: Monite.AccountingConnectionResponse[]; diff --git a/src/api/types/AccountingConnectionResponse.ts b/src/api/types/AccountingConnectionResponse.ts index dcd0043..e25573d 100644 --- a/src/api/types/AccountingConnectionResponse.ts +++ b/src/api/types/AccountingConnectionResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingConnectionResponse { id: string; diff --git a/src/api/types/AccountingLineItem.ts b/src/api/types/AccountingLineItem.ts index 782ab75..a309ad3 100644 --- a/src/api/types/AccountingLineItem.ts +++ b/src/api/types/AccountingLineItem.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains the details of an invoice line item retrieved from an accounting system. diff --git a/src/api/types/AccountingPayable.ts b/src/api/types/AccountingPayable.ts index 61abfbb..4300433 100644 --- a/src/api/types/AccountingPayable.ts +++ b/src/api/types/AccountingPayable.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Details of an accounts payable invoice (bill) retrieved from an accounting system. @@ -17,7 +17,7 @@ export interface AccountingPayable { /** Rate to convert the total amount of the transaction into the entity's base currency at the time of the transaction. */ currency_rate?: number; /** The payable's due date. */ - due_date?: Monite.AccountingPayableDueDate; + due_date?: AccountingPayable.DueDate; /** Invoice number of the payable. */ invoice_number?: string; lines?: Monite.AccountingLineItem[]; @@ -38,3 +38,10 @@ export interface AccountingPayable { /** Information about the vendor from whom the payable was received. */ vendor_ref?: Monite.AccountingVendorRefObject; } + +export namespace AccountingPayable { + /** + * The payable's due date. + */ + export type DueDate = string | string; +} diff --git a/src/api/types/AccountingPayableDueDate.ts b/src/api/types/AccountingPayableDueDate.ts deleted file mode 100644 index 99beb7f..0000000 --- a/src/api/types/AccountingPayableDueDate.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * The payable's due date. - */ -export type AccountingPayableDueDate = string | string; diff --git a/src/api/types/AccountingPayableList.ts b/src/api/types/AccountingPayableList.ts index 9e35c91..2429960 100644 --- a/src/api/types/AccountingPayableList.ts +++ b/src/api/types/AccountingPayableList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingPayableList { data: Monite.AccountingPayable[]; diff --git a/src/api/types/AccountingReceivable.ts b/src/api/types/AccountingReceivable.ts index 380d062..c5138f4 100644 --- a/src/api/types/AccountingReceivable.ts +++ b/src/api/types/AccountingReceivable.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Invoice details retrieved from an accounting system. @@ -17,7 +17,7 @@ export interface AccountingReceivable { /** Information about the customer that the invoice was sent to. */ customer_ref?: Monite.AccountingCustomerRefObject; /** Invoice due date. */ - due_date?: Monite.AccountingReceivableDueDate; + due_date?: AccountingReceivable.DueDate; /** Invoice document number. */ invoice_number?: string; lines?: Monite.AccountingLineItem[]; @@ -28,3 +28,10 @@ export interface AccountingReceivable { /** Date when the invoice was added to the accounting service. This may differ from the invoice creation date. */ posted_date?: string; } + +export namespace AccountingReceivable { + /** + * Invoice due date. + */ + export type DueDate = string | string; +} diff --git a/src/api/types/AccountingReceivableDueDate.ts b/src/api/types/AccountingReceivableDueDate.ts deleted file mode 100644 index 75e27df..0000000 --- a/src/api/types/AccountingReceivableDueDate.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * Invoice due date. - */ -export type AccountingReceivableDueDate = string | string; diff --git a/src/api/types/AccountingReceivableList.ts b/src/api/types/AccountingReceivableList.ts index 11b071b..31e5d0c 100644 --- a/src/api/types/AccountingReceivableList.ts +++ b/src/api/types/AccountingReceivableList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingReceivableList { data: Monite.AccountingReceivable[]; diff --git a/src/api/types/AccountingSettings.ts b/src/api/types/AccountingSettings.ts index d1b49f6..e3f8233 100644 --- a/src/api/types/AccountingSettings.ts +++ b/src/api/types/AccountingSettings.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingSettings { /** Default ledger accounts that will be used for various objects pushed into an accounting system. Use `GET /ledger_accounts` to get the IDs of these ledger accounts. */ diff --git a/src/api/types/AccountingTaxRateListResponse.ts b/src/api/types/AccountingTaxRateListResponse.ts index 478faf2..07cc056 100644 --- a/src/api/types/AccountingTaxRateListResponse.ts +++ b/src/api/types/AccountingTaxRateListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingTaxRateListResponse { data: Monite.AccountingTaxRateResponse[]; diff --git a/src/api/types/AccountingTaxRateResponse.ts b/src/api/types/AccountingTaxRateResponse.ts index daaba59..2946223 100644 --- a/src/api/types/AccountingTaxRateResponse.ts +++ b/src/api/types/AccountingTaxRateResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AccountingTaxRateResponse { id: string; diff --git a/src/api/types/ActionSchema.ts b/src/api/types/ActionSchema.ts index d1478e6..e1e4095 100644 --- a/src/api/types/ActionSchema.ts +++ b/src/api/types/ActionSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ActionSchema { /** Action name */ diff --git a/src/api/types/AirwallexMandate.ts b/src/api/types/AirwallexMandate.ts deleted file mode 100644 index acff632..0000000 --- a/src/api/types/AirwallexMandate.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface AirwallexMandate { - /** PDF copy of mandate will be sent to the email by Airwallex */ - email: string; - /** Name of the person signed the mandate, must be a bank account owner */ - signatory: string; - type: Monite.AirwallexMandateType; - version: Monite.AirwallexMandateVersion; -} diff --git a/src/api/types/AirwallexMandateType.ts b/src/api/types/AirwallexMandateType.ts deleted file mode 100644 index 455edd3..0000000 --- a/src/api/types/AirwallexMandateType.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type AirwallexMandateType = "us_ach_debit"; diff --git a/src/api/types/AirwallexPlaidAccount.ts b/src/api/types/AirwallexPlaidAccount.ts deleted file mode 100644 index b8d8b4b..0000000 --- a/src/api/types/AirwallexPlaidAccount.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface AirwallexPlaidAccount { - /** Plaid`s unique identifier for the account */ - id: string; - /** The last 2-4 alphanumeric characters of an account's official account number */ - mask: string; - /** The name of the account, either assigned by the user or by the financial institution itself */ - name: string; -} diff --git a/src/api/types/AirwallexPlaidBankAccountVerificationStatus.ts b/src/api/types/AirwallexPlaidBankAccountVerificationStatus.ts deleted file mode 100644 index 46334ce..0000000 --- a/src/api/types/AirwallexPlaidBankAccountVerificationStatus.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type AirwallexPlaidBankAccountVerificationStatus = "verified" | "expired" | "suspended"; -export const AirwallexPlaidBankAccountVerificationStatus = { - Verified: "verified", - Expired: "expired", - Suspended: "suspended", -} as const; diff --git a/src/api/types/AirwallexPlaidInstitution.ts b/src/api/types/AirwallexPlaidInstitution.ts deleted file mode 100644 index fb21c2b..0000000 --- a/src/api/types/AirwallexPlaidInstitution.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface AirwallexPlaidInstitution { - /** The institution identifier assigned by Plaid */ - id: string; - /** The full financial institution name */ - name: string; -} diff --git a/src/api/types/AirwallexPlaidVerification.ts b/src/api/types/AirwallexPlaidVerification.ts deleted file mode 100644 index 4ab4d93..0000000 --- a/src/api/types/AirwallexPlaidVerification.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface AirwallexPlaidVerification { - /** Status of the bank account verification */ - status: Monite.AirwallexPlaidBankAccountVerificationStatus; -} diff --git a/src/api/types/AllDocumentExportResponseSchema.ts b/src/api/types/AllDocumentExportResponseSchema.ts index de6d533..8926e70 100644 --- a/src/api/types/AllDocumentExportResponseSchema.ts +++ b/src/api/types/AllDocumentExportResponseSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AllDocumentExportResponseSchema { /** A set of export objects returned per page. */ diff --git a/src/api/types/AllOverdueRemindersResponse.ts b/src/api/types/AllOverdueRemindersResponse.ts index 97fbfda..182ef88 100644 --- a/src/api/types/AllOverdueRemindersResponse.ts +++ b/src/api/types/AllOverdueRemindersResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface AllOverdueRemindersResponse { data: Monite.OverdueReminderResponse[]; diff --git a/src/api/types/AllowedFileTypes.ts b/src/api/types/AllowedFileTypes.ts index 17c659f..d6e40f3 100644 --- a/src/api/types/AllowedFileTypes.ts +++ b/src/api/types/AllowedFileTypes.ts @@ -16,7 +16,8 @@ export type AllowedFileTypes = | "identity_documents" | "additional_identity_documents" | "receivable_signatures" - | "einvoices_xml"; + | "einvoices_xml" + | "attachments"; export const AllowedFileTypes = { OcrResults: "ocr_results", OcrFiles: "ocr_files", @@ -32,4 +33,5 @@ export const AllowedFileTypes = { AdditionalIdentityDocuments: "additional_identity_documents", ReceivableSignatures: "receivable_signatures", EinvoicesXml: "einvoices_xml", + Attachments: "attachments", } as const; diff --git a/src/api/types/ApprovalPolicyResource.ts b/src/api/types/ApprovalPolicyResource.ts index 1ec2303..7ba8971 100644 --- a/src/api/types/ApprovalPolicyResource.ts +++ b/src/api/types/ApprovalPolicyResource.ts @@ -2,8 +2,6 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; - export interface ApprovalPolicyResource { id: string; created_at: string; @@ -15,13 +13,36 @@ export interface ApprovalPolicyResource { ends_at?: string; /** The name of the approval policy. */ name: string; + /** The priority controls which approval policy takes precedence when a payable matches multiple approval policies. A higher value mean higher priority. */ + priority?: number; /** A list of JSON objects that represents the approval policy script. The script contains the logic that determines whether an action should be sent to approval. This field is required, and it should contain at least one script object. */ - script: Monite.ApprovalPolicyResourceScriptItem[]; + script: ApprovalPolicyResource.Script.Item[]; /** The date and time (in the ISO 8601 format) when the approval policy becomes active. Only payables submitted for approval during the policy's active period will trigger this policy. If omitted or `null`, the policy is effective immediately. The value will be converted to UTC. */ starts_at?: string; /** The current status of the approval policy. */ - status: Monite.ApprovalPolicyResourceStatus; + status: ApprovalPolicyResource.Status; /** A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. */ - trigger?: Monite.ApprovalPolicyResourceTrigger; + trigger?: ApprovalPolicyResource.Trigger; updated_by?: string; } + +export namespace ApprovalPolicyResource { + export type Script = Script.Item[]; + + export namespace Script { + export type Item = boolean | number | string | unknown[] | Record; + } + + /** + * The current status of the approval policy. + */ + export type Status = "active" | "pending"; + export const Status = { + Active: "active", + Pending: "pending", + } as const; + /** + * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. + */ + export type Trigger = boolean | number | string | unknown[] | Record; +} diff --git a/src/api/types/ApprovalPolicyResourceList.ts b/src/api/types/ApprovalPolicyResourceList.ts index c421e2d..56bf475 100644 --- a/src/api/types/ApprovalPolicyResourceList.ts +++ b/src/api/types/ApprovalPolicyResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalPolicyResourceList { data: Monite.ApprovalPolicyResource[]; diff --git a/src/api/types/ApprovalPolicyResourceScriptItem.ts b/src/api/types/ApprovalPolicyResourceScriptItem.ts deleted file mode 100644 index 48a1b4e..0000000 --- a/src/api/types/ApprovalPolicyResourceScriptItem.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type ApprovalPolicyResourceScriptItem = boolean | number | string | unknown[] | Record; diff --git a/src/api/types/ApprovalPolicyResourceStatus.ts b/src/api/types/ApprovalPolicyResourceStatus.ts deleted file mode 100644 index fd060e4..0000000 --- a/src/api/types/ApprovalPolicyResourceStatus.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * The current status of the approval policy. - */ -export type ApprovalPolicyResourceStatus = "active" | "pending"; -export const ApprovalPolicyResourceStatus = { - Active: "active", - Pending: "pending", -} as const; diff --git a/src/api/types/ApprovalPolicyResourceTrigger.ts b/src/api/types/ApprovalPolicyResourceTrigger.ts deleted file mode 100644 index 77167f2..0000000 --- a/src/api/types/ApprovalPolicyResourceTrigger.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated. - */ -export type ApprovalPolicyResourceTrigger = boolean | number | string | unknown[] | Record; diff --git a/src/api/types/ApprovalProcessResourceList.ts b/src/api/types/ApprovalProcessResourceList.ts index 967cf1f..62d784c 100644 --- a/src/api/types/ApprovalProcessResourceList.ts +++ b/src/api/types/ApprovalProcessResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalProcessResourceList { data: Monite.ProcessResource[]; diff --git a/src/api/types/ApprovalProcessStepResource.ts b/src/api/types/ApprovalProcessStepResource.ts index 284ec8e..eb93b42 100644 --- a/src/api/types/ApprovalProcessStepResource.ts +++ b/src/api/types/ApprovalProcessStepResource.ts @@ -2,9 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalProcessStepResource { + approval_request_id?: string; approved_by: string[]; object_id: string; rejected_by?: string; diff --git a/src/api/types/ApprovalProcessStepResourceList.ts b/src/api/types/ApprovalProcessStepResourceList.ts index 3e48c28..96b071e 100644 --- a/src/api/types/ApprovalProcessStepResourceList.ts +++ b/src/api/types/ApprovalProcessStepResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalProcessStepResourceList { data: Monite.ApprovalProcessStepResource[]; diff --git a/src/api/types/ApprovalRequestCreateByRoleRequest.ts b/src/api/types/ApprovalRequestCreateByRoleRequest.ts index 16301d0..056b192 100644 --- a/src/api/types/ApprovalRequestCreateByRoleRequest.ts +++ b/src/api/types/ApprovalRequestCreateByRoleRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalRequestCreateByRoleRequest { object_id: string; diff --git a/src/api/types/ApprovalRequestCreateByUserRequest.ts b/src/api/types/ApprovalRequestCreateByUserRequest.ts index 17ba956..2a13f76 100644 --- a/src/api/types/ApprovalRequestCreateByUserRequest.ts +++ b/src/api/types/ApprovalRequestCreateByUserRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalRequestCreateByUserRequest { object_id: string; diff --git a/src/api/types/ApprovalRequestCreateRequest.ts b/src/api/types/ApprovalRequestCreateRequest.ts index 98a4044..b26d6bf 100644 --- a/src/api/types/ApprovalRequestCreateRequest.ts +++ b/src/api/types/ApprovalRequestCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type ApprovalRequestCreateRequest = | Monite.ApprovalRequestCreateByRoleRequest diff --git a/src/api/types/ApprovalRequestResourceList.ts b/src/api/types/ApprovalRequestResourceList.ts index f969895..8d63b38 100644 --- a/src/api/types/ApprovalRequestResourceList.ts +++ b/src/api/types/ApprovalRequestResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalRequestResourceList { data: Monite.ApprovalRequestResourceWithMetadata[]; diff --git a/src/api/types/ApprovalRequestResourceWithMetadata.ts b/src/api/types/ApprovalRequestResourceWithMetadata.ts index 64cb254..4342ee7 100644 --- a/src/api/types/ApprovalRequestResourceWithMetadata.ts +++ b/src/api/types/ApprovalRequestResourceWithMetadata.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ApprovalRequestResourceWithMetadata { id: string; diff --git a/src/api/types/AttachmentRequest.ts b/src/api/types/AttachmentRequest.ts new file mode 100644 index 0000000..178097b --- /dev/null +++ b/src/api/types/AttachmentRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface AttachmentRequest { + /** Unique ID of the file with file_type=attachment from /v1/files. */ + id: string; + /** Indicates whether the file would be included in the email. */ + include_in_email?: boolean; +} diff --git a/src/api/types/AttachmentResponse.ts b/src/api/types/AttachmentResponse.ts new file mode 100644 index 0000000..03cba00 --- /dev/null +++ b/src/api/types/AttachmentResponse.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface AttachmentResponse { + /** Unique ID of the file with file_type=attachment from /v1/files. */ + id: string; + /** Indicates whether the file would be included in the email. */ + include_in_email?: boolean; + /** The file's media type, for example, `application/pdf` or `image/png`. */ + mimetype: string; + /** The original file name (if available). */ + name: string; + /** The file size in bytes. */ + size: number; + /** The URL to download the file. */ + url: string; +} diff --git a/src/api/types/BankAccount.ts b/src/api/types/BankAccount.ts index da156ce..2887e17 100644 --- a/src/api/types/BankAccount.ts +++ b/src/api/types/BankAccount.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface BankAccount { /** The ID of the bank account. */ diff --git a/src/api/types/BankAccountVerificationType.ts b/src/api/types/BankAccountVerificationType.ts deleted file mode 100644 index e78fd68..0000000 --- a/src/api/types/BankAccountVerificationType.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type BankAccountVerificationType = "airwallex_plaid" | "micro_deposit"; -export const BankAccountVerificationType = { - AirwallexPlaid: "airwallex_plaid", - MicroDeposit: "micro_deposit", -} as const; diff --git a/src/api/types/BankAccountVerifications.ts b/src/api/types/BankAccountVerifications.ts deleted file mode 100644 index 607649f..0000000 --- a/src/api/types/BankAccountVerifications.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface BankAccountVerifications { - /** Airwallex Plaid verification */ - airwallex_plaid?: Monite.AirwallexPlaidVerification; -} diff --git a/src/api/types/BasedOnReceivableCreatedEventData.ts b/src/api/types/BasedOnReceivableCreatedEventData.ts index df292fb..c81959c 100644 --- a/src/api/types/BasedOnReceivableCreatedEventData.ts +++ b/src/api/types/BasedOnReceivableCreatedEventData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * In invoice history, this object contains information about a credit note created for this invoice. diff --git a/src/api/types/BizObjectsSchemaInput.ts b/src/api/types/BizObjectsSchemaInput.ts index 8025fb4..fa1c14f 100644 --- a/src/api/types/BizObjectsSchemaInput.ts +++ b/src/api/types/BizObjectsSchemaInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface BizObjectsSchemaInput { /** List of objects */ diff --git a/src/api/types/BizObjectsSchemaOutput.ts b/src/api/types/BizObjectsSchemaOutput.ts index 035beab..75ef0fb 100644 --- a/src/api/types/BizObjectsSchemaOutput.ts +++ b/src/api/types/BizObjectsSchemaOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface BizObjectsSchemaOutput { /** List of objects */ diff --git a/src/api/types/BusinessProfileInput.ts b/src/api/types/BusinessProfileInput.ts index 64c611d..0d3924e 100644 --- a/src/api/types/BusinessProfileInput.ts +++ b/src/api/types/BusinessProfileInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface BusinessProfileInput { /** Required for US entities. A free-form description of the products the entity sells (whether online or at offline retail stores) or the services it provides to its customers. */ diff --git a/src/api/types/BusinessProfileOutput.ts b/src/api/types/BusinessProfileOutput.ts index 8cde9d5..211218a 100644 --- a/src/api/types/BusinessProfileOutput.ts +++ b/src/api/types/BusinessProfileOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface BusinessProfileOutput { /** Required for US entities. A free-form description of the products the entity sells (whether online or at offline retail stores) or the services it provides to its customers. */ diff --git a/src/api/types/ButtonTheme.ts b/src/api/types/ButtonTheme.ts index e803996..c4e2975 100644 --- a/src/api/types/ButtonTheme.ts +++ b/src/api/types/ButtonTheme.ts @@ -4,7 +4,10 @@ export interface ButtonTheme { primary_color?: string; + /** Unused. */ primary_hover_color?: string; + /** Unused. */ secondary_color?: string; + /** Unused. */ secondary_hover_color?: string; } diff --git a/src/api/types/CommentResource.ts b/src/api/types/CommentResource.ts index 3586915..29bfdff 100644 --- a/src/api/types/CommentResource.ts +++ b/src/api/types/CommentResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CommentResource { id: string; diff --git a/src/api/types/CommentResourceList.ts b/src/api/types/CommentResourceList.ts index 5264637..0590d4e 100644 --- a/src/api/types/CommentResourceList.ts +++ b/src/api/types/CommentResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CommentResourceList { data: Monite.CommentResource[]; diff --git a/src/api/types/CommonSchemaInput.ts b/src/api/types/CommonSchemaInput.ts index af93bb1..72de418 100644 --- a/src/api/types/CommonSchemaInput.ts +++ b/src/api/types/CommonSchemaInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CommonSchemaInput { /** List of actions */ diff --git a/src/api/types/CommonSchemaOutput.ts b/src/api/types/CommonSchemaOutput.ts index 1a5162e..c280116 100644 --- a/src/api/types/CommonSchemaOutput.ts +++ b/src/api/types/CommonSchemaOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CommonSchemaOutput { /** List of actions */ diff --git a/src/api/types/CompleteRefreshVerificationRequest.ts b/src/api/types/CompleteRefreshVerificationRequest.ts deleted file mode 100644 index c218cb8..0000000 --- a/src/api/types/CompleteRefreshVerificationRequest.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CompleteRefreshVerificationRequest { - type: Monite.BankAccountVerificationType; -} diff --git a/src/api/types/CompleteRefreshVerificationResponse.ts b/src/api/types/CompleteRefreshVerificationResponse.ts deleted file mode 100644 index 370ca9e..0000000 --- a/src/api/types/CompleteRefreshVerificationResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CompleteRefreshVerificationResponse { - verifications: Monite.BankAccountVerifications; -} diff --git a/src/api/types/CompleteVerificationAirwallexPlaidRequest.ts b/src/api/types/CompleteVerificationAirwallexPlaidRequest.ts deleted file mode 100644 index 1e54ed3..0000000 --- a/src/api/types/CompleteVerificationAirwallexPlaidRequest.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CompleteVerificationAirwallexPlaidRequest { - /** The bank account that was selected in the Plaid Modal */ - account: Monite.AirwallexPlaidAccount; - /** The financial institution that was selected in the Plaid Modal */ - institution: Monite.AirwallexPlaidInstitution; - mandate: Monite.AirwallexMandate; - /** The Plaid Public Token */ - public_token: string; -} diff --git a/src/api/types/CompleteVerificationRequest.ts b/src/api/types/CompleteVerificationRequest.ts deleted file mode 100644 index ef640dc..0000000 --- a/src/api/types/CompleteVerificationRequest.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CompleteVerificationRequest { - airwallex_plaid: Monite.CompleteVerificationAirwallexPlaidRequest; - type: Monite.BankAccountVerificationType; -} diff --git a/src/api/types/CompleteVerificationResponse.ts b/src/api/types/CompleteVerificationResponse.ts deleted file mode 100644 index 4c0bdd3..0000000 --- a/src/api/types/CompleteVerificationResponse.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CompleteVerificationResponse { - /** Deprecated. Use bank_account_id instead. */ - id: string; - /** Account holder's name */ - account_holder_name?: string; - /** Account number (required if IBAN is not provided) */ - account_number?: string; - bank_account_id: string; - /** The name of the entity`s bank account. */ - bank_name?: string; - /** The BIC of the entity`s bank account. */ - bic?: string; - country?: Monite.AllowedCountries; - currency?: Monite.CurrencyEnum; - display_name?: string; - /** The IBAN of the entity`s bank account. */ - iban?: string; - /** Marks if a bank account should be used by default for the currency. Only 1 can be True for each currency. */ - is_default: boolean; - /** Routing number (US) */ - routing_number?: string; - /** Sort code (GB) */ - sort_code?: string; - verifications: Monite.BankAccountVerifications; - was_created_by_user_id?: string; -} diff --git a/src/api/types/CounterpartAddress.ts b/src/api/types/CounterpartAddress.ts index 84902b2..e58cf16 100644 --- a/src/api/types/CounterpartAddress.ts +++ b/src/api/types/CounterpartAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. @@ -18,6 +18,6 @@ export interface CounterpartAddress { line2?: string; /** ZIP or postal code. */ postal_code: string; - /** State, region, province, or county. */ + /** State, county, province, prefecture, region, or similar component of the counterpart's address. For US counterparts, `state` is required and must be a two-letter [USPS state abbreviation](https://pe.usps.com/text/pub28/28apb.htm), for example, NY or CA. */ state?: string; } diff --git a/src/api/types/CounterpartAddressResourceList.ts b/src/api/types/CounterpartAddressResourceList.ts index 218b5eb..26e3de3 100644 --- a/src/api/types/CounterpartAddressResourceList.ts +++ b/src/api/types/CounterpartAddressResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartAddressResourceList { data: Monite.CounterpartAddressResponseWithCounterpartId[]; diff --git a/src/api/types/CounterpartAddressResponseWithCounterpartId.ts b/src/api/types/CounterpartAddressResponseWithCounterpartId.ts index 5eaef3c..219f77e 100644 --- a/src/api/types/CounterpartAddressResponseWithCounterpartId.ts +++ b/src/api/types/CounterpartAddressResponseWithCounterpartId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. diff --git a/src/api/types/CounterpartBankAccountResourceList.ts b/src/api/types/CounterpartBankAccountResourceList.ts index 0697eb5..e5d64d1 100644 --- a/src/api/types/CounterpartBankAccountResourceList.ts +++ b/src/api/types/CounterpartBankAccountResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartBankAccountResourceList { data: Monite.CounterpartBankAccountResponse[]; diff --git a/src/api/types/CounterpartBankAccountResponse.ts b/src/api/types/CounterpartBankAccountResponse.ts index eda1faa..772afd0 100644 --- a/src/api/types/CounterpartBankAccountResponse.ts +++ b/src/api/types/CounterpartBankAccountResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartBankAccountResponse { id: string; diff --git a/src/api/types/CounterpartContactResponse.ts b/src/api/types/CounterpartContactResponse.ts index 3ffa3b0..3ffcad4 100644 --- a/src/api/types/CounterpartContactResponse.ts +++ b/src/api/types/CounterpartContactResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * The contact person for an organization. diff --git a/src/api/types/CounterpartContactsResourceList.ts b/src/api/types/CounterpartContactsResourceList.ts index 9a7d86f..e5758da 100644 --- a/src/api/types/CounterpartContactsResourceList.ts +++ b/src/api/types/CounterpartContactsResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartContactsResourceList { data: Monite.CounterpartContactResponse[]; diff --git a/src/api/types/CounterpartCreatePayload.ts b/src/api/types/CounterpartCreatePayload.ts index 5dedcae..e0b4358 100644 --- a/src/api/types/CounterpartCreatePayload.ts +++ b/src/api/types/CounterpartCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * This schema is used to create new counterparts (either organizations or individuals). diff --git a/src/api/types/CounterpartEinvoicingCredentialExistenceResponse.ts b/src/api/types/CounterpartEinvoicingCredentialExistenceResponse.ts new file mode 100644 index 0000000..372f699 --- /dev/null +++ b/src/api/types/CounterpartEinvoicingCredentialExistenceResponse.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface CounterpartEinvoicingCredentialExistenceResponse { + /** `true` is the specified identifier is registered as a receiver in PEPPOL, and `false` otherwise. */ + exists: boolean; +} diff --git a/src/api/types/CounterpartEinvoicingCredentialResponse.ts b/src/api/types/CounterpartEinvoicingCredentialResponse.ts index 527872a..1437249 100644 --- a/src/api/types/CounterpartEinvoicingCredentialResponse.ts +++ b/src/api/types/CounterpartEinvoicingCredentialResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartEinvoicingCredentialResponse { id: string; diff --git a/src/api/types/CounterpartEinvoicingCredentialResponseList.ts b/src/api/types/CounterpartEinvoicingCredentialResponseList.ts index 3068a5c..fa32c86 100644 --- a/src/api/types/CounterpartEinvoicingCredentialResponseList.ts +++ b/src/api/types/CounterpartEinvoicingCredentialResponseList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartEinvoicingCredentialResponseList { data: Monite.CounterpartEinvoicingCredentialResponse[]; diff --git a/src/api/types/CounterpartEinvoicingCredentialSchema.ts b/src/api/types/CounterpartEinvoicingCredentialSchema.ts index 13a6c6b..45664fb 100644 --- a/src/api/types/CounterpartEinvoicingCredentialSchema.ts +++ b/src/api/types/CounterpartEinvoicingCredentialSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartEinvoicingCredentialSchema { network_identifier: string; diff --git a/src/api/types/CounterpartFields.ts b/src/api/types/CounterpartFields.ts index 0db791a..05c3694 100644 --- a/src/api/types/CounterpartFields.ts +++ b/src/api/types/CounterpartFields.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartFields { /** Object describing the required field `tax_id` of an counterpart */ diff --git a/src/api/types/CounterpartIndividualCreatePayload.ts b/src/api/types/CounterpartIndividualCreatePayload.ts index 8180f14..777c197 100644 --- a/src/api/types/CounterpartIndividualCreatePayload.ts +++ b/src/api/types/CounterpartIndividualCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are individuals (natural persons). diff --git a/src/api/types/CounterpartIndividualResponse.ts b/src/api/types/CounterpartIndividualResponse.ts index 3978282..167a6fe 100644 --- a/src/api/types/CounterpartIndividualResponse.ts +++ b/src/api/types/CounterpartIndividualResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartIndividualResponse { /** The person's email address. */ diff --git a/src/api/types/CounterpartIndividualRootCreatePayload.ts b/src/api/types/CounterpartIndividualRootCreatePayload.ts index 7b2bf54..80fc90f 100644 --- a/src/api/types/CounterpartIndividualRootCreatePayload.ts +++ b/src/api/types/CounterpartIndividualRootCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * This schema is used to create counterparts that are individuals (natural persons). diff --git a/src/api/types/CounterpartIndividualRootResponse.ts b/src/api/types/CounterpartIndividualRootResponse.ts index 6dfc30e..b2f90a9 100644 --- a/src/api/types/CounterpartIndividualRootResponse.ts +++ b/src/api/types/CounterpartIndividualRootResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are individuals (natural persons). @@ -16,12 +16,12 @@ export interface CounterpartIndividualRootResponse { updated_at: string; /** `true` if the counterpart was created automatically by Monite when processing incoming invoices with OCR. `false` if the counterpart was created by the API client. */ created_automatically?: boolean; + /** Entity user ID of counterpart creator. */ + created_by_entity_user_id?: string; /** ID of the counterpart's billing address. If the counterpart is US-based and needs to accept ACH payments, this address must have all fields filled in. If `default_billing_address_id` is not defined, the default address is instead used as the billing address for ACH payments. */ default_billing_address_id?: string; /** ID of the shipping address. */ default_shipping_address_id?: string; - /** Entity user ID of counterpart creator. */ - created_by_entity_user_id?: string; /** A user-defined identifier of the counterpart. For example, the customer or vendor reference number in the entity's CRM system. If specified, it will be displayed in PDF invoices and other accounts receivable documents created by the entity. */ external_reference?: string; individual: Monite.CounterpartIndividualResponse; diff --git a/src/api/types/CounterpartIndividualRootUpdatePayload.ts b/src/api/types/CounterpartIndividualRootUpdatePayload.ts index d88135a..501c884 100644 --- a/src/api/types/CounterpartIndividualRootUpdatePayload.ts +++ b/src/api/types/CounterpartIndividualRootUpdatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are individuals (natural persons). diff --git a/src/api/types/CounterpartOrganizationCreatePayload.ts b/src/api/types/CounterpartOrganizationCreatePayload.ts index 50fbcd7..5b3adc2 100644 --- a/src/api/types/CounterpartOrganizationCreatePayload.ts +++ b/src/api/types/CounterpartOrganizationCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are organizations (juridical persons). diff --git a/src/api/types/CounterpartOrganizationResponse.ts b/src/api/types/CounterpartOrganizationResponse.ts index c624c5d..e32b9a5 100644 --- a/src/api/types/CounterpartOrganizationResponse.ts +++ b/src/api/types/CounterpartOrganizationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartOrganizationResponse { /** The email address of the organization */ diff --git a/src/api/types/CounterpartOrganizationRootCreatePayload.ts b/src/api/types/CounterpartOrganizationRootCreatePayload.ts index bca33ef..ad8b61c 100644 --- a/src/api/types/CounterpartOrganizationRootCreatePayload.ts +++ b/src/api/types/CounterpartOrganizationRootCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * This schema is used to create counterparts that are organizations (juridical persons). diff --git a/src/api/types/CounterpartOrganizationRootResponse.ts b/src/api/types/CounterpartOrganizationRootResponse.ts index 1171804..238ae01 100644 --- a/src/api/types/CounterpartOrganizationRootResponse.ts +++ b/src/api/types/CounterpartOrganizationRootResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are organizations (juridical persons). @@ -16,12 +16,12 @@ export interface CounterpartOrganizationRootResponse { updated_at: string; /** `true` if the counterpart was created automatically by Monite when processing incoming invoices with OCR. `false` if the counterpart was created by the API client. */ created_automatically?: boolean; + /** Entity user ID of counterpart creator. */ + created_by_entity_user_id?: string; /** ID of the counterpart's billing address. If the counterpart is US-based and needs to accept ACH payments, this address must have all fields filled in. If `default_billing_address_id` is not defined, the default address is instead used as the billing address for ACH payments. */ default_billing_address_id?: string; /** ID of the shipping address. */ default_shipping_address_id?: string; - /** Entity user ID of counterpart creator. */ - created_by_entity_user_id?: string; /** A user-defined identifier of the counterpart. For example, the customer or vendor reference number in the entity's CRM system. If specified, it will be displayed in PDF invoices and other accounts receivable documents created by the entity. */ external_reference?: string; /** The language used to generate PDF documents for this counterpart. */ diff --git a/src/api/types/CounterpartOrganizationRootUpdatePayload.ts b/src/api/types/CounterpartOrganizationRootUpdatePayload.ts index 4887eb7..8d91c7a 100644 --- a/src/api/types/CounterpartOrganizationRootUpdatePayload.ts +++ b/src/api/types/CounterpartOrganizationRootUpdatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are organizations (juridical persons). diff --git a/src/api/types/CounterpartPaginationResponse.ts b/src/api/types/CounterpartPaginationResponse.ts index 0917756..df40aa6 100644 --- a/src/api/types/CounterpartPaginationResponse.ts +++ b/src/api/types/CounterpartPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of counterparts diff --git a/src/api/types/CounterpartRawAddress.ts b/src/api/types/CounterpartRawAddress.ts index f5621ad..a48084e 100644 --- a/src/api/types/CounterpartRawAddress.ts +++ b/src/api/types/CounterpartRawAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. diff --git a/src/api/types/CounterpartRawAddressUpdateRequest.ts b/src/api/types/CounterpartRawAddressUpdateRequest.ts index badacaf..a08c602 100644 --- a/src/api/types/CounterpartRawAddressUpdateRequest.ts +++ b/src/api/types/CounterpartRawAddressUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. diff --git a/src/api/types/CounterpartRawBankAccount.ts b/src/api/types/CounterpartRawBankAccount.ts index f5203c3..ed015ac 100644 --- a/src/api/types/CounterpartRawBankAccount.ts +++ b/src/api/types/CounterpartRawBankAccount.ts @@ -11,6 +11,8 @@ export interface CounterpartRawBankAccount { bic?: string; /** required for non-GB bank accounts */ iban?: string; + /** required for US bank accounts */ + routing_number?: string; /** required for GB bank accounts */ sort_code?: string; } diff --git a/src/api/types/CounterpartRawBankAccountUpdateRequest.ts b/src/api/types/CounterpartRawBankAccountUpdateRequest.ts index 390cb70..9bfdebb 100644 --- a/src/api/types/CounterpartRawBankAccountUpdateRequest.ts +++ b/src/api/types/CounterpartRawBankAccountUpdateRequest.ts @@ -11,6 +11,8 @@ export interface CounterpartRawBankAccountUpdateRequest { bic?: string; /** required for non-GB bank accounts */ iban?: string; + /** required for US bank accounts */ + routing_number?: string; /** required for GB bank accounts */ sort_code?: string; } diff --git a/src/api/types/CounterpartRawData.ts b/src/api/types/CounterpartRawData.ts index 50a101b..58c3fcf 100644 --- a/src/api/types/CounterpartRawData.ts +++ b/src/api/types/CounterpartRawData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartRawData { /** The address of the vendor or supplier. */ diff --git a/src/api/types/CounterpartRawDataUpdateRequest.ts b/src/api/types/CounterpartRawDataUpdateRequest.ts index 1d073b9..9c6ed89 100644 --- a/src/api/types/CounterpartRawDataUpdateRequest.ts +++ b/src/api/types/CounterpartRawDataUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartRawDataUpdateRequest { /** The address of the vendor or supplier. */ diff --git a/src/api/types/CounterpartRawVatId.ts b/src/api/types/CounterpartRawVatId.ts index 8ecf5dc..1505089 100644 --- a/src/api/types/CounterpartRawVatId.ts +++ b/src/api/types/CounterpartRawVatId.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartRawVatId { country?: Monite.AllowedCountries; diff --git a/src/api/types/CounterpartRawVatIdUpdateRequest.ts b/src/api/types/CounterpartRawVatIdUpdateRequest.ts index 098cb7c..aee375e 100644 --- a/src/api/types/CounterpartRawVatIdUpdateRequest.ts +++ b/src/api/types/CounterpartRawVatIdUpdateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartRawVatIdUpdateRequest { country?: Monite.AllowedCountries; diff --git a/src/api/types/CounterpartResponse.ts b/src/api/types/CounterpartResponse.ts index 1c12034..23e273d 100644 --- a/src/api/types/CounterpartResponse.ts +++ b/src/api/types/CounterpartResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A Counterpart object contains information about an organization (juridical person) or diff --git a/src/api/types/CounterpartTagCategory.ts b/src/api/types/CounterpartTagCategory.ts deleted file mode 100644 index 9c12682..0000000 --- a/src/api/types/CounterpartTagCategory.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type CounterpartTagCategory = - | "document_type" - | "department" - | "project" - | "cost_center" - | "vendor_type" - | "payment_method" - | "approval_status"; -export const CounterpartTagCategory = { - DocumentType: "document_type", - Department: "department", - Project: "project", - CostCenter: "cost_center", - VendorType: "vendor_type", - PaymentMethod: "payment_method", - ApprovalStatus: "approval_status", -} as const; diff --git a/src/api/types/CounterpartTagSchema.ts b/src/api/types/CounterpartTagSchema.ts index 982455c..3373e3f 100644 --- a/src/api/types/CounterpartTagSchema.ts +++ b/src/api/types/CounterpartTagSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a user-defined tag that can be assigned to resources to filter them. @@ -15,7 +15,7 @@ export interface CounterpartTagSchema { /** Date and time when the tag was last updated. Timestamps follow the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard. */ updated_at: string; /** The tag category. */ - category?: Monite.CounterpartTagCategory; + category?: Monite.TagCategory; /** ID of the user who created the tag. */ created_by_entity_user_id?: string; /** The tag description. */ diff --git a/src/api/types/CounterpartUpdatePayload.ts b/src/api/types/CounterpartUpdatePayload.ts index 4dba3b7..1741b5b 100644 --- a/src/api/types/CounterpartUpdatePayload.ts +++ b/src/api/types/CounterpartUpdatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * This schema is used to update existing counterparts (organizations or individuals). diff --git a/src/api/types/CounterpartVatIdResourceList.ts b/src/api/types/CounterpartVatIdResourceList.ts index 028549d..57c2c4f 100644 --- a/src/api/types/CounterpartVatIdResourceList.ts +++ b/src/api/types/CounterpartVatIdResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartVatIdResourceList { data: Monite.CounterpartVatIdResponse[]; diff --git a/src/api/types/CounterpartVatIdResponse.ts b/src/api/types/CounterpartVatIdResponse.ts index 4e81578..9c42e6a 100644 --- a/src/api/types/CounterpartVatIdResponse.ts +++ b/src/api/types/CounterpartVatIdResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CounterpartVatIdResponse { id: string; diff --git a/src/api/types/CreateCounterpartEinvoicingCredentialPayload.ts b/src/api/types/CreateCounterpartEinvoicingCredentialPayload.ts index bdf3b20..9d55e1b 100644 --- a/src/api/types/CreateCounterpartEinvoicingCredentialPayload.ts +++ b/src/api/types/CreateCounterpartEinvoicingCredentialPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type CreateCounterpartEinvoicingCredentialPayload = | Monite.CreateCounterpartEinvoicingCredentialCounterpartVatId diff --git a/src/api/types/CreateOnboardingLinkRequest.ts b/src/api/types/CreateOnboardingLinkRequest.ts deleted file mode 100644 index 461e335..0000000 --- a/src/api/types/CreateOnboardingLinkRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface CreateOnboardingLinkRequest { - recipient: Monite.Recipient; - refresh_url: string; - return_url: string; -} diff --git a/src/api/types/CreditNoteLineItemPaginationResponse.ts b/src/api/types/CreditNoteLineItemPaginationResponse.ts index b01ba2c..82f6708 100644 --- a/src/api/types/CreditNoteLineItemPaginationResponse.ts +++ b/src/api/types/CreditNoteLineItemPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of credit note line items. diff --git a/src/api/types/CreditNotePaginationResponse.ts b/src/api/types/CreditNotePaginationResponse.ts index c6c2d3e..a585d0b 100644 --- a/src/api/types/CreditNotePaginationResponse.ts +++ b/src/api/types/CreditNotePaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of credit notes. diff --git a/src/api/types/CreditNoteResponse.ts b/src/api/types/CreditNoteResponse.ts index 24d1c51..5e999fe 100644 --- a/src/api/types/CreditNoteResponse.ts +++ b/src/api/types/CreditNoteResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Schema for credit note response. Includes all fields that can be returned from the API. diff --git a/src/api/types/CreditNoteResponsePayload.ts b/src/api/types/CreditNoteResponsePayload.ts index b789f32..37d32b0 100644 --- a/src/api/types/CreditNoteResponsePayload.ts +++ b/src/api/types/CreditNoteResponsePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CreditNoteResponsePayload { id: string; @@ -10,6 +10,8 @@ export interface CreditNoteResponsePayload { created_at: string; /** Time at which the receivable was last updated. Timestamps follow the ISO 8601 standard. */ updated_at: string; + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentResponse[]; /** The unique ID of a previous document related to the receivable if applicable. */ based_on?: string; /** The unique document ID of a previous document related to the receivable if applicable. */ @@ -35,7 +37,7 @@ export interface CreditNoteResponsePayload { /** The VAT/TAX ID of the counterpart. */ counterpart_tax_id?: string; /** The type of the counterpart. */ - counterpart_type: Monite.ReceivableCounterpartType; + counterpart_type: Monite.CounterpartType; counterpart_vat_id?: Monite.ReceivableCounterpartVatIdResponse; /** The currency used in the receivable. */ currency: Monite.CurrencyEnum; @@ -44,11 +46,13 @@ export interface CreditNoteResponsePayload { /** A note with additional information about a tax deduction */ deduction_memo?: string; /** The discount for a receivable. */ - discount?: Monite.Discount; + discount?: Monite.DiscountResponse; /** Total price of the receivable with discounts before taxes [minor units](https://docs.monite.com/references/currencies#minor-units). */ discounted_subtotal?: number; /** The sequential code systematically assigned to invoices. */ document_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; /** Optional field representing date until which invoice should be paid */ due_date?: string; /** Error that was returned by E-invoicing */ @@ -65,12 +69,14 @@ export interface CreditNoteResponsePayload { file_language: Monite.LanguageCodeEnum; /** The receivable's PDF URL in the counterpart's default language. */ file_url?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** Optional text displayed below the line items table in the PDF. See also: `memo`, `commercial_condition_description`. */ footer?: string; + /** If `true`, the credit note will be sent through an e-invoicing network. The value is inherited from the invoice for which the credit note was created, and cannot be changed. */ + is_einvoice?: boolean; /** Optional field for the issue of the entry. */ issue_date?: string; line_items: Monite.ResponseItem[]; - /** A note with additional information for a receivable. */ + /** An optional note for the customer, displayed above the line items table in the PDF. See also: `footer`, `commercial_condition_description`. */ memo?: string; /** E-invoicing credentials of the entity */ network_credentials?: Monite.EinvoicingCredentials; @@ -80,7 +86,7 @@ export interface CreditNoteResponsePayload { original_file_url?: string; /** Metadata for partner needs */ partner_metadata?: Record; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this credit note. If specified, the project name will be included in the header of the PDF credit note. */ project_id?: string; /** Contain purchase order number. */ purchase_order?: string; diff --git a/src/api/types/CreditNoteResponsePayloadEntity.ts b/src/api/types/CreditNoteResponsePayloadEntity.ts index 47f06da..7c36cfd 100644 --- a/src/api/types/CreditNoteResponsePayloadEntity.ts +++ b/src/api/types/CreditNoteResponsePayloadEntity.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type CreditNoteResponsePayloadEntity = | Monite.CreditNoteResponsePayloadEntity.Organization diff --git a/src/api/types/CreditNoteStateEnum.ts b/src/api/types/CreditNoteStateEnum.ts index 620d043..b600dbe 100644 --- a/src/api/types/CreditNoteStateEnum.ts +++ b/src/api/types/CreditNoteStateEnum.ts @@ -2,6 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ +/** + * Credit note statuses (used in accounts receivable). + */ export type CreditNoteStateEnum = "draft" | "issuing" | "issued" | "failed"; export const CreditNoteStateEnum = { Draft: "draft", diff --git a/src/api/types/CreditNoteValidationsResource.ts b/src/api/types/CreditNoteValidationsResource.ts index e99d489..0a74e01 100644 --- a/src/api/types/CreditNoteValidationsResource.ts +++ b/src/api/types/CreditNoteValidationsResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CreditNoteValidationsResource { required_fields: Monite.CreditNoteFieldsAllowedForValidate[]; diff --git a/src/api/types/CurrencySettingsInput.ts b/src/api/types/CurrencySettingsInput.ts index e300e2f..baf4ae6 100644 --- a/src/api/types/CurrencySettingsInput.ts +++ b/src/api/types/CurrencySettingsInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CurrencySettingsInput { default: Monite.CurrencyEnum; diff --git a/src/api/types/CurrencySettingsOutput.ts b/src/api/types/CurrencySettingsOutput.ts index e324c86..65d28ee 100644 --- a/src/api/types/CurrencySettingsOutput.ts +++ b/src/api/types/CurrencySettingsOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CurrencySettingsOutput { default: Monite.CurrencyEnum; diff --git a/src/api/types/CustomTemplatesPaginationResponse.ts b/src/api/types/CustomTemplatesPaginationResponse.ts index 2232fc5..4cff454 100644 --- a/src/api/types/CustomTemplatesPaginationResponse.ts +++ b/src/api/types/CustomTemplatesPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface CustomTemplatesPaginationResponse { /** All user-defined email templates */ diff --git a/src/api/types/CustomVatRateResponse.ts b/src/api/types/CustomVatRateResponse.ts new file mode 100644 index 0000000..939628b --- /dev/null +++ b/src/api/types/CustomVatRateResponse.ts @@ -0,0 +1,21 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface CustomVatRateResponse { + id: string; + /** Time at which the Custom VAT rate was created. Timestamps follow the ISO 8601 standard. */ + created_at: string; + /** Time at which the Custom VAT rate was last updated. Timestamps follow the ISO 8601 standard. */ + updated_at: string; + /** Sub-taxes included in the Custom VAT. */ + components: Monite.VatRateComponent[]; + /** ID of the user that created the Custom VAT rate */ + created_by_entity_user_id?: string; + /** Display name of the Custom VAT. */ + name: string; + /** Total sum of the Custom VAT rate including components. Percent multiplied by a 100. Example: 12.125% is 1212.5. */ + value: number; +} diff --git a/src/api/types/CustomVatRateResponseList.ts b/src/api/types/CustomVatRateResponseList.ts new file mode 100644 index 0000000..1e15a63 --- /dev/null +++ b/src/api/types/CustomVatRateResponseList.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface CustomVatRateResponseList { + data: Monite.CustomVatRateResponse[]; +} diff --git a/src/api/types/DeliveryNoteCounterpartResource.ts b/src/api/types/DeliveryNoteCounterpartResource.ts index df16f2d..b5621f4 100644 --- a/src/api/types/DeliveryNoteCounterpartResource.ts +++ b/src/api/types/DeliveryNoteCounterpartResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteCounterpartResource { /** ID of the counterpart */ diff --git a/src/api/types/DeliveryNoteCreateLineItem.ts b/src/api/types/DeliveryNoteCreateLineItem.ts index 70a5a61..eba1d91 100644 --- a/src/api/types/DeliveryNoteCreateLineItem.ts +++ b/src/api/types/DeliveryNoteCreateLineItem.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteCreateLineItem { /** Object of product. Can be used instead of product_id, created in product's catalog */ diff --git a/src/api/types/DeliveryNoteCreateRequest.ts b/src/api/types/DeliveryNoteCreateRequest.ts index 6cd26d4..d3b3bc4 100644 --- a/src/api/types/DeliveryNoteCreateRequest.ts +++ b/src/api/types/DeliveryNoteCreateRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Delivery Note creation request schema @@ -22,6 +22,6 @@ export interface DeliveryNoteCreateRequest { document_id?: string; /** List of line items in the delivery note */ line_items: Monite.DeliveryNoteCreateLineItem[]; - /** Additional information regarding the delivery note */ + /** An optional note for the customer, displayed above the line items table in the PDF. */ memo?: string; } diff --git a/src/api/types/DeliveryNoteLineItemProduct.ts b/src/api/types/DeliveryNoteLineItemProduct.ts index 6b7186b..0b0b036 100644 --- a/src/api/types/DeliveryNoteLineItemProduct.ts +++ b/src/api/types/DeliveryNoteLineItemProduct.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteLineItemProduct { /** Description of the product. */ diff --git a/src/api/types/DeliveryNoteLineItemResource.ts b/src/api/types/DeliveryNoteLineItemResource.ts index 683bb3f..06f00fe 100644 --- a/src/api/types/DeliveryNoteLineItemResource.ts +++ b/src/api/types/DeliveryNoteLineItemResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteLineItemResource { product: Monite.DeliveryNoteLineItemProduct; diff --git a/src/api/types/DeliveryNoteResource.ts b/src/api/types/DeliveryNoteResource.ts index c8aac1e..395b49e 100644 --- a/src/api/types/DeliveryNoteResource.ts +++ b/src/api/types/DeliveryNoteResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteResource { /** Unique ID of the delivery note */ @@ -43,7 +43,7 @@ export interface DeliveryNoteResource { file_url?: string; /** List of line items in the delivery note */ line_items: Monite.DeliveryNoteLineItemResource[]; - /** Additional information regarding the delivery note */ + /** An optional note for the customer, displayed above the line items table in the PDF. */ memo?: string; /** The language of the entity's copy of the PDF file (`original_file_url`). The value matches the entity's `language` at the time when this PDF file was generated. */ original_file_language: Monite.LanguageCodeEnum; diff --git a/src/api/types/DeliveryNoteResourceEntity.ts b/src/api/types/DeliveryNoteResourceEntity.ts index 4a84cef..e0617c8 100644 --- a/src/api/types/DeliveryNoteResourceEntity.ts +++ b/src/api/types/DeliveryNoteResourceEntity.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Entity that created the delivery note diff --git a/src/api/types/DeliveryNoteResourceList.ts b/src/api/types/DeliveryNoteResourceList.ts index c960a07..9c192bf 100644 --- a/src/api/types/DeliveryNoteResourceList.ts +++ b/src/api/types/DeliveryNoteResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DeliveryNoteResourceList { /** List of delivery notes */ diff --git a/src/api/types/Discount.ts b/src/api/types/Discount.ts index a32b7bc..78828c4 100644 --- a/src/api/types/Discount.ts +++ b/src/api/types/Discount.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface Discount { /** The actual discount of the product in [minor units](https://docs.monite.com/references/currencies#minor-units) if type field equals amount, else in percent minor units */ diff --git a/src/api/types/DiscountResponse.ts b/src/api/types/DiscountResponse.ts new file mode 100644 index 0000000..464b5f8 --- /dev/null +++ b/src/api/types/DiscountResponse.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface DiscountResponse { + /** The actual discount of the product in [minor units](https://docs.monite.com/references/currencies#minor-units) if type field equals amount, else in percent minor units */ + amount: number; + /** The field specifies whether to use product currency or %. */ + type: Monite.DiscountType; + /** The monetary amount of the discount, in [minor units](https://docs.monite.com/references/currencies#minor-units). If the discount `type` is `amount`, this value is the same as the `amount` value. If `type` is `percentage`, the value is the calculated discount amount. */ + value?: number; +} diff --git a/src/api/types/DnsRecord.ts b/src/api/types/DnsRecord.ts index 8fc1edf..81cc2c5 100644 --- a/src/api/types/DnsRecord.ts +++ b/src/api/types/DnsRecord.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DnsRecord { is_active: boolean; diff --git a/src/api/types/DnsRecords.ts b/src/api/types/DnsRecords.ts index dc99156..dbbf1c0 100644 --- a/src/api/types/DnsRecords.ts +++ b/src/api/types/DnsRecords.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DnsRecords { /** Set of DNS settings required by Mailgun for domain verification before emails receiving is possible. */ diff --git a/src/api/types/DocumentIDsSettings.ts b/src/api/types/DocumentIDsSettings.ts index c86aa31..1d4c288 100644 --- a/src/api/types/DocumentIDsSettings.ts +++ b/src/api/types/DocumentIDsSettings.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DocumentIDsSettings { /** Prefixes for each document_type. */ diff --git a/src/api/types/DocumentIDsSettingsRequest.ts b/src/api/types/DocumentIDsSettingsRequest.ts index f1daa73..dd9c641 100644 --- a/src/api/types/DocumentIDsSettingsRequest.ts +++ b/src/api/types/DocumentIDsSettingsRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DocumentIDsSettingsRequest { /** Prefixes for each document_type. */ diff --git a/src/api/types/DocumentRenderingSettings.ts b/src/api/types/DocumentRenderingSettings.ts index 9bfac81..f9680f4 100644 --- a/src/api/types/DocumentRenderingSettings.ts +++ b/src/api/types/DocumentRenderingSettings.ts @@ -2,13 +2,22 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; +/** + * Settings for rendering documents in PDF format, including settings for line items and specific document types. + */ export interface DocumentRenderingSettings { - /** Settings for rendering credit notes in PDF documents. */ + /** Credit note-specific rendering settings for PDF documents. */ credit_note?: Monite.CreditNoteRenderingSettings; - /** Settings for rendering invoices in PDF documents. */ + /** If set to `true`, the entity's bank account details will be displayed on the PDF documents. Defaults to `true`. */ + display_entity_bank_account?: boolean; + /** If set to `true`, the line items table will be displayed on the quote PDF. Defaults to `true`. */ + display_line_items?: boolean; + /** Invoice-specific rendering settings for PDF documents. */ invoice?: Monite.InvoiceRenderingSettings; - /** Settings for rendering quotes in PDF documents. */ + /** Settings for rendering line items in PDF documents. */ + line_items?: Monite.LineItemsRenderingSettings; + /** Quote-specific rendering settings for PDF documents. */ quote?: Monite.QuoteRenderingSettings; } diff --git a/src/api/types/DocumentRenderingSettingsInput.ts b/src/api/types/DocumentRenderingSettingsInput.ts new file mode 100644 index 0000000..93165e0 --- /dev/null +++ b/src/api/types/DocumentRenderingSettingsInput.ts @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +/** + * Rendering settings that control how different parts of the PDF documents are displayed. + * Includes common settings for all document types such as quotes, invoices, and credit notes and document + * type-specific settings that are defined in their respective objects. + */ +export interface DocumentRenderingSettingsInput { + /** Credit note-specific rendering settings for PDF documents. */ + credit_note?: Monite.CreditNoteRenderingSettings; + /** If set to `true`, the entity's bank account details will be displayed on the PDF documents. Defaults to `true`. */ + display_entity_bank_account?: boolean; + /** If set to `true`, the line items table will be displayed on the quote PDF. Defaults to `true`. */ + display_line_items?: boolean; + /** Invoice-specific rendering settings for PDF documents. */ + invoice?: Monite.InvoiceRenderingSettings; + /** Settings for rendering line items in PDF documents. */ + line_items?: Monite.LineItemsRenderingSettings; + /** Quote-specific rendering settings for PDF documents. */ + quote?: Monite.QuoteRenderingSettings; +} diff --git a/src/api/types/DocumentRenderingSettingsOutput.ts b/src/api/types/DocumentRenderingSettingsOutput.ts new file mode 100644 index 0000000..a127e76 --- /dev/null +++ b/src/api/types/DocumentRenderingSettingsOutput.ts @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +/** + * Rendering settings that control how different parts of the PDF documents are displayed. + * Includes common settings for all document types such as quotes, invoices, and credit notes and document + * type-specific settings that are defined in their respective objects. + */ +export interface DocumentRenderingSettingsOutput { + /** Credit note-specific rendering settings for PDF documents. */ + credit_note?: Monite.CreditNoteRenderingSettings; + /** If set to `true`, the entity's bank account details will be displayed on the PDF documents. Defaults to `true`. */ + display_entity_bank_account?: boolean; + /** If set to `true`, the line items table will be displayed on the quote PDF. Defaults to `true`. */ + display_line_items?: boolean; + /** Invoice-specific rendering settings for PDF documents. */ + invoice?: Monite.InvoiceRenderingSettings; + /** Settings for rendering line items in PDF documents. */ + line_items?: Monite.LineItemsRenderingSettings; + /** Quote-specific rendering settings for PDF documents. */ + quote?: Monite.QuoteRenderingSettings; +} diff --git a/src/api/types/DomainListResponse.ts b/src/api/types/DomainListResponse.ts index bdad4b8..cfb7464 100644 --- a/src/api/types/DomainListResponse.ts +++ b/src/api/types/DomainListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DomainListResponse { data: Monite.DomainResponse[]; diff --git a/src/api/types/DomainResponse.ts b/src/api/types/DomainResponse.ts index 8b47a9b..12102ea 100644 --- a/src/api/types/DomainResponse.ts +++ b/src/api/types/DomainResponse.ts @@ -2,17 +2,21 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface DomainResponse { /** Entry UUID */ id: string; /** A dedicated IP address assigned to this mailbox and used to send outgoing email. */ dedicated_ip?: string; - dns_records: Monite.DomainResponseDnsRecords; + dns_records: DomainResponse.DnsRecords; /** The domain name. */ domain: string; /** The time the domain was updated for the last time */ last_updated_at?: string; status: string; } + +export namespace DomainResponse { + export type DnsRecords = Monite.DnsRecords | Record; +} diff --git a/src/api/types/DomainResponseDnsRecords.ts b/src/api/types/DomainResponseDnsRecords.ts deleted file mode 100644 index 4bc4f6e..0000000 --- a/src/api/types/DomainResponseDnsRecords.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export type DomainResponseDnsRecords = Monite.DnsRecords | Record; diff --git a/src/api/types/EInvoicingRetrieveListData.ts b/src/api/types/EInvoicingRetrieveListData.ts index 4fbe4a1..06fbd6c 100644 --- a/src/api/types/EInvoicingRetrieveListData.ts +++ b/src/api/types/EInvoicingRetrieveListData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EInvoicingRetrieveListData { /** List of connections for the current page */ diff --git a/src/api/types/EinvoicingAddress.ts b/src/api/types/EinvoicingAddress.ts index 45be8be..6f34e21 100644 --- a/src/api/types/EinvoicingAddress.ts +++ b/src/api/types/EinvoicingAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EinvoicingAddress { /** Street address line 1 */ diff --git a/src/api/types/EinvoicingConnectionResponse.ts b/src/api/types/EinvoicingConnectionResponse.ts index 6ae8764..da6be93 100644 --- a/src/api/types/EinvoicingConnectionResponse.ts +++ b/src/api/types/EinvoicingConnectionResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EinvoicingConnectionResponse { id: string; @@ -16,6 +16,10 @@ export interface EinvoicingConnectionResponse { credentials: Monite.EinvoicingNetworkCredentialsResponse[]; /** ID of the entity */ entity_id: string; + /** Set to `true` if the entity needs to receive e-invoices. */ + is_receiver?: boolean; + /** Set to `true` if the entity needs to send e-invoices. Either `is_sender` or `is_receiver` or both must be `true`. */ + is_sender?: boolean; /** Legal name of the Entity */ legal_name: string; /** ID assigned by integration partner */ diff --git a/src/api/types/EinvoicingNetworkCredentialsResponse.ts b/src/api/types/EinvoicingNetworkCredentialsResponse.ts index 9ec53f0..63e11ac 100644 --- a/src/api/types/EinvoicingNetworkCredentialsResponse.ts +++ b/src/api/types/EinvoicingNetworkCredentialsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EinvoicingNetworkCredentialsResponse { /** ID of the credentials */ diff --git a/src/api/types/EntityAddressResponseSchema.ts b/src/api/types/EntityAddressResponseSchema.ts index fd89523..5e06e61 100644 --- a/src/api/types/EntityAddressResponseSchema.ts +++ b/src/api/types/EntityAddressResponseSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema represents address info of the entity diff --git a/src/api/types/EntityAddressSchema.ts b/src/api/types/EntityAddressSchema.ts index c7ec355..3947651 100644 --- a/src/api/types/EntityAddressSchema.ts +++ b/src/api/types/EntityAddressSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema represents address info of the entity diff --git a/src/api/types/EntityBankAccountPaginationResponse.ts b/src/api/types/EntityBankAccountPaginationResponse.ts index 6f01cd3..da8eac1 100644 --- a/src/api/types/EntityBankAccountPaginationResponse.ts +++ b/src/api/types/EntityBankAccountPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of an entity's bank accounts. diff --git a/src/api/types/EntityBankAccountResponse.ts b/src/api/types/EntityBankAccountResponse.ts index fd7a14d..2932522 100644 --- a/src/api/types/EntityBankAccountResponse.ts +++ b/src/api/types/EntityBankAccountResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a bank account owned by an entity. diff --git a/src/api/types/EntityFields.ts b/src/api/types/EntityFields.ts index 1f9a1c9..174540c 100644 --- a/src/api/types/EntityFields.ts +++ b/src/api/types/EntityFields.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityFields { /** Object describing the required field `tax_id` of an entity */ diff --git a/src/api/types/EntityIndividualResponse.ts b/src/api/types/EntityIndividualResponse.ts index 9af77af..e859f0c 100644 --- a/src/api/types/EntityIndividualResponse.ts +++ b/src/api/types/EntityIndividualResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityIndividualResponse { /** UUID entity ID */ @@ -17,7 +17,7 @@ export interface EntityIndividualResponse { email?: string; /** A set of metadata describing an individual */ individual: Monite.IndividualResponseSchema; - /** A logo image of the entity */ + /** An object containing the entity logo URL and other image details, or `null` if the entity does not have a logo. */ logo?: Monite.FileSchema2; /** A phone number of the entity */ phone?: string; diff --git a/src/api/types/EntityOnboardingDataResponse.ts b/src/api/types/EntityOnboardingDataResponse.ts index a90ac6a..536f98e 100644 --- a/src/api/types/EntityOnboardingDataResponse.ts +++ b/src/api/types/EntityOnboardingDataResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityOnboardingDataResponse { /** Business information about the entity. */ @@ -11,4 +11,6 @@ export interface EntityOnboardingDataResponse { ownership_declaration?: Monite.OwnershipDeclarationOutput; /** Details on the entity's acceptance of the service agreement. */ tos_acceptance?: Monite.TermsOfServiceAcceptanceOutput; + /** Details on the entity's acceptance of the Stripe Treasury service agreement. */ + treasury_tos_acceptance?: Monite.TermsOfServiceAcceptanceOutput; } diff --git a/src/api/types/EntityOrganizationResponse.ts b/src/api/types/EntityOrganizationResponse.ts index f6a8e74..f91cbbe 100644 --- a/src/api/types/EntityOrganizationResponse.ts +++ b/src/api/types/EntityOrganizationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityOrganizationResponse { /** UUID entity ID */ @@ -15,7 +15,7 @@ export interface EntityOrganizationResponse { address: Monite.EntityAddressResponseSchema; /** An official email address of the entity */ email?: string; - /** A logo image of the entity */ + /** An object containing the entity logo URL and other image details, or `null` if the entity does not have a logo. */ logo?: Monite.FileSchema2; /** A set of metadata describing an organization */ organization: Monite.OrganizationResponseSchema; diff --git a/src/api/types/EntityPaginationResponse.ts b/src/api/types/EntityPaginationResponse.ts index f0e4a86..da71339 100644 --- a/src/api/types/EntityPaginationResponse.ts +++ b/src/api/types/EntityPaginationResponse.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityPaginationResponse { /** A set of entities of different types returned per page */ data: Monite.EntityResponse[]; - /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ - prev_pagination_token?: string; /** A token that can be sent in the `pagination_token` query parameter to get the next page of results, or `null` if there is no next page (i.e. you've reached the last page). */ next_pagination_token?: string; + /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ + prev_pagination_token?: string; } diff --git a/src/api/types/EntityResponse.ts b/src/api/types/EntityResponse.ts index cb525c8..0c38fee 100644 --- a/src/api/types/EntityResponse.ts +++ b/src/api/types/EntityResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema for a response after creation of an entity of different types diff --git a/src/api/types/EntityUserPaginationResponse.ts b/src/api/types/EntityUserPaginationResponse.ts index 4823d78..c02711e 100644 --- a/src/api/types/EntityUserPaginationResponse.ts +++ b/src/api/types/EntityUserPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityUserPaginationResponse { /** array of records */ diff --git a/src/api/types/EntityUserResponse.ts b/src/api/types/EntityUserResponse.ts index 4252613..44e7e23 100644 --- a/src/api/types/EntityUserResponse.ts +++ b/src/api/types/EntityUserResponse.ts @@ -2,28 +2,33 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityUserResponse { - /** UUID entity user ID */ + /** A unique Monite-assigned ID of this entity user. Can be used with `POST /auth/token` to generate an API access token for this user. */ id: string; - /** UTC datetime */ + /** UTC date and time when this user was created in Monite. */ created_at: string; - /** UTC datetime */ + /** UTC date and time when this user was last updated. */ updated_at: string; - /** An entity user business email */ + /** The user's business email address. */ email?: string; - /** First name */ + /** The user's first name. */ first_name?: string; - /** Last name */ + /** The user's last name. */ last_name?: string; - /** Login */ + /** + * The username assigned to this user. Usernames must be unique within the entity. + * + * The `login` value is not used by Monite but may be used by partner applications, for example, to map the users between the partner's platform and Monite. + */ login: string; - /** An entity user phone number in the international format */ + /** The user's phone number. */ phone?: string; - /** UUID role ID */ + /** ID of the role assigned to this user. The role defines the user's [access permissions](https://docs.monite.com/api/concepts/authentication#permissions) within the entity. Each user has just one role. */ role_id: string; - /** record status, 'active' by default */ + /** The user's status. Always `active`. */ status: Monite.StatusEnum; + /** Unused. Reserved for future use. Currently always returns `null`. */ userpic_file_id?: string; } diff --git a/src/api/types/EntityVatIdResourceList.ts b/src/api/types/EntityVatIdResourceList.ts index 119a299..0a9dc5a 100644 --- a/src/api/types/EntityVatIdResourceList.ts +++ b/src/api/types/EntityVatIdResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityVatIdResourceList { data: Monite.EntityVatIdResponse[]; diff --git a/src/api/types/EntityVatIdResponse.ts b/src/api/types/EntityVatIdResponse.ts index 30edb45..1669644 100644 --- a/src/api/types/EntityVatIdResponse.ts +++ b/src/api/types/EntityVatIdResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EntityVatIdResponse { id: string; diff --git a/src/api/types/ErrorSchemaResponse.ts b/src/api/types/ErrorSchemaResponse.ts index c7e8035..b77fd1b 100644 --- a/src/api/types/ErrorSchemaResponse.ts +++ b/src/api/types/ErrorSchemaResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ErrorSchemaResponse { error: Monite.ErrorSchema; diff --git a/src/api/types/ErrorSchemaResponse2.ts b/src/api/types/ErrorSchemaResponse2.ts index 57577bf..eb08c1d 100644 --- a/src/api/types/ErrorSchemaResponse2.ts +++ b/src/api/types/ErrorSchemaResponse2.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ErrorSchemaResponse2 { error: Monite.ErrorSchema2; diff --git a/src/api/types/EstimatedMonthlyRevenue.ts b/src/api/types/EstimatedMonthlyRevenue.ts index 8c3ef05..fb357d7 100644 --- a/src/api/types/EstimatedMonthlyRevenue.ts +++ b/src/api/types/EstimatedMonthlyRevenue.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EstimatedMonthlyRevenue { /** The amount of the monthly revenue, in [minor units](https://docs.monite.com/references/currencies#minor-units). For example, $12.50 is represented as 1250. */ diff --git a/src/api/types/EventPaginationResource.ts b/src/api/types/EventPaginationResource.ts index 5e29d07..919e524 100644 --- a/src/api/types/EventPaginationResource.ts +++ b/src/api/types/EventPaginationResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EventPaginationResource { /** A set of events returned per page */ diff --git a/src/api/types/EventResource.ts b/src/api/types/EventResource.ts index 2a3073f..60408e7 100644 --- a/src/api/types/EventResource.ts +++ b/src/api/types/EventResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EventResource { id: string; diff --git a/src/api/types/EventResourceForWebhookClient.ts b/src/api/types/EventResourceForWebhookClient.ts index b9c1630..7349610 100644 --- a/src/api/types/EventResourceForWebhookClient.ts +++ b/src/api/types/EventResourceForWebhookClient.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface EventResourceForWebhookClient { id: string; diff --git a/src/api/types/ExchangeRate.ts b/src/api/types/ExchangeRate.ts index 7865ff3..b0e142e 100644 --- a/src/api/types/ExchangeRate.ts +++ b/src/api/types/ExchangeRate.ts @@ -2,10 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ExchangeRate { base: Monite.CurrencyEnum; - to: Monite.CurrencyEnum; rate: number; + to: Monite.CurrencyEnum; } diff --git a/src/api/types/ExportObjectSchema.ts b/src/api/types/ExportObjectSchema.ts index c13c428..11f93c5 100644 --- a/src/api/types/ExportObjectSchema.ts +++ b/src/api/types/ExportObjectSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type ExportObjectSchema = Monite.ExportObjectSchema.Payable | Monite.ExportObjectSchema.Receivable; diff --git a/src/api/types/ExportPayableSchema.ts b/src/api/types/ExportPayableSchema.ts index b3e3363..f35865d 100644 --- a/src/api/types/ExportPayableSchema.ts +++ b/src/api/types/ExportPayableSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ExportPayableSchema { statuses: Monite.PayableStateEnum[]; diff --git a/src/api/types/ExportReceivableSchema.ts b/src/api/types/ExportReceivableSchema.ts index 0c67067..715b2c3 100644 --- a/src/api/types/ExportReceivableSchema.ts +++ b/src/api/types/ExportReceivableSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ExportReceivableSchema { statuses: Monite.ReceivablesStatusEnum[]; diff --git a/src/api/types/ExtraDataResource.ts b/src/api/types/ExtraDataResource.ts index 7ba0f67..19dc32a 100644 --- a/src/api/types/ExtraDataResource.ts +++ b/src/api/types/ExtraDataResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ExtraDataResource { id: string; diff --git a/src/api/types/ExtraDataResourceList.ts b/src/api/types/ExtraDataResourceList.ts index 5316300..b195dd0 100644 --- a/src/api/types/ExtraDataResourceList.ts +++ b/src/api/types/ExtraDataResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ExtraDataResourceList { data: Monite.ExtraDataResource[]; diff --git a/src/api/types/FileAttachedEventData.ts b/src/api/types/FileAttachedEventData.ts new file mode 100644 index 0000000..d99ee4b --- /dev/null +++ b/src/api/types/FileAttachedEventData.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface FileAttachedEventData { + file_name: string; + file_size: number; + url: string; +} diff --git a/src/api/types/FileResponse.ts b/src/api/types/FileResponse.ts index e9df806..2079a36 100644 --- a/src/api/types/FileResponse.ts +++ b/src/api/types/FileResponse.ts @@ -3,16 +3,39 @@ */ export interface FileResponse { + /** A unique ID assigned to this file. */ id: string; + /** Date and time when this file was uploaded to or created in Monite. Timestamps follow the ISO 8601 format. */ created_at: string; + /** Date and time when this file was last updated in Monite. Timestamps follow the ISO 8601 format. */ updated_at: string; + /** + * Possible values: + * + * * `additional_identity_documents` and `identity_documents` - [entity verification documents](https://docs.monite.com/payments/onboarding/via-api/documents) uploaded for payments onboarding. + * * `attachments` - supplementary attachments for accounts receivable invoices, quotes, and credit notes. + * * `delivery_notes` - auto-generated PDF versions of delivery notes. + * * `einvoices_xml` - e-invoice XML generated when sending e-invoices. + * * `payables` - payables (bills) received via email or uploaded via API. + * * `receivable_signatures` - images of customer signatures provided during quote acceptance. + * * `receivables` - auto-generated PDF versions of invoices, quotes, and credit notes. + * * `zip` - data export archives created by `POST /data_exports`. + */ file_type: string; + /** The MD5 hash of the file. */ md5: string; + /** The file's media type, for example, `application/pdf` or `image/png`. */ mimetype: string; + /** The original file name (if available). */ name: string; + /** Geographical region of the data center where the file is stored. */ region: string; + /** Unused. */ s3_bucket: string; + /** Unused. */ s3_file_path: string; + /** The file size in bytes. */ size: number; + /** The URL to download the file. */ url: string; } diff --git a/src/api/types/FileSchema.ts b/src/api/types/FileSchema.ts index d0eeb25..54e9d7c 100644 --- a/src/api/types/FileSchema.ts +++ b/src/api/types/FileSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a file (such as a PDF invoice) that was uploaded to Monite. @@ -14,20 +14,20 @@ export interface FileSchema { created_at: string; /** The type of the business object associated with this file. */ file_type: string; - /** The original file name (if available). */ - name: string; - /** Geographical region of the data center where the file is stored. */ - region: string; /** The MD5 hash of the file. */ md5: string; /** The file's [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types). */ mimetype: string; - /** The URL to download the file. */ - url: string; - /** The file size in bytes. */ - size: number; - /** Preview images generated for this file. There can be multiple images with different sizes. */ - previews?: Monite.PreviewSchema2[]; + /** The original file name (if available). */ + name: string; /** If the file is a PDF document, this property contains individual pages extracted from the file. Otherwise, an empty array. */ pages?: Monite.PageSchema2[]; + /** Preview images generated for this file. There can be multiple images with different sizes. */ + previews?: Monite.PreviewSchema2[]; + /** Geographical region of the data center where the file is stored. */ + region: string; + /** The file size in bytes. */ + size: number; + /** The URL to download the file. */ + url: string; } diff --git a/src/api/types/FileSchema2.ts b/src/api/types/FileSchema2.ts index 5fc8653..da4b0e5 100644 --- a/src/api/types/FileSchema2.ts +++ b/src/api/types/FileSchema2.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a file (such as a PDF invoice) that was uploaded to Monite. diff --git a/src/api/types/FileSchema3.ts b/src/api/types/FileSchema3.ts index 8d9ab8b..8eedb71 100644 --- a/src/api/types/FileSchema3.ts +++ b/src/api/types/FileSchema3.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a file (such as a PDF invoice) that was uploaded to Monite. diff --git a/src/api/types/FilesResponse.ts b/src/api/types/FilesResponse.ts index af04336..3d23f9b 100644 --- a/src/api/types/FilesResponse.ts +++ b/src/api/types/FilesResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FilesResponse { data: Monite.FileResponse[]; diff --git a/src/api/types/FinancingInvoice.ts b/src/api/types/FinancingInvoice.ts index b2a5c5c..835d007 100644 --- a/src/api/types/FinancingInvoice.ts +++ b/src/api/types/FinancingInvoice.ts @@ -2,49 +2,49 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FinancingInvoice { - /** The type of the invoice i.e. receivable or payable. */ - type: Monite.FinancingInvoiceType; - /** Status of the invoice. */ - status: Monite.WcInvoiceStatus; - /** Monite invoice ID. */ - invoice_id: string; + /** Amount after fees the business will receive in minor units. */ + advance_amount?: number; + /** Advance rate percentage. 10000 means 100% */ + advance_rate_percentage?: number; + /** Currency code. */ + currency: Monite.CurrencyEnum; + /** Description of the invoice. */ + description?: string; /** Monite document ID. */ document_id: string; /** Monite invoice due date. */ due_date: string; + /** Fee amount in minor units. */ + fee_amount?: number; + /** Fee percentage. 300 means 3% */ + fee_percentage?: number; + /** Monite invoice ID. */ + invoice_id: string; /** Monite invoice issue date. */ issue_date: string; - /** Total amount of the invoice in minor units. */ - total_amount: number; - /** Currency code. */ - currency: Monite.CurrencyEnum; - /** Description of the invoice. */ - description?: string; - /** Payer type. BUSINESS or INDIVIDUAL */ - payer_type: string; /** Payer business name. Only applicable for BUSINESS payer type. */ payer_business_name?: string; /** Payer first name. Only applicable for INDIVIDUAL payer type. */ payer_first_name?: string; /** Payer last name. Only applicable for INDIVIDUAL payer type. */ payer_last_name?: string; - /** Amount the business requests to be financed in minor units. */ - requested_amount?: number; + /** Payer type. BUSINESS or INDIVIDUAL */ + payer_type: string; /** Principal amount of the loan in minor units. */ principal_amount?: number; /** Amount the business will repay in minor units. */ repayment_amount?: number; - /** Amount after fees the business will receive in minor units. */ - advance_amount?: number; - /** Advance rate percentage. 10000 means 100% */ - advance_rate_percentage?: number; - /** Fee amount in minor units. */ - fee_amount?: number; - /** Fee percentage. 300 means 3% */ - fee_percentage?: number; /** Repayment schedule of the invoice. */ repayment_schedule?: Monite.RepaymentSchedule; + /** Amount the business requests to be financed in minor units. */ + requested_amount?: number; + /** Status of the invoice. */ + status: Monite.WcInvoiceStatus; + /** Total amount of the invoice in minor units. */ + total_amount: number; + /** The type of the invoice i.e. receivable or payable. */ + type: Monite.FinancingInvoiceType; } diff --git a/src/api/types/FinancingInvoiceListResponse.ts b/src/api/types/FinancingInvoiceListResponse.ts index a4c7344..3efba69 100644 --- a/src/api/types/FinancingInvoiceListResponse.ts +++ b/src/api/types/FinancingInvoiceListResponse.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FinancingInvoiceListResponse { /** A list of invoices requested for financing. */ data: Monite.FinancingInvoice[]; - /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ - prev_pagination_token?: string; /** A token that can be sent in the `pagination_token` query parameter to get the next page of results, or `null` if there is no next page (i.e. you've reached the last page). */ next_pagination_token?: string; + /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ + prev_pagination_token?: string; } diff --git a/src/api/types/FinancingOffer.ts b/src/api/types/FinancingOffer.ts index e2b03ed..a3ad4b1 100644 --- a/src/api/types/FinancingOffer.ts +++ b/src/api/types/FinancingOffer.ts @@ -2,17 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FinancingOffer { - /** The status of the financing offer. */ - status: Monite.WcOfferStatus; - /** The total credit limit in minor units. */ - total_amount: number; /** The available credit limit in minor units. */ available_amount?: number; /** The currency code. */ currency: Monite.CurrencyEnum; /** A list of pricing plans for the offer. */ pricing_plans: Monite.PricingPlan[]; + /** The status of the financing offer. */ + status: Monite.WcOfferStatus; + /** The total credit limit in minor units. */ + total_amount: number; } diff --git a/src/api/types/FinancingOffersResponse.ts b/src/api/types/FinancingOffersResponse.ts index d45662a..d2e5c3d 100644 --- a/src/api/types/FinancingOffersResponse.ts +++ b/src/api/types/FinancingOffersResponse.ts @@ -2,11 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FinancingOffersResponse { - /** A list of financing offers extended to the business. */ - offers: Monite.FinancingOffer[]; /** The business's onboarding status. */ business_status: Monite.WcBusinessStatus; + /** A list of financing offers extended to the business. */ + offers: Monite.FinancingOffer[]; } diff --git a/src/api/types/FinancingPushInvoicesRequestInvoice.ts b/src/api/types/FinancingPushInvoicesRequestInvoice.ts index aac108b..8202ad8 100644 --- a/src/api/types/FinancingPushInvoicesRequestInvoice.ts +++ b/src/api/types/FinancingPushInvoicesRequestInvoice.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface FinancingPushInvoicesRequestInvoice { /** The invoice ID. */ diff --git a/src/api/types/GetAllPaymentReminders.ts b/src/api/types/GetAllPaymentReminders.ts index 35bd0d1..ec73eba 100644 --- a/src/api/types/GetAllPaymentReminders.ts +++ b/src/api/types/GetAllPaymentReminders.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface GetAllPaymentReminders { data: Monite.PaymentReminderResponse[]; diff --git a/src/api/types/GetAllRecurrences.ts b/src/api/types/GetAllRecurrences.ts deleted file mode 100644 index 6f8dae7..0000000 --- a/src/api/types/GetAllRecurrences.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface GetAllRecurrences { - data: Monite.Recurrence[]; -} diff --git a/src/api/types/GetOnboardingRequirementsResponse.ts b/src/api/types/GetOnboardingRequirementsResponse.ts index f470060..24b2aa9 100644 --- a/src/api/types/GetOnboardingRequirementsResponse.ts +++ b/src/api/types/GetOnboardingRequirementsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface GetOnboardingRequirementsResponse { data: Monite.SingleOnboardingRequirementsResponse[]; diff --git a/src/api/types/HttpValidationError.ts b/src/api/types/HttpValidationError.ts index 1d0e607..2f18edc 100644 --- a/src/api/types/HttpValidationError.ts +++ b/src/api/types/HttpValidationError.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface HttpValidationError { detail?: Monite.ValidationError[]; diff --git a/src/api/types/InlinePaymentTermsRequestPayload.ts b/src/api/types/InlinePaymentTermsRequestPayload.ts new file mode 100644 index 0000000..30df173 --- /dev/null +++ b/src/api/types/InlinePaymentTermsRequestPayload.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface InlinePaymentTermsRequestPayload { + /** The first tier of the payment term. Represents the terms of the first early discount. */ + term_1?: Monite.InlineTermDiscount; + /** The second tier of the payment term. Defines the terms of the second early discount. */ + term_2?: Monite.InlineTermDiscount; + /** The final tier of the payment term. Defines the invoice due date. */ + term_final: Monite.InlineTermFinal; +} diff --git a/src/api/types/PaymentTermDiscountWithDate.ts b/src/api/types/InlineTermDiscount.ts similarity index 78% rename from src/api/types/PaymentTermDiscountWithDate.ts rename to src/api/types/InlineTermDiscount.ts index 993aa7a..9897fa4 100644 --- a/src/api/types/PaymentTermDiscountWithDate.ts +++ b/src/api/types/InlineTermDiscount.ts @@ -2,10 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface PaymentTermDiscountWithDate { +export interface InlineTermDiscount { /** The discount percentage in minor units. E.g., 200 means 2%. 1050 means 10.5%. */ discount: number; end_date?: string; /** The amount of days after the invoice issue date. */ - number_of_days: number; + number_of_days?: number; } diff --git a/src/api/types/TermFinalWithDate.ts b/src/api/types/InlineTermFinal.ts similarity index 70% rename from src/api/types/TermFinalWithDate.ts rename to src/api/types/InlineTermFinal.ts index 1cf6acc..0258e27 100644 --- a/src/api/types/TermFinalWithDate.ts +++ b/src/api/types/InlineTermFinal.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface TermFinalWithDate { +export interface InlineTermFinal { end_date?: string; /** The amount of days after the invoice issue date. */ - number_of_days: number; + number_of_days?: number; } diff --git a/src/api/types/Invoice.ts b/src/api/types/Invoice.ts index 1b5130e..22e0a54 100644 --- a/src/api/types/Invoice.ts +++ b/src/api/types/Invoice.ts @@ -2,10 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface Invoice { + /** The invoice due date (`yyyy-mm-dd`) to be displayed on the payment page. */ due_date?: string; + /** The invoice file (for example, PDF or PNG). If specified, the payment page will include a link to download this file. */ file?: Monite.InvoiceFile; + /** The invoice issue date (`yyyy-mm-dd`) to be displayed on the payment page. */ issue_date?: string; } diff --git a/src/api/types/InvoiceResponsePayload.ts b/src/api/types/InvoiceResponsePayload.ts index f352d1b..ebbebb7 100644 --- a/src/api/types/InvoiceResponsePayload.ts +++ b/src/api/types/InvoiceResponsePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface InvoiceResponsePayload { id: string; @@ -16,6 +16,8 @@ export interface InvoiceResponsePayload { amount_paid: number; /** How much is left to be paid in in [minor units](https://docs.monite.com/references/currencies#minor-units), including payment_term discounts. */ amount_to_pay?: number; + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentResponse[]; /** The unique ID of a previous document related to the receivable if applicable. */ based_on?: string; /** The unique document ID of a previous document related to the receivable if applicable. */ @@ -43,7 +45,7 @@ export interface InvoiceResponsePayload { /** The VAT/TAX ID of the counterpart. */ counterpart_tax_id?: string; /** The type of the counterpart. */ - counterpart_type: Monite.ReceivableCounterpartType; + counterpart_type: Monite.CounterpartType; counterpart_vat_id?: Monite.ReceivableCounterpartVatIdResponse; /** The currency used in the receivable. */ currency: Monite.CurrencyEnum; @@ -52,11 +54,13 @@ export interface InvoiceResponsePayload { /** A note with additional information about a tax deduction */ deduction_memo?: string; /** The discount for a receivable. */ - discount?: Monite.Discount; + discount?: Monite.DiscountResponse; /** Total price of the receivable with discounts before taxes [minor units](https://docs.monite.com/references/currencies#minor-units). */ discounted_subtotal?: number; /** The sequential code systematically assigned to invoices. */ document_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; /** Optional field representing date until which invoice should be paid */ due_date?: string; /** Error that was returned by E-invoicing */ @@ -73,7 +77,7 @@ export interface InvoiceResponsePayload { file_language: Monite.LanguageCodeEnum; /** The receivable's PDF URL in the counterpart's default language. */ file_url?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** Optional text displayed below the line items table in the PDF. See also: `memo`, `commercial_condition_description`. */ footer?: string; /** * The date when the goods are shipped or the service is provided. Can be a current, past, or future date. @@ -88,7 +92,7 @@ export interface InvoiceResponsePayload { /** Optional field for the issue of the entry. */ issue_date?: string; line_items: Monite.ResponseItem[]; - /** A note with additional information for a receivable. */ + /** An optional note for the customer, displayed above the line items table in the PDF. See also: `footer`, `commercial_condition_description`. */ memo?: string; /** E-invoicing credentials of the entity */ network_credentials?: Monite.EinvoicingCredentials; @@ -105,13 +109,13 @@ export interface InvoiceResponsePayload { payment_page_url?: string; payment_reminder_id?: string; payment_terms?: Monite.PaymentTerms; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this invoice. If specified, the project name will be included in the header of the PDF invoice. */ project_id?: string; /** Contain purchase order number. */ purchase_order?: string; /** Stores an unique ID of a recurrence if the receivable is in a recurring status */ recurrence_id?: string; - /** Ids of documents that relate to invoice. I.e credit notes, proforma invoices, etc. */ + /** IDs of other documents related to this invoice. See also: `based_on`, `based_on_document_id`, `purchase_order`. */ related_documents: Monite.RelatedDocuments; /** The status of the receivable inside the receivable workflow. */ status: Monite.ReceivablesStatusEnum; diff --git a/src/api/types/InvoiceResponsePayloadEntity.ts b/src/api/types/InvoiceResponsePayloadEntity.ts index 9864ac0..a9c7c42 100644 --- a/src/api/types/InvoiceResponsePayloadEntity.ts +++ b/src/api/types/InvoiceResponsePayloadEntity.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type InvoiceResponsePayloadEntity = | Monite.InvoiceResponsePayloadEntity.Organization diff --git a/src/api/types/Item.ts b/src/api/types/Item.ts index 62ca8cc..72c5168 100644 --- a/src/api/types/Item.ts +++ b/src/api/types/Item.ts @@ -6,9 +6,9 @@ * Contains information about a text block or line extracted from an uploaded document by OCR. */ export interface Item { - /** The text as recognized by OCR. */ - text: string; /** OCR confidence score - the estimated accuracy percentage of character recognition of the extracted text, from 0 to 100%. */ confidence: number; processed_text?: unknown; + /** The text as recognized by OCR. */ + text: string; } diff --git a/src/api/types/IterationStatus.ts b/src/api/types/IterationStatus.ts index 97cace3..3ab5a97 100644 --- a/src/api/types/IterationStatus.ts +++ b/src/api/types/IterationStatus.ts @@ -2,11 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -export type IterationStatus = "pending" | "completed" | "canceled" | "issue_failed" | "send_failed"; +export type IterationStatus = "pending" | "completed" | "canceled" | "skipped" | "issue_failed" | "send_failed"; export const IterationStatus = { Pending: "pending", Completed: "completed", Canceled: "canceled", + Skipped: "skipped", IssueFailed: "issue_failed", SendFailed: "send_failed", } as const; diff --git a/src/api/types/LabelNValue.ts b/src/api/types/LabelNValue.ts index ef7f7e8..f12f831 100644 --- a/src/api/types/LabelNValue.ts +++ b/src/api/types/LabelNValue.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A label-value pair extracted from an uploaded document by OCR. diff --git a/src/api/types/LedgerAccountListResponse.ts b/src/api/types/LedgerAccountListResponse.ts index ce31d69..38cf2b8 100644 --- a/src/api/types/LedgerAccountListResponse.ts +++ b/src/api/types/LedgerAccountListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of ledger accounts. diff --git a/src/api/types/LedgerAccountResponse.ts b/src/api/types/LedgerAccountResponse.ts index dad0ec2..6fcab68 100644 --- a/src/api/types/LedgerAccountResponse.ts +++ b/src/api/types/LedgerAccountResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a general ledger account retrieved from an accounting system. diff --git a/src/api/types/LineItem.ts b/src/api/types/LineItem.ts index b31ff4d..a2ce9b2 100644 --- a/src/api/types/LineItem.ts +++ b/src/api/types/LineItem.ts @@ -2,11 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItem { /** ID of the tax rate in the connected accounting system, to be used when pushing the invoice to that accounting system. Use `GET /accounting_tax_rates` to get these IDs. If omitted, Monite will attempt to match the tax rates based on their numeric value. */ accounting_tax_rate_id?: string; + /** Unique identifier of the user-defined vat rate object. */ + custom_vat_rate_id?: string; /** The discount for a product. */ discount?: Monite.Discount; /** Object of product. Can be used instead of product_id, created in product's catalog */ @@ -15,6 +17,8 @@ export interface LineItem { product_id?: string; /** The quantity of each of the goods, materials, or services listed in the receivable. */ quantity: number; + /** Specifies the display name of the tax rate. This field is applicable only when tax_rate_value is also provided. */ + tax_rate_name?: string; /** Percent minor units. Example: 12.5% is 1250. This field is only required on invoices issued by entities in the US, Pakistan, and other unsupported countries. */ tax_rate_value?: number; /** Unique identifier of the vat rate object. This field is required for all entities in supported countries except the US and Pakistan. */ diff --git a/src/api/types/LineItemColumnSettings.ts b/src/api/types/LineItemColumnSettings.ts new file mode 100644 index 0000000..6224d16 --- /dev/null +++ b/src/api/types/LineItemColumnSettings.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface LineItemColumnSettings { + display?: boolean; + /** Line item table column header to override Monite's default. If not set, the Monite's default will be used. */ + label?: string; +} diff --git a/src/api/types/LineItemFields.ts b/src/api/types/LineItemFields.ts index 54e5e5c..528f5ad 100644 --- a/src/api/types/LineItemFields.ts +++ b/src/api/types/LineItemFields.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemFields { /** Object describing the required field `measure_unit` of a line item's product */ diff --git a/src/api/types/LineItemNumericColumnSettings.ts b/src/api/types/LineItemNumericColumnSettings.ts new file mode 100644 index 0000000..8787127 --- /dev/null +++ b/src/api/types/LineItemNumericColumnSettings.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * Extended settings for numeric columns in line items. + */ +export interface LineItemNumericColumnSettings { + display?: boolean; + /** Line item table column header to override Monite's default. If not set, the Monite's default will be used. */ + label?: string; + /** Number of decimal places to display for numeric values in this column. */ + precision?: number; +} diff --git a/src/api/types/LineItemPaginationResponse.ts b/src/api/types/LineItemPaginationResponse.ts index 62941c4..efd2550 100644 --- a/src/api/types/LineItemPaginationResponse.ts +++ b/src/api/types/LineItemPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemPaginationResponse { data: Monite.LineItemResponse[]; diff --git a/src/api/types/LineItemProduct.ts b/src/api/types/LineItemProduct.ts index 2c81704..42ed0d2 100644 --- a/src/api/types/LineItemProduct.ts +++ b/src/api/types/LineItemProduct.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemProduct { /** Unique ID of the product. */ @@ -11,6 +11,8 @@ export interface LineItemProduct { accounting_tax_rate_id?: string; /** Description of the product. */ description?: string; + /** A user-defined identifier of the product. For example, an internal product code or SKU (stock keeping unit). Client applications can use this field to map the products in Monite to an external product catalog. */ + external_reference?: string; /** Indicates whether the product is inline */ is_inline?: boolean; ledger_account_id?: string; diff --git a/src/api/types/LineItemProductCreate.ts b/src/api/types/LineItemProductCreate.ts index 80ee218..0d3081f 100644 --- a/src/api/types/LineItemProductCreate.ts +++ b/src/api/types/LineItemProductCreate.ts @@ -2,11 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemProductCreate { /** Description of the product. */ description?: string; + /** A user-defined identifier of the product. For example, an internal product code or SKU (stock keeping unit). Client applications can use this field to map the products in Monite to an external product catalog. */ + external_reference?: string; ledger_account_id?: string; measure_unit?: Monite.UnitRequest; /** Name of the product. */ diff --git a/src/api/types/LineItemProductVatRate.ts b/src/api/types/LineItemProductVatRate.ts index e7aab1a..a486737 100644 --- a/src/api/types/LineItemProductVatRate.ts +++ b/src/api/types/LineItemProductVatRate.ts @@ -2,13 +2,19 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemProductVatRate { /** Unique identifier of the vat rate object. */ id?: string; + /** Sub-taxes included in the VAT. */ + components?: Monite.VatRateComponent[]; /** Two-letter ISO country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). */ country: Monite.AllowedCountries; + /** Indicates whether this vat rate is defined by user. */ + is_custom?: boolean; + /** Display name of the vat rate. */ + name?: string; /** Percent minor units. Example: 12.5% is 1250. */ value: number; } diff --git a/src/api/types/LineItemUpdate.ts b/src/api/types/LineItemUpdate.ts index e09b90b..e621544 100644 --- a/src/api/types/LineItemUpdate.ts +++ b/src/api/types/LineItemUpdate.ts @@ -2,15 +2,19 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemUpdate { + /** Unique identifier of the user-defined vat rate object. */ + custom_vat_rate_id?: string; /** The discount for a product. */ discount?: Monite.Discount; /** The actual price of the product in [minor units](https://docs.monite.com/references/currencies#minor-units). */ price?: number; /** The quantity of each of the goods, materials, or services listed in the receivable. */ quantity?: number; + /** Specifies the display name of the tax rate. This field is applicable only when tax_rate_value is also provided. */ + tax_rate_name?: string; /** Percent minor units. Example: 12.5% is 1250. This field is only required on invoices issued by entities in the US, Pakistan, and other unsupported countries. */ tax_rate_value?: number; /** Unique identifier of the vat rate object. This field is required for all entities in supported countries except the US and Pakistan. */ diff --git a/src/api/types/LineItemsRenderingSettings.ts b/src/api/types/LineItemsRenderingSettings.ts new file mode 100644 index 0000000..424fdc8 --- /dev/null +++ b/src/api/types/LineItemsRenderingSettings.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface LineItemsRenderingSettings { + /** Settings for the discount column in the line items table. */ + discount?: Monite.LineItemColumnSettings; + /** Settings for the measure unit column in the line items table. */ + measure_unit?: Monite.LineItemColumnSettings; + /** Settings for the name column in the line items table. */ + name?: Monite.LineItemColumnSettings; + /** Settings for the price column in the line items table. */ + price?: Monite.LineItemNumericColumnSettings; + /** Settings for the price after VAT column in the line items table. */ + price_after_vat?: Monite.LineItemNumericColumnSettings; + /** Settings for the quantity column in the line items table. */ + quantity?: Monite.LineItemColumnSettings; + /** Settings for the total price column in the line items table. */ + total_price?: Monite.LineItemNumericColumnSettings; + /** Settings for the total price after VAT column in the line items table. */ + total_price_after_vat?: Monite.LineItemNumericColumnSettings; + /** Settings for the VAT amount column in the line items table. */ + vat_amount?: Monite.LineItemNumericColumnSettings; + /** Settings for the VAT rate column in the line items table. */ + vat_rate?: Monite.LineItemNumericColumnSettings; +} diff --git a/src/api/types/LineItemsReplaceResponse.ts b/src/api/types/LineItemsReplaceResponse.ts index 02abd24..db3afd3 100644 --- a/src/api/types/LineItemsReplaceResponse.ts +++ b/src/api/types/LineItemsReplaceResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemsReplaceResponse { data: Monite.LineItemResponse[]; diff --git a/src/api/types/LineItemsResponse.ts b/src/api/types/LineItemsResponse.ts index 0dd2915..3f7b9e0 100644 --- a/src/api/types/LineItemsResponse.ts +++ b/src/api/types/LineItemsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface LineItemsResponse { data: Monite.ResponseItem[]; diff --git a/src/api/types/MailSentEventData.ts b/src/api/types/MailSentEventData.ts index 5216bdf..055b9e2 100644 --- a/src/api/types/MailSentEventData.ts +++ b/src/api/types/MailSentEventData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains information about a sent email. diff --git a/src/api/types/MailSettings.ts b/src/api/types/MailSettings.ts index 197ad9f..16f2ba2 100644 --- a/src/api/types/MailSettings.ts +++ b/src/api/types/MailSettings.ts @@ -3,7 +3,26 @@ */ export interface MailSettings { + /** + * This setting affects accounts receivable emails. + * + * If it is `true`, emails sent by [`POST /receivables/{receivable_id}/send`](https://docs.monite.com/api/receivables/post-receivables-id-send) will include the PDF version of the specified invoice, quote, or credit note as an attachment. When emailing [e-invoices](https://docs.monite.com/e-invoicing/send), e-invoice XML will also be attached to the email. + * + * If it is `false`, PDFs and e-invoice XML is not attached to outgoing emails. + */ attach_documents_as_pdf: boolean; + /** + * The local part of the sender email address (the part before the @domain). If `null`, defaults to `noreply`. + * + * For example, to send emails from `Acme Inc. ` use "invoicing" as the `from_email_username` value. + * + * To customize the domain name for outgoing emails, [set up a mailbox](https://docs.monite.com/advanced/mailboxes#manage-mailboxes) for the entity. + */ from_email_username?: string; + /** + * The sender name in outgoing emails. For example, to send emails from `Acme Inc. ` use "Acme Inc." as the `from_name` value. + * + * If `null`, the sender address will be just an email address without a name. + */ from_name?: string; } diff --git a/src/api/types/MailboxDataResponse.ts b/src/api/types/MailboxDataResponse.ts index 8036e87..047aca9 100644 --- a/src/api/types/MailboxDataResponse.ts +++ b/src/api/types/MailboxDataResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface MailboxDataResponse { data?: Monite.MailboxResponse[]; diff --git a/src/api/types/MailboxObjectTypeEnum.ts b/src/api/types/MailboxObjectTypeEnum.ts index a2e34d8..a005c43 100644 --- a/src/api/types/MailboxObjectTypeEnum.ts +++ b/src/api/types/MailboxObjectTypeEnum.ts @@ -2,4 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -export type MailboxObjectTypeEnum = "payable"; +export type MailboxObjectTypeEnum = "payable" | "receipt"; +export const MailboxObjectTypeEnum = { + Payable: "payable", + Receipt: "receipt", +} as const; diff --git a/src/api/types/MissingFields.ts b/src/api/types/MissingFields.ts index 6b8f151..9569361 100644 --- a/src/api/types/MissingFields.ts +++ b/src/api/types/MissingFields.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface MissingFields { /** Missing fields of counterpart. */ diff --git a/src/api/types/MoniteAllPaymentMethods.ts b/src/api/types/MoniteAllPaymentMethods.ts index 7aed24b..ae52688 100644 --- a/src/api/types/MoniteAllPaymentMethods.ts +++ b/src/api/types/MoniteAllPaymentMethods.ts @@ -16,7 +16,9 @@ export type MoniteAllPaymentMethods = | "SEPA Direct Debit" | "SOFORT" | "Apple Pay" - | "Google Pay"; + | "Google Pay" + | "Affirm" + | "Klarna"; export const MoniteAllPaymentMethods = { SepaPayments: "SEPA Payments", UsAchPayments: "US ACH Payments", @@ -32,4 +34,6 @@ export const MoniteAllPaymentMethods = { Sofort: "SOFORT", ApplePay: "Apple Pay", GooglePay: "Google Pay", + Affirm: "Affirm", + Klarna: "Klarna", } as const; diff --git a/src/api/types/MoniteAllPaymentMethodsTypes.ts b/src/api/types/MoniteAllPaymentMethodsTypes.ts index 2fe7f6f..9b81af1 100644 --- a/src/api/types/MoniteAllPaymentMethodsTypes.ts +++ b/src/api/types/MoniteAllPaymentMethodsTypes.ts @@ -16,7 +16,9 @@ export type MoniteAllPaymentMethodsTypes = | "sepa_debit" | "sofort" | "applepay" - | "googlepay"; + | "googlepay" + | "affirm" + | "klarna"; export const MoniteAllPaymentMethodsTypes = { SepaCredit: "sepa_credit", UsAch: "us_ach", @@ -32,4 +34,6 @@ export const MoniteAllPaymentMethodsTypes = { Sofort: "sofort", Applepay: "applepay", Googlepay: "googlepay", + Affirm: "affirm", + Klarna: "klarna", } as const; diff --git a/src/api/types/NextDocumentNumbers.ts b/src/api/types/NextDocumentNumbers.ts new file mode 100644 index 0000000..8e4461f --- /dev/null +++ b/src/api/types/NextDocumentNumbers.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface NextDocumentNumbers { + /** Next credit note number */ + credit_note?: number; + /** Next delivery note number */ + delivery_note?: number; + /** Next invoice number */ + invoice?: number; + /** Next purchase order number */ + purchase_order?: number; + /** Next quote number */ + quote?: number; +} diff --git a/src/api/types/OcrAddress.ts b/src/api/types/OcrAddress.ts index 428cb79..be0ca65 100644 --- a/src/api/types/OcrAddress.ts +++ b/src/api/types/OcrAddress.ts @@ -8,18 +8,18 @@ * * There is an additional field original_country_name */ export interface OcrAddress { + /** City name. */ + city?: string; /** Two-letter ISO country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). */ country?: string; + /** Street address. */ + line1?: string; + /** Additional address information (if any). */ + line2?: string; /** Country name as it is stated in the document. */ original_country_name?: string; - /** City name. */ - city?: string; /** ZIP or postal code. */ postal_code?: string; /** State, region, province, or county. */ state?: string; - /** Street address. */ - line1?: string; - /** Additional address information (if any). */ - line2?: string; } diff --git a/src/api/types/OcrAddressDetails.ts b/src/api/types/OcrAddressDetails.ts index 843beaa..223a97e 100644 --- a/src/api/types/OcrAddressDetails.ts +++ b/src/api/types/OcrAddressDetails.ts @@ -2,12 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrAddressDetails { - street_and_number?: string; city?: string; - postal_code?: string; country?: Monite.AllowedCountries; + postal_code?: string; state?: string; + street_and_number?: string; } diff --git a/src/api/types/OcrCounterpartDetails.ts b/src/api/types/OcrCounterpartDetails.ts index d748aa8..aab353e 100644 --- a/src/api/types/OcrCounterpartDetails.ts +++ b/src/api/types/OcrCounterpartDetails.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrCounterpartDetails { - vat_number?: string; - tax_number?: string; - email?: string; - name?: string; address: Monite.OcrAddressDetails; bank_account: Monite.OcrBankDetails; + email?: string; + name?: string; + tax_number?: string; + vat_number?: string; } diff --git a/src/api/types/OcrCreditNote.ts b/src/api/types/OcrCreditNote.ts index 077fac8..cb26483 100644 --- a/src/api/types/OcrCreditNote.ts +++ b/src/api/types/OcrCreditNote.ts @@ -2,18 +2,18 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrCreditNote { + currency?: Monite.CurrencyEnum; document_number?: string; - original_invoice_number?: string; issue_date?: string; - currency?: Monite.CurrencyEnum; + line_items: Monite.OcrLineItem[]; + original_invoice_number?: string; + recipient: Monite.OcrCounterpartDetails; + sender: Monite.OcrCounterpartDetails; subtotal?: number; - tax_rate?: number; tax_amount?: number; + tax_rate?: number; total_amount?: number; - sender: Monite.OcrCounterpartDetails; - recipient: Monite.OcrCounterpartDetails; - line_items: Monite.OcrLineItem[]; } diff --git a/src/api/types/OcrDocumentTypeEnum.ts b/src/api/types/OcrDocumentTypeEnum.ts index 1763587..4052212 100644 --- a/src/api/types/OcrDocumentTypeEnum.ts +++ b/src/api/types/OcrDocumentTypeEnum.ts @@ -2,20 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ -export type OcrDocumentTypeEnum = - | "quote" - | "invoice" - | "credit_note" - | "discount_reminder" - | "final_reminder" - | "payables_purchase_order" - | "overdue_reminder"; +export type OcrDocumentTypeEnum = "invoice" | "credit_note" | "receipt"; export const OcrDocumentTypeEnum = { - Quote: "quote", Invoice: "invoice", CreditNote: "credit_note", - DiscountReminder: "discount_reminder", - FinalReminder: "final_reminder", - PayablesPurchaseOrder: "payables_purchase_order", - OverdueReminder: "overdue_reminder", + Receipt: "receipt", } as const; diff --git a/src/api/types/OcrInvoice.ts b/src/api/types/OcrInvoice.ts index 38b7122..2c8b130 100644 --- a/src/api/types/OcrInvoice.ts +++ b/src/api/types/OcrInvoice.ts @@ -2,20 +2,20 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrInvoice { + amount_paid?: number; currency?: Monite.CurrencyEnum; + document_number?: string; due_date?: string; issue_date?: string; - document_number?: string; - sender: Monite.OcrCounterpartDetails; + line_items?: Monite.OcrLineItem[]; + payment_terms?: string; recipient: Monite.OcrCounterpartDetails; + sender: Monite.OcrCounterpartDetails; subtotal?: number; - total_amount?: number; tax_amount?: number; tax_rate?: number; - amount_paid?: number; - payment_terms?: string; - line_items?: Monite.OcrLineItem[]; + total_amount?: number; } diff --git a/src/api/types/OcrLineItem.ts b/src/api/types/OcrLineItem.ts index d1b41eb..8193645 100644 --- a/src/api/types/OcrLineItem.ts +++ b/src/api/types/OcrLineItem.ts @@ -3,14 +3,14 @@ */ export interface OcrLineItem { + description?: string; line_reference?: string; name?: string; - description?: string; quantity?: number; - unit_price?: number; - unit?: string; subtotal?: number; - tax_rate?: number; tax_amount?: number; + tax_rate?: number; total_amount?: number; + unit?: string; + unit_price?: number; } diff --git a/src/api/types/OcrReceipt.ts b/src/api/types/OcrReceipt.ts index af571a2..46e44ed 100644 --- a/src/api/types/OcrReceipt.ts +++ b/src/api/types/OcrReceipt.ts @@ -2,18 +2,18 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrReceipt { + currency?: Monite.CurrencyEnum; + discount?: number; document_number?: string; issued_at?: string; - currency?: Monite.CurrencyEnum; + line_items: Monite.OcrReceiptLineItem[]; + sender: Monite.OcrCounterpartDetails; subtotal?: number; - tax_rate?: number; tax_amount?: number; - total_amount?: number; - discount?: number; + tax_rate?: number; tax_type?: string; - line_items: Monite.OcrReceiptLineItem[]; - sender: Monite.OcrCounterpartDetails; + total_amount?: number; } diff --git a/src/api/types/OcrReceiptLineItem.ts b/src/api/types/OcrReceiptLineItem.ts index dc24f3b..d394b32 100644 --- a/src/api/types/OcrReceiptLineItem.ts +++ b/src/api/types/OcrReceiptLineItem.ts @@ -3,15 +3,15 @@ */ export interface OcrReceiptLineItem { + description?: string; + discount_amount?: number; line_reference?: string; name?: string; - description?: string; quantity?: number; - unit_price?: number; - unit?: string; subtotal?: number; - tax_rate?: number; tax_amount?: number; + tax_rate?: number; total_amount?: number; - discount_amount?: number; + unit?: string; + unit_price?: number; } diff --git a/src/api/types/OcrRecognitionResponse.ts b/src/api/types/OcrRecognitionResponse.ts index 19f316a..b24fb01 100644 --- a/src/api/types/OcrRecognitionResponse.ts +++ b/src/api/types/OcrRecognitionResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains information about all text blocks extracted from an uploaded invoice by OCR. @@ -10,8 +10,8 @@ import * as Monite from "../index"; * Legacy schema used for AWS textract recognition. */ export interface OcrRecognitionResponse { - /** Invoice text content other than the line items. Such as the invoice issue and due dates, vendor name and address, and other general information. */ - summary?: Monite.LabelNValue[]; /** Text content of the invoice line items as recognized by OCR. */ line_items?: Monite.LabelNValue[]; + /** Invoice text content other than the line items. Such as the invoice issue and due dates, vendor name and address, and other general information. */ + summary?: Monite.LabelNValue[]; } diff --git a/src/api/types/OcrResponseInvoiceReceiptData.ts b/src/api/types/OcrResponseInvoiceReceiptData.ts index 4639d8c..3f49b2e 100644 --- a/src/api/types/OcrResponseInvoiceReceiptData.ts +++ b/src/api/types/OcrResponseInvoiceReceiptData.ts @@ -2,52 +2,54 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrResponseInvoiceReceiptData { - type?: "invoice"; + /** Counterpart bank ID */ + counterpart_account_id?: string; + /** The bank account number */ + counterpart_account_number?: string; + /** Counterpart address */ + counterpart_address?: string; + /** Counterpart address as a json object compatible with counterparts service */ + counterpart_address_object?: Monite.OcrAddress; + /** The bank branch number */ + counterpart_branch_number?: string; + /** Email address of the counterpart */ + counterpart_email?: string; + /** Counterpart name */ + counterpart_name?: string; + /** The bank routing number */ + counterpart_routing_number?: string; + /** Counterpart VAT ID */ + counterpart_vat_id?: string; + /** ISO 4217 currency code */ + currency?: string; /** Discount Raw amount */ discount_raw?: number; + /** Document due date in ISO format */ + document_due_date?: string; + /** Invoice/receipt ID */ + document_id?: string; + /** Document issuance date in ISO format */ + document_issued_at_date?: string; + /** List of line items from document raw, without minor units conversion. */ + line_items_raw?: Monite.OcrResponseInvoiceReceiptLineItemRaw[]; + /** Raw payment terms parsed but not calculated. */ + payment_terms_raw?: string[]; + /** Purchase Order Number */ + purchase_order_number?: string; + /** Tax payer ID */ + tax_payer_id?: string; + /** Subtotal, without minor units */ + total_excl_vat_raw?: number; /** Total paid amount */ total_paid_amount_raw?: number; /** Total, without minor units */ total_raw?: number; - /** Subtotal, without minor units */ - total_excl_vat_raw?: number; /** VAT amount, without minor units */ total_vat_amount_raw?: number; /** VAT Percent raw, without minor units. */ total_vat_rate_raw?: number; - /** ISO 4217 currency code */ - currency?: string; - /** Purchase Order Number */ - purchase_order_number?: string; - /** Counterpart name */ - counterpart_name?: string; - /** Email address of the counterpart */ - counterpart_email?: string; - /** Counterpart address */ - counterpart_address?: string; - /** Counterpart bank ID */ - counterpart_account_id?: string; - /** Invoice/receipt ID */ - document_id?: string; - /** Raw payment terms parsed but not calculated. */ - payment_terms_raw?: string[]; - /** Tax payer ID */ - tax_payer_id?: string; - /** Counterpart VAT ID */ - counterpart_vat_id?: string; - /** Document issuance date in ISO format */ - document_issued_at_date?: string; - /** Document due date in ISO format */ - document_due_date?: string; - /** Counterpart address as a json object compatible with counterparts service */ - counterpart_address_object?: Monite.OcrAddress; - /** The bank account number */ - counterpart_account_number?: string; - /** The bank routing number */ - counterpart_routing_number?: string; - /** List of line items from document raw, without minor units conversion. */ - line_items_raw?: Monite.OcrResponseInvoiceReceiptLineItemRaw[]; + type?: "invoice"; } diff --git a/src/api/types/OcrResponseInvoiceReceiptLineItemRaw.ts b/src/api/types/OcrResponseInvoiceReceiptLineItemRaw.ts index e9e6866..1da8ead 100644 --- a/src/api/types/OcrResponseInvoiceReceiptLineItemRaw.ts +++ b/src/api/types/OcrResponseInvoiceReceiptLineItemRaw.ts @@ -3,24 +3,24 @@ */ export interface OcrResponseInvoiceReceiptLineItemRaw { - /** OCR Id of line item */ - line_item_ocr_id?: string; /** Human-readable line item description */ description?: string; /** Item Quantity/Unit Price adjusted */ item_adjusted?: boolean; + /** OCR Id of line item */ + line_item_ocr_id?: string; /** Quantity */ quantity?: number; - /** Price as parsed */ - unit_price?: number; - /** Unit */ - unit?: string; - /** VAT Percent as parsed. */ - vat_percentage?: number; - /** VAT Amount as parsed. */ - vat_amount?: number; /** Total excluded VAT as parsed. */ total_excl_vat?: number; /** Total included VAT as parsed. */ total_incl_vat?: number; + /** Unit */ + unit?: string; + /** Price as parsed */ + unit_price?: number; + /** VAT Amount as parsed. */ + vat_amount?: number; + /** VAT Percent as parsed. */ + vat_percentage?: number; } diff --git a/src/api/types/OcrTaskResponseSchema.ts b/src/api/types/OcrTaskResponseSchema.ts index a657ca7..575242b 100644 --- a/src/api/types/OcrTaskResponseSchema.ts +++ b/src/api/types/OcrTaskResponseSchema.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OcrTaskResponseSchema { id: string; created_at: string; updated_at: string; - status: Monite.OcrTaskStatus; document_type?: Monite.OcrDocumentTypeEnum; recognized_data?: Monite.OcrTaskResponseSchemaRecognizedData; + status: Monite.OcrTaskStatus; } diff --git a/src/api/types/OcrTaskResponseSchemaRecognizedData.ts b/src/api/types/OcrTaskResponseSchemaRecognizedData.ts index ca3e0f0..6aa233a 100644 --- a/src/api/types/OcrTaskResponseSchemaRecognizedData.ts +++ b/src/api/types/OcrTaskResponseSchemaRecognizedData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type OcrTaskResponseSchemaRecognizedData = | Monite.OcrTaskResponseSchemaRecognizedData.Invoice diff --git a/src/api/types/OcrTasksPaginationResponse.ts b/src/api/types/OcrTasksPaginationResponse.ts index c4c8aab..ceb2927 100644 --- a/src/api/types/OcrTasksPaginationResponse.ts +++ b/src/api/types/OcrTasksPaginationResponse.ts @@ -2,15 +2,15 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of ocr requests. */ export interface OcrTasksPaginationResponse { data: Monite.OcrTaskResponseSchema[]; - /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ - prev_pagination_token?: string; /** A token that can be sent in the `pagination_token` query parameter to get the next page of results, or `null` if there is no next page (i.e. you've reached the last page). */ next_pagination_token?: string; + /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ + prev_pagination_token?: string; } diff --git a/src/api/types/OnboardingLinkPublicResponse.ts b/src/api/types/OnboardingLinkPublicResponse.ts deleted file mode 100644 index 1019e76..0000000 --- a/src/api/types/OnboardingLinkPublicResponse.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface OnboardingLinkPublicResponse { - id: string; - entity_id: string; - expires_at: string; - refresh_url: string; - return_url: string; - url: string; -} diff --git a/src/api/types/OnboardingLinkRequest.ts b/src/api/types/OnboardingLinkRequest.ts deleted file mode 100644 index f1f1cb3..0000000 --- a/src/api/types/OnboardingLinkRequest.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface OnboardingLinkRequest { - expires_at: string; - refresh_url: string; - return_url: string; -} diff --git a/src/api/types/OnboardingLinkResponse.ts b/src/api/types/OnboardingLinkResponse.ts deleted file mode 100644 index 974794b..0000000 --- a/src/api/types/OnboardingLinkResponse.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface OnboardingLinkResponse { - id: string; - created_at: string; - expires_at: string; - recipient: Monite.Recipient; - refresh_url: string; - return_url: string; - url: string; -} diff --git a/src/api/types/OnboardingPaymentMethodsResponse.ts b/src/api/types/OnboardingPaymentMethodsResponse.ts index 63283dc..4509829 100644 --- a/src/api/types/OnboardingPaymentMethodsResponse.ts +++ b/src/api/types/OnboardingPaymentMethodsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OnboardingPaymentMethodsResponse { data: Monite.PaymentMethod[]; diff --git a/src/api/types/OnboardingRequirementsResponse.ts b/src/api/types/OnboardingRequirementsResponse.ts index 7787991..b0adac6 100644 --- a/src/api/types/OnboardingRequirementsResponse.ts +++ b/src/api/types/OnboardingRequirementsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OnboardingRequirementsResponse { disabled_reason?: Monite.AccountDisabledReason; diff --git a/src/api/types/OptionalOrganizationSchema.ts b/src/api/types/OptionalOrganizationSchema.ts index cb749cc..8343bc8 100644 --- a/src/api/types/OptionalOrganizationSchema.ts +++ b/src/api/types/OptionalOrganizationSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema contains metadata for updating an organization diff --git a/src/api/types/OptionalPersonAddressRequest.ts b/src/api/types/OptionalPersonAddressRequest.ts index fb0c76f..af475f3 100644 --- a/src/api/types/OptionalPersonAddressRequest.ts +++ b/src/api/types/OptionalPersonAddressRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OptionalPersonAddressRequest { /** City, district, suburb, town, or village */ diff --git a/src/api/types/OrganizationResponseSchema.ts b/src/api/types/OrganizationResponseSchema.ts index 5509d6b..acb3338 100644 --- a/src/api/types/OrganizationResponseSchema.ts +++ b/src/api/types/OrganizationResponseSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains data specific to entities of the `organization` type. diff --git a/src/api/types/OrganizationSchema.ts b/src/api/types/OrganizationSchema.ts index ff12de9..77287c7 100644 --- a/src/api/types/OrganizationSchema.ts +++ b/src/api/types/OrganizationSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema contains metadata for an organization diff --git a/src/api/types/OverdueReminderResponse.ts b/src/api/types/OverdueReminderResponse.ts index 175268b..43bc19e 100644 --- a/src/api/types/OverdueReminderResponse.ts +++ b/src/api/types/OverdueReminderResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface OverdueReminderResponse { id: string; diff --git a/src/api/types/PageSchema2.ts b/src/api/types/PageSchema2.ts index 1cbafc3..9a2ca92 100644 --- a/src/api/types/PageSchema2.ts +++ b/src/api/types/PageSchema2.ts @@ -11,10 +11,10 @@ export interface PageSchema2 { id: string; /** The [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types) of the image. */ mimetype: string; - /** Image file size, in bytes. */ - size: number; /** The page number in the PDF document, from 0. */ number: number; + /** Image file size, in bytes. */ + size: number; /** The URL to download the image. */ url: string; } diff --git a/src/api/types/PartnerProjectSettingsPayloadOutput.ts b/src/api/types/PartnerProjectSettingsPayloadOutput.ts index 0b206f9..0106b7f 100644 --- a/src/api/types/PartnerProjectSettingsPayloadOutput.ts +++ b/src/api/types/PartnerProjectSettingsPayloadOutput.ts @@ -2,26 +2,32 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PartnerProjectSettingsPayloadOutput { + /** Default API version for partner. */ + api_version?: Monite.ApiVersion; + /** Unused. To specify commercial conditions for invoices and quotes, use the `commercial_condition_description` field in those documents. */ + commercial_conditions?: string[]; /** Custom currency exchange rates. */ currency?: Monite.CurrencySettingsOutput; - /** Settings for the payables module. */ - payable?: Monite.PayableSettings; - /** Settings for the receivables module. */ - receivable?: Monite.ReceivableSettings; - /** Settings for email and mailboxes. */ - mail?: Monite.MailSettings; - /** Commercial conditions for receivables. */ - commercial_conditions?: string[]; - /** Measurement units. */ - units?: Monite.Unit[]; - website?: string; /** A default role to provision upon new entity creation. */ default_role?: Record; + /** + * Settings for outgoing email. Used by: + * + * * accounts receivable emails, for example, emails sent by `POST /recevables/{receivable_id}/send`, + * * accounts payable approval notifications. + */ + mail?: Monite.MailSettings; + /** Settings for accounts payable. */ + payable?: Monite.PayableSettings; /** Settings for the payments module. */ payments?: Monite.PaymentsSettingsOutput; - /** Default API version for partner. */ - api_version?: Monite.ApiVersion; + /** Settings for accounts receivable. */ + receivable?: Monite.ReceivableSettings; + /** Unused. To manage the [measure units](https://docs.monite.com/accounts-receivable/products#manage-measure-units) for your entities, use the `/measure_units` endpoints. */ + units?: Monite.Unit[]; + /** The URL of the partner's website. Must be an HTTPS URL. Required if the partner's entities use [payment links](https://docs.monite.com/payments/payment-links). The "Powered by" badge in the payment page footer will link to this website. */ + website?: string; } diff --git a/src/api/types/PayableActionSchema.ts b/src/api/types/PayableActionSchema.ts index 4b41b73..95e9e65 100644 --- a/src/api/types/PayableActionSchema.ts +++ b/src/api/types/PayableActionSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableActionSchema { /** Action name */ diff --git a/src/api/types/PayableAggregatedDataResponse.ts b/src/api/types/PayableAggregatedDataResponse.ts index 9644954..809b808 100644 --- a/src/api/types/PayableAggregatedDataResponse.ts +++ b/src/api/types/PayableAggregatedDataResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableAggregatedDataResponse { /** The total count of payables across all statuses. */ diff --git a/src/api/types/PayableAggregatedItem.ts b/src/api/types/PayableAggregatedItem.ts index a7e2224..cc50f93 100644 --- a/src/api/types/PayableAggregatedItem.ts +++ b/src/api/types/PayableAggregatedItem.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableAggregatedItem { /** The total count of payables with this specific status. */ diff --git a/src/api/types/PayableAnalyticsResponse.ts b/src/api/types/PayableAnalyticsResponse.ts index d455957..2950efa 100644 --- a/src/api/types/PayableAnalyticsResponse.ts +++ b/src/api/types/PayableAnalyticsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableAnalyticsResponse { data: Monite.AnalyticsDataPoint[]; diff --git a/src/api/types/PayableCreatedEventData.ts b/src/api/types/PayableCreatedEventData.ts new file mode 100644 index 0000000..57457eb --- /dev/null +++ b/src/api/types/PayableCreatedEventData.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface PayableCreatedEventData { + payable_source: Monite.PayableOriginEnum; +} diff --git a/src/api/types/PayableCreditNoteLinkedEventData.ts b/src/api/types/PayableCreditNoteLinkedEventData.ts new file mode 100644 index 0000000..7744b78 --- /dev/null +++ b/src/api/types/PayableCreditNoteLinkedEventData.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface PayableCreditNoteLinkedEventData { + credit_note_document_id?: string; + credit_note_id: string; +} diff --git a/src/api/types/PayableCreditNoteStateEnum.ts b/src/api/types/PayableCreditNoteStateEnum.ts index 2880455..18b842f 100644 --- a/src/api/types/PayableCreditNoteStateEnum.ts +++ b/src/api/types/PayableCreditNoteStateEnum.ts @@ -2,6 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ +/** + * Credit note statuses (used in accounts payable). + */ export type PayableCreditNoteStateEnum = | "new" | "draft" diff --git a/src/api/types/PayableCreditNoteUnlinkedEventData.ts b/src/api/types/PayableCreditNoteUnlinkedEventData.ts new file mode 100644 index 0000000..9149574 --- /dev/null +++ b/src/api/types/PayableCreditNoteUnlinkedEventData.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface PayableCreditNoteUnlinkedEventData { + credit_note_document_id?: string; + credit_note_id: string; +} diff --git a/src/api/types/PayableEntityAddressSchema.ts b/src/api/types/PayableEntityAddressSchema.ts index 88af7f7..cdd1266 100644 --- a/src/api/types/PayableEntityAddressSchema.ts +++ b/src/api/types/PayableEntityAddressSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema represents address info of the entity diff --git a/src/api/types/PayableEntityIndividualResponse.ts b/src/api/types/PayableEntityIndividualResponse.ts index c6a17d4..a4bb32a 100644 --- a/src/api/types/PayableEntityIndividualResponse.ts +++ b/src/api/types/PayableEntityIndividualResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A base for an entity response schema diff --git a/src/api/types/PayableEntityOrganizationResponse.ts b/src/api/types/PayableEntityOrganizationResponse.ts index 2955371..3ecb67b 100644 --- a/src/api/types/PayableEntityOrganizationResponse.ts +++ b/src/api/types/PayableEntityOrganizationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A base for an entity response schema diff --git a/src/api/types/ValidationErrorLocItem.ts b/src/api/types/PayableHistoryCursorFields.ts similarity index 57% rename from src/api/types/ValidationErrorLocItem.ts rename to src/api/types/PayableHistoryCursorFields.ts index c97f7db..68bc601 100644 --- a/src/api/types/ValidationErrorLocItem.ts +++ b/src/api/types/PayableHistoryCursorFields.ts @@ -2,4 +2,4 @@ * This file was auto-generated by Fern from our API Definition. */ -export type ValidationErrorLocItem = string | number; +export type PayableHistoryCursorFields = "timestamp"; diff --git a/src/api/types/PayableHistoryEventTypeEnum.ts b/src/api/types/PayableHistoryEventTypeEnum.ts new file mode 100644 index 0000000..7b4899b --- /dev/null +++ b/src/api/types/PayableHistoryEventTypeEnum.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type PayableHistoryEventTypeEnum = + | "status_changed" + | "payable_created" + | "payable_updated" + | "credit_note_linked" + | "credit_note_unlinked" + | "file_attached"; +export const PayableHistoryEventTypeEnum = { + StatusChanged: "status_changed", + PayableCreated: "payable_created", + PayableUpdated: "payable_updated", + CreditNoteLinked: "credit_note_linked", + CreditNoteUnlinked: "credit_note_unlinked", + FileAttached: "file_attached", +} as const; diff --git a/src/api/types/PayableHistoryPaginationResponse.ts b/src/api/types/PayableHistoryPaginationResponse.ts new file mode 100644 index 0000000..fef9979 --- /dev/null +++ b/src/api/types/PayableHistoryPaginationResponse.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +/** + * A paginated list of change history records. + */ +export interface PayableHistoryPaginationResponse { + data: Monite.PayableHistoryResponse[]; + /** A token that can be sent in the `pagination_token` query parameter to get the next page of results, or `null` if there is no next page (i.e. you've reached the last page). */ + next_pagination_token?: string; + /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ + prev_pagination_token?: string; +} diff --git a/src/api/types/PayableHistoryResponse.ts b/src/api/types/PayableHistoryResponse.ts new file mode 100644 index 0000000..d25834a --- /dev/null +++ b/src/api/types/PayableHistoryResponse.ts @@ -0,0 +1,33 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface PayableHistoryResponse { + /** A unique ID of the history record. */ + id: string; + /** ID of the entity user who made the change or trigger the event, or `null` if it was done by using a partner access token. */ + entity_user_id?: string; + /** An object containing additional information about the event or change. The object structure varies based on the `event_type`. */ + event_data: PayableHistoryResponse.EventData; + /** The type of the event or change. */ + event_type: Monite.PayableHistoryEventTypeEnum; + /** ID of the payable document that was changed or triggered an event. */ + payable_id: string; + /** UTC date and time when the event or change occurred. */ + timestamp: string; +} + +export namespace PayableHistoryResponse { + /** + * An object containing additional information about the event or change. The object structure varies based on the `event_type`. + */ + export type EventData = + | Monite.PayableStatusChangedEventData + | Monite.PayableUpdatedEventData + | Monite.PayableCreatedEventData + | Monite.PayableCreditNoteLinkedEventData + | Monite.PayableCreditNoteUnlinkedEventData + | Monite.FileAttachedEventData; +} diff --git a/src/api/types/PayableOrganizationSchema.ts b/src/api/types/PayableOrganizationSchema.ts index be3bbaf..fe844fc 100644 --- a/src/api/types/PayableOrganizationSchema.ts +++ b/src/api/types/PayableOrganizationSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema contains metadata for an organization diff --git a/src/api/types/PayablePaginationResponse.ts b/src/api/types/PayablePaginationResponse.ts index 4d457cd..60457d0 100644 --- a/src/api/types/PayablePaginationResponse.ts +++ b/src/api/types/PayablePaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of payables. diff --git a/src/api/types/PayablePaymentTermsCreatePayload.ts b/src/api/types/PayablePaymentTermsCreatePayload.ts index 3c9e357..d6dec5d 100644 --- a/src/api/types/PayablePaymentTermsCreatePayload.ts +++ b/src/api/types/PayablePaymentTermsCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayablePaymentTermsCreatePayload { description?: string; diff --git a/src/api/types/PayableResponseSchema.ts b/src/api/types/PayableResponseSchema.ts index 98a9fa9..074b37e 100644 --- a/src/api/types/PayableResponseSchema.ts +++ b/src/api/types/PayableResponseSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents an Accounts Payable document received from a vendor or supplier. @@ -66,7 +66,7 @@ export interface PayableResponseSchema { /** The status of the data recognition process using OCR. The 'processing' status means that the data recognition is in progress and the user needs to wait for the data enrichment. The 'error' status indicates that some error occurred on the OCR side and the user can fill in the data manually. The 'success' status means the data recognition has been successfully completed, after which the user can check the data if desired and enrich or correct it. */ ocr_status?: Monite.OcrStatusEnum; /** Data extracted from the uploaded payable by OCR. */ - other_extracted_data?: Monite.PayableResponseSchemaOtherExtractedData; + other_extracted_data?: PayableResponseSchema.OtherExtractedData; /** The date by which the payable was paid */ paid_at?: string; /** Metadata for partner needs */ @@ -101,3 +101,10 @@ export interface PayableResponseSchema { total_amount_with_credit_notes?: number; was_created_by_user_id?: string; } + +export namespace PayableResponseSchema { + /** + * Data extracted from the uploaded payable by OCR. + */ + export type OtherExtractedData = Monite.OcrResponseInvoiceReceiptData | Monite.OcrRecognitionResponse; +} diff --git a/src/api/types/PayableResponseSchemaOtherExtractedData.ts b/src/api/types/PayableResponseSchemaOtherExtractedData.ts deleted file mode 100644 index 1d077f9..0000000 --- a/src/api/types/PayableResponseSchemaOtherExtractedData.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -/** - * Data extracted from the uploaded payable by OCR. - */ -export type PayableResponseSchemaOtherExtractedData = - | Monite.OcrResponseInvoiceReceiptData - | Monite.OcrRecognitionResponse; diff --git a/src/api/types/PayableSchemaInput.ts b/src/api/types/PayableSchemaInput.ts index c9844df..8515c0a 100644 --- a/src/api/types/PayableSchemaInput.ts +++ b/src/api/types/PayableSchemaInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableSchemaInput { /** List of actions */ diff --git a/src/api/types/PayableSchemaOutput.ts b/src/api/types/PayableSchemaOutput.ts index aaff19f..d4d34c0 100644 --- a/src/api/types/PayableSchemaOutput.ts +++ b/src/api/types/PayableSchemaOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableSchemaOutput { /** List of actions */ diff --git a/src/api/types/PayableSettings.ts b/src/api/types/PayableSettings.ts index 91fc89f..5480372 100644 --- a/src/api/types/PayableSettings.ts +++ b/src/api/types/PayableSettings.ts @@ -3,14 +3,20 @@ */ export interface PayableSettings { + /** When enabled, Monite will automatically detect and cancel payables identified as duplicates during ingestionβ€”reducing manual review overhead. */ allow_cancel_duplicates_automatically?: boolean; + /** Enables creation of a new counterpart record (supplier) when incoming payable data doesn't match any existing counterpart. */ allow_counterpart_autocreation?: boolean; + /** Automatically links incoming payables to existing counterpart records using matching logic (e.g., tax ID, IBAN, name/address). */ allow_counterpart_autolinking?: boolean; + /** If true, Monite will attempt to automatically attach credit notes to the corresponding payables when processing them. */ allow_credit_note_autolinking?: boolean; + /** The URL included in approval notification emails and UI buttons, directing approvers to complete the invoice approval workflow. Useful for linking to your custom approval portal. */ approve_page_url: string; - /** A state each new payable will have upon creation */ + /** The initial status assigned to newly created payables (e.g., `draft`, `new`). Determines whether they require approval or review. */ default_state?: string; - /** Starting from version 2024-05-25 by default is always set to True. */ + /** Partners can set this to True or False to control line item detection in OCR flows. */ enable_line_items?: boolean; + /** When set to true, payables that are already marked as paid bypass the approval workflow entirely. */ skip_approval_for_paid_invoice?: boolean; } diff --git a/src/api/types/PayableStatusChangedEventData.ts b/src/api/types/PayableStatusChangedEventData.ts new file mode 100644 index 0000000..673e3bf --- /dev/null +++ b/src/api/types/PayableStatusChangedEventData.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface PayableStatusChangedEventData { + new_status: Monite.PayableStateEnum; + old_status: Monite.PayableStateEnum; +} diff --git a/src/api/types/PayableTemplatesVariablesObject.ts b/src/api/types/PayableTemplatesVariablesObject.ts index d3b69fa..5b2333b 100644 --- a/src/api/types/PayableTemplatesVariablesObject.ts +++ b/src/api/types/PayableTemplatesVariablesObject.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableTemplatesVariablesObject { object_subtype: Monite.PayablesVariableType; diff --git a/src/api/types/PayableTemplatesVariablesObjectList.ts b/src/api/types/PayableTemplatesVariablesObjectList.ts index 677403c..ae61931 100644 --- a/src/api/types/PayableTemplatesVariablesObjectList.ts +++ b/src/api/types/PayableTemplatesVariablesObjectList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableTemplatesVariablesObjectList { data: Monite.PayableTemplatesVariablesObject[]; diff --git a/src/api/types/AirwallexMandateVersion.ts b/src/api/types/PayableUpdatedEventData.ts similarity index 62% rename from src/api/types/AirwallexMandateVersion.ts rename to src/api/types/PayableUpdatedEventData.ts index ef933a0..a79a527 100644 --- a/src/api/types/AirwallexMandateVersion.ts +++ b/src/api/types/PayableUpdatedEventData.ts @@ -2,4 +2,4 @@ * This file was auto-generated by Fern from our API Definition. */ -export type AirwallexMandateVersion = "1.0"; +export interface PayableUpdatedEventData {} diff --git a/src/api/types/PayableValidationsResource.ts b/src/api/types/PayableValidationsResource.ts index f4cf235..c970305 100644 --- a/src/api/types/PayableValidationsResource.ts +++ b/src/api/types/PayableValidationsResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayableValidationsResource { required_fields: Monite.PayablesFieldsAllowedForValidate[]; diff --git a/src/api/types/PayerAccountResponse.ts b/src/api/types/PayerAccountResponse.ts index 9d11b83..34ae69c 100644 --- a/src/api/types/PayerAccountResponse.ts +++ b/src/api/types/PayerAccountResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PayerAccountResponse { /** ID of a payment account */ diff --git a/src/api/types/PaymentAccountObject.ts b/src/api/types/PaymentAccountObject.ts index edf6422..7592220 100644 --- a/src/api/types/PaymentAccountObject.ts +++ b/src/api/types/PaymentAccountObject.ts @@ -2,11 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentAccountObject { - /** ID of a payment account */ + /** ID of the entity or counterpart that issued the invoice for which you are creating a payment link. */ id: string; - /** Type of a payment account. Can be `entity` or `counterpart` */ type: Monite.PaymentAccountType; } diff --git a/src/api/types/PaymentIntent.ts b/src/api/types/PaymentIntent.ts index 3f14e42..5c9f8e2 100644 --- a/src/api/types/PaymentIntent.ts +++ b/src/api/types/PaymentIntent.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentIntent { id: string; diff --git a/src/api/types/PaymentIntentHistoryResponse.ts b/src/api/types/PaymentIntentHistoryResponse.ts index 850a989..693c96f 100644 --- a/src/api/types/PaymentIntentHistoryResponse.ts +++ b/src/api/types/PaymentIntentHistoryResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentIntentHistoryResponse { /** Payment intent history */ diff --git a/src/api/types/PaymentIntentPayoutMethod.ts b/src/api/types/PaymentIntentPayoutMethod.ts deleted file mode 100644 index 352c8f4..0000000 --- a/src/api/types/PaymentIntentPayoutMethod.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type PaymentIntentPayoutMethod = "bank_account" | "paper_check"; -export const PaymentIntentPayoutMethod = { - BankAccount: "bank_account", - PaperCheck: "paper_check", -} as const; diff --git a/src/api/types/PaymentIntentResponse.ts b/src/api/types/PaymentIntentResponse.ts index c2d02d1..6fb507d 100644 --- a/src/api/types/PaymentIntentResponse.ts +++ b/src/api/types/PaymentIntentResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentIntentResponse { id: string; diff --git a/src/api/types/PaymentIntentsListResponse.ts b/src/api/types/PaymentIntentsListResponse.ts index 2c809cc..043e5c3 100644 --- a/src/api/types/PaymentIntentsListResponse.ts +++ b/src/api/types/PaymentIntentsListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentIntentsListResponse { data: Monite.PaymentIntentResponse[]; diff --git a/src/api/types/PaymentIntentsRecipient.ts b/src/api/types/PaymentIntentsRecipient.ts deleted file mode 100644 index 0c2aa59..0000000 --- a/src/api/types/PaymentIntentsRecipient.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface PaymentIntentsRecipient { - id: string; - bank_account_id?: string; - payout_method?: Monite.PaymentIntentPayoutMethod; - type: "counterpart"; -} diff --git a/src/api/types/PaymentMethod.ts b/src/api/types/PaymentMethod.ts index 195550c..c94488a 100644 --- a/src/api/types/PaymentMethod.ts +++ b/src/api/types/PaymentMethod.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentMethod { direction: Monite.PaymentMethodDirection; diff --git a/src/api/types/PaymentObject.ts b/src/api/types/PaymentObject.ts index 760960c..c690c04 100644 --- a/src/api/types/PaymentObject.ts +++ b/src/api/types/PaymentObject.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentObject { id: string; diff --git a/src/api/types/PaymentObjectPayable.ts b/src/api/types/PaymentObjectPayable.ts deleted file mode 100644 index 07f3e24..0000000 --- a/src/api/types/PaymentObjectPayable.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface PaymentObjectPayable { - id: string; - type: "payable"; -} diff --git a/src/api/types/PaymentPageTheme.ts b/src/api/types/PaymentPageTheme.ts index b537f41..115a5dc 100644 --- a/src/api/types/PaymentPageTheme.ts +++ b/src/api/types/PaymentPageTheme.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentPageTheme { background_color?: string; diff --git a/src/api/types/PaymentReceivedEventData.ts b/src/api/types/PaymentReceivedEventData.ts index f92b529..f4eff3e 100644 --- a/src/api/types/PaymentReceivedEventData.ts +++ b/src/api/types/PaymentReceivedEventData.ts @@ -6,7 +6,7 @@ * Contains information about a payment received for an invoice. */ export interface PaymentReceivedEventData { - /** The remainimg amount due of the invoice, in [minor units](https://docs.monite.com/references/currencies#minor-units) of the currency. For example, $12.5 is represented as 1250. */ + /** The remaining amount due of the invoice, in [minor units](https://docs.monite.com/references/currencies#minor-units) of the currency. For example, $12.5 is represented as 1250. */ amount_due: number; /** The payment amount, in minor units of the currency. */ amount_paid: number; diff --git a/src/api/types/PaymentRecordHistoryResponse.ts b/src/api/types/PaymentRecordHistoryResponse.ts new file mode 100644 index 0000000..d4b4ebe --- /dev/null +++ b/src/api/types/PaymentRecordHistoryResponse.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface PaymentRecordHistoryResponse { + entity_user_id?: string; + status: Monite.PaymentRecordStatusEnum; + /** Timestamp of the change in a history */ + timestamp: string; +} diff --git a/src/api/types/PaymentRecordObjectRequest.ts b/src/api/types/PaymentRecordObjectRequest.ts index 67ed4f0..e294968 100644 --- a/src/api/types/PaymentRecordObjectRequest.ts +++ b/src/api/types/PaymentRecordObjectRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentRecordObjectRequest { /** ID of the invoice */ diff --git a/src/api/types/PaymentRecordObjectResponse.ts b/src/api/types/PaymentRecordObjectResponse.ts index 91b65f1..0cd8fa6 100644 --- a/src/api/types/PaymentRecordObjectResponse.ts +++ b/src/api/types/PaymentRecordObjectResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentRecordObjectResponse { /** ID of the invoice */ diff --git a/src/api/types/PaymentRecordResponse.ts b/src/api/types/PaymentRecordResponse.ts index 4812339..3f14c89 100644 --- a/src/api/types/PaymentRecordResponse.ts +++ b/src/api/types/PaymentRecordResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentRecordResponse { id: string; @@ -12,6 +12,8 @@ export interface PaymentRecordResponse { currency: Monite.CurrencyEnum; /** ID of the user associated with the payment, if applicable. */ entity_user_id?: string; + /** History of the payment record. */ + history: Monite.PaymentRecordHistoryResponse[]; is_external: boolean; object: Monite.PaymentRecordObjectResponse; /** Filled in a case, if payment amount is more, than total_amount */ @@ -19,7 +21,7 @@ export interface PaymentRecordResponse { /** Timestamp marking when the payment was executed. Null if payment hasn't occurred yet. */ paid_at?: string; /** Identifier for an payment intent. */ - payment_intent_id: string; + payment_intent_id?: string; /** Raw status string of the external payment intent. */ payment_intent_status?: string; /** Payment method used or planned for the transaction. */ diff --git a/src/api/types/PaymentRecordResponseList.ts b/src/api/types/PaymentRecordResponseList.ts index 67556ed..c5564cd 100644 --- a/src/api/types/PaymentRecordResponseList.ts +++ b/src/api/types/PaymentRecordResponseList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentRecordResponseList { data: Monite.PaymentRecordResponse[]; diff --git a/src/api/types/PaymentReminderResponse.ts b/src/api/types/PaymentReminderResponse.ts index 8a8b7e0..8b54b03 100644 --- a/src/api/types/PaymentReminderResponse.ts +++ b/src/api/types/PaymentReminderResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentReminderResponse { id: string; diff --git a/src/api/types/PaymentTerms.ts b/src/api/types/PaymentTerms.ts index 6c7169f..9e95391 100644 --- a/src/api/types/PaymentTerms.ts +++ b/src/api/types/PaymentTerms.ts @@ -2,15 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentTerms { - id: string; + id?: string; + /** Description of the payment term. */ + description?: string; name?: string; /** The first tier of the payment term. Represents the terms of the first early discount. */ - term_1?: Monite.PaymentTermDiscountWithDate; + term_1?: Monite.InlineTermDiscount; /** The second tier of the payment term. Defines the terms of the second early discount. */ - term_2?: Monite.PaymentTermDiscountWithDate; + term_2?: Monite.InlineTermDiscount; /** The final tier of the payment term. Defines the invoice due date. */ - term_final: Monite.TermFinalWithDate; + term_final: Monite.InlineTermFinal; } diff --git a/src/api/types/PaymentTermsListResponse.ts b/src/api/types/PaymentTermsListResponse.ts index 0ef2464..7fa017b 100644 --- a/src/api/types/PaymentTermsListResponse.ts +++ b/src/api/types/PaymentTermsListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentTermsListResponse { data?: Monite.PaymentTermsResponse[]; diff --git a/src/api/types/PaymentTermsResponse.ts b/src/api/types/PaymentTermsResponse.ts index 581d33d..26a99e1 100644 --- a/src/api/types/PaymentTermsResponse.ts +++ b/src/api/types/PaymentTermsResponse.ts @@ -2,16 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentTermsResponse { id: string; description?: string; name: string; /** The first tier of the payment term. Represents the terms of the first early discount. */ - term_1?: Monite.PaymentTermDiscount; + term_1?: Monite.TermDiscountDays; /** The second tier of the payment term. Defines the terms of the second early discount. */ - term_2?: Monite.PaymentTermDiscount; + term_2?: Monite.TermDiscountDays; /** The final tier of the payment term. Defines the invoice due date. */ - term_final: Monite.PaymentTerm; + term_final: Monite.TermFinalDays; } diff --git a/src/api/types/PaymentsBatchPaymentRequest.ts b/src/api/types/PaymentsBatchPaymentRequest.ts deleted file mode 100644 index 52903b0..0000000 --- a/src/api/types/PaymentsBatchPaymentRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface PaymentsBatchPaymentRequest { - payer_bank_account_id: string; - payment_intents: Monite.SinglePaymentIntent[]; - payment_method: "us_ach"; -} diff --git a/src/api/types/PaymentsBatchPaymentResponse.ts b/src/api/types/PaymentsBatchPaymentResponse.ts deleted file mode 100644 index 54e7f34..0000000 --- a/src/api/types/PaymentsBatchPaymentResponse.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface PaymentsBatchPaymentResponse { - id: string; - created_at: string; - error?: Record; - payer_bank_account_id: string; - payment_intents: Monite.SinglePaymentIntentResponse[]; - payment_method: "us_ach"; - status: Monite.PaymentsBatchPaymentStatus; - total_amount?: number; -} diff --git a/src/api/types/PaymentsBatchPaymentStatus.ts b/src/api/types/PaymentsBatchPaymentStatus.ts deleted file mode 100644 index 31349d6..0000000 --- a/src/api/types/PaymentsBatchPaymentStatus.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type PaymentsBatchPaymentStatus = "created" | "processing" | "partially_successful" | "succeeded" | "failed"; -export const PaymentsBatchPaymentStatus = { - Created: "created", - Processing: "processing", - PartiallySuccessful: "partially_successful", - Succeeded: "succeeded", - Failed: "failed", -} as const; diff --git a/src/api/types/PaymentsSettingsInput.ts b/src/api/types/PaymentsSettingsInput.ts index 2b25248..2f71ec5 100644 --- a/src/api/types/PaymentsSettingsInput.ts +++ b/src/api/types/PaymentsSettingsInput.ts @@ -2,11 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentsSettingsInput { payment_page_domain?: string; + /** See [Payment page customization](https://docs.monite.com/payments/payment-page-customization). */ payment_page_theme?: Monite.PaymentPageTheme; - /** The support email address */ + /** Required if the partner has UK entities that want to accept Bacs Direct Debit payments. This email address will be included in Bacs debit notification emails sent to the payers, as the contact email address where the payers can send payments-related inquiries. */ support_email?: string; } diff --git a/src/api/types/PaymentsSettingsOutput.ts b/src/api/types/PaymentsSettingsOutput.ts index 19b20b5..fd64de9 100644 --- a/src/api/types/PaymentsSettingsOutput.ts +++ b/src/api/types/PaymentsSettingsOutput.ts @@ -2,11 +2,12 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PaymentsSettingsOutput { payment_page_domain?: string; + /** See [Payment page customization](https://docs.monite.com/payments/payment-page-customization). */ payment_page_theme?: Monite.PaymentPageTheme; - /** The support email address */ + /** Required if the partner has UK entities that want to accept Bacs Direct Debit payments. This email address will be included in Bacs debit notification emails sent to the payers, as the contact email address where the payers can send payments-related inquiries. */ support_email?: string; } diff --git a/src/api/types/PersonAddressRequest.ts b/src/api/types/PersonAddressRequest.ts index 8b87a09..217609e 100644 --- a/src/api/types/PersonAddressRequest.ts +++ b/src/api/types/PersonAddressRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PersonAddressRequest { /** City, district, suburb, town, or village */ diff --git a/src/api/types/PersonResponse.ts b/src/api/types/PersonResponse.ts index 9533a4c..0ce49c0 100644 --- a/src/api/types/PersonResponse.ts +++ b/src/api/types/PersonResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PersonResponse { /** The person's unique identifier */ diff --git a/src/api/types/PersonsResponse.ts b/src/api/types/PersonsResponse.ts index 949dfac..70b0898 100644 --- a/src/api/types/PersonsResponse.ts +++ b/src/api/types/PersonsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PersonsResponse { /** array of objects of type person */ diff --git a/src/api/types/PreviewSchema2.ts b/src/api/types/PreviewSchema2.ts index c06df90..b03999f 100644 --- a/src/api/types/PreviewSchema2.ts +++ b/src/api/types/PreviewSchema2.ts @@ -6,10 +6,10 @@ * A preview image generated for a file. */ export interface PreviewSchema2 { + /** The image height in pixels. */ + height: number; /** The image URL. */ url: string; /** The image width in pixels. */ width: number; - /** The image height in pixels. */ - height: number; } diff --git a/src/api/types/Price.ts b/src/api/types/Price.ts index fb775f6..480740f 100644 --- a/src/api/types/Price.ts +++ b/src/api/types/Price.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface Price { /** The currency in which the price of the product is set. */ diff --git a/src/api/types/PricingPlan.ts b/src/api/types/PricingPlan.ts index b58efe9..2e70e8d 100644 --- a/src/api/types/PricingPlan.ts +++ b/src/api/types/PricingPlan.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A pricing plan of a financing offer @@ -12,8 +12,8 @@ export interface PricingPlan { advance_rate_percentage: number; /** Transaction fee percentage. 300 means 3.00% */ fee_percentage: number; - /** Repayment type of the loan. */ - repayment_type: Monite.WcRepaymentType; /** This amount of days after which the repayment duration is due. This is only applicable for FIXED_DURATION repayment type */ repayment_duration_days?: number; + /** Repayment type of the loan. */ + repayment_type: Monite.WcRepaymentType; } diff --git a/src/api/types/ProcessResource.ts b/src/api/types/ProcessResource.ts index 1bbb945..38f7ba6 100644 --- a/src/api/types/ProcessResource.ts +++ b/src/api/types/ProcessResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ProcessResource { id: string; @@ -16,8 +16,15 @@ export interface ProcessResource { /** The metadata for the process. */ metadata: Record; /** The script snapshot taken when script started. */ - script_snapshot?: Monite.ProcessResourceScriptSnapshot; + script_snapshot?: ProcessResource.ScriptSnapshot; /** Tthe current status of the approval policy process. */ status: Monite.ProcessStatusEnum; updated_by?: string; } + +export namespace ProcessResource { + /** + * The script snapshot taken when script started. + */ + export type ScriptSnapshot = boolean | number | string | unknown[] | Record; +} diff --git a/src/api/types/ProcessResourceScriptSnapshot.ts b/src/api/types/ProcessResourceScriptSnapshot.ts deleted file mode 100644 index 918e267..0000000 --- a/src/api/types/ProcessResourceScriptSnapshot.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * The script snapshot taken when script started. - */ -export type ProcessResourceScriptSnapshot = boolean | number | string | unknown[] | Record; diff --git a/src/api/types/ProductServicePaginationResponse.ts b/src/api/types/ProductServicePaginationResponse.ts index 1f9227a..2160e70 100644 --- a/src/api/types/ProductServicePaginationResponse.ts +++ b/src/api/types/ProductServicePaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of products and services diff --git a/src/api/types/ProductServiceResponse.ts b/src/api/types/ProductServiceResponse.ts index 406c56b..ac346f3 100644 --- a/src/api/types/ProductServiceResponse.ts +++ b/src/api/types/ProductServiceResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ProductServiceResponse { /** Unique ID of the product. */ @@ -15,6 +15,8 @@ export interface ProductServiceResponse { description?: string; entity_id: string; entity_user_id?: string; + /** A user-defined identifier of the product. For example, an internal product code or SKU (stock keeping unit). Client applications can use this field to map the products in Monite to an external product catalog. */ + external_reference?: string; ledger_account_id?: string; /** The unique ID reference of the unit used to measure the quantity of this product (e.g. items, meters, kilograms). */ measure_unit_id?: string; diff --git a/src/api/types/ProjectPaginationResponse.ts b/src/api/types/ProjectPaginationResponse.ts index 585e25f..cb6df47 100644 --- a/src/api/types/ProjectPaginationResponse.ts +++ b/src/api/types/ProjectPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of projects. diff --git a/src/api/types/ProjectResource.ts b/src/api/types/ProjectResource.ts index ff77374..5012b28 100644 --- a/src/api/types/ProjectResource.ts +++ b/src/api/types/ProjectResource.ts @@ -2,34 +2,34 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ProjectResource { /** A unique ID assigned to this project. */ id: string; - /** Project created at */ + /** UTC date and time when this project was created. */ created_at: string; - /** Last time project was updated at */ + /** UTC date and time when this project was last updated. */ updated_at: string; - /** Project code */ + /** A user-defined identifier of this project. */ code?: string; - /** Project color */ + /** Project color as a [CSS-compatible](https://developer.mozilla.org/en-US/docs/Web/CSS/color) value. Client applications can use this to color-code the projects or project-related data. */ color?: string; - /** Project created by entity user */ + /** ID of the entity user who created this project, or `null` if it was created using a partner access token. */ created_by_entity_user_id?: string; - /** Description of project */ + /** A user-defined description of the project. */ description?: string; - /** Project end date */ + /** Project end date. */ end_date?: string; - /** The ID of the entity to which the project was issued. */ + /** ID of the entity that owns this project. */ entity_id: string; /** The project name. */ name: string; - /** Parent project ID */ + /** Unused. Reserved for future use. */ parent_id?: string; - /** Project metadata */ + /** [Metadata](https://docs.monite.com/common/metadata) for partner needs. */ partner_metadata?: Record; - /** Project start date */ + /** Project start date. */ start_date?: string; /** A list of user-defined tags (labels) assigned to this project. */ tags?: Monite.TagReadSchema[]; diff --git a/src/api/types/PublicPaymentLinkResponse.ts b/src/api/types/PublicPaymentLinkResponse.ts index 7da5f9c..f564cec 100644 --- a/src/api/types/PublicPaymentLinkResponse.ts +++ b/src/api/types/PublicPaymentLinkResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PublicPaymentLinkResponse { id: string; diff --git a/src/api/types/PurchaseOrderCounterpartAddressSchema.ts b/src/api/types/PurchaseOrderCounterpartAddressSchema.ts index 61c88ba..3514f82 100644 --- a/src/api/types/PurchaseOrderCounterpartAddressSchema.ts +++ b/src/api/types/PurchaseOrderCounterpartAddressSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. diff --git a/src/api/types/PurchaseOrderCounterpartIndividualRootResponse.ts b/src/api/types/PurchaseOrderCounterpartIndividualRootResponse.ts index 181d6c1..f5f9bfa 100644 --- a/src/api/types/PurchaseOrderCounterpartIndividualRootResponse.ts +++ b/src/api/types/PurchaseOrderCounterpartIndividualRootResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are individuals (natural persons). @@ -16,12 +16,12 @@ export interface PurchaseOrderCounterpartIndividualRootResponse { updated_at: string; /** `true` if the counterpart was created automatically by Monite when processing incoming invoices with OCR. `false` if the counterpart was created by the API client. */ created_automatically?: boolean; + /** Entity user ID of counterpart creator. */ + created_by_entity_user_id?: string; /** ID of the counterpart's billing address. If the counterpart is US-based and needs to accept ACH payments, this address must have all fields filled in. If `default_billing_address_id` is not defined, the default address is instead used as the billing address for ACH payments. */ default_billing_address_id?: string; /** ID of the shipping address. */ default_shipping_address_id?: string; - /** Entity user ID of counterpart creator. */ - created_by_entity_user_id?: string; individual: Monite.PurchaseOrderCounterpartIndividualResponse; /** The language used to generate PDF documents for this counterpart. */ language?: Monite.LanguageCodeEnum; diff --git a/src/api/types/PurchaseOrderCounterpartOrganizationRootResponse.ts b/src/api/types/PurchaseOrderCounterpartOrganizationRootResponse.ts index 4ad7c8b..fa7b455 100644 --- a/src/api/types/PurchaseOrderCounterpartOrganizationRootResponse.ts +++ b/src/api/types/PurchaseOrderCounterpartOrganizationRootResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents counterparts that are organizations (juridical persons). @@ -16,12 +16,12 @@ export interface PurchaseOrderCounterpartOrganizationRootResponse { updated_at: string; /** `true` if the counterpart was created automatically by Monite when processing incoming invoices with OCR. `false` if the counterpart was created by the API client. */ created_automatically?: boolean; + /** Entity user ID of counterpart creator. */ + created_by_entity_user_id?: string; /** ID of the counterpart's billing address. If the counterpart is US-based and needs to accept ACH payments, this address must have all fields filled in. If `default_billing_address_id` is not defined, the default address is instead used as the billing address for ACH payments. */ default_billing_address_id?: string; /** ID of the shipping address. */ default_shipping_address_id?: string; - /** Entity user ID of counterpart creator. */ - created_by_entity_user_id?: string; /** The language used to generate PDF documents for this counterpart. */ language?: Monite.LanguageCodeEnum; organization: Monite.PurchaseOrderCounterpartOrganizationResponse; diff --git a/src/api/types/PurchaseOrderCounterpartSchema.ts b/src/api/types/PurchaseOrderCounterpartSchema.ts index ac44007..0b63911 100644 --- a/src/api/types/PurchaseOrderCounterpartSchema.ts +++ b/src/api/types/PurchaseOrderCounterpartSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A Counterpart object contains information about an organization (juridical person) or diff --git a/src/api/types/PurchaseOrderItem.ts b/src/api/types/PurchaseOrderItem.ts index b9a96da..0eaf02c 100644 --- a/src/api/types/PurchaseOrderItem.ts +++ b/src/api/types/PurchaseOrderItem.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface PurchaseOrderItem { /** The currency in which the price of the product is set. */ diff --git a/src/api/types/PurchaseOrderPaginationResponse.ts b/src/api/types/PurchaseOrderPaginationResponse.ts index 3e0aa94..d9ff6e9 100644 --- a/src/api/types/PurchaseOrderPaginationResponse.ts +++ b/src/api/types/PurchaseOrderPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of purchase orders. diff --git a/src/api/types/PurchaseOrderResponseSchema.ts b/src/api/types/PurchaseOrderResponseSchema.ts index fc08522..b17358d 100644 --- a/src/api/types/PurchaseOrderResponseSchema.ts +++ b/src/api/types/PurchaseOrderResponseSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents response for an Accounts Purchase Order document created by entity. @@ -28,7 +28,7 @@ export interface PurchaseOrderResponseSchema { currency: Monite.CurrencyEnum; document_id: string; /** Data of the entity (address, name, contact) */ - entity: Monite.PurchaseOrderResponseSchemaEntity; + entity: PurchaseOrderResponseSchema.Entity; /** The ID of the entity which issued the purchase order. */ entity_id: string; entity_vat_id?: Monite.PurchaseOrderVatId; @@ -47,3 +47,10 @@ export interface PurchaseOrderResponseSchema { /** Number of days for which purchase order is valid */ valid_for_days: number; } + +export namespace PurchaseOrderResponseSchema { + /** + * Data of the entity (address, name, contact) + */ + export type Entity = Monite.PayableEntityIndividualResponse | Monite.PayableEntityOrganizationResponse; +} diff --git a/src/api/types/PurchaseOrderResponseSchemaEntity.ts b/src/api/types/PurchaseOrderResponseSchemaEntity.ts deleted file mode 100644 index a5f8565..0000000 --- a/src/api/types/PurchaseOrderResponseSchemaEntity.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -/** - * Data of the entity (address, name, contact) - */ -export type PurchaseOrderResponseSchemaEntity = - | Monite.PayableEntityIndividualResponse - | Monite.PayableEntityOrganizationResponse; diff --git a/src/api/types/QuoteResponsePayload.ts b/src/api/types/QuoteResponsePayload.ts index b7f96f1..555bb47 100644 --- a/src/api/types/QuoteResponsePayload.ts +++ b/src/api/types/QuoteResponsePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface QuoteResponsePayload { id: string; @@ -10,9 +10,11 @@ export interface QuoteResponsePayload { created_at: string; /** Time at which the receivable was last updated. Timestamps follow the ISO 8601 standard. */ updated_at: string; - /** The unique ID of a previous document related to the receivable if applicable. */ + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentResponse[]; + /** Unused. Always returns `null`. */ based_on?: string; - /** The unique document ID of a previous document related to the receivable if applicable. */ + /** Unused. Always returns `null`. */ based_on_document_id?: string; /** Field with a comment on why the client declined this Quote */ comment?: string; @@ -35,7 +37,7 @@ export interface QuoteResponsePayload { /** The VAT/TAX ID of the counterpart. */ counterpart_tax_id?: string; /** The type of the counterpart. */ - counterpart_type: Monite.ReceivableCounterpartType; + counterpart_type: Monite.CounterpartType; counterpart_vat_id?: Monite.ReceivableCounterpartVatIdResponse; /** The currency used in the receivable. */ currency: Monite.CurrencyEnum; @@ -44,14 +46,16 @@ export interface QuoteResponsePayload { /** A note with additional information about a tax deduction */ deduction_memo?: string; /** The discount for a receivable. */ - discount?: Monite.Discount; + discount?: Monite.DiscountResponse; /** Total price of the receivable with discounts before taxes [minor units](https://docs.monite.com/references/currencies#minor-units). */ discounted_subtotal?: number; /** The sequential code systematically assigned to invoices. */ document_id?: string; - /** Optional field representing date until which invoice should be paid */ + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; + /** Unused. Always returns `null`. */ due_date?: string; - /** E-invoice XML file that was sent to the counterpart via an e-invoicing network. Available only if `is_einvoice` is `true`. */ + /** Unused. Always returns `null`. */ einvoice_file_url?: string; entity: Monite.QuoteResponsePayloadEntity; entity_address: Monite.ReceivableEntityAddressSchema; @@ -65,12 +69,12 @@ export interface QuoteResponsePayload { file_language: Monite.LanguageCodeEnum; /** The receivable's PDF URL in the counterpart's default language. */ file_url?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** Optional text displayed below the line items table in the PDF. See also: `memo`, `commercial_condition_description`. */ footer?: string; /** Optional field for the issue of the entry. */ issue_date?: string; line_items: Monite.ResponseItem[]; - /** A note with additional information for a receivable. */ + /** An optional note for the customer, displayed above the line items table in the PDF. See also: `footer`, `commercial_condition_description`. */ memo?: string; /** The language of the entity's copy of the PDF file (`original_file_url`). The value matches the entity's `language` at the time when this PDF file was generated. */ original_file_language: Monite.LanguageCodeEnum; @@ -78,7 +82,7 @@ export interface QuoteResponsePayload { original_file_url?: string; /** Metadata for partner needs */ partner_metadata?: Record; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this quote. If specified, the project name will be included in the header of the PDF quote. */ project_id?: string; /** Link for custom quote accept page */ quote_accept_page_url?: string; diff --git a/src/api/types/QuoteResponsePayloadEntity.ts b/src/api/types/QuoteResponsePayloadEntity.ts index 47023e6..5c655bc 100644 --- a/src/api/types/QuoteResponsePayloadEntity.ts +++ b/src/api/types/QuoteResponsePayloadEntity.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type QuoteResponsePayloadEntity = | Monite.QuoteResponsePayloadEntity.Organization diff --git a/src/api/types/QuoteStateEnum.ts b/src/api/types/QuoteStateEnum.ts index 990221a..950e04c 100644 --- a/src/api/types/QuoteStateEnum.ts +++ b/src/api/types/QuoteStateEnum.ts @@ -2,6 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ +/** + * Quote statuses. + */ export type QuoteStateEnum = "draft" | "issued" | "accepted" | "expired" | "declined"; export const QuoteStateEnum = { Draft: "draft", diff --git a/src/api/types/ReceiptCursorFields.ts b/src/api/types/ReceiptCursorFields.ts new file mode 100644 index 0000000..40a6c97 --- /dev/null +++ b/src/api/types/ReceiptCursorFields.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type ReceiptCursorFields = "id" | "created_at"; +export const ReceiptCursorFields = { + Id: "id", + CreatedAt: "created_at", +} as const; diff --git a/src/api/types/ReceiptLineItemCursorFields.ts b/src/api/types/ReceiptLineItemCursorFields.ts new file mode 100644 index 0000000..8ae2fa3 --- /dev/null +++ b/src/api/types/ReceiptLineItemCursorFields.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type ReceiptLineItemCursorFields = "created_at" | "updated_at"; +export const ReceiptLineItemCursorFields = { + CreatedAt: "created_at", + UpdatedAt: "updated_at", +} as const; diff --git a/src/api/types/ReceiptLineItemResponseSchema.ts b/src/api/types/ReceiptLineItemResponseSchema.ts new file mode 100644 index 0000000..636b62e --- /dev/null +++ b/src/api/types/ReceiptLineItemResponseSchema.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ReceiptLineItemResponseSchema { + /** Unique line item ID. */ + id: string; + /** Created at. */ + created_at: string; + /** Updated at. */ + updated_at: string; + /** Accounting tax rate ID. */ + accounting_tax_rate_id?: string; + /** Cost center ID. */ + cost_center_id?: string; + /** Created by user. */ + created_by_entity_user_id?: string; + /** Line item name. */ + name?: string; + /** Receipt ID. */ + receipt_id: string; + /** Total. */ + total?: number; +} diff --git a/src/api/types/ReceiptLineItemsPaginationResponse.ts b/src/api/types/ReceiptLineItemsPaginationResponse.ts new file mode 100644 index 0000000..d798048 --- /dev/null +++ b/src/api/types/ReceiptLineItemsPaginationResponse.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface ReceiptLineItemsPaginationResponse { + data: Monite.ReceiptLineItemResponseSchema[]; + /** Next page token. */ + next_pagination_token?: string; + /** Previous page token. */ + prev_pagination_token?: string; +} diff --git a/src/api/types/ReceiptPaginationResponse.ts b/src/api/types/ReceiptPaginationResponse.ts new file mode 100644 index 0000000..9394ee1 --- /dev/null +++ b/src/api/types/ReceiptPaginationResponse.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface ReceiptPaginationResponse { + data: Monite.ReceiptResponseSchema[]; + /** Next page token. */ + next_pagination_token?: string; + /** Previous page token. */ + prev_pagination_token?: string; +} diff --git a/src/api/types/ReceiptResponseSchema.ts b/src/api/types/ReceiptResponseSchema.ts new file mode 100644 index 0000000..1116f1e --- /dev/null +++ b/src/api/types/ReceiptResponseSchema.ts @@ -0,0 +1,44 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface ReceiptResponseSchema { + /** Unique receipt ID. */ + id: string; + /** Creation timestamp. */ + created_at: string; + /** Update timestamp. */ + updated_at: string; + /** Entity user who created. */ + created_by_entity_user_id?: string; + /** Currency code. */ + currency?: Monite.CurrencyEnum; + /** Currency exchange details. */ + currency_exchange?: Record; + /** Receipt number. */ + document_id?: string; + /** The id of the receipt file stored in the file saver. */ + file_id?: string; + /** The URL of the receipt file stored in the file saver. */ + file_url?: string; + /** Date when the receipt was issued. */ + issued_at?: string; + /** Merchant location. */ + merchant_location?: string; + /** Merchant name. */ + merchant_name?: string; + /** OCR request id. */ + ocr_request_id?: string; + /** OCR status. */ + ocr_status?: string; + /** Partner metadata. */ + partner_metadata?: Record; + /** Source of data. */ + source_of_data?: Monite.SourceOfReceiptDataEnum; + /** Total amount in minor units. */ + total_amount?: number; + /** Transaction ID. */ + transaction_id?: string; +} diff --git a/src/api/types/ReceivableCounterpartContact.ts b/src/api/types/ReceivableCounterpartContact.ts index 6c6b941..ae6a360 100644 --- a/src/api/types/ReceivableCounterpartContact.ts +++ b/src/api/types/ReceivableCounterpartContact.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableCounterpartContact { /** The contact address of the counterpart */ diff --git a/src/api/types/ReceivableCounterpartType.ts b/src/api/types/ReceivableCounterpartType.ts deleted file mode 100644 index a8d2e3c..0000000 --- a/src/api/types/ReceivableCounterpartType.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type ReceivableCounterpartType = "individual" | "organization"; -export const ReceivableCounterpartType = { - Individual: "individual", - Organization: "organization", -} as const; diff --git a/src/api/types/ReceivableCounterpartVatIdResponse.ts b/src/api/types/ReceivableCounterpartVatIdResponse.ts index cbc7960..0f3f6bd 100644 --- a/src/api/types/ReceivableCounterpartVatIdResponse.ts +++ b/src/api/types/ReceivableCounterpartVatIdResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableCounterpartVatIdResponse { id: string; diff --git a/src/api/types/ReceivableCreateBasedOnPayload.ts b/src/api/types/ReceivableCreateBasedOnPayload.ts index 651ea82..965521d 100644 --- a/src/api/types/ReceivableCreateBasedOnPayload.ts +++ b/src/api/types/ReceivableCreateBasedOnPayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableCreateBasedOnPayload { /** The unique ID of a previous document related to the receivable if applicable. */ diff --git a/src/api/types/ReceivableCursorFields.ts b/src/api/types/ReceivableCursorFields.ts index fb60935..10324f2 100644 --- a/src/api/types/ReceivableCursorFields.ts +++ b/src/api/types/ReceivableCursorFields.ts @@ -7,6 +7,7 @@ export type ReceivableCursorFields = | "counterpart_id" | "amount" | "total_amount" + | "discounted_subtotal" | "status" | "due_date" | "issue_date" @@ -18,6 +19,7 @@ export const ReceivableCursorFields = { CounterpartId: "counterpart_id", Amount: "amount", TotalAmount: "total_amount", + DiscountedSubtotal: "discounted_subtotal", Status: "status", DueDate: "due_date", IssueDate: "issue_date", diff --git a/src/api/types/ReceivableCursorFields2.ts b/src/api/types/ReceivableCursorFields2.ts new file mode 100644 index 0000000..0ca01a2 --- /dev/null +++ b/src/api/types/ReceivableCursorFields2.ts @@ -0,0 +1,27 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type ReceivableCursorFields2 = + | "counterpart_name" + | "counterpart_id" + | "amount" + | "total_amount" + | "status" + | "due_date" + | "issue_date" + | "document_id" + | "created_at" + | "project_id"; +export const ReceivableCursorFields2 = { + CounterpartName: "counterpart_name", + CounterpartId: "counterpart_id", + Amount: "amount", + TotalAmount: "total_amount", + Status: "status", + DueDate: "due_date", + IssueDate: "issue_date", + DocumentId: "document_id", + CreatedAt: "created_at", + ProjectId: "project_id", +} as const; diff --git a/src/api/types/ReceivableEntityAddressSchema.ts b/src/api/types/ReceivableEntityAddressSchema.ts index 605555a..a101cd6 100644 --- a/src/api/types/ReceivableEntityAddressSchema.ts +++ b/src/api/types/ReceivableEntityAddressSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema represents address info of the entity diff --git a/src/api/types/ReceivableEntityVatIdResponse.ts b/src/api/types/ReceivableEntityVatIdResponse.ts index 207b4cc..e2fb030 100644 --- a/src/api/types/ReceivableEntityVatIdResponse.ts +++ b/src/api/types/ReceivableEntityVatIdResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableEntityVatIdResponse { id: string; diff --git a/src/api/types/ReceivableFacadeCreateInvoicePayload.ts b/src/api/types/ReceivableFacadeCreateInvoicePayload.ts index 79cbff9..a7a25f3 100644 --- a/src/api/types/ReceivableFacadeCreateInvoicePayload.ts +++ b/src/api/types/ReceivableFacadeCreateInvoicePayload.ts @@ -2,9 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableFacadeCreateInvoicePayload { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; commercial_condition_description?: string; /** Address of invoicing, need to state as a separate fields for some countries if it differs from address of a company. */ counterpart_billing_address_id: string; @@ -26,12 +28,18 @@ export interface ReceivableFacadeCreateInvoicePayload { discount?: Monite.Discount; /** The document number of the receivable, which will appear in the PDF document. Can be set manually only in the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance). Otherwise (or if omitted), it will be generated automatically based on the entity's [document number customization](https://docs.monite.com/advanced/document-number-customization) settings when the document is issued. */ document_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; entity?: Monite.ReceivableEntityBase; /** Entity bank account ID */ entity_bank_account_id?: string; /** Entity VAT ID id */ entity_vat_id_id?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; /** * The date when the goods are shipped or the service is provided. Can be a current, past, or future date. @@ -44,7 +52,11 @@ export interface ReceivableFacadeCreateInvoicePayload { /** Is this Invoice will be sent through E-invoice system */ is_einvoice?: boolean; line_items: Monite.LineItem[]; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; /** E-invoicing credentials ID of the entity */ network_credentials_id?: string; @@ -54,8 +66,9 @@ export interface ReceivableFacadeCreateInvoicePayload { /** Link to the invoice's payment page. Either Monite's payment links or your custom payment links. */ payment_page_url?: string; payment_reminder_id?: string; + payment_terms?: Monite.InlinePaymentTermsRequestPayload; payment_terms_id?: string; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this invoice. If specified, the project name will be included in the header of the PDF invoice. */ project_id?: string; /** Contain purchase order number. */ purchase_order?: string; diff --git a/src/api/types/ReceivableFacadeCreatePayload.ts b/src/api/types/ReceivableFacadeCreatePayload.ts index 149c191..a8b1f5e 100644 --- a/src/api/types/ReceivableFacadeCreatePayload.ts +++ b/src/api/types/ReceivableFacadeCreatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type ReceivableFacadeCreatePayload = | Monite.ReceivableFacadeCreateQuotePayload diff --git a/src/api/types/ReceivableFacadeCreateQuotePayload.ts b/src/api/types/ReceivableFacadeCreateQuotePayload.ts index 88633b7..1b8795b 100644 --- a/src/api/types/ReceivableFacadeCreateQuotePayload.ts +++ b/src/api/types/ReceivableFacadeCreateQuotePayload.ts @@ -2,9 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableFacadeCreateQuotePayload { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; commercial_condition_description?: string; /** Address of invoicing, need to state as a separate fields for some countries if it differs from address of a company. */ counterpart_billing_address_id: string; @@ -24,6 +26,8 @@ export interface ReceivableFacadeCreateQuotePayload { discount?: Monite.Discount; /** The document number of the receivable, which will appear in the PDF document. Can be set manually only in the [non-compliant mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance). Otherwise (or if omitted), it will be generated automatically based on the entity's [document number customization](https://docs.monite.com/advanced/document-number-customization) settings when the document is issued. */ document_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; entity?: Monite.ReceivableEntityBase; /** Entity bank account ID */ entity_bank_account_id?: string; @@ -31,14 +35,22 @@ export interface ReceivableFacadeCreateQuotePayload { entity_vat_id_id?: string; /** The date (in ISO 8601 format) until which the quote is valid. */ expiry_date?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; line_items: Monite.LineItem[]; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; /** Metadata for partner needs */ partner_metadata?: Record; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this quote. If specified, the project name will be included in the header of the PDF quote. */ project_id?: string; /** Link for custom quote accept page */ quote_accept_page_url?: string; diff --git a/src/api/types/ReceivableHistoryPaginationResponse.ts b/src/api/types/ReceivableHistoryPaginationResponse.ts index c5261d0..0133254 100644 --- a/src/api/types/ReceivableHistoryPaginationResponse.ts +++ b/src/api/types/ReceivableHistoryPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of change history records. diff --git a/src/api/types/ReceivableHistoryResponse.ts b/src/api/types/ReceivableHistoryResponse.ts index 4aa9dcd..edfb3d4 100644 --- a/src/api/types/ReceivableHistoryResponse.ts +++ b/src/api/types/ReceivableHistoryResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents an entry in the change history of an accounts receivable document. @@ -21,7 +21,7 @@ export interface ReceivableHistoryResponse { /** ID of the entity user who made the change or trigger the event, or `null` if it was done by using a partner access token. */ entity_user_id?: string; /** An object containing additional information about the event or change. The object structure varies based on the `event_type`. In `receivable_created` and `receivable_updated` events, `event_data` is an empty object `{}`. */ - event_data: Monite.ReceivableHistoryResponseEventData; + event_data: ReceivableHistoryResponse.EventData; /** The type of the event or change. See [Event types](https://docs.monite.com/accounts-receivable/document-history#event-types). */ event_type: Monite.ReceivableHistoryEventTypeEnum; /** ID of the receivable document that was changed or triggered an event. */ @@ -29,3 +29,17 @@ export interface ReceivableHistoryResponse { /** UTC date and time when the event or change occurred. */ timestamp: string; } + +export namespace ReceivableHistoryResponse { + /** + * An object containing additional information about the event or change. The object structure varies based on the `event_type`. In `receivable_created` and `receivable_updated` events, `event_data` is an empty object `{}`. + */ + export type EventData = + | Monite.StatusChangedEventData + | Monite.ReceivableUpdatedEventData + | Monite.ReceivableCreatedEventData + | Monite.BasedOnReceivableCreatedEventData + | Monite.PaymentReceivedEventData + | Monite.MailSentEventData + | Monite.ReminderMailSentEventData; +} diff --git a/src/api/types/ReceivableHistoryResponseEventData.ts b/src/api/types/ReceivableHistoryResponseEventData.ts deleted file mode 100644 index fb342ce..0000000 --- a/src/api/types/ReceivableHistoryResponseEventData.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -/** - * An object containing additional information about the event or change. The object structure varies based on the `event_type`. In `receivable_created` and `receivable_updated` events, `event_data` is an empty object `{}`. - */ -export type ReceivableHistoryResponseEventData = - | Monite.StatusChangedEventData - | Monite.ReceivableUpdatedEventData - | Monite.ReceivableCreatedEventData - | Monite.BasedOnReceivableCreatedEventData - | Monite.PaymentReceivedEventData - | Monite.MailSentEventData - | Monite.ReminderMailSentEventData; diff --git a/src/api/types/ReceivableMailPaginationResponse.ts b/src/api/types/ReceivableMailPaginationResponse.ts index 6306576..c2e8042 100644 --- a/src/api/types/ReceivableMailPaginationResponse.ts +++ b/src/api/types/ReceivableMailPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableMailPaginationResponse { data: Monite.ReceivableMailResponse[]; diff --git a/src/api/types/ReceivableMailRecipients.ts b/src/api/types/ReceivableMailRecipients.ts index 96d1f0b..b6ffe24 100644 --- a/src/api/types/ReceivableMailRecipients.ts +++ b/src/api/types/ReceivableMailRecipients.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableMailRecipients { bcc?: Monite.ReceivableMailRecipientState[]; diff --git a/src/api/types/ReceivableMailResponse.ts b/src/api/types/ReceivableMailResponse.ts index 971f2ad..8344519 100644 --- a/src/api/types/ReceivableMailResponse.ts +++ b/src/api/types/ReceivableMailResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableMailResponse { id: string; diff --git a/src/api/types/ReceivablePaginationResponse.ts b/src/api/types/ReceivablePaginationResponse.ts index 1bba829..7ce61b8 100644 --- a/src/api/types/ReceivablePaginationResponse.ts +++ b/src/api/types/ReceivablePaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of receivables diff --git a/src/api/types/ReceivableRequiredFields.ts b/src/api/types/ReceivableRequiredFields.ts index a99516b..c10c284 100644 --- a/src/api/types/ReceivableRequiredFields.ts +++ b/src/api/types/ReceivableRequiredFields.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableRequiredFields { /** Object describing the required fields for counterpart */ diff --git a/src/api/types/ReceivableResponse.ts b/src/api/types/ReceivableResponse.ts index 5d9ee85..a903cfa 100644 --- a/src/api/types/ReceivableResponse.ts +++ b/src/api/types/ReceivableResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type ReceivableResponse = | Monite.ReceivableResponse.Quote diff --git a/src/api/types/ReceivableSettings.ts b/src/api/types/ReceivableSettings.ts index 321cd7f..e325007 100644 --- a/src/api/types/ReceivableSettings.ts +++ b/src/api/types/ReceivableSettings.ts @@ -3,6 +3,8 @@ */ export interface ReceivableSettings { + /** Unused. */ create_without_personal_info: boolean; + /** The title for the section in PDF invoices that contains [special deductions or incentives](https://docs.monite.com/accounts-receivable/special-deductions). If `null`, the title defaults to "Incentives" (localized). Custom title is not automatically localized. */ deduction_title?: string; } diff --git a/src/api/types/ReceivableTagCategory.ts b/src/api/types/ReceivableTagCategory.ts deleted file mode 100644 index daad0b7..0000000 --- a/src/api/types/ReceivableTagCategory.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type ReceivableTagCategory = - | "document_type" - | "department" - | "project" - | "cost_center" - | "vendor_type" - | "payment_method" - | "approval_status"; -export const ReceivableTagCategory = { - DocumentType: "document_type", - Department: "department", - Project: "project", - CostCenter: "cost_center", - VendorType: "vendor_type", - PaymentMethod: "payment_method", - ApprovalStatus: "approval_status", -} as const; diff --git a/src/api/types/ReceivableTemplatesVariablesObject.ts b/src/api/types/ReceivableTemplatesVariablesObject.ts index 9d7a5d3..715b4f0 100644 --- a/src/api/types/ReceivableTemplatesVariablesObject.ts +++ b/src/api/types/ReceivableTemplatesVariablesObject.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableTemplatesVariablesObject { object_subtype: Monite.VariablesType; diff --git a/src/api/types/ReceivableTemplatesVariablesObjectList.ts b/src/api/types/ReceivableTemplatesVariablesObjectList.ts index 420c6b4..a5a0b56 100644 --- a/src/api/types/ReceivableTemplatesVariablesObjectList.ts +++ b/src/api/types/ReceivableTemplatesVariablesObjectList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivableTemplatesVariablesObjectList { data: Monite.ReceivableTemplatesVariablesObject[]; diff --git a/src/api/types/ReceivableUpdatePayload.ts b/src/api/types/ReceivableUpdatePayload.ts index 4e6e53c..684faf9 100644 --- a/src/api/types/ReceivableUpdatePayload.ts +++ b/src/api/types/ReceivableUpdatePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type ReceivableUpdatePayload = | Monite.UpdateQuotePayload diff --git a/src/api/types/ReceivablesAnalyticsResponse.ts b/src/api/types/ReceivablesAnalyticsResponse.ts index 7a68a12..24b6bfd 100644 --- a/src/api/types/ReceivablesAnalyticsResponse.ts +++ b/src/api/types/ReceivablesAnalyticsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivablesAnalyticsResponse { data: Monite.ReceivablesAnalyticsDataPoint[]; diff --git a/src/api/types/ReceivablesCounterpartAddress.ts b/src/api/types/ReceivablesCounterpartAddress.ts index 86a053d..bddb1bf 100644 --- a/src/api/types/ReceivablesCounterpartAddress.ts +++ b/src/api/types/ReceivablesCounterpartAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Address information. diff --git a/src/api/types/ReceivablesRepresentationOfCounterpartAddress.ts b/src/api/types/ReceivablesRepresentationOfCounterpartAddress.ts index bcbd5f4..2235c1d 100644 --- a/src/api/types/ReceivablesRepresentationOfCounterpartAddress.ts +++ b/src/api/types/ReceivablesRepresentationOfCounterpartAddress.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ReceivablesRepresentationOfCounterpartAddress { /** Unique ID of the address in the system */ diff --git a/src/api/types/ReceivablesStatusEnum.ts b/src/api/types/ReceivablesStatusEnum.ts index 661aaf1..ba34196 100644 --- a/src/api/types/ReceivablesStatusEnum.ts +++ b/src/api/types/ReceivablesStatusEnum.ts @@ -2,6 +2,9 @@ * This file was auto-generated by Fern from our API Definition. */ +/** + * Invoice statuses (used in accounts receivable). + */ export type ReceivablesStatusEnum = | "draft" | "issuing" diff --git a/src/api/types/ReceivablesVerifyResponse.ts b/src/api/types/ReceivablesVerifyResponse.ts index f4de88d..72a8378 100644 --- a/src/api/types/ReceivablesVerifyResponse.ts +++ b/src/api/types/ReceivablesVerifyResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema for returning a response with validation results diff --git a/src/api/types/Recipient.ts b/src/api/types/Recipient.ts deleted file mode 100644 index 7439b70..0000000 --- a/src/api/types/Recipient.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface Recipient { - id: string; - type: Monite.RecipientType; -} diff --git a/src/api/types/RecipientAccountResponse.ts b/src/api/types/RecipientAccountResponse.ts index 57bd403..2b836a5 100644 --- a/src/api/types/RecipientAccountResponse.ts +++ b/src/api/types/RecipientAccountResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface RecipientAccountResponse { /** ID of a payment account */ diff --git a/src/api/types/RecipientType.ts b/src/api/types/RecipientType.ts deleted file mode 100644 index 8772f66..0000000 --- a/src/api/types/RecipientType.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type RecipientType = "entity" | "counterpart"; -export const RecipientType = { - Entity: "entity", - Counterpart: "counterpart", -} as const; diff --git a/src/api/types/Recurrence.ts b/src/api/types/Recurrence.ts deleted file mode 100644 index 3c74001..0000000 --- a/src/api/types/Recurrence.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface Recurrence { - id: string; - /** Time at which the receivable was created. Timestamps follow the ISO 8601 standard. */ - created_at: string; - /** Time at which the receivable was last updated. Timestamps follow the ISO 8601 standard. */ - updated_at: string; - /** - * Controls how invoices are processed when generated: - * - "draft": Creates invoices in draft status, requiring manual review, issuing, and sending - * - "issue": Automatically issues invoices but requires manual sending - * - "issue_and_send": Fully automates the process (creates, issues, and sends invoices) - * - * Default: "issue" (or "issue_and_send" if subject_text and body_text are provided) - * - * Note: When using "issue_and_send", both subject_text and body_text must be provided. - */ - automation_level: Monite.AutomationLevel; - body_text?: string; - current_iteration: number; - day_of_month: Monite.DayOfMonth; - end_month: number; - end_year: number; - invoice_id: string; - iterations: Monite.RecurrenceIteration[]; - recipients?: Monite.Recipients; - start_month: number; - start_year: number; - status: Monite.RecurrenceStatus; - subject_text?: string; -} diff --git a/src/api/types/RecurrenceFrequency.ts b/src/api/types/RecurrenceFrequency.ts new file mode 100644 index 0000000..0588105 --- /dev/null +++ b/src/api/types/RecurrenceFrequency.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type RecurrenceFrequency = "day" | "week" | "month" | "quarter" | "year"; +export const RecurrenceFrequency = { + Day: "day", + Week: "week", + Month: "month", + Quarter: "quarter", + Year: "year", +} as const; diff --git a/src/api/types/RecurrenceIteration.ts b/src/api/types/RecurrenceIteration.ts index f5f7eb9..056e9fb 100644 --- a/src/api/types/RecurrenceIteration.ts +++ b/src/api/types/RecurrenceIteration.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface RecurrenceIteration { issue_at: string; diff --git a/src/api/types/RecurrenceResponse.ts b/src/api/types/RecurrenceResponse.ts new file mode 100644 index 0000000..3fec6f4 --- /dev/null +++ b/src/api/types/RecurrenceResponse.ts @@ -0,0 +1,58 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface RecurrenceResponse { + id: string; + /** Time at which the recurrence was created. Timestamps follow the ISO 8601 standard. */ + created_at: string; + /** Time at which the recurrence was last updated. Timestamps follow the ISO 8601 standard. */ + updated_at: string; + /** + * Controls how invoices are processed when generated: + * - "draft": Creates invoices in draft status, requiring manual review, issuing, and sending + * - "issue": Automatically issues invoices but requires manual sending + * - "issue_and_send": Fully automates the process (creates, issues, and sends invoices) + * + * Default: "issue" (or "issue_and_send" if subject_text and body_text are provided) + * + * Note: When using "issue_and_send", both subject_text and body_text must be provided. + */ + automation_level: Monite.AutomationLevel; + /** The body text for the email that will be sent with the recurring invoice. */ + body_text?: string; + /** Current iteration number */ + current_iteration: number; + /** Deprecated, use `start_date` instead */ + day_of_month: Monite.DayOfMonth; + /** The end date of the recurring invoice, in the `yyyy-mm-dd` format. The end date is inclusive, that is, the last invoice will be created on this date if the last occurrence falls on this date. `end_date` is mutually exclusive with `max_occurrences`. Either `end_date` or `max_occurrences` must be specified. */ + end_date?: string; + /** Deprecated, use `end_date` instead */ + end_month?: number; + /** Deprecated, use `end_date` instead */ + end_year?: number; + /** How often the invoice will be created. */ + frequency: Monite.RecurrenceFrequency; + /** The interval between each occurrence of the invoice. For example, when using monthly frequency, an interval of 1 means invoices will be created every month, an interval of 2 means invoices will be created every 2 months. */ + interval: number; + /** ID of the base invoice that will be used as a template for creating recurring invoices. */ + invoice_id: string; + /** List of iterations for the recurrence */ + iterations: Monite.RecurrenceIteration[]; + /** How many times the recurring invoice will be created. The recurrence will stop after this number is reached. `max_occurrences` is mutually exclusive with `end_date`. Either `max_occurrences` or `end_date` must be specified. */ + max_occurrences?: number; + /** An object containing the recipients (To, CC, BCC) of the recurring invoices. Can be omitted if the base invoice has the counterpart contact email specified in the `counterpart_contact.email` field. */ + recipients?: Monite.Recipients; + /** The date when the first invoice will be created, in the `yyyy-mm-dd` format. Cannot be a past date. Subsequent invoice dates will be calculated based on `start_date`, `frequency`, and `interval`. */ + start_date: string; + /** Deprecated, use `start_date` instead */ + start_month: number; + /** Deprecated, use `start_date` instead */ + start_year: number; + /** Status of the recurrence */ + status: Monite.RecurrenceStatus; + /** The subject for the email that will be sent with the recurring invoice. */ + subject_text?: string; +} diff --git a/src/api/types/RecurrenceResponseList.ts b/src/api/types/RecurrenceResponseList.ts new file mode 100644 index 0000000..4933ee6 --- /dev/null +++ b/src/api/types/RecurrenceResponseList.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface RecurrenceResponseList { + data: Monite.RecurrenceResponse[]; +} diff --git a/src/api/types/RecurrenceStatus.ts b/src/api/types/RecurrenceStatus.ts index 2e3f108..4f37816 100644 --- a/src/api/types/RecurrenceStatus.ts +++ b/src/api/types/RecurrenceStatus.ts @@ -2,9 +2,20 @@ * This file was auto-generated by Fern from our API Definition. */ -export type RecurrenceStatus = "active" | "canceled" | "completed"; +/** + * Represents the status of a recurrence + * + * Allowed transitions: + * - active -> paused + * - active -> canceled + * - active -> completed + * - paused -> active + * - paused -> canceled + */ +export type RecurrenceStatus = "active" | "paused" | "canceled" | "completed"; export const RecurrenceStatus = { Active: "active", + Paused: "paused", Canceled: "canceled", Completed: "completed", } as const; diff --git a/src/api/types/RelatedDocuments.ts b/src/api/types/RelatedDocuments.ts index ef41169..32f13d7 100644 --- a/src/api/types/RelatedDocuments.ts +++ b/src/api/types/RelatedDocuments.ts @@ -3,6 +3,8 @@ */ export interface RelatedDocuments { + /** IDs of credit notes created from this invoice. The list includes both draft and issued credit notes. */ credit_note_ids?: string[]; + /** Unused. Always returns `null`. */ proforma_invoice_id?: string; } diff --git a/src/api/types/ReminderMailSentEventData.ts b/src/api/types/ReminderMailSentEventData.ts index 2d82a64..f9ba011 100644 --- a/src/api/types/ReminderMailSentEventData.ts +++ b/src/api/types/ReminderMailSentEventData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains information about an invoice reminder sent via email. diff --git a/src/api/types/RepaymentSchedule.ts b/src/api/types/RepaymentSchedule.ts index bec3a1b..c7d1a40 100644 --- a/src/api/types/RepaymentSchedule.ts +++ b/src/api/types/RepaymentSchedule.ts @@ -6,10 +6,10 @@ * Repayment schedule model */ export interface RepaymentSchedule { - /** Repayment date in ISO 8601 format */ - repayment_date: string; /** Repayment amount in minor units */ repayment_amount: number; + /** Repayment date in ISO 8601 format */ + repayment_date: string; /** Repayment fee amount in minor units */ repayment_fee_amount: number; /** Repayment principal amount in minor units */ diff --git a/src/api/types/ResponseItem.ts b/src/api/types/ResponseItem.ts index f3214cd..5d7fc9c 100644 --- a/src/api/types/ResponseItem.ts +++ b/src/api/types/ResponseItem.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface ResponseItem { /** The discount for a product. */ diff --git a/src/api/types/RolePaginationResponse.ts b/src/api/types/RolePaginationResponse.ts index 4a8773c..77533a4 100644 --- a/src/api/types/RolePaginationResponse.ts +++ b/src/api/types/RolePaginationResponse.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface RolePaginationResponse { /** array of records */ data: Monite.RoleResponse[]; - /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ - prev_pagination_token?: string; /** A token that can be sent in the `pagination_token` query parameter to get the next page of results, or `null` if there is no next page (i.e. you've reached the last page). */ next_pagination_token?: string; + /** A token that can be sent in the `pagination_token` query parameter to get the previous page of results, or `null` if there is no previous page (i.e. you've reached the first page). */ + prev_pagination_token?: string; } diff --git a/src/api/types/RoleResponse.ts b/src/api/types/RoleResponse.ts index 3c74819..3bdd440 100644 --- a/src/api/types/RoleResponse.ts +++ b/src/api/types/RoleResponse.ts @@ -2,19 +2,19 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface RoleResponse { /** UUID role ID */ id: string; + /** UTC datetime */ + created_at: string; + /** UTC datetime */ + updated_at: string; /** Role name */ name: string; /** Access permissions */ permissions: Monite.BizObjectsSchemaOutput; /** record status, 'active' by default */ status: Monite.StatusEnum; - /** UTC datetime */ - created_at: string; - /** UTC datetime */ - updated_at: string; } diff --git a/src/api/types/RootSchemaInput.ts b/src/api/types/RootSchemaInput.ts index 8d1cda4..2bb1e9f 100644 --- a/src/api/types/RootSchemaInput.ts +++ b/src/api/types/RootSchemaInput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type RootSchemaInput = | Monite.RootSchemaInput.ApprovalPolicy @@ -27,6 +27,7 @@ export type RootSchemaInput = | Monite.RootSchemaInput.Person | Monite.RootSchemaInput.Product | Monite.RootSchemaInput.Project + | Monite.RootSchemaInput.Receipt | Monite.RootSchemaInput.Receivable | Monite.RootSchemaInput.Reconciliation | Monite.RootSchemaInput.Role @@ -125,6 +126,10 @@ export namespace RootSchemaInput { object_type: "project"; } + export interface Receipt extends Monite.CommonSchemaInput { + object_type: "receipt"; + } + export interface Receivable extends Monite.CommonSchemaInput { object_type: "receivable"; } diff --git a/src/api/types/RootSchemaOutput.ts b/src/api/types/RootSchemaOutput.ts index cec2fb5..1293f0e 100644 --- a/src/api/types/RootSchemaOutput.ts +++ b/src/api/types/RootSchemaOutput.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type RootSchemaOutput = | Monite.RootSchemaOutput.ApprovalPolicy @@ -27,6 +27,7 @@ export type RootSchemaOutput = | Monite.RootSchemaOutput.Person | Monite.RootSchemaOutput.Product | Monite.RootSchemaOutput.Project + | Monite.RootSchemaOutput.Receipt | Monite.RootSchemaOutput.Receivable | Monite.RootSchemaOutput.Reconciliation | Monite.RootSchemaOutput.Role @@ -125,6 +126,10 @@ export namespace RootSchemaOutput { object_type: "project"; } + export interface Receipt extends Monite.CommonSchemaOutput { + object_type: "receipt"; + } + export interface Receivable extends Monite.CommonSchemaOutput { object_type: "receivable"; } diff --git a/src/api/types/SettingsResponse.ts b/src/api/types/SettingsResponse.ts index 0addc5f..1ff5ebc 100644 --- a/src/api/types/SettingsResponse.ts +++ b/src/api/types/SettingsResponse.ts @@ -2,37 +2,46 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SettingsResponse { - language?: Monite.LanguageCodeEnum; - currency?: Monite.CurrencySettingsOutput; - reminder?: Monite.RemindersSettings; - /** Defines whether the prices of products in receivables will already include VAT or not. */ - vat_mode?: Monite.VatModeEnum; - /** Defines whether the amount discounts (for percentage discounts it does not matter) on VAT inclusive invoices will be applied on amounts including VAT or excluding VAT. */ - vat_inclusive_discount_mode?: Monite.VatModeEnum; - /** Payment preferences for entity to automate calculating suggested payment date based on payment terms and entity preferences. */ - payment_priority?: Monite.PaymentPriorityEnum; + accounting?: Monite.AccountingSettings; /** Automatically attempt to find a corresponding purchase order for all incoming payables. */ allow_purchase_order_autolinking?: boolean; - receivable_edit_flow?: Monite.ReceivableEditFlow; + currency?: Monite.CurrencySettingsOutput; document_ids?: Monite.DocumentIDsSettings; - /** Auto tagging settings for all incoming OCR payable documents. */ - payables_ocr_auto_tagging?: Monite.OcrAutoTaggingSettingsRequest[]; - /** Sets the default behavior of whether a signature is required to accept quotes. */ - quote_signature_required?: boolean; + /** Settings for rendering documents in PDF format. */ + document_rendering?: Monite.DocumentRenderingSettingsOutput; /** - * This setting affects how PDF is generated for paid accounts receivable invoices. If set to `true`, once an invoice is fully paid its PDF version is updated to display the amount paid and the payment-related features are removed. + * This setting affects how PDF is generated for accounts receivable invoices that are paid, partially paid, or have credit notes applied. + * If this setting is `true`: * - * The PDF file gets regenerated at the moment when an invoice becomes paid. It is not issued as a separate document, and the original PDF invoice is no longer available. + * * The totals block in the PDF invoice will include a list of all payments made and credit notes issued. + * * Once an invoice becomes fully paid, the payment link and QR code are removed. * - * This field is deprecated and will be replaced by `document_rendering.invoice.generate_paid_invoice_pdf`. + * The PDF invoice gets regenerated at the moment when an invoice payment is recorded or a credit note is issued. This PDF is not issued as a separate document, and the original PDF invoice is no longer available. */ generate_paid_invoice_pdf?: boolean; - accounting?: Monite.AccountingSettings; + language?: Monite.LanguageCodeEnum; + /** Auto tagging settings for all incoming OCR payable documents. */ + payables_ocr_auto_tagging?: Monite.OcrAutoTaggingSettingsRequest[]; /** If enabled, the approval policy will be skipped and the payable will be moved to `waiting_to_be_paid` status. */ payables_skip_approval_flow?: boolean; - /** Settings for rendering documents in PDF format. */ - document_rendering?: Monite.DocumentRenderingSettings; + /** Payment preferences for entity to automate calculating suggested payment date based on payment terms and entity preferences. */ + payment_priority?: Monite.PaymentPriorityEnum; + /** Sets the default behavior of whether a signature is required to accept quotes. */ + quote_signature_required?: boolean; + /** + * [Invoice compliance mode](https://docs.monite.com/accounts-receivable/regulatory-compliance/invoice-compliance) for accounts receivable. Possible values: + * + * * `compliant` - invoices cannot be edited once issued. + * * `non_compliant` - issued invoices can still be edited. + * * `partially_compliant` - deprecated mode, should not be used. + */ + receivable_edit_flow?: Monite.ReceivableEditFlow; + reminder?: Monite.RemindersSettings; + /** Defines whether the amount discounts (for percentage discounts it does not matter) on VAT inclusive invoices will be applied on amounts including VAT or excluding VAT. */ + vat_inclusive_discount_mode?: Monite.VatModeEnum; + /** Defines whether the prices of products in receivables will already include VAT or not. */ + vat_mode?: Monite.VatModeEnum; } diff --git a/src/api/types/Signature.ts b/src/api/types/Signature.ts index d0b4370..1954ef8 100644 --- a/src/api/types/Signature.ts +++ b/src/api/types/Signature.ts @@ -3,10 +3,10 @@ */ export interface Signature { - /** The email of a person who signed a quote */ + /** The email of the person who signed the quote. */ email: string; - /** The full name of a person who signed a quote */ + /** The full name of the person who signed the quote. */ full_name: string; - /** Base64 encoded PNG image of a signature */ + /** Base64-encoded PNG image of the signature of the person who signed the quote. */ signature_image: string; } diff --git a/src/api/types/SingleOnboardingRequirementsResponse.ts b/src/api/types/SingleOnboardingRequirementsResponse.ts index 7b46e4e..3867e07 100644 --- a/src/api/types/SingleOnboardingRequirementsResponse.ts +++ b/src/api/types/SingleOnboardingRequirementsResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SingleOnboardingRequirementsResponse { disabled_reason?: string; diff --git a/src/api/types/SinglePaymentIntent.ts b/src/api/types/SinglePaymentIntent.ts deleted file mode 100644 index 8a8a0ff..0000000 --- a/src/api/types/SinglePaymentIntent.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface SinglePaymentIntent { - object: Monite.PaymentObjectPayable; - /** Must be provided if payable's document id is missing. */ - payment_reference?: string; - recipient: Monite.PaymentIntentsRecipient; -} diff --git a/src/api/types/SinglePaymentIntentResponse.ts b/src/api/types/SinglePaymentIntentResponse.ts deleted file mode 100644 index 28975a3..0000000 --- a/src/api/types/SinglePaymentIntentResponse.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface SinglePaymentIntentResponse { - id: string; - created_at: string; - amount: number; - currency: Monite.CurrencyEnum; - error?: Record; - object: Monite.PaymentObjectPayable; - payment_reference: string; - recipient: Monite.PaymentIntentsRecipient; - status: string; -} diff --git a/src/api/types/SourceOfReceiptDataEnum.ts b/src/api/types/SourceOfReceiptDataEnum.ts new file mode 100644 index 0000000..41e878c --- /dev/null +++ b/src/api/types/SourceOfReceiptDataEnum.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type SourceOfReceiptDataEnum = "ocr" | "user_specified"; +export const SourceOfReceiptDataEnum = { + Ocr: "ocr", + UserSpecified: "user_specified", +} as const; diff --git a/src/api/types/StatusChangedEventData.ts b/src/api/types/StatusChangedEventData.ts index 1f12b42..85a63d5 100644 --- a/src/api/types/StatusChangedEventData.ts +++ b/src/api/types/StatusChangedEventData.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Contains information about a document's status change. See the applicable diff --git a/src/api/types/SuggestedCounterpartPayload.ts b/src/api/types/SuggestedCounterpartPayload.ts new file mode 100644 index 0000000..0330934 --- /dev/null +++ b/src/api/types/SuggestedCounterpartPayload.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface SuggestedCounterpartPayload { + id: string; + address_id?: string; + bank_account_id?: string; + vat_id_id?: string; +} diff --git a/src/api/types/SuggestedResponse.ts b/src/api/types/SuggestedResponse.ts new file mode 100644 index 0000000..5c241a0 --- /dev/null +++ b/src/api/types/SuggestedResponse.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Monite from "../index.js"; + +export interface SuggestedResponse { + suggested_counterpart: Monite.SuggestedCounterpartPayload; +} diff --git a/src/api/types/SupportedFormatSchema.ts b/src/api/types/SupportedFormatSchema.ts index f52172f..e5d93a8 100644 --- a/src/api/types/SupportedFormatSchema.ts +++ b/src/api/types/SupportedFormatSchema.ts @@ -2,9 +2,17 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SupportedFormatSchema { available_types: Record; - object_type: Monite.SupportedFormatSchemaObjectType; + object_type: SupportedFormatSchema.ObjectType; +} + +export namespace SupportedFormatSchema { + export type ObjectType = "payable" | "receivable"; + export const ObjectType = { + Payable: "payable", + Receivable: "receivable", + } as const; } diff --git a/src/api/types/SupportedFormatSchemaObjectType.ts b/src/api/types/SupportedFormatSchemaObjectType.ts deleted file mode 100644 index 39472d5..0000000 --- a/src/api/types/SupportedFormatSchemaObjectType.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export type SupportedFormatSchemaObjectType = "payable" | "receivable"; -export const SupportedFormatSchemaObjectType = { - Payable: "payable", - Receivable: "receivable", -} as const; diff --git a/src/api/types/SyncRecordResource.ts b/src/api/types/SyncRecordResource.ts index 3b9cb16..3b63efe 100644 --- a/src/api/types/SyncRecordResource.ts +++ b/src/api/types/SyncRecordResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SyncRecordResource { id: string; @@ -10,14 +10,14 @@ export interface SyncRecordResource { updated_at: string; errors?: Record; last_pulled_at: string; - object_updated_at?: string; object_id?: string; + object_type: Monite.ObjectMatchTypes; + object_updated_at?: string; platform?: Monite.Platform; - platform_updated_at?: string; platform_object_id?: string; + platform_updated_at?: string; provider?: Monite.ServiceProvidersEnum; - provider_updated_at?: string; provider_object_id?: string; + provider_updated_at?: string; sync_status: Monite.SyncStatus; - object_type: Monite.ObjectMatchTypes; } diff --git a/src/api/types/SyncRecordResourceList.ts b/src/api/types/SyncRecordResourceList.ts index 2323d54..9780ca5 100644 --- a/src/api/types/SyncRecordResourceList.ts +++ b/src/api/types/SyncRecordResourceList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SyncRecordResourceList { data: Monite.SyncRecordResource[]; diff --git a/src/api/types/SystemTemplateDataSchema.ts b/src/api/types/SystemTemplateDataSchema.ts index e9e71be..5be2a56 100644 --- a/src/api/types/SystemTemplateDataSchema.ts +++ b/src/api/types/SystemTemplateDataSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SystemTemplateDataSchema { /** Array of templates */ diff --git a/src/api/types/SystemTemplates.ts b/src/api/types/SystemTemplates.ts index 68d1e54..4db97b6 100644 --- a/src/api/types/SystemTemplates.ts +++ b/src/api/types/SystemTemplates.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface SystemTemplates { /** All pre-defined email templates */ diff --git a/src/api/types/TagReadSchema.ts b/src/api/types/TagReadSchema.ts index 84b3225..8656771 100644 --- a/src/api/types/TagReadSchema.ts +++ b/src/api/types/TagReadSchema.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Represents a user-defined tag that can be assigned to resources to filter them. @@ -15,7 +15,7 @@ export interface TagReadSchema { /** Date and time when the tag was last updated. Timestamps follow the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard. */ updated_at: string; /** The tag category. */ - category?: Monite.ReceivableTagCategory; + category?: Monite.TagCategory; /** ID of the user who created the tag. */ created_by_entity_user_id?: string; /** The tag description. */ diff --git a/src/api/types/TagsPaginationResponse.ts b/src/api/types/TagsPaginationResponse.ts index 5c69adb..1ac72d0 100644 --- a/src/api/types/TagsPaginationResponse.ts +++ b/src/api/types/TagsPaginationResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A paginated list of tags. diff --git a/src/api/types/TemplateListResponse.ts b/src/api/types/TemplateListResponse.ts index 26793ba..b75a292 100644 --- a/src/api/types/TemplateListResponse.ts +++ b/src/api/types/TemplateListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface TemplateListResponse { data?: Monite.TemplateReceivableResponse[]; diff --git a/src/api/types/TemplateReceivableResponse.ts b/src/api/types/TemplateReceivableResponse.ts index 6130eff..3e25424 100644 --- a/src/api/types/TemplateReceivableResponse.ts +++ b/src/api/types/TemplateReceivableResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface TemplateReceivableResponse { id: string; diff --git a/src/api/types/PaymentTermDiscount.ts b/src/api/types/TermDiscountDays.ts similarity index 87% rename from src/api/types/PaymentTermDiscount.ts rename to src/api/types/TermDiscountDays.ts index 144ac72..9f9be5e 100644 --- a/src/api/types/PaymentTermDiscount.ts +++ b/src/api/types/TermDiscountDays.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface PaymentTermDiscount { +export interface TermDiscountDays { /** The discount percentage in minor units. E.g., 200 means 2%. 1050 means 10.5%. */ discount: number; /** The amount of days after the invoice issue date. */ diff --git a/src/api/types/PaymentTerm.ts b/src/api/types/TermFinalDays.ts similarity index 83% rename from src/api/types/PaymentTerm.ts rename to src/api/types/TermFinalDays.ts index d748266..39403a9 100644 --- a/src/api/types/PaymentTerm.ts +++ b/src/api/types/TermFinalDays.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -export interface PaymentTerm { +export interface TermFinalDays { /** The amount of days after the invoice issue date. */ number_of_days: number; } diff --git a/src/api/types/TextTemplateResponse.ts b/src/api/types/TextTemplateResponse.ts index 90bdb4e..16e97d5 100644 --- a/src/api/types/TextTemplateResponse.ts +++ b/src/api/types/TextTemplateResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface TextTemplateResponse { id: string; diff --git a/src/api/types/TextTemplateResponseList.ts b/src/api/types/TextTemplateResponseList.ts index 0670eeb..1ceaa87 100644 --- a/src/api/types/TextTemplateResponseList.ts +++ b/src/api/types/TextTemplateResponseList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface TextTemplateResponseList { data: Monite.TextTemplateResponse[]; diff --git a/src/api/types/TotalVatAmountItem.ts b/src/api/types/TotalVatAmountItem.ts index eaf4900..01a48d9 100644 --- a/src/api/types/TotalVatAmountItem.ts +++ b/src/api/types/TotalVatAmountItem.ts @@ -2,10 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ +import * as Monite from "../index.js"; + export interface TotalVatAmountItem { id?: string; /** The total VAT of all line items, in [minor units](https://docs.monite.com/references/currencies#minor-units). */ amount: number; + /** Sub-taxes included in the VAT. */ + components?: Monite.TotalVatAmountItemComponent[]; + /** Display name of the vat rate. */ + name?: string; /** The amount on which this VAT is calculated, in [minor units](https://docs.monite.com/references/currencies#minor-units). */ taxable_amount: number; /** Percent minor units. Example: 12.5% is 1250. */ diff --git a/src/api/types/TotalVatAmountItemComponent.ts b/src/api/types/TotalVatAmountItemComponent.ts new file mode 100644 index 0000000..9bc9130 --- /dev/null +++ b/src/api/types/TotalVatAmountItemComponent.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface TotalVatAmountItemComponent { + /** The total VAT of all line items, in [minor units](https://docs.monite.com/references/currencies#minor-units). */ + amount: number; + name: string; + /** Percent minor units. Example: 12.5% is 1250. */ + value: number; +} diff --git a/src/api/types/UnitListResponse.ts b/src/api/types/UnitListResponse.ts index c5be817..c0de371 100644 --- a/src/api/types/UnitListResponse.ts +++ b/src/api/types/UnitListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UnitListResponse { data: Monite.UnitResponse[]; diff --git a/src/api/types/UpdateCreditNote.ts b/src/api/types/UpdateCreditNote.ts index cb9b64a..e1f046e 100644 --- a/src/api/types/UpdateCreditNote.ts +++ b/src/api/types/UpdateCreditNote.ts @@ -2,24 +2,36 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateCreditNote { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; /** Address of invoicing, need to state as a separate fields for some countries if it differs from address of a company. */ counterpart_billing_address_id?: string; /** Additional information about counterpart contacts. */ counterpart_contact?: Monite.ReceivableCounterpartContact; /** Address where goods were shipped / where services were provided. */ counterpart_shipping_address_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; entity?: Monite.ReceivableEntityBase; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; line_items?: Monite.UpdateLineItemForCreditNote; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; /** Metadata for partner needs */ partner_metadata?: Record; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this credit note. If specified, the project name will be included in the header of the PDF credit note. */ project_id?: string; /** A list of IDs of user-defined tags (labels) assigned to this receivable. */ tag_ids?: string[]; diff --git a/src/api/types/UpdateCreditNotePayload.ts b/src/api/types/UpdateCreditNotePayload.ts index a5c2666..fcd0c35 100644 --- a/src/api/types/UpdateCreditNotePayload.ts +++ b/src/api/types/UpdateCreditNotePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateCreditNotePayload { credit_note: Monite.UpdateCreditNote; diff --git a/src/api/types/UpdateEinvoicingAddress.ts b/src/api/types/UpdateEinvoicingAddress.ts new file mode 100644 index 0000000..da86614 --- /dev/null +++ b/src/api/types/UpdateEinvoicingAddress.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface UpdateEinvoicingAddress { + /** Street address line 1 */ + address_line1: string; + /** Street address line 2 */ + address_line2?: string; + /** City name */ + city: string; + /** Postal/ZIP code */ + postal_code: string; + /** State/Province/County */ + state?: string; +} diff --git a/src/api/types/UpdateEntityRequest.ts b/src/api/types/UpdateEntityRequest.ts index c302c23..7f233d9 100644 --- a/src/api/types/UpdateEntityRequest.ts +++ b/src/api/types/UpdateEntityRequest.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * A schema for a request to update an entity @@ -12,18 +12,18 @@ export interface UpdateEntityRequest { address?: Monite.UpdateEntityAddressSchema; /** An official email address of the entity */ email?: string; + /** A set of meta data describing the individual */ + individual?: Monite.OptionalIndividualSchema; + /** A set of meta data describing the organization */ + organization?: Monite.OptionalOrganizationSchema; /** The contact phone number of the entity. Required for US organizations to use payments. */ phone?: string; - /** A website of the entity */ - website?: string; - /** The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered. */ - tax_id?: string; - /** (Germany only) The entity's commercial register number (_Handelsregisternummer_) in the German Commercial Register, if available. */ - registration_number?: string; /** (Germany only) The name of the local district court (_Amtsgericht_) where the entity is registered. Required if `registration_number` is provided. */ registration_authority?: string; - /** A set of meta data describing the organization */ - organization?: Monite.OptionalOrganizationSchema; - /** A set of meta data describing the individual */ - individual?: Monite.OptionalIndividualSchema; + /** (Germany only) The entity's commercial register number (_Handelsregisternummer_) in the German Commercial Register, if available. */ + registration_number?: string; + /** The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered. */ + tax_id?: string; + /** A website of the entity */ + website?: string; } diff --git a/src/api/types/UpdateInvoice.ts b/src/api/types/UpdateInvoice.ts index 3dd952a..d5a6d14 100644 --- a/src/api/types/UpdateInvoice.ts +++ b/src/api/types/UpdateInvoice.ts @@ -2,9 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateInvoice { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; /** Unique ID of the counterpart contact. */ contact_id?: string; /** Address of invoicing, need to state as a separate fields for some countries if it differs from address of a company. */ @@ -24,12 +26,18 @@ export interface UpdateInvoice { deduction_memo?: string; /** The discount for a receivable. */ discount?: Monite.Discount; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; entity?: Monite.ReceivableEntityBase; /** Entity bank account ID */ entity_bank_account_id?: string; /** Entity VAT ID id */ entity_vat_id_id?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; /** * The date when the goods are shipped or the service is provided. Can be a current, past, or future date. @@ -42,7 +50,11 @@ export interface UpdateInvoice { /** Is this Invoice will be sent through E-invoice system */ is_einvoice?: boolean; line_items?: Monite.LineItemUpdate[]; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; /** E-invoicing network credentials ID of the entity */ network_credentials_id?: string; @@ -52,9 +64,10 @@ export interface UpdateInvoice { /** Link to your invoice's custom payment rails or external payment link. */ payment_page_url?: string; payment_reminder_id?: string; + payment_terms?: Monite.InlinePaymentTermsRequestPayload; /** Unique ID of the payment terms. */ payment_terms_id?: string; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this invoice. If specified, the project name will be included in the header of the PDF invoice. */ project_id?: string; /** A list of IDs of user-defined tags (labels) assigned to this receivable. */ tag_ids?: string[]; diff --git a/src/api/types/UpdateInvoicePayload.ts b/src/api/types/UpdateInvoicePayload.ts index 8e0431a..a25f9a8 100644 --- a/src/api/types/UpdateInvoicePayload.ts +++ b/src/api/types/UpdateInvoicePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateInvoicePayload { invoice: Monite.UpdateInvoice; diff --git a/src/api/types/UpdateIssuedInvoice.ts b/src/api/types/UpdateIssuedInvoice.ts index 5659415..2c51ea9 100644 --- a/src/api/types/UpdateIssuedInvoice.ts +++ b/src/api/types/UpdateIssuedInvoice.ts @@ -2,22 +2,30 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateIssuedInvoice { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; /** Unique ID of the counterpart contact. */ contact_id?: string; /** Id of a new or updated counterpart */ counterpart_id?: string; /** Counterpart VAT ID id */ counterpart_vat_id_id?: string; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; /** The date by which the invoice must be paid. */ due_date?: string; entity?: Monite.UpdateIssuedInvoiceEntity; entity_address?: Monite.ReceivableEntityAddressSchema; /** Entity VAT ID id */ entity_vat_id_id?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; /** * The date when the goods are shipped or the service is provided. Can be a current, past, or future date. @@ -29,14 +37,19 @@ export interface UpdateIssuedInvoice { fulfillment_date?: string; /** The datetime when the invoice was issued */ issue_date?: string; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; overdue_reminder_id?: string; /** Metadata for partner needs */ partner_metadata?: Record; payment_reminder_id?: string; + payment_terms?: Monite.InlinePaymentTermsRequestPayload; payment_terms_id?: string; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this invoice. If specified, the project name will be included in the header of the PDF invoice. */ project_id?: string; /** A list of IDs of user-defined tags (labels) assigned to this receivable. */ tag_ids?: string[]; diff --git a/src/api/types/UpdateIssuedInvoiceEntity.ts b/src/api/types/UpdateIssuedInvoiceEntity.ts index e1ff9a9..e39ce15 100644 --- a/src/api/types/UpdateIssuedInvoiceEntity.ts +++ b/src/api/types/UpdateIssuedInvoiceEntity.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export type UpdateIssuedInvoiceEntity = | Monite.UpdateIssuedInvoiceEntity.Organization diff --git a/src/api/types/UpdateIssuedInvoicePayload.ts b/src/api/types/UpdateIssuedInvoicePayload.ts index 74d4533..025e28c 100644 --- a/src/api/types/UpdateIssuedInvoicePayload.ts +++ b/src/api/types/UpdateIssuedInvoicePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateIssuedInvoicePayload { issued_invoice: Monite.UpdateIssuedInvoice; diff --git a/src/api/types/UpdateLineItemForCreditNote.ts b/src/api/types/UpdateLineItemForCreditNote.ts index 242ace7..41c4aef 100644 --- a/src/api/types/UpdateLineItemForCreditNote.ts +++ b/src/api/types/UpdateLineItemForCreditNote.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; /** * Line item with given product id can be changed only once diff --git a/src/api/types/UpdateQuote.ts b/src/api/types/UpdateQuote.ts index 2b6d1fd..fab4b01 100644 --- a/src/api/types/UpdateQuote.ts +++ b/src/api/types/UpdateQuote.ts @@ -2,9 +2,11 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateQuote { + /** List of attachments to include with the receivable. Each attachment can be configured for email inclusion. If not provided, no attachments will be associated. */ + attachments?: Monite.AttachmentRequest[]; /** Unique ID of the counterpart contact. */ contact_id?: string; /** Address of invoicing, need to state as a separate fields for some countries if it differs from address of a company. */ @@ -22,6 +24,8 @@ export interface UpdateQuote { deduction_memo?: string; /** The discount for a receivable. */ discount?: Monite.Discount; + /** Settings for rendering documents in PDF format, including settings for line items and specific document types. */ + document_rendering?: Monite.DocumentRenderingSettings; entity?: Monite.ReceivableEntityBase; /** Entity bank account ID */ entity_bank_account_id?: string; @@ -29,16 +33,25 @@ export interface UpdateQuote { entity_vat_id_id?: string; /** The date (in ISO 8601 format) until which the quote is valid. */ expiry_date?: string; - /** Optional text displayed below the line items table in the PDF. */ + /** + * Optional text displayed below the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `memo`, `commercial_condition_description`. + */ footer?: string; line_items?: Monite.LineItemUpdate[]; - /** A note with additional information for a receivable */ + /** + * An optional note for the customer that will be displayed above the line items table in the PDF. The text can include [variables](https://docs.monite.com/advanced/variables). + * + * See also: `footer`, `commercial_condition_description`. + */ memo?: string; /** Metadata for partner needs */ partner_metadata?: Record; + payment_terms?: Monite.InlinePaymentTermsRequestPayload; /** Unique ID of the payment terms. */ payment_terms_id?: string; - /** A project related to current receivable */ + /** ID of the [project](https://docs.monite.com/common/projects) associated with this quote. If specified, the project name will be included in the header of the PDF quote. */ project_id?: string; /** Link for custom quote accept page */ quote_accept_page_url?: string; diff --git a/src/api/types/UpdateQuotePayload.ts b/src/api/types/UpdateQuotePayload.ts index ebf5ccd..127968e 100644 --- a/src/api/types/UpdateQuotePayload.ts +++ b/src/api/types/UpdateQuotePayload.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface UpdateQuotePayload { quote: Monite.UpdateQuote; diff --git a/src/api/types/ValidationError.ts b/src/api/types/ValidationError.ts index 9e72e4d..1c398a1 100644 --- a/src/api/types/ValidationError.ts +++ b/src/api/types/ValidationError.ts @@ -2,10 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; - export interface ValidationError { - loc: Monite.ValidationErrorLocItem[]; + loc: ValidationError.Loc.Item[]; msg: string; type: string; } + +export namespace ValidationError { + export type Loc = Loc.Item[]; + + export namespace Loc { + export type Item = string | number; + } +} diff --git a/src/api/types/VariablesObject.ts b/src/api/types/VariablesObject.ts index 7e23ea4..998ed81 100644 --- a/src/api/types/VariablesObject.ts +++ b/src/api/types/VariablesObject.ts @@ -2,10 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface VariablesObject { - object_subtype: Monite.OcrDocumentTypeEnum; + object_subtype: Monite.DocumentTypeEnum; object_type: string; variables: Monite.Variable[]; } diff --git a/src/api/types/VariablesObjectList.ts b/src/api/types/VariablesObjectList.ts index bac4133..29e80ef 100644 --- a/src/api/types/VariablesObjectList.ts +++ b/src/api/types/VariablesObjectList.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface VariablesObjectList { data: Monite.VariablesObject[]; diff --git a/src/api/types/VatRateComponent.ts b/src/api/types/VatRateComponent.ts new file mode 100644 index 0000000..fd9493a --- /dev/null +++ b/src/api/types/VatRateComponent.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface VatRateComponent { + /** Display name of the Tax. */ + name: string; + /** Percent multiplied by a 100. Example: 12.125% is 1212.5. Will be rounded to 2 decimal places */ + value: number; +} diff --git a/src/api/types/VatRateListResponse.ts b/src/api/types/VatRateListResponse.ts index f9d0e14..4d4683f 100644 --- a/src/api/types/VatRateListResponse.ts +++ b/src/api/types/VatRateListResponse.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface VatRateListResponse { data: Monite.VatRateResponse[]; diff --git a/src/api/types/VatRateResponse.ts b/src/api/types/VatRateResponse.ts index 920c656..8b425ec 100644 --- a/src/api/types/VatRateResponse.ts +++ b/src/api/types/VatRateResponse.ts @@ -2,18 +2,20 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface VatRateResponse { - /** Unique identifier of the vat rate object. */ + /** A unique ID assigned to this VAT rate. Use this ID as the value of the `line_items[].vat_rate_id` field in invoices and quotes. */ id: string; - /** Date/time when this rate was recorded in the table. */ + /** UTC date and time when this VAT rate was recorded in Monite. */ created_at: string; - /** Date/time when this rate was updated in the table. */ + /** UTC date and time when this VAT rate was last updated by Monite. */ updated_at: string; + /** Sub-taxes included in the VAT. */ + components?: Monite.VatRateComponent[]; /** Two-letter ISO country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). */ country: Monite.AllowedCountries; - /** By whom this rate was recorded: monite employee | accounting system. */ + /** Unused. */ created_by?: Monite.VatRateCreator; /** Status for this vat rate: active | inactive. */ status?: Monite.VatRateStatusEnum; @@ -21,6 +23,6 @@ export interface VatRateResponse { valid_from?: string; /** Date when this rate was depreciated, after this date rate cannot be used. */ valid_until?: string; - /** Percent minor units. Example: 12.5% is 1250. */ + /** VAT percentage multiplied by 100. For example, 12.5% is represented as 1250. */ value: number; } diff --git a/src/api/types/VerificationAirwallexPlaidRequest.ts b/src/api/types/VerificationAirwallexPlaidRequest.ts deleted file mode 100644 index b2c0c53..0000000 --- a/src/api/types/VerificationAirwallexPlaidRequest.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface VerificationAirwallexPlaidRequest { - /** The name of your application to be displayed in Plaid Modal */ - client_name: string; - /** The name of the Link customization configured on the Plaid Dashboard. If not specified, the default customization will be applied */ - link_customization_name?: string; - /** URL to handle the OAuth verification flow */ - redirect_url: string; -} diff --git a/src/api/types/VerificationAirwallexPlaidResponse.ts b/src/api/types/VerificationAirwallexPlaidResponse.ts deleted file mode 100644 index b2053b9..0000000 --- a/src/api/types/VerificationAirwallexPlaidResponse.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface VerificationAirwallexPlaidResponse { - /** Client name from the request */ - client_name: string; - expires_at: string; - /** Customization name from the request */ - link_customization_name?: string; - /** Link token that should be used to init Plaid SDK */ - link_token: string; - /** URL from the request */ - redirect_url: string; -} diff --git a/src/api/types/VerificationRequest.ts b/src/api/types/VerificationRequest.ts deleted file mode 100644 index 7281029..0000000 --- a/src/api/types/VerificationRequest.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface VerificationRequest { - airwallex_plaid: Monite.VerificationAirwallexPlaidRequest; - type: Monite.BankAccountVerificationType; -} diff --git a/src/api/types/VerificationResponse.ts b/src/api/types/VerificationResponse.ts deleted file mode 100644 index 4f7f7e3..0000000 --- a/src/api/types/VerificationResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as Monite from "../index"; - -export interface VerificationResponse { - airwallex_plaid: Monite.VerificationAirwallexPlaidResponse; - type: Monite.BankAccountVerificationType; -} diff --git a/src/api/types/WebhookDeliveryPaginationResource.ts b/src/api/types/WebhookDeliveryPaginationResource.ts index 4f3133b..a9649d7 100644 --- a/src/api/types/WebhookDeliveryPaginationResource.ts +++ b/src/api/types/WebhookDeliveryPaginationResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface WebhookDeliveryPaginationResource { /** A set of webhooks returned per page */ diff --git a/src/api/types/WebhookObjectType.ts b/src/api/types/WebhookObjectType.ts index a225acb..4b4eef1 100644 --- a/src/api/types/WebhookObjectType.ts +++ b/src/api/types/WebhookObjectType.ts @@ -42,7 +42,8 @@ export type WebhookObjectType = | "workflow" | "workflow_pipeline" | "ocr_task" - | "delivery_note"; + | "delivery_note" + | "receipt"; export const WebhookObjectType = { Account: "account", AccountingConnection: "accounting_connection", @@ -84,4 +85,5 @@ export const WebhookObjectType = { WorkflowPipeline: "workflow_pipeline", OcrTask: "ocr_task", DeliveryNote: "delivery_note", + Receipt: "receipt", } as const; diff --git a/src/api/types/WebhookSubscriptionPaginationResource.ts b/src/api/types/WebhookSubscriptionPaginationResource.ts index c129d98..5f2b02a 100644 --- a/src/api/types/WebhookSubscriptionPaginationResource.ts +++ b/src/api/types/WebhookSubscriptionPaginationResource.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface WebhookSubscriptionPaginationResource { /** A set of webhook settings of different types returned per page */ diff --git a/src/api/types/WebhookSubscriptionResource.ts b/src/api/types/WebhookSubscriptionResource.ts index 06e1d2d..bc7f04a 100644 --- a/src/api/types/WebhookSubscriptionResource.ts +++ b/src/api/types/WebhookSubscriptionResource.ts @@ -2,12 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface WebhookSubscriptionResource { + /** A unique URL assigned to this webhook subscription. This ID is also included in the webhook data as the `webhook_subscription_id` field. */ id: string; + /** [Events](https://docs.monite.com/references/webhooks/index#events) included in this webhook subscription. An empty array means the subscription includes all events triggered by the specified `object_type`. */ event_types: string[]; + /** The object type associated with this webhook subscription. */ object_type: Monite.WebhookObjectType; status: Monite.WebhookSubscriptionStatus; + /** URL to which the webhooks are sent. The same URL can be used by multiple webhook subscriptions. */ url: string; } diff --git a/src/api/types/WebhookSubscriptionResourceWithSecret.ts b/src/api/types/WebhookSubscriptionResourceWithSecret.ts index c720c69..320ec35 100644 --- a/src/api/types/WebhookSubscriptionResourceWithSecret.ts +++ b/src/api/types/WebhookSubscriptionResourceWithSecret.ts @@ -2,13 +2,18 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Monite from "../index"; +import * as Monite from "../index.js"; export interface WebhookSubscriptionResourceWithSecret { + /** A unique URL assigned to this webhook subscription. This ID is also included in the webhook data as the `webhook_subscription_id` field. */ id: string; + /** [Events](https://docs.monite.com/references/webhooks/index#events) included in this webhook subscription. An empty array means the subscription includes all events triggered by the specified `object_type`. */ event_types: string[]; + /** The object type associated with this webhook subscription. */ object_type: Monite.WebhookObjectType; + /** The webhook signing secret for this subscriptions. You can use it to [verify webhook signatures](https://docs.monite.com/references/webhooks/signatures). */ secret: string; status: Monite.WebhookSubscriptionStatus; + /** URL to which the webhooks are sent. The same URL can be used by multiple webhook subscriptions. */ url: string; } diff --git a/src/api/types/index.ts b/src/api/types/index.ts index ad49eef..5187bb8 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -1,612 +1,603 @@ -export * from "./ApiVersion"; -export * from "./AccessTokenResponse"; -export * from "./AccountDisabledReason"; -export * from "./AccountingConnectionList"; -export * from "./AccountingConnectionResponse"; -export * from "./AccountingCustomerRefObject"; -export * from "./AccountingLineItem"; -export * from "./AccountingMessageResponse"; -export * from "./AccountingPayableDueDate"; -export * from "./AccountingPayable"; -export * from "./AccountingPayableList"; -export * from "./AccountingPurchaseOrderRef"; -export * from "./AccountingReceivableDueDate"; -export * from "./AccountingReceivable"; -export * from "./AccountingReceivableList"; -export * from "./AccountingRefObject"; -export * from "./AccountingSettings"; -export * from "./AccountingTaxRateListResponse"; -export * from "./AccountingTaxRateResponse"; -export * from "./AccountingVendorRefObject"; -export * from "./ActionEnum"; -export * from "./ActionSchema"; -export * from "./AggregationFunctionEnum"; -export * from "./AirwallexMandate"; -export * from "./AirwallexMandateType"; -export * from "./AirwallexMandateVersion"; -export * from "./AirwallexPlaidAccount"; -export * from "./AirwallexPlaidBankAccountVerificationStatus"; -export * from "./AirwallexPlaidInstitution"; -export * from "./AirwallexPlaidVerification"; -export * from "./AllDocumentExportResponseSchema"; -export * from "./AllOverdueRemindersResponse"; -export * from "./AllowedCountries"; -export * from "./AllowedEinvoicingCountryCodes"; -export * from "./AllowedFileTypes"; -export * from "./AnalyticsDataPoint"; -export * from "./ApprovalPolicyCursorFields"; -export * from "./ApprovalPolicyResourceScriptItem"; -export * from "./ApprovalPolicyResourceStatus"; -export * from "./ApprovalPolicyResourceTrigger"; -export * from "./ApprovalPolicyResource"; -export * from "./ApprovalPolicyResourceList"; -export * from "./ApprovalPolicyStatus"; -export * from "./ApprovalProcessResourceList"; -export * from "./ApprovalProcessStepResource"; -export * from "./ApprovalProcessStepResourceList"; -export * from "./ApprovalProcessStepStatus"; -export * from "./ApprovalRequestCreateByRoleRequest"; -export * from "./ApprovalRequestCreateByUserRequest"; -export * from "./ApprovalRequestCreateRequest"; -export * from "./ApprovalRequestCursorFields"; -export * from "./ApprovalRequestResourceList"; -export * from "./ApprovalRequestResourceWithMetadata"; -export * from "./ApprovalRequestStatus"; -export * from "./AutomationLevel"; -export * from "./BankAccount"; -export * from "./BankAccountVerificationType"; -export * from "./BankAccountVerifications"; -export * from "./BasedOnReceivableCreatedEventData"; -export * from "./BasedOnTransitionType"; -export * from "./BizObjectsSchemaInput"; -export * from "./BizObjectsSchemaOutput"; -export * from "./BusinessInfoSchema"; -export * from "./BusinessProfileInput"; -export * from "./BusinessProfileOutput"; -export * from "./ButtonTheme"; -export * from "./CardTheme"; -export * from "./CommentCursorFields"; -export * from "./CommentResource"; -export * from "./CommentResourceList"; -export * from "./CommonSchemaInput"; -export * from "./CommonSchemaOutput"; -export * from "./CompleteRefreshVerificationRequest"; -export * from "./CompleteRefreshVerificationResponse"; -export * from "./CompleteVerificationAirwallexPlaidRequest"; -export * from "./CompleteVerificationRequest"; -export * from "./CompleteVerificationResponse"; -export * from "./ConnectionStatus"; -export * from "./CounterpartAddress"; -export * from "./CounterpartAddressResourceList"; -export * from "./CounterpartAddressResponseWithCounterpartId"; -export * from "./CounterpartBankAccountResourceList"; -export * from "./CounterpartBankAccountResponse"; -export * from "./CounterpartContactResponse"; -export * from "./CounterpartContactsResourceList"; -export * from "./CounterpartCreatePayload"; -export * from "./CounterpartCursorFields"; -export * from "./CounterpartEinvoicingCredentialResponse"; -export * from "./CounterpartEinvoicingCredentialResponseList"; -export * from "./CounterpartEinvoicingCredentialSchema"; -export * from "./CounterpartFields"; -export * from "./CounterpartIndividualCreatePayload"; -export * from "./CounterpartIndividualResponse"; -export * from "./CounterpartIndividualRootCreatePayload"; -export * from "./CounterpartIndividualRootResponse"; -export * from "./CounterpartIndividualRootUpdatePayload"; -export * from "./CounterpartIndividualUpdatePayload"; -export * from "./CounterpartOrganizationCreatePayload"; -export * from "./CounterpartOrganizationResponse"; -export * from "./CounterpartOrganizationRootCreatePayload"; -export * from "./CounterpartOrganizationRootResponse"; -export * from "./CounterpartOrganizationRootUpdatePayload"; -export * from "./CounterpartOrganizationUpdatePayload"; -export * from "./CounterpartPaginationResponse"; -export * from "./CounterpartRawAddress"; -export * from "./CounterpartRawAddressUpdateRequest"; -export * from "./CounterpartRawBankAccount"; -export * from "./CounterpartRawBankAccountUpdateRequest"; -export * from "./CounterpartRawData"; -export * from "./CounterpartRawDataUpdateRequest"; -export * from "./CounterpartRawVatId"; -export * from "./CounterpartRawVatIdUpdateRequest"; -export * from "./CounterpartResponse"; -export * from "./CounterpartTagCategory"; -export * from "./CounterpartTagSchema"; -export * from "./CounterpartType"; -export * from "./CounterpartUpdatePayload"; -export * from "./CounterpartVatIdResourceList"; -export * from "./CounterpartVatIdResponse"; -export * from "./CreateCounterpartEinvoicingCredentialCounterpartVatId"; -export * from "./CreateCounterpartEinvoicingCredentialPayload"; -export * from "./CreateExportTaskResponseSchema"; -export * from "./CreateOnboardingLinkRequest"; -export * from "./CreditNoteCursorFields"; -export * from "./CreditNoteDimensionEnum"; -export * from "./CreditNoteFieldsAllowedForValidate"; -export * from "./CreditNoteLineItemCreateRequest"; -export * from "./CreditNoteLineItemCursorFields"; -export * from "./CreditNoteLineItemPaginationResponse"; -export * from "./CreditNoteLineItemResponse"; -export * from "./CreditNoteMetricEnum"; -export * from "./CreditNotePaginationResponse"; -export * from "./CreditNoteRenderingSettings"; -export * from "./CreditNoteResponse"; -export * from "./CreditNoteResponsePayloadEntity"; -export * from "./CreditNoteResponsePayload"; -export * from "./CreditNoteStateEnum"; -export * from "./CreditNoteValidationResponse"; -export * from "./CreditNoteValidationsResource"; -export * from "./CurrencyEnum"; -export * from "./CurrencyExchangeSchema"; -export * from "./CurrencyExchangeSchema2"; -export * from "./CurrencySettingsInput"; -export * from "./CurrencySettingsOutput"; -export * from "./CursorFields"; -export * from "./CustomTemplateDataSchema"; -export * from "./CustomTemplatesCursorFields"; -export * from "./CustomTemplatesPaginationResponse"; -export * from "./DnsRecord"; -export * from "./DnsRecordPurpose"; -export * from "./DnsRecordType"; -export * from "./DnsRecords"; -export * from "./DataExportCursorFields"; -export * from "./DateDimensionBreakdownEnum"; -export * from "./DayOfMonth"; -export * from "./DefaultAccountingTaxIDs"; -export * from "./DefaultLedgerAccountIDs"; -export * from "./DeliveryNoteCounterpartResource"; -export * from "./DeliveryNoteCreateBasedOnRequest"; -export * from "./DeliveryNoteCreateLineItem"; -export * from "./DeliveryNoteCreateRequest"; -export * from "./DeliveryNoteCursorFields"; -export * from "./DeliveryNoteLineItemProduct"; -export * from "./DeliveryNoteLineItemResource"; -export * from "./DeliveryNoteResourceEntity"; -export * from "./DeliveryNoteResource"; -export * from "./DeliveryNoteResourceList"; -export * from "./DeliveryNoteStatusEnum"; -export * from "./Discount"; -export * from "./DiscountType"; -export * from "./DocumentExportResponseSchema"; -export * from "./DocumentIdSeparators"; -export * from "./DocumentIDsSettings"; -export * from "./DocumentIDsSettingsNextNumber"; -export * from "./DocumentIDsSettingsRequest"; -export * from "./DocumentObjectTypeRequestEnum"; -export * from "./DocumentRenderingSettings"; -export * from "./DocumentTypeEnum"; -export * from "./DocumentTypePrefix"; -export * from "./DomainListResponse"; -export * from "./DomainResponseDnsRecords"; -export * from "./DomainResponse"; -export * from "./EInvoicingRetrieveListData"; -export * from "./EinvoiceSchemaTypeEnum"; -export * from "./EinvoicingAddress"; -export * from "./EinvoicingConnectionResponse"; -export * from "./EinvoicingCredentials"; -export * from "./EinvoicingNetworkCredentialsResponse"; -export * from "./EntityAddressResponseSchema"; -export * from "./EntityAddressSchema"; -export * from "./EntityBankAccountPaginationResponse"; -export * from "./EntityBankAccountResponse"; -export * from "./EntityBusinessStructure"; -export * from "./EntityCursorFields"; -export * from "./EntityFields"; -export * from "./EntityIndividualResponse"; -export * from "./EntityOnboardingDataResponse"; -export * from "./EntityOnboardingDocuments"; -export * from "./EntityOrganizationResponse"; -export * from "./EntityPaginationResponse"; -export * from "./EntityResponse"; -export * from "./EntityStatusEnum"; -export * from "./EntityTypeEnum"; -export * from "./EntityUserCursorFields"; -export * from "./EntityUserPaginationResponse"; -export * from "./EntityUserResponse"; -export * from "./EntityVatIdResourceList"; -export * from "./EntityVatIdResponse"; -export * from "./ErrorSchema"; -export * from "./ErrorSchema2"; -export * from "./ErrorSchemaResponse"; -export * from "./ErrorSchemaResponse2"; -export * from "./EstimatedMonthlyRevenue"; -export * from "./EventCursorFields"; -export * from "./EventPaginationResource"; -export * from "./EventResource"; -export * from "./EventResourceForWebhookClient"; -export * from "./ExchangeRate"; -export * from "./ExportFormat"; -export * from "./ExportObjectSchema"; -export * from "./ExportPayableSchema"; -export * from "./ExportReceivableSchema"; -export * from "./ExportSettingCursorFields"; -export * from "./ExtraDataResource"; -export * from "./ExtraDataResourceList"; -export * from "./FieldSchema"; -export * from "./FileResponse"; -export * from "./FileSchema"; -export * from "./FileSchema2"; -export * from "./FileSchema3"; -export * from "./FilesResponse"; -export * from "./FinancingInvoice"; -export * from "./FinancingInvoiceCursorFields"; -export * from "./FinancingInvoiceListResponse"; -export * from "./FinancingInvoiceType"; -export * from "./FinancingOffer"; -export * from "./FinancingOffersResponse"; -export * from "./FinancingPushInvoicesRequestInvoice"; -export * from "./FinancingPushInvoicesResponse"; -export * from "./FinancingTokenResponse"; -export * from "./GetAllPaymentReminders"; -export * from "./GetAllRecurrences"; -export * from "./GetOnboardingRequirementsResponse"; -export * from "./GrantType"; -export * from "./HttpValidationError"; -export * from "./IndividualResponseSchema"; -export * from "./IndividualSchema"; -export * from "./Invoice"; -export * from "./InvoiceFile"; -export * from "./InvoiceRenderingSettings"; -export * from "./InvoiceResponsePayloadEntity"; -export * from "./InvoiceResponsePayload"; -export * from "./Item"; -export * from "./IterationStatus"; -export * from "./LabelNValue"; -export * from "./LanguageCodeEnum"; -export * from "./LedgerAccountCursorFields"; -export * from "./LedgerAccountListResponse"; -export * from "./LedgerAccountResponse"; -export * from "./LineItem"; -export * from "./LineItemCursorFields"; -export * from "./LineItemFields"; -export * from "./LineItemInternalRequest"; -export * from "./LineItemPaginationResponse"; -export * from "./LineItemProduct"; -export * from "./LineItemProductCreate"; -export * from "./LineItemProductMeasureUnit"; -export * from "./LineItemProductVatRate"; -export * from "./LineItemRequest"; -export * from "./LineItemResponse"; -export * from "./LineItemUpdate"; -export * from "./LineItemsReplaceResponse"; -export * from "./LineItemsResponse"; -export * from "./MailSentEventData"; -export * from "./MailSettings"; -export * from "./MailboxDataResponse"; -export * from "./MailboxObjectTypeEnum"; -export * from "./MailboxResponse"; -export * from "./MessageResponse"; -export * from "./MissingFields"; -export * from "./MissingLineItemFields"; -export * from "./MoniteAllPaymentMethods"; -export * from "./MoniteAllPaymentMethodsTypes"; -export * from "./OcrAddress"; -export * from "./OcrAddressDetails"; -export * from "./OcrBankDetails"; -export * from "./OcrCounterpartDetails"; -export * from "./OcrCreditNote"; -export * from "./OcrDocumentTypeEnum"; -export * from "./OcrInvoice"; -export * from "./OcrLineItem"; -export * from "./OcrReceipt"; -export * from "./OcrReceiptLineItem"; -export * from "./OcrResponseInvoiceReceiptData"; -export * from "./OcrResponseInvoiceReceiptLineItemRaw"; -export * from "./OcrTaskStatus"; -export * from "./OcrTasksPaginationResponse"; -export * from "./ObjectMatchTypes"; -export * from "./ObjectType"; -export * from "./ObjectTypeAvailableComment"; -export * from "./ObjectTypeEnum"; -export * from "./OcrAutoTaggingSettingsRequest"; -export * from "./OcrRecognitionResponse"; -export * from "./OcrStatusEnum"; -export * from "./OcrTaskResponseSchemaRecognizedData"; -export * from "./OcrTaskResponseSchema"; -export * from "./OnboardingLinkPublicResponse"; -export * from "./OnboardingLinkRequest"; -export * from "./OnboardingLinkResponse"; -export * from "./OnboardingPaymentMethodsResponse"; -export * from "./OnboardingRequirementsError"; -export * from "./OnboardingRequirementsResponse"; -export * from "./OnboardingVerificationError"; -export * from "./OnboardingVerificationStatusEnum"; -export * from "./OptionalIndividualSchema"; -export * from "./OptionalOrganizationSchema"; -export * from "./OptionalPersonAddressRequest"; -export * from "./OptionalPersonRelationship"; -export * from "./OrderEnum"; -export * from "./OrganizationResponseSchema"; -export * from "./OrganizationSchema"; -export * from "./OriginEnum"; -export * from "./OverdueReminderResponse"; -export * from "./OverdueReminderTerm"; -export * from "./OwnershipDeclarationInput"; -export * from "./OwnershipDeclarationOutput"; -export * from "./PageSchema"; -export * from "./PageSchema2"; -export * from "./PageSchema3"; -export * from "./PartnerMetadata"; -export * from "./PartnerMetadataResponse"; -export * from "./PartnerProjectSettingsPayloadOutput"; -export * from "./PayableActionEnum"; -export * from "./PayableActionSchema"; -export * from "./PayableAggregatedDataResponse"; -export * from "./PayableAggregatedItem"; -export * from "./PayableAnalyticsResponse"; -export * from "./PayableCreditNoteData"; -export * from "./PayableCreditNoteStateEnum"; -export * from "./PayableCursorFields"; -export * from "./PayableDimensionEnum"; -export * from "./PayableEntityAddressSchema"; -export * from "./PayableEntityIndividualResponse"; -export * from "./PayableEntityOrganizationResponse"; -export * from "./PayableIndividualSchema"; -export * from "./PayableMetricEnum"; -export * from "./PayableOrganizationSchema"; -export * from "./PayableOriginEnum"; -export * from "./PayablePaginationResponse"; -export * from "./PayablePaymentTermDiscount"; -export * from "./PayablePaymentTermFinal"; -export * from "./PayablePaymentTermsCreatePayload"; -export * from "./PayableResponseSchemaOtherExtractedData"; -export * from "./PayableResponseSchema"; -export * from "./PayableSchemaInput"; -export * from "./PayableSchemaOutput"; -export * from "./PayableSettings"; -export * from "./PayableStateEnum"; -export * from "./PayableTemplatesVariable"; -export * from "./PayableTemplatesVariablesObject"; -export * from "./PayableTemplatesVariablesObjectList"; -export * from "./PayableValidationResponse"; -export * from "./PayableValidationsResource"; -export * from "./PayablesFieldsAllowedForValidate"; -export * from "./PayablesVariableType"; -export * from "./PayerAccountResponse"; -export * from "./PaymentAccountObject"; -export * from "./PaymentAccountType"; -export * from "./PaymentIntent"; -export * from "./PaymentIntentCursorFields"; -export * from "./PaymentIntentHistory"; -export * from "./PaymentIntentHistoryResponse"; -export * from "./PaymentIntentPayoutMethod"; -export * from "./PaymentIntentResponse"; -export * from "./PaymentIntentsListResponse"; -export * from "./PaymentIntentsRecipient"; -export * from "./PaymentMethod"; -export * from "./PaymentMethodDirection"; -export * from "./PaymentMethodRequirements"; -export * from "./PaymentMethodStatus"; -export * from "./PaymentObject"; -export * from "./PaymentObjectPayable"; -export * from "./PaymentObjectType"; -export * from "./PaymentPageTheme"; -export * from "./PaymentPriorityEnum"; -export * from "./PaymentReceivedEventData"; -export * from "./PaymentRecordCursorFields"; -export * from "./PaymentRecordObjectRequest"; -export * from "./PaymentRecordObjectResponse"; -export * from "./PaymentRecordResponse"; -export * from "./PaymentRecordResponseList"; -export * from "./PaymentRecordStatusEnum"; -export * from "./PaymentRecordStatusUpdateRequest"; -export * from "./PaymentReminderResponse"; -export * from "./PaymentRequirements"; -export * from "./PaymentTerm"; -export * from "./PaymentTermDiscount"; -export * from "./PaymentTermDiscountWithDate"; -export * from "./PaymentTerms"; -export * from "./PaymentTermsListResponse"; -export * from "./PaymentTermsResponse"; -export * from "./PaymentsBatchPaymentRequest"; -export * from "./PaymentsBatchPaymentResponse"; -export * from "./PaymentsBatchPaymentStatus"; -export * from "./PaymentsSettingsInput"; -export * from "./PaymentsSettingsOutput"; -export * from "./PermissionEnum"; -export * from "./PersonAddressRequest"; -export * from "./PersonAddressResponse"; -export * from "./PersonOnboardingDocuments"; -export * from "./PersonRelationshipRequest"; -export * from "./PersonRelationshipResponse"; -export * from "./PersonResponse"; -export * from "./PersonsResponse"; -export * from "./Platform"; -export * from "./PreviewSchema"; -export * from "./PreviewSchema2"; -export * from "./PreviewSchema3"; -export * from "./PreviewTemplateResponse"; -export * from "./Price"; -export * from "./PricingPlan"; -export * from "./ProcessResourceScriptSnapshot"; -export * from "./ProcessResource"; -export * from "./ProcessStatusEnum"; -export * from "./ProductCursorFields"; -export * from "./ProductServicePaginationResponse"; -export * from "./ProductServiceResponse"; -export * from "./ProductServiceTypeEnum"; -export * from "./ProjectCursorFields"; -export * from "./ProjectPaginationResponse"; -export * from "./ProjectResource"; -export * from "./PublicPaymentLinkResponse"; -export * from "./PurchaseOrderCounterpartAddressSchema"; -export * from "./PurchaseOrderCounterpartIndividualResponse"; -export * from "./PurchaseOrderCounterpartIndividualRootResponse"; -export * from "./PurchaseOrderCounterpartOrganizationResponse"; -export * from "./PurchaseOrderCounterpartOrganizationRootResponse"; -export * from "./PurchaseOrderCounterpartSchema"; -export * from "./PurchaseOrderCursorFields"; -export * from "./PurchaseOrderEmailPreviewResponse"; -export * from "./PurchaseOrderEmailSentResponse"; -export * from "./PurchaseOrderItem"; -export * from "./PurchaseOrderPaginationResponse"; -export * from "./PurchaseOrderResponseSchemaEntity"; -export * from "./PurchaseOrderResponseSchema"; -export * from "./PurchaseOrderStatusEnum"; -export * from "./PurchaseOrderVatId"; -export * from "./QuoteRenderingSettings"; -export * from "./QuoteResponsePayloadEntity"; -export * from "./QuoteResponsePayload"; -export * from "./QuoteStateEnum"; -export * from "./ReceivableCounterpartContact"; -export * from "./ReceivableCounterpartType"; -export * from "./ReceivableCounterpartVatIdResponse"; -export * from "./ReceivableCreateBasedOnPayload"; -export * from "./ReceivableCreatedEventData"; -export * from "./ReceivableCursorFields"; -export * from "./ReceivableDimensionEnum"; -export * from "./ReceivableEditFlow"; -export * from "./ReceivableEntityAddressSchema"; -export * from "./ReceivableEntityBase"; -export * from "./ReceivableEntityIndividual"; -export * from "./ReceivableEntityIndividualRequest"; -export * from "./ReceivableEntityOrganization"; -export * from "./ReceivableEntityOrganizationRequest"; -export * from "./ReceivableEntityVatIdResponse"; -export * from "./ReceivableFacadeCreateInvoicePayload"; -export * from "./ReceivableFacadeCreatePayload"; -export * from "./ReceivableFacadeCreateQuotePayload"; -export * from "./ReceivableFileUrl"; -export * from "./ReceivableHistoryCursorFields"; -export * from "./ReceivableHistoryEventTypeEnum"; -export * from "./ReceivableHistoryPaginationResponse"; -export * from "./ReceivableHistoryResponseEventData"; -export * from "./ReceivableHistoryResponse"; -export * from "./ReceivableMailCursorFields"; -export * from "./ReceivableMailPaginationResponse"; -export * from "./ReceivableMailRecipientState"; -export * from "./ReceivableMailRecipients"; -export * from "./ReceivableMailResponse"; -export * from "./ReceivableMailStatusEnum"; -export * from "./ReceivableMetricEnum"; -export * from "./ReceivablePaginationResponse"; -export * from "./ReceivablePreviewResponse"; -export * from "./ReceivableRequiredFields"; -export * from "./ReceivableResponse"; -export * from "./ReceivableSendResponse"; -export * from "./ReceivableSettings"; -export * from "./ReceivableTagCategory"; -export * from "./ReceivableTemplatesVariable"; -export * from "./ReceivableTemplatesVariablesObject"; -export * from "./ReceivableTemplatesVariablesObjectList"; -export * from "./ReceivableType"; -export * from "./ReceivableUpdatePayload"; -export * from "./ReceivableUpdatedEventData"; -export * from "./ReceivablesAnalyticsDataPoint"; -export * from "./ReceivablesAnalyticsResponse"; -export * from "./ReceivablesCounterpartAddress"; -export * from "./ReceivablesPreviewTypeEnum"; -export * from "./ReceivablesRemindersWarningMessage"; -export * from "./ReceivablesRepresentationOfCounterpartAddress"; -export * from "./ReceivablesRepresentationOfEntityBankAccount"; -export * from "./ReceivablesSendResponse"; -export * from "./ReceivablesStatusEnum"; -export * from "./ReceivablesVerifyResponse"; -export * from "./Recipient"; -export * from "./RecipientAccountResponse"; -export * from "./RecipientType"; -export * from "./Recipients"; -export * from "./Recurrence"; -export * from "./RecurrenceIteration"; -export * from "./RecurrenceStatus"; -export * from "./RelatedDocuments"; -export * from "./Reminder"; -export * from "./ReminderMailSentEventData"; -export * from "./ReminderTypeEnum"; -export * from "./RemindersSettings"; -export * from "./RepaymentSchedule"; -export * from "./RequirementsError"; -export * from "./ResponseItem"; -export * from "./RoleCursorFields"; -export * from "./RolePaginationResponse"; -export * from "./RoleResponse"; -export * from "./RootSchemaInput"; -export * from "./RootSchemaOutput"; -export * from "./ServiceProvidersEnum"; -export * from "./SettingsResponse"; -export * from "./Signature"; -export * from "./SingleOnboardingRequirementsResponse"; -export * from "./SinglePaymentIntent"; -export * from "./SinglePaymentIntentResponse"; -export * from "./SourceOfPayableDataEnum"; -export * from "./StatusChangedEventData"; -export * from "./StatusEnum"; -export * from "./SuccessResult"; -export * from "./SuggestedPaymentTerm"; -export * from "./SupportedFieldNames"; -export * from "./SupportedFormatSchemaObjectType"; -export * from "./SupportedFormatSchema"; -export * from "./SyncRecordCursorFields"; -export * from "./SyncRecordResource"; -export * from "./SyncRecordResourceList"; -export * from "./SyncStatus"; -export * from "./SystemTemplateDataSchema"; -export * from "./SystemTemplates"; -export * from "./TagCategory"; -export * from "./TagCursorFields"; -export * from "./TagReadSchema"; -export * from "./TagsPaginationResponse"; -export * from "./TaxComponentResponse"; -export * from "./TaxRateAccountCursorFields"; -export * from "./TemplateDataSchema"; -export * from "./TemplateListResponse"; -export * from "./TemplateReceivableResponse"; -export * from "./TemplateTypeEnum"; -export * from "./TermFinalWithDate"; -export * from "./TermsOfServiceAcceptanceInput"; -export * from "./TermsOfServiceAcceptanceOutput"; -export * from "./TextTemplateDocumentTypeEnum"; -export * from "./TextTemplateResponse"; -export * from "./TextTemplateResponseList"; -export * from "./TextTemplateType"; -export * from "./TotalVatAmountItem"; -export * from "./Unit"; -export * from "./UnitListResponse"; -export * from "./UnitRequest"; -export * from "./UnitResponse"; -export * from "./UpdateCreditNote"; -export * from "./UpdateCreditNotePayload"; -export * from "./UpdateEntityAddressSchema"; -export * from "./UpdateEntityRequest"; -export * from "./UpdateInvoice"; -export * from "./UpdateInvoicePayload"; -export * from "./UpdateIssuedInvoiceEntity"; -export * from "./UpdateIssuedInvoice"; -export * from "./UpdateIssuedInvoicePayload"; -export * from "./UpdateLineItemForCreditNote"; -export * from "./UpdateProductForCreditNote"; -export * from "./UpdateQuote"; -export * from "./UpdateQuotePayload"; -export * from "./ValidationErrorLocItem"; -export * from "./ValidationError"; -export * from "./Variable"; -export * from "./VariablesObject"; -export * from "./VariablesObjectList"; -export * from "./VariablesType"; -export * from "./VatIdTypeEnum"; -export * from "./VatModeEnum"; -export * from "./VatRateCreator"; -export * from "./VatRateListResponse"; -export * from "./VatRateResponse"; -export * from "./VatRateStatusEnum"; -export * from "./VerificationAirwallexPlaidRequest"; -export * from "./VerificationAirwallexPlaidResponse"; -export * from "./VerificationError"; -export * from "./VerificationRequest"; -export * from "./VerificationResponse"; -export * from "./VerificationStatusEnum"; -export * from "./VerifyResponse"; -export * from "./WcBusinessStatus"; -export * from "./WcInvoiceStatus"; -export * from "./WcOfferStatus"; -export * from "./WcRepaymentType"; -export * from "./WebhookDeliveryCursorFields"; -export * from "./WebhookDeliveryPaginationResource"; -export * from "./WebhookDeliveryResource"; -export * from "./WebhookObjectType"; -export * from "./WebhookSubscriptionCursorFields"; -export * from "./WebhookSubscriptionPaginationResource"; -export * from "./WebhookSubscriptionResource"; -export * from "./WebhookSubscriptionResourceWithSecret"; -export * from "./WebhookSubscriptionStatus"; +export * from "./ApiVersion.js"; +export * from "./AccessTokenResponse.js"; +export * from "./AccountDisabledReason.js"; +export * from "./AccountingConnectionList.js"; +export * from "./AccountingConnectionResponse.js"; +export * from "./AccountingCustomerRefObject.js"; +export * from "./AccountingLineItem.js"; +export * from "./AccountingMessageResponse.js"; +export * from "./AccountingPayable.js"; +export * from "./AccountingPayableList.js"; +export * from "./AccountingPurchaseOrderRef.js"; +export * from "./AccountingReceivable.js"; +export * from "./AccountingReceivableList.js"; +export * from "./AccountingRefObject.js"; +export * from "./AccountingSettings.js"; +export * from "./AccountingTaxRateListResponse.js"; +export * from "./AccountingTaxRateResponse.js"; +export * from "./AccountingVendorRefObject.js"; +export * from "./ActionEnum.js"; +export * from "./ActionSchema.js"; +export * from "./AggregationFunctionEnum.js"; +export * from "./AllDocumentExportResponseSchema.js"; +export * from "./AllOverdueRemindersResponse.js"; +export * from "./AllowedCountries.js"; +export * from "./AllowedEinvoicingCountryCodes.js"; +export * from "./AllowedFileTypes.js"; +export * from "./AnalyticsDataPoint.js"; +export * from "./ApprovalPolicyCursorFields.js"; +export * from "./ApprovalPolicyResource.js"; +export * from "./ApprovalPolicyResourceList.js"; +export * from "./ApprovalPolicyStatus.js"; +export * from "./ApprovalProcessResourceList.js"; +export * from "./ApprovalProcessStepResource.js"; +export * from "./ApprovalProcessStepResourceList.js"; +export * from "./ApprovalProcessStepStatus.js"; +export * from "./ApprovalRequestCreateByRoleRequest.js"; +export * from "./ApprovalRequestCreateByUserRequest.js"; +export * from "./ApprovalRequestCreateRequest.js"; +export * from "./ApprovalRequestCursorFields.js"; +export * from "./ApprovalRequestResourceList.js"; +export * from "./ApprovalRequestResourceWithMetadata.js"; +export * from "./ApprovalRequestStatus.js"; +export * from "./AttachmentRequest.js"; +export * from "./AttachmentResponse.js"; +export * from "./AutomationLevel.js"; +export * from "./BankAccount.js"; +export * from "./BasedOnReceivableCreatedEventData.js"; +export * from "./BasedOnTransitionType.js"; +export * from "./BizObjectsSchemaInput.js"; +export * from "./BizObjectsSchemaOutput.js"; +export * from "./BusinessInfoSchema.js"; +export * from "./BusinessProfileInput.js"; +export * from "./BusinessProfileOutput.js"; +export * from "./ButtonTheme.js"; +export * from "./CardTheme.js"; +export * from "./CommentCursorFields.js"; +export * from "./CommentResource.js"; +export * from "./CommentResourceList.js"; +export * from "./CommonSchemaInput.js"; +export * from "./CommonSchemaOutput.js"; +export * from "./ConnectionStatus.js"; +export * from "./CounterpartAddress.js"; +export * from "./CounterpartAddressResourceList.js"; +export * from "./CounterpartAddressResponseWithCounterpartId.js"; +export * from "./CounterpartBankAccountResourceList.js"; +export * from "./CounterpartBankAccountResponse.js"; +export * from "./CounterpartContactResponse.js"; +export * from "./CounterpartContactsResourceList.js"; +export * from "./CounterpartCreatePayload.js"; +export * from "./CounterpartCursorFields.js"; +export * from "./CounterpartEinvoicingCredentialExistenceResponse.js"; +export * from "./CounterpartEinvoicingCredentialResponse.js"; +export * from "./CounterpartEinvoicingCredentialResponseList.js"; +export * from "./CounterpartEinvoicingCredentialSchema.js"; +export * from "./CounterpartFields.js"; +export * from "./CounterpartIndividualCreatePayload.js"; +export * from "./CounterpartIndividualResponse.js"; +export * from "./CounterpartIndividualRootCreatePayload.js"; +export * from "./CounterpartIndividualRootResponse.js"; +export * from "./CounterpartIndividualRootUpdatePayload.js"; +export * from "./CounterpartIndividualUpdatePayload.js"; +export * from "./CounterpartOrganizationCreatePayload.js"; +export * from "./CounterpartOrganizationResponse.js"; +export * from "./CounterpartOrganizationRootCreatePayload.js"; +export * from "./CounterpartOrganizationRootResponse.js"; +export * from "./CounterpartOrganizationRootUpdatePayload.js"; +export * from "./CounterpartOrganizationUpdatePayload.js"; +export * from "./CounterpartPaginationResponse.js"; +export * from "./CounterpartRawAddress.js"; +export * from "./CounterpartRawAddressUpdateRequest.js"; +export * from "./CounterpartRawBankAccount.js"; +export * from "./CounterpartRawBankAccountUpdateRequest.js"; +export * from "./CounterpartRawData.js"; +export * from "./CounterpartRawDataUpdateRequest.js"; +export * from "./CounterpartRawVatId.js"; +export * from "./CounterpartRawVatIdUpdateRequest.js"; +export * from "./CounterpartResponse.js"; +export * from "./CounterpartTagSchema.js"; +export * from "./CounterpartType.js"; +export * from "./CounterpartUpdatePayload.js"; +export * from "./CounterpartVatIdResourceList.js"; +export * from "./CounterpartVatIdResponse.js"; +export * from "./CreateCounterpartEinvoicingCredentialCounterpartVatId.js"; +export * from "./CreateCounterpartEinvoicingCredentialPayload.js"; +export * from "./CreateExportTaskResponseSchema.js"; +export * from "./CreditNoteCursorFields.js"; +export * from "./CreditNoteDimensionEnum.js"; +export * from "./CreditNoteFieldsAllowedForValidate.js"; +export * from "./CreditNoteLineItemCreateRequest.js"; +export * from "./CreditNoteLineItemCursorFields.js"; +export * from "./CreditNoteLineItemPaginationResponse.js"; +export * from "./CreditNoteLineItemResponse.js"; +export * from "./CreditNoteMetricEnum.js"; +export * from "./CreditNotePaginationResponse.js"; +export * from "./CreditNoteRenderingSettings.js"; +export * from "./CreditNoteResponse.js"; +export * from "./CreditNoteResponsePayloadEntity.js"; +export * from "./CreditNoteResponsePayload.js"; +export * from "./CreditNoteStateEnum.js"; +export * from "./CreditNoteValidationResponse.js"; +export * from "./CreditNoteValidationsResource.js"; +export * from "./CurrencyEnum.js"; +export * from "./CurrencyExchangeSchema.js"; +export * from "./CurrencyExchangeSchema2.js"; +export * from "./CurrencySettingsInput.js"; +export * from "./CurrencySettingsOutput.js"; +export * from "./CursorFields.js"; +export * from "./CustomTemplateDataSchema.js"; +export * from "./CustomTemplatesCursorFields.js"; +export * from "./CustomTemplatesPaginationResponse.js"; +export * from "./CustomVatRateResponse.js"; +export * from "./CustomVatRateResponseList.js"; +export * from "./DnsRecord.js"; +export * from "./DnsRecordPurpose.js"; +export * from "./DnsRecordType.js"; +export * from "./DnsRecords.js"; +export * from "./DataExportCursorFields.js"; +export * from "./DateDimensionBreakdownEnum.js"; +export * from "./DayOfMonth.js"; +export * from "./DefaultAccountingTaxIDs.js"; +export * from "./DefaultLedgerAccountIDs.js"; +export * from "./DeliveryNoteCounterpartResource.js"; +export * from "./DeliveryNoteCreateBasedOnRequest.js"; +export * from "./DeliveryNoteCreateLineItem.js"; +export * from "./DeliveryNoteCreateRequest.js"; +export * from "./DeliveryNoteCursorFields.js"; +export * from "./DeliveryNoteLineItemProduct.js"; +export * from "./DeliveryNoteLineItemResource.js"; +export * from "./DeliveryNoteResourceEntity.js"; +export * from "./DeliveryNoteResource.js"; +export * from "./DeliveryNoteResourceList.js"; +export * from "./DeliveryNoteStatusEnum.js"; +export * from "./Discount.js"; +export * from "./DiscountResponse.js"; +export * from "./DiscountType.js"; +export * from "./DocumentExportResponseSchema.js"; +export * from "./DocumentIdSeparators.js"; +export * from "./DocumentIDsSettings.js"; +export * from "./DocumentIDsSettingsNextNumber.js"; +export * from "./DocumentIDsSettingsRequest.js"; +export * from "./DocumentObjectTypeRequestEnum.js"; +export * from "./DocumentRenderingSettings.js"; +export * from "./DocumentRenderingSettingsInput.js"; +export * from "./DocumentRenderingSettingsOutput.js"; +export * from "./DocumentTypeEnum.js"; +export * from "./DocumentTypePrefix.js"; +export * from "./DomainListResponse.js"; +export * from "./DomainResponse.js"; +export * from "./EInvoicingRetrieveListData.js"; +export * from "./EinvoiceSchemaTypeEnum.js"; +export * from "./EinvoicingAddress.js"; +export * from "./EinvoicingConnectionResponse.js"; +export * from "./EinvoicingCredentials.js"; +export * from "./EinvoicingNetworkCredentialsResponse.js"; +export * from "./EntityAddressResponseSchema.js"; +export * from "./EntityAddressSchema.js"; +export * from "./EntityBankAccountPaginationResponse.js"; +export * from "./EntityBankAccountResponse.js"; +export * from "./EntityBusinessStructure.js"; +export * from "./EntityCursorFields.js"; +export * from "./EntityFields.js"; +export * from "./EntityIndividualResponse.js"; +export * from "./EntityOnboardingDataResponse.js"; +export * from "./EntityOnboardingDocuments.js"; +export * from "./EntityOrganizationResponse.js"; +export * from "./EntityPaginationResponse.js"; +export * from "./EntityResponse.js"; +export * from "./EntityStatusEnum.js"; +export * from "./EntityTypeEnum.js"; +export * from "./EntityUserCursorFields.js"; +export * from "./EntityUserPaginationResponse.js"; +export * from "./EntityUserResponse.js"; +export * from "./EntityVatIdResourceList.js"; +export * from "./EntityVatIdResponse.js"; +export * from "./ErrorSchema.js"; +export * from "./ErrorSchema2.js"; +export * from "./ErrorSchemaResponse.js"; +export * from "./ErrorSchemaResponse2.js"; +export * from "./EstimatedMonthlyRevenue.js"; +export * from "./EventCursorFields.js"; +export * from "./EventPaginationResource.js"; +export * from "./EventResource.js"; +export * from "./EventResourceForWebhookClient.js"; +export * from "./ExchangeRate.js"; +export * from "./ExportFormat.js"; +export * from "./ExportObjectSchema.js"; +export * from "./ExportPayableSchema.js"; +export * from "./ExportReceivableSchema.js"; +export * from "./ExportSettingCursorFields.js"; +export * from "./ExtraDataResource.js"; +export * from "./ExtraDataResourceList.js"; +export * from "./FieldSchema.js"; +export * from "./FileAttachedEventData.js"; +export * from "./FileResponse.js"; +export * from "./FileSchema.js"; +export * from "./FileSchema2.js"; +export * from "./FileSchema3.js"; +export * from "./FilesResponse.js"; +export * from "./FinancingInvoice.js"; +export * from "./FinancingInvoiceCursorFields.js"; +export * from "./FinancingInvoiceListResponse.js"; +export * from "./FinancingInvoiceType.js"; +export * from "./FinancingOffer.js"; +export * from "./FinancingOffersResponse.js"; +export * from "./FinancingPushInvoicesRequestInvoice.js"; +export * from "./FinancingPushInvoicesResponse.js"; +export * from "./FinancingTokenResponse.js"; +export * from "./GetAllPaymentReminders.js"; +export * from "./GetOnboardingRequirementsResponse.js"; +export * from "./GrantType.js"; +export * from "./HttpValidationError.js"; +export * from "./IndividualResponseSchema.js"; +export * from "./IndividualSchema.js"; +export * from "./InlinePaymentTermsRequestPayload.js"; +export * from "./InlineTermDiscount.js"; +export * from "./InlineTermFinal.js"; +export * from "./Invoice.js"; +export * from "./InvoiceFile.js"; +export * from "./InvoiceRenderingSettings.js"; +export * from "./InvoiceResponsePayloadEntity.js"; +export * from "./InvoiceResponsePayload.js"; +export * from "./Item.js"; +export * from "./IterationStatus.js"; +export * from "./LabelNValue.js"; +export * from "./LanguageCodeEnum.js"; +export * from "./LedgerAccountCursorFields.js"; +export * from "./LedgerAccountListResponse.js"; +export * from "./LedgerAccountResponse.js"; +export * from "./LineItem.js"; +export * from "./LineItemColumnSettings.js"; +export * from "./LineItemCursorFields.js"; +export * from "./LineItemFields.js"; +export * from "./LineItemInternalRequest.js"; +export * from "./LineItemNumericColumnSettings.js"; +export * from "./LineItemPaginationResponse.js"; +export * from "./LineItemProduct.js"; +export * from "./LineItemProductCreate.js"; +export * from "./LineItemProductMeasureUnit.js"; +export * from "./LineItemProductVatRate.js"; +export * from "./LineItemRequest.js"; +export * from "./LineItemResponse.js"; +export * from "./LineItemUpdate.js"; +export * from "./LineItemsRenderingSettings.js"; +export * from "./LineItemsReplaceResponse.js"; +export * from "./LineItemsResponse.js"; +export * from "./MailSentEventData.js"; +export * from "./MailSettings.js"; +export * from "./MailboxDataResponse.js"; +export * from "./MailboxObjectTypeEnum.js"; +export * from "./MailboxResponse.js"; +export * from "./MessageResponse.js"; +export * from "./MissingFields.js"; +export * from "./MissingLineItemFields.js"; +export * from "./MoniteAllPaymentMethods.js"; +export * from "./MoniteAllPaymentMethodsTypes.js"; +export * from "./NextDocumentNumbers.js"; +export * from "./OcrAddress.js"; +export * from "./OcrAddressDetails.js"; +export * from "./OcrBankDetails.js"; +export * from "./OcrCounterpartDetails.js"; +export * from "./OcrCreditNote.js"; +export * from "./OcrDocumentTypeEnum.js"; +export * from "./OcrInvoice.js"; +export * from "./OcrLineItem.js"; +export * from "./OcrReceipt.js"; +export * from "./OcrReceiptLineItem.js"; +export * from "./OcrResponseInvoiceReceiptData.js"; +export * from "./OcrResponseInvoiceReceiptLineItemRaw.js"; +export * from "./OcrTaskStatus.js"; +export * from "./OcrTasksPaginationResponse.js"; +export * from "./ObjectMatchTypes.js"; +export * from "./ObjectType.js"; +export * from "./ObjectTypeAvailableComment.js"; +export * from "./ObjectTypeEnum.js"; +export * from "./OcrAutoTaggingSettingsRequest.js"; +export * from "./OcrRecognitionResponse.js"; +export * from "./OcrStatusEnum.js"; +export * from "./OcrTaskResponseSchemaRecognizedData.js"; +export * from "./OcrTaskResponseSchema.js"; +export * from "./OnboardingPaymentMethodsResponse.js"; +export * from "./OnboardingRequirementsError.js"; +export * from "./OnboardingRequirementsResponse.js"; +export * from "./OnboardingVerificationError.js"; +export * from "./OnboardingVerificationStatusEnum.js"; +export * from "./OptionalIndividualSchema.js"; +export * from "./OptionalOrganizationSchema.js"; +export * from "./OptionalPersonAddressRequest.js"; +export * from "./OptionalPersonRelationship.js"; +export * from "./OrderEnum.js"; +export * from "./OrganizationResponseSchema.js"; +export * from "./OrganizationSchema.js"; +export * from "./OriginEnum.js"; +export * from "./OverdueReminderResponse.js"; +export * from "./OverdueReminderTerm.js"; +export * from "./OwnershipDeclarationInput.js"; +export * from "./OwnershipDeclarationOutput.js"; +export * from "./PageSchema.js"; +export * from "./PageSchema2.js"; +export * from "./PageSchema3.js"; +export * from "./PartnerMetadata.js"; +export * from "./PartnerMetadataResponse.js"; +export * from "./PartnerProjectSettingsPayloadOutput.js"; +export * from "./PayableActionEnum.js"; +export * from "./PayableActionSchema.js"; +export * from "./PayableAggregatedDataResponse.js"; +export * from "./PayableAggregatedItem.js"; +export * from "./PayableAnalyticsResponse.js"; +export * from "./PayableCreatedEventData.js"; +export * from "./PayableCreditNoteData.js"; +export * from "./PayableCreditNoteLinkedEventData.js"; +export * from "./PayableCreditNoteStateEnum.js"; +export * from "./PayableCreditNoteUnlinkedEventData.js"; +export * from "./PayableCursorFields.js"; +export * from "./PayableDimensionEnum.js"; +export * from "./PayableEntityAddressSchema.js"; +export * from "./PayableEntityIndividualResponse.js"; +export * from "./PayableEntityOrganizationResponse.js"; +export * from "./PayableHistoryCursorFields.js"; +export * from "./PayableHistoryEventTypeEnum.js"; +export * from "./PayableHistoryPaginationResponse.js"; +export * from "./PayableHistoryResponse.js"; +export * from "./PayableIndividualSchema.js"; +export * from "./PayableMetricEnum.js"; +export * from "./PayableOrganizationSchema.js"; +export * from "./PayableOriginEnum.js"; +export * from "./PayablePaginationResponse.js"; +export * from "./PayablePaymentTermDiscount.js"; +export * from "./PayablePaymentTermFinal.js"; +export * from "./PayablePaymentTermsCreatePayload.js"; +export * from "./PayableResponseSchema.js"; +export * from "./PayableSchemaInput.js"; +export * from "./PayableSchemaOutput.js"; +export * from "./PayableSettings.js"; +export * from "./PayableStateEnum.js"; +export * from "./PayableStatusChangedEventData.js"; +export * from "./PayableTemplatesVariable.js"; +export * from "./PayableTemplatesVariablesObject.js"; +export * from "./PayableTemplatesVariablesObjectList.js"; +export * from "./PayableUpdatedEventData.js"; +export * from "./PayableValidationResponse.js"; +export * from "./PayableValidationsResource.js"; +export * from "./PayablesFieldsAllowedForValidate.js"; +export * from "./PayablesVariableType.js"; +export * from "./PayerAccountResponse.js"; +export * from "./PaymentAccountObject.js"; +export * from "./PaymentAccountType.js"; +export * from "./PaymentIntent.js"; +export * from "./PaymentIntentCursorFields.js"; +export * from "./PaymentIntentHistory.js"; +export * from "./PaymentIntentHistoryResponse.js"; +export * from "./PaymentIntentResponse.js"; +export * from "./PaymentIntentsListResponse.js"; +export * from "./PaymentMethod.js"; +export * from "./PaymentMethodDirection.js"; +export * from "./PaymentMethodRequirements.js"; +export * from "./PaymentMethodStatus.js"; +export * from "./PaymentObject.js"; +export * from "./PaymentObjectType.js"; +export * from "./PaymentPageTheme.js"; +export * from "./PaymentPriorityEnum.js"; +export * from "./PaymentReceivedEventData.js"; +export * from "./PaymentRecordCursorFields.js"; +export * from "./PaymentRecordHistoryResponse.js"; +export * from "./PaymentRecordObjectRequest.js"; +export * from "./PaymentRecordObjectResponse.js"; +export * from "./PaymentRecordResponse.js"; +export * from "./PaymentRecordResponseList.js"; +export * from "./PaymentRecordStatusEnum.js"; +export * from "./PaymentRecordStatusUpdateRequest.js"; +export * from "./PaymentReminderResponse.js"; +export * from "./PaymentRequirements.js"; +export * from "./PaymentTerms.js"; +export * from "./PaymentTermsListResponse.js"; +export * from "./PaymentTermsResponse.js"; +export * from "./PaymentsSettingsInput.js"; +export * from "./PaymentsSettingsOutput.js"; +export * from "./PermissionEnum.js"; +export * from "./PersonAddressRequest.js"; +export * from "./PersonAddressResponse.js"; +export * from "./PersonOnboardingDocuments.js"; +export * from "./PersonRelationshipRequest.js"; +export * from "./PersonRelationshipResponse.js"; +export * from "./PersonResponse.js"; +export * from "./PersonsResponse.js"; +export * from "./Platform.js"; +export * from "./PreviewSchema.js"; +export * from "./PreviewSchema2.js"; +export * from "./PreviewSchema3.js"; +export * from "./PreviewTemplateResponse.js"; +export * from "./Price.js"; +export * from "./PricingPlan.js"; +export * from "./ProcessResource.js"; +export * from "./ProcessStatusEnum.js"; +export * from "./ProductCursorFields.js"; +export * from "./ProductServicePaginationResponse.js"; +export * from "./ProductServiceResponse.js"; +export * from "./ProductServiceTypeEnum.js"; +export * from "./ProjectCursorFields.js"; +export * from "./ProjectPaginationResponse.js"; +export * from "./ProjectResource.js"; +export * from "./PublicPaymentLinkResponse.js"; +export * from "./PurchaseOrderCounterpartAddressSchema.js"; +export * from "./PurchaseOrderCounterpartIndividualResponse.js"; +export * from "./PurchaseOrderCounterpartIndividualRootResponse.js"; +export * from "./PurchaseOrderCounterpartOrganizationResponse.js"; +export * from "./PurchaseOrderCounterpartOrganizationRootResponse.js"; +export * from "./PurchaseOrderCounterpartSchema.js"; +export * from "./PurchaseOrderCursorFields.js"; +export * from "./PurchaseOrderEmailPreviewResponse.js"; +export * from "./PurchaseOrderEmailSentResponse.js"; +export * from "./PurchaseOrderItem.js"; +export * from "./PurchaseOrderPaginationResponse.js"; +export * from "./PurchaseOrderResponseSchema.js"; +export * from "./PurchaseOrderStatusEnum.js"; +export * from "./PurchaseOrderVatId.js"; +export * from "./QuoteRenderingSettings.js"; +export * from "./QuoteResponsePayloadEntity.js"; +export * from "./QuoteResponsePayload.js"; +export * from "./QuoteStateEnum.js"; +export * from "./ReceiptCursorFields.js"; +export * from "./ReceiptLineItemCursorFields.js"; +export * from "./ReceiptLineItemResponseSchema.js"; +export * from "./ReceiptLineItemsPaginationResponse.js"; +export * from "./ReceiptPaginationResponse.js"; +export * from "./ReceiptResponseSchema.js"; +export * from "./ReceivableCounterpartContact.js"; +export * from "./ReceivableCounterpartVatIdResponse.js"; +export * from "./ReceivableCreateBasedOnPayload.js"; +export * from "./ReceivableCreatedEventData.js"; +export * from "./ReceivableCursorFields.js"; +export * from "./ReceivableCursorFields2.js"; +export * from "./ReceivableDimensionEnum.js"; +export * from "./ReceivableEditFlow.js"; +export * from "./ReceivableEntityAddressSchema.js"; +export * from "./ReceivableEntityBase.js"; +export * from "./ReceivableEntityIndividual.js"; +export * from "./ReceivableEntityIndividualRequest.js"; +export * from "./ReceivableEntityOrganization.js"; +export * from "./ReceivableEntityOrganizationRequest.js"; +export * from "./ReceivableEntityVatIdResponse.js"; +export * from "./ReceivableFacadeCreateInvoicePayload.js"; +export * from "./ReceivableFacadeCreatePayload.js"; +export * from "./ReceivableFacadeCreateQuotePayload.js"; +export * from "./ReceivableFileUrl.js"; +export * from "./ReceivableHistoryCursorFields.js"; +export * from "./ReceivableHistoryEventTypeEnum.js"; +export * from "./ReceivableHistoryPaginationResponse.js"; +export * from "./ReceivableHistoryResponse.js"; +export * from "./ReceivableMailCursorFields.js"; +export * from "./ReceivableMailPaginationResponse.js"; +export * from "./ReceivableMailRecipientState.js"; +export * from "./ReceivableMailRecipients.js"; +export * from "./ReceivableMailResponse.js"; +export * from "./ReceivableMailStatusEnum.js"; +export * from "./ReceivableMetricEnum.js"; +export * from "./ReceivablePaginationResponse.js"; +export * from "./ReceivablePreviewResponse.js"; +export * from "./ReceivableRequiredFields.js"; +export * from "./ReceivableResponse.js"; +export * from "./ReceivableSendResponse.js"; +export * from "./ReceivableSettings.js"; +export * from "./ReceivableTemplatesVariable.js"; +export * from "./ReceivableTemplatesVariablesObject.js"; +export * from "./ReceivableTemplatesVariablesObjectList.js"; +export * from "./ReceivableType.js"; +export * from "./ReceivableUpdatePayload.js"; +export * from "./ReceivableUpdatedEventData.js"; +export * from "./ReceivablesAnalyticsDataPoint.js"; +export * from "./ReceivablesAnalyticsResponse.js"; +export * from "./ReceivablesCounterpartAddress.js"; +export * from "./ReceivablesPreviewTypeEnum.js"; +export * from "./ReceivablesRemindersWarningMessage.js"; +export * from "./ReceivablesRepresentationOfCounterpartAddress.js"; +export * from "./ReceivablesRepresentationOfEntityBankAccount.js"; +export * from "./ReceivablesSendResponse.js"; +export * from "./ReceivablesStatusEnum.js"; +export * from "./ReceivablesVerifyResponse.js"; +export * from "./RecipientAccountResponse.js"; +export * from "./Recipients.js"; +export * from "./RecurrenceFrequency.js"; +export * from "./RecurrenceIteration.js"; +export * from "./RecurrenceResponse.js"; +export * from "./RecurrenceResponseList.js"; +export * from "./RecurrenceStatus.js"; +export * from "./RelatedDocuments.js"; +export * from "./Reminder.js"; +export * from "./ReminderMailSentEventData.js"; +export * from "./ReminderTypeEnum.js"; +export * from "./RemindersSettings.js"; +export * from "./RepaymentSchedule.js"; +export * from "./RequirementsError.js"; +export * from "./ResponseItem.js"; +export * from "./RoleCursorFields.js"; +export * from "./RolePaginationResponse.js"; +export * from "./RoleResponse.js"; +export * from "./RootSchemaInput.js"; +export * from "./RootSchemaOutput.js"; +export * from "./ServiceProvidersEnum.js"; +export * from "./SettingsResponse.js"; +export * from "./Signature.js"; +export * from "./SingleOnboardingRequirementsResponse.js"; +export * from "./SourceOfPayableDataEnum.js"; +export * from "./SourceOfReceiptDataEnum.js"; +export * from "./StatusChangedEventData.js"; +export * from "./StatusEnum.js"; +export * from "./SuccessResult.js"; +export * from "./SuggestedCounterpartPayload.js"; +export * from "./SuggestedPaymentTerm.js"; +export * from "./SuggestedResponse.js"; +export * from "./SupportedFieldNames.js"; +export * from "./SupportedFormatSchema.js"; +export * from "./SyncRecordCursorFields.js"; +export * from "./SyncRecordResource.js"; +export * from "./SyncRecordResourceList.js"; +export * from "./SyncStatus.js"; +export * from "./SystemTemplateDataSchema.js"; +export * from "./SystemTemplates.js"; +export * from "./TagCategory.js"; +export * from "./TagCursorFields.js"; +export * from "./TagReadSchema.js"; +export * from "./TagsPaginationResponse.js"; +export * from "./TaxComponentResponse.js"; +export * from "./TaxRateAccountCursorFields.js"; +export * from "./TemplateDataSchema.js"; +export * from "./TemplateListResponse.js"; +export * from "./TemplateReceivableResponse.js"; +export * from "./TemplateTypeEnum.js"; +export * from "./TermDiscountDays.js"; +export * from "./TermFinalDays.js"; +export * from "./TermsOfServiceAcceptanceInput.js"; +export * from "./TermsOfServiceAcceptanceOutput.js"; +export * from "./TextTemplateDocumentTypeEnum.js"; +export * from "./TextTemplateResponse.js"; +export * from "./TextTemplateResponseList.js"; +export * from "./TextTemplateType.js"; +export * from "./TotalVatAmountItem.js"; +export * from "./TotalVatAmountItemComponent.js"; +export * from "./Unit.js"; +export * from "./UnitListResponse.js"; +export * from "./UnitRequest.js"; +export * from "./UnitResponse.js"; +export * from "./UpdateCreditNote.js"; +export * from "./UpdateCreditNotePayload.js"; +export * from "./UpdateEinvoicingAddress.js"; +export * from "./UpdateEntityAddressSchema.js"; +export * from "./UpdateEntityRequest.js"; +export * from "./UpdateInvoice.js"; +export * from "./UpdateInvoicePayload.js"; +export * from "./UpdateIssuedInvoiceEntity.js"; +export * from "./UpdateIssuedInvoice.js"; +export * from "./UpdateIssuedInvoicePayload.js"; +export * from "./UpdateLineItemForCreditNote.js"; +export * from "./UpdateProductForCreditNote.js"; +export * from "./UpdateQuote.js"; +export * from "./UpdateQuotePayload.js"; +export * from "./ValidationError.js"; +export * from "./Variable.js"; +export * from "./VariablesObject.js"; +export * from "./VariablesObjectList.js"; +export * from "./VariablesType.js"; +export * from "./VatIdTypeEnum.js"; +export * from "./VatModeEnum.js"; +export * from "./VatRateComponent.js"; +export * from "./VatRateCreator.js"; +export * from "./VatRateListResponse.js"; +export * from "./VatRateResponse.js"; +export * from "./VatRateStatusEnum.js"; +export * from "./VerificationError.js"; +export * from "./VerificationStatusEnum.js"; +export * from "./VerifyResponse.js"; +export * from "./WcBusinessStatus.js"; +export * from "./WcInvoiceStatus.js"; +export * from "./WcOfferStatus.js"; +export * from "./WcRepaymentType.js"; +export * from "./WebhookDeliveryCursorFields.js"; +export * from "./WebhookDeliveryPaginationResource.js"; +export * from "./WebhookDeliveryResource.js"; +export * from "./WebhookObjectType.js"; +export * from "./WebhookSubscriptionCursorFields.js"; +export * from "./WebhookSubscriptionPaginationResource.js"; +export * from "./WebhookSubscriptionResource.js"; +export * from "./WebhookSubscriptionResourceWithSecret.js"; +export * from "./WebhookSubscriptionStatus.js"; diff --git a/src/core/auth/AuthProvider.ts b/src/core/auth/AuthProvider.ts new file mode 100644 index 0000000..07e0d6a --- /dev/null +++ b/src/core/auth/AuthProvider.ts @@ -0,0 +1,5 @@ +import { AuthRequest } from "./AuthRequest.js"; + +export interface AuthProvider { + getAuthRequest(): Promise; +} diff --git a/src/core/auth/AuthRequest.ts b/src/core/auth/AuthRequest.ts new file mode 100644 index 0000000..f6218b4 --- /dev/null +++ b/src/core/auth/AuthRequest.ts @@ -0,0 +1,9 @@ +/** + * Request parameters for authentication requests. + */ +export interface AuthRequest { + /** + * The headers to be included in the request. + */ + headers: Record; +} diff --git a/src/core/auth/BasicAuth.ts b/src/core/auth/BasicAuth.ts index 146df21..1c0d883 100644 --- a/src/core/auth/BasicAuth.ts +++ b/src/core/auth/BasicAuth.ts @@ -1,4 +1,4 @@ -import { Base64 } from "js-base64"; +import { base64Decode, base64Encode } from "../base64.js"; export interface BasicAuth { username: string; @@ -12,12 +12,12 @@ export const BasicAuth = { if (basicAuth == null) { return undefined; } - const token = Base64.encode(`${basicAuth.username}:${basicAuth.password}`); + const token = base64Encode(`${basicAuth.username}:${basicAuth.password}`); return `Basic ${token}`; }, fromAuthorizationHeader: (header: string): BasicAuth => { const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, ""); - const decoded = Base64.decode(credentials); + const decoded = base64Decode(credentials); const [username, password] = decoded.split(":", 2); if (username == null || password == null) { diff --git a/src/core/auth/index.ts b/src/core/auth/index.ts index ee293b3..7519e98 100644 --- a/src/core/auth/index.ts +++ b/src/core/auth/index.ts @@ -1,2 +1,4 @@ -export { BasicAuth } from "./BasicAuth"; -export { BearerToken } from "./BearerToken"; +export { BasicAuth } from "./BasicAuth.js"; +export { BearerToken } from "./BearerToken.js"; +export { type AuthRequest } from "./AuthRequest.js"; +export { AuthProvider } from "./AuthProvider.js"; diff --git a/src/core/base64.ts b/src/core/base64.ts new file mode 100644 index 0000000..448a0db --- /dev/null +++ b/src/core/base64.ts @@ -0,0 +1,27 @@ +function base64ToBytes(base64: string): Uint8Array { + const binString = atob(base64); + return Uint8Array.from(binString, (m) => m.codePointAt(0)!); +} + +function bytesToBase64(bytes: Uint8Array): string { + const binString = String.fromCodePoint(...bytes); + return btoa(binString); +} + +export function base64Encode(input: string): string { + if (typeof Buffer !== "undefined") { + return Buffer.from(input, "utf8").toString("base64"); + } + + const bytes = new TextEncoder().encode(input); + return bytesToBase64(bytes); +} + +export function base64Decode(input: string): string { + if (typeof Buffer !== "undefined") { + return Buffer.from(input, "base64").toString("utf8"); + } + + const bytes = base64ToBytes(input); + return new TextDecoder().decode(bytes); +} diff --git a/src/core/exports.ts b/src/core/exports.ts new file mode 100644 index 0000000..e415a8f --- /dev/null +++ b/src/core/exports.ts @@ -0,0 +1 @@ +export * from "./file/exports.js"; diff --git a/src/core/fetcher/APIResponse.ts b/src/core/fetcher/APIResponse.ts index 6335291..dd4b946 100644 --- a/src/core/fetcher/APIResponse.ts +++ b/src/core/fetcher/APIResponse.ts @@ -1,4 +1,4 @@ -import { RawResponse } from "./RawResponse"; +import { RawResponse } from "./RawResponse.js"; /** * The response of an API call. diff --git a/src/core/fetcher/BinaryResponse.ts b/src/core/fetcher/BinaryResponse.ts new file mode 100644 index 0000000..614cb59 --- /dev/null +++ b/src/core/fetcher/BinaryResponse.ts @@ -0,0 +1,36 @@ +import { ResponseWithBody } from "./ResponseWithBody.js"; + +export type BinaryResponse = { + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */ + bodyUsed: boolean; + /** + * Returns a ReadableStream of the response body. + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body) + */ + stream: () => ReadableStream; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */ + arrayBuffer: () => Promise; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */ + blob: () => Promise; + /** + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes) + * Some versions of the Fetch API may not support this method. + */ + bytes?(): Promise; +}; + +export function getBinaryResponse(response: ResponseWithBody): BinaryResponse { + const binaryResponse: BinaryResponse = { + get bodyUsed() { + return response.bodyUsed; + }, + stream: () => response.body, + arrayBuffer: response.arrayBuffer.bind(response), + blob: response.blob.bind(response), + }; + if ("bytes" in response && typeof response.bytes === "function") { + binaryResponse.bytes = response.bytes.bind(response); + } + + return binaryResponse; +} diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index 336ee10..693dad8 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -1,12 +1,14 @@ -import { toJson } from "../json"; -import { APIResponse } from "./APIResponse"; -import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse"; -import { createRequestUrl } from "./createRequestUrl"; -import { getFetchFn } from "./getFetchFn"; -import { getRequestBody } from "./getRequestBody"; -import { getResponseBody } from "./getResponseBody"; -import { makeRequest } from "./makeRequest"; -import { requestWithRetries } from "./requestWithRetries"; +import { toJson } from "../json.js"; +import { APIResponse } from "./APIResponse.js"; +import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js"; +import { Supplier } from "./Supplier.js"; +import { createRequestUrl } from "./createRequestUrl.js"; +import { getErrorResponseBody } from "./getErrorResponseBody.js"; +import { getFetchFn } from "./getFetchFn.js"; +import { getRequestBody } from "./getRequestBody.js"; +import { getResponseBody } from "./getResponseBody.js"; +import { makeRequest } from "./makeRequest.js"; +import { requestWithRetries } from "./requestWithRetries.js"; export type FetchFunction = (args: Fetcher.Args) => Promise>; @@ -15,15 +17,15 @@ export declare namespace Fetcher { url: string; method: string; contentType?: string; - headers?: Record; - queryParameters?: Record; + headers?: Record | undefined>; + queryParameters?: Record; body?: unknown; timeoutMs?: number; maxRetries?: number; withCredentials?: boolean; abortSignal?: AbortSignal; requestType?: "json" | "file" | "bytes"; - responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer"; + responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response"; duplex?: "half"; } @@ -51,20 +53,31 @@ export declare namespace Fetcher { } } -export async function fetcherImpl(args: Fetcher.Args): Promise> { - const headers: Record = {}; +async function getHeaders(args: Fetcher.Args): Promise> { + const newHeaders: Record = {}; if (args.body !== undefined && args.contentType != null) { - headers["Content-Type"] = args.contentType; + newHeaders["Content-Type"] = args.contentType; + } + + if (args.headers == null) { + return newHeaders; } - if (args.headers != null) { - for (const [key, value] of Object.entries(args.headers)) { - if (value != null) { - headers[key] = value; - } + for (const [key, value] of Object.entries(args.headers)) { + const result = await Supplier.get(value); + if (typeof result === "string") { + newHeaders[key] = result; + continue; } + if (result == null) { + continue; + } + newHeaders[key] = `${result}`; } + return newHeaders; +} +export async function fetcherImpl(args: Fetcher.Args): Promise> { const url = createRequestUrl(args.url, args.queryParameters); const requestBody: BodyInit | undefined = await getRequestBody({ body: args.body, @@ -79,7 +92,7 @@ export async function fetcherImpl(args: Fetcher.Args): Promise(args: Fetcher.Args): Promise= 200 && response.status < 400) { return { ok: true, - body: responseBody as R, + body: (await getResponseBody(response, args.responseType)) as R, headers: response.headers, rawResponse: toRawResponse(response), }; @@ -103,7 +115,7 @@ export async function fetcherImpl(args: Fetcher.Args): Promise; +}; + +export function isResponseWithBody(response: Response): response is ResponseWithBody { + return (response as ResponseWithBody).body != null; +} diff --git a/src/core/fetcher/createRequestUrl.ts b/src/core/fetcher/createRequestUrl.ts index f1157ce..88e1326 100644 --- a/src/core/fetcher/createRequestUrl.ts +++ b/src/core/fetcher/createRequestUrl.ts @@ -1,10 +1,6 @@ -import qs from "qs"; +import { toQueryString } from "../url/qs.js"; -export function createRequestUrl( - baseUrl: string, - queryParameters?: Record, -): string { - return Object.keys(queryParameters ?? {}).length > 0 - ? `${baseUrl}?${qs.stringify(queryParameters, { arrayFormat: "repeat" })}` - : baseUrl; +export function createRequestUrl(baseUrl: string, queryParameters?: Record): string { + const queryString = toQueryString(queryParameters, { arrayFormat: "repeat" }); + return queryString ? `${baseUrl}?${queryString}` : baseUrl; } diff --git a/src/core/fetcher/getErrorResponseBody.ts b/src/core/fetcher/getErrorResponseBody.ts new file mode 100644 index 0000000..450424b --- /dev/null +++ b/src/core/fetcher/getErrorResponseBody.ts @@ -0,0 +1,32 @@ +import { fromJson } from "../json.js"; +import { getResponseBody } from "./getResponseBody.js"; + +export async function getErrorResponseBody(response: Response): Promise { + let contentType = response.headers.get("Content-Type")?.toLowerCase(); + if (contentType == null || contentType.length === 0) { + return getResponseBody(response); + } + + if (contentType.indexOf(";") !== -1) { + contentType = contentType.split(";")[0]?.trim() ?? ""; + } + switch (contentType) { + case "application/hal+json": + case "application/json": + case "application/ld+json": + case "application/problem+json": + case "application/vnd.api+json": + case "text/json": + const text = await response.text(); + return text.length > 0 ? fromJson(text) : undefined; + default: + if (contentType.startsWith("application/vnd.") && contentType.endsWith("+json")) { + const text = await response.text(); + return text.length > 0 ? fromJson(text) : undefined; + } + + // Fallback to plain text if content type is not recognized + // Even if no body is present, the response will be an empty string + return await response.text(); + } +} diff --git a/src/core/fetcher/getFetchFn.ts b/src/core/fetcher/getFetchFn.ts index 9fd9bfc..9f845b9 100644 --- a/src/core/fetcher/getFetchFn.ts +++ b/src/core/fetcher/getFetchFn.ts @@ -1,25 +1,3 @@ -import { RUNTIME } from "../runtime"; - -/** - * Returns a fetch function based on the runtime - */ -export async function getFetchFn(): Promise { - // In Node.js 18+ environments, use native fetch - if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { - return fetch; - } - - // In Node.js 18 or lower environments, the SDK always uses`node-fetch`. - if (RUNTIME.type === "node") { - return (await import("node-fetch")).default as any; - } - - // Otherwise the SDK uses global fetch if available, - // and falls back to node-fetch. - if (typeof fetch == "function") { - return fetch; - } - - // Defaults to node `node-fetch` if global fetch isn't available - return (await import("node-fetch")).default as any; +export async function getFetchFn(): Promise { + return fetch; } diff --git a/src/core/fetcher/getRequestBody.ts b/src/core/fetcher/getRequestBody.ts index fce5589..e38457c 100644 --- a/src/core/fetcher/getRequestBody.ts +++ b/src/core/fetcher/getRequestBody.ts @@ -1,4 +1,4 @@ -import { toJson } from "../json"; +import { toJson } from "../json.js"; export declare namespace GetRequestBody { interface Args { diff --git a/src/core/fetcher/getResponseBody.ts b/src/core/fetcher/getResponseBody.ts index d046e6e..7ca8b3d 100644 --- a/src/core/fetcher/getResponseBody.ts +++ b/src/core/fetcher/getResponseBody.ts @@ -1,34 +1,43 @@ -import { chooseStreamWrapper } from "./stream-wrappers/chooseStreamWrapper"; +import { getBinaryResponse } from "./BinaryResponse.js"; +import { isResponseWithBody } from "./ResponseWithBody.js"; +import { fromJson } from "../json.js"; export async function getResponseBody(response: Response, responseType?: string): Promise { - if (response.body != null && responseType === "blob") { - return await response.blob(); - } else if (response.body != null && responseType === "arrayBuffer") { - return await response.arrayBuffer(); - } else if (response.body != null && responseType === "sse") { - return response.body; - } else if (response.body != null && responseType === "streaming") { - return chooseStreamWrapper(response.body); - } else if (response.body != null && responseType === "text") { - return await response.text(); - } else { - const text = await response.text(); - if (text.length > 0) { - try { - let responseBody = JSON.parse(text); - return responseBody; - } catch (err) { - return { - ok: false, - error: { - reason: "non-json", - statusCode: response.status, - rawBody: text, - }, - }; - } - } else { - return undefined; + if (!isResponseWithBody(response)) { + return undefined; + } + switch (responseType) { + case "binary-response": + return getBinaryResponse(response); + case "blob": + return await response.blob(); + case "arrayBuffer": + return await response.arrayBuffer(); + case "sse": + return response.body; + case "streaming": + return response.body; + + case "text": + return await response.text(); + } + + // if responseType is "json" or not specified, try to parse as JSON + const text = await response.text(); + if (text.length > 0) { + try { + let responseBody = fromJson(text); + return responseBody; + } catch (err) { + return { + ok: false, + error: { + reason: "non-json", + statusCode: response.status, + rawBody: text, + }, + }; } } + return undefined; } diff --git a/src/core/fetcher/index.ts b/src/core/fetcher/index.ts index 249f517..9f4e61d 100644 --- a/src/core/fetcher/index.ts +++ b/src/core/fetcher/index.ts @@ -1,8 +1,9 @@ -export type { APIResponse } from "./APIResponse"; -export { fetcher } from "./Fetcher"; -export type { Fetcher, FetchFunction } from "./Fetcher"; -export { getHeader } from "./getHeader"; -export { Supplier } from "./Supplier"; -export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse"; -export type { RawResponse, WithRawResponse } from "./RawResponse"; -export { HttpResponsePromise } from "./HttpResponsePromise"; +export type { APIResponse } from "./APIResponse.js"; +export { fetcher } from "./Fetcher.js"; +export type { Fetcher, FetchFunction } from "./Fetcher.js"; +export { getHeader } from "./getHeader.js"; +export { Supplier } from "./Supplier.js"; +export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js"; +export type { RawResponse, WithRawResponse } from "./RawResponse.js"; +export { HttpResponsePromise } from "./HttpResponsePromise.js"; +export type { BinaryResponse } from "./BinaryResponse.js"; diff --git a/src/core/fetcher/makeRequest.ts b/src/core/fetcher/makeRequest.ts index 1af42bb..1a5ffd3 100644 --- a/src/core/fetcher/makeRequest.ts +++ b/src/core/fetcher/makeRequest.ts @@ -1,4 +1,4 @@ -import { anySignal, getTimeoutSignal } from "./signals"; +import { anySignal, getTimeoutSignal } from "./signals.js"; export const makeRequest = async ( fetchFn: (url: string, init: RequestInit) => Promise, diff --git a/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts b/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts deleted file mode 100644 index 6f1a82e..0000000 --- a/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +++ /dev/null @@ -1,257 +0,0 @@ -import type { Writable } from "readable-stream"; - -import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; - -export class Node18UniversalStreamWrapper - implements - StreamWrapper | Writable | WritableStream, ReadFormat> -{ - private readableStream: ReadableStream; - private reader: ReadableStreamDefaultReader; - private events: Record; - private paused: boolean; - private resumeCallback: ((value?: unknown) => void) | null; - private encoding: string | null; - - constructor(readableStream: ReadableStream) { - this.readableStream = readableStream; - this.reader = this.readableStream.getReader(); - this.events = { - data: [], - end: [], - error: [], - readable: [], - close: [], - pause: [], - resume: [], - }; - this.paused = false; - this.resumeCallback = null; - this.encoding = null; - } - - public on(event: string, callback: EventCallback): void { - this.events[event]?.push(callback); - } - - public off(event: string, callback: EventCallback): void { - this.events[event] = this.events[event]?.filter((cb) => cb !== callback); - } - - public pipe( - dest: Node18UniversalStreamWrapper | Writable | WritableStream, - ): Node18UniversalStreamWrapper | Writable | WritableStream { - this.on("data", async (chunk) => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._write(chunk); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.write(chunk).then(() => writer.releaseLock()); - } else { - dest.write(chunk); - } - }); - - this.on("end", async () => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._end(); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.close(); - } else { - dest.end(); - } - }); - - this.on("error", async (error) => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._error(error); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.abort(error); - } else { - dest.destroy(error); - } - }); - - this._startReading(); - - return dest; - } - - public pipeTo( - dest: Node18UniversalStreamWrapper | Writable | WritableStream, - ): Node18UniversalStreamWrapper | Writable | WritableStream { - return this.pipe(dest); - } - - public unpipe(dest: Node18UniversalStreamWrapper | Writable | WritableStream): void { - this.off("data", async (chunk) => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._write(chunk); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.write(chunk).then(() => writer.releaseLock()); - } else { - dest.write(chunk); - } - }); - - this.off("end", async () => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._end(); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.close(); - } else { - dest.end(); - } - }); - - this.off("error", async (error) => { - if (dest instanceof Node18UniversalStreamWrapper) { - dest._error(error); - } else if (dest instanceof WritableStream) { - const writer = dest.getWriter(); - writer.abort(error); - } else { - dest.destroy(error); - } - }); - } - - public destroy(error?: Error): void { - this.reader - .cancel(error) - .then(() => { - this._emit("close"); - }) - .catch((err) => { - this._emit("error", err); - }); - } - - public pause(): void { - this.paused = true; - this._emit("pause"); - } - - public resume(): void { - if (this.paused) { - this.paused = false; - this._emit("resume"); - if (this.resumeCallback) { - this.resumeCallback(); - this.resumeCallback = null; - } - } - } - - public get isPaused(): boolean { - return this.paused; - } - - public async read(): Promise { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - - if (done) { - return undefined; - } - return value; - } - - public setEncoding(encoding: string): void { - this.encoding = encoding; - } - - public async text(): Promise { - const chunks: ReadFormat[] = []; - - while (true) { - const { done, value } = await this.reader.read(); - if (done) { - break; - } - if (value) { - chunks.push(value); - } - } - - const decoder = new TextDecoder(this.encoding || "utf-8"); - return decoder.decode(await new Blob(chunks).arrayBuffer()); - } - - public async json(): Promise { - const text = await this.text(); - return JSON.parse(text); - } - - private _write(chunk: ReadFormat): void { - this._emit("data", chunk); - } - - private _end(): void { - this._emit("end"); - } - - private _error(error: any): void { - this._emit("error", error); - } - - private _emit(event: string, data?: any): void { - if (this.events[event]) { - for (const callback of this.events[event] || []) { - callback(data); - } - } - } - - private async _startReading(): Promise { - try { - this._emit("readable"); - while (true) { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - if (done) { - this._emit("end"); - this._emit("close"); - break; - } - if (value) { - this._emit("data", value); - } - } - } catch (error) { - this._emit("error", error); - } - } - - [Symbol.asyncIterator](): AsyncIterableIterator { - return { - next: async () => { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - if (done) { - return { done: true, value: undefined }; - } - return { done: false, value }; - }, - [Symbol.asyncIterator]() { - return this; - }, - }; - } -} diff --git a/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts b/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts deleted file mode 100644 index 23c01a1..0000000 --- a/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts +++ /dev/null @@ -1,107 +0,0 @@ -import type { Readable, Writable } from "readable-stream"; - -import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; - -export class NodePre18StreamWrapper implements StreamWrapper { - private readableStream: Readable; - private encoding: string | undefined; - - constructor(readableStream: Readable) { - this.readableStream = readableStream; - } - - public on(event: string, callback: EventCallback): void { - this.readableStream.on(event, callback); - } - - public off(event: string, callback: EventCallback): void { - this.readableStream.off(event, callback); - } - - public pipe(dest: Writable): Writable { - this.readableStream.pipe(dest); - return dest; - } - - public pipeTo(dest: Writable): Writable { - return this.pipe(dest); - } - - public unpipe(dest?: Writable): void { - if (dest) { - this.readableStream.unpipe(dest); - } else { - this.readableStream.unpipe(); - } - } - - public destroy(error?: Error): void { - this.readableStream.destroy(error); - } - - public pause(): void { - this.readableStream.pause(); - } - - public resume(): void { - this.readableStream.resume(); - } - - public get isPaused(): boolean { - return this.readableStream.isPaused(); - } - - public async read(): Promise { - return new Promise((resolve, reject) => { - const chunk = this.readableStream.read(); - if (chunk) { - resolve(chunk); - } else { - this.readableStream.once("readable", () => { - const chunk = this.readableStream.read(); - resolve(chunk); - }); - this.readableStream.once("error", reject); - } - }); - } - - public setEncoding(encoding?: string): void { - this.readableStream.setEncoding(encoding as BufferEncoding); - this.encoding = encoding; - } - - public async text(): Promise { - const chunks: Uint8Array[] = []; - const encoder = new TextEncoder(); - this.readableStream.setEncoding((this.encoding || "utf-8") as BufferEncoding); - - for await (const chunk of this.readableStream) { - chunks.push(encoder.encode(chunk)); - } - - const decoder = new TextDecoder(this.encoding || "utf-8"); - return decoder.decode(Buffer.concat(chunks)); - } - - public async json(): Promise { - const text = await this.text(); - return JSON.parse(text); - } - - public [Symbol.asyncIterator](): AsyncIterableIterator { - const readableStream = this.readableStream; - const iterator = readableStream[Symbol.asyncIterator](); - - // Create and return an async iterator that yields buffers - return { - async next(): Promise> { - const { value, done } = await iterator.next(); - return { value: value as Buffer, done }; - }, - [Symbol.asyncIterator]() { - return this; - }, - }; - } -} diff --git a/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts b/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts deleted file mode 100644 index 091e2a7..0000000 --- a/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +++ /dev/null @@ -1,243 +0,0 @@ -import { StreamWrapper } from "./chooseStreamWrapper"; - -type EventCallback = (data?: any) => void; - -export class UndiciStreamWrapper - implements StreamWrapper | WritableStream, ReadFormat> -{ - private readableStream: ReadableStream; - private reader: ReadableStreamDefaultReader; - private events: Record; - private paused: boolean; - private resumeCallback: ((value?: unknown) => void) | null; - private encoding: string | null; - - constructor(readableStream: ReadableStream) { - this.readableStream = readableStream; - this.reader = this.readableStream.getReader(); - this.events = { - data: [], - end: [], - error: [], - readable: [], - close: [], - pause: [], - resume: [], - }; - this.paused = false; - this.resumeCallback = null; - this.encoding = null; - } - - public on(event: string, callback: EventCallback): void { - this.events[event]?.push(callback); - } - - public off(event: string, callback: EventCallback): void { - this.events[event] = this.events[event]?.filter((cb) => cb !== callback); - } - - public pipe( - dest: UndiciStreamWrapper | WritableStream, - ): UndiciStreamWrapper | WritableStream { - this.on("data", (chunk) => { - if (dest instanceof UndiciStreamWrapper) { - dest._write(chunk); - } else { - const writer = dest.getWriter(); - writer.write(chunk).then(() => writer.releaseLock()); - } - }); - - this.on("end", () => { - if (dest instanceof UndiciStreamWrapper) { - dest._end(); - } else { - const writer = dest.getWriter(); - writer.close(); - } - }); - - this.on("error", (error) => { - if (dest instanceof UndiciStreamWrapper) { - dest._error(error); - } else { - const writer = dest.getWriter(); - writer.abort(error); - } - }); - - this._startReading(); - - return dest; - } - - public pipeTo( - dest: UndiciStreamWrapper | WritableStream, - ): UndiciStreamWrapper | WritableStream { - return this.pipe(dest); - } - - public unpipe(dest: UndiciStreamWrapper | WritableStream): void { - this.off("data", (chunk) => { - if (dest instanceof UndiciStreamWrapper) { - dest._write(chunk); - } else { - const writer = dest.getWriter(); - writer.write(chunk).then(() => writer.releaseLock()); - } - }); - - this.off("end", () => { - if (dest instanceof UndiciStreamWrapper) { - dest._end(); - } else { - const writer = dest.getWriter(); - writer.close(); - } - }); - - this.off("error", (error) => { - if (dest instanceof UndiciStreamWrapper) { - dest._error(error); - } else { - const writer = dest.getWriter(); - writer.abort(error); - } - }); - } - - public destroy(error?: Error): void { - this.reader - .cancel(error) - .then(() => { - this._emit("close"); - }) - .catch((err) => { - this._emit("error", err); - }); - } - - public pause(): void { - this.paused = true; - this._emit("pause"); - } - - public resume(): void { - if (this.paused) { - this.paused = false; - this._emit("resume"); - if (this.resumeCallback) { - this.resumeCallback(); - this.resumeCallback = null; - } - } - } - - public get isPaused(): boolean { - return this.paused; - } - - public async read(): Promise { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - if (done) { - return undefined; - } - return value; - } - - public setEncoding(encoding: string): void { - this.encoding = encoding; - } - - public async text(): Promise { - const chunks: BlobPart[] = []; - - while (true) { - const { done, value } = await this.reader.read(); - if (done) { - break; - } - if (value) { - chunks.push(value); - } - } - - const decoder = new TextDecoder(this.encoding || "utf-8"); - return decoder.decode(await new Blob(chunks).arrayBuffer()); - } - - public async json(): Promise { - const text = await this.text(); - return JSON.parse(text); - } - - private _write(chunk: ReadFormat): void { - this._emit("data", chunk); - } - - private _end(): void { - this._emit("end"); - } - - private _error(error: any): void { - this._emit("error", error); - } - - private _emit(event: string, data?: any): void { - if (this.events[event]) { - for (const callback of this.events[event] || []) { - callback(data); - } - } - } - - private async _startReading(): Promise { - try { - this._emit("readable"); - while (true) { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - if (done) { - this._emit("end"); - this._emit("close"); - break; - } - if (value) { - this._emit("data", value); - } - } - } catch (error) { - this._emit("error", error); - } - } - - [Symbol.asyncIterator](): AsyncIterableIterator { - return { - next: async () => { - if (this.paused) { - await new Promise((resolve) => { - this.resumeCallback = resolve; - }); - } - const { done, value } = await this.reader.read(); - if (done) { - return { done: true, value: undefined }; - } - return { done: false, value }; - }, - [Symbol.asyncIterator]() { - return this; - }, - }; - } -} diff --git a/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts b/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts deleted file mode 100644 index 8c7492f..0000000 --- a/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { Readable } from "readable-stream"; - -import { RUNTIME } from "../../runtime"; - -export type EventCallback = (data?: any) => void; - -export interface StreamWrapper { - setEncoding(encoding?: string): void; - on(event: string, callback: EventCallback): void; - off(event: string, callback: EventCallback): void; - pipe(dest: WritableStream): WritableStream; - pipeTo(dest: WritableStream): WritableStream; - unpipe(dest?: WritableStream): void; - destroy(error?: Error): void; - pause(): void; - resume(): void; - get isPaused(): boolean; - read(): Promise; - text(): Promise; - json(): Promise; - [Symbol.asyncIterator](): AsyncIterableIterator; -} - -export async function chooseStreamWrapper(responseBody: any): Promise>> { - if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { - return new (await import("./Node18UniversalStreamWrapper")).Node18UniversalStreamWrapper( - responseBody as ReadableStream, - ); - } else if (RUNTIME.type !== "node" && typeof fetch === "function") { - return new (await import("./UndiciStreamWrapper")).UndiciStreamWrapper(responseBody as ReadableStream); - } else { - return new (await import("./NodePre18StreamWrapper")).NodePre18StreamWrapper(responseBody as Readable); - } -} diff --git a/src/core/file/exports.ts b/src/core/file/exports.ts new file mode 100644 index 0000000..acda036 --- /dev/null +++ b/src/core/file/exports.ts @@ -0,0 +1 @@ +export { Uploadable } from "./types.js"; diff --git a/src/core/file/file.ts b/src/core/file/file.ts new file mode 100644 index 0000000..bc4b7e5 --- /dev/null +++ b/src/core/file/file.ts @@ -0,0 +1,186 @@ +import { Uploadable } from "./types.js"; + +export async function toBinaryUploadRequest( + file: Uploadable, +): Promise<{ body: Uploadable.FileLike; headers?: Record }> { + const { data, filename, contentLength, contentType } = await getFileWithMetadata(file); + const request = { + body: data, + headers: {} as Record, + }; + if (filename) { + request.headers["Content-Disposition"] = `attachment; filename="${filename}"`; + } + if (contentType) { + request.headers["Content-Type"] = contentType; + } + if (contentLength != null) { + request.headers["Content-Length"] = contentLength.toString(); + } + return request; +} + +async function getFileWithMetadata(file: Uploadable): Promise { + if (isFileLike(file)) { + return getFileWithMetadata({ + data: file, + }); + } + if ("path" in file) { + const fs = await import("fs"); + if (!fs || !fs.createReadStream) { + throw new Error("File path uploads are not supported in this environment."); + } + const data = fs.createReadStream(file.path); + const contentLength = file.contentLength ?? (await tryGetFileSizeFromPath(file.path)); + const filename = file.filename ?? getNameFromPath(file.path); + return { + data, + filename, + contentType: file.contentType, + contentLength, + }; + } + if ("data" in file) { + const data = file.data; + const contentLength = file.contentLength ?? (await tryGetContentLengthFromFileLike(data)); + const filename = file.filename ?? tryGetNameFromFileLike(data); + return { + data, + filename, + contentType: file.contentType ?? tryGetContentTypeFromFileLike(data), + contentLength, + }; + } + + throw new Error(`Invalid FileUpload of type ${typeof file}: ${JSON.stringify(file)}`); +} + +function isFileLike(value: unknown): value is Uploadable.FileLike { + return ( + isBuffer(value) || + isArrayBufferView(value) || + isArrayBuffer(value) || + isUint8Array(value) || + isBlob(value) || + isFile(value) || + isStreamLike(value) || + isReadableStream(value) + ); +} + +async function tryGetFileSizeFromPath(path: string): Promise { + try { + const fs = await import("fs"); + if (!fs || !fs.promises || !fs.promises.stat) { + return undefined; + } + const fileStat = await fs.promises.stat(path); + return fileStat.size; + } catch (fallbackError) { + return undefined; + } +} + +function tryGetNameFromFileLike(data: Uploadable.FileLike): string | undefined { + if (isNamedValue(data)) { + return data.name; + } + if (isPathedValue(data)) { + return getNameFromPath(data.path.toString()); + } + return undefined; +} + +async function tryGetContentLengthFromFileLike(data: Uploadable.FileLike): Promise { + if (isBuffer(data)) { + return data.length; + } + if (isArrayBufferView(data)) { + return data.byteLength; + } + if (isArrayBuffer(data)) { + return data.byteLength; + } + if (isBlob(data)) { + return data.size; + } + if (isFile(data)) { + return data.size; + } + if (isPathedValue(data)) { + return await tryGetFileSizeFromPath(data.path.toString()); + } + return undefined; +} + +function tryGetContentTypeFromFileLike(data: Uploadable.FileLike): string | undefined { + if (isBlob(data)) { + return data.type; + } + if (isFile(data)) { + return data.type; + } + + return undefined; +} + +function getNameFromPath(path: string): string | undefined { + const lastForwardSlash = path.lastIndexOf("/"); + const lastBackSlash = path.lastIndexOf("\\"); + const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash); + return lastSlashIndex >= 0 ? path.substring(lastSlashIndex + 1) : path; +} + +type NamedValue = { + name: string; +} & unknown; + +type PathedValue = { + path: string | { toString(): string }; +} & unknown; + +type StreamLike = { + read?: () => unknown; + pipe?: (dest: unknown) => unknown; +} & unknown; + +function isNamedValue(value: unknown): value is NamedValue { + return typeof value === "object" && value != null && "name" in value; +} + +function isPathedValue(value: unknown): value is PathedValue { + return typeof value === "object" && value != null && "path" in value; +} + +function isStreamLike(value: unknown): value is StreamLike { + return typeof value === "object" && value != null && ("read" in value || "pipe" in value); +} + +function isReadableStream(value: unknown): value is ReadableStream { + return typeof value === "object" && value != null && "getReader" in value; +} + +function isBuffer(value: unknown): value is Buffer { + return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value); +} + +function isArrayBufferView(value: unknown): value is ArrayBufferView { + return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value); +} + +function isArrayBuffer(value: unknown): value is ArrayBuffer { + return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer; +} + +function isUint8Array(value: unknown): value is Uint8Array { + return typeof Uint8Array !== "undefined" && value instanceof Uint8Array; +} + +function isBlob(value: unknown): value is Blob { + return typeof Blob !== "undefined" && value instanceof Blob; +} + +function isFile(value: unknown): value is File { + return typeof File !== "undefined" && value instanceof File; +} diff --git a/src/core/file/index.ts b/src/core/file/index.ts new file mode 100644 index 0000000..fc16dd5 --- /dev/null +++ b/src/core/file/index.ts @@ -0,0 +1,2 @@ +export * from "./file.js"; +export * from "./types.js"; diff --git a/src/core/file/types.ts b/src/core/file/types.ts new file mode 100644 index 0000000..531b692 --- /dev/null +++ b/src/core/file/types.ts @@ -0,0 +1,81 @@ +/** + * A file that can be uploaded. Can be a file-like object (stream, buffer, blob, etc.), + * a path to a file, or an object with a file-like object and metadata. + */ +export type Uploadable = Uploadable.FileLike | Uploadable.FromPath | Uploadable.WithMetadata; + +export namespace Uploadable { + /** + * Various file-like objects that can be used to upload a file. + */ + export type FileLike = + | ArrayBuffer + | ArrayBufferLike + | ArrayBufferView + | Uint8Array + | import("buffer").Buffer + | import("buffer").Blob + | import("buffer").File + | import("stream").Readable + | import("stream/web").ReadableStream + | globalThis.Blob + | globalThis.File + | ReadableStream; + + /** + * A file path with optional metadata, used for uploading a file from the file system. + */ + export type FromPath = { + /** The path to the file to upload */ + path: string; + /** + * Optional override for the file name (defaults to basename of path). + * This is used to set the `Content-Disposition` header in upload requests. + */ + filename?: string; + /** + * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain'). + * This is used to set the `Content-Type` header in upload requests. + */ + contentType?: string; + /** + * Optional file size in bytes. + * If not provided, the file size will be determined from the file system. + * The content length is used to set the `Content-Length` header in upload requests. + */ + contentLength?: number; + }; + + /** + * A file-like object with metadata, used for uploading files. + */ + export type WithMetadata = { + /** The file data */ + data: FileLike; + /** + * Optional override for the file name (defaults to basename of path). + * This is used to set the `Content-Disposition` header in upload requests. + */ + filename?: string; + /** + * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain'). + * This is used to set the `Content-Type` header in upload requests. + * + * If not provided, the content type may be determined from the data itself. + * * If the data is a `File`, `Blob`, or similar, the content type will be determined from the file itself, if the type is set. + * * Any other data type will not have a content type set, and the upload request will use `Content-Type: application/octet-stream` instead. + */ + contentType?: string; + /** + * Optional file size in bytes. + * The content length is used to set the `Content-Length` header in upload requests. + * If the content length is not provided and cannot be determined, the upload request will not include the `Content-Length` header, but will use `Transfer-Encoding: chunked` instead. + * + * If not provided, the file size will be determined depending on the data type. + * * If the data is of type `fs.ReadStream` (`createReadStream`), the size will be determined from the file system. + * * If the data is a `Buffer`, `ArrayBuffer`, `Uint8Array`, `Blob`, `File`, or similar, the size will be determined from the data itself. + * * If the data is a `Readable` or `ReadableStream`, the size will not be determined. + */ + contentLength?: number; + }; +} diff --git a/src/core/form-data-utils/FormDataWrapper.ts b/src/core/form-data-utils/FormDataWrapper.ts index f7a9830..fa1ca9b 100644 --- a/src/core/form-data-utils/FormDataWrapper.ts +++ b/src/core/form-data-utils/FormDataWrapper.ts @@ -1,145 +1,115 @@ -import { RUNTIME } from "../runtime"; +import { toJson } from "../../core/json.js"; +import { RUNTIME } from "../runtime/index.js"; -export type MaybePromise = Promise | T; +type NamedValue = { + name: string; +} & unknown; -interface FormDataRequest { - body: Body; - headers: Record; - duplex?: "half"; -} +type PathedValue = { + path: string | { toString(): string }; +} & unknown; + +type StreamLike = { + read?: () => unknown; + pipe?: (dest: unknown) => unknown; +} & unknown; -function isNamedValue(value: unknown): value is { name: string } { +function isNamedValue(value: unknown): value is NamedValue { return typeof value === "object" && value != null && "name" in value; } -function isPathedValue(value: unknown): value is { path: unknown } { + +function isPathedValue(value: unknown): value is PathedValue { return typeof value === "object" && value != null && "path" in value; } -function getLastPathSegment(pathStr: string): string { - const lastForwardSlash = pathStr.lastIndexOf("/"); - const lastBackSlash = pathStr.lastIndexOf("\\"); - const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash); - return lastSlashIndex >= 0 ? pathStr.substring(lastSlashIndex + 1) : pathStr; +function isStreamLike(value: unknown): value is StreamLike { + return typeof value === "object" && value != null && ("read" in value || "pipe" in value); } -export interface CrossPlatformFormData { - setup(): Promise; - - append(key: string, value: unknown): void; +function isReadableStream(value: unknown): value is ReadableStream { + return typeof value === "object" && value != null && "getReader" in value; +} - appendFile(key: string, value: unknown, fileName?: string): Promise; +function isBuffer(value: unknown): value is Buffer { + return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value); +} - getRequest(): MaybePromise>; +function isArrayBufferView(value: unknown): value is ArrayBufferView { + return ArrayBuffer.isView(value); } -export async function newFormData(): Promise { - let formdata: CrossPlatformFormData; - if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { - formdata = new Node18FormData(); - } else if (RUNTIME.type === "node") { - formdata = new Node16FormData(); - } else { - formdata = new WebFormData(); - } - await formdata.setup(); - return formdata; +interface FormDataRequest { + body: Body; + headers: Record; + duplex?: "half"; } -export type Node18FormDataFd = - | { - append(name: string, value: unknown, fileName?: string): void; - } - | undefined; +function getLastPathSegment(pathStr: string): string { + const lastForwardSlash = pathStr.lastIndexOf("/"); + const lastBackSlash = pathStr.lastIndexOf("\\"); + const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash); + return lastSlashIndex >= 0 ? pathStr.substring(lastSlashIndex + 1) : pathStr; +} -/** - * Form Data Implementation for Node.js 18+ - */ -export class Node18FormData implements CrossPlatformFormData { - private fd: Node18FormDataFd; +async function streamToBuffer(stream: unknown): Promise { + if (RUNTIME.type === "node") { + const { Readable } = await import("stream"); - public async setup() { - this.fd = new (await import("formdata-node")).FormData(); + if (stream instanceof Readable) { + const chunks: Buffer[] = []; + for await (const chunk of stream) { + chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); + } + return Buffer.concat(chunks); + } } - public append(key: string, value: any): void { - this.fd?.append(key, value); - } + if (isReadableStream(stream)) { + const reader = stream.getReader(); + const chunks: Uint8Array[] = []; - private getFileName(value: any, filename?: string): string | undefined { - if (filename != null) { - return filename; - } - if (isNamedValue(value)) { - return value.name; - } - if (isPathedValue(value) && value.path) { - return getLastPathSegment(value.path.toString()); + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + chunks.push(value); + } + } finally { + reader.releaseLock(); } - return undefined; - } - - public async appendFile(key: string, value: unknown, fileName?: string): Promise { - fileName = this.getFileName(value, fileName); - if (value instanceof Blob) { - this.fd?.append(key, value, fileName); - } else { - this.fd?.append(key, { - type: undefined, - name: fileName, - [Symbol.toStringTag]: "File", - stream() { - return value; - }, - }); + const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0); + const result = new Uint8Array(totalLength); + let offset = 0; + for (const chunk of chunks) { + result.set(chunk, offset); + offset += chunk.length; } - } - public async getRequest(): Promise> { - const encoder = new (await import("form-data-encoder")).FormDataEncoder(this.fd as any); - return { - body: (await import("readable-stream")).Readable.from(encoder), - headers: encoder.headers, - duplex: "half", - }; + return Buffer.from(result); } + + throw new Error( + "Unsupported stream type: " + typeof stream + ". Expected Node.js Readable stream or Web ReadableStream.", + ); +} + +export async function newFormData(): Promise { + return new FormDataWrapper(); } -export type Node16FormDataFd = - | { - append( - name: string, - value: unknown, - options?: - | string - | { - header?: string | Headers; - knownLength?: number; - filename?: string; - filepath?: string; - contentType?: string; - }, - ): void; - - getHeaders(): Record; - } - | undefined; - -/** - * Form Data Implementation for Node.js 16-18 - */ -export class Node16FormData implements CrossPlatformFormData { - private fd: Node16FormDataFd; +export class FormDataWrapper { + private fd: FormData = new FormData(); public async setup(): Promise { - this.fd = new (await import("form-data")).default(); + // noop } - public append(key: string, value: any): void { - this.fd?.append(key, value); + public append(key: string, value: unknown): void { + this.fd.append(key, String(value)); } - private getFileName(value: any, filename?: string): string | undefined { + private getFileName(value: unknown, filename?: string): string | undefined { if (filename != null) { return filename; } @@ -152,74 +122,55 @@ export class Node16FormData implements CrossPlatformFormData { return undefined; } - public async appendFile(key: string, value: unknown, fileName?: string): Promise { - fileName = this.getFileName(value, fileName); + private async convertToBlob(value: unknown): Promise { + if (isStreamLike(value) || isReadableStream(value)) { + const buffer = await streamToBuffer(value); + return new Blob([buffer]); + } - let bufferedValue; if (value instanceof Blob) { - bufferedValue = Buffer.from(await (value as any).arrayBuffer()); - } else { - bufferedValue = value; + return value; } - if (fileName == null) { - this.fd?.append(key, bufferedValue); - } else { - this.fd?.append(key, bufferedValue, { filename: fileName }); + if (isBuffer(value)) { + return new Blob([value]); } - } - - public getRequest(): FormDataRequest { - return { - body: this.fd, - headers: this.fd ? this.fd.getHeaders() : {}, - }; - } -} -export type WebFormDataFd = { append(name: string, value: string | Blob, fileName?: string): void } | undefined; - -/** - * Form Data Implementation for Web - */ -export class WebFormData implements CrossPlatformFormData { - protected fd: WebFormDataFd; - - public async setup(): Promise { - this.fd = new FormData(); - } - - public append(key: string, value: any): void { - this.fd?.append(key, value); - } + if (value instanceof ArrayBuffer) { + return new Blob([value]); + } - private getFileName(value: any, filename?: string): string | undefined { - if (filename != null) { - return filename; + if (isArrayBufferView(value)) { + return new Blob([value]); } - if (isNamedValue(value)) { - return value.name; + + if (typeof value === "string") { + return new Blob([value]); } - if (isPathedValue(value) && value.path) { - return getLastPathSegment(value.path.toString()); + + if (typeof value === "object" && value !== null) { + return new Blob([toJson(value)], { type: "application/json" }); } - return undefined; + + return new Blob([String(value)]); } - public async appendFile(key: string, value: any, fileName?: string): Promise { + public async appendFile(key: string, value: unknown, fileName?: string): Promise { fileName = this.getFileName(value, fileName); + const blob = await this.convertToBlob(value); - if (value instanceof Blob) { - this.fd?.append(key, value, fileName); - return; + if (fileName) { + this.fd.append(key, blob, fileName); + } else { + this.fd.append(key, blob); } - this.fd?.append(key, new Blob([value]), fileName); } - public getRequest(): FormDataRequest { + public getRequest(): FormDataRequest { return { body: this.fd, headers: {}, + duplex: "half" as const, }; } } diff --git a/src/core/form-data-utils/encodeAsFormParameter.ts b/src/core/form-data-utils/encodeAsFormParameter.ts index 3b3f4c1..cfc6741 100644 --- a/src/core/form-data-utils/encodeAsFormParameter.ts +++ b/src/core/form-data-utils/encodeAsFormParameter.ts @@ -1,10 +1,7 @@ -import qs from "qs"; +import { toQueryString } from "../url/qs.js"; -/** - * Takes an unknown value, stringifies it using qs, and parses it into a key-value record - */ export function encodeAsFormParameter(value: unknown): Record { - const stringified = qs.stringify(value, { encode: false }); + const stringified = toQueryString(value, { encode: false }); const keyValuePairs = stringified.split("&").map((pair) => { const [key, value] = pair.split("="); diff --git a/src/core/form-data-utils/index.ts b/src/core/form-data-utils/index.ts index 62121d5..1188f80 100644 --- a/src/core/form-data-utils/index.ts +++ b/src/core/form-data-utils/index.ts @@ -1,2 +1,2 @@ -export { encodeAsFormParameter } from "./encodeAsFormParameter"; -export * from "./FormDataWrapper"; +export { encodeAsFormParameter } from "./encodeAsFormParameter.js"; +export * from "./FormDataWrapper.js"; diff --git a/src/core/headers.ts b/src/core/headers.ts new file mode 100644 index 0000000..561314d --- /dev/null +++ b/src/core/headers.ts @@ -0,0 +1,35 @@ +import * as core from "./index.js"; + +export function mergeHeaders( + ...headersArray: (Record | undefined> | undefined)[] +): Record> { + const result: Record> = {}; + + for (const [key, value] of headersArray + .filter((headers) => headers != null) + .flatMap((headers) => Object.entries(headers))) { + if (value != null) { + result[key] = value; + } else if (key in result) { + delete result[key]; + } + } + + return result; +} + +export function mergeOnlyDefinedHeaders( + ...headersArray: (Record | undefined> | undefined)[] +): Record> { + const result: Record> = {}; + + for (const [key, value] of headersArray + .filter((headers) => headers != null) + .flatMap((headers) => Object.entries(headers))) { + if (value != null) { + result[key] = value; + } + } + + return result; +} diff --git a/src/core/index.ts b/src/core/index.ts index 4f67d9a..60b2566 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,4 +1,7 @@ -export * from "./fetcher"; -export * from "./runtime"; -export * from "./auth"; -export * from "./form-data-utils"; +export * from "./fetcher/index.js"; +export * from "./runtime/index.js"; +export * as url from "./url/index.js"; +export * from "./auth/index.js"; +export * from "./base64.js"; +export * from "./form-data-utils/index.js"; +export * as file from "./file/index.js"; diff --git a/src/core/runtime/index.ts b/src/core/runtime/index.ts index 5c76dbb..cfab23f 100644 --- a/src/core/runtime/index.ts +++ b/src/core/runtime/index.ts @@ -1 +1 @@ -export { RUNTIME } from "./runtime"; +export { RUNTIME } from "./runtime.js"; diff --git a/src/core/runtime/runtime.ts b/src/core/runtime/runtime.ts index a975017..08fd256 100644 --- a/src/core/runtime/runtime.ts +++ b/src/core/runtime/runtime.ts @@ -11,6 +11,9 @@ interface BunGlobal { declare const Deno: DenoGlobal | undefined; declare const Bun: BunGlobal | undefined; declare const EdgeRuntime: string | undefined; +declare const self: typeof globalThis.self & { + importScripts?: unknown; +}; /** * A constant that indicates which environment and version the SDK is running in. @@ -62,7 +65,6 @@ function evaluateRuntime(): Runtime { */ const isWebWorker = typeof self === "object" && - // @ts-ignore typeof self?.importScripts === "function" && (self.constructor?.name === "DedicatedWorkerGlobalScope" || self.constructor?.name === "ServiceWorkerGlobalScope" || diff --git a/src/core/url/index.ts b/src/core/url/index.ts new file mode 100644 index 0000000..ed5aa0f --- /dev/null +++ b/src/core/url/index.ts @@ -0,0 +1,2 @@ +export { join } from "./join.js"; +export { toQueryString } from "./qs.js"; diff --git a/src/core/url/join.ts b/src/core/url/join.ts new file mode 100644 index 0000000..200426b --- /dev/null +++ b/src/core/url/join.ts @@ -0,0 +1,80 @@ +export function join(base: string, ...segments: string[]): string { + if (!base) { + return ""; + } + + if (segments.length === 0) { + return base; + } + + if (base.includes("://")) { + let url: URL; + try { + url = new URL(base); + } catch { + // Fallback to path joining if URL is malformed + return joinPath(base, ...segments); + } + + const lastSegment = segments[segments.length - 1]; + const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/"); + + for (const segment of segments) { + const cleanSegment = trimSlashes(segment); + if (cleanSegment) { + url.pathname = joinPathSegments(url.pathname, cleanSegment); + } + } + + if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) { + url.pathname += "/"; + } + + return url.toString(); + } + + return joinPath(base, ...segments); +} + +function joinPath(base: string, ...segments: string[]): string { + if (segments.length === 0) { + return base; + } + + let result = base; + + const lastSegment = segments[segments.length - 1]; + const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/"); + + for (const segment of segments) { + const cleanSegment = trimSlashes(segment); + if (cleanSegment) { + result = joinPathSegments(result, cleanSegment); + } + } + + if (shouldPreserveTrailingSlash && !result.endsWith("/")) { + result += "/"; + } + + return result; +} + +function joinPathSegments(left: string, right: string): string { + if (left.endsWith("/")) { + return left + right; + } + return left + "/" + right; +} + +function trimSlashes(str: string): string { + if (!str) return str; + + let start = 0; + let end = str.length; + + if (str.startsWith("/")) start = 1; + if (str.endsWith("/")) end = str.length - 1; + + return start === 0 && end === str.length ? str : str.slice(start, end); +} diff --git a/src/core/url/qs.ts b/src/core/url/qs.ts new file mode 100644 index 0000000..13e89be --- /dev/null +++ b/src/core/url/qs.ts @@ -0,0 +1,74 @@ +interface QueryStringOptions { + arrayFormat?: "indices" | "repeat"; + encode?: boolean; +} + +const defaultQsOptions: Required = { + arrayFormat: "indices", + encode: true, +} as const; + +function encodeValue(value: unknown, shouldEncode: boolean): string { + if (value === undefined) { + return ""; + } + if (value === null) { + return ""; + } + const stringValue = String(value); + return shouldEncode ? encodeURIComponent(stringValue) : stringValue; +} + +function stringifyObject(obj: Record, prefix = "", options: Required): string[] { + const parts: string[] = []; + + for (const [key, value] of Object.entries(obj)) { + const fullKey = prefix ? `${prefix}[${key}]` : key; + + if (value === undefined) { + continue; + } + + if (Array.isArray(value)) { + if (value.length === 0) { + continue; + } + for (let i = 0; i < value.length; i++) { + const item = value[i]; + if (item === undefined) { + continue; + } + if (typeof item === "object" && !Array.isArray(item) && item !== null) { + const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey; + parts.push(...stringifyObject(item as Record, arrayKey, options)); + } else { + const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey; + const encodedKey = options.encode ? encodeURIComponent(arrayKey) : arrayKey; + parts.push(`${encodedKey}=${encodeValue(item, options.encode)}`); + } + } + } else if (typeof value === "object" && value !== null) { + if (Object.keys(value as Record).length === 0) { + continue; + } + parts.push(...stringifyObject(value as Record, fullKey, options)); + } else { + const encodedKey = options.encode ? encodeURIComponent(fullKey) : fullKey; + parts.push(`${encodedKey}=${encodeValue(value, options.encode)}`); + } + } + + return parts; +} + +export function toQueryString(obj: unknown, options?: QueryStringOptions): string { + if (obj == null || typeof obj !== "object") { + return ""; + } + + const parts = stringifyObject(obj as Record, "", { + ...defaultQsOptions, + ...options, + }); + return parts.join("&"); +} diff --git a/src/errors/MoniteError.ts b/src/errors/MoniteError.ts index 4f44b50..4e22bee 100644 --- a/src/errors/MoniteError.ts +++ b/src/errors/MoniteError.ts @@ -2,8 +2,8 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../core"; -import { toJson } from "../core/json"; +import * as core from "../core/index.js"; +import { toJson } from "../core/json.js"; export class MoniteError extends Error { public readonly statusCode?: number; diff --git a/src/errors/index.ts b/src/errors/index.ts index 8f63c9a..a104d7e 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,2 +1,2 @@ -export { MoniteError } from "./MoniteError"; -export { MoniteTimeoutError } from "./MoniteTimeoutError"; +export { MoniteError } from "./MoniteError.js"; +export { MoniteTimeoutError } from "./MoniteTimeoutError.js"; diff --git a/src/exports.ts b/src/exports.ts new file mode 100644 index 0000000..7b70ee1 --- /dev/null +++ b/src/exports.ts @@ -0,0 +1 @@ +export * from "./core/exports.js"; diff --git a/src/index.ts b/src/index.ts index fa21f0c..03b951d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -export * as Monite from "./api"; -export { MoniteClient } from "./Client"; -export { MoniteEnvironment } from "./environments"; -export { MoniteError, MoniteTimeoutError } from "./errors"; +export * as Monite from "./api/index.js"; +export { MoniteError, MoniteTimeoutError } from "./errors/index.js"; +export { MoniteClient } from "./Client.js"; +export { MoniteEnvironment } from "./environments.js"; +export * from "./exports.js"; diff --git a/src/version.ts b/src/version.ts index 9b7fc09..659d877 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const SDK_VERSION = "0.3.3"; +export const SDK_VERSION = "0.3.4"; diff --git a/tests/BrowserTestEnvironment.ts b/tests/BrowserTestEnvironment.ts new file mode 100644 index 0000000..0f32bf7 --- /dev/null +++ b/tests/BrowserTestEnvironment.ts @@ -0,0 +1,17 @@ +import { TestEnvironment } from "jest-environment-jsdom"; + +class BrowserTestEnvironment extends TestEnvironment { + async setup() { + await super.setup(); + this.global.Request = Request; + this.global.Response = Response; + this.global.ReadableStream = ReadableStream; + this.global.TextEncoder = TextEncoder; + this.global.TextDecoder = TextDecoder; + this.global.FormData = FormData; + this.global.File = File; + this.global.Blob = Blob; + } +} + +export default BrowserTestEnvironment; diff --git a/tests/mock-server/MockServer.ts b/tests/mock-server/MockServer.ts new file mode 100644 index 0000000..6e258f1 --- /dev/null +++ b/tests/mock-server/MockServer.ts @@ -0,0 +1,29 @@ +import { RequestHandlerOptions } from "msw"; +import type { SetupServer } from "msw/node"; + +import { mockEndpointBuilder } from "./mockEndpointBuilder"; + +export interface MockServerOptions { + baseUrl: string; + server: SetupServer; +} + +export class MockServer { + private readonly server: SetupServer; + public readonly baseUrl: string; + + constructor({ baseUrl, server }: MockServerOptions) { + this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl; + this.server = server; + } + + public mockEndpoint(options?: RequestHandlerOptions): ReturnType { + const builder = mockEndpointBuilder({ + once: options?.once, + onBuild: (handler) => { + this.server.use(handler); + }, + }).baseUrl(this.baseUrl); + return builder; + } +} diff --git a/tests/mock-server/MockServerPool.ts b/tests/mock-server/MockServerPool.ts new file mode 100644 index 0000000..8160806 --- /dev/null +++ b/tests/mock-server/MockServerPool.ts @@ -0,0 +1,106 @@ +import { setupServer } from "msw/node"; + +import { fromJson, toJson } from "../../src/core/json"; +import { MockServer } from "./MockServer"; +import { randomBaseUrl } from "./randomBaseUrl"; + +const mswServer = setupServer(); +interface MockServerOptions { + baseUrl?: string; +} + +async function formatHttpRequest(request: Request, id?: string): Promise { + try { + const clone = request.clone(); + const headers = [...clone.headers.entries()].map(([k, v]) => `${k}: ${v}`).join("\n"); + + let body = ""; + try { + const contentType = clone.headers.get("content-type"); + if (contentType?.includes("application/json")) { + body = toJson(fromJson(await clone.text()), undefined, 2); + } else if (clone.body) { + body = await clone.text(); + } + } catch (e) { + body = "(unable to parse body)"; + } + + const title = id ? `### Request ${id} ###\n` : ""; + const firstLine = `${title}${request.method} ${request.url.toString()} HTTP/1.1`; + + return `\n${firstLine}\n${headers}\n\n${body || "(no body)"}\n`; + } catch (e) { + return `Error formatting request: ${e}`; + } +} + +async function formatHttpResponse(response: Response, id?: string): Promise { + try { + const clone = response.clone(); + const headers = [...clone.headers.entries()].map(([k, v]) => `${k}: ${v}`).join("\n"); + + let body = ""; + try { + const contentType = clone.headers.get("content-type"); + if (contentType?.includes("application/json")) { + body = toJson(fromJson(await clone.text()), undefined, 2); + } else if (clone.body) { + body = await clone.text(); + } + } catch (e) { + body = "(unable to parse body)"; + } + + const title = id ? `### Response for ${id} ###\n` : ""; + const firstLine = `${title}HTTP/1.1 ${response.status} ${response.statusText}`; + + return `\n${firstLine}\n${headers}\n\n${body || "(no body)"}\n`; + } catch (e) { + return `Error formatting response: ${e}`; + } +} + +class MockServerPool { + private servers: MockServer[] = []; + + public createServer(options?: Partial): MockServer { + const baseUrl = options?.baseUrl || randomBaseUrl(); + const server = new MockServer({ baseUrl, server: mswServer }); + this.servers.push(server); + return server; + } + + public getServers(): MockServer[] { + return [...this.servers]; + } + + public listen(): void { + const onUnhandledRequest = process.env.LOG_LEVEL === "debug" ? "warn" : "bypass"; + mswServer.listen({ onUnhandledRequest }); + + if (process.env.LOG_LEVEL === "debug") { + mswServer.events.on("request:start", async ({ request, requestId }) => { + const formattedRequest = await formatHttpRequest(request, requestId); + console.debug("request:start\n" + formattedRequest); + }); + + mswServer.events.on("request:unhandled", async ({ request, requestId }) => { + const formattedRequest = await formatHttpRequest(request, requestId); + console.debug("request:unhandled\n" + formattedRequest); + }); + + mswServer.events.on("response:mocked", async ({ request, response, requestId }) => { + const formattedResponse = await formatHttpResponse(response, requestId); + console.debug("response:mocked\n" + formattedResponse); + }); + } + } + + public close(): void { + this.servers = []; + mswServer.close(); + } +} + +export const mockServerPool = new MockServerPool(); diff --git a/tests/mock-server/mockEndpointBuilder.ts b/tests/mock-server/mockEndpointBuilder.ts new file mode 100644 index 0000000..0b069b2 --- /dev/null +++ b/tests/mock-server/mockEndpointBuilder.ts @@ -0,0 +1,210 @@ +import { DefaultBodyType, HttpHandler, HttpResponse, HttpResponseResolver, http } from "msw"; + +import { url } from "../../src/core"; +import { toJson } from "../../src/core/json"; +import { withHeaders } from "./withHeaders"; +import { withJson } from "./withJson"; + +type HttpMethod = "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head"; + +interface MethodStage { + baseUrl(baseUrl: string): MethodStage; + all(path: string): RequestHeadersStage; + get(path: string): RequestHeadersStage; + post(path: string): RequestHeadersStage; + put(path: string): RequestHeadersStage; + delete(path: string): RequestHeadersStage; + patch(path: string): RequestHeadersStage; + options(path: string): RequestHeadersStage; + head(path: string): RequestHeadersStage; +} + +interface RequestHeadersStage extends RequestBodyStage, ResponseStage { + header(name: string, value: string): RequestHeadersStage; + headers(headers: Record): RequestBodyStage; +} + +interface RequestBodyStage extends ResponseStage { + jsonBody(body: unknown): ResponseStage; +} + +interface ResponseStage { + respondWith(): ResponseStatusStage; +} +interface ResponseStatusStage { + statusCode(statusCode: number): ResponseHeaderStage; +} + +interface ResponseHeaderStage extends ResponseBodyStage, BuildStage { + header(name: string, value: string): ResponseHeaderStage; + headers(headers: Record): ResponseHeaderStage; +} + +interface ResponseBodyStage { + jsonBody(body: unknown): BuildStage; +} + +interface BuildStage { + build(): HttpHandler; +} + +export interface HttpHandlerBuilderOptions { + onBuild?: (handler: HttpHandler) => void; + once?: boolean; +} + +class RequestBuilder implements MethodStage, RequestHeadersStage, RequestBodyStage, ResponseStage { + private method: HttpMethod = "get"; + private _baseUrl: string = ""; + private path: string = "/"; + private readonly predicates: ((resolver: HttpResponseResolver) => HttpResponseResolver)[] = []; + private readonly handlerOptions?: HttpHandlerBuilderOptions; + + constructor(options?: HttpHandlerBuilderOptions) { + this.handlerOptions = options; + } + + baseUrl(baseUrl: string): MethodStage { + this._baseUrl = baseUrl; + return this; + } + + all(path: string): RequestHeadersStage { + this.method = "all"; + this.path = path; + return this; + } + + get(path: string): RequestHeadersStage { + this.method = "get"; + this.path = path; + return this; + } + + post(path: string): RequestHeadersStage { + this.method = "post"; + this.path = path; + return this; + } + + put(path: string): RequestHeadersStage { + this.method = "put"; + this.path = path; + return this; + } + + delete(path: string): RequestHeadersStage { + this.method = "delete"; + this.path = path; + return this; + } + + patch(path: string): RequestHeadersStage { + this.method = "patch"; + this.path = path; + return this; + } + + options(path: string): RequestHeadersStage { + this.method = "options"; + this.path = path; + return this; + } + + head(path: string): RequestHeadersStage { + this.method = "head"; + this.path = path; + return this; + } + + header(name: string, value: string): RequestHeadersStage { + this.predicates.push((resolver) => withHeaders({ [name]: value }, resolver)); + return this; + } + + headers(headers: Record): RequestBodyStage { + this.predicates.push((resolver) => withHeaders(headers, resolver)); + return this; + } + + jsonBody(body: unknown): ResponseStage { + if (body === undefined) { + throw new Error("Undefined is not valid JSON. Do not call jsonBody if you want an empty body."); + } + this.predicates.push((resolver) => withJson(body, resolver)); + return this; + } + + respondWith(): ResponseStatusStage { + return new ResponseBuilder(this.method, this.buildUrl(), this.predicates, this.handlerOptions); + } + + private buildUrl(): string { + return url.join(this._baseUrl, this.path); + } +} + +class ResponseBuilder implements ResponseStatusStage, ResponseHeaderStage, ResponseBodyStage, BuildStage { + private readonly method: HttpMethod; + private readonly url: string; + private readonly requestPredicates: ((resolver: HttpResponseResolver) => HttpResponseResolver)[]; + private readonly handlerOptions?: HttpHandlerBuilderOptions; + + private responseStatusCode: number = 200; + private responseHeaders: Record = {}; + private responseBody: DefaultBodyType = undefined; + + constructor( + method: HttpMethod, + url: string, + requestPredicates: ((resolver: HttpResponseResolver) => HttpResponseResolver)[], + options?: HttpHandlerBuilderOptions, + ) { + this.method = method; + this.url = url; + this.requestPredicates = requestPredicates; + this.handlerOptions = options; + } + + public statusCode(code: number): ResponseHeaderStage { + this.responseStatusCode = code; + return this; + } + + public header(name: string, value: string): ResponseHeaderStage { + this.responseHeaders[name] = value; + return this; + } + + public headers(headers: Record): ResponseHeaderStage { + this.responseHeaders = { ...this.responseHeaders, ...headers }; + return this; + } + + public jsonBody(body: unknown): BuildStage { + if (body === undefined) { + throw new Error("Undefined is not valid JSON. Do not call jsonBody if you expect an empty body."); + } + this.responseBody = toJson(body); + return this; + } + + public build(): HttpHandler { + const responseResolver: HttpResponseResolver = () => { + return new HttpResponse(this.responseBody, { + status: this.responseStatusCode, + headers: this.responseHeaders, + }); + }; + + const finalResolver = this.requestPredicates.reduceRight((acc, predicate) => predicate(acc), responseResolver); + + const handler = http[this.method](this.url, finalResolver, this.handlerOptions); + this.handlerOptions?.onBuild?.(handler); + return handler; + } +} + +export function mockEndpointBuilder(options?: HttpHandlerBuilderOptions): MethodStage { + return new RequestBuilder(options); +} diff --git a/tests/mock-server/randomBaseUrl.ts b/tests/mock-server/randomBaseUrl.ts new file mode 100644 index 0000000..031aa64 --- /dev/null +++ b/tests/mock-server/randomBaseUrl.ts @@ -0,0 +1,4 @@ +export function randomBaseUrl(): string { + const randomString = Math.random().toString(36).substring(2, 15); + return `http://${randomString}.localhost`; +} diff --git a/tests/mock-server/setup.ts b/tests/mock-server/setup.ts new file mode 100644 index 0000000..c216d60 --- /dev/null +++ b/tests/mock-server/setup.ts @@ -0,0 +1,10 @@ +import { afterAll, beforeAll } from "@jest/globals"; + +import { mockServerPool } from "./MockServerPool"; + +beforeAll(() => { + mockServerPool.listen(); +}); +afterAll(() => { + mockServerPool.close(); +}); diff --git a/tests/mock-server/withHeaders.ts b/tests/mock-server/withHeaders.ts new file mode 100644 index 0000000..e77c837 --- /dev/null +++ b/tests/mock-server/withHeaders.ts @@ -0,0 +1,70 @@ +import { HttpResponseResolver, passthrough } from "msw"; + +/** + * Creates a request matcher that validates if request headers match specified criteria + * @param expectedHeaders - Headers to match against + * @param resolver - Response resolver to execute if headers match + */ +export function withHeaders( + expectedHeaders: Record boolean)>, + resolver: HttpResponseResolver, +): HttpResponseResolver { + return (args) => { + const { request } = args; + const { headers } = request; + + const mismatches: Record< + string, + { actual: string | null; expected: string | RegExp | ((value: string) => boolean) } + > = {}; + + for (const [key, expectedValue] of Object.entries(expectedHeaders)) { + const actualValue = headers.get(key); + + if (actualValue === null) { + mismatches[key] = { actual: null, expected: expectedValue }; + continue; + } + + if (typeof expectedValue === "function") { + if (!expectedValue(actualValue)) { + mismatches[key] = { actual: actualValue, expected: expectedValue }; + } + } else if (expectedValue instanceof RegExp) { + if (!expectedValue.test(actualValue)) { + mismatches[key] = { actual: actualValue, expected: expectedValue }; + } + } else if (expectedValue !== actualValue) { + mismatches[key] = { actual: actualValue, expected: expectedValue }; + } + } + + if (Object.keys(mismatches).length > 0) { + const formattedMismatches = formatHeaderMismatches(mismatches); + console.error("Header mismatch:", formattedMismatches); + return passthrough(); + } + + return resolver(args); + }; +} + +function formatHeaderMismatches( + mismatches: Record boolean) }>, +): Record { + const formatted: Record = {}; + + for (const [key, { actual, expected }] of Object.entries(mismatches)) { + formatted[key] = { + actual, + expected: + expected instanceof RegExp + ? expected.toString() + : typeof expected === "function" + ? "[Function]" + : expected, + }; + } + + return formatted; +} diff --git a/tests/mock-server/withJson.ts b/tests/mock-server/withJson.ts new file mode 100644 index 0000000..bfcd9a6 --- /dev/null +++ b/tests/mock-server/withJson.ts @@ -0,0 +1,158 @@ +import { HttpResponseResolver, passthrough } from "msw"; + +import { fromJson, toJson } from "../../src/core/json"; + +/** + * Creates a request matcher that validates if the request JSON body exactly matches the expected object + * @param expectedBody - The exact body object to match against + * @param resolver - Response resolver to execute if body matches + */ +export function withJson(expectedBody: unknown, resolver: HttpResponseResolver): HttpResponseResolver { + return async (args) => { + const { request } = args; + + let clonedRequest: Request; + let bodyText: string | undefined; + let actualBody: unknown; + try { + clonedRequest = request.clone(); + bodyText = await clonedRequest.text(); + if (bodyText === "") { + console.error("Request body is empty, expected a JSON object."); + return passthrough(); + } + actualBody = fromJson(bodyText); + } catch (error) { + console.error(`Error processing request body:\n\tError: ${error}\n\tBody: ${bodyText}`); + return passthrough(); + } + + const mismatches = findMismatches(actualBody, expectedBody); + if (Object.keys(mismatches).length > 0) { + console.error("JSON body mismatch:", toJson(mismatches, undefined, 2)); + return passthrough(); + } + + return resolver(args); + }; +} + +function findMismatches(actual: any, expected: any): Record { + const mismatches: Record = {}; + + if (typeof actual !== typeof expected) { + if (areEquivalent(actual, expected)) { + return {}; + } + return { value: { actual, expected } }; + } + + if (typeof actual !== "object" || actual === null || expected === null) { + if (actual !== expected) { + if (areEquivalent(actual, expected)) { + return {}; + } + return { value: { actual, expected } }; + } + return {}; + } + + if (Array.isArray(actual) && Array.isArray(expected)) { + if (actual.length !== expected.length) { + return { length: { actual: actual.length, expected: expected.length } }; + } + + const arrayMismatches: Record = {}; + for (let i = 0; i < actual.length; i++) { + const itemMismatches = findMismatches(actual[i], expected[i]); + if (Object.keys(itemMismatches).length > 0) { + for (const [mismatchKey, mismatchValue] of Object.entries(itemMismatches)) { + arrayMismatches[`[${i}]${mismatchKey === "value" ? "" : "." + mismatchKey}`] = mismatchValue; + } + } + } + return arrayMismatches; + } + + const actualKeys = Object.keys(actual); + const expectedKeys = Object.keys(expected); + + const allKeys = new Set([...actualKeys, ...expectedKeys]); + + for (const key of allKeys) { + if (!expectedKeys.includes(key)) { + if (actual[key] === undefined) { + continue; // Skip undefined values in actual + } + mismatches[key] = { actual: actual[key], expected: undefined }; + } else if (!actualKeys.includes(key)) { + if (expected[key] === undefined) { + continue; // Skip undefined values in expected + } + mismatches[key] = { actual: undefined, expected: expected[key] }; + } else if ( + typeof actual[key] === "object" && + actual[key] !== null && + typeof expected[key] === "object" && + expected[key] !== null + ) { + const nestedMismatches = findMismatches(actual[key], expected[key]); + if (Object.keys(nestedMismatches).length > 0) { + for (const [nestedKey, nestedValue] of Object.entries(nestedMismatches)) { + mismatches[`${key}${nestedKey === "value" ? "" : "." + nestedKey}`] = nestedValue; + } + } + } else if (actual[key] !== expected[key]) { + if (areEquivalent(actual[key], expected[key])) { + continue; + } + mismatches[key] = { actual: actual[key], expected: expected[key] }; + } + } + + return mismatches; +} + +function areEquivalent(actual: unknown, expected: unknown): boolean { + if (actual === expected) { + return true; + } + if (isEquivalentBigInt(actual, expected)) { + return true; + } + if (isEquivalentDatetime(actual, expected)) { + return true; + } + return false; +} + +function isEquivalentBigInt(actual: unknown, expected: unknown) { + if (typeof actual === "number") { + actual = BigInt(actual); + } + if (typeof expected === "number") { + expected = BigInt(expected); + } + if (typeof actual === "bigint" && typeof expected === "bigint") { + return actual === expected; + } + return false; +} + +function isEquivalentDatetime(str1: unknown, str2: unknown): boolean { + if (typeof str1 !== "string" || typeof str2 !== "string") { + return false; + } + const isoDatePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/; + if (!isoDatePattern.test(str1) || !isoDatePattern.test(str2)) { + return false; + } + + try { + const date1 = new Date(str1).getTime(); + const date2 = new Date(str2).getTime(); + return date1 === date2; + } catch { + return false; + } +} diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..10185ed --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": null, + "rootDir": "..", + "baseUrl": ".." + }, + "include": ["../src", "../tests"], + "exclude": [] +} diff --git a/tests/unit/base64.test.ts b/tests/unit/base64.test.ts new file mode 100644 index 0000000..939594c --- /dev/null +++ b/tests/unit/base64.test.ts @@ -0,0 +1,53 @@ +import { base64Decode, base64Encode } from "../../src/core/base64"; + +describe("base64", () => { + describe("base64Encode", () => { + it("should encode ASCII strings", () => { + expect(base64Encode("hello")).toBe("aGVsbG8="); + expect(base64Encode("")).toBe(""); + }); + + it("should encode UTF-8 strings", () => { + expect(base64Encode("cafΓ©")).toBe("Y2Fmw6k="); + expect(base64Encode("πŸŽ‰")).toBe("8J+OiQ=="); + }); + + it("should handle basic auth credentials", () => { + expect(base64Encode("username:password")).toBe("dXNlcm5hbWU6cGFzc3dvcmQ="); + }); + }); + + describe("base64Decode", () => { + it("should decode ASCII strings", () => { + expect(base64Decode("aGVsbG8=")).toBe("hello"); + expect(base64Decode("")).toBe(""); + }); + + it("should decode UTF-8 strings", () => { + expect(base64Decode("Y2Fmw6k=")).toBe("cafΓ©"); + expect(base64Decode("8J+OiQ==")).toBe("πŸŽ‰"); + }); + + it("should handle basic auth credentials", () => { + expect(base64Decode("dXNlcm5hbWU6cGFzc3dvcmQ=")).toBe("username:password"); + }); + }); + + describe("round-trip encoding", () => { + const testStrings = [ + "hello world", + "test@example.com", + "cafΓ©", + "username:password", + "user@domain.com:super$ecret123!", + ]; + + testStrings.forEach((testString) => { + it(`should round-trip encode/decode: "${testString}"`, () => { + const encoded = base64Encode(testString); + const decoded = base64Decode(encoded); + expect(decoded).toBe(testString); + }); + }); + }); +}); diff --git a/tests/unit/fetcher/Fetcher.test.ts b/tests/unit/fetcher/Fetcher.test.ts index a32945e..f983f08 100644 --- a/tests/unit/fetcher/Fetcher.test.ts +++ b/tests/unit/fetcher/Fetcher.test.ts @@ -1,7 +1,9 @@ import fs from "fs"; +import stream from "stream"; import { join } from "path"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; +import type { BinaryResponse } from "../../../src/core"; describe("Test fetcherImpl", () => { it("should handle successful request", async () => { @@ -12,14 +14,15 @@ describe("Test fetcherImpl", () => { body: { data: "test" }, contentType: "application/json", requestType: "json", + responseType: "json", }; - global.fetch = jest.fn().mockResolvedValue({ - ok: true, - status: 200, - text: () => Promise.resolve(JSON.stringify({ data: "test" })), - json: () => ({ data: "test" }), - }); + global.fetch = jest.fn().mockResolvedValue( + new Response(JSON.stringify({ data: "test" }), { + status: 200, + statusText: "OK", + }), + ); const result = await fetcherImpl(mockArgs); expect(result.ok).toBe(true); @@ -45,16 +48,16 @@ describe("Test fetcherImpl", () => { headers: { "X-Test": "x-test-header" }, contentType: "application/octet-stream", requestType: "bytes", - duplex: "half", + responseType: "json", body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - global.fetch = jest.fn().mockResolvedValue({ - ok: true, - status: 200, - text: () => Promise.resolve(JSON.stringify({ data: "test" })), - json: () => Promise.resolve({ data: "test" }), - }); + global.fetch = jest.fn().mockResolvedValue( + new Response(JSON.stringify({ data: "test" }), { + status: 200, + statusText: "OK", + }), + ); const result = await fetcherImpl(mockArgs); @@ -71,4 +74,183 @@ describe("Test fetcherImpl", () => { expect(result.body).toEqual({ data: "test" }); } }); + + it("should receive file as stream", async () => { + const url = "https://httpbin.org/post/file"; + const mockArgs: Fetcher.Args = { + url, + method: "GET", + headers: { "X-Test": "x-test-header" }, + responseType: "binary-response", + }; + + global.fetch = jest.fn().mockResolvedValue( + new Response( + stream.Readable.toWeb(fs.createReadStream(join(__dirname, "test-file.txt"))) as ReadableStream, + { + status: 200, + statusText: "OK", + }, + ), + ); + + const result = await fetcherImpl(mockArgs); + + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "GET", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + }), + ); + expect(result.ok).toBe(true); + if (result.ok) { + const body = result.body as BinaryResponse; + expect(body).toBeDefined(); + expect(body.bodyUsed).toBe(false); + expect(typeof body.stream).toBe("function"); + const stream = body.stream(); + expect(stream).toBeInstanceOf(ReadableStream); + const reader = stream.getReader(); + const { value } = await reader.read(); + const decoder = new TextDecoder(); + const streamContent = decoder.decode(value); + expect(streamContent).toBe("This is a test file!\n"); + expect(body.bodyUsed).toBe(true); + } + }); + + it("should receive file as blob", async () => { + const url = "https://httpbin.org/post/file"; + const mockArgs: Fetcher.Args = { + url, + method: "GET", + headers: { "X-Test": "x-test-header" }, + responseType: "binary-response", + }; + + global.fetch = jest.fn().mockResolvedValue( + new Response( + stream.Readable.toWeb(fs.createReadStream(join(__dirname, "test-file.txt"))) as ReadableStream, + { + status: 200, + statusText: "OK", + }, + ), + ); + + const result = await fetcherImpl(mockArgs); + + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "GET", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + }), + ); + expect(result.ok).toBe(true); + if (result.ok) { + const body = result.body as BinaryResponse; + expect(body).toBeDefined(); + expect(body.bodyUsed).toBe(false); + expect(typeof body.blob).toBe("function"); + const blob = await body.blob(); + expect(blob).toBeInstanceOf(Blob); + const reader = blob.stream().getReader(); + const { value } = await reader.read(); + const decoder = new TextDecoder(); + const streamContent = decoder.decode(value); + expect(streamContent).toBe("This is a test file!\n"); + expect(body.bodyUsed).toBe(true); + } + }); + + it("should receive file as arraybuffer", async () => { + const url = "https://httpbin.org/post/file"; + const mockArgs: Fetcher.Args = { + url, + method: "GET", + headers: { "X-Test": "x-test-header" }, + responseType: "binary-response", + }; + + global.fetch = jest.fn().mockResolvedValue( + new Response( + stream.Readable.toWeb(fs.createReadStream(join(__dirname, "test-file.txt"))) as ReadableStream, + { + status: 200, + statusText: "OK", + }, + ), + ); + + const result = await fetcherImpl(mockArgs); + + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "GET", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + }), + ); + expect(result.ok).toBe(true); + if (result.ok) { + const body = result.body as BinaryResponse; + expect(body).toBeDefined(); + expect(body.bodyUsed).toBe(false); + expect(typeof body.arrayBuffer).toBe("function"); + const arrayBuffer = await body.arrayBuffer(); + expect(arrayBuffer).toBeInstanceOf(ArrayBuffer); + const decoder = new TextDecoder(); + const streamContent = decoder.decode(new Uint8Array(arrayBuffer)); + expect(streamContent).toBe("This is a test file!\n"); + expect(body.bodyUsed).toBe(true); + } + }); + + it("should receive file as bytes", async () => { + const url = "https://httpbin.org/post/file"; + const mockArgs: Fetcher.Args = { + url, + method: "GET", + headers: { "X-Test": "x-test-header" }, + responseType: "binary-response", + }; + + global.fetch = jest.fn().mockResolvedValue( + new Response( + stream.Readable.toWeb(fs.createReadStream(join(__dirname, "test-file.txt"))) as ReadableStream, + { + status: 200, + statusText: "OK", + }, + ), + ); + + const result = await fetcherImpl(mockArgs); + + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "GET", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + }), + ); + expect(result.ok).toBe(true); + if (result.ok) { + const body = result.body as BinaryResponse; + expect(body).toBeDefined(); + expect(body.bodyUsed).toBe(false); + expect(typeof body.bytes).toBe("function"); + if (!body.bytes) { + return; + } + const bytes = await body.bytes(); + expect(bytes).toBeInstanceOf(Uint8Array); + const decoder = new TextDecoder(); + const streamContent = decoder.decode(bytes); + expect(streamContent).toBe("This is a test file!\n"); + expect(body.bodyUsed).toBe(true); + } + }); }); diff --git a/tests/unit/fetcher/createRequestUrl.test.ts b/tests/unit/fetcher/createRequestUrl.test.ts index 486e1e6..06e03b2 100644 --- a/tests/unit/fetcher/createRequestUrl.test.ts +++ b/tests/unit/fetcher/createRequestUrl.test.ts @@ -48,4 +48,113 @@ describe("Test createRequestUrl", () => { const queryParams = { special: "a&b=c d" }; expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?special=a%26b%3Dc%20d"); }); + + // Additional tests for edge cases and different value types + it("should handle numeric values", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { count: 42, price: 19.99, active: 1, inactive: 0 }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?count=42&price=19.99&active=1&inactive=0", + ); + }); + + it("should handle boolean values", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { enabled: true, disabled: false }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?enabled=true&disabled=false"); + }); + + it("should handle null and undefined values", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + valid: "value", + nullValue: null, + undefinedValue: undefined, + emptyString: "", + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?valid=value&nullValue=&emptyString=", + ); + }); + + it("should handle deeply nested objects", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + user: { + profile: { + name: "John", + settings: { theme: "dark" }, + }, + }, + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?user%5Bprofile%5D%5Bname%5D=John&user%5Bprofile%5D%5Bsettings%5D%5Btheme%5D=dark", + ); + }); + + it("should handle arrays of objects", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + users: [ + { name: "John", age: 30 }, + { name: "Jane", age: 25 }, + ], + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?users%5Bname%5D=John&users%5Bage%5D=30&users%5Bname%5D=Jane&users%5Bage%5D=25", + ); + }); + + it("should handle mixed arrays", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + mixed: ["string", 42, true, { key: "value" }], + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?mixed=string&mixed=42&mixed=true&mixed%5Bkey%5D=value", + ); + }); + + it("should handle empty arrays", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { emptyArray: [] }; + expect(createRequestUrl(baseUrl, queryParams)).toBe(baseUrl); + }); + + it("should handle empty objects", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { emptyObject: {} }; + expect(createRequestUrl(baseUrl, queryParams)).toBe(baseUrl); + }); + + it("should handle special characters in keys", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { "key with spaces": "value", "key[with]brackets": "value" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?key%20with%20spaces=value&key%5Bwith%5Dbrackets=value", + ); + }); + + it("should handle URL with existing query parameters", () => { + const baseUrl = "https://api.example.com?existing=param"; + const queryParams = { new: "value" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?existing=param?new=value"); + }); + + it("should handle complex nested structures", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + filters: { + status: ["active", "pending"], + category: { + type: "electronics", + subcategories: ["phones", "laptops"], + }, + }, + sort: { field: "name", direction: "asc" }, + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?filters%5Bstatus%5D=active&filters%5Bstatus%5D=pending&filters%5Bcategory%5D%5Btype%5D=electronics&filters%5Bcategory%5D%5Bsubcategories%5D=phones&filters%5Bcategory%5D%5Bsubcategories%5D=laptops&sort%5Bfield%5D=name&sort%5Bdirection%5D=asc", + ); + }); }); diff --git a/tests/unit/fetcher/getFetchFn.test.ts b/tests/unit/fetcher/getFetchFn.test.ts deleted file mode 100644 index 9b315ad..0000000 --- a/tests/unit/fetcher/getFetchFn.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { RUNTIME } from "../../../src/core/runtime"; -import { getFetchFn } from "../../../src/core/fetcher/getFetchFn"; - -describe("Test for getFetchFn", () => { - it("should get node-fetch function", async () => { - if (RUNTIME.type == "node") { - if (RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { - expect(await getFetchFn()).toBe(fetch); - } else { - expect(await getFetchFn()).toEqual((await import("node-fetch")).default as any); - } - } - }); - - it("should get fetch function", async () => { - if (RUNTIME.type == "browser") { - const fetchFn = await getFetchFn(); - expect(typeof fetchFn).toBe("function"); - expect(fetchFn.name).toBe("fetch"); - } - }); -}); diff --git a/tests/unit/fetcher/getRequestBody.test.ts b/tests/unit/fetcher/getRequestBody.test.ts index 919604c..e864c8b 100644 --- a/tests/unit/fetcher/getRequestBody.test.ts +++ b/tests/unit/fetcher/getRequestBody.test.ts @@ -1,19 +1,7 @@ -import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; +import { RUNTIME } from "../../../src/core/runtime"; describe("Test getRequestBody", () => { - it("should return FormData as is in Node environment", async () => { - if (RUNTIME.type === "node") { - const formData = new (await import("formdata-node")).FormData(); - formData.append("key", "value"); - const result = await getRequestBody({ - body: formData, - type: "file", - }); - expect(result).toBe(formData); - } - }); - it("should stringify body if not FormData in Node environment", async () => { if (RUNTIME.type === "node") { const body = { key: "value" }; @@ -27,7 +15,7 @@ describe("Test getRequestBody", () => { it("should return FormData in browser environment", async () => { if (RUNTIME.type === "browser") { - const formData = new (await import("form-data")).default(); + const formData = new FormData(); formData.append("key", "value"); const result = await getRequestBody({ body: formData, diff --git a/tests/unit/fetcher/getResponseBody.test.ts b/tests/unit/fetcher/getResponseBody.test.ts index 1030c51..400782f 100644 --- a/tests/unit/fetcher/getResponseBody.test.ts +++ b/tests/unit/fetcher/getResponseBody.test.ts @@ -1,6 +1,5 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; -import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; describe("Test getResponseBody", () => { it("should handle blob response type", async () => { @@ -21,13 +20,27 @@ describe("Test getResponseBody", () => { }); it("should handle streaming response type", async () => { - if (RUNTIME.type === "node") { - const mockStream = new ReadableStream(); - const mockResponse = new Response(mockStream); - const result = await getResponseBody(mockResponse, "streaming"); - // need to reinstantiate string as a result of locked state in Readable Stream after registration with Response - expect(JSON.stringify(result)).toBe(JSON.stringify(await chooseStreamWrapper(new ReadableStream()))); - } + // Create a ReadableStream with some test data + const encoder = new TextEncoder(); + const testData = "test stream data"; + const mockStream = new ReadableStream({ + start(controller) { + controller.enqueue(encoder.encode(testData)); + controller.close(); + }, + }); + + const mockResponse = new Response(mockStream); + const result = (await getResponseBody(mockResponse, "streaming")) as ReadableStream; + + expect(result).toBeInstanceOf(ReadableStream); + + // Read and verify the stream content + const reader = result.getReader(); + const decoder = new TextDecoder(); + const { value } = await reader.read(); + const streamContent = decoder.decode(value); + expect(streamContent).toBe(testData); }); it("should handle text response type", async () => { diff --git a/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts deleted file mode 100644 index 172c1c2..0000000 --- a/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts +++ /dev/null @@ -1,178 +0,0 @@ -import { Node18UniversalStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper"; - -describe("Node18UniversalStreamWrapper", () => { - it("should set encoding to utf-8", async () => { - const rawStream = new ReadableStream(); - const stream = new Node18UniversalStreamWrapper(rawStream); - const setEncodingSpy = jest.spyOn(stream, "setEncoding"); - - stream.setEncoding("utf-8"); - - expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); - }); - - it("should register an event listener for readable", async () => { - const rawStream = new ReadableStream(); - const stream = new Node18UniversalStreamWrapper(rawStream); - const onSpy = jest.spyOn(stream, "on"); - - stream.on("readable", () => {}); - - expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); - }); - - it("should remove an event listener for data", async () => { - const rawStream = new ReadableStream(); - const stream = new Node18UniversalStreamWrapper(rawStream); - const offSpy = jest.spyOn(stream, "off"); - - const fn = () => {}; - stream.on("data", fn); - stream.off("data", fn); - - expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); - }); - - it("should write to dest when calling pipe to writable stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - const dest = new WritableStream({ - write(chunk) { - expect(chunk).toEqual(new TextEncoder().encode("test")); - }, - }); - - stream.pipe(dest); - }); - - it("should write to dest when calling pipe to node writable stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - const dest = new (await import("readable-stream")).Writable({ - write(chunk, encoding, callback) { - expect(chunk.toString()).toEqual("test"); - callback(); - }, - }); - - stream.pipe(dest); - }); - - it("should write nothing when calling pipe and unpipe", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - const buffer: Uint8Array[] = []; - const dest = new WritableStream({ - write(chunk) { - buffer.push(chunk); - }, - }); - - stream.pipe(dest); - stream.unpipe(dest); - expect(buffer).toEqual([]); - }); - - it("should destroy the stream", async () => { - const rawStream = new ReadableStream(); - const stream = new Node18UniversalStreamWrapper(rawStream); - const destroySpy = jest.spyOn(stream, "destroy"); - - stream.destroy(); - - expect(destroySpy).toHaveBeenCalled(); - }); - - it("should pause and resume the stream", async () => { - const rawStream = new ReadableStream(); - const stream = new Node18UniversalStreamWrapper(rawStream); - const pauseSpy = jest.spyOn(stream, "pause"); - const resumeSpy = jest.spyOn(stream, "resume"); - - expect(stream.isPaused).toBe(false); - stream.pause(); - expect(stream.isPaused).toBe(true); - stream.resume(); - - expect(pauseSpy).toHaveBeenCalled(); - expect(resumeSpy).toHaveBeenCalled(); - }); - - it("should read the stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - - expect(await stream.read()).toEqual(new TextEncoder().encode("test")); - expect(await stream.read()).toEqual(new TextEncoder().encode("test")); - }); - - it("should read the stream as text", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - - const data = await stream.text(); - - expect(data).toEqual("testtest"); - }); - - it("should read the stream as json", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode(JSON.stringify({ test: "test" }))); - controller.close(); - }, - }); - const stream = new Node18UniversalStreamWrapper(rawStream); - - const data = await stream.json(); - - expect(data).toEqual({ test: "test" }); - }); - - it("should allow use with async iterable stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - let data = ""; - const stream = new Node18UniversalStreamWrapper(rawStream); - for await (const chunk of stream) { - data += new TextDecoder().decode(chunk); - } - - expect(data).toEqual("testtest"); - }); -}); diff --git a/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts deleted file mode 100644 index 19c2666..0000000 --- a/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { NodePre18StreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/NodePre18StreamWrapper"; - -describe("NodePre18StreamWrapper", () => { - it("should set encoding to utf-8", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const setEncodingSpy = jest.spyOn(stream, "setEncoding"); - - stream.setEncoding("utf-8"); - - expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); - }); - - it("should register an event listener for readable", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const onSpy = jest.spyOn(stream, "on"); - - stream.on("readable", () => {}); - - expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); - }); - - it("should remove an event listener for data", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const offSpy = jest.spyOn(stream, "off"); - - const fn = () => {}; - stream.on("data", fn); - stream.off("data", fn); - - expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); - }); - - it("should write to dest when calling pipe to node writable stream", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const dest = new (await import("readable-stream")).Writable({ - write(chunk, encoding, callback) { - expect(chunk.toString()).toEqual("test"); - callback(); - }, - }); - - stream.pipe(dest); - }); - - it("should write nothing when calling pipe and unpipe", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const buffer: Uint8Array[] = []; - const dest = new (await import("readable-stream")).Writable({ - write(chunk, encoding, callback) { - buffer.push(chunk); - callback(); - }, - }); - stream.pipe(dest); - stream.unpipe(); - - expect(buffer).toEqual([]); - }); - - it("should destroy the stream", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const destroySpy = jest.spyOn(stream, "destroy"); - - stream.destroy(); - - expect(destroySpy).toHaveBeenCalledWith(); - }); - - it("should pause the stream and resume", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - const pauseSpy = jest.spyOn(stream, "pause"); - - stream.pause(); - expect(stream.isPaused).toBe(true); - stream.resume(); - expect(stream.isPaused).toBe(false); - - expect(pauseSpy).toHaveBeenCalledWith(); - }); - - it("should read the stream", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - - expect(await stream.read()).toEqual("test"); - expect(await stream.read()).toEqual("test"); - }); - - it("should read the stream as text", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - const stream = new NodePre18StreamWrapper(rawStream); - - const data = await stream.text(); - - expect(data).toEqual("testtest"); - }); - - it("should read the stream as json", async () => { - const rawStream = (await import("readable-stream")).Readable.from([JSON.stringify({ test: "test" })]); - const stream = new NodePre18StreamWrapper(rawStream); - - const data = await stream.json(); - - expect(data).toEqual({ test: "test" }); - }); - - it("should allow use with async iterable stream", async () => { - const rawStream = (await import("readable-stream")).Readable.from(["test", "test"]); - let data = ""; - const stream = new NodePre18StreamWrapper(rawStream); - for await (const chunk of stream) { - data += chunk; - } - - expect(data).toEqual("testtest"); - }); -}); diff --git a/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts deleted file mode 100644 index 0ea1483..0000000 --- a/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { UndiciStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/UndiciStreamWrapper"; - -describe("UndiciStreamWrapper", () => { - it("should set encoding to utf-8", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const setEncodingSpy = jest.spyOn(stream, "setEncoding"); - - stream.setEncoding("utf-8"); - - expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); - }); - - it("should register an event listener for readable", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const onSpy = jest.spyOn(stream, "on"); - - stream.on("readable", () => {}); - - expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); - }); - - it("should remove an event listener for data", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const offSpy = jest.spyOn(stream, "off"); - - const fn = () => {}; - stream.on("data", fn); - stream.off("data", fn); - - expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); - }); - - it("should write to dest when calling pipe to writable stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new UndiciStreamWrapper(rawStream); - const dest = new WritableStream({ - write(chunk) { - expect(chunk).toEqual(new TextEncoder().encode("test")); - }, - }); - - stream.pipe(dest); - }); - - it("should write nothing when calling pipe and unpipe", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const buffer: Uint8Array[] = []; - const dest = new WritableStream({ - write(chunk) { - buffer.push(chunk); - }, - }); - stream.pipe(dest); - stream.unpipe(dest); - - expect(buffer).toEqual([]); - }); - - it("should destroy the stream", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const destroySpy = jest.spyOn(stream, "destroy"); - - stream.destroy(); - - expect(destroySpy).toHaveBeenCalled(); - }); - - it("should pause and resume the stream", async () => { - const rawStream = new ReadableStream(); - const stream = new UndiciStreamWrapper(rawStream); - const pauseSpy = jest.spyOn(stream, "pause"); - const resumeSpy = jest.spyOn(stream, "resume"); - - expect(stream.isPaused).toBe(false); - stream.pause(); - expect(stream.isPaused).toBe(true); - stream.resume(); - - expect(pauseSpy).toHaveBeenCalled(); - expect(resumeSpy).toHaveBeenCalled(); - }); - - it("should read the stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new UndiciStreamWrapper(rawStream); - - expect(await stream.read()).toEqual(new TextEncoder().encode("test")); - expect(await stream.read()).toEqual(new TextEncoder().encode("test")); - }); - - it("should read the stream as text", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - const stream = new UndiciStreamWrapper(rawStream); - - const data = await stream.text(); - - expect(data).toEqual("testtest"); - }); - - it("should read the stream as json", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode(JSON.stringify({ test: "test" }))); - controller.close(); - }, - }); - const stream = new UndiciStreamWrapper(rawStream); - - const data = await stream.json(); - - expect(data).toEqual({ test: "test" }); - }); - - it("should allow use with async iterable stream", async () => { - const rawStream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode("test")); - controller.enqueue(new TextEncoder().encode("test")); - controller.close(); - }, - }); - let data = ""; - const stream = new UndiciStreamWrapper(rawStream); - for await (const chunk of stream) { - data += new TextDecoder().decode(chunk); - } - - expect(data).toEqual("testtest"); - }); -}); diff --git a/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts deleted file mode 100644 index 8004e9a..0000000 --- a/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { RUNTIME } from "../../../../src/core/runtime"; -import { Node18UniversalStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper"; -import { NodePre18StreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/NodePre18StreamWrapper"; -import { UndiciStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/UndiciStreamWrapper"; -import { chooseStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; - -describe("chooseStreamWrapper", () => { - beforeEach(() => { - RUNTIME.type = "unknown"; - RUNTIME.parsedVersion = 0; - }); - - it('should return a Node18UniversalStreamWrapper when RUNTIME.type is "node" and RUNTIME.parsedVersion is not null and RUNTIME.parsedVersion is greater than or equal to 18', async () => { - const expected = new Node18UniversalStreamWrapper(new ReadableStream()); - RUNTIME.type = "node"; - RUNTIME.parsedVersion = 18; - - const result = await chooseStreamWrapper(new ReadableStream()); - - expect(JSON.stringify(result)).toBe(JSON.stringify(expected)); - }); - - it('should return a NodePre18StreamWrapper when RUNTIME.type is "node" and RUNTIME.parsedVersion is not null and RUNTIME.parsedVersion is less than 18', async () => { - const stream = await import("readable-stream"); - const expected = new NodePre18StreamWrapper(new stream.Readable()); - - RUNTIME.type = "node"; - RUNTIME.parsedVersion = 16; - - const result = await chooseStreamWrapper(new stream.Readable()); - - expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)); - }); - - it('should return a Undici when RUNTIME.type is not "node"', async () => { - const expected = new UndiciStreamWrapper(new ReadableStream()); - RUNTIME.type = "browser"; - - const result = await chooseStreamWrapper(new ReadableStream()); - - expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)); - }); -}); diff --git a/tests/unit/fetcher/stream-wrappers/webpack.test.ts b/tests/unit/fetcher/stream-wrappers/webpack.test.ts deleted file mode 100644 index f7537d3..0000000 --- a/tests/unit/fetcher/stream-wrappers/webpack.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import webpack from "webpack"; - -describe("test env compatibility", () => { - test("webpack", () => { - return new Promise((resolve, reject) => { - webpack( - { - mode: "production", - entry: "./src/index.ts", - module: { - rules: [ - { - test: /\.tsx?$/, - use: "ts-loader", - exclude: /node_modules/, - }, - ], - }, - resolve: { - extensions: [".tsx", ".ts", ".jsx", ".js"], - extensionAlias: { - ".js": [".ts", ".js"], - ".jsx": [".tsx", ".jsx"], - }, - }, - }, - (err, stats) => { - try { - expect(err).toBe(null); - if (stats?.hasErrors()) { - console.log(stats?.toString()); - } - expect(stats?.hasErrors()).toBe(false); - resolve(); - } catch (error) { - reject(error); - } - }, - ); - }); - }, 180_000); -}); diff --git a/tests/unit/file/file.test.ts b/tests/unit/file/file.test.ts new file mode 100644 index 0000000..0bc7c87 --- /dev/null +++ b/tests/unit/file/file.test.ts @@ -0,0 +1,540 @@ +import fs from "fs"; +import { join } from "path"; +import { Readable } from "stream"; +import { toBinaryUploadRequest, Uploadable } from "../../../src/core/file/index"; + +describe("toBinaryUploadRequest", () => { + const TEST_FILE_PATH = join(__dirname, "test-file.txt"); + + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe("Buffer input", () => { + it("should handle Buffer with all metadata", async () => { + const buffer = Buffer.from("test data"); + const input: Uploadable.WithMetadata = { + data: buffer, + filename: "test.txt", + contentType: "text/plain", + contentLength: 42, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="test.txt"', + "Content-Type": "text/plain", + "Content-Length": "42", + }); + }); + + it("should handle Buffer without metadata", async () => { + const buffer = Buffer.from("test data"); + const input: Uploadable.WithMetadata = { + data: buffer, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Length": "9", // buffer.length + }); + }); + + it("should handle Buffer passed directly", async () => { + const buffer = Buffer.from("test data"); + + const result = await toBinaryUploadRequest(buffer); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Length": "9", // buffer.length + }); + }); + }); + + describe("ArrayBuffer input", () => { + it("should handle ArrayBuffer with metadata", async () => { + const arrayBuffer = new ArrayBuffer(10); + const input: Uploadable.WithMetadata = { + data: arrayBuffer, + filename: "data.bin", + contentType: "application/octet-stream", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(arrayBuffer); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="data.bin"', + "Content-Type": "application/octet-stream", + "Content-Length": "10", // arrayBuffer.byteLength + }); + }); + + it("should handle ArrayBuffer passed directly", async () => { + const arrayBuffer = new ArrayBuffer(10); + + const result = await toBinaryUploadRequest(arrayBuffer); + + expect(result.body).toBe(arrayBuffer); + expect(result.headers).toEqual({ + "Content-Length": "10", // arrayBuffer.byteLength + }); + }); + }); + + describe("Uint8Array input", () => { + it("should handle Uint8Array with metadata", async () => { + const uint8Array = new Uint8Array([1, 2, 3, 4, 5]); + const input: Uploadable.WithMetadata = { + data: uint8Array, + filename: "bytes.bin", + contentType: "application/octet-stream", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(uint8Array); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="bytes.bin"', + "Content-Type": "application/octet-stream", + "Content-Length": "5", // uint8Array.byteLength + }); + }); + + it("should handle Uint8Array passed directly", async () => { + const uint8Array = new Uint8Array([1, 2, 3, 4, 5]); + + const result = await toBinaryUploadRequest(uint8Array); + + expect(result.body).toBe(uint8Array); + expect(result.headers).toEqual({ + "Content-Length": "5", // uint8Array.byteLength + }); + }); + }); + + describe("Blob input", () => { + it("should handle Blob with metadata", async () => { + const blob = new Blob(["test content"], { type: "text/plain" }); + const input: Uploadable.WithMetadata = { + data: blob, + filename: "override.txt", + contentType: "text/html", // Override blob's type + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(blob); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="override.txt"', + "Content-Type": "text/html", // Should use provided contentType + "Content-Length": "12", // blob.size + }); + }); + + it("should handle Blob with intrinsic type", async () => { + const blob = new Blob(["test content"], { type: "application/json" }); + const input: Uploadable.WithMetadata = { + data: blob, + filename: "data.json", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(blob); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="data.json"', + "Content-Type": "application/json", // Should use blob's type + "Content-Length": "12", // blob.size + }); + }); + + it("should handle Blob passed directly", async () => { + const blob = new Blob(["test content"], { type: "text/plain" }); + + const result = await toBinaryUploadRequest(blob); + + expect(result.body).toBe(blob); + expect(result.headers).toEqual({ + "Content-Type": "text/plain", // Should use blob's type + "Content-Length": "12", // blob.size + }); + }); + }); + + describe("File input", () => { + it("should handle File with metadata", async () => { + const file = new File(["file content"], "original.txt", { type: "text/plain" }); + const input: Uploadable.WithMetadata = { + data: file, + filename: "renamed.txt", + contentType: "text/html", // Override file's type + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(file); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="renamed.txt"', + "Content-Type": "text/html", // Should use provided contentType + "Content-Length": "12", // file.size + }); + }); + + it("should handle File with intrinsic properties", async () => { + const file = new File(["file content"], "test.json", { type: "application/json" }); + const input: Uploadable.WithMetadata = { + data: file, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(file); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="test.json"', // Should use file's name + "Content-Type": "application/json", // Should use file's type + "Content-Length": "12", // file.size + }); + }); + + it("should handle File passed directly", async () => { + const file = new File(["file content"], "direct.txt", { type: "text/plain" }); + + const result = await toBinaryUploadRequest(file); + + expect(result.body).toBe(file); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="direct.txt"', + "Content-Type": "text/plain", + "Content-Length": "12", // file.size + }); + }); + }); + + describe("ReadableStream input", () => { + it("should handle ReadableStream with metadata", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("stream data")); + controller.close(); + }, + }); + const input: Uploadable.WithMetadata = { + data: stream, + filename: "stream.txt", + contentType: "text/plain", + contentLength: 100, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(stream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="stream.txt"', + "Content-Type": "text/plain", + "Content-Length": "100", // Should use provided contentLength + }); + }); + + it("should handle ReadableStream without size", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("stream data")); + controller.close(); + }, + }); + const input: Uploadable.WithMetadata = { + data: stream, + filename: "stream.txt", + contentType: "text/plain", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(stream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="stream.txt"', + "Content-Type": "text/plain", + // No Content-Length header since it cannot be determined from ReadableStream + }); + }); + + it("should handle ReadableStream passed directly", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("stream data")); + controller.close(); + }, + }); + + const result = await toBinaryUploadRequest(stream); + + expect(result.body).toBe(stream); + expect(result.headers).toEqual({ + // No headers since no metadata provided and cannot be determined + }); + }); + }); + + describe("Node.js Readable stream input", () => { + it("should handle Readable stream with metadata", async () => { + const readable = new Readable({ + read() { + this.push("readable data"); + this.push(null); + }, + }); + const input: Uploadable.WithMetadata = { + data: readable, + filename: "readable.txt", + contentType: "text/plain", + contentLength: 50, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(readable); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="readable.txt"', + "Content-Type": "text/plain", + "Content-Length": "50", // Should use provided contentLength + }); + }); + + it("should handle Readable stream without size", async () => { + const readable = new Readable({ + read() { + this.push("readable data"); + this.push(null); + }, + }); + const input: Uploadable.WithMetadata = { + data: readable, + filename: "readable.txt", + contentType: "text/plain", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(readable); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="readable.txt"', + "Content-Type": "text/plain", + // No Content-Length header since it cannot be determined from Readable + }); + }); + + it("should handle Readable stream passed directly", async () => { + const readable = new Readable({ + read() { + this.push("readable data"); + this.push(null); + }, + }); + + const result = await toBinaryUploadRequest(readable); + + expect(result.body).toBe(readable); + expect(result.headers).toEqual({ + // No headers since no metadata provided and cannot be determined + }); + }); + }); + + describe("File path input (FromPath type)", () => { + it("should handle file path with all metadata", async () => { + const input: Uploadable.FromPath = { + path: TEST_FILE_PATH, + filename: "custom.txt", + contentType: "text/html", + contentLength: 42, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBeInstanceOf(fs.ReadStream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="custom.txt"', + "Content-Type": "text/html", + "Content-Length": "42", // Should use provided contentLength + }); + }); + + it("should handle file path with minimal metadata", async () => { + const input: Uploadable.FromPath = { + path: TEST_FILE_PATH, + contentType: "text/plain", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBeInstanceOf(fs.ReadStream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="test-file.txt"', // Should extract from path + "Content-Type": "text/plain", + "Content-Length": "21", // Should determine from file system (test file is 21 bytes) + }); + }); + + it("should handle file path with no metadata", async () => { + const input: Uploadable.FromPath = { + path: TEST_FILE_PATH, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBeInstanceOf(fs.ReadStream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="test-file.txt"', // Should extract from path + "Content-Length": "21", // Should determine from file system (test file is 21 bytes) + }); + }); + + it("should handle Windows-style paths", async () => { + const input: Uploadable.FromPath = { + path: "C:\\Users\\test\\file.txt", + }; + + // Mock fs methods to avoid actual file system access + const mockStats = { size: 123 }; + const mockReadStream = {} as fs.ReadStream; + + const createReadStreamSpy = jest.spyOn(fs, "createReadStream").mockReturnValue(mockReadStream); + const statSpy = jest.spyOn(fs.promises, "stat").mockResolvedValue(mockStats as fs.Stats); + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(mockReadStream); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="file.txt"', // Should extract from Windows path + "Content-Length": "123", + }); + + // Restore mocks + createReadStreamSpy.mockRestore(); + statSpy.mockRestore(); + }); + + it("should handle file path when fs is not available", async () => { + const input: Uploadable.FromPath = { + path: TEST_FILE_PATH, + }; + + // Mock import to simulate environment without fs + const originalImport = jest.requireActual("fs"); + jest.doMock("fs", () => null); + + await expect(toBinaryUploadRequest(input)).rejects.toThrow( + "File path uploads are not supported in this environment.", + ); + + // Restore fs + jest.doMock("fs", () => originalImport); + }); + }); + + describe("ArrayBufferView input", () => { + it("should handle ArrayBufferView with metadata", async () => { + const arrayBuffer = new ArrayBuffer(10); + const arrayBufferView = new Int8Array(arrayBuffer); + const input: Uploadable.WithMetadata = { + data: arrayBufferView, + filename: "view.bin", + contentType: "application/octet-stream", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(arrayBufferView); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="view.bin"', + "Content-Type": "application/octet-stream", + "Content-Length": "10", // arrayBufferView.byteLength + }); + }); + + it("should handle ArrayBufferView passed directly", async () => { + const arrayBuffer = new ArrayBuffer(10); + const arrayBufferView = new Int8Array(arrayBuffer); + + const result = await toBinaryUploadRequest(arrayBufferView); + + expect(result.body).toBe(arrayBufferView); + expect(result.headers).toEqual({ + "Content-Length": "10", // arrayBufferView.byteLength + }); + }); + }); + + describe("Edge cases", () => { + it("should handle empty headers when no metadata is available", async () => { + const buffer = Buffer.from(""); + const input: Uploadable.WithMetadata = { + data: buffer, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Length": "0", + }); + }); + + it("should handle zero contentLength", async () => { + const buffer = Buffer.from("test"); + const input: Uploadable.WithMetadata = { + data: buffer, + contentLength: 0, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Length": "0", // Should use provided 0 + }); + }); + + it("should handle null filename", async () => { + const buffer = Buffer.from("test"); + const input: Uploadable.WithMetadata = { + data: buffer, + filename: undefined, + contentType: "text/plain", + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Type": "text/plain", + "Content-Length": "4", + // No Content-Disposition since filename is undefined + }); + }); + + it("should handle null contentType", async () => { + const buffer = Buffer.from("test"); + const input: Uploadable.WithMetadata = { + data: buffer, + filename: "test.txt", + contentType: undefined, + }; + + const result = await toBinaryUploadRequest(input); + + expect(result.body).toBe(buffer); + expect(result.headers).toEqual({ + "Content-Disposition": 'attachment; filename="test.txt"', + "Content-Length": "4", + // No Content-Type since contentType is undefined + }); + }); + }); +}); diff --git a/tests/unit/file/test-file.txt b/tests/unit/file/test-file.txt new file mode 100644 index 0000000..c66d471 --- /dev/null +++ b/tests/unit/file/test-file.txt @@ -0,0 +1 @@ +This is a test file! diff --git a/tests/unit/form-data-utils/encodeAsFormParameter.test.ts b/tests/unit/form-data-utils/encodeAsFormParameter.test.ts new file mode 100644 index 0000000..d4b0c45 --- /dev/null +++ b/tests/unit/form-data-utils/encodeAsFormParameter.test.ts @@ -0,0 +1,344 @@ +import { encodeAsFormParameter } from "../../../src/core/form-data-utils/encodeAsFormParameter"; + +describe("encodeAsFormParameter", () => { + describe("Basic functionality", () => { + it("should return empty object for null/undefined", () => { + expect(encodeAsFormParameter(null)).toEqual({}); + expect(encodeAsFormParameter(undefined)).toEqual({}); + }); + + it("should return empty object for primitive values", () => { + expect(encodeAsFormParameter("hello")).toEqual({}); + expect(encodeAsFormParameter(42)).toEqual({}); + expect(encodeAsFormParameter(true)).toEqual({}); + }); + + it("should handle simple key-value pairs", () => { + const obj = { name: "John", age: 30 }; + expect(encodeAsFormParameter(obj)).toEqual({ + name: "John", + age: "30", + }); + }); + + it("should handle empty objects", () => { + expect(encodeAsFormParameter({})).toEqual({}); + }); + }); + + describe("Array handling", () => { + it("should handle arrays with indices format (default)", () => { + const obj = { items: ["a", "b", "c"] }; + expect(encodeAsFormParameter(obj)).toEqual({ + "items[0]": "a", + "items[1]": "b", + "items[2]": "c", + }); + }); + + it("should handle empty arrays", () => { + const obj = { items: [] }; + expect(encodeAsFormParameter(obj)).toEqual({}); + }); + + it("should handle arrays with mixed types", () => { + const obj = { mixed: ["string", 42, true, false] }; + expect(encodeAsFormParameter(obj)).toEqual({ + "mixed[0]": "string", + "mixed[1]": "42", + "mixed[2]": "true", + "mixed[3]": "false", + }); + }); + + it("should handle arrays with objects", () => { + const obj = { users: [{ name: "John" }, { name: "Jane" }] }; + expect(encodeAsFormParameter(obj)).toEqual({ + "users[0][name]": "John", + "users[1][name]": "Jane", + }); + }); + + it("should handle arrays with null/undefined values", () => { + const obj = { items: ["a", null, "c", undefined, "e"] }; + expect(encodeAsFormParameter(obj)).toEqual({ + "items[0]": "a", + "items[1]": "", + "items[2]": "c", + "items[4]": "e", + }); + }); + }); + + describe("Nested objects", () => { + it("should handle nested objects", () => { + const obj = { user: { name: "John", age: 30 } }; + expect(encodeAsFormParameter(obj)).toEqual({ + "user[name]": "John", + "user[age]": "30", + }); + }); + + it("should handle deeply nested objects", () => { + const obj = { user: { profile: { name: "John", settings: { theme: "dark" } } } }; + expect(encodeAsFormParameter(obj)).toEqual({ + "user[profile][name]": "John", + "user[profile][settings][theme]": "dark", + }); + }); + + it("should handle empty nested objects", () => { + const obj = { user: {} }; + expect(encodeAsFormParameter(obj)).toEqual({}); + }); + }); + + describe("Special characters and encoding", () => { + it("should not encode values (encode: false is used)", () => { + const obj = { name: "John Doe", email: "john@example.com" }; + expect(encodeAsFormParameter(obj)).toEqual({ + name: "John Doe", + email: "john@example.com", + }); + }); + + it("should not encode special characters in keys", () => { + const obj = { "user name": "John", "email[primary]": "john@example.com" }; + expect(encodeAsFormParameter(obj)).toEqual({ + "user name": "John", + "email[primary]": "john@example.com", + }); + }); + + it("should handle values that contain special characters", () => { + const obj = { + query: "search term with spaces", + filter: "category:electronics", + }; + expect(encodeAsFormParameter(obj)).toEqual({ + query: "search term with spaces", + filter: "category:electronics", + }); + }); + + it("should handle ampersand and equals characters (edge case)", () => { + // Note: Values containing & and = may be problematic because + // encodeAsFormParameter splits on these characters when parsing the stringified result + const obj = { + message: "Hello & welcome", + equation: "x = y + z", + }; + // This demonstrates the limitation - ampersands and equals signs in values + // will cause the parameter to be split incorrectly + const result = encodeAsFormParameter(obj); + + // We expect this to be parsed incorrectly due to the implementation + expect(result.message).toBe("Hello "); + expect(result[" welcome"]).toBeUndefined(); + expect(result.equation).toBe("x "); + expect(result[" y + z"]).toBeUndefined(); + }); + }); + + describe("Form data specific scenarios", () => { + it("should handle file upload metadata", () => { + const metadata = { + file: { + name: "document.pdf", + size: 1024, + type: "application/pdf", + }, + options: { + compress: true, + quality: 0.8, + }, + }; + expect(encodeAsFormParameter(metadata)).toEqual({ + "file[name]": "document.pdf", + "file[size]": "1024", + "file[type]": "application/pdf", + "options[compress]": "true", + "options[quality]": "0.8", + }); + }); + + it("should handle form validation data", () => { + const formData = { + fields: ["name", "email", "phone"], + validation: { + required: ["name", "email"], + patterns: { + email: "^[^@]+@[^@]+\\.[^@]+$", + phone: "^\\+?[1-9]\\d{1,14}$", + }, + }, + }; + expect(encodeAsFormParameter(formData)).toEqual({ + "fields[0]": "name", + "fields[1]": "email", + "fields[2]": "phone", + "validation[required][0]": "name", + "validation[required][1]": "email", + "validation[patterns][email]": "^[^@]+@[^@]+\\.[^@]+$", + "validation[patterns][phone]": "^\\+?[1-9]\\d{1,14}$", + }); + }); + + it("should handle search/filter parameters", () => { + const searchParams = { + filters: { + status: ["active", "pending"], + category: { + type: "electronics", + subcategories: ["phones", "laptops"], + }, + }, + sort: { field: "name", direction: "asc" }, + pagination: { page: 1, limit: 20 }, + }; + expect(encodeAsFormParameter(searchParams)).toEqual({ + "filters[status][0]": "active", + "filters[status][1]": "pending", + "filters[category][type]": "electronics", + "filters[category][subcategories][0]": "phones", + "filters[category][subcategories][1]": "laptops", + "sort[field]": "name", + "sort[direction]": "asc", + "pagination[page]": "1", + "pagination[limit]": "20", + }); + }); + }); + + describe("Edge cases", () => { + it("should handle boolean values", () => { + const obj = { enabled: true, disabled: false }; + expect(encodeAsFormParameter(obj)).toEqual({ + enabled: "true", + disabled: "false", + }); + }); + + it("should handle empty strings", () => { + const obj = { name: "", description: "test" }; + expect(encodeAsFormParameter(obj)).toEqual({ + name: "", + description: "test", + }); + }); + + it("should handle zero values", () => { + const obj = { count: 0, price: 0.0 }; + expect(encodeAsFormParameter(obj)).toEqual({ + count: "0", + price: "0", + }); + }); + + it("should handle numeric keys", () => { + const obj = { "0": "zero", "1": "one" }; + expect(encodeAsFormParameter(obj)).toEqual({ + "0": "zero", + "1": "one", + }); + }); + + it("should handle objects with null/undefined values", () => { + const obj = { name: "John", age: null, email: undefined, active: true }; + expect(encodeAsFormParameter(obj)).toEqual({ + name: "John", + age: "", + active: "true", + }); + }); + }); + + describe("Integration with form submission", () => { + it("should produce form-compatible key-value pairs", () => { + const formObject = { + username: "john_doe", + preferences: { + theme: "dark", + notifications: ["email", "push"], + settings: { + autoSave: true, + timeout: 300, + }, + }, + }; + + const result = encodeAsFormParameter(formObject); + + // Verify all values are strings (as required for form data) + Object.values(result).forEach((value) => { + expect(typeof value).toBe("string"); + }); + + // Verify the structure can be reconstructed + expect(result).toEqual({ + username: "john_doe", + "preferences[theme]": "dark", + "preferences[notifications][0]": "email", + "preferences[notifications][1]": "push", + "preferences[settings][autoSave]": "true", + "preferences[settings][timeout]": "300", + }); + }); + + it("should handle complex nested arrays for API parameters", () => { + const apiParams = { + query: { + filters: [ + { field: "status", operator: "eq", value: "active" }, + { field: "created", operator: "gte", value: "2023-01-01" }, + ], + sort: [ + { field: "name", direction: "asc" }, + { field: "created", direction: "desc" }, + ], + }, + }; + + const result = encodeAsFormParameter(apiParams); + expect(result).toEqual({ + "query[filters][0][field]": "status", + "query[filters][0][operator]": "eq", + "query[filters][0][value]": "active", + "query[filters][1][field]": "created", + "query[filters][1][operator]": "gte", + "query[filters][1][value]": "2023-01-01", + "query[sort][0][field]": "name", + "query[sort][0][direction]": "asc", + "query[sort][1][field]": "created", + "query[sort][1][direction]": "desc", + }); + }); + }); + + describe("Error cases and malformed input", () => { + it("should handle circular references gracefully", () => { + const obj: any = { name: "test" }; + obj.self = obj; + + // This will throw a RangeError due to stack overflow - this is expected behavior + expect(() => encodeAsFormParameter(obj)).toThrow("Maximum call stack size exceeded"); + }); + + it("should handle very deeply nested objects", () => { + let deepObj: any = { value: "deep" }; + for (let i = 0; i < 100; i++) { + deepObj = { level: deepObj }; + } + + expect(() => encodeAsFormParameter(deepObj)).not.toThrow(); + const result = encodeAsFormParameter(deepObj); + expect(Object.keys(result).length).toBeGreaterThan(0); + }); + + it("should handle empty string splitting edge case", () => { + // Test what happens when qs returns an empty string + const result = encodeAsFormParameter({}); + expect(result).toEqual({}); + }); + }); +}); diff --git a/tests/unit/form-data-utils/formDataWrapper.browser.test.ts b/tests/unit/form-data-utils/formDataWrapper.browser.test.ts new file mode 100644 index 0000000..f766761 --- /dev/null +++ b/tests/unit/form-data-utils/formDataWrapper.browser.test.ts @@ -0,0 +1,378 @@ +import { FormDataWrapper, newFormData } from "../../../src/core/form-data-utils/FormDataWrapper"; + +type FormDataRequest = ReturnType["getRequest"]>; + +async function getFormDataInfo(formRequest: FormDataRequest): Promise<{ + hasFile: boolean; + filename?: string; + contentType?: string; + serialized: string; +}> { + const request = new Request("http://localhost", { + ...formRequest, + method: "POST", + }); + const buffer = await request.arrayBuffer(); + const serialized = new TextDecoder().decode(buffer); + + const filenameMatch = serialized.match(/filename="([^"]+)"/); + const filename = filenameMatch ? filenameMatch[1] : undefined; + + const contentTypeMatch = serialized.match(/Content-Type: ([^\r\n]+)/); + const contentType = contentTypeMatch ? contentTypeMatch[1] : undefined; + + return { + hasFile: !!filename, + filename, + contentType, + serialized, + }; +} + +describe("FormDataWrapper - Browser Environment", () => { + let formData: FormDataWrapper; + + beforeEach(async () => { + formData = new FormDataWrapper(); + await formData.setup(); + }); + + describe("Web ReadableStream", () => { + it("serializes Web ReadableStream with filename", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("web stream content")); + controller.close(); + }, + }); + + await formData.appendFile("file", stream, "webstream.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="webstream.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("webstream.txt"); + }); + + it("handles empty Web ReadableStream", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.close(); + }, + }); + + await formData.appendFile("file", stream, "empty.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="empty.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("empty.txt"); + }); + }); + + describe("Browser-specific types", () => { + it("serializes Blob with specified filename and content type", async () => { + const blob = new Blob(["file content"], { type: "text/plain" }); + await formData.appendFile("file", blob, "testfile.txt"); + + const { serialized, hasFile, contentType, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="testfile.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("testfile.txt"); + expect(contentType).toBe("text/plain"); + }); + + it("serializes File and preserves filename", async () => { + const file = new File(["file content"], "testfile.txt", { type: "text/plain" }); + await formData.appendFile("file", file); + + const { serialized, hasFile, contentType, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="testfile.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("testfile.txt"); + expect(contentType).toBe("text/plain"); + }); + + it("allows filename override for File objects", async () => { + const file = new File(["file content"], "original.txt", { type: "text/plain" }); + await formData.appendFile("file", file, "override.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="override.txt"'); + expect(serialized).not.toContain('filename="original.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("override.txt"); + }); + }); + + describe("Binary data types", () => { + it("serializes ArrayBuffer with filename", async () => { + const arrayBuffer = new ArrayBuffer(8); + new Uint8Array(arrayBuffer).set([1, 2, 3, 4, 5, 6, 7, 8]); + + await formData.appendFile("file", arrayBuffer, "binary.bin"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="binary.bin"'); + expect(hasFile).toBe(true); + expect(filename).toBe("binary.bin"); + }); + + it("serializes Uint8Array with filename", async () => { + const uint8Array = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" + await formData.appendFile("file", uint8Array, "binary.bin"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="binary.bin"'); + expect(hasFile).toBe(true); + expect(filename).toBe("binary.bin"); + }); + + it("serializes other typed arrays", async () => { + const int16Array = new Int16Array([1000, 2000, 3000]); + await formData.appendFile("file", int16Array, "numbers.bin"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="numbers.bin"'); + expect(hasFile).toBe(true); + expect(filename).toBe("numbers.bin"); + }); + }); + + describe("Text and primitive types", () => { + it("serializes string as regular form field", async () => { + formData.append("text", "test string"); + + const { serialized, hasFile } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="text"'); + expect(serialized).not.toContain("filename="); + expect(serialized).toContain("test string"); + expect(hasFile).toBe(false); + }); + + it("serializes string as file with filename", async () => { + await formData.appendFile("file", "test content", "text.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="text.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("text.txt"); + }); + + it("serializes numbers and booleans as strings", async () => { + formData.append("number", 12345); + formData.append("flag", true); + + const { serialized } = await getFormDataInfo(formData.getRequest()); + expect(serialized).toContain("12345"); + expect(serialized).toContain("true"); + }); + }); + + describe("Object and JSON handling", () => { + it("serializes objects as JSON with filename", async () => { + const obj = { test: "value", nested: { key: "data" } }; + await formData.appendFile("data", obj, "data.json"); + + const { serialized, hasFile, contentType, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="data"'); + expect(serialized).toContain('filename="data.json"'); + expect(serialized).toContain("Content-Type: application/json"); + expect(hasFile).toBe(true); + expect(filename).toBe("data.json"); + expect(contentType).toBe("application/json"); + }); + + it("serializes arrays as JSON", async () => { + const arr = [1, 2, 3, "test"]; + await formData.appendFile("array", arr, "array.json"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="array"'); + expect(serialized).toContain('filename="array.json"'); + expect(hasFile).toBe(true); + expect(filename).toBe("array.json"); + }); + + it("handles null and undefined values", async () => { + formData.append("nullValue", null); + formData.append("undefinedValue", undefined); + + const { serialized } = await getFormDataInfo(formData.getRequest()); + expect(serialized).toContain("null"); + expect(serialized).toContain("undefined"); + }); + }); + + describe("Filename extraction from objects", () => { + it("extracts filename from object with name property", async () => { + const namedValue = { name: "custom-name.txt", data: "content" }; + await formData.appendFile("file", namedValue); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="custom-name.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("custom-name.txt"); + }); + + it("extracts filename from object with path property", async () => { + const pathedValue = { path: "/some/path/file.txt", content: "data" }; + await formData.appendFile("file", pathedValue); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="file.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("file.txt"); + }); + + it("prioritizes explicit filename over object properties", async () => { + const namedValue = { name: "original.txt", data: "content" }; + await formData.appendFile("file", namedValue, "override.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file"'); + expect(serialized).toContain('filename="override.txt"'); + expect(serialized).not.toContain('filename="original.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("override.txt"); + }); + }); + + describe("Edge cases and error handling", () => { + it("handles empty filename gracefully", async () => { + await formData.appendFile("file", "content", ""); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('Content-Disposition: form-data; name="file"'); + expect(serialized).toContain('filename="blob"'); // Default fallback + expect(hasFile).toBe(true); + expect(filename).toBe("blob"); + }); + + it("handles large strings", async () => { + const largeString = "x".repeat(1000); + await formData.appendFile("large", largeString, "large.txt"); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="large"'); + expect(serialized).toContain('filename="large.txt"'); + expect(hasFile).toBe(true); + expect(filename).toBe("large.txt"); + }); + + it("handles unicode content and filenames", async () => { + const unicodeContent = "Hello δΈ–η•Œ 🌍 Emoji πŸš€"; + const unicodeFilename = "Ρ„Π°ΠΉΠ»-тСст-🌟.txt"; + + await formData.appendFile("unicode", unicodeContent, unicodeFilename); + + const { serialized, hasFile, filename } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="unicode"'); + expect(serialized).toContain(`filename="${unicodeFilename}"`); + expect(hasFile).toBe(true); + expect(filename).toBe(unicodeFilename); + }); + + it("handles multiple files in single form", async () => { + await formData.appendFile("file1", "content1", "file1.txt"); + await formData.appendFile("file2", "content2", "file2.txt"); + formData.append("text", "regular field"); + + const { serialized } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toContain('name="file1"'); + expect(serialized).toContain('filename="file1.txt"'); + + expect(serialized).toContain('name="file2"'); + expect(serialized).toContain('filename="file2.txt"'); + + expect(serialized).toContain('name="text"'); + expect(serialized).not.toContain('filename="text"'); + expect(serialized).toContain("regular field"); + }); + }); + + describe("Request structure", () => { + it("returns correct request structure", async () => { + await formData.appendFile("file", "content", "test.txt"); + + const request = formData.getRequest(); + + expect(request).toHaveProperty("body"); + expect(request).toHaveProperty("headers"); + expect(request).toHaveProperty("duplex"); + expect(request.body).toBeInstanceOf(FormData); + expect(request.headers).toEqual({}); + expect(request.duplex).toBe("half"); + }); + + it("generates proper multipart boundary structure", async () => { + await formData.appendFile("file", "test content", "test.txt"); + formData.append("field", "value"); + + const { serialized } = await getFormDataInfo(formData.getRequest()); + + expect(serialized).toMatch(/------formdata-undici-\w+|------WebKitFormBoundary\w+/); + expect(serialized).toContain("Content-Disposition: form-data;"); + expect(serialized).toMatch(/------formdata-undici-\w+--|------WebKitFormBoundary\w+--/); + }); + }); + + describe("Factory function", () => { + it("returns FormDataWrapper instance", async () => { + const formData = await newFormData(); + expect(formData).toBeInstanceOf(FormDataWrapper); + }); + + it("creates independent instances", async () => { + const formData1 = await newFormData(); + const formData2 = await newFormData(); + + await formData1.setup(); + await formData2.setup(); + + formData1.append("test1", "value1"); + formData2.append("test2", "value2"); + + const request1 = formData1.getRequest() as { body: FormData }; + const request2 = formData2.getRequest() as { body: FormData }; + + const entries1 = Array.from(request1.body.entries()); + const entries2 = Array.from(request2.body.entries()); + + expect(entries1).toHaveLength(1); + expect(entries2).toHaveLength(1); + expect(entries1[0][0]).toBe("test1"); + expect(entries2[0][0]).toBe("test2"); + }); + }); +}); diff --git a/tests/unit/form-data-utils/formDataWrapper.test.ts b/tests/unit/form-data-utils/formDataWrapper.test.ts index aa96262..0ec0bca 100644 --- a/tests/unit/form-data-utils/formDataWrapper.test.ts +++ b/tests/unit/form-data-utils/formDataWrapper.test.ts @@ -1,141 +1,360 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import fs from "fs"; +import { Readable } from "stream"; +import { FormDataWrapper, newFormData } from "../../../src/core/form-data-utils/FormDataWrapper"; +import { File, Blob } from "buffer"; + +// Helper function to serialize FormData to string for inspection +async function serializeFormData(formData: FormData): Promise { + const request = new Request("http://localhost", { + method: "POST", + body: formData, + }); + + const buffer = await request.arrayBuffer(); + return new TextDecoder().decode(buffer); +} + +describe("FormDataWrapper", () => { + let formData: FormDataWrapper; -import { Node18FormData, WebFormData } from "../../../src/core/form-data-utils/FormDataWrapper"; + beforeEach(async () => { + formData = new FormDataWrapper(); + await formData.setup(); + }); + + describe("Stream handling", () => { + it("serializes Node.js Readable stream with filename", async () => { + const stream = Readable.from(["file content"]); + await formData.appendFile("file", stream, "testfile.txt"); -describe("CrossPlatformFormData", () => { - describe("Node18FormData", () => { - let formData: any; + const serialized = await serializeFormData(formData.getRequest().body); - beforeEach(async () => { - formData = new Node18FormData(); - await formData.setup(); + expect(serialized).toContain('Content-Disposition: form-data; name="file"'); + expect(serialized).toContain('filename="testfile.txt"'); + expect(serialized).toContain("file content"); }); - it("should append a Readable stream with a specified filename", async () => { - const value = (await import("readable-stream")).Readable.from(["file content"]); - const filename = "testfile.txt"; + it("auto-detects filename from stream path property", async () => { + const stream = Readable.from(["file content"]); + (stream as { path?: string }).path = "/test/path/testfile.txt"; - await formData.appendFile("file", value, filename); + await formData.appendFile("file", stream); - const request = await formData.getRequest(); - const decoder = new TextDecoder("utf-8"); - let data = ""; - for await (const chunk of request.body) { - data += decoder.decode(chunk); - } - expect(data).toContain(filename); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="testfile.txt"'); }); - it("should append a Blob with a specified filename", async () => { - const value = new Blob(["file content"], { type: "text/plain" }); - const filename = "testfile.txt"; + it("handles Windows-style paths", async () => { + const stream = Readable.from(["file content"]); + (stream as { path?: string }).path = "C:\\test\\path\\testfile.txt"; - await formData.appendFile("file", value, filename); + await formData.appendFile("file", stream); - const request = await formData.getRequest(); - const decoder = new TextDecoder("utf-8"); - let data = ""; - for await (const chunk of request.body) { - data += decoder.decode(chunk); - } - expect(data).toContain(filename); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="testfile.txt"'); }); - it("should append a File with a specified filename", async () => { - const filename = "testfile.txt"; - const value = new (await import("buffer")).File(["file content"], filename); + it("handles empty streams", async () => { + const stream = Readable.from([]); + await formData.appendFile("file", stream, "empty.txt"); - await formData.appendFile("file", value); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="empty.txt"'); + expect(serialized).toMatch(/------formdata-undici-\w+|------WebKitFormBoundary\w+/); + }); - const request = await formData.getRequest(); - const decoder = new TextDecoder("utf-8"); - let data = ""; - for await (const chunk of request.body) { - data += decoder.decode(chunk); - } - expect(data).toContain("testfile.txt"); + it("serializes Web ReadableStream with filename", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("web stream content")); + controller.close(); + }, + }); + + await formData.appendFile("file", stream, "webstream.txt"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="webstream.txt"'); + expect(serialized).toContain("web stream content"); }); - it("should append a File with an explicit filename", async () => { - const filename = "testfile.txt"; - const value = new (await import("buffer")).File(["file content"], filename); + it("handles empty Web ReadableStream", async () => { + const stream = new ReadableStream({ + start(controller) { + controller.close(); + }, + }); + + await formData.appendFile("file", stream, "empty.txt"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="empty.txt"'); + expect(serialized).toMatch(/------formdata-undici-\w+|------WebKitFormBoundary\w+/); + }); + }); - await formData.appendFile("file", value, "test.txt"); + describe("Blob and File types", () => { + it("serializes Blob with specified filename", async () => { + const blob = new Blob(["file content"], { type: "text/plain" }); + await formData.appendFile("file", blob, "testfile.txt"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="testfile.txt"'); + expect(serialized).toContain("Content-Type: text/plain"); + expect(serialized).toContain("file content"); + }); + + it("uses default filename for Blob without explicit filename", async () => { + const blob = new Blob(["file content"], { type: "text/plain" }); + await formData.appendFile("file", blob); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="blob"'); + }); - const request = await formData.getRequest(); - const decoder = new TextDecoder("utf-8"); - let data = ""; - for await (const chunk of request.body) { - data += decoder.decode(chunk); + it("preserves File object filename", async () => { + if (typeof File !== "undefined") { + const file = new File(["file content"], "original.txt", { type: "text/plain" }); + await formData.appendFile("file", file); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="original.txt"'); + expect(serialized).toContain("file content"); } - expect(data).toContain("test.txt"); }); - it("should append stream with path", async () => { - const expectedFileName = "testfile.txt"; - const filePath = "/test/testfile.txt"; - const stream = (await import("readable-stream")).Readable.from(["file content"]); - (stream as any).path = filePath; - await formData.appendFile("file", stream); + it("allows filename override for File objects", async () => { + if (typeof File !== "undefined") { + const file = new File(["file content"], "original.txt", { type: "text/plain" }); + await formData.appendFile("file", file, "override.txt"); - const request = await formData.getRequest(); - const decoder = new TextDecoder("utf-8"); - let data = ""; - for await (const chunk of request.body) { - data += decoder.decode(chunk); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="override.txt"'); + expect(serialized).not.toContain('filename="original.txt"'); } - expect(data).toContain(`Content-Disposition: form-data; name="file"; filename="${expectedFileName}"`); }); }); - describe("WebFormData", () => { - let formData: any; + describe("Binary data types", () => { + it("serializes ArrayBuffer with filename", async () => { + const arrayBuffer = new ArrayBuffer(8); + new Uint8Array(arrayBuffer).set([1, 2, 3, 4, 5, 6, 7, 8]); + + await formData.appendFile("file", arrayBuffer, "binary.bin"); - beforeEach(async () => { - formData = new WebFormData(); - await formData.setup(); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="binary.bin"'); + expect(serialized).toMatch(/------formdata-undici-\w+|------WebKitFormBoundary\w+/); }); - it("should append a Readable stream with a specified filename", async () => { - const value = (await import("readable-stream")).Readable.from(["file content"]); - const filename = "testfile.txt"; + it("serializes Uint8Array with filename", async () => { + const uint8Array = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" + await formData.appendFile("file", uint8Array, "binary.bin"); - await formData.appendFile("file", value, filename); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="binary.bin"'); + expect(serialized).toContain("Hello"); + }); - const request = formData.getRequest(); - expect(request.body.get("file").name).toBe(filename); + it("serializes other typed arrays", async () => { + const int16Array = new Int16Array([1000, 2000, 3000]); + await formData.appendFile("file", int16Array, "numbers.bin"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="numbers.bin"'); }); - it("should append a Blob with a specified filename", async () => { - const value = new Blob(["file content"], { type: "text/plain" }); - const filename = "testfile.txt"; + it("serializes Buffer data with filename", async () => { + if (typeof Buffer !== "undefined" && typeof Buffer.isBuffer === "function") { + const buffer = Buffer.from("test content"); + await formData.appendFile("file", buffer, "test.txt"); - await formData.appendFile("file", value, filename); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="test.txt"'); + expect(serialized).toContain("test content"); + } + }); + }); - const request = formData.getRequest(); + describe("Text and primitive types", () => { + it("serializes string as regular form field", async () => { + formData.append("text", "test string"); - expect(request.body.get("file").name).toBe(filename); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('name="text"'); + expect(serialized).not.toContain("filename="); + expect(serialized).toContain("test string"); }); - it("should append a File with a specified filename", async () => { - const filename = "testfile.txt"; - const value = new (await import("buffer")).File(["file content"], filename); + it("serializes string as file with filename", async () => { + await formData.appendFile("file", "test content", "text.txt"); - await formData.appendFile("file", value); + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="text.txt"'); + expect(serialized).toContain("test content"); + }); - const request = formData.getRequest(); - expect(request.body.get("file").name).toBe(filename); + it("serializes numbers and booleans as strings", async () => { + formData.append("number", 12345); + formData.append("flag", true); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain("12345"); + expect(serialized).toContain("true"); + }); + }); + + describe("Object and JSON handling", () => { + it("serializes objects as JSON with filename", async () => { + const obj = { test: "value", nested: { key: "data" } }; + await formData.appendFile("data", obj, "data.json"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="data.json"'); + expect(serialized).toContain("Content-Type: application/json"); + expect(serialized).toContain(JSON.stringify(obj)); }); - it("should append a File with an explicit filename", async () => { - const filename = "testfile.txt"; - const value = new (await import("buffer")).File(["file content"], filename); + it("serializes arrays as JSON", async () => { + const arr = [1, 2, 3, "test"]; + await formData.appendFile("array", arr, "array.json"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="array.json"'); + expect(serialized).toContain(JSON.stringify(arr)); + }); - await formData.appendFile("file", value, "test.txt"); + it("handles null and undefined values", async () => { + formData.append("nullValue", null); + formData.append("undefinedValue", undefined); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain("null"); + expect(serialized).toContain("undefined"); + }); + }); + + describe("Filename extraction from objects", () => { + it("extracts filename from object with name property", async () => { + const namedValue = { name: "custom-name.txt", data: "content" }; + await formData.appendFile("file", namedValue); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="custom-name.txt"'); + expect(serialized).toContain(JSON.stringify(namedValue)); + }); + + it("extracts filename from object with path property", async () => { + const pathedValue = { path: "/some/path/file.txt", content: "data" }; + await formData.appendFile("file", pathedValue); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="file.txt"'); + }); + + it("prioritizes explicit filename over object properties", async () => { + const namedValue = { name: "original.txt", data: "content" }; + await formData.appendFile("file", namedValue, "override.txt"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="override.txt"'); + expect(serialized).not.toContain('filename="original.txt"'); + }); + }); + + describe("Edge cases and error handling", () => { + it("handles empty filename gracefully", async () => { + await formData.appendFile("file", "content", ""); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="blob"'); // Default fallback + }); + + it("handles large strings", async () => { + const largeString = "x".repeat(1000); + await formData.appendFile("large", largeString, "large.txt"); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="large.txt"'); + }); + + it("handles unicode content and filenames", async () => { + const unicodeContent = "Hello δΈ–η•Œ 🌍 Emoji πŸš€"; + const unicodeFilename = "Ρ„Π°ΠΉΠ»-тСст-🌟.txt"; + + await formData.appendFile("unicode", unicodeContent, unicodeFilename); + + const serialized = await serializeFormData(formData.getRequest().body); + expect(serialized).toContain('filename="' + unicodeFilename + '"'); + expect(serialized).toContain(unicodeContent); + }); + + it("handles multiple files in single form", async () => { + await formData.appendFile("file1", "content1", "file1.txt"); + await formData.appendFile("file2", "content2", "file2.txt"); + formData.append("text", "regular field"); + + const serialized = await serializeFormData(formData.getRequest().body); + + expect(serialized).toContain('filename="file1.txt"'); + expect(serialized).toContain('filename="file2.txt"'); + expect(serialized).toContain('name="text"'); + expect(serialized).not.toContain('filename="text"'); + }); + }); + + describe("Request structure", () => { + it("returns correct request structure", async () => { + await formData.appendFile("file", "content", "test.txt"); const request = formData.getRequest(); - expect(request.body.get("file").name).toBe("test.txt"); + + expect(request).toHaveProperty("body"); + expect(request).toHaveProperty("headers"); + expect(request).toHaveProperty("duplex"); + expect(request.body).toBeInstanceOf(FormData); + expect(request.headers).toEqual({}); + expect(request.duplex).toBe("half"); + }); + + it("generates proper multipart boundary structure", async () => { + await formData.appendFile("file", "test content", "test.txt"); + formData.append("field", "value"); + + const serialized = await serializeFormData(formData.getRequest().body); + + expect(serialized).toMatch(/------formdata-undici-\w+|------WebKitFormBoundary\w+/); + expect(serialized).toContain("Content-Disposition: form-data;"); + expect(serialized).toMatch(/------formdata-undici-\w+--|------WebKitFormBoundary\w+--/); + }); + }); + + describe("Factory function", () => { + it("returns FormDataWrapper instance", async () => { + const formData = await newFormData(); + expect(formData).toBeInstanceOf(FormDataWrapper); + }); + + it("creates independent instances", async () => { + const formData1 = await newFormData(); + const formData2 = await newFormData(); + + await formData1.setup(); + await formData2.setup(); + + formData1.append("test1", "value1"); + formData2.append("test2", "value2"); + + const request1 = formData1.getRequest() as { body: FormData }; + const request2 = formData2.getRequest() as { body: FormData }; + + const entries1 = Array.from(request1.body.entries()); + const entries2 = Array.from(request2.body.entries()); + + expect(entries1).toHaveLength(1); + expect(entries2).toHaveLength(1); + expect(entries1[0][0]).toBe("test1"); + expect(entries2[0][0]).toBe("test2"); }); }); }); diff --git a/tests/unit/url/join.test.ts b/tests/unit/url/join.test.ts new file mode 100644 index 0000000..984cfe6 --- /dev/null +++ b/tests/unit/url/join.test.ts @@ -0,0 +1,120 @@ +import { join } from "../../../src/core/url/index"; + +describe("join", () => { + describe("basic functionality", () => { + it("should return empty string for empty base", () => { + expect(join("")).toBe(""); + expect(join("", "path")).toBe(""); + }); + + it("should handle single segment", () => { + expect(join("base", "segment")).toBe("base/segment"); + expect(join("base/", "segment")).toBe("base/segment"); + expect(join("base", "/segment")).toBe("base/segment"); + expect(join("base/", "/segment")).toBe("base/segment"); + }); + + it("should handle multiple segments", () => { + expect(join("base", "path1", "path2", "path3")).toBe("base/path1/path2/path3"); + expect(join("base/", "/path1/", "/path2/", "/path3/")).toBe("base/path1/path2/path3/"); + }); + }); + + describe("URL handling", () => { + it("should handle absolute URLs", () => { + expect(join("https://example.com", "api", "v1")).toBe("https://example.com/api/v1"); + expect(join("https://example.com/", "/api/", "/v1/")).toBe("https://example.com/api/v1/"); + expect(join("https://example.com/base", "api", "v1")).toBe("https://example.com/base/api/v1"); + }); + + it("should preserve URL query parameters and fragments", () => { + expect(join("https://example.com?query=1", "api")).toBe("https://example.com/api?query=1"); + expect(join("https://example.com#fragment", "api")).toBe("https://example.com/api#fragment"); + expect(join("https://example.com?query=1#fragment", "api")).toBe( + "https://example.com/api?query=1#fragment", + ); + }); + + it("should handle different protocols", () => { + expect(join("http://example.com", "api")).toBe("http://example.com/api"); + expect(join("ftp://example.com", "files")).toBe("ftp://example.com/files"); + expect(join("ws://example.com", "socket")).toBe("ws://example.com/socket"); + }); + + it("should fallback to path joining for malformed URLs", () => { + expect(join("not-a-url://", "path")).toBe("not-a-url:///path"); + }); + }); + + describe("edge cases", () => { + it("should handle empty segments", () => { + expect(join("base", "", "path")).toBe("base/path"); + expect(join("base", null as any, "path")).toBe("base/path"); + expect(join("base", undefined as any, "path")).toBe("base/path"); + }); + + it("should handle segments with only slashes", () => { + expect(join("base", "/", "path")).toBe("base/path"); + expect(join("base", "//", "path")).toBe("base/path"); + }); + + it("should handle base paths with trailing slashes", () => { + expect(join("base/", "path")).toBe("base/path"); + }); + + it("should handle complex nested paths", () => { + expect(join("api/v1/", "/users/", "/123/", "/profile")).toBe("api/v1/users/123/profile"); + }); + }); + + describe("real-world scenarios", () => { + it("should handle API endpoint construction", () => { + const baseUrl = "https://api.example.com/v1"; + expect(join(baseUrl, "users", "123", "posts")).toBe("https://api.example.com/v1/users/123/posts"); + }); + + it("should handle file path construction", () => { + expect(join("/var/www", "html", "assets", "images")).toBe("/var/www/html/assets/images"); + }); + + it("should handle relative path construction", () => { + expect(join("../parent", "child", "grandchild")).toBe("../parent/child/grandchild"); + }); + + it("should handle Windows-style paths", () => { + expect(join("C:\\Users", "Documents", "file.txt")).toBe("C:\\Users/Documents/file.txt"); + }); + }); + + describe("performance scenarios", () => { + it("should handle many segments efficiently", () => { + const segments = Array(100).fill("segment"); + const result = join("base", ...segments); + expect(result).toBe("base/" + segments.join("/")); + }); + + it("should handle long URLs", () => { + const longPath = "a".repeat(1000); + expect(join("https://example.com", longPath)).toBe(`https://example.com/${longPath}`); + }); + }); + + describe("trailing slash preservation", () => { + it("should preserve trailing slash on final result when base has trailing slash and no segments", () => { + expect(join("https://api.example.com/")).toBe("https://api.example.com/"); + expect(join("https://api.example.com/v1/")).toBe("https://api.example.com/v1/"); + }); + + it("should preserve trailing slash when last segment has trailing slash", () => { + expect(join("https://api.example.com", "users/")).toBe("https://api.example.com/users/"); + expect(join("api/v1", "users/")).toBe("api/v1/users/"); + }); + + it("should preserve trailing slash with multiple segments where last has trailing slash", () => { + expect(join("https://api.example.com", "v1", "collections/")).toBe( + "https://api.example.com/v1/collections/", + ); + expect(join("base", "path1", "path2/")).toBe("base/path1/path2/"); + }); + }); +}); diff --git a/tests/unit/url/qs.test.ts b/tests/unit/url/qs.test.ts new file mode 100644 index 0000000..80e7e04 --- /dev/null +++ b/tests/unit/url/qs.test.ts @@ -0,0 +1,187 @@ +import { toQueryString } from "../../../src/core/url/index"; + +describe("Test qs toQueryString", () => { + describe("Basic functionality", () => { + it("should return empty string for null/undefined", () => { + expect(toQueryString(null)).toBe(""); + expect(toQueryString(undefined)).toBe(""); + }); + + it("should return empty string for primitive values", () => { + expect(toQueryString("hello")).toBe(""); + expect(toQueryString(42)).toBe(""); + expect(toQueryString(true)).toBe(""); + expect(toQueryString(false)).toBe(""); + }); + + it("should handle empty objects", () => { + expect(toQueryString({})).toBe(""); + }); + + it("should handle simple key-value pairs", () => { + const obj = { name: "John", age: 30 }; + expect(toQueryString(obj)).toBe("name=John&age=30"); + }); + }); + + describe("Array handling", () => { + it("should handle arrays with indices format (default)", () => { + const obj = { items: ["a", "b", "c"] }; + expect(toQueryString(obj)).toBe("items%5B0%5D=a&items%5B1%5D=b&items%5B2%5D=c"); + }); + + it("should handle arrays with repeat format", () => { + const obj = { items: ["a", "b", "c"] }; + expect(toQueryString(obj, { arrayFormat: "repeat" })).toBe("items=a&items=b&items=c"); + }); + + it("should handle empty arrays", () => { + const obj = { items: [] }; + expect(toQueryString(obj)).toBe(""); + }); + + it("should handle arrays with mixed types", () => { + const obj = { mixed: ["string", 42, true, false] }; + expect(toQueryString(obj)).toBe("mixed%5B0%5D=string&mixed%5B1%5D=42&mixed%5B2%5D=true&mixed%5B3%5D=false"); + }); + + it("should handle arrays with objects", () => { + const obj = { users: [{ name: "John" }, { name: "Jane" }] }; + expect(toQueryString(obj)).toBe("users%5B0%5D%5Bname%5D=John&users%5B1%5D%5Bname%5D=Jane"); + }); + + it("should handle arrays with objects in repeat format", () => { + const obj = { users: [{ name: "John" }, { name: "Jane" }] }; + expect(toQueryString(obj, { arrayFormat: "repeat" })).toBe("users%5Bname%5D=John&users%5Bname%5D=Jane"); + }); + }); + + describe("Nested objects", () => { + it("should handle nested objects", () => { + const obj = { user: { name: "John", age: 30 } }; + expect(toQueryString(obj)).toBe("user%5Bname%5D=John&user%5Bage%5D=30"); + }); + + it("should handle deeply nested objects", () => { + const obj = { user: { profile: { name: "John", settings: { theme: "dark" } } } }; + expect(toQueryString(obj)).toBe( + "user%5Bprofile%5D%5Bname%5D=John&user%5Bprofile%5D%5Bsettings%5D%5Btheme%5D=dark", + ); + }); + + it("should handle empty nested objects", () => { + const obj = { user: {} }; + expect(toQueryString(obj)).toBe(""); + }); + }); + + describe("Encoding", () => { + it("should encode by default", () => { + const obj = { name: "John Doe", email: "john@example.com" }; + expect(toQueryString(obj)).toBe("name=John%20Doe&email=john%40example.com"); + }); + + it("should not encode when encode is false", () => { + const obj = { name: "John Doe", email: "john@example.com" }; + expect(toQueryString(obj, { encode: false })).toBe("name=John Doe&email=john@example.com"); + }); + + it("should encode special characters in keys", () => { + const obj = { "user name": "John", "email[primary]": "john@example.com" }; + expect(toQueryString(obj)).toBe("user%20name=John&email%5Bprimary%5D=john%40example.com"); + }); + + it("should not encode special characters in keys when encode is false", () => { + const obj = { "user name": "John", "email[primary]": "john@example.com" }; + expect(toQueryString(obj, { encode: false })).toBe("user name=John&email[primary]=john@example.com"); + }); + }); + + describe("Mixed scenarios", () => { + it("should handle complex nested structures", () => { + const obj = { + filters: { + status: ["active", "pending"], + category: { + type: "electronics", + subcategories: ["phones", "laptops"], + }, + }, + sort: { field: "name", direction: "asc" }, + }; + expect(toQueryString(obj)).toBe( + "filters%5Bstatus%5D%5B0%5D=active&filters%5Bstatus%5D%5B1%5D=pending&filters%5Bcategory%5D%5Btype%5D=electronics&filters%5Bcategory%5D%5Bsubcategories%5D%5B0%5D=phones&filters%5Bcategory%5D%5Bsubcategories%5D%5B1%5D=laptops&sort%5Bfield%5D=name&sort%5Bdirection%5D=asc", + ); + }); + + it("should handle complex nested structures with repeat format", () => { + const obj = { + filters: { + status: ["active", "pending"], + category: { + type: "electronics", + subcategories: ["phones", "laptops"], + }, + }, + sort: { field: "name", direction: "asc" }, + }; + expect(toQueryString(obj, { arrayFormat: "repeat" })).toBe( + "filters%5Bstatus%5D=active&filters%5Bstatus%5D=pending&filters%5Bcategory%5D%5Btype%5D=electronics&filters%5Bcategory%5D%5Bsubcategories%5D=phones&filters%5Bcategory%5D%5Bsubcategories%5D=laptops&sort%5Bfield%5D=name&sort%5Bdirection%5D=asc", + ); + }); + + it("should handle arrays with null/undefined values", () => { + const obj = { items: ["a", null, "c", undefined, "e"] }; + expect(toQueryString(obj)).toBe("items%5B0%5D=a&items%5B1%5D=&items%5B2%5D=c&items%5B4%5D=e"); + }); + + it("should handle objects with null/undefined values", () => { + const obj = { name: "John", age: null, email: undefined, active: true }; + expect(toQueryString(obj)).toBe("name=John&age=&active=true"); + }); + }); + + describe("Edge cases", () => { + it("should handle numeric keys", () => { + const obj = { "0": "zero", "1": "one" }; + expect(toQueryString(obj)).toBe("0=zero&1=one"); + }); + + it("should handle boolean values in objects", () => { + const obj = { enabled: true, disabled: false }; + expect(toQueryString(obj)).toBe("enabled=true&disabled=false"); + }); + + it("should handle empty strings", () => { + const obj = { name: "", description: "test" }; + expect(toQueryString(obj)).toBe("name=&description=test"); + }); + + it("should handle zero values", () => { + const obj = { count: 0, price: 0.0 }; + expect(toQueryString(obj)).toBe("count=0&price=0"); + }); + + it("should handle arrays with empty strings", () => { + const obj = { items: ["a", "", "c"] }; + expect(toQueryString(obj)).toBe("items%5B0%5D=a&items%5B1%5D=&items%5B2%5D=c"); + }); + }); + + describe("Options combinations", () => { + it("should respect both arrayFormat and encode options", () => { + const obj = { items: ["a & b", "c & d"] }; + expect(toQueryString(obj, { arrayFormat: "repeat", encode: false })).toBe("items=a & b&items=c & d"); + }); + + it("should use default options when none provided", () => { + const obj = { items: ["a", "b"] }; + expect(toQueryString(obj)).toBe("items%5B0%5D=a&items%5B1%5D=b"); + }); + + it("should merge provided options with defaults", () => { + const obj = { items: ["a", "b"], name: "John Doe" }; + expect(toQueryString(obj, { encode: false })).toBe("items[0]=a&items[1]=b&name=John Doe"); + }); + }); +}); diff --git a/tests/wire/.gitkeep b/tests/wire/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/wire/accessTokens.test.ts b/tests/wire/accessTokens.test.ts new file mode 100644 index 0000000..1e8eb5d --- /dev/null +++ b/tests/wire/accessTokens.test.ts @@ -0,0 +1,76 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("AccessTokens", () => { + test("revoke", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { client_id: "client_id", client_secret: "client_secret", token: "token" }; + const rawResponseBody = { message: "message" }; + server + .mockEndpoint() + .post("/auth/revoke") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accessTokens.revoke({ + client_id: "client_id", + client_secret: "client_secret", + token: "token", + }); + expect(response).toEqual({ + message: "message", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", + grant_type: "client_credentials", + }; + const rawResponseBody = { + access_token: "L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg", + expires_in: 86400, + token_type: "Bearer", + }; + server + .mockEndpoint() + .post("/auth/token") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accessTokens.create({ + client_id: "eb959578-a74d-4ac3-8b25-bf0910027857", + client_secret: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", + grant_type: "client_credentials", + }); + expect(response).toEqual({ + access_token: "L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg", + expires_in: 86400, + token_type: "Bearer", + }); + }); +}); diff --git a/tests/wire/accounting/connections.test.ts b/tests/wire/accounting/connections.test.ts new file mode 100644 index 0000000..3ff3cb4 --- /dev/null +++ b/tests/wire/accounting/connections.test.ts @@ -0,0 +1,258 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Connections", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + connection_url: "connection_url", + errors: [{ message: "message" }], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }, + ], + }; + server + .mockEndpoint() + .get("/accounting_connections") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.connections.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + connection_url: "connection_url", + errors: [ + { + message: "message", + }, + ], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [{ message: "message" }], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }; + server + .mockEndpoint() + .post("/accounting_connections") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.connections.create(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [ + { + message: "message", + }, + ], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [{ message: "message" }], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }; + server + .mockEndpoint() + .get("/accounting_connections/connection_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.connections.getById("connection_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [ + { + message: "message", + }, + ], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }); + }); + + test("disconnect_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [{ message: "message" }], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }; + server + .mockEndpoint() + .post("/accounting_connections/connection_id/disconnect") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.connections.disconnectById("connection_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + business_info: { + base_currency: "base_currency", + email: "email", + legal_name: "legal_name", + name: "name", + type: "type", + }, + connection_url: "connection_url", + errors: [ + { + message: "message", + }, + ], + last_pull: "2024-01-15T09:30:00Z", + platform: "platform", + status: "connected", + }); + }); + + test("sync_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { message: "message" }; + server + .mockEndpoint() + .post("/accounting_connections/connection_id/sync") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.connections.syncById("connection_id"); + expect(response).toEqual({ + message: "message", + }); + }); +}); diff --git a/tests/wire/accounting/ledgerAccounts.test.ts b/tests/wire/accounting/ledgerAccounts.test.ts new file mode 100644 index 0000000..5d2a641 --- /dev/null +++ b/tests/wire/accounting/ledgerAccounts.test.ts @@ -0,0 +1,102 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("LedgerAccounts", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + currency: "AED", + current_balance: 1, + description: "description", + is_bank_account: true, + name: "Accounts Receivable", + nominal_code: "610", + status: "Active", + subtype: "Current", + type: "Asset", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/ledger_accounts").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.accounting.ledgerAccounts.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + currency: "AED", + current_balance: 1, + description: "description", + is_bank_account: true, + name: "Accounts Receivable", + nominal_code: "610", + status: "Active", + subtype: "Current", + type: "Asset", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + currency: "AED", + current_balance: 1, + description: "description", + is_bank_account: true, + name: "Accounts Receivable", + nominal_code: "610", + status: "Active", + subtype: "Current", + type: "Asset", + }; + server + .mockEndpoint() + .get("/ledger_accounts/ledger_account_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.ledgerAccounts.getById("ledger_account_id"); + expect(response).toEqual({ + id: "id", + currency: "AED", + current_balance: 1, + description: "description", + is_bank_account: true, + name: "Accounts Receivable", + nominal_code: "610", + status: "Active", + subtype: "Current", + type: "Asset", + }); + }); +}); diff --git a/tests/wire/accounting/payables.test.ts b/tests/wire/accounting/payables.test.ts new file mode 100644 index 0000000..8c52fea --- /dev/null +++ b/tests/wire/accounting/payables.test.ts @@ -0,0 +1,162 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Payables", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + amount_due: 1.1, + currency: "EUR", + currency_rate: 1.1, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [{ description: "Logo design" }], + memo: "memo", + posted_date: "posted_date", + purchase_order_refs: [{ id: "10", name: "PO-1234" }], + status: "paid", + subtotal: 1.1, + tax_amount: 1.1, + total_amount: 1.1, + vendor_ref: { id: "120", name: "Acme Inc." }, + }, + ], + }; + server + .mockEndpoint() + .get("/accounting/payables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.payables.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + amount_due: 1.1, + currency: "EUR", + currency_rate: 1.1, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + }, + ], + memo: "memo", + posted_date: "posted_date", + purchase_order_refs: [ + { + id: "10", + name: "PO-1234", + }, + ], + status: "paid", + subtotal: 1.1, + tax_amount: 1.1, + total_amount: 1.1, + vendor_ref: { + id: "120", + name: "Acme Inc.", + }, + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + amount_due: 1.1, + currency: "EUR", + currency_rate: 1.1, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + discount_amount: 1.1, + discount_percentage: 1.1, + ledger_account_id: "ledger_account_id", + quantity: 1.1, + unit_amount: 1.1, + }, + ], + memo: "memo", + posted_date: "posted_date", + purchase_order_refs: [{ id: "10", name: "PO-1234" }], + status: "paid", + subtotal: 1.1, + tax_amount: 1.1, + total_amount: 1.1, + vendor_ref: { id: "120", name: "Acme Inc." }, + }; + server + .mockEndpoint() + .get("/accounting/payables/payable_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.payables.getById("payable_id"); + expect(response).toEqual({ + id: "id", + amount_due: 1.1, + currency: "EUR", + currency_rate: 1.1, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + discount_amount: 1.1, + discount_percentage: 1.1, + ledger_account_id: "ledger_account_id", + quantity: 1.1, + unit_amount: 1.1, + }, + ], + memo: "memo", + posted_date: "posted_date", + purchase_order_refs: [ + { + id: "10", + name: "PO-1234", + }, + ], + status: "paid", + subtotal: 1.1, + tax_amount: 1.1, + total_amount: 1.1, + vendor_ref: { + id: "120", + name: "Acme Inc.", + }, + }); + }); +}); diff --git a/tests/wire/accounting/receivables.test.ts b/tests/wire/accounting/receivables.test.ts new file mode 100644 index 0000000..b967d6a --- /dev/null +++ b/tests/wire/accounting/receivables.test.ts @@ -0,0 +1,136 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Receivables", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + currency: "EUR", + currency_rate: 1.1, + customer_ref: { id: "120", company_name: "Acme Inc." }, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [{ description: "Logo design" }], + memo: "memo", + pass_through: { key: "value" }, + posted_date: "posted_date", + }, + ], + }; + server + .mockEndpoint() + .get("/accounting/receivables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.receivables.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + currency: "EUR", + currency_rate: 1.1, + customer_ref: { + id: "120", + company_name: "Acme Inc.", + }, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + }, + ], + memo: "memo", + pass_through: { + key: "value", + }, + posted_date: "posted_date", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + currency: "EUR", + currency_rate: 1.1, + customer_ref: { id: "120", company_name: "Acme Inc." }, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + discount_amount: 1.1, + discount_percentage: 1.1, + ledger_account_id: "ledger_account_id", + quantity: 1.1, + unit_amount: 1.1, + }, + ], + memo: "memo", + pass_through: { key: "value" }, + posted_date: "posted_date", + }; + server + .mockEndpoint() + .get("/accounting/receivables/invoice_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.receivables.getById("invoice_id"); + expect(response).toEqual({ + id: "id", + currency: "EUR", + currency_rate: 1.1, + customer_ref: { + id: "120", + company_name: "Acme Inc.", + }, + due_date: "2024-01-15T09:30:00Z", + invoice_number: "invoice_number", + lines: [ + { + description: "Logo design", + discount_amount: 1.1, + discount_percentage: 1.1, + ledger_account_id: "ledger_account_id", + quantity: 1.1, + unit_amount: 1.1, + }, + ], + memo: "memo", + pass_through: { + key: "value", + }, + posted_date: "posted_date", + }); + }); +}); diff --git a/tests/wire/accounting/syncedRecords.test.ts b/tests/wire/accounting/syncedRecords.test.ts new file mode 100644 index 0000000..361d0dd --- /dev/null +++ b/tests/wire/accounting/syncedRecords.test.ts @@ -0,0 +1,194 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("SyncedRecords", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { key: "value" }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }, + ], + next_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + prev_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + }; + server + .mockEndpoint() + .get("/accounting_synced_records") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.syncedRecords.get({ + object_type: "product", + }); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { + key: "value", + }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }, + ], + next_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + prev_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { key: "value" }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }; + server + .mockEndpoint() + .get("/accounting_synced_records/synced_record_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.syncedRecords.getById("synced_record_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { + key: "value", + }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }); + }); + + test("push_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { key: "value" }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }; + server + .mockEndpoint() + .post("/accounting_synced_records/synced_record_id/push") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.syncedRecords.pushById("synced_record_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + errors: { + key: "value", + }, + last_pulled_at: "2024-01-15T09:30:00Z", + object_id: "object_id", + object_type: "product", + object_updated_at: "2024-01-15T09:30:00Z", + platform: "xero", + platform_object_id: "platform_object_id", + platform_updated_at: "2024-01-15T09:30:00Z", + provider: "codat", + provider_object_id: "provider_object_id", + provider_updated_at: "2024-01-15T09:30:00Z", + sync_status: "pending", + }); + }); +}); diff --git a/tests/wire/accounting/taxRates.test.ts b/tests/wire/accounting/taxRates.test.ts new file mode 100644 index 0000000..0a2475c --- /dev/null +++ b/tests/wire/accounting/taxRates.test.ts @@ -0,0 +1,102 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("TaxRates", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + code: "code", + components: [{}], + effective_tax_rate: 1, + name: "name", + status: "status", + total_tax_rate: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/accounting_tax_rates") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.taxRates.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + code: "code", + components: [{}], + effective_tax_rate: 1, + name: "name", + status: "status", + total_tax_rate: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + code: "code", + components: [{ is_compound: true, name: "name", rate: 1 }], + effective_tax_rate: 1, + name: "name", + status: "status", + total_tax_rate: 1, + }; + server + .mockEndpoint() + .get("/accounting_tax_rates/tax_rate_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.accounting.taxRates.getById("tax_rate_id"); + expect(response).toEqual({ + id: "id", + code: "code", + components: [ + { + is_compound: true, + name: "name", + rate: 1, + }, + ], + effective_tax_rate: 1, + name: "name", + status: "status", + total_tax_rate: 1, + }); + }); +}); diff --git a/tests/wire/analytics.test.ts b/tests/wire/analytics.test.ts new file mode 100644 index 0000000..43e2057 --- /dev/null +++ b/tests/wire/analytics.test.ts @@ -0,0 +1,104 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Analytics", () => { + test("get_analytics_credit_notes", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { data: [{ dimension_value: "dimension_value", metric_value: 1.1 }] }; + server + .mockEndpoint() + .get("/analytics/credit_notes") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.analytics.getAnalyticsCreditNotes({ + metric: "id", + aggregation_function: "count", + }); + expect(response).toEqual({ + data: [ + { + dimension_value: "dimension_value", + metric_value: 1.1, + }, + ], + }); + }); + + test("get_analytics_payables", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { data: [{ dimension_value: "dimension_value", metric_value: 1.1 }] }; + server + .mockEndpoint() + .get("/analytics/payables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.analytics.getAnalyticsPayables({ + metric: "id", + aggregation_function: "count", + }); + expect(response).toEqual({ + data: [ + { + dimension_value: "dimension_value", + metric_value: 1.1, + }, + ], + }); + }); + + test("get_analytics_receivables", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { data: [{ dimension_value: "dimension_value", metric_value: 1 }] }; + server + .mockEndpoint() + .get("/analytics/receivables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.analytics.getAnalyticsReceivables({ + metric: "id", + aggregation_function: "count", + }); + expect(response).toEqual({ + data: [ + { + dimension_value: "dimension_value", + metric_value: 1, + }, + ], + }); + }); +}); diff --git a/tests/wire/approvalPolicies.test.ts b/tests/wire/approvalPolicies.test.ts new file mode 100644 index 0000000..da995d9 --- /dev/null +++ b/tests/wire/approvalPolicies.test.ts @@ -0,0 +1,234 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("ApprovalPolicies", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/approval_policies").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.approvalPolicies.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name", script: [true] }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }; + server + .mockEndpoint() + .post("/approval_policies") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.create({ + name: "name", + script: [true], + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }; + server + .mockEndpoint() + .get("/approval_policies/approval_policy_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.getById("approval_policy_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/approval_policies/approval_policy_id").respondWith().statusCode(200).build(); + + const response = await client.approvalPolicies.deleteById("approval_policy_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }; + server + .mockEndpoint() + .patch("/approval_policies/approval_policy_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.updateById("approval_policy_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + description: "description", + ends_at: "2024-01-15T09:30:00Z", + name: "name", + priority: 1, + script: [true], + starts_at: "2024-01-15T09:30:00Z", + status: "active", + trigger: true, + updated_by: "updated_by", + }); + }); +}); diff --git a/tests/wire/approvalPolicies/processes.test.ts b/tests/wire/approvalPolicies/processes.test.ts new file mode 100644 index 0000000..0c9fb23 --- /dev/null +++ b/tests/wire/approvalPolicies/processes.test.ts @@ -0,0 +1,214 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Processes", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { key: "value" }, + input: { key: "value" }, + metadata: { key: "value" }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }, + ], + }; + server + .mockEndpoint() + .get("/approval_policies/approval_policy_id/processes") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.processes.get("approval_policy_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { + key: "value", + }, + input: { + key: "value", + }, + metadata: { + key: "value", + }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { key: "value" }, + input: { key: "value" }, + metadata: { key: "value" }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }; + server + .mockEndpoint() + .get("/approval_policies/approval_policy_id/processes/process_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.processes.getById("approval_policy_id", "process_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { + key: "value", + }, + input: { + key: "value", + }, + metadata: { + key: "value", + }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }); + }); + + test("cancel_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { key: "value" }, + input: { key: "value" }, + metadata: { key: "value" }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }; + server + .mockEndpoint() + .post("/approval_policies/approval_policy_id/processes/process_id/cancel") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.processes.cancelById("approval_policy_id", "process_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + error: { + key: "value", + }, + input: { + key: "value", + }, + metadata: { + key: "value", + }, + script_snapshot: true, + status: "succeeded", + updated_by: "updated_by", + }); + }); + + test("get_steps", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + approval_request_id: "approval_request_id", + approved_by: ["approved_by"], + object_id: "object_id", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }, + ], + }; + server + .mockEndpoint() + .get("/approval_policies/approval_policy_id/processes/process_id/steps") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalPolicies.processes.getSteps("approval_policy_id", "process_id"); + expect(response).toEqual({ + data: [ + { + approval_request_id: "approval_request_id", + approved_by: ["approved_by"], + object_id: "object_id", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }, + ], + }); + }); +}); diff --git a/tests/wire/approvalRequests.test.ts b/tests/wire/approvalRequests.test.ts new file mode 100644 index 0000000..b42f074 --- /dev/null +++ b/tests/wire/approvalRequests.test.ts @@ -0,0 +1,313 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("ApprovalRequests", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/approval_requests").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.approvalRequests.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + object_id: "object_id", + object_type: "account", + required_approval_count: 1, + role_ids: ["role_ids"], + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }; + server + .mockEndpoint() + .post("/approval_requests") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalRequests.create({ + object_id: "object_id", + object_type: "account", + required_approval_count: 1, + role_ids: ["role_ids"], + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }; + server + .mockEndpoint() + .get("/approval_requests/approval_request_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalRequests.getById("approval_request_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }); + }); + + test("approve_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }; + server + .mockEndpoint() + .post("/approval_requests/approval_request_id/approve") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalRequests.approveById("approval_request_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }); + }); + + test("cancel_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }; + server + .mockEndpoint() + .post("/approval_requests/approval_request_id/cancel") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalRequests.cancelById("approval_request_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }); + }); + + test("reject_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }; + server + .mockEndpoint() + .post("/approval_requests/approval_request_id/reject") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.approvalRequests.rejectById("approval_request_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + approved_by: ["approved_by"], + created_by: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + object_id: "object_id", + object_type: "account", + rejected_by: "rejected_by", + required_approval_count: 1, + role_ids: ["role_ids"], + status: "waiting", + user_ids: ["user_ids"], + }); + }); +}); diff --git a/tests/wire/comments.test.ts b/tests/wire/comments.test.ts new file mode 100644 index 0000000..55c0430 --- /dev/null +++ b/tests/wire/comments.test.ts @@ -0,0 +1,214 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Comments", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/comments").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.comments.get({ + object_type: "payable", + object_id: "object_id", + }); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { object_id: "object_id", object_type: "object_type", text: "text" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }; + server + .mockEndpoint() + .post("/comments") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.comments.create({ + object_id: "object_id", + object_type: "object_type", + text: "text", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }; + server + .mockEndpoint() + .get("/comments/comment_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.comments.getById("comment_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/comments/comment_id").respondWith().statusCode(200).build(); + + const response = await client.comments.deleteById("comment_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }; + server + .mockEndpoint() + .patch("/comments/comment_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.comments.updateById("comment_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + entity_id: "entity_id", + object_id: "object_id", + object_type: "object_type", + reply_to_entity_user_id: "reply_to_entity_user_id", + status: "active", + text: "text", + }); + }); +}); diff --git a/tests/wire/counterpartEInvoicingCredentials.test.ts b/tests/wire/counterpartEInvoicingCredentials.test.ts new file mode 100644 index 0000000..86bc264 --- /dev/null +++ b/tests/wire/counterpartEInvoicingCredentials.test.ts @@ -0,0 +1,155 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("CounterpartEInvoicingCredentials", () => { + test("get_counterparts_id_einvoicing_credentials", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [{ id: "id", network_identifier: "network_identifier", network_schema: "DE:VAT" }], + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/einvoicing_credentials") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = + await client.counterpartEInvoicingCredentials.getCounterpartsIdEinvoicingCredentials("counterpart_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + network_identifier: "network_identifier", + network_schema: "DE:VAT", + }, + ], + }); + }); + + test("post_counterparts_id_einvoicing_credentials", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { counterpart_vat_id_id: "14c84a34-282b-4fd8-8af6-86b5b5f2c212" }; + const rawResponseBody = { id: "id", network_identifier: "network_identifier", network_schema: "DE:VAT" }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/einvoicing_credentials") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterpartEInvoicingCredentials.postCounterpartsIdEinvoicingCredentials( + "counterpart_id", + { + counterpart_vat_id_id: "14c84a34-282b-4fd8-8af6-86b5b5f2c212", + }, + ); + expect(response).toEqual({ + id: "id", + network_identifier: "network_identifier", + network_schema: "DE:VAT", + }); + }); + + test("get_counterparts_id_einvoicing_credentials_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { id: "id", network_identifier: "network_identifier", network_schema: "DE:VAT" }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/einvoicing_credentials/credential_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterpartEInvoicingCredentials.getCounterpartsIdEinvoicingCredentialsId( + "credential_id", + "counterpart_id", + ); + expect(response).toEqual({ + id: "id", + network_identifier: "network_identifier", + network_schema: "DE:VAT", + }); + }); + + test("delete_counterparts_id_einvoicing_credentials_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/counterparts/counterpart_id/einvoicing_credentials/credential_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.counterpartEInvoicingCredentials.deleteCounterpartsIdEinvoicingCredentialsId( + "credential_id", + "counterpart_id", + ); + expect(response).toEqual(undefined); + }); + + test("patch_counterparts_id_einvoicing_credentials_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { id: "id", network_identifier: "network_identifier", network_schema: "DE:VAT" }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id/einvoicing_credentials/credential_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterpartEInvoicingCredentials.patchCounterpartsIdEinvoicingCredentialsId( + "credential_id", + "counterpart_id", + ); + expect(response).toEqual({ + id: "id", + network_identifier: "network_identifier", + network_schema: "DE:VAT", + }); + }); +}); diff --git a/tests/wire/counterparts.test.ts b/tests/wire/counterparts.test.ts new file mode 100644 index 0000000..a0e3209 --- /dev/null +++ b/tests/wire/counterparts.test.ts @@ -0,0 +1,457 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Counterparts", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/counterparts").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.counterparts.get({ + sort_code: "123456", + }); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + organization: { + address: { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }, + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + }, + type: "organization", + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }; + server + .mockEndpoint() + .post("/counterparts") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.create({ + type: "organization", + organization: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + }, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.getById("counterpart_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/counterparts/counterpart_id").respondWith().statusCode(200).build(); + + const response = await client.counterparts.deleteById("counterpart_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { individual: {} }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.updateById("counterpart_id", { + individual: {}, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + external_reference: "123456789", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }); + }); + + test("get_partner_metadata_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { metadata: { key: "value" } }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/partner_metadata") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.getPartnerMetadataById("counterpart_id"); + expect(response).toEqual({ + metadata: { + key: "value", + }, + }); + }); + + test("update_partner_metadata_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { metadata: { key: "value" } }; + const rawResponseBody = { metadata: { key: "value" } }; + server + .mockEndpoint() + .put("/counterparts/counterpart_id/partner_metadata") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.updatePartnerMetadataById("counterpart_id", { + metadata: { + key: "value", + }, + }); + expect(response).toEqual({ + metadata: { + key: "value", + }, + }); + }); +}); diff --git a/tests/wire/counterparts/addresses.test.ts b/tests/wire/counterparts/addresses.test.ts new file mode 100644 index 0000000..02242b9 --- /dev/null +++ b/tests/wire/counterparts/addresses.test.ts @@ -0,0 +1,203 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Addresses", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + ], + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/addresses") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.addresses.get("counterpart_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }; + const rawResponseBody = { + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/addresses") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.addresses.create("counterpart_id", { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }); + expect(response).toEqual({ + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/addresses/address_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.addresses.getById("address_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/counterparts/counterpart_id/addresses/address_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.counterparts.addresses.deleteById("address_id", "counterpart_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id/addresses/address_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.addresses.updateById("address_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + city: "Berlin", + counterpart_id: "counterpart_id", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }); + }); +}); diff --git a/tests/wire/counterparts/bankAccounts.test.ts b/tests/wire/counterparts/bankAccounts.test.ts new file mode 100644 index 0000000..70084e5 --- /dev/null +++ b/tests/wire/counterparts/bankAccounts.test.ts @@ -0,0 +1,273 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("BankAccounts", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { key: "value" }, + routing_number: "routing_number", + sort_code: "123456", + }, + ], + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/bank_accounts") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.bankAccounts.get("counterpart_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { + key: "value", + }, + routing_number: "routing_number", + sort_code: "123456", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { country: "AF", currency: "AED" }; + const rawResponseBody = { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { key: "value" }, + routing_number: "routing_number", + sort_code: "123456", + }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/bank_accounts") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.bankAccounts.create("counterpart_id", { + country: "AF", + currency: "AED", + }); + expect(response).toEqual({ + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { + key: "value", + }, + routing_number: "routing_number", + sort_code: "123456", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { key: "value" }, + routing_number: "routing_number", + sort_code: "123456", + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/bank_accounts/bank_account_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.bankAccounts.getById("bank_account_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { + key: "value", + }, + routing_number: "routing_number", + sort_code: "123456", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/counterparts/counterpart_id/bank_accounts/bank_account_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.counterparts.bankAccounts.deleteById("bank_account_id", "counterpart_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { key: "value" }, + routing_number: "routing_number", + sort_code: "123456", + }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id/bank_accounts/bank_account_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.bankAccounts.updateById("bank_account_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + counterpart_id: "counterpart_id", + country: "AF", + currency: "AED", + iban: "DE74500700100100000900", + is_default_for_currency: true, + name: "name", + partner_metadata: { + key: "value", + }, + routing_number: "routing_number", + sort_code: "123456", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { key: "value" }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/bank_accounts/bank_account_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.bankAccounts.makeDefaultById("bank_account_id", "counterpart_id"); + expect(response).toEqual({ + key: "value", + }); + }); +}); diff --git a/tests/wire/counterparts/contacts.test.ts b/tests/wire/counterparts/contacts.test.ts new file mode 100644 index 0000000..5a75b28 --- /dev/null +++ b/tests/wire/counterparts/contacts.test.ts @@ -0,0 +1,322 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Contacts", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + address: { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }, + ], + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/contacts") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.contacts.get("counterpart_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + address: { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }, + first_name: "Mary", + last_name: "O'Brien", + }; + const rawResponseBody = { + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/contacts") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.contacts.create("counterpart_id", { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + first_name: "Mary", + last_name: "O'Brien", + }); + expect(response).toEqual({ + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/contacts/contact_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.contacts.getById("contact_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/counterparts/counterpart_id/contacts/contact_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.counterparts.contacts.deleteById("contact_id", "counterpart_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id/contacts/contact_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.contacts.updateById("contact_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/contacts/contact_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.contacts.makeDefaultById("contact_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_id: "counterpart_id", + email: "contact@example.org", + first_name: "Mary", + is_default: true, + last_name: "O'Brien", + phone: "5551235476", + title: "Ms.", + }); + }); +}); diff --git a/tests/wire/counterparts/vatIds.test.ts b/tests/wire/counterparts/vatIds.test.ts new file mode 100644 index 0000000..7c41bab --- /dev/null +++ b/tests/wire/counterparts/vatIds.test.ts @@ -0,0 +1,168 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("VatIds", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [{ id: "id", counterpart_id: "counterpart_id", country: "AF", type: "ae_trn", value: "123456789" }], + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/vat_ids") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.vatIds.get("counterpart_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { value: "123456789" }; + const rawResponseBody = { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }; + server + .mockEndpoint() + .post("/counterparts/counterpart_id/vat_ids") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.vatIds.create("counterpart_id", { + value: "123456789", + }); + expect(response).toEqual({ + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }; + server + .mockEndpoint() + .get("/counterparts/counterpart_id/vat_ids/vat_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.vatIds.getById("vat_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/counterparts/counterpart_id/vat_ids/vat_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.counterparts.vatIds.deleteById("vat_id", "counterpart_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }; + server + .mockEndpoint() + .patch("/counterparts/counterpart_id/vat_ids/vat_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.counterparts.vatIds.updateById("vat_id", "counterpart_id"); + expect(response).toEqual({ + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }); + }); +}); diff --git a/tests/wire/creditNotes.test.ts b/tests/wire/creditNotes.test.ts new file mode 100644 index 0000000..09b1db9 --- /dev/null +++ b/tests/wire/creditNotes.test.ts @@ -0,0 +1,2336 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; +import * as Monite from "../../src/api/index"; + +describe("CreditNotes", () => { + test("get_payable_credit_notes", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }; + server + .mockEndpoint() + .get("/payable_credit_notes") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotes(); + expect(response).toEqual({ + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }); + }); + + test("post_payable_credit_notes", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { document_id: "CN-2287", issued_at: "2024-01-15" }; + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotes({ + document_id: "CN-2287", + issued_at: "2024-01-15", + }); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("get_payable_credit_notes_validations", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .get("/payable_credit_notes/validations") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotesValidations(); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("put_payable_credit_notes_validations", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { required_fields: ["currency"] }; + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .put("/payable_credit_notes/validations") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.putPayableCreditNotesValidations({ + required_fields: ["currency"], + }); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("post_payable_credit_notes_validations_reset", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .post("/payable_credit_notes/validations/reset") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesValidationsReset(); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("get_payable_credit_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .get("/payable_credit_notes/credit_note_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotesId("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("delete_payable_credit_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/payable_credit_notes/credit_note_id").respondWith().statusCode(200).build(); + + const response = await client.creditNotes.deletePayableCreditNotesId("credit_note_id"); + expect(response).toEqual(undefined); + }); + + test("patch_payable_credit_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .patch("/payable_credit_notes/credit_note_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.patchPayableCreditNotesId("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("post_payable_credit_notes_id_approve", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/approve") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdApprove("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("post_payable_credit_notes_id_cancel", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/cancel") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdCancel("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("post_payable_credit_notes_id_cancel_ocr", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/cancel_ocr") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdCancelOcr("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("get_payable_credit_notes_id_line_items", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }; + server + .mockEndpoint() + .get("/payable_credit_notes/credit_note_id/line_items") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotesIdLineItems("credit_note_id"); + expect(response).toEqual({ + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }); + }); + + test("post_payable_credit_notes_id_line_items", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdLineItems("credit_note_id", {}); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }); + }); + + test("put_payable_credit_notes_id_line_items", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { data: [{}] }; + const rawResponseBody = { + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }; + server + .mockEndpoint() + .put("/payable_credit_notes/credit_note_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.putPayableCreditNotesIdLineItems("credit_note_id", { + data: [{}], + }); + expect(response).toEqual({ + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }); + }); + + test("get_payable_credit_notes_id_line_items_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }; + server + .mockEndpoint() + .get("/payable_credit_notes/credit_note_id/line_items/line_item_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotesIdLineItemsId("credit_note_id", "line_item_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }); + }); + + test("delete_payable_credit_notes_id_line_items_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }; + server + .mockEndpoint() + .delete("/payable_credit_notes/credit_note_id/line_items/line_item_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.deletePayableCreditNotesIdLineItemsId( + "credit_note_id", + "line_item_id", + ); + expect(response).toEqual({ + data: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }, + ], + next_pagination_token: "eyJwYWdlIjoyfQ==", + prev_pagination_token: "eyJwYWdlIjoxfQ==", + }); + }); + + test("patch_payable_credit_notes_id_line_items_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }; + server + .mockEndpoint() + .patch("/payable_credit_notes/credit_note_id/line_items/line_item_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.patchPayableCreditNotesIdLineItemsId( + "credit_note_id", + "line_item_id", + ); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + credit_note_id: "123e4567-e89b-12d3-a456-426614174000", + description: "Premium version of Product XYZ with extended warranty", + name: "Product XYZ", + quantity: 2, + subtotal: 10000, + tax: 20, + tax_amount: 2000, + total: 12000, + unit: "pieces", + unit_price: 5000, + }); + }); + + test("post_payable_credit_notes_id_reject", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/reject") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdReject("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("post_payable_credit_notes_id_submit_for_approval", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }; + server + .mockEndpoint() + .post("/payable_credit_notes/credit_note_id/submit_for_approval") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.postPayableCreditNotesIdSubmitForApproval("credit_note_id"); + expect(response).toEqual({ + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2024-01-15T14:30:00Z", + updated_at: "2024-01-15T14:30:00Z", + based_on: "123e4567-e89b-12d3-a456-426614174000", + based_on_document_id: "INV-2287", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_bank_account_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_id: "123e4567-e89b-12d3-a456-426614174000", + counterpart_raw: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "123e4567-e89b-12d3-a456-426614174000", + created_by_external_user_id: "ext_user_123", + created_by_external_user_name: "John Doe", + created_by_user_id: "123e4567-e89b-12d3-a456-426614174000", + currency: "EUR", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "Credit note for returned items from invoice INV-2287", + document_id: "CN-2287", + entity_id: "123e4567-e89b-12d3-a456-426614174000", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15", + ocr_request_id: "123e4567-e89b-12d3-a456-426614174000", + ocr_status: "completed", + origin: "SAP", + project_id: "123e4567-e89b-12d3-a456-426614174000", + sender: "supplier@example.com", + source_of_data: "user_specified", + status: "submitted_for_approval", + subtotal: 1000, + tags: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "department", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Department A", + }, + ], + tax: 20, + tax_amount: 200, + total_amount: 1200, + }); + }); + + test("get_payable_credit_notes_id_validate", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { id: "id", validation_errors: [{ key: "value" }] }; + server + .mockEndpoint() + .get("/payable_credit_notes/credit_note_id/validate") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.creditNotes.getPayableCreditNotesIdValidate("credit_note_id"); + expect(response).toEqual({ + id: "id", + validation_errors: [ + { + key: "value", + }, + ], + }); + }); +}); diff --git a/tests/wire/customVatRates.test.ts b/tests/wire/customVatRates.test.ts new file mode 100644 index 0000000..bfc4f92 --- /dev/null +++ b/tests/wire/customVatRates.test.ts @@ -0,0 +1,207 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("CustomVatRates", () => { + test("get_custom_vat_rates", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [{ name: "name", value: 1.1 }], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }, + ], + }; + server.mockEndpoint().get("/custom_vat_rates").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.customVatRates.getCustomVatRates(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [ + { + name: "name", + value: 1.1, + }, + ], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }, + ], + }); + }); + + test("post_custom_vat_rates", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { components: [{ name: "name", value: 1.1 }], name: "name" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [{ name: "name", value: 1.1 }], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }; + server + .mockEndpoint() + .post("/custom_vat_rates") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.customVatRates.postCustomVatRates({ + components: [ + { + name: "name", + value: 1.1, + }, + ], + name: "name", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [ + { + name: "name", + value: 1.1, + }, + ], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }); + }); + + test("get_custom_vat_rates_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [{ name: "name", value: 1.1 }], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }; + server + .mockEndpoint() + .get("/custom_vat_rates/custom_vat_rate_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.customVatRates.getCustomVatRatesId("custom_vat_rate_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [ + { + name: "name", + value: 1.1, + }, + ], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }); + }); + + test("delete_custom_vat_rates_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/custom_vat_rates/custom_vat_rate_id").respondWith().statusCode(200).build(); + + const response = await client.customVatRates.deleteCustomVatRatesId("custom_vat_rate_id"); + expect(response).toEqual(undefined); + }); + + test("patch_custom_vat_rates_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [{ name: "name", value: 1.1 }], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }; + server + .mockEndpoint() + .patch("/custom_vat_rates/custom_vat_rate_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.customVatRates.patchCustomVatRatesId("custom_vat_rate_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [ + { + name: "name", + value: 1.1, + }, + ], + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + value: 1.1, + }); + }); +}); diff --git a/tests/wire/dataExports.test.ts b/tests/wire/dataExports.test.ts new file mode 100644 index 0000000..a239285 --- /dev/null +++ b/tests/wire/dataExports.test.ts @@ -0,0 +1,171 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("DataExports", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + count: 1, + created_by_entity_user_id: "created_by_entity_user_id", + end_datetime: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + format: "format", + language: "language", + source_url: "source_url", + start_datetime: "2024-01-15T09:30:00Z", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/data_exports").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.dataExports.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + count: 1, + created_by_entity_user_id: "created_by_entity_user_id", + end_datetime: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + format: "format", + language: "language", + source_url: "source_url", + start_datetime: "2024-01-15T09:30:00Z", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + date_from: "date_from", + date_to: "date_to", + format: "csv", + objects: [{ statuses: ["draft"], name: "payable" }], + }; + const rawResponseBody = { id: "id" }; + server + .mockEndpoint() + .post("/data_exports") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.create({ + date_from: "date_from", + date_to: "date_to", + format: "csv", + objects: [ + { + name: "payable", + statuses: ["draft"], + }, + ], + }); + expect(response).toEqual({ + id: "id", + }); + }); + + test("get_supported_formats", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = [{ available_types: { key: ["csv"] }, object_type: "payable" }]; + server + .mockEndpoint() + .get("/data_exports/supported_formats") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.getSupportedFormats(); + expect(response).toEqual([ + { + available_types: { + key: ["csv"], + }, + object_type: "payable", + }, + ]); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + count: 1, + created_by_entity_user_id: "created_by_entity_user_id", + end_datetime: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + format: "format", + language: "language", + source_url: "source_url", + start_datetime: "2024-01-15T09:30:00Z", + status: "status", + }; + server + .mockEndpoint() + .get("/data_exports/document_export_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.getById("document_export_id"); + expect(response).toEqual({ + id: "id", + count: 1, + created_by_entity_user_id: "created_by_entity_user_id", + end_datetime: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + format: "format", + language: "language", + source_url: "source_url", + start_datetime: "2024-01-15T09:30:00Z", + status: "status", + }); + }); +}); diff --git a/tests/wire/dataExports/extraData.test.ts b/tests/wire/dataExports/extraData.test.ts new file mode 100644 index 0000000..9e6ede8 --- /dev/null +++ b/tests/wire/dataExports/extraData.test.ts @@ -0,0 +1,231 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("ExtraData", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/data_exports/extra_data") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.extraData.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }; + server + .mockEndpoint() + .post("/data_exports/extra_data") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.extraData.create({ + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }; + server + .mockEndpoint() + .get("/data_exports/extra_data/extra_data_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.extraData.getById("extra_data_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }; + server + .mockEndpoint() + .delete("/data_exports/extra_data/extra_data_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.extraData.deleteById("extra_data_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }; + server + .mockEndpoint() + .patch("/data_exports/extra_data/extra_data_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.dataExports.extraData.updateById("extra_data_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by: "created_by", + field_name: "default_account_code", + field_value: "field_value", + object_id: "object_id", + object_type: "counterpart", + }); + }); +}); diff --git a/tests/wire/deliveryNotes.test.ts b/tests/wire/deliveryNotes.test.ts new file mode 100644 index 0000000..dccf5fc --- /dev/null +++ b/tests/wire/deliveryNotes.test.ts @@ -0,0 +1,1344 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("DeliveryNotes", () => { + test("get_delivery_notes", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + postal_code: "123009", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { name: "name", type: "organization" }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + postal_code: "123009", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/delivery_notes").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.deliveryNotes.getDeliveryNotes(); + expect(response).toEqual({ + data: [ + { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + postal_code: "123009", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + name: "name", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + postal_code: "123009", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("post_delivery_notes", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + counterpart_address_id: "9a0282e1-bae7-49c9-a6f3-152dbe6fe6b8", + counterpart_id: "18a45457-377e-4b7c-b9a1-7b2e7f264d46", + delivery_date: "2025-07-01", + delivery_number: "INV-042", + display_signature_placeholder: true, + line_items: [ + { product: { name: "LG WH1000XM Monitor" }, quantity: 10 }, + { product_id: "e0c21d00-6556-4536-8390-830c4d3cf4ca", quantity: 5 }, + ], + }; + const rawResponseBody = { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }; + server + .mockEndpoint() + .post("/delivery_notes") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.deliveryNotes.postDeliveryNotes({ + counterpart_address_id: "9a0282e1-bae7-49c9-a6f3-152dbe6fe6b8", + counterpart_id: "18a45457-377e-4b7c-b9a1-7b2e7f264d46", + delivery_date: "2025-07-01", + delivery_number: "INV-042", + display_signature_placeholder: true, + line_items: [ + { + product: { + name: "LG WH1000XM Monitor", + }, + quantity: 10, + }, + { + product_id: "e0c21d00-6556-4536-8390-830c4d3cf4ca", + quantity: 5, + }, + ], + }); + expect(response).toEqual({ + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }); + }); + + test("get_delivery_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }; + server + .mockEndpoint() + .get("/delivery_notes/delivery_note_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.deliveryNotes.getDeliveryNotesId("delivery_note_id"); + expect(response).toEqual({ + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }); + }); + + test("delete_delivery_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/delivery_notes/delivery_note_id").respondWith().statusCode(200).build(); + + const response = await client.deliveryNotes.deleteDeliveryNotesId("delivery_note_id"); + expect(response).toEqual(undefined); + }); + + test("patch_delivery_notes_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }; + server + .mockEndpoint() + .patch("/delivery_notes/delivery_note_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.deliveryNotes.patchDeliveryNotesId("delivery_note_id"); + expect(response).toEqual({ + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }); + }); + + test("post_delivery_notes_id_cancel", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }; + server + .mockEndpoint() + .post("/delivery_notes/delivery_note_id/cancel") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.deliveryNotes.postDeliveryNotesIdCancel("delivery_note_id"); + expect(response).toEqual({ + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }); + }); + + test("post_delivery_notes_id_mark_as_delivered", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { description: "Pieces", name: "pcs" }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }; + server + .mockEndpoint() + .post("/delivery_notes/delivery_note_id/mark_as_delivered") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.deliveryNotes.postDeliveryNotesIdMarkAsDelivered("delivery_note_id"); + expect(response).toEqual({ + id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_at: "2022-01-01T00:00:00Z", + updated_at: "2022-01-01T00:00:00Z", + based_on: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + based_on_document_id: "IN-2022-01-01-0001", + counterpart: { + id: "id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + title: "Mr.", + }, + language: "ab", + organization: { + email: "acme@example.com", + is_customer: true, + is_vendor: true, + legal_name: "Acme Inc.", + phone: "5551231234", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + }, + counterpart_address: { + city: "Counterpart City", + country: "DE", + line1: "Counterpart Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + counterpart_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + created_by_entity_user_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + delivery_date: "2022-01-01", + delivery_number: "102-2022-0987", + display_signature_placeholder: true, + document_id: "DN-2022-01-01-0001", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "Entity City", + country: "DE", + line1: "Entity Street", + line2: "line2", + postal_code: "123009", + state: "state", + }, + entity_id: "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", + file_language: "en", + file_url: "https://example.com/delivery_note.pdf", + line_items: [ + { + product: { + description: "Description of product", + measure_unit: { + description: "Pieces", + name: "pcs", + }, + name: "Product Name", + }, + quantity: 20, + }, + ], + memo: "This is a memo", + original_file_language: "de", + original_file_url: "https://example.com/delivery_note_original.pdf", + status: "created", + }); + }); +}); diff --git a/tests/wire/eInvoicingConnections.test.ts b/tests/wire/eInvoicingConnections.test.ts new file mode 100644 index 0000000..1c9854d --- /dev/null +++ b/tests/wire/eInvoicingConnections.test.ts @@ -0,0 +1,398 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("EInvoicingConnections", () => { + test("get_einvoicing_connections", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + city: "city", + country: "DE", + postal_code: "postal_code", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }, + ], + }; + server + .mockEndpoint() + .get("/einvoicing_connections") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.eInvoicingConnections.getEinvoicingConnections(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + city: "city", + country: "DE", + postal_code: "postal_code", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }, + ], + }); + }); + + test("post_einvoicing_connections", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + address: { address_line1: "address_line1", city: "city", country: "DE", postal_code: "postal_code" }, + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }; + server + .mockEndpoint() + .post("/einvoicing_connections") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.eInvoicingConnections.postEinvoicingConnections({ + address: { + address_line1: "address_line1", + city: "city", + country: "DE", + postal_code: "postal_code", + }, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }); + }); + + test("get_einvoicing_connections_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }; + server + .mockEndpoint() + .get("/einvoicing_connections/einvoicing_connection_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.eInvoicingConnections.getEinvoicingConnectionsId("einvoicing_connection_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }); + }); + + test("delete_einvoicing_connections_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/einvoicing_connections/einvoicing_connection_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.eInvoicingConnections.deleteEinvoicingConnectionsId("einvoicing_connection_id"); + expect(response).toEqual(undefined); + }); + + test("patch_einvoicing_connections_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }; + server + .mockEndpoint() + .patch("/einvoicing_connections/einvoicing_connection_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.eInvoicingConnections.patchEinvoicingConnectionsId("einvoicing_connection_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + address_line1: "address_line1", + address_line2: "address_line2", + city: "city", + country: "DE", + postal_code: "postal_code", + state: "state", + }, + credentials: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ], + entity_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", + is_receiver: true, + is_sender: true, + legal_name: "legal_name", + provider_id: "12345", + status: "active", + }); + }); + + test("post_einvoicing_connections_id_network_credentials", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { network_credentials_identifier: "12345678", network_credentials_schema: "DE:VAT" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }; + server + .mockEndpoint() + .post("/einvoicing_connections/einvoicing_connection_id/network_credentials") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.eInvoicingConnections.postEinvoicingConnectionsIdNetworkCredentials( + "einvoicing_connection_id", + { + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }, + ); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + einvoicing_connection_id: "einvoicing_connection_id", + network_credentials_identifier: "12345678", + network_credentials_schema: "DE:VAT", + }); + }); +}); diff --git a/tests/wire/eInvoicingSearch.test.ts b/tests/wire/eInvoicingSearch.test.ts new file mode 100644 index 0000000..1839e9a --- /dev/null +++ b/tests/wire/eInvoicingSearch.test.ts @@ -0,0 +1,29 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("EInvoicingSearch", () => { + test("get_einvoice_search", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { exists: true }; + server.mockEndpoint().get("/einvoice_search").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.eInvoicingSearch.getEinvoiceSearch({ + network_identifier: "DE010101010", + network_schema: "DE:VAT", + }); + expect(response).toEqual({ + exists: true, + }); + }); +}); diff --git a/tests/wire/entities.test.ts b/tests/wire/entities.test.ts new file mode 100644 index 0000000..eec9c1b --- /dev/null +++ b/tests/wire/entities.test.ts @@ -0,0 +1,1430 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; +import * as Monite from "../../src/api/index"; + +describe("Entities", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { city: "city", country: "AF", line1: "line1", postal_code: "postal_code" }, + email: "email", + individual: { first_name: "first_name", last_name: "last_name" }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/entities").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entities.get(); + expect(response).toEqual({ + data: [ + { + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + postal_code: "postal_code", + }, + email: "email", + individual: { + first_name: "first_name", + last_name: "last_name", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + address: { city: "city", country: "AF", line1: "line1", postal_code: "postal_code" }, + email: "email", + type: "individual", + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .post("/entities") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.create({ + address: { + city: "city", + country: "AF", + line1: "line1", + postal_code: "postal_code", + }, + email: "email", + type: "individual", + }); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("get_entities_me", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server.mockEndpoint().get("/entities/me").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entities.getEntitiesMe(); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("patch_entities_me", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .patch("/entities/me") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.patchEntitiesMe({}); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .get("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.getById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .patch("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.updateById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5", {}); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("post_entities_id_activate", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .post("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5/activate") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.postEntitiesIdActivate("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("post_entities_id_deactivate", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .post("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5/deactivate") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.postEntitiesIdDeactivate("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("delete_logo_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5/logo") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.entities.deleteLogoById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual(undefined); + }); + + test("get_partner_metadata_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { metadata: { key: "value" } }; + server + .mockEndpoint() + .get("/entities/entity_id/partner_metadata") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.getPartnerMetadataById("entity_id"); + expect(response).toEqual({ + metadata: { + key: "value", + }, + }); + }); + + test("update_partner_metadata_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { metadata: { key: "value" } }; + const rawResponseBody = { metadata: { key: "value" } }; + server + .mockEndpoint() + .put("/entities/entity_id/partner_metadata") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.updatePartnerMetadataById("entity_id", { + metadata: { + key: "value", + }, + }); + expect(response).toEqual({ + metadata: { + key: "value", + }, + }); + }); + + test("get_settings_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + accounting: { + ledger_account_ids: { payments: "payments", products: "products" }, + tax_ids: { deductions: "deductions" }, + }, + allow_purchase_order_autolinking: true, + currency: { default: "AED", exchange_rates: [{ base: "AED", rate: 0.98, to: "AED" }] }, + document_ids: { + document_type_prefix: { + credit_note: "credit_note", + delivery_note: "delivery_note", + invoice: "invoice", + purchase_order: "purchase_order", + quote: "quote", + }, + include_date: true, + min_digits: 1, + prefix: "prefix", + separator: "/", + }, + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + generate_paid_invoice_pdf: true, + language: "ab", + payables_ocr_auto_tagging: [{ enabled: true, keywords: ["keywords"], tag_id: "tag_id" }], + payables_skip_approval_flow: true, + payment_priority: "working_capital", + quote_signature_required: true, + receivable_edit_flow: "compliant", + reminder: { enabled: true }, + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + }; + server + .mockEndpoint() + .get("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5/settings") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.getSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual({ + accounting: { + ledger_account_ids: { + payments: "payments", + products: "products", + }, + tax_ids: { + deductions: "deductions", + }, + }, + allow_purchase_order_autolinking: true, + currency: { + default: "AED", + exchange_rates: [ + { + base: "AED", + rate: 0.98, + to: "AED", + }, + ], + }, + document_ids: { + document_type_prefix: { + credit_note: "credit_note", + delivery_note: "delivery_note", + invoice: "invoice", + purchase_order: "purchase_order", + quote: "quote", + }, + include_date: true, + min_digits: 1, + prefix: "prefix", + separator: "/", + }, + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + generate_paid_invoice_pdf: true, + language: "ab", + payables_ocr_auto_tagging: [ + { + enabled: true, + keywords: ["keywords"], + tag_id: "tag_id", + }, + ], + payables_skip_approval_flow: true, + payment_priority: "working_capital", + quote_signature_required: true, + receivable_edit_flow: "compliant", + reminder: { + enabled: true, + }, + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + }); + }); + + test("update_settings_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + accounting: { + ledger_account_ids: { payments: "payments", products: "products" }, + tax_ids: { deductions: "deductions" }, + }, + allow_purchase_order_autolinking: true, + currency: { default: "AED", exchange_rates: [{ base: "AED", rate: 0.98, to: "AED" }] }, + document_ids: { + document_type_prefix: { + credit_note: "credit_note", + delivery_note: "delivery_note", + invoice: "invoice", + purchase_order: "purchase_order", + quote: "quote", + }, + include_date: true, + min_digits: 1, + prefix: "prefix", + separator: "/", + }, + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + generate_paid_invoice_pdf: true, + language: "ab", + payables_ocr_auto_tagging: [{ enabled: true, keywords: ["keywords"], tag_id: "tag_id" }], + payables_skip_approval_flow: true, + payment_priority: "working_capital", + quote_signature_required: true, + receivable_edit_flow: "compliant", + reminder: { enabled: true }, + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + }; + server + .mockEndpoint() + .patch("/entities/ea837e28-509b-4b6a-a600-d54b6aa0b1f5/settings") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.updateSettingsById("ea837e28-509b-4b6a-a600-d54b6aa0b1f5"); + expect(response).toEqual({ + accounting: { + ledger_account_ids: { + payments: "payments", + products: "products", + }, + tax_ids: { + deductions: "deductions", + }, + }, + allow_purchase_order_autolinking: true, + currency: { + default: "AED", + exchange_rates: [ + { + base: "AED", + rate: 0.98, + to: "AED", + }, + ], + }, + document_ids: { + document_type_prefix: { + credit_note: "credit_note", + delivery_note: "delivery_note", + invoice: "invoice", + purchase_order: "purchase_order", + quote: "quote", + }, + include_date: true, + min_digits: 1, + prefix: "prefix", + separator: "/", + }, + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + generate_paid_invoice_pdf: true, + language: "ab", + payables_ocr_auto_tagging: [ + { + enabled: true, + keywords: ["keywords"], + tag_id: "tag_id", + }, + ], + payables_skip_approval_flow: true, + payment_priority: "working_capital", + quote_signature_required: true, + receivable_edit_flow: "compliant", + reminder: { + enabled: true, + }, + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + }); + }); + + test("get_entities_id_settings_next_document_numbers", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { credit_note: 1, delivery_note: 1, invoice: 1, purchase_order: 1, quote: 1 }; + server + .mockEndpoint() + .get("/entities/entity_id/settings/next_document_numbers") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.getEntitiesIdSettingsNextDocumentNumbers("entity_id"); + expect(response).toEqual({ + credit_note: 1, + delivery_note: 1, + invoice: 1, + purchase_order: 1, + quote: 1, + }); + }); + + test("upload_onboarding_documents", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + + server + .mockEndpoint() + .post("/onboarding_documents") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .build(); + + const response = await client.entities.uploadOnboardingDocuments(); + expect(response).toEqual(undefined); + }); + + test("get_onboarding_requirements", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + disabled_reason: "disabled_reason", + payment_method: "payment_method", + requirements: { + currently_due: ["currently_due"], + eventually_due: ["eventually_due"], + past_due: ["past_due"], + pending_verification: ["pending_verification"], + }, + requirements_errors: [{ code: "code", reason: "reason", requirement: "requirement" }], + verification_errors: [{ code: "code", details: "details" }], + verification_status: "enabled", + }, + ], + }; + server + .mockEndpoint() + .get("/onboarding_requirements") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.getOnboardingRequirements(); + expect(response).toEqual({ + data: [ + { + disabled_reason: "disabled_reason", + payment_method: "payment_method", + requirements: { + currently_due: ["currently_due"], + eventually_due: ["eventually_due"], + past_due: ["past_due"], + pending_verification: ["pending_verification"], + }, + requirements_errors: [ + { + code: "code", + reason: "reason", + requirement: "requirement", + }, + ], + verification_errors: [ + { + code: "code", + details: "details", + }, + ], + verification_status: "enabled", + }, + ], + }); + }); +}); diff --git a/tests/wire/entities/bankAccounts.test.ts b/tests/wire/entities/bankAccounts.test.ts new file mode 100644 index 0000000..e967c42 --- /dev/null +++ b/tests/wire/entities/bankAccounts.test.ts @@ -0,0 +1,299 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("BankAccounts", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/bank_accounts").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entities.bankAccounts.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + account_holder_name: "Tobias Weingart", + bank_name: "DEUTSCHE BANK AG", + bic: "DEUTDEFFXXX", + country: "DE", + currency: "EUR", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + }; + const rawResponseBody = { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/bank_accounts") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.bankAccounts.create({ + account_holder_name: "Tobias Weingart", + bank_name: "DEUTSCHE BANK AG", + bic: "DEUTDEFFXXX", + country: "DE", + currency: "EUR", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + }); + expect(response).toEqual({ + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .get("/bank_accounts/bank_account_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.bankAccounts.getById("bank_account_id"); + expect(response).toEqual({ + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/bank_accounts/bank_account_id").respondWith().statusCode(200).build(); + + const response = await client.entities.bankAccounts.deleteById("bank_account_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .patch("/bank_accounts/bank_account_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.bankAccounts.updateById("bank_account_id"); + expect(response).toEqual({ + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/bank_accounts/bank_account_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.bankAccounts.makeDefaultById("bank_account_id"); + expect(response).toEqual({ + id: "id", + account_holder_name: "Cayla Lloyd", + account_number: "12345678", + bank_name: "Deutsche Bank", + bic: "DEUTDEFFXXX", + country: "AF", + currency: "AED", + display_name: "Primary account", + iban: "DE74500700100100000900", + is_default_for_currency: true, + routing_number: "routing_number", + sort_code: "123456", + was_created_by_user_id: "was_created_by_user_id", + }); + }); +}); diff --git a/tests/wire/entities/onboardingData.test.ts b/tests/wire/entities/onboardingData.test.ts new file mode 100644 index 0000000..7ca13fb --- /dev/null +++ b/tests/wire/entities/onboardingData.test.ts @@ -0,0 +1,121 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("OnboardingData", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + business_profile: { + description_of_goods_or_services: "description_of_goods_or_services", + estimated_monthly_revenue: { amount: 1, currency: "AED" }, + mcc: "mcc", + operating_countries: ["AF"], + url: "url", + }, + ownership_declaration: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + tos_acceptance: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + treasury_tos_acceptance: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + }; + server + .mockEndpoint() + .get("/entities/entity_id/onboarding_data") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.onboardingData.get("entity_id"); + expect(response).toEqual({ + business_profile: { + description_of_goods_or_services: "description_of_goods_or_services", + estimated_monthly_revenue: { + amount: 1, + currency: "AED", + }, + mcc: "mcc", + operating_countries: ["AF"], + url: "url", + }, + ownership_declaration: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + tos_acceptance: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + treasury_tos_acceptance: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + }); + }); + + test("update", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + business_profile: { + description_of_goods_or_services: "description_of_goods_or_services", + estimated_monthly_revenue: { amount: 1, currency: "AED" }, + mcc: "mcc", + operating_countries: ["AF"], + url: "url", + }, + ownership_declaration: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + tos_acceptance: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + treasury_tos_acceptance: { date: "2024-01-15T09:30:00Z", ip: "ip" }, + }; + server + .mockEndpoint() + .patch("/entities/entity_id/onboarding_data") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.onboardingData.update("entity_id"); + expect(response).toEqual({ + business_profile: { + description_of_goods_or_services: "description_of_goods_or_services", + estimated_monthly_revenue: { + amount: 1, + currency: "AED", + }, + mcc: "mcc", + operating_countries: ["AF"], + url: "url", + }, + ownership_declaration: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + tos_acceptance: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + treasury_tos_acceptance: { + date: "2024-01-15T09:30:00Z", + ip: "ip", + }, + }); + }); +}); diff --git a/tests/wire/entities/paymentMethods.test.ts b/tests/wire/entities/paymentMethods.test.ts new file mode 100644 index 0000000..014d2b7 --- /dev/null +++ b/tests/wire/entities/paymentMethods.test.ts @@ -0,0 +1,81 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("PaymentMethods", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [{ direction: "receive", name: "SEPA Payments", status: "active", type: "sepa_credit" }], + }; + server + .mockEndpoint() + .get("/entities/entity_id/payment_methods") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.paymentMethods.get("entity_id"); + expect(response).toEqual({ + data: [ + { + direction: "receive", + name: "SEPA Payments", + status: "active", + type: "sepa_credit", + }, + ], + }); + }); + + test("set", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + payment_methods_receive: ["card", "sepa_credit", "sepa_debit"], + payment_methods_send: ["sepa_credit"], + }; + const rawResponseBody = { + data: [{ direction: "receive", name: "SEPA Payments", status: "active", type: "sepa_credit" }], + }; + server + .mockEndpoint() + .put("/entities/entity_id/payment_methods") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.paymentMethods.set("entity_id", { + payment_methods_receive: ["card", "sepa_credit", "sepa_debit"], + payment_methods_send: ["sepa_credit"], + }); + expect(response).toEqual({ + data: [ + { + direction: "receive", + name: "SEPA Payments", + status: "active", + type: "sepa_credit", + }, + ], + }); + }); +}); diff --git a/tests/wire/entities/persons.test.ts b/tests/wire/entities/persons.test.ts new file mode 100644 index 0000000..07f1030 --- /dev/null +++ b/tests/wire/entities/persons.test.ts @@ -0,0 +1,353 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("Persons", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { city: "city", country: "country", line1: "line1", postal_code: "postal_code" }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: {}, + ssn_last_4: "ssn_last_4", + }, + ], + }; + server.mockEndpoint().get("/persons").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entities.persons.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + postal_code: "postal_code", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: {}, + ssn_last_4: "ssn_last_4", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { email: "email", first_name: "first_name", last_name: "last_name", relationship: {} }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }; + server + .mockEndpoint() + .post("/persons") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.persons.create({ + email: "email", + first_name: "first_name", + last_name: "last_name", + relationship: {}, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }; + server.mockEndpoint().get("/persons/person_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entities.persons.getById("person_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/persons/person_id").respondWith().statusCode(200).build(); + + const response = await client.entities.persons.deleteById("person_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }; + server + .mockEndpoint() + .patch("/persons/person_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.persons.updateById("person_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "country", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + citizenship: "AF", + created_by_entity_user_id: "created_by_entity_user_id", + date_of_birth: "date_of_birth", + email: "email", + entity_id: "entity_id", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + phone: "phone", + relationship: { + director: true, + executive: true, + owner: true, + percent_ownership: 1.1, + representative: true, + title: "title", + }, + ssn_last_4: "ssn_last_4", + }); + }); + + test("upload_onboarding_documents", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + + server + .mockEndpoint() + .post("/persons/person_id/onboarding_documents") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .build(); + + const response = await client.entities.persons.uploadOnboardingDocuments("person_id"); + expect(response).toEqual(undefined); + }); +}); diff --git a/tests/wire/entities/vatIds.test.ts b/tests/wire/entities/vatIds.test.ts new file mode 100644 index 0000000..42b4fbf --- /dev/null +++ b/tests/wire/entities/vatIds.test.ts @@ -0,0 +1,146 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; + +describe("VatIds", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [{ id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }], + }; + server + .mockEndpoint() + .get("/entities/entity_id/vat_ids") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.vatIds.get("entity_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { country: "AF", value: "123456789" }; + const rawResponseBody = { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }; + server + .mockEndpoint() + .post("/entities/entity_id/vat_ids") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.vatIds.create("entity_id", { + country: "AF", + value: "123456789", + }); + expect(response).toEqual({ + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }; + server + .mockEndpoint() + .get("/entities/entity_id/vat_ids/id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.vatIds.getById("id", "entity_id"); + expect(response).toEqual({ + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/entities/entity_id/vat_ids/id").respondWith().statusCode(200).build(); + + const response = await client.entities.vatIds.deleteById("id", "entity_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }; + server + .mockEndpoint() + .patch("/entities/entity_id/vat_ids/id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entities.vatIds.updateById("id", "entity_id"); + expect(response).toEqual({ + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }); + }); +}); diff --git a/tests/wire/entityUsers.test.ts b/tests/wire/entityUsers.test.ts new file mode 100644 index 0000000..4000b22 --- /dev/null +++ b/tests/wire/entityUsers.test.ts @@ -0,0 +1,601 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; +import * as Monite from "../../src/api/index"; + +describe("EntityUsers", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/entity_users").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entityUsers.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { first_name: "Casey", login: "login" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }; + server + .mockEndpoint() + .post("/entity_users") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.create({ + first_name: "Casey", + login: "login", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }); + }); + + test("get_current", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }; + server.mockEndpoint().get("/entity_users/me").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.entityUsers.getCurrent(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }); + }); + + test("update_current", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }; + server + .mockEndpoint() + .patch("/entity_users/me") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.updateCurrent(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }); + }); + + test("get_current_entity", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .get("/entity_users/my_entity") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.getCurrentEntity(); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("update_current_entity", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + type: "individual", + }; + server + .mockEndpoint() + .patch("/entity_users/my_entity") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.updateCurrentEntity({}); + expect(response).toEqual({ + type: "individual", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + status: "active", + tax_id: "tax_id", + website: "website", + }); + }); + + test("get_current_role", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { objects: [{ object_type: "approval_policy" }] }, + status: "active", + }; + server + .mockEndpoint() + .get("/entity_users/my_role") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.getCurrentRole(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { + objects: [ + { + object_type: "approval_policy", + }, + ], + }, + status: "active", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }; + server + .mockEndpoint() + .get("/entity_users/entity_user_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.getById("entity_user_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/entity_users/entity_user_id").respondWith().statusCode(200).build(); + + const response = await client.entityUsers.deleteById("entity_user_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }; + server + .mockEndpoint() + .patch("/entity_users/entity_user_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.entityUsers.updateById("entity_user_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + email: "email", + first_name: "Casey", + last_name: "last_name", + login: "caseyp", + phone: "phone", + role_id: "role_id", + status: "active", + userpic_file_id: "userpic_file_id", + }); + }); +}); diff --git a/tests/wire/events.test.ts b/tests/wire/events.test.ts new file mode 100644 index 0000000..61fe08b --- /dev/null +++ b/tests/wire/events.test.ts @@ -0,0 +1,92 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Events", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + action: "action", + api_version: "api_version", + description: "description", + entity_id: "entity_id", + object: { key: "value" }, + object_type: "account", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/events").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.events.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + action: "action", + api_version: "api_version", + description: "description", + entity_id: "entity_id", + object: { + key: "value", + }, + object_type: "account", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + action: "action", + api_version: "api_version", + description: "description", + entity_id: "entity_id", + object: { key: "value" }, + object_type: "account", + }; + server.mockEndpoint().get("/events/event_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.events.getById("event_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + action: "action", + api_version: "api_version", + description: "description", + entity_id: "entity_id", + object: { + key: "value", + }, + object_type: "account", + }); + }); +}); diff --git a/tests/wire/files.test.ts b/tests/wire/files.test.ts new file mode 100644 index 0000000..bd92bd2 --- /dev/null +++ b/tests/wire/files.test.ts @@ -0,0 +1,115 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Files", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + }; + server.mockEndpoint().get("/files").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.files.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }; + server.mockEndpoint().get("/files/file_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.files.getById("file_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }); + }); + + test("delete", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/files/file_id").respondWith().statusCode(200).build(); + + const response = await client.files.delete("file_id"); + expect(response).toEqual(undefined); + }); +}); diff --git a/tests/wire/financing.test.ts b/tests/wire/financing.test.ts new file mode 100644 index 0000000..3afa62f --- /dev/null +++ b/tests/wire/financing.test.ts @@ -0,0 +1,193 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Financing", () => { + test("get_financing_invoices", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + advance_amount: 1, + advance_rate_percentage: 1, + currency: "AED", + description: "description", + document_id: "document_id", + due_date: "due_date", + fee_amount: 1, + fee_percentage: 1, + invoice_id: "invoice_id", + issue_date: "issue_date", + payer_business_name: "payer_business_name", + payer_first_name: "payer_first_name", + payer_last_name: "payer_last_name", + payer_type: "payer_type", + principal_amount: 1, + repayment_amount: 1, + repayment_schedule: { + repayment_amount: 1, + repayment_date: "repayment_date", + repayment_fee_amount: 1, + repayment_principal_amount: 1, + }, + requested_amount: 1, + status: "DRAFT", + total_amount: 1, + type: "payable", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/financing_invoices") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.financing.getFinancingInvoices(); + expect(response).toEqual({ + data: [ + { + advance_amount: 1, + advance_rate_percentage: 1, + currency: "AED", + description: "description", + document_id: "document_id", + due_date: "due_date", + fee_amount: 1, + fee_percentage: 1, + invoice_id: "invoice_id", + issue_date: "issue_date", + payer_business_name: "payer_business_name", + payer_first_name: "payer_first_name", + payer_last_name: "payer_last_name", + payer_type: "payer_type", + principal_amount: 1, + repayment_amount: 1, + repayment_schedule: { + repayment_amount: 1, + repayment_date: "repayment_date", + repayment_fee_amount: 1, + repayment_principal_amount: 1, + }, + requested_amount: 1, + status: "DRAFT", + total_amount: 1, + type: "payable", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("post_financing_invoices", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { invoices: [{ id: "id", type: "payable" }] }; + const rawResponseBody = { connect_token: "connect_token", session_token: "session_token" }; + server + .mockEndpoint() + .post("/financing_invoices") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.financing.postFinancingInvoices({ + invoices: [ + { + id: "id", + type: "payable", + }, + ], + }); + expect(response).toEqual({ + connect_token: "connect_token", + session_token: "session_token", + }); + }); + + test("get_financing_offers", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + business_status: "NEW", + offers: [ + { + available_amount: 500000, + currency: "AED", + pricing_plans: [ + { advance_rate_percentage: 1, fee_percentage: 1, repayment_type: "MULTIPLE_DURATION" }, + ], + status: "NEW", + total_amount: 1000000, + }, + ], + }; + server.mockEndpoint().get("/financing_offers").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.financing.getFinancingOffers(); + expect(response).toEqual({ + business_status: "NEW", + offers: [ + { + available_amount: 500000, + currency: "AED", + pricing_plans: [ + { + advance_rate_percentage: 1, + fee_percentage: 1, + repayment_type: "MULTIPLE_DURATION", + }, + ], + status: "NEW", + total_amount: 1000000, + }, + ], + }); + }); + + test("post_financing_tokens", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { connect_token: "connect_token" }; + server.mockEndpoint().post("/financing_tokens").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.financing.postFinancingTokens(); + expect(response).toEqual({ + connect_token: "connect_token", + }); + }); +}); diff --git a/tests/wire/mailTemplates.test.ts b/tests/wire/mailTemplates.test.ts new file mode 100644 index 0000000..11ffcbd --- /dev/null +++ b/tests/wire/mailTemplates.test.ts @@ -0,0 +1,331 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("MailTemplates", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/mail_templates").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.mailTemplates.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + body_template: "body_template", + name: "name", + subject_template: "subject_template", + type: "receivables_quote", + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }; + server + .mockEndpoint() + .post("/mail_templates") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.create({ + body_template: "body_template", + name: "name", + subject_template: "subject_template", + type: "receivables_quote", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }); + }); + + test("preview", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + body: "body", + document_type: "receivables_quote", + language_code: "ab", + subject: "subject", + }; + const rawResponseBody = { body_preview: "body_preview", subject_preview: "subject_preview" }; + server + .mockEndpoint() + .post("/mail_templates/preview") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.preview({ + body: "body", + document_type: "receivables_quote", + language_code: "ab", + subject: "subject", + }); + expect(response).toEqual({ + body_preview: "body_preview", + subject_preview: "subject_preview", + }); + }); + + test("get_system", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + available_templates: [ + { body_template: "body_template", language: "language", subject_template: "subject_template" }, + ], + template_name: "template_name", + }, + ], + }; + server + .mockEndpoint() + .get("/mail_templates/system") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.getSystem(); + expect(response).toEqual({ + data: [ + { + available_templates: [ + { + body_template: "body_template", + language: "language", + subject_template: "subject_template", + }, + ], + template_name: "template_name", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }; + server + .mockEndpoint() + .get("/mail_templates/template_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.getById("template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/mail_templates/template_id").respondWith().statusCode(200).build(); + + const response = await client.mailTemplates.deleteById("template_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }; + server + .mockEndpoint() + .patch("/mail_templates/template_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.updateById("template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }; + server + .mockEndpoint() + .post("/mail_templates/template_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailTemplates.makeDefaultById("template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + body_template: "body_template", + is_default: true, + language: "language", + name: "name", + subject_template: "subject_template", + type: "type", + }); + }); +}); diff --git a/tests/wire/mailboxDomains.test.ts b/tests/wire/mailboxDomains.test.ts new file mode 100644 index 0000000..3ae5892 --- /dev/null +++ b/tests/wire/mailboxDomains.test.ts @@ -0,0 +1,168 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("MailboxDomains", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + dedicated_ip: "dedicated_ip", + dns_records: { + receiving_dns_records: [ + { is_active: true, record_type: "TXT", valid: "valid", value: "value" }, + ], + sending_dns_records: [{ is_active: true, record_type: "TXT", valid: "valid", value: "value" }], + }, + domain: "domain", + last_updated_at: "2024-01-15T09:30:00Z", + status: "status", + }, + ], + }; + server.mockEndpoint().get("/mailbox_domains").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.mailboxDomains.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + dedicated_ip: "dedicated_ip", + dns_records: { + receiving_dns_records: [ + { + is_active: true, + record_type: "TXT", + valid: "valid", + value: "value", + }, + ], + sending_dns_records: [ + { + is_active: true, + record_type: "TXT", + valid: "valid", + value: "value", + }, + ], + }, + domain: "domain", + last_updated_at: "2024-01-15T09:30:00Z", + status: "status", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { domain: "domain" }; + const rawResponseBody = { + id: "id", + dedicated_ip: "dedicated_ip", + dns_records: { + receiving_dns_records: [{ is_active: true, record_type: "TXT", valid: "valid", value: "value" }], + sending_dns_records: [{ is_active: true, record_type: "TXT", valid: "valid", value: "value" }], + }, + domain: "domain", + last_updated_at: "2024-01-15T09:30:00Z", + status: "status", + }; + server + .mockEndpoint() + .post("/mailbox_domains") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailboxDomains.create({ + domain: "domain", + }); + expect(response).toEqual({ + id: "id", + dedicated_ip: "dedicated_ip", + dns_records: { + receiving_dns_records: [ + { + is_active: true, + record_type: "TXT", + valid: "valid", + value: "value", + }, + ], + sending_dns_records: [ + { + is_active: true, + record_type: "TXT", + valid: "valid", + value: "value", + }, + ], + }, + domain: "domain", + last_updated_at: "2024-01-15T09:30:00Z", + status: "status", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/mailbox_domains/domain_id").respondWith().statusCode(200).build(); + + const response = await client.mailboxDomains.deleteById("domain_id"); + expect(response).toEqual(undefined); + }); + + test("verify_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { id: "id", domain: "domain", status: "status" }; + server + .mockEndpoint() + .post("/mailbox_domains/domain_id/verify") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailboxDomains.verifyById("domain_id"); + expect(response).toEqual({ + id: "id", + domain: "domain", + status: "status", + }); + }); +}); diff --git a/tests/wire/mailboxes.test.ts b/tests/wire/mailboxes.test.ts new file mode 100644 index 0000000..2bb817c --- /dev/null +++ b/tests/wire/mailboxes.test.ts @@ -0,0 +1,153 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Mailboxes", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }, + ], + }; + server.mockEndpoint().get("/mailboxes").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.mailboxes.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + mailbox_domain_id: "mailbox_domain_id", + mailbox_name: "mailbox_name", + related_object_type: "payable", + }; + const rawResponseBody = { + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }; + server + .mockEndpoint() + .post("/mailboxes") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailboxes.create({ + mailbox_domain_id: "mailbox_domain_id", + mailbox_name: "mailbox_name", + related_object_type: "payable", + }); + expect(response).toEqual({ + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }); + }); + + test("search", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { entity_ids: ["entity_ids"] }; + const rawResponseBody = { + data: [ + { + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }, + ], + }; + server + .mockEndpoint() + .post("/mailboxes/search") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.mailboxes.search({ + entity_ids: ["entity_ids"], + }); + expect(response).toEqual({ + data: [ + { + id: "id", + mailbox_domain_id: "mailbox_domain_id", + mailbox_full_address: "mailbox_full_address", + mailbox_name: "mailbox_name", + related_object_type: "related_object_type", + status: "status", + }, + ], + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/mailboxes/mailbox_id").respondWith().statusCode(200).build(); + + const response = await client.mailboxes.deleteById("mailbox_id"); + expect(response).toEqual(undefined); + }); +}); diff --git a/tests/wire/measureUnits.test.ts b/tests/wire/measureUnits.test.ts new file mode 100644 index 0000000..0186c1e --- /dev/null +++ b/tests/wire/measureUnits.test.ts @@ -0,0 +1,165 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("MeasureUnits", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }, + ], + }; + server.mockEndpoint().get("/measure_units").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.measureUnits.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }; + server + .mockEndpoint() + .post("/measure_units") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.measureUnits.create({ + name: "name", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }; + server + .mockEndpoint() + .get("/measure_units/unit_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.measureUnits.getById("unit_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/measure_units/unit_id").respondWith().statusCode(200).build(); + + const response = await client.measureUnits.deleteById("unit_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }; + server + .mockEndpoint() + .patch("/measure_units/unit_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.measureUnits.updateById("unit_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + name: "name", + }); + }); +}); diff --git a/tests/wire/ocr.test.ts b/tests/wire/ocr.test.ts new file mode 100644 index 0000000..e49f240 --- /dev/null +++ b/tests/wire/ocr.test.ts @@ -0,0 +1,249 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Ocr", () => { + test("get_ocr_tasks", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + recipient: { address: {}, bank_account: {} }, + sender: { address: {}, bank_account: {} }, + type: "invoice", + }, + status: "processing", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/ocr_tasks").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.ocr.getOcrTasks(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + type: "invoice", + recipient: { + address: {}, + bank_account: {}, + }, + sender: { + address: {}, + bank_account: {}, + }, + }, + status: "processing", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("post_ocr_tasks", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { file_url: "file_url" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + amount_paid: 1.1, + currency: "AED", + document_number: "document_number", + due_date: "due_date", + issue_date: "issue_date", + line_items: [{}], + payment_terms: "payment_terms", + recipient: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + sender: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + subtotal: 1.1, + tax_amount: 1.1, + tax_rate: 1.1, + total_amount: 1.1, + type: "invoice", + }, + status: "processing", + }; + server + .mockEndpoint() + .post("/ocr_tasks") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.ocr.postOcrTasks({ + file_url: "file_url", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + type: "invoice", + amount_paid: 1.1, + currency: "AED", + document_number: "document_number", + due_date: "due_date", + issue_date: "issue_date", + line_items: [{}], + payment_terms: "payment_terms", + recipient: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + sender: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + subtotal: 1.1, + tax_amount: 1.1, + tax_rate: 1.1, + total_amount: 1.1, + }, + status: "processing", + }); + }); + + test("get_ocr_tasks_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + amount_paid: 1.1, + currency: "AED", + document_number: "document_number", + due_date: "due_date", + issue_date: "issue_date", + line_items: [{}], + payment_terms: "payment_terms", + recipient: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + sender: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + subtotal: 1.1, + tax_amount: 1.1, + tax_rate: 1.1, + total_amount: 1.1, + type: "invoice", + }, + status: "processing", + }; + server.mockEndpoint().get("/ocr_tasks/task_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.ocr.getOcrTasksId("task_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "invoice", + recognized_data: { + type: "invoice", + amount_paid: 1.1, + currency: "AED", + document_number: "document_number", + due_date: "due_date", + issue_date: "issue_date", + line_items: [{}], + payment_terms: "payment_terms", + recipient: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + sender: { + address: {}, + bank_account: {}, + email: "email", + name: "name", + tax_number: "tax_number", + vat_number: "vat_number", + }, + subtotal: 1.1, + tax_amount: 1.1, + tax_rate: 1.1, + total_amount: 1.1, + }, + status: "processing", + }); + }); +}); diff --git a/tests/wire/overdueReminders.test.ts b/tests/wire/overdueReminders.test.ts new file mode 100644 index 0000000..da40ab5 --- /dev/null +++ b/tests/wire/overdueReminders.test.ts @@ -0,0 +1,207 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("OverdueReminders", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + terms: [{ body: "body", days_after: 1, subject: "subject" }], + }, + ], + }; + server.mockEndpoint().get("/overdue_reminders").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.overdueReminders.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + terms: [ + { + body: "body", + days_after: 1, + subject: "subject", + }, + ], + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + terms: [{ body: "body", days_after: 1, subject: "subject" }], + }; + server + .mockEndpoint() + .post("/overdue_reminders") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.overdueReminders.create({ + name: "name", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + terms: [ + { + body: "body", + days_after: 1, + subject: "subject", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + terms: [{ body: "body", days_after: 1, subject: "subject" }], + }; + server + .mockEndpoint() + .get("/overdue_reminders/overdue_reminder_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.overdueReminders.getById("overdue_reminder_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + terms: [ + { + body: "body", + days_after: 1, + subject: "subject", + }, + ], + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/overdue_reminders/overdue_reminder_id").respondWith().statusCode(200).build(); + + const response = await client.overdueReminders.deleteById("overdue_reminder_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + terms: [{ body: "body", days_after: 1, subject: "subject" }], + }; + server + .mockEndpoint() + .patch("/overdue_reminders/overdue_reminder_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.overdueReminders.updateById("overdue_reminder_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + terms: [ + { + body: "body", + days_after: 1, + subject: "subject", + }, + ], + }); + }); +}); diff --git a/tests/wire/partnerSettings.test.ts b/tests/wire/partnerSettings.test.ts new file mode 100644 index 0000000..ef217a4 --- /dev/null +++ b/tests/wire/partnerSettings.test.ts @@ -0,0 +1,217 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PartnerSettings", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + api_version: "2024-05-25", + commercial_conditions: ["commercial_conditions"], + currency: { default: "AED", exchange_rates: [{ base: "AED", rate: 0.98, to: "AED" }] }, + default_role: { key: "value" }, + mail: { attach_documents_as_pdf: true, from_email_username: "from_email_username", from_name: "from_name" }, + payable: { + allow_cancel_duplicates_automatically: true, + allow_counterpart_autocreation: true, + allow_counterpart_autolinking: true, + allow_credit_note_autolinking: true, + approve_page_url: "https://monite.com", + default_state: "default_state", + enable_line_items: true, + skip_approval_for_paid_invoice: true, + }, + payments: { + payment_page_domain: "payment_page_domain", + payment_page_theme: { + background_color: "background_color", + border_radius: "border_radius", + font_color: "font_color", + font_family: "font_family", + font_link_href: "font_link_href", + logo_src: "logo_src", + }, + support_email: "support_email", + }, + receivable: { create_without_personal_info: true, deduction_title: "deduction_title" }, + units: [{ designation: "kg", name: "Kilogram" }], + website: "website", + }; + server.mockEndpoint().get("/settings").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.partnerSettings.get(); + expect(response).toEqual({ + api_version: "2024-05-25", + commercial_conditions: ["commercial_conditions"], + currency: { + default: "AED", + exchange_rates: [ + { + base: "AED", + rate: 0.98, + to: "AED", + }, + ], + }, + default_role: { + key: "value", + }, + mail: { + attach_documents_as_pdf: true, + from_email_username: "from_email_username", + from_name: "from_name", + }, + payable: { + allow_cancel_duplicates_automatically: true, + allow_counterpart_autocreation: true, + allow_counterpart_autolinking: true, + allow_credit_note_autolinking: true, + approve_page_url: "https://monite.com", + default_state: "default_state", + enable_line_items: true, + skip_approval_for_paid_invoice: true, + }, + payments: { + payment_page_domain: "payment_page_domain", + payment_page_theme: { + background_color: "background_color", + border_radius: "border_radius", + font_color: "font_color", + font_family: "font_family", + font_link_href: "font_link_href", + logo_src: "logo_src", + }, + support_email: "support_email", + }, + receivable: { + create_without_personal_info: true, + deduction_title: "deduction_title", + }, + units: [ + { + designation: "kg", + name: "Kilogram", + }, + ], + website: "website", + }); + }); + + test("update", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + api_version: "2024-05-25", + commercial_conditions: ["commercial_conditions"], + currency: { default: "AED", exchange_rates: [{ base: "AED", rate: 0.98, to: "AED" }] }, + default_role: { key: "value" }, + mail: { attach_documents_as_pdf: true, from_email_username: "from_email_username", from_name: "from_name" }, + payable: { + allow_cancel_duplicates_automatically: true, + allow_counterpart_autocreation: true, + allow_counterpart_autolinking: true, + allow_credit_note_autolinking: true, + approve_page_url: "https://monite.com", + default_state: "default_state", + enable_line_items: true, + skip_approval_for_paid_invoice: true, + }, + payments: { + payment_page_domain: "payment_page_domain", + payment_page_theme: { + background_color: "background_color", + border_radius: "border_radius", + font_color: "font_color", + font_family: "font_family", + font_link_href: "font_link_href", + logo_src: "logo_src", + }, + support_email: "support_email", + }, + receivable: { create_without_personal_info: true, deduction_title: "deduction_title" }, + units: [{ designation: "kg", name: "Kilogram" }], + website: "website", + }; + server + .mockEndpoint() + .patch("/settings") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.partnerSettings.update(); + expect(response).toEqual({ + api_version: "2024-05-25", + commercial_conditions: ["commercial_conditions"], + currency: { + default: "AED", + exchange_rates: [ + { + base: "AED", + rate: 0.98, + to: "AED", + }, + ], + }, + default_role: { + key: "value", + }, + mail: { + attach_documents_as_pdf: true, + from_email_username: "from_email_username", + from_name: "from_name", + }, + payable: { + allow_cancel_duplicates_automatically: true, + allow_counterpart_autocreation: true, + allow_counterpart_autolinking: true, + allow_credit_note_autolinking: true, + approve_page_url: "https://monite.com", + default_state: "default_state", + enable_line_items: true, + skip_approval_for_paid_invoice: true, + }, + payments: { + payment_page_domain: "payment_page_domain", + payment_page_theme: { + background_color: "background_color", + border_radius: "border_radius", + font_color: "font_color", + font_family: "font_family", + font_link_href: "font_link_href", + logo_src: "logo_src", + }, + support_email: "support_email", + }, + receivable: { + create_without_personal_info: true, + deduction_title: "deduction_title", + }, + units: [ + { + designation: "kg", + name: "Kilogram", + }, + ], + website: "website", + }); + }); +}); diff --git a/tests/wire/payables.test.ts b/tests/wire/payables.test.ts new file mode 100644 index 0000000..f2aaa33 --- /dev/null +++ b/tests/wire/payables.test.ts @@ -0,0 +1,5129 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Payables", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_name: "Monite GMbH", + counterpart_vat_id: "DE88939004", + currency: "EUR", + document_id: "CST-13341", + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { name: "name", term_final: { number_of_days: 1 } }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date" }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/payables").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.payables.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_name: "Monite GMbH", + counterpart_vat_id: "DE88939004", + currency: "EUR", + document_id: "CST-13341", + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + name: "name", + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.create(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("get_analytics", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + count: 1, + data: [{ count: 1, status: "draft", sum_total_amount: 1 }], + sum_total_amount: 1, + }; + server + .mockEndpoint() + .get("/payables/analytics") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getAnalytics(); + expect(response).toEqual({ + count: 1, + data: [ + { + count: 1, + status: "draft", + sum_total_amount: 1, + }, + ], + sum_total_amount: 1, + }); + }); + + test("get_validations", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .get("/payables/validations") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getValidations(); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("update_validations", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { required_fields: ["currency"] }; + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .put("/payables/validations") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.updateValidations({ + required_fields: ["currency"], + }); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("reset_validations", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { required_fields: ["currency"] }; + server + .mockEndpoint() + .post("/payables/validations/reset") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.resetValidations(); + expect(response).toEqual({ + required_fields: ["currency"], + }); + }); + + test("get_variables", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + object_subtype: "payables_purchase_order", + object_type: "account", + variables: [{ description: "description", name: "name" }], + }, + ], + }; + server + .mockEndpoint() + .get("/payables/variables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getVariables(); + expect(response).toEqual({ + data: [ + { + object_subtype: "payables_purchase_order", + object_type: "account", + variables: [ + { + description: "description", + name: "name", + }, + ], + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .get("/payables/payable_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/payables/payable_id").respondWith().statusCode(200).build(); + + const response = await client.payables.deleteById("payable_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .patch("/payables/payable_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.updateById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("approve_payment_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/approve_payment_operation") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.approvePaymentById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("cancel_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/cancel") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.cancelById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("post_payables_id_cancel_ocr", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/cancel_ocr") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.postPayablesIdCancelOcr("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("get_payables_id_history", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { new_status: "draft", old_status: "draft" }, + event_type: "status_changed", + payable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/payables/payable_id/history") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getPayablesIdHistory("payable_id"); + expect(response).toEqual({ + data: [ + { + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { + new_status: "draft", + old_status: "draft", + }, + event_type: "status_changed", + payable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("mark_as_paid_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/mark_as_paid") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.markAsPaidById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("mark_as_partially_paid_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { amount_paid: 1 }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/mark_as_partially_paid") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.markAsPartiallyPaidById("payable_id", { + amount_paid: 1, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("reject_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/reject") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.rejectById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("reopen_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/reopen") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.reopenById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("submit_for_approval_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { country: "AF", type: "type", value: "value" }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { default_currency_code: "default_currency_code", rate: 1.1, total: 1.1 }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { key: "value" }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { date: "date", discount: 1 }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }; + server + .mockEndpoint() + .post("/payables/payable_id/submit_for_approval") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.submitForApprovalById("payable_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + amount_due: 1000, + amount_paid: 1000, + amount_to_pay: 1000, + approval_policy_id: "approval_policy_id", + counterpart: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_address_id: "counterpart_address_id", + counterpart_bank_account_id: "counterpart_bank_account_id", + counterpart_id: "counterpart_id", + counterpart_raw_data: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + bank_account: { + account_holder_name: "account_holder_name", + account_number: "123456789012", + bic: "DEUTDE2HXXX", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + email: "acme@example.com", + name: "Acme Inc.", + phone: "5551231234", + tax_id: "DE12345678", + vat_id: { + country: "AF", + type: "type", + value: "value", + }, + }, + counterpart_vat_id_id: "counterpart_vat_id_id", + created_by_role_id: "created_by_role_id", + credit_notes: [ + { + id: "123e4567-e89b-12d3-a456-426614174000", + document_id: "CN-123456", + issued_at: "2024-01-15", + status: "submitted_for_approval", + total_amount: 1000, + }, + ], + currency: "AED", + currency_exchange: { + default_currency_code: "default_currency_code", + rate: 1.1, + total: 1.1, + }, + description: "description", + discount: 500, + document_id: "DE2287", + due_date: "due_date", + entity_id: "entity_id", + file: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + file_id: "file_id", + issued_at: "issued_at", + marked_as_paid_by_entity_user_id: "71e8875a-43b3-434f-b12a-54c84c176ef3", + marked_as_paid_with_comment: "Was paid partly in the end of the month.", + ocr_request_id: "ocr_request_id", + ocr_status: "processing", + other_extracted_data: { + counterpart_account_id: "DEUTDEFF", + counterpart_account_number: "counterpart_account_number", + counterpart_address: "counterpart_address", + counterpart_address_object: { + city: "Berlin", + country: "DE", + line1: "Flughafenstrasse 52", + line2: "line2", + original_country_name: "Berlin", + postal_code: "10115", + state: "state", + }, + counterpart_branch_number: "counterpart_branch_number", + counterpart_email: "counterpart_email", + counterpart_name: "Monite GMbH", + counterpart_routing_number: "counterpart_routing_number", + counterpart_vat_id: "DE88939004", + currency: "EUR", + discount_raw: 1.1, + document_due_date: "document_due_date", + document_id: "CST-13341", + document_issued_at_date: "document_issued_at_date", + line_items_raw: [ + { + description: "Impact Players : How to Take the Lead , Play Bigger , and Multiply Your", + quantity: 1.2, + total_excl_vat: 120, + total_incl_vat: 135, + unit: "meters", + unit_price: 100, + vat_amount: 15, + vat_percentage: 12.5, + }, + ], + payment_terms_raw: ["payment_terms_raw"], + purchase_order_number: "1234", + tax_payer_id: "12345678901", + total_excl_vat_raw: 77, + total_paid_amount_raw: 50, + total_raw: 70, + total_vat_amount_raw: 7, + total_vat_rate_raw: 12.5, + type: "invoice", + }, + paid_at: "2024-01-15T09:30:00Z", + partner_metadata: { + key: "value", + }, + payable_origin: "upload", + payment_terms: { + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + project_id: "project_id", + purchase_order_id: "purchase_order_id", + sender: "hello@example.com", + source_of_payable_data: "ocr", + status: "draft", + subtotal: 1250, + suggested_payment_term: { + date: "date", + discount: 1, + }, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + tax: 2000, + tax_amount: 250, + total_amount: 1500, + total_amount_with_credit_notes: 1, + was_created_by_user_id: "was_created_by_user_id", + }); + }); + + test("get_payables_id_suggestions", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + suggested_counterpart: { + id: "id", + address_id: "address_id", + bank_account_id: "bank_account_id", + vat_id_id: "vat_id_id", + }, + }; + server + .mockEndpoint() + .get("/payables/payable_id/suggestions") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.getPayablesIdSuggestions("payable_id"); + expect(response).toEqual({ + suggested_counterpart: { + id: "id", + address_id: "address_id", + bank_account_id: "bank_account_id", + vat_id_id: "vat_id_id", + }, + }); + }); + + test("delete_payables_id_suggestions", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { key: "value" }; + server + .mockEndpoint() + .delete("/payables/payable_id/suggestions") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.deletePayablesIdSuggestions("payable_id"); + expect(response).toEqual({ + key: "value", + }); + }); + + test("validate_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { id: "id", validation_errors: [{ key: "value" }] }; + server + .mockEndpoint() + .post("/payables/payable_id/validate") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.validateById("payable_id"); + expect(response).toEqual({ + id: "id", + validation_errors: [ + { + key: "value", + }, + ], + }); + }); +}); diff --git a/tests/wire/payables/lineItems.test.ts b/tests/wire/payables/lineItems.test.ts new file mode 100644 index 0000000..d993906 --- /dev/null +++ b/tests/wire/payables/lineItems.test.ts @@ -0,0 +1,324 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../../mock-server/MockServerPool"; +import { MoniteClient } from "../../../src/Client"; +import * as Monite from "../../../src/api/index"; + +describe("LineItems", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/payables/payable_id/line_items") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.lineItems.get("payable_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }; + server + .mockEndpoint() + .post("/payables/payable_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.lineItems.create("payable_id", {}); + expect(response).toEqual({ + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }); + }); + + test("replace", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { data: [{}] }; + const rawResponseBody = { + data: [ + { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }, + ], + }; + server + .mockEndpoint() + .put("/payables/payable_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.lineItems.replace("payable_id", { + data: [{}], + }); + expect(response).toEqual({ + data: [ + { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }; + server + .mockEndpoint() + .get("/payables/payable_id/line_items/line_item_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.lineItems.getById("line_item_id", "payable_id"); + expect(response).toEqual({ + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/payables/payable_id/line_items/line_item_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.payables.lineItems.deleteById("line_item_id", "payable_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }; + server + .mockEndpoint() + .patch("/payables/payable_id/line_items/line_item_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.payables.lineItems.updateById("line_item_id", "payable_id", {}); + expect(response).toEqual({ + id: "id", + accounting_tax_rate_id: "dd13735f-ef3a-4312-8c37-835d70341375", + description: "description", + ledger_account_id: "7df884fd-8be8-4eba-b6ff-417b66efe033", + name: "name", + ocr_set_quantity_to_one: false, + payable_id: "payable_id", + quantity: 1.22, + subtotal: 1250, + tax: 2000, + tax_amount: 250, + total: 1200, + unit: "meter", + unit_price: 1500, + was_created_by_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + }); + }); +}); diff --git a/tests/wire/paymentIntents.test.ts b/tests/wire/paymentIntents.test.ts new file mode 100644 index 0000000..ca3eefe --- /dev/null +++ b/tests/wire/paymentIntents.test.ts @@ -0,0 +1,414 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PaymentIntents", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + }, + object: { id: "id", type: "payable" }, + payer: { id: "id", type: "entity" }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { id: "id", type: "entity" }, + selected_payment_method: "sepa_credit", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/payment_intents").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.paymentIntents.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + }, + object: { + id: "id", + type: "payable", + }, + payer: { + id: "id", + type: "entity", + }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { + id: "id", + type: "entity", + }, + selected_payment_method: "sepa_credit", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + object: { id: "id", type: "payable" }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + selected_payment_method: "sepa_credit", + status: "status", + }; + server + .mockEndpoint() + .get("/payment_intents/payment_intent_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentIntents.getById("payment_intent_id"); + expect(response).toEqual({ + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + object: { + id: "id", + type: "payable", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + selected_payment_method: "sepa_credit", + status: "status", + }); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { amount: 1 }; + const rawResponseBody = { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + object: { id: "id", type: "payable" }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + selected_payment_method: "sepa_credit", + status: "status", + }; + server + .mockEndpoint() + .patch("/payment_intents/payment_intent_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentIntents.updateById("payment_intent_id", { + amount: 1, + }); + expect(response).toEqual({ + id: "id", + updated_at: "2024-01-15T09:30:00Z", + amount: 1, + application_fee_amount: 1, + batch_payment_id: "batch_payment_id", + currency: "currency", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + object: { + id: "id", + type: "payable", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_link_id: "payment_link_id", + payment_methods: ["sepa_credit"], + payment_reference: "payment_reference", + provider: "provider", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + selected_payment_method: "sepa_credit", + status: "status", + }); + }); + + test("get_history_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + status: "status", + }, + ], + }; + server + .mockEndpoint() + .get("/payment_intents/payment_intent_id/history") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentIntents.getHistoryById("payment_intent_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + status: "status", + }, + ], + }); + }); +}); diff --git a/tests/wire/paymentLinks.test.ts b/tests/wire/paymentLinks.test.ts new file mode 100644 index 0000000..0634f46 --- /dev/null +++ b/tests/wire/paymentLinks.test.ts @@ -0,0 +1,478 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PaymentLinks", () => { + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + object: { id: "5940eb3a-de95-4e7e-b5e7-8a4ad0ea341b", type: "payable" }, + payment_methods: ["sepa_credit"], + recipient: { id: "6296af34-6feb-43c1-b567-83e3bf45050c", type: "counterpart" }, + return_url: "https://example.com/where-to-redirect-after-payment", + }; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { id: "id", type: "payable" }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_links") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentLinks.create({ + object: { + id: "5940eb3a-de95-4e7e-b5e7-8a4ad0ea341b", + type: "payable", + }, + payment_methods: ["sepa_credit"], + recipient: { + id: "6296af34-6feb-43c1-b567-83e3bf45050c", + type: "counterpart", + }, + return_url: "https://example.com/where-to-redirect-after-payment", + }); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { + id: "id", + type: "payable", + }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { id: "id", type: "payable" }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }; + server + .mockEndpoint() + .get("/payment_links/payment_link_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentLinks.getById("payment_link_id"); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { + id: "id", + type: "payable", + }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }); + }); + + test("expire_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { id: "id", type: "payable" }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_links/payment_link_id/expire") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentLinks.expireById("payment_link_id"); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + expires_at: "2024-01-15T09:30:00Z", + invoice: { + due_date: "due_date", + file: { + mimetype: "application/pdf", + name: "INV-00042.pdf", + url: "https://example.com/path/to/invoice.pdf", + }, + issue_date: "issue_date", + }, + payer: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + payment_intent: { + id: "id", + updated_at: "2024-01-15T09:30:00Z", + application_fee_amount: 1, + object: { + id: "id", + type: "payable", + }, + provider: "provider", + selected_payment_method: "selected_payment_method", + status: "status", + }, + payment_intent_id: "payment_intent_id", + payment_methods: ["payment_methods"], + payment_page_url: "payment_page_url", + payment_reference: "payment_reference", + recipient: { + id: "id", + bank_accounts: [ + { + id: "id", + account_holder_name: "Bob Jones", + account_number: "12345678", + bic: "DEUTDEFFXXX", + display_name: "Primary account", + iban: "DE74500700100100000900", + name: "Primary account", + sort_code: "123456", + }, + ], + name: "name", + type: "entity", + }, + return_url: "https://pay.example.com/complete", + status: "status", + }); + }); +}); diff --git a/tests/wire/paymentRecords.test.ts b/tests/wire/paymentRecords.test.ts new file mode 100644 index 0000000..cb76e38 --- /dev/null +++ b/tests/wire/paymentRecords.test.ts @@ -0,0 +1,469 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; +import * as Monite from "../../src/api/index"; + +describe("PaymentRecords", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/payment_records").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.paymentRecords.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { amount: 1, currency: "AED", object: { id: "id", type: "receivable" } }; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_records") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.create({ + amount: 1, + currency: "AED", + object: { + id: "id", + type: "receivable", + }, + }); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .get("/payment_records/payment_record_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.getById("payment_record_id"); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); + + test("patch_payment_records_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .patch("/payment_records/payment_record_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.patchPaymentRecordsId("payment_record_id"); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); + + test("post_payment_records_id_cancel", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_records/payment_record_id/cancel") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.postPaymentRecordsIdCancel("payment_record_id", {}); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); + + test("post_payment_records_id_mark_as_succeeded", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { paid_at: "2024-01-15T09:30:00Z" }; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_records/payment_record_id/mark_as_succeeded") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.postPaymentRecordsIdMarkAsSucceeded("payment_record_id", { + paid_at: "2024-01-15T09:30:00Z", + }); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); + + test("post_payment_records_id_start_processing", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [{ entity_user_id: "entity_user_id", status: "created", timestamp: "2024-01-15T09:30:00Z" }], + is_external: true, + object: { id: "id", new_status: "new_status", old_status: "old_status", type: "receivable" }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }; + server + .mockEndpoint() + .post("/payment_records/payment_record_id/start_processing") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentRecords.postPaymentRecordsIdStartProcessing("payment_record_id", {}); + expect(response).toEqual({ + id: "id", + amount: 1, + currency: "AED", + entity_user_id: "entity_user_id", + history: [ + { + entity_user_id: "entity_user_id", + status: "created", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + is_external: true, + object: { + id: "id", + new_status: "new_status", + old_status: "old_status", + type: "receivable", + }, + overpaid_amount: 1, + paid_at: "2024-01-15T09:30:00Z", + payment_intent_id: "payment_intent_id", + payment_intent_status: "payment_intent_status", + payment_method: "payment_method", + planned_payment_date: "planned_payment_date", + status: "status", + }); + }); +}); diff --git a/tests/wire/paymentReminders.test.ts b/tests/wire/paymentReminders.test.ts new file mode 100644 index 0000000..afe93d6 --- /dev/null +++ b/tests/wire/paymentReminders.test.ts @@ -0,0 +1,263 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PaymentReminders", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + status: "active", + term_1_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_2_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_final_reminder: { body: "body", days_before: 1, subject: "subject" }, + }, + ], + }; + server.mockEndpoint().get("/payment_reminders").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.paymentReminders.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + status: "active", + term_1_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_2_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_final_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + status: "active", + term_1_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_2_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_final_reminder: { body: "body", days_before: 1, subject: "subject" }, + }; + server + .mockEndpoint() + .post("/payment_reminders") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentReminders.create({ + name: "name", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + status: "active", + term_1_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_2_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_final_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + status: "active", + term_1_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_2_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_final_reminder: { body: "body", days_before: 1, subject: "subject" }, + }; + server + .mockEndpoint() + .get("/payment_reminders/payment_reminder_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentReminders.getById("payment_reminder_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + status: "active", + term_1_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_2_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_final_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/payment_reminders/payment_reminder_id").respondWith().statusCode(200).build(); + + const response = await client.paymentReminders.deleteById("payment_reminder_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + status: "active", + term_1_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_2_reminder: { body: "body", days_before: 1, subject: "subject" }, + term_final_reminder: { body: "body", days_before: 1, subject: "subject" }, + }; + server + .mockEndpoint() + .patch("/payment_reminders/payment_reminder_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentReminders.updateById("payment_reminder_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + entity_id: "entity_id", + name: "name", + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + status: "active", + term_1_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_2_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + term_final_reminder: { + body: "body", + days_before: 1, + subject: "subject", + }, + }); + }); +}); diff --git a/tests/wire/paymentTerms.test.ts b/tests/wire/paymentTerms.test.ts new file mode 100644 index 0000000..40d19fa --- /dev/null +++ b/tests/wire/paymentTerms.test.ts @@ -0,0 +1,213 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PaymentTerms", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }, + ], + }; + server.mockEndpoint().get("/payment_terms").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.paymentTerms.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + description: "Payment is due within 30 days after the invoice issue date", + name: "Net 30", + term_final: { number_of_days: 30 }, + }; + const rawResponseBody = { + id: "id", + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }; + server + .mockEndpoint() + .post("/payment_terms") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentTerms.create({ + description: "Payment is due within 30 days after the invoice issue date", + name: "Net 30", + term_final: { + number_of_days: 30, + }, + }); + expect(response).toEqual({ + id: "id", + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }; + server + .mockEndpoint() + .get("/payment_terms/payment_terms_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentTerms.getById("payment_terms_id"); + expect(response).toEqual({ + id: "id", + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/payment_terms/payment_terms_id").respondWith().statusCode(200).build(); + + const response = await client.paymentTerms.deleteById("payment_terms_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + description: "description", + name: "name", + term_1: { discount: 1, number_of_days: 1 }, + term_2: { discount: 1, number_of_days: 1 }, + term_final: { number_of_days: 1 }, + }; + server + .mockEndpoint() + .patch("/payment_terms/payment_terms_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.paymentTerms.updateById("payment_terms_id"); + expect(response).toEqual({ + id: "id", + description: "description", + name: "name", + term_1: { + discount: 1, + number_of_days: 1, + }, + term_2: { + discount: 1, + number_of_days: 1, + }, + term_final: { + number_of_days: 1, + }, + }); + }); +}); diff --git a/tests/wire/pdfTemplates.test.ts b/tests/wire/pdfTemplates.test.ts new file mode 100644 index 0000000..3ab3128 --- /dev/null +++ b/tests/wire/pdfTemplates.test.ts @@ -0,0 +1,312 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PdfTemplates", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }, + ], + }; + server + .mockEndpoint() + .get("/document_templates") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.pdfTemplates.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }, + ], + }); + }); + + test("get_system", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }, + ], + }; + server + .mockEndpoint() + .get("/document_templates/system") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.pdfTemplates.getSystem(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }; + server + .mockEndpoint() + .get("/document_templates/document_template_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.pdfTemplates.getById("document_template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }; + server + .mockEndpoint() + .post("/document_templates/document_template_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.pdfTemplates.makeDefaultById("document_template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + blocks: ["blocks"], + document_type: "receivable", + is_default: true, + language: "language", + name: "name", + preview: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + file_type: "file_type", + md5: "60997cbcc1a6fb2ec37d389ffa8588db", + mimetype: "application/pdf", + name: "timesheet.pdf", + region: "eu-central-1", + s3_bucket: "s3_bucket", + s3_file_path: "s3_file_path", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + template: "template", + template_type: "block", + }); + }); +}); diff --git a/tests/wire/products.test.ts b/tests/wire/products.test.ts new file mode 100644 index 0000000..468a6ce --- /dev/null +++ b/tests/wire/products.test.ts @@ -0,0 +1,245 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Products", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { currency: "AED", value: 1 }, + smallest_amount: 1.1, + type: "product", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/products").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.products.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { + currency: "AED", + value: 1, + }, + smallest_amount: 1.1, + type: "product", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { currency: "AED", value: 1 }, + smallest_amount: 1.1, + type: "product", + }; + server + .mockEndpoint() + .post("/products") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.products.create({ + name: "name", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { + currency: "AED", + value: 1, + }, + smallest_amount: 1.1, + type: "product", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { currency: "AED", value: 1 }, + smallest_amount: 1.1, + type: "product", + }; + server + .mockEndpoint() + .get("/products/product_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.products.getById("product_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { + currency: "AED", + value: 1, + }, + smallest_amount: 1.1, + type: "product", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/products/product_id").respondWith().statusCode(200).build(); + + const response = await client.products.deleteById("product_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { currency: "AED", value: 1 }, + smallest_amount: 1.1, + type: "product", + }; + server + .mockEndpoint() + .patch("/products/product_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.products.updateById("product_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + description: "description", + entity_id: "entity_id", + entity_user_id: "entity_user_id", + external_reference: "HT-1234-S-BL", + ledger_account_id: "ledger_account_id", + measure_unit_id: "measure_unit_id", + name: "name", + price: { + currency: "AED", + value: 1, + }, + smallest_amount: 1.1, + type: "product", + }); + }); +}); diff --git a/tests/wire/projects.test.ts b/tests/wire/projects.test.ts new file mode 100644 index 0000000..36a57ea --- /dev/null +++ b/tests/wire/projects.test.ts @@ -0,0 +1,327 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Projects", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { key: "value" }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/projects").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.projects.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { + key: "value", + }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "Marketing" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { key: "value" }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }; + server + .mockEndpoint() + .post("/projects") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.projects.create({ + name: "Marketing", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { + key: "value", + }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { key: "value" }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }; + server + .mockEndpoint() + .get("/projects/project_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.projects.getById("project_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { + key: "value", + }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/projects/project_id").respondWith().statusCode(200).build(); + + const response = await client.projects.deleteById("project_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { key: "value" }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }; + server + .mockEndpoint() + .patch("/projects/project_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.projects.updateById("project_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + code: "code", + color: "red", + created_by_entity_user_id: "created_by_entity_user_id", + description: "description", + end_date: "end_date", + entity_id: "entity_id", + name: "Marketing", + parent_id: "parent_id", + partner_metadata: { + key: "value", + }, + start_date: "start_date", + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + }); + }); +}); diff --git a/tests/wire/purchaseOrders.test.ts b/tests/wire/purchaseOrders.test.ts new file mode 100644 index 0000000..fea59d9 --- /dev/null +++ b/tests/wire/purchaseOrders.test.ts @@ -0,0 +1,1064 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("PurchaseOrders", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { city: "city", line1: "line1", postal_code: "postal_code" }, + individual: { first_name: "first_name", last_name: "last_name" }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + status: "active", + }, + entity_id: "entity_id", + entity_vat_id: { + id: "id", + country: "country", + entity_id: "entity_id", + type: "type", + value: "value", + }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [{ currency: "AED", name: "name", price: 1, quantity: 1, unit: "unit", vat_rate: 1 }], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/payable_purchase_orders") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + line1: "line1", + postal_code: "postal_code", + }, + individual: { + first_name: "first_name", + last_name: "last_name", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + status: "active", + }, + entity_id: "entity_id", + entity_vat_id: { + id: "id", + country: "country", + entity_id: "entity_id", + type: "type", + value: "value", + }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [ + { + currency: "AED", + name: "name", + price: 1, + quantity: 1, + unit: "unit", + vat_rate: 1, + }, + ], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + counterpart_id: "counterpart_id", + currency: "AED", + items: [{ currency: "AED", name: "name", price: 1, quantity: 1, unit: "unit", vat_rate: 1 }], + message: "message", + valid_for_days: 1, + }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { id: "id", country: "country", entity_id: "entity_id", type: "type", value: "value" }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [{ currency: "AED", name: "name", price: 1, quantity: 1, unit: "unit", vat_rate: 1 }], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }; + server + .mockEndpoint() + .post("/payable_purchase_orders") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.create({ + counterpart_id: "counterpart_id", + currency: "AED", + items: [ + { + currency: "AED", + name: "name", + price: 1, + quantity: 1, + unit: "unit", + vat_rate: 1, + }, + ], + message: "message", + valid_for_days: 1, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { + id: "id", + country: "country", + entity_id: "entity_id", + type: "type", + value: "value", + }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [ + { + currency: "AED", + name: "name", + price: 1, + quantity: 1, + unit: "unit", + vat_rate: 1, + }, + ], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }); + }); + + test("get_variables", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + object_subtype: "receivable", + object_type: "object_type", + variables: [{ description: "description", name: "name" }], + }, + ], + }; + server + .mockEndpoint() + .get("/payable_purchase_orders/variables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.getVariables(); + expect(response).toEqual({ + data: [ + { + object_subtype: "receivable", + object_type: "object_type", + variables: [ + { + description: "description", + name: "name", + }, + ], + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { id: "id", country: "country", entity_id: "entity_id", type: "type", value: "value" }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [{ currency: "AED", name: "name", price: 1, quantity: 1, unit: "unit", vat_rate: 1 }], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }; + server + .mockEndpoint() + .get("/payable_purchase_orders/purchase_order_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.getById("purchase_order_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { + id: "id", + country: "country", + entity_id: "entity_id", + type: "type", + value: "value", + }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [ + { + currency: "AED", + name: "name", + price: 1, + quantity: 1, + unit: "unit", + vat_rate: 1, + }, + ], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/payable_purchase_orders/purchase_order_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.purchaseOrders.deleteById("purchase_order_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [{ height: 400, url: "https://bucketname.s3.amazonaws.com/1/2/3.png", width: 200 }], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { id: "id", country: "country", entity_id: "entity_id", type: "type", value: "value" }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [{ currency: "AED", name: "name", price: 1, quantity: 1, unit: "unit", vat_rate: 1 }], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }; + server + .mockEndpoint() + .patch("/payable_purchase_orders/purchase_order_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.updateById("purchase_order_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + counterpart: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_automatically: true, + created_by_entity_user_id: "created_by_entity_user_id", + default_billing_address_id: "default_billing_address_id", + default_shipping_address_id: "default_shipping_address_id", + individual: { + email: "asingh@example.net", + first_name: "Adnan", + is_customer: true, + is_vendor: true, + last_name: "Singh", + phone: "5553211234", + title: "Mr.", + }, + language: "ab", + reminders_enabled: true, + tax_id: "tax_id", + type: "individual", + }, + counterpart_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_address_id: "counterpart_address_id", + counterpart_id: "counterpart_id", + created_by_user_id: "created_by_user_id", + currency: "AED", + document_id: "document_id", + entity: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + email: "email", + individual: { + date_of_birth: "date_of_birth", + first_name: "first_name", + id_number: "id_number", + last_name: "last_name", + ssn_last_4: "ssn_last_4", + title: "title", + }, + logo: { + id: "id", + created_at: "2024-01-15T09:30:00Z", + file_type: "payables", + md5: "31d1a2dd1ad3dfc39be849d70a68dac0", + mimetype: "application/pdf", + name: "invoice.pdf", + pages: [ + { + id: "id", + mimetype: "image/png", + number: 0, + size: 21972, + url: "https://bucket.s3.amazonaws.com/123/456.png", + }, + ], + previews: [ + { + height: 400, + url: "https://bucketname.s3.amazonaws.com/1/2/3.png", + width: 200, + }, + ], + region: "eu-central-1", + size: 24381, + url: "https://bucketname.s3.amazonaws.com/12345/67890.pdf", + }, + phone: "phone", + status: "active", + tax_id: "tax_id", + website: "website", + }, + entity_id: "entity_id", + entity_vat_id: { + id: "id", + country: "country", + entity_id: "entity_id", + type: "type", + value: "value", + }, + file_id: "file_id", + file_url: "file_url", + issued_at: "issued_at", + items: [ + { + currency: "AED", + name: "name", + price: 1, + quantity: 1, + unit: "unit", + vat_rate: 1, + }, + ], + message: "message", + project_id: "project_id", + status: "status", + valid_for_days: 1, + }); + }); + + test("preview_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { body_text: "body_text", subject_text: "subject_text" }; + const rawResponseBody = { body_preview: "body_preview", subject_preview: "subject_preview" }; + server + .mockEndpoint() + .post("/payable_purchase_orders/purchase_order_id/preview") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.previewById("purchase_order_id", { + body_text: "body_text", + subject_text: "subject_text", + }); + expect(response).toEqual({ + body_preview: "body_preview", + subject_preview: "subject_preview", + }); + }); + + test("send_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { body_text: "body_text", subject_text: "subject_text" }; + const rawResponseBody = { mail_id: "mail_id" }; + server + .mockEndpoint() + .post("/payable_purchase_orders/purchase_order_id/send") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.purchaseOrders.sendById("purchase_order_id", { + body_text: "body_text", + subject_text: "subject_text", + }); + expect(response).toEqual({ + mail_id: "mail_id", + }); + }); +}); diff --git a/tests/wire/receipts.test.ts b/tests/wire/receipts.test.ts new file mode 100644 index 0000000..63169cf --- /dev/null +++ b/tests/wire/receipts.test.ts @@ -0,0 +1,447 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Receipts", () => { + test("get_receipts", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { key: "value" }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { key: "value" }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/receipts").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.receipts.getReceipts(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { + key: "value", + }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { + key: "value", + }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("post_receipts", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { key: "value" }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { key: "value" }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }; + server + .mockEndpoint() + .post("/receipts") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.postReceipts(); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { + key: "value", + }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { + key: "value", + }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }); + }); + + test("get_receipts_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { key: "value" }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { key: "value" }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }; + server + .mockEndpoint() + .get("/receipts/receipt_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.getReceiptsId("receipt_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { + key: "value", + }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { + key: "value", + }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }); + }); + + test("delete_receipts_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/receipts/receipt_id").respondWith().statusCode(200).build(); + + const response = await client.receipts.deleteReceiptsId("receipt_id"); + expect(response).toEqual(undefined); + }); + + test("patch_receipts_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { key: "value" }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { key: "value" }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }; + server + .mockEndpoint() + .patch("/receipts/receipt_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.patchReceiptsId("receipt_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + created_by_entity_user_id: "created_by_entity_user_id", + currency: "AED", + currency_exchange: { + key: "value", + }, + document_id: "document_id", + file_id: "123e4567-e89b-12d3-a456-426614174000", + file_url: "file_url", + issued_at: "2024-01-15T09:30:00Z", + merchant_location: "merchant_location", + merchant_name: "merchant_name", + ocr_request_id: "ocr_request_id", + ocr_status: "ocr_status", + partner_metadata: { + key: "value", + }, + source_of_data: "ocr", + total_amount: 1, + transaction_id: "transaction_id", + }); + }); + + test("get_receipts_id_line_items", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/receipts/receipt_id/line_items") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.getReceiptsIdLineItems("receipt_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("post_receipts_id_line_items", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }; + server + .mockEndpoint() + .post("/receipts/receipt_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.postReceiptsIdLineItems("receipt_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }); + }); + + test("delete_receipts_id_line_items_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/receipts/receipt_id/line_items/line_item_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.receipts.deleteReceiptsIdLineItemsId("receipt_id", "line_item_id"); + expect(response).toEqual(undefined); + }); + + test("patch_receipts_id_line_items_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }; + server + .mockEndpoint() + .patch("/receipts/receipt_id/line_items/line_item_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receipts.patchReceiptsIdLineItemsId("receipt_id", "line_item_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + accounting_tax_rate_id: "accounting_tax_rate_id", + cost_center_id: "cost_center_id", + created_by_entity_user_id: "created_by_entity_user_id", + name: "name", + receipt_id: "receipt_id", + total: 1, + }); + }); +}); diff --git a/tests/wire/receivables.test.ts b/tests/wire/receivables.test.ts new file mode 100644 index 0000000..f18a126 --- /dev/null +++ b/tests/wire/receivables.test.ts @@ -0,0 +1,4512 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Receivables", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { id: "id", counterpart_id: "counterpart_id", value: "123456789" }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount" }, + discounted_subtotal: 1, + document_id: "document_id", + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { name: "name", type: "organization" }, + entity_address: { city: "city", line1: "line1", postal_code: "postal_code" }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [{ amount: 1, taxable_amount: 1, value: 1 }], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/receivables").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.receivables.get(); + expect(response).toEqual({ + data: [ + { + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + }, + discounted_subtotal: 1, + document_id: "document_id", + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + name: "name", + }, + entity_address: { + city: "city", + line1: "line1", + postal_code: "postal_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + amount: 1, + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { based_on: "based_on", type: "invoice" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.create({ + based_on: "based_on", + type: "invoice", + }); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("get_receivables_required_fields", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + counterpart: { + tax_id: { + description: + "The counterpart's taxpayer identification number or tax ID. For identification purposes, this field may be required for counterparts that are not VAT-registered.", + required: false, + }, + vat_id: { + description: + "The counterpart's VAT (Value Added Tax) identification number. This field is required for counterparts that are VAT-registered.", + required: true, + }, + }, + entity: { + tax_id: { + description: + "The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered.", + required: false, + }, + vat_id: { + description: + "The entity's VAT (Value Added Tax) identification number. This field is required for entities that are VAT-registered.", + required: true, + }, + }, + line_item: { + measure_unit: { + description: "Unit used to measure the quantity of the product (e.g. items, meters, kilograms)", + required: true, + }, + tax_rate_value: { + description: + "Percent minor units. Example: 12.5% is 1250. This field is only required on invoices issued by entities in the US, Pakistan, and other unsupported countries.", + required: false, + }, + vat_rate_id: { + description: + "Unique identifier of the vat rate object. This field is required for all entities in supported countries except the US and Pakistan.", + required: true, + }, + }, + }; + server + .mockEndpoint() + .get("/receivables/required_fields") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getReceivablesRequiredFields(); + expect(response).toEqual({ + counterpart: { + tax_id: { + description: + "The counterpart's taxpayer identification number or tax ID. For identification purposes, this field may be required for counterparts that are not VAT-registered.", + required: false, + }, + vat_id: { + description: + "The counterpart's VAT (Value Added Tax) identification number. This field is required for counterparts that are VAT-registered.", + required: true, + }, + }, + entity: { + tax_id: { + description: + "The entity's taxpayer identification number or tax ID. This field is required for entities that are non-VAT registered.", + required: false, + }, + vat_id: { + description: + "The entity's VAT (Value Added Tax) identification number. This field is required for entities that are VAT-registered.", + required: true, + }, + }, + line_item: { + measure_unit: { + description: "Unit used to measure the quantity of the product (e.g. items, meters, kilograms)", + required: true, + }, + tax_rate_value: { + description: + "Percent minor units. Example: 12.5% is 1250. This field is only required on invoices issued by entities in the US, Pakistan, and other unsupported countries.", + required: false, + }, + vat_rate_id: { + description: + "Unique identifier of the vat rate object. This field is required for all entities in supported countries except the US and Pakistan.", + required: true, + }, + }, + }); + }); + + test("post_receivables_search", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { status: "draft", type: "invoice" }; + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { city: "Berlin", country: "AF", line1: "Flughafenstrasse 52", postal_code: "10115" }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { id: "id", counterpart_id: "counterpart_id", value: "123456789" }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount" }, + discounted_subtotal: 1, + document_id: "document_id", + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { name: "name", type: "organization" }, + entity_address: { city: "city", line1: "line1", postal_code: "postal_code" }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [{ amount: 1, taxable_amount: 1, value: 1 }], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .post("/receivables/search") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.postReceivablesSearch({ + status: "draft", + type: "invoice", + }); + expect(response).toEqual({ + data: [ + { + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + postal_code: "10115", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + }, + discounted_subtotal: 1, + document_id: "document_id", + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + name: "name", + }, + entity_address: { + city: "city", + line1: "line1", + postal_code: "postal_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + amount: 1, + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_variables", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + object_subtype: "quote", + object_type: "object_type", + variables: [{ description: "description", name: "name" }], + }, + ], + }; + server + .mockEndpoint() + .get("/receivables/variables") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getVariables(); + expect(response).toEqual({ + data: [ + { + object_subtype: "quote", + object_type: "object_type", + variables: [ + { + description: "description", + name: "name", + }, + ], + }, + ], + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .get("/receivables/receivable_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getById("receivable_id"); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/receivables/receivable_id").respondWith().statusCode(200).build(); + + const response = await client.receivables.deleteById("receivable_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { quote: {} }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .patch("/receivables/receivable_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.updateById("receivable_id", { + quote: {}, + }); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("accept_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + signature: { + email: "theo@example.com", + full_name: "Theo Quinn", + signature_image: "iVBORw0KGgoAAAANSUhEUg.....AAABJRU5ErkJggg==", + }, + }; + const rawResponseBody = { success: true }; + server + .mockEndpoint() + .post("/receivables/receivable_id/accept") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.acceptById("receivable_id", { + signature: { + email: "theo@example.com", + full_name: "Theo Quinn", + signature_image: "iVBORw0KGgoAAAANSUhEUg.....AAABJRU5ErkJggg==", + }, + }); + expect(response).toEqual({ + success: true, + }); + }); + + test("cancel_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().post("/receivables/receivable_id/cancel").respondWith().statusCode(200).build(); + + const response = await client.receivables.cancelById("receivable_id"); + expect(response).toEqual(undefined); + }); + + test("clone_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/clone") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.cloneById("receivable_id"); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("decline_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { success: true }; + server + .mockEndpoint() + .post("/receivables/receivable_id/decline") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.declineById("receivable_id"); + expect(response).toEqual({ + success: true, + }); + }); + + test("get_history", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + current_pdf_url: "https://monite-file-saver.example.com/12345/67890.pdf", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { new_status: "draft", old_status: "draft" }, + event_type: "status_changed", + receivable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/receivables/receivable_id/history") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getHistory("receivable_id"); + expect(response).toEqual({ + data: [ + { + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + current_pdf_url: "https://monite-file-saver.example.com/12345/67890.pdf", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { + new_status: "draft", + old_status: "draft", + }, + event_type: "status_changed", + receivable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_history_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + current_pdf_url: "https://monite-file-saver.example.com/12345/67890.pdf", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { new_status: "draft", old_status: "draft" }, + event_type: "status_changed", + receivable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }; + server + .mockEndpoint() + .get("/receivables/receivable_id/history/receivable_history_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getHistoryById("receivable_history_id", "receivable_id"); + expect(response).toEqual({ + id: "cd58435b-1c79-4b17-9f79-f898c93e5f97", + current_pdf_url: "https://monite-file-saver.example.com/12345/67890.pdf", + entity_user_id: "d5a577b0-01c0-4566-ac5c-44f41935e8c4", + event_data: { + new_status: "draft", + old_status: "draft", + }, + event_type: "status_changed", + receivable_id: "f669a8a4-0563-4ab9-b54f-e9d700d282c5", + timestamp: "2024-01-15T09:30:00Z", + }); + }); + + test("issue_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/issue") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.issueById("receivable_id"); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("update_line_items_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { data: [{ quantity: 1.1 }] }; + const rawResponseBody = { + data: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + }; + server + .mockEndpoint() + .put("/receivables/receivable_id/line_items") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.updateLineItemsById("receivable_id", { + data: [ + { + quantity: 1.1, + }, + ], + }); + expect(response).toEqual({ + data: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + }); + }); + + test("get_mails", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { id: "id", created_at: "2024-01-15T09:30:00Z", updated_at: "2024-01-15T09:30:00Z", status: "pending" }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/receivables/receivable_id/mails") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getMails("receivable_id"); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + status: "pending", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("get_mail_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + recipients: { + bcc: [{ email: "email", is_success: true }], + cc: [{ email: "email", is_success: true }], + to: [{ email: "email", is_success: true }], + }, + status: "pending", + }; + server + .mockEndpoint() + .get("/receivables/receivable_id/mails/mail_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getMailById("receivable_id", "mail_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + recipients: { + bcc: [ + { + email: "email", + is_success: true, + }, + ], + cc: [ + { + email: "email", + is_success: true, + }, + ], + to: [ + { + email: "email", + is_success: true, + }, + ], + }, + status: "pending", + }); + }); + + test("mark_as_paid_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/mark_as_paid") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.markAsPaidById("receivable_id"); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("mark_as_partially_paid_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { amount_paid: 1 }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/mark_as_partially_paid") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.markAsPartiallyPaidById("receivable_id", { + amount_paid: 1, + }); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("mark_as_uncollectible_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { amount: 1, type: "amount", value: 1 }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { display_entity_bank_account: true }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { display_entity_bank_account: true }, + quote: { display_entity_bank_account: true, display_signature: true }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + type: "organization", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { id: "id", country: "AF", entity_id: "entity_id", type: "ae_trn", value: "123456789" }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { amount: 1, type: "amount" }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { currency: "AED", value: 1 }, + price_after_vat: { currency: "AED", value: 1 }, + vat_rate: { country: "AF", value: 1 }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { key: "value" }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [{ amount: 1, name: "name", value: 1.1 }], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + type: "quote", + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/mark_as_uncollectible") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.markAsUncollectibleById("receivable_id"); + expect(response).toEqual({ + type: "quote", + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + attachments: [ + { + id: "id", + include_in_email: true, + mimetype: "application/pdf", + name: "timesheet.pdf", + size: 120101, + url: "https://bucketname.s3.amazonaws.com/path/to/timesheet.pdf", + }, + ], + based_on: "based_on", + based_on_document_id: "based_on_document_id", + comment: "comment", + commercial_condition_description: "commercial_condition_description", + counterpart_billing_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_business_type: "counterpart_business_type", + counterpart_contact: { + address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + email: "marge@example.org", + first_name: "Marge", + last_name: "Smith", + phone: "55512378654", + title: "Dr.", + }, + counterpart_external_reference: "counterpart_external_reference", + counterpart_id: "counterpart_id", + counterpart_name: "counterpart_name", + counterpart_shipping_address: { + id: "id", + city: "Berlin", + country: "AF", + line1: "Flughafenstrasse 52", + line2: "line2", + postal_code: "10115", + state: "state", + }, + counterpart_tax_id: "counterpart_tax_id", + counterpart_type: "individual", + counterpart_vat_id: { + id: "id", + counterpart_id: "counterpart_id", + country: "AF", + type: "ae_trn", + value: "123456789", + }, + currency: "AED", + deduction_amount: 1, + deduction_memo: "deduction_memo", + discount: { + amount: 1, + type: "amount", + value: 1, + }, + discounted_subtotal: 1, + document_id: "document_id", + document_rendering: { + credit_note: { + display_entity_bank_account: true, + }, + display_entity_bank_account: true, + display_line_items: true, + invoice: { + display_entity_bank_account: true, + }, + quote: { + display_entity_bank_account: true, + display_signature: true, + }, + }, + due_date: "due_date", + einvoice_file_url: "einvoice_file_url", + entity: { + type: "organization", + email: "email", + logo: "logo", + name: "name", + phone: "phone", + registration_authority: "registration_authority", + registration_number: "registration_number", + tax_id: "tax_id", + vat_id: "vat_id", + website: "website", + }, + entity_address: { + city: "city", + country: "AF", + line1: "line1", + line2: "line2", + postal_code: "postal_code", + state: "state", + }, + entity_bank_account: { + id: "id", + account_holder_name: "account_holder_name", + account_number: "account_number", + bank_name: "bank_name", + bic: "bic", + iban: "iban", + routing_number: "routing_number", + sort_code: "sort_code", + }, + entity_user_id: "entity_user_id", + entity_vat_id: { + id: "id", + country: "AF", + entity_id: "entity_id", + type: "ae_trn", + value: "123456789", + }, + expiry_date: "expiry_date", + file_language: "ab", + file_url: "file_url", + footer: "footer", + issue_date: "2024-01-15T09:30:00Z", + line_items: [ + { + discount: { + amount: 1, + type: "amount", + }, + product: { + id: "id", + external_reference: "HT-1234-S-BL", + name: "name", + price: { + currency: "AED", + value: 1, + }, + price_after_vat: { + currency: "AED", + value: 1, + }, + vat_rate: { + country: "AF", + value: 1, + }, + }, + quantity: 1.1, + total_after_vat: 1, + total_before_vat: 1, + }, + ], + memo: "memo", + original_file_language: "ab", + original_file_url: "original_file_url", + partner_metadata: { + key: "value", + }, + project_id: "project_id", + quote_accept_page_url: "quote_accept_page_url", + signature_required: true, + status: "draft", + subtotal: 1, + subtotal_after_vat: 1, + tags: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + total_amount: 1, + total_vat_amount: 1, + total_vat_amounts: [ + { + id: "id", + amount: 1, + components: [ + { + amount: 1, + name: "name", + value: 1.1, + }, + ], + name: "name", + taxable_amount: 1, + value: 1, + }, + ], + total_withholding_tax: 1, + trade_name: "trade_name", + vat_exempt: true, + vat_exemption_rationale: "vat_exemption_rationale", + vat_inclusive_discount_mode: "exclusive", + vat_mode: "exclusive", + withholding_tax_rate: 1, + }); + }); + + test("get_pdf_link_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { file_url: "file_url", original_file_url: "original_file_url" }; + server + .mockEndpoint() + .get("/receivables/receivable_id/pdf_link") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.getPdfLinkById("receivable_id"); + expect(response).toEqual({ + file_url: "file_url", + original_file_url: "original_file_url", + }); + }); + + test("preview_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { body_text: "body_text", subject_text: "subject_text" }; + const rawResponseBody = { body_preview: "body_preview", subject_preview: "subject_preview" }; + server + .mockEndpoint() + .post("/receivables/receivable_id/preview") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.previewById("receivable_id", { + body_text: "body_text", + subject_text: "subject_text", + }); + expect(response).toEqual({ + body_preview: "body_preview", + subject_preview: "subject_preview", + }); + }); + + test("send_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { body_text: "body_text", subject_text: "subject_text" }; + const rawResponseBody = { mail_id: "mail_id" }; + server + .mockEndpoint() + .post("/receivables/receivable_id/send") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.sendById("receivable_id", { + body_text: "body_text", + subject_text: "subject_text", + }); + expect(response).toEqual({ + mail_id: "mail_id", + }); + }); + + test("send_test_reminder_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { reminder_type: "term_1" }; + const rawResponseBody = { mail_ids: ["mail_ids"] }; + server + .mockEndpoint() + .post("/receivables/receivable_id/send_test_reminder") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.sendTestReminderById("receivable_id", { + reminder_type: "term_1", + }); + expect(response).toEqual({ + mail_ids: ["mail_ids"], + }); + }); + + test("verify_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + errors: { + counterpart: ["counterpart"], + entity: ["entity"], + products: [{ line_item_number: 1, missing_fields: ["missing_fields"] }], + receivable: ["receivable"], + vat_rates: ["vat_rates"], + }, + warnings: { payment_reminders: "payment_reminders" }, + }; + server + .mockEndpoint() + .post("/receivables/receivable_id/verify") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.receivables.verifyById("receivable_id"); + expect(response).toEqual({ + errors: { + counterpart: ["counterpart"], + entity: ["entity"], + products: [ + { + line_item_number: 1, + missing_fields: ["missing_fields"], + }, + ], + receivable: ["receivable"], + vat_rates: ["vat_rates"], + }, + warnings: { + payment_reminders: "payment_reminders", + }, + }); + }); +}); diff --git a/tests/wire/recurrences.test.ts b/tests/wire/recurrences.test.ts new file mode 100644 index 0000000..294af16 --- /dev/null +++ b/tests/wire/recurrences.test.ts @@ -0,0 +1,367 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Recurrences", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [{ issue_at: "issue_at", status: "pending" }], + max_occurrences: 1, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }, + ], + }; + server.mockEndpoint().get("/recurrences").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.recurrences.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { + issue_at: "issue_at", + status: "pending", + }, + ], + max_occurrences: 1, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }, + ], + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { invoice_id: "invoice_id" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { issue_at: "issue_at", issued_invoice_id: "issued_invoice_id", iteration: 1, status: "pending" }, + ], + max_occurrences: 1, + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }; + server + .mockEndpoint() + .post("/recurrences") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.recurrences.create({ + invoice_id: "invoice_id", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { + issue_at: "issue_at", + issued_invoice_id: "issued_invoice_id", + iteration: 1, + status: "pending", + }, + ], + max_occurrences: 1, + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { issue_at: "issue_at", issued_invoice_id: "issued_invoice_id", iteration: 1, status: "pending" }, + ], + max_occurrences: 1, + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }; + server + .mockEndpoint() + .get("/recurrences/recurrence_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.recurrences.getById("recurrence_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { + issue_at: "issue_at", + issued_invoice_id: "issued_invoice_id", + iteration: 1, + status: "pending", + }, + ], + max_occurrences: 1, + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { issue_at: "issue_at", issued_invoice_id: "issued_invoice_id", iteration: 1, status: "pending" }, + ], + max_occurrences: 1, + recipients: { bcc: ["bcc"], cc: ["cc"], to: ["to"] }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }; + server + .mockEndpoint() + .patch("/recurrences/recurrence_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.recurrences.updateById("recurrence_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + automation_level: "draft", + body_text: "body_text", + current_iteration: 1, + day_of_month: "first_day", + end_date: "end_date", + frequency: "day", + interval: 1, + invoice_id: "invoice_id", + iterations: [ + { + issue_at: "issue_at", + issued_invoice_id: "issued_invoice_id", + iteration: 1, + status: "pending", + }, + ], + max_occurrences: 1, + recipients: { + bcc: ["bcc"], + cc: ["cc"], + to: ["to"], + }, + start_date: "start_date", + start_month: 1, + start_year: 1, + status: "active", + subject_text: "subject_text", + }); + }); + + test("cancel_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().post("/recurrences/recurrence_id/cancel").respondWith().statusCode(200).build(); + + const response = await client.recurrences.cancelById("recurrence_id"); + expect(response).toEqual(undefined); + }); + + test("post_recurrences_id_pause", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { key: "value" }; + server + .mockEndpoint() + .post("/recurrences/recurrence_id/pause") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.recurrences.postRecurrencesIdPause("recurrence_id"); + expect(response).toEqual({ + key: "value", + }); + }); + + test("post_recurrences_id_resume", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { key: "value" }; + server + .mockEndpoint() + .post("/recurrences/recurrence_id/resume") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.recurrences.postRecurrencesIdResume("recurrence_id"); + expect(response).toEqual({ + key: "value", + }); + }); +}); diff --git a/tests/wire/roles.test.ts b/tests/wire/roles.test.ts new file mode 100644 index 0000000..04aabfa --- /dev/null +++ b/tests/wire/roles.test.ts @@ -0,0 +1,190 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Roles", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: {}, + status: "active", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/roles").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.roles.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: {}, + status: "active", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "name", permissions: {} }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { objects: [{ object_type: "approval_policy" }] }, + status: "active", + }; + server + .mockEndpoint() + .post("/roles") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.roles.create({ + name: "name", + permissions: {}, + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { + objects: [ + { + object_type: "approval_policy", + }, + ], + }, + status: "active", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { objects: [{ object_type: "approval_policy" }] }, + status: "active", + }; + server.mockEndpoint().get("/roles/role_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.roles.getById("role_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { + objects: [ + { + object_type: "approval_policy", + }, + ], + }, + status: "active", + }); + }); + + test("delete_roles_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/roles/role_id").respondWith().statusCode(200).build(); + + const response = await client.roles.deleteRolesId("role_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { objects: [{ object_type: "approval_policy" }] }, + status: "active", + }; + server + .mockEndpoint() + .patch("/roles/role_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.roles.updateById("role_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + name: "name", + permissions: { + objects: [ + { + object_type: "approval_policy", + }, + ], + }, + status: "active", + }); + }); +}); diff --git a/tests/wire/tags.test.ts b/tests/wire/tags.test.ts new file mode 100644 index 0000000..be23e40 --- /dev/null +++ b/tests/wire/tags.test.ts @@ -0,0 +1,183 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("Tags", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + next_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + prev_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + }; + server.mockEndpoint().get("/tags").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.tags.get(); + expect(response).toEqual({ + data: [ + { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }, + ], + next_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + prev_pagination_token: + "eyJvcmRlciI6ImFzYyIsImxpbWl0IjoyLCJwYWdpbmF0aW9uX2ZpbHRlcnMiOnsiZW50aXR5X2lkIjoiOWQyYjRjOGYtMjA4Ny00NzM4LWJhOTEtNzM1OTY4M2M0OWE0In0sInBhZ2luYXRpb25fdG9rZW5fdHlwZSI6Im5leHQiLCJjdXJzb3JfZmllbGQiOm51bGwsImN1cnNvcl9maWVsZF92YWx1ZSI6bnVsbCwiY3VycmVudF9vaWQiOjR9", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { name: "Marketing" }; + const rawResponseBody = { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }; + server + .mockEndpoint() + .post("/tags") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.tags.create({ + name: "Marketing", + }); + expect(response).toEqual({ + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }; + server.mockEndpoint().get("/tags/tag_id").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.tags.getById("tag_id"); + expect(response).toEqual({ + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/tags/tag_id").respondWith().statusCode(200).build(); + + const response = await client.tags.deleteById("tag_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }; + server + .mockEndpoint() + .patch("/tags/tag_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.tags.updateById("tag_id"); + expect(response).toEqual({ + id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + created_at: "2022-09-07T16:35:18Z", + updated_at: "2022-09-07T16:35:18Z", + category: "document_type", + created_by_entity_user_id: "ea837e28-509b-4b6a-a600-d54b6aa0b1f5", + description: "Tag for the Marketing Department", + name: "Marketing", + }); + }); +}); diff --git a/tests/wire/textTemplates.test.ts b/tests/wire/textTemplates.test.ts new file mode 100644 index 0000000..dfbae86 --- /dev/null +++ b/tests/wire/textTemplates.test.ts @@ -0,0 +1,236 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("TextTemplates", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server.mockEndpoint().get("/text_templates").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.textTemplates.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { document_type: "quote", name: "name", template: "template", type: "email_header" }; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }; + server + .mockEndpoint() + .post("/text_templates") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.textTemplates.create({ + document_type: "quote", + name: "name", + template: "template", + type: "email_header", + }); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }; + server + .mockEndpoint() + .get("/text_templates/text_template_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.textTemplates.getById("text_template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server.mockEndpoint().delete("/text_templates/text_template_id").respondWith().statusCode(200).build(); + + const response = await client.textTemplates.deleteById("text_template_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }; + server + .mockEndpoint() + .patch("/text_templates/text_template_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.textTemplates.updateById("text_template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }); + }); + + test("make_default_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }; + server + .mockEndpoint() + .post("/text_templates/text_template_id/make_default") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.textTemplates.makeDefaultById("text_template_id"); + expect(response).toEqual({ + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + document_type: "quote", + is_default: true, + name: "name", + template: "template", + type: "email_header", + }); + }); +}); diff --git a/tests/wire/vatRates.test.ts b/tests/wire/vatRates.test.ts new file mode 100644 index 0000000..b520f19 --- /dev/null +++ b/tests/wire/vatRates.test.ts @@ -0,0 +1,57 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("VatRates", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [{ name: "name", value: 1.1 }], + country: "AF", + status: "active", + valid_from: "valid_from", + valid_until: "valid_until", + value: 1, + }, + ], + }; + server.mockEndpoint().get("/vat_rates").respondWith().statusCode(200).jsonBody(rawResponseBody).build(); + + const response = await client.vatRates.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + created_at: "2024-01-15T09:30:00Z", + updated_at: "2024-01-15T09:30:00Z", + components: [ + { + name: "name", + value: 1.1, + }, + ], + country: "AF", + status: "active", + valid_from: "valid_from", + valid_until: "valid_until", + value: 1, + }, + ], + }); + }); +}); diff --git a/tests/wire/webhookDeliveries.test.ts b/tests/wire/webhookDeliveries.test.ts new file mode 100644 index 0000000..c022060 --- /dev/null +++ b/tests/wire/webhookDeliveries.test.ts @@ -0,0 +1,58 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("WebhookDeliveries", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + event_id: "event_id", + requests_made_count: 1, + response: "response", + response_status_code: 1, + url: "url", + was_successful: true, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/webhook_deliveries") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookDeliveries.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + event_id: "event_id", + requests_made_count: 1, + response: "response", + response_status_code: 1, + url: "url", + was_successful: true, + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); +}); diff --git a/tests/wire/webhookSubscriptions.test.ts b/tests/wire/webhookSubscriptions.test.ts new file mode 100644 index 0000000..1f2d183 --- /dev/null +++ b/tests/wire/webhookSubscriptions.test.ts @@ -0,0 +1,300 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import { mockServerPool } from "../mock-server/MockServerPool"; +import { MoniteClient } from "../../src/Client"; + +describe("WebhookSubscriptions", () => { + test("get", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + data: [ + { + id: "id", + event_types: [ + "created", + "onboarding_requirements.updated", + "onboarding_requirements.status_updated", + ], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }; + server + .mockEndpoint() + .get("/webhook_subscriptions") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.get(); + expect(response).toEqual({ + data: [ + { + id: "id", + event_types: [ + "created", + "onboarding_requirements.updated", + "onboarding_requirements.status_updated", + ], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }, + ], + next_pagination_token: "next_pagination_token", + prev_pagination_token: "prev_pagination_token", + }); + }); + + test("create", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = { + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "entity", + url: "https://example.com/your-webhook-listener", + }; + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + secret: "whsec_Iw3mr...", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .post("/webhook_subscriptions") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.create({ + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "entity", + url: "https://example.com/your-webhook-listener", + }); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + secret: "whsec_Iw3mr...", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); + + test("get_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .get("/webhook_subscriptions/webhook_subscription_id") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.getById("webhook_subscription_id"); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); + + test("delete_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + server + .mockEndpoint() + .delete("/webhook_subscriptions/webhook_subscription_id") + .respondWith() + .statusCode(200) + .build(); + + const response = await client.webhookSubscriptions.deleteById("webhook_subscription_id"); + expect(response).toEqual(undefined); + }); + + test("update_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + const rawRequestBody = {}; + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .patch("/webhook_subscriptions/webhook_subscription_id") + .jsonBody(rawRequestBody) + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.updateById("webhook_subscription_id"); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); + + test("disable_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .post("/webhook_subscriptions/webhook_subscription_id/disable") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.disableById("webhook_subscription_id"); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); + + test("enable_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .post("/webhook_subscriptions/webhook_subscription_id/enable") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.enableById("webhook_subscription_id"); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); + + test("regenerate_secret_by_id", async () => { + const server = mockServerPool.createServer(); + const client = new MoniteClient({ + token: "test", + moniteVersion: "test", + moniteEntityId: "test", + environment: server.baseUrl, + }); + + const rawResponseBody = { + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + secret: "whsec_Iw3mr...", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }; + server + .mockEndpoint() + .post("/webhook_subscriptions/webhook_subscription_id/regenerate_secret") + .respondWith() + .statusCode(200) + .jsonBody(rawResponseBody) + .build(); + + const response = await client.webhookSubscriptions.regenerateSecretById("webhook_subscription_id"); + expect(response).toEqual({ + id: "id", + event_types: ["created", "onboarding_requirements.updated", "onboarding_requirements.status_updated"], + object_type: "account", + secret: "whsec_Iw3mr...", + status: "enabled", + url: "https://example.com/your-webhook-listener", + }); + }); +}); diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..c75083d --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "extendedDiagnostics": true, + "strict": true, + "target": "ES6", + "moduleResolution": "node", + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true, + "outDir": "dist", + "rootDir": "src", + "baseUrl": "src" + }, + "include": ["src"], + "exclude": [] +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..5c11446 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "dist/cjs" + }, + "include": ["src"], + "exclude": [] +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..95a5eb7 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "esnext", + "outDir": "dist/esm" + }, + "include": ["src"], + "exclude": [] +} diff --git a/tsconfig.json b/tsconfig.json index 1ec87dd..d77fdf0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,3 @@ { - "compilerOptions": { - "extendedDiagnostics": true, - "strict": true, - "target": "ES6", - "moduleResolution": "node", - "esModuleInterop": true, - "skipLibCheck": true, - "declaration": true, - "outDir": "dist", - "rootDir": "src", - "baseUrl": "src", - "module": "CommonJS" - }, - "include": ["src"], - "exclude": [] + "extends": "./tsconfig.cjs.json" } diff --git a/yarn.lock b/yarn.lock index df80c55..a077bc8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20,43 +20,43 @@ picocolors "^1.1.1" "@babel/compat-data@^7.27.2": - version "7.27.2" - resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.27.2.tgz#4183f9e642fd84e74e3eea7ffa93a412e3b102c9" - integrity sha512-TUtMJYRPyUb/9aU8f3K0mjmjf6M9N5Woshn2CS6nqJSeJtTtQcpLUXjGt9vbF8ZGff0El99sWkLgzwW3VXnxZQ== + version "7.28.0" + resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.28.0.tgz#9fc6fd58c2a6a15243cd13983224968392070790" + integrity sha512-60X7qkglvrap8mn1lh2ebxXdZYtUcpd7gsmy9kLaBJ4i/WdY8PqTSdxyA8qraikqKQK5C1KRBKXqznrVapyNaw== "@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.23.9": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.27.1.tgz#89de51e86bd12246003e3524704c49541b16c3e6" - integrity sha512-IaaGWsQqfsQWVLqMn9OB92MNN7zukfVA4s7KKAI0KfrrDsZ0yhi5uV4baBuLuN7n3vsZpwP8asPPcVwApxvjBQ== + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.28.3.tgz#aceddde69c5d1def69b839d09efa3e3ff59c97cb" + integrity sha512-yDBHV9kQNcr2/sUr9jghVyz9C3Y5G2zUM2H2lo+9mKv4sFgbA8s8Z9t8D1jiTkGoO/NoIfKMyKWr4s6CN23ZwQ== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.27.1" - "@babel/generator" "^7.27.1" - "@babel/helper-compilation-targets" "^7.27.1" - "@babel/helper-module-transforms" "^7.27.1" - "@babel/helpers" "^7.27.1" - "@babel/parser" "^7.27.1" - "@babel/template" "^7.27.1" - "@babel/traverse" "^7.27.1" - "@babel/types" "^7.27.1" + "@babel/generator" "^7.28.3" + "@babel/helper-compilation-targets" "^7.27.2" + "@babel/helper-module-transforms" "^7.28.3" + "@babel/helpers" "^7.28.3" + "@babel/parser" "^7.28.3" + "@babel/template" "^7.27.2" + "@babel/traverse" "^7.28.3" + "@babel/types" "^7.28.2" convert-source-map "^2.0.0" debug "^4.1.0" gensync "^1.0.0-beta.2" json5 "^2.2.3" semver "^6.3.1" -"@babel/generator@^7.27.1", "@babel/generator@^7.7.2": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.27.1.tgz#862d4fad858f7208edd487c28b58144036b76230" - integrity sha512-UnJfnIpc/+JO0/+KRVQNGU+y5taA5vCbwN8+azkX6beii/ZF+enZJSOKo11ZSzGJjlNfJHfQtmQT8H+9TXPG2w== +"@babel/generator@^7.28.3", "@babel/generator@^7.7.2": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.28.3.tgz#9626c1741c650cbac39121694a0f2d7451b8ef3e" + integrity sha512-3lSpxGgvnmZznmBkCRnVREPUFJv2wrv9iAoFDvADJc0ypmdOxdUtcLeBgBJ6zE0PMeTKnxeQzyk0xTBq4Ep7zw== dependencies: - "@babel/parser" "^7.27.1" - "@babel/types" "^7.27.1" - "@jridgewell/gen-mapping" "^0.3.5" - "@jridgewell/trace-mapping" "^0.3.25" + "@babel/parser" "^7.28.3" + "@babel/types" "^7.28.2" + "@jridgewell/gen-mapping" "^0.3.12" + "@jridgewell/trace-mapping" "^0.3.28" jsesc "^3.0.2" -"@babel/helper-compilation-targets@^7.27.1": +"@babel/helper-compilation-targets@^7.27.2": version "7.27.2" resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.2.tgz#46a0f6efab808d51d29ce96858dd10ce8732733d" integrity sha512-2+1thGUUWWjLTYTHZWK1n8Yga0ijBz1XAhUXcKy81rd5g6yh7hGqMp45v7cadSbEHc9G3OTv45SyneRN3ps4DQ== @@ -67,6 +67,11 @@ lru-cache "^5.1.1" semver "^6.3.1" +"@babel/helper-globals@^7.28.0": + version "7.28.0" + resolved "https://registry.yarnpkg.com/@babel/helper-globals/-/helper-globals-7.28.0.tgz#b9430df2aa4e17bc28665eadeae8aa1d985e6674" + integrity sha512-+W6cISkXFa1jXsDEdYA8HeevQT/FULhxzR99pxphltZcVaugps53THCeiWA8SguxxpSp3gKPiuYfSWopkLQ4hw== + "@babel/helper-module-imports@^7.27.1": version "7.27.1" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.27.1.tgz#7ef769a323e2655e126673bb6d2d6913bbead204" @@ -75,14 +80,14 @@ "@babel/traverse" "^7.27.1" "@babel/types" "^7.27.1" -"@babel/helper-module-transforms@^7.27.1": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.27.1.tgz#e1663b8b71d2de948da5c4fb2a20ca4f3ec27a6f" - integrity sha512-9yHn519/8KvTU5BjTVEEeIM3w9/2yXNKoD82JifINImhpKkARMJKPP59kLo+BafpdN5zgNeIcS4jsGDmd3l58g== +"@babel/helper-module-transforms@^7.28.3": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.28.3.tgz#a2b37d3da3b2344fe085dab234426f2b9a2fa5f6" + integrity sha512-gytXUbs8k2sXS9PnQptz5o0QnpLL51SwASIORY6XaBKF88nsOT0Zw9szLqlSGQDP/4TljBAD5y98p2U1fqkdsw== dependencies: "@babel/helper-module-imports" "^7.27.1" "@babel/helper-validator-identifier" "^7.27.1" - "@babel/traverse" "^7.27.1" + "@babel/traverse" "^7.28.3" "@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.27.1", "@babel/helper-plugin-utils@^7.8.0": version "7.27.1" @@ -104,20 +109,20 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.27.1.tgz#fa52f5b1e7db1ab049445b421c4471303897702f" integrity sha512-YvjJow9FxbhFFKDSuFnVCe2WxXk1zWc22fFePVNEaWJEu8IrZVlda6N0uHwzZrUM1il7NC9Mlp4MaJYbYd9JSg== -"@babel/helpers@^7.27.1": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.27.1.tgz#ffc27013038607cdba3288e692c3611c06a18aa4" - integrity sha512-FCvFTm0sWV8Fxhpp2McP5/W53GPllQ9QeQ7SiqGWjMf/LVG07lFa5+pgK05IRhVwtvafT22KF+ZSnM9I545CvQ== +"@babel/helpers@^7.28.3": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.28.3.tgz#b83156c0a2232c133d1b535dd5d3452119c7e441" + integrity sha512-PTNtvUQihsAsDHMOP5pfobP8C6CM4JWXmP8DrEIt46c3r2bf87Ua1zoqevsMo9g+tWDwgWrFP5EIxuBx5RudAw== dependencies: - "@babel/template" "^7.27.1" - "@babel/types" "^7.27.1" + "@babel/template" "^7.27.2" + "@babel/types" "^7.28.2" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.27.1", "@babel/parser@^7.27.2": - version "7.27.2" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.27.2.tgz#577518bedb17a2ce4212afd052e01f7df0941127" - integrity sha512-QYLs8299NA7WM/bZAdp+CviYYkVoYXlDW2rzliy3chxd1PQjej7JORuMJDJXJUb9g0TT+B99EwaVLKmX+sPXWw== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.27.2", "@babel/parser@^7.28.3": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.28.3.tgz#d2d25b814621bca5fe9d172bc93792547e7a2a71" + integrity sha512-7+Ey1mAgYqFAx2h0RuoxcQT5+MlG3GTV0TQrgr7/ZliKsm/MNDxVVutlWaziMq7wJNAz8MTqz55XLpWvva6StA== dependencies: - "@babel/types" "^7.27.1" + "@babel/types" "^7.28.2" "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -238,7 +243,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.27.1" -"@babel/template@^7.27.1", "@babel/template@^7.3.3": +"@babel/template@^7.27.2", "@babel/template@^7.3.3": version "7.27.2" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.2.tgz#fa78ceed3c4e7b63ebf6cb39e5852fca45f6809d" integrity sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw== @@ -247,23 +252,23 @@ "@babel/parser" "^7.27.2" "@babel/types" "^7.27.1" -"@babel/traverse@^7.27.1": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.27.1.tgz#4db772902b133bbddd1c4f7a7ee47761c1b9f291" - integrity sha512-ZCYtZciz1IWJB4U61UPu4KEaqyfj+r5T1Q5mqPo+IBpcG9kHv30Z0aD8LXPgC1trYa6rK0orRyAhqUgk4MjmEg== +"@babel/traverse@^7.27.1", "@babel/traverse@^7.28.3": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.28.3.tgz#6911a10795d2cce43ec6a28cffc440cca2593434" + integrity sha512-7w4kZYHneL3A6NP2nxzHvT3HCZ7puDZZjFMqDpBPECub79sTtSO5CGXDkKrTQq8ksAwfD/XI2MRFX23njdDaIQ== dependencies: "@babel/code-frame" "^7.27.1" - "@babel/generator" "^7.27.1" - "@babel/parser" "^7.27.1" - "@babel/template" "^7.27.1" - "@babel/types" "^7.27.1" + "@babel/generator" "^7.28.3" + "@babel/helper-globals" "^7.28.0" + "@babel/parser" "^7.28.3" + "@babel/template" "^7.27.2" + "@babel/types" "^7.28.2" debug "^4.3.1" - globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.27.1", "@babel/types@^7.3.3": - version "7.27.1" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.27.1.tgz#9defc53c16fc899e46941fc6901a9eea1c9d8560" - integrity sha512-+EzkxvLNfiUeKMgy/3luqfsCWFRXLb7U6wNQTk60tovuckwB15B191tJWvpp4HjiQWdJkCxO3Wbvc6jlk3Xb2Q== +"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.27.1", "@babel/types@^7.28.2", "@babel/types@^7.3.3": + version "7.28.2" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.28.2.tgz#da9db0856a9a88e0a13b019881d7513588cf712b" + integrity sha512-ruv7Ae4J5dUYULmeXw1gmb7rYRz57OWCPM57pHojnLq/3Z1CK2lNSLTCVjxVk1F/TZHwOZZrOWi0ur95BbLxNQ== dependencies: "@babel/helper-string-parser" "^7.27.1" "@babel/helper-validator-identifier" "^7.27.1" @@ -273,6 +278,60 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@bundled-es-modules/cookie@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@bundled-es-modules/cookie/-/cookie-2.0.1.tgz#b41376af6a06b3e32a15241d927b840a9b4de507" + integrity sha512-8o+5fRPLNbjbdGRRmJj3h6Hh1AQJf2dk3qQ/5ZFb+PXkRNiSoMGGUKlsgLfrxneb72axVJyIYji64E2+nNfYyw== + dependencies: + cookie "^0.7.2" + +"@bundled-es-modules/statuses@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@bundled-es-modules/statuses/-/statuses-1.0.1.tgz#761d10f44e51a94902c4da48675b71a76cc98872" + integrity sha512-yn7BklA5acgcBr+7w064fGV+SGIFySjCKpqjcWgBAIfrAkY+4GQTJJHQMeT3V/sgz23VTEVV8TtOmkvJAhFVfg== + dependencies: + statuses "^2.0.1" + +"@bundled-es-modules/tough-cookie@^0.1.6": + version "0.1.6" + resolved "https://registry.yarnpkg.com/@bundled-es-modules/tough-cookie/-/tough-cookie-0.1.6.tgz#fa9cd3cedfeecd6783e8b0d378b4a99e52bde5d3" + integrity sha512-dvMHbL464C0zI+Yqxbz6kZ5TOEp7GLW+pry/RWndAR8MJQAXZ2rPmIs8tziTZjeIyhSNZgZbCePtfSbdWqStJw== + dependencies: + "@types/tough-cookie" "^4.0.5" + tough-cookie "^4.1.4" + +"@inquirer/confirm@^5.0.0": + version "5.1.14" + resolved "https://registry.yarnpkg.com/@inquirer/confirm/-/confirm-5.1.14.tgz#e6321edf51a3a5f54dc548b80ef6ba89891351ad" + integrity sha512-5yR4IBfe0kXe59r1YCTG8WXkUbl7Z35HK87Sw+WUyGD8wNUx7JvY7laahzeytyE1oLn74bQnL7hstctQxisQ8Q== + dependencies: + "@inquirer/core" "^10.1.15" + "@inquirer/type" "^3.0.8" + +"@inquirer/core@^10.1.15": + version "10.1.15" + resolved "https://registry.yarnpkg.com/@inquirer/core/-/core-10.1.15.tgz#8feb69fd536786181a2b6bfb84d8674faa9d2e59" + integrity sha512-8xrp836RZvKkpNbVvgWUlxjT4CraKk2q+I3Ksy+seI2zkcE+y6wNs1BVhgcv8VyImFecUhdQrYLdW32pAjwBdA== + dependencies: + "@inquirer/figures" "^1.0.13" + "@inquirer/type" "^3.0.8" + ansi-escapes "^4.3.2" + cli-width "^4.1.0" + mute-stream "^2.0.0" + signal-exit "^4.1.0" + wrap-ansi "^6.2.0" + yoctocolors-cjs "^2.1.2" + +"@inquirer/figures@^1.0.13": + version "1.0.13" + resolved "https://registry.yarnpkg.com/@inquirer/figures/-/figures-1.0.13.tgz#ad0afd62baab1c23175115a9b62f511b6a751e45" + integrity sha512-lGPVU3yO9ZNqA7vTYz26jny41lE7yoQansmqdMLBEfqaGsmdg7V3W9mK9Pvb5IL4EVZ9GnSDGMO/cJXud5dMaw== + +"@inquirer/type@^3.0.8": + version "3.0.8" + resolved "https://registry.yarnpkg.com/@inquirer/type/-/type-3.0.8.tgz#efc293ba0ed91e90e6267f1aacc1c70d20b8b4e8" + integrity sha512-lg9Whz8onIHRthWaN1Q9EGLa/0LFJjyM8mEUbL1eTi6yMGvBf8gvyDLtxSXztQsxMvhxxNpJYrwa1YHdq+w4Jw== + "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced" @@ -481,13 +540,12 @@ "@types/yargs" "^17.0.8" chalk "^4.0.0" -"@jridgewell/gen-mapping@^0.3.5": - version "0.3.8" - resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz#4f0e06362e01362f823d348f1872b08f666d8142" - integrity sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA== +"@jridgewell/gen-mapping@^0.3.12", "@jridgewell/gen-mapping@^0.3.5": + version "0.3.13" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz#6342a19f44347518c93e43b1ac69deb3c4656a1f" + integrity sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA== dependencies: - "@jridgewell/set-array" "^1.2.1" - "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/sourcemap-codec" "^1.5.0" "@jridgewell/trace-mapping" "^0.3.24" "@jridgewell/resolve-uri@^3.1.0": @@ -495,32 +553,57 @@ resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz#7a0ee601f60f99a20c7c7c5ff0c80388c1189bd6" integrity sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw== -"@jridgewell/set-array@^1.2.1": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.2.1.tgz#558fb6472ed16a4c850b889530e6b36438c49280" - integrity sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A== - "@jridgewell/source-map@^0.3.3": - version "0.3.6" - resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.6.tgz#9d71ca886e32502eb9362c9a74a46787c36df81a" - integrity sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ== + version "0.3.11" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.11.tgz#b21835cbd36db656b857c2ad02ebd413cc13a9ba" + integrity sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA== dependencies: "@jridgewell/gen-mapping" "^0.3.5" "@jridgewell/trace-mapping" "^0.3.25" -"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a" - integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== +"@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.5.0": + version "1.5.5" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz#6912b00d2c631c0d15ce1a7ab57cd657f2a8f8ba" + integrity sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og== -"@jridgewell/trace-mapping@^0.3.12", "@jridgewell/trace-mapping@^0.3.18", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25": - version "0.3.25" - resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz#15f190e98895f3fc23276ee14bc76b675c2e50f0" - integrity sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ== +"@jridgewell/trace-mapping@^0.3.12", "@jridgewell/trace-mapping@^0.3.18", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25", "@jridgewell/trace-mapping@^0.3.28": + version "0.3.30" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.30.tgz#4a76c4daeee5df09f5d3940e087442fb36ce2b99" + integrity sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q== dependencies: "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@mswjs/interceptors@^0.39.1": + version "0.39.6" + resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.39.6.tgz#44094a578f20da4749d1a0eaf3cdb7973604004b" + integrity sha512-bndDP83naYYkfayr/qhBHMhk0YGwS1iv6vaEGcr0SQbO0IZtbOPqjKjds/WcG+bJA+1T5vCx6kprKOzn5Bg+Vw== + dependencies: + "@open-draft/deferred-promise" "^2.2.0" + "@open-draft/logger" "^0.3.0" + "@open-draft/until" "^2.0.0" + is-node-process "^1.2.0" + outvariant "^1.4.3" + strict-event-emitter "^0.5.1" + +"@open-draft/deferred-promise@^2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz#4a822d10f6f0e316be4d67b4d4f8c9a124b073bd" + integrity sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA== + +"@open-draft/logger@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@open-draft/logger/-/logger-0.3.0.tgz#2b3ab1242b360aa0adb28b85f5d7da1c133a0954" + integrity sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ== + dependencies: + is-node-process "^1.2.0" + outvariant "^1.4.0" + +"@open-draft/until@^2.0.0", "@open-draft/until@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@open-draft/until/-/until-2.1.0.tgz#0acf32f470af2ceaf47f095cdecd40d68666efda" + integrity sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg== + "@sinclair/typebox@^0.27.8": version "0.27.8" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" @@ -572,11 +655,16 @@ "@babel/types" "^7.0.0" "@types/babel__traverse@*", "@types/babel__traverse@^7.0.6": - version "7.20.7" - resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.20.7.tgz#968cdc2366ec3da159f61166428ee40f370e56c2" - integrity sha512-dkO5fhS7+/oos4ciWxyEyjWe48zmG6wbCheo/G2ZnHx4fs3EU6YC6UM8rk56gAjNJ9P3MTH2jo5jb92/K6wbng== + version "7.28.0" + resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.28.0.tgz#07d713d6cce0d265c9849db0cbe62d3f61f36f74" + integrity sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q== dependencies: - "@babel/types" "^7.20.7" + "@babel/types" "^7.28.2" + +"@types/cookie@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" + integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== "@types/eslint-scope@^3.7.7": version "3.7.7" @@ -594,10 +682,10 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/estree@*", "@types/estree@^1.0.6": - version "1.0.7" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8" - integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ== +"@types/estree@*", "@types/estree@^1.0.8": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.8.tgz#958b91c991b1867ced318bedea0e215ee050726e" + integrity sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w== "@types/graceful-fs@^4.1.3": version "4.1.9" @@ -647,56 +735,35 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== -"@types/node-fetch@^2.6.12": - version "2.6.12" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.12.tgz#8ab5c3ef8330f13100a7479e2cd56d3386830a03" - integrity sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA== - dependencies: - "@types/node" "*" - form-data "^4.0.0" - "@types/node@*": - version "22.15.17" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.15.17.tgz#355ccec95f705b664e4332bb64a7f07db30b7055" - integrity sha512-wIX2aSZL5FE+MR0JlvF87BNVrtFWf6AE6rxSE9X7OwnVvoyCQjpzSRJ+M87se/4QCkCiebQAqrJ0y6fwIyi7nw== + version "24.3.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-24.3.0.tgz#89b09f45cb9a8ee69466f18ee5864e4c3eb84dec" + integrity sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow== dependencies: - undici-types "~6.21.0" + undici-types "~7.10.0" "@types/node@^18.19.70": - version "18.19.100" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.100.tgz#7f3aefbb6911099ab7e0902a1f373b1a4d2c1947" - integrity sha512-ojmMP8SZBKprc3qGrGk8Ujpo80AXkrP7G2tOT4VWr5jlr5DHjsJF+emXJz+Wm0glmy4Js62oKMdZZ6B9Y+tEcA== + version "18.19.123" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.123.tgz#08a3e4f5e0c73b8840c677b7635ce59d5dc1f76d" + integrity sha512-K7DIaHnh0mzVxreCR9qwgNxp3MH9dltPNIEddW9MYUlcKAzm+3grKNSTe2vCJHI1FaLpvpL5JGJrz1UZDKYvDg== dependencies: undici-types "~5.26.4" -"@types/qs@^6.9.17": - version "6.9.18" - resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.18.tgz#877292caa91f7c1b213032b34626505b746624c2" - integrity sha512-kK7dgTYDyGqS+e2Q4aK9X3D7q234CIZ1Bv0q/7Z5IwRDoADNU81xXJK/YVyLbLTZCoIwUoDoffFeF+p/eIklAA== - -"@types/readable-stream@^4.0.18": - version "4.0.18" - resolved "https://registry.yarnpkg.com/@types/readable-stream/-/readable-stream-4.0.18.tgz#5d8d15d26c776500ce573cae580787d149823bfc" - integrity sha512-21jK/1j+Wg+7jVw1xnSwy/2Q1VgVjWuFssbYGTREPUBeZ+rqVFl2udq0IkxzPC0ZhOzVceUbyIACFZKLqKEBlA== - dependencies: - "@types/node" "*" - safe-buffer "~5.1.1" - "@types/stack-utils@^2.0.0": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8" integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== -"@types/tough-cookie@*": +"@types/statuses@^2.0.4": + version "2.0.6" + resolved "https://registry.yarnpkg.com/@types/statuses/-/statuses-2.0.6.tgz#66748315cc9a96d63403baa8671b2c124f8633aa" + integrity sha512-xMAgYwceFhRA2zY+XbEA7mxYbA093wdiW8Vu6gZPGWy9cmOyU9XesH1tNcEWsKFd5Vzrqx5T3D38PWx1FIIXkA== + +"@types/tough-cookie@*", "@types/tough-cookie@^4.0.5": version "4.0.5" resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304" integrity sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA== -"@types/url-join@4.0.1": - version "4.0.1" - resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-4.0.1.tgz#4989c97f969464647a8586c7252d97b449cdc045" - integrity sha512-wDXw9LEEUHyV+7UWy7U315nrJGJ7p1BzaCxDpEoLr789Dk1WDVMMlf3iBfbG2F8NdWnYyFbtTxUn2ZNbm1Q4LQ== - "@types/yargs-parser@*": version "21.0.3" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15" @@ -845,13 +912,6 @@ abab@^2.0.6: resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.6.tgz#41b80f2c871d19686216b82309231cfd3cb3d291" integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA== -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - acorn-globals@^7.0.0: version "7.0.1" resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-7.0.1.tgz#0dbf05c44fa7c94332914c02066d5beff62c40c3" @@ -860,6 +920,11 @@ acorn-globals@^7.0.0: acorn "^8.1.0" acorn-walk "^8.0.2" +acorn-import-phases@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/acorn-import-phases/-/acorn-import-phases-1.0.4.tgz#16eb850ba99a056cb7cbfe872ffb8972e18c8bd7" + integrity sha512-wKmbr/DDiIXzEOiWrTTUcDm24kQ2vGfZQvM2fwg2vXqR5uW6aapr7ObPtj1th32b9u90/Pf4AItvdTh42fBmVQ== + acorn-walk@^8.0.2: version "8.3.4" resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.4.tgz#794dd169c3977edf4ba4ea47583587c5866236b7" @@ -867,10 +932,10 @@ acorn-walk@^8.0.2: dependencies: acorn "^8.11.0" -acorn@^8.1.0, acorn@^8.11.0, acorn@^8.14.0, acorn@^8.8.1, acorn@^8.8.2: - version "8.14.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.14.1.tgz#721d5dc10f7d5b5609a891773d47731796935dfb" - integrity sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg== +acorn@^8.1.0, acorn@^8.11.0, acorn@^8.14.0, acorn@^8.15.0, acorn@^8.8.1: + version "8.15.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.15.0.tgz#a360898bc415edaac46c8241f6383975b930b816" + integrity sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg== agent-base@6: version "6.0.2" @@ -903,7 +968,7 @@ ajv@^8.0.0, ajv@^8.9.0: json-schema-traverse "^1.0.0" require-from-string "^2.0.2" -ansi-escapes@^4.2.1: +ansi-escapes@^4.2.1, ansi-escapes@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" integrity sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ== @@ -942,11 +1007,6 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" -async@^3.2.3: - version "3.2.6" - resolved "https://registry.yarnpkg.com/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce" - integrity sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA== - asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -987,9 +1047,9 @@ babel-plugin-jest-hoist@^29.6.3: "@types/babel__traverse" "^7.0.6" babel-preset-current-node-syntax@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz#9a929eafece419612ef4ae4f60b1862ebad8ef30" - integrity sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw== + version "1.2.0" + resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.2.0.tgz#20730d6cdc7dda5d89401cab10ac6a32067acde6" + integrity sha512-E/VlAEzRrsLEb2+dv8yp3bo4scof3l9nR4lrld+Iy5NyVqgVYUJnDAmunkhPMisRI32Qc4iRiz425d8vM++2fg== dependencies: "@babel/plugin-syntax-async-generators" "^7.8.4" "@babel/plugin-syntax-bigint" "^7.8.3" @@ -1020,26 +1080,14 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== -base64-js@^1.3.1: - version "1.5.1" - resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" - integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== - brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + version "1.1.12" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.12.tgz#ab9b454466e5a8cc3a187beaad580412a9c5b843" + integrity sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg== dependencies: balanced-match "^1.0.0" concat-map "0.0.1" -brace-expansion@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" - integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== - dependencies: - balanced-match "^1.0.0" - braces@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" @@ -1048,12 +1096,12 @@ braces@^3.0.3: fill-range "^7.1.1" browserslist@^4.24.0: - version "4.24.5" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.24.5.tgz#aa0f5b8560fe81fde84c6dcb38f759bafba0e11b" - integrity sha512-FDToo4Wo82hIdgc1CQ+NQD0hEhmpPjrZ3hiUgwgOG6IuTdlpr8jdjyG24P6cNP1yJpTLzS5OcGgSw0xmDU1/Tw== + version "4.25.2" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.25.2.tgz#90c1507143742d743544ae6e92bca3348adff667" + integrity sha512-0si2SJK3ooGzIawRu61ZdPCO1IncZwS8IzuX73sPZsXW6EQ/w/DAfPyKI8l1ETTCr2MnvqWitmlCUxgdul45jA== dependencies: - caniuse-lite "^1.0.30001716" - electron-to-chromium "^1.5.149" + caniuse-lite "^1.0.30001733" + electron-to-chromium "^1.5.199" node-releases "^2.0.19" update-browserslist-db "^1.1.3" @@ -1076,14 +1124,6 @@ buffer-from@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -buffer@^6.0.3: - version "6.0.3" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" - integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.2.1" - call-bind-apply-helpers@^1.0.1, call-bind-apply-helpers@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz#4b5428c222be985d79c3d82657479dbe0b59b2d6" @@ -1092,14 +1132,6 @@ call-bind-apply-helpers@^1.0.1, call-bind-apply-helpers@^1.0.2: es-errors "^1.3.0" function-bind "^1.1.2" -call-bound@^1.0.2: - version "1.0.4" - resolved "https://registry.yarnpkg.com/call-bound/-/call-bound-1.0.4.tgz#238de935d2a2a692928c538c7ccfa91067fd062a" - integrity sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg== - dependencies: - call-bind-apply-helpers "^1.0.2" - get-intrinsic "^1.3.0" - callsites@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" @@ -1115,12 +1147,12 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== -caniuse-lite@^1.0.30001716: - version "1.0.30001717" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001717.tgz#5d9fec5ce09796a1893013825510678928aca129" - integrity sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw== +caniuse-lite@^1.0.30001733: + version "1.0.30001735" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001735.tgz#ba658fd3fd24a4106fd68d5ce472a2c251494dbe" + integrity sha512-EV/laoX7Wq2J9TQlyIXRxTJqIw4sxfXS4OYgudGxBYRuTv0q7AM6yMEpU/Vo1I94thg9U6EZ2NfZx9GJq83u7w== -chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0: +chalk@^4.0.0, chalk@^4.1.0: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -1148,6 +1180,11 @@ cjs-module-lexer@^1.0.0: resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.4.3.tgz#0f79731eb8cfe1ec72acd4066efac9d61991b00d" integrity sha512-9z8TZaGM1pfswYeXrUpzPrkx8UnWYdhJclsiYMm6x/w5+nN+8Tf/LnAgfLGQCm59qAOxU8WwHEq2vNwF6i4j+Q== +cli-width@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.1.0.tgz#42daac41d3c254ef38ad8ac037672130173691c5" + integrity sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ== + cliui@^8.0.1: version "8.0.1" resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa" @@ -1201,6 +1238,11 @@ convert-source-map@^2.0.0: resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a" integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg== +cookie@^0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7" + integrity sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w== + create-jest@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/create-jest/-/create-jest-29.7.0.tgz#a355c5b3cb1e1af02ba177fe7afd7feee49a5320" @@ -1250,16 +1292,16 @@ data-urls@^3.0.2: whatwg-url "^11.0.0" debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1: - version "4.4.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.0.tgz#2b3f2aea2ffeb776477460267377dc8710faba8a" - integrity sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA== + version "4.4.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.1.tgz#e5a8bc6cbc4c6cd3e64308b0693a3d4fa550189b" + integrity sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ== dependencies: ms "^2.1.3" decimal.js@^10.4.2: - version "10.5.0" - resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.5.0.tgz#0f371c7cf6c4898ce0afb09836db73cd82010f22" - integrity sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw== + version "10.6.0" + resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.6.0.tgz#e649a43e3ab953a72192ff5983865e509f37ed9a" + integrity sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg== dedent@^1.0.0: version "1.6.0" @@ -1302,17 +1344,10 @@ dunder-proto@^1.0.1: es-errors "^1.3.0" gopd "^1.2.0" -ejs@^3.1.10: - version "3.1.10" - resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b" - integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA== - dependencies: - jake "^10.8.5" - -electron-to-chromium@^1.5.149: - version "1.5.151" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.151.tgz#5edd6c17e1b2f14b4662c41b9379f96cc8c2bb7c" - integrity sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA== +electron-to-chromium@^1.5.199: + version "1.5.202" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.202.tgz#e243716943a2cab144604a81b9ebaa87b4e8c1d4" + integrity sha512-NxbYjRmiHcHXV1Ws3fWUW+SLb62isauajk45LUJ/HgIOkUA7jLZu/X2Iif+X9FBNK8QkF9Zb4Q2mcwXCcY30mg== emittery@^0.13.1: version "0.13.1" @@ -1324,18 +1359,18 @@ emoji-regex@^8.0.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== -enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.1: - version "5.18.1" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.18.1.tgz#728ab082f8b7b6836de51f1637aab5d3b9568faf" - integrity sha512-ZSW3ma5GkcQBIpwZTSRAI8N71Uuwgs93IezB7mf7R60tC8ZbJideoDNKjHn2O9KIlx6rkGTTEk1xUCK2E1Y2Yg== +enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.3: + version "5.18.3" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.18.3.tgz#9b5f4c5c076b8787c78fe540392ce76a88855b44" + integrity sha512-d4lC8xfavMeBjzGr2vECC3fsGXziXZQyJxD868h2M/mBI3PwAuODxAkLkq5HYuvrPYcUtiLzsTo8U3PgX3Ocww== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" entities@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/entities/-/entities-6.0.0.tgz#09c9e29cb79b0a6459a9b9db9efb418ac5bb8e51" - integrity sha512-aKstq2TDOndCn4diEyp9Uq/Flu2i1GlLkc6XIDQSDMuaFE3OPW5OphLCyQ5SpSJZTb4reN+kTcYru5yIfXoRPw== + version "6.0.1" + resolved "https://registry.yarnpkg.com/entities/-/entities-6.0.1.tgz#c28c34a43379ca7f61d074130b2f5f7020a30694" + integrity sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g== error-ex@^1.3.1: version "1.3.2" @@ -1432,12 +1467,7 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - -events@^3.2.0, events@^3.3.0: +events@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== @@ -1495,13 +1525,6 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -filelist@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5" - integrity sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q== - dependencies: - minimatch "^5.0.1" - fill-range@^7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" @@ -1517,26 +1540,17 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -form-data-encoder@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-4.0.2.tgz#dd286fd5f9049e8ded1d44ce427f5e29185c7c12" - integrity sha512-KQVhvhK8ZkWzxKxOr56CPulAhH3dobtuQ4+hNQ+HekH/Wp5gSOafqRAeTphQUJAIk0GBvHZgJ2ZGRWd5kphMuw== - form-data@^4.0.0: - version "4.0.2" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.2.tgz#35cabbdd30c3ce73deb2c42d3c8d3ed9ca51794c" - integrity sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w== + version "4.0.4" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4" + integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow== dependencies: asynckit "^0.4.0" combined-stream "^1.0.8" es-set-tostringtag "^2.1.0" + hasown "^2.0.2" mime-types "^2.1.12" -formdata-node@^6.0.3: - version "6.0.3" - resolved "https://registry.yarnpkg.com/formdata-node/-/formdata-node-6.0.3.tgz#48f8e2206ae2befded82af621ef015f08168dc6d" - integrity sha512-8e1++BCiTzUno9v5IZ2J6bv4RU+3UKDmqWUQD0MIMVCd9AdhWkO1gw57oo1mNEX1dMq2EGI+FbWz4B92pscSQg== - fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -1562,7 +1576,7 @@ get-caller-file@^2.0.5: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-intrinsic@^1.2.5, get-intrinsic@^1.2.6, get-intrinsic@^1.3.0: +get-intrinsic@^1.2.6: version "1.3.0" resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz#743f0e3b6964a93a5491ed1bffaae054d7f98d01" integrity sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ== @@ -1613,11 +1627,6 @@ glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" -globals@^11.1.0: - version "11.12.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" - integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== - gopd@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.2.0.tgz#89f56b8217bdbc8802bd299df6d7f1081d7e51a1" @@ -1628,6 +1637,23 @@ graceful-fs@^4.1.2, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.9: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== +graphql@^16.8.1: + version "16.11.0" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.11.0.tgz#96d17f66370678027fdf59b2d4c20b4efaa8a633" + integrity sha512-mS1lbMsxgQj6hge1XZ6p7GPhbrtFwUFYi3wRzXAC/FmYnyXMTvvI3td3rjmQ2u8ewXueaSvRPWaEcgVVOT9Jnw== + +handlebars@^4.7.8: + version "4.7.8" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9" + integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ== + dependencies: + minimist "^1.2.5" + neo-async "^2.6.2" + source-map "^0.6.1" + wordwrap "^1.0.0" + optionalDependencies: + uglify-js "^3.1.4" + has-flag@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" @@ -1652,6 +1678,11 @@ hasown@^2.0.2: dependencies: function-bind "^1.1.2" +headers-polyfill@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/headers-polyfill/-/headers-polyfill-4.0.3.tgz#922a0155de30ecc1f785bcf04be77844ca95ad07" + integrity sha512-IScLbePpkvO846sIwOtOTDjutRMWdXdJmXdMvk6gCBHxFO8d+QKOQedyZSxFTTFYRSmlgSTDtXqqq4pcenBXLQ== + html-encoding-sniffer@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz#2cb1a8cf0db52414776e5b2a7a04d5dd98158de9" @@ -1693,11 +1724,6 @@ iconv-lite@0.6.3: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" -ieee754@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" - integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== - import-local@^3.0.2: version "3.2.0" resolved "https://registry.yarnpkg.com/import-local/-/import-local-3.2.0.tgz#c3d5c745798c02a6f8b897726aba5100186ee260" @@ -1746,6 +1772,11 @@ is-generator-fn@^2.0.0: resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118" integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ== +is-node-process@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/is-node-process/-/is-node-process-1.2.0.tgz#ea02a1b90ddb3934a19aea414e88edef7e11d134" + integrity sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw== + is-number@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" @@ -1819,16 +1850,6 @@ istanbul-reports@^3.1.3: html-escaper "^2.0.0" istanbul-lib-report "^3.0.0" -jake@^10.8.5: - version "10.9.2" - resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f" - integrity sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA== - dependencies: - async "^3.2.3" - chalk "^4.0.2" - filelist "^1.0.4" - minimatch "^3.1.2" - jest-changed-files@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-29.7.0.tgz#1c06d07e77c78e1585d020424dedc10d6e17ac3a" @@ -2143,7 +2164,7 @@ jest-snapshot@^29.7.0: pretty-format "^29.7.0" semver "^7.5.3" -jest-util@^29.0.0, jest-util@^29.7.0: +jest-util@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc" integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA== @@ -2210,11 +2231,6 @@ jest@^29.7.0: import-local "^3.0.2" jest-cli "^29.7.0" -js-base64@3.7.7: - version "3.7.7" - resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79" - integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw== - js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -2373,25 +2389,52 @@ mimic-fn@^2.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== -minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: +minimatch@^3.0.4, minimatch@^3.1.1: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== dependencies: brace-expansion "^1.1.7" -minimatch@^5.0.1: - version "5.1.6" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" - integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== - dependencies: - brace-expansion "^2.0.1" +minimist@^1.2.5: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +msw@^2.8.4: + version "2.10.5" + resolved "https://registry.yarnpkg.com/msw/-/msw-2.10.5.tgz#3e43f12e97581c260bf38d8817732b9fec3bfdb0" + integrity sha512-0EsQCrCI1HbhpBWd89DvmxY6plmvrM96b0sCIztnvcNHQbXn5vqwm1KlXslo6u4wN9LFGLC1WFjjgljcQhe40A== + dependencies: + "@bundled-es-modules/cookie" "^2.0.1" + "@bundled-es-modules/statuses" "^1.0.1" + "@bundled-es-modules/tough-cookie" "^0.1.6" + "@inquirer/confirm" "^5.0.0" + "@mswjs/interceptors" "^0.39.1" + "@open-draft/deferred-promise" "^2.2.0" + "@open-draft/until" "^2.1.0" + "@types/cookie" "^0.6.0" + "@types/statuses" "^2.0.4" + graphql "^16.8.1" + headers-polyfill "^4.0.2" + is-node-process "^1.2.0" + outvariant "^1.4.3" + path-to-regexp "^6.3.0" + picocolors "^1.1.1" + strict-event-emitter "^0.5.1" + type-fest "^4.26.1" + yargs "^17.7.2" + +mute-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-2.0.0.tgz#a5446fc0c512b71c83c44d908d5c7b7b4c493b2b" + integrity sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -2402,13 +2445,6 @@ neo-async@^2.6.2: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -node-fetch@^2.7.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" - integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== - dependencies: - whatwg-url "^5.0.0" - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -2432,14 +2468,9 @@ npm-run-path@^4.0.1: path-key "^3.0.0" nwsapi@^2.2.2: - version "2.2.20" - resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.20.tgz#22e53253c61e7b0e7e93cef42c891154bcca11ef" - integrity sha512-/ieB+mDe4MrrKMT8z+mQL8klXydZWGR5Dowt4RAGKbJ3kIGEx3X4ljUo+6V73IXtUPWgfOlU5B9MlGxFO5T+cA== - -object-inspect@^1.13.3: - version "1.13.4" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.4.tgz#8375265e21bc20d0fa582c22e1b13485d6e00213" - integrity sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew== + version "2.2.21" + resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.21.tgz#8df7797079350adda208910d8c33fc4c2d7520c3" + integrity sha512-o6nIY3qwiSXl7/LuOU0Dmuctd34Yay0yeuZRLFmDPrrdHpXKFndPj3hM+YEPVHYC5fx2otBx4Ilc/gyYSAUaIA== once@^1.3.0: version "1.4.0" @@ -2455,6 +2486,11 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +outvariant@^1.4.0, outvariant@^1.4.3: + version "1.4.3" + resolved "https://registry.yarnpkg.com/outvariant/-/outvariant-1.4.3.tgz#221c1bfc093e8fec7075497e7799fdbf43d14873" + integrity sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA== + p-limit@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" @@ -2518,6 +2554,11 @@ path-parse@^1.0.7: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== +path-to-regexp@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.3.0.tgz#2b6a26a337737a8e1416f9272ed0766b1c0389f4" + integrity sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ== + picocolors@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b" @@ -2541,9 +2582,9 @@ pkg-dir@^4.2.0: find-up "^4.0.0" prettier@^3.4.2: - version "3.5.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.5.3.tgz#4fc2ce0d657e7a02e602549f053b239cb7dfe1b5" - integrity sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw== + version "3.6.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.6.2.tgz#ccda02a1003ebbb2bfda6f83a074978f608b9393" + integrity sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ== pretty-format@^29.0.0, pretty-format@^29.7.0: version "29.7.0" @@ -2554,11 +2595,6 @@ pretty-format@^29.0.0, pretty-format@^29.7.0: ansi-styles "^5.0.0" react-is "^18.0.0" -process@^0.11.10: - version "0.11.10" - resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" - integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== - prompts@^2.0.1: version "2.4.2" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069" @@ -2584,13 +2620,6 @@ pure-rand@^6.0.0: resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.1.0.tgz#d173cf23258231976ccbdb05247c9787957604f2" integrity sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA== -qs@^6.13.1: - version "6.14.0" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.14.0.tgz#c63fa40680d2c5c941412a0e899c89af60c0a930" - integrity sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w== - dependencies: - side-channel "^1.1.0" - querystringify@^2.1.1: version "2.2.0" resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" @@ -2608,17 +2637,6 @@ react-is@^18.0.0: resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== -readable-stream@^4.5.2: - version "4.7.0" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.7.0.tgz#cedbd8a1146c13dfff8dab14068028d58c15ac91" - integrity sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg== - dependencies: - abort-controller "^3.0.0" - buffer "^6.0.3" - events "^3.3.0" - process "^0.11.10" - string_decoder "^1.3.0" - require-directory@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" @@ -2660,16 +2678,11 @@ resolve@^1.20.0: path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" -safe-buffer@^5.1.0, safe-buffer@~5.2.0: +safe-buffer@^5.1.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== -safe-buffer@~5.1.1: - version "5.1.2" - resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" - integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== - "safer-buffer@>= 2.1.2 < 3.0.0": version "2.1.2" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" @@ -2697,10 +2710,10 @@ semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.3.4, semver@^7.5.3, semver@^7.5.4, semver@^7.7.1: - version "7.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.1.tgz#abd5098d82b18c6c81f6074ff2647fd3e7220c9f" - integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== +semver@^7.3.4, semver@^7.5.3, semver@^7.5.4, semver@^7.7.2: + version "7.7.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.2.tgz#67d99fdcd35cec21e6f8b87a7fd515a33f982b58" + integrity sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA== serialize-javascript@^6.0.2: version "6.0.2" @@ -2721,51 +2734,16 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -side-channel-list@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/side-channel-list/-/side-channel-list-1.0.0.tgz#10cb5984263115d3b7a0e336591e290a830af8ad" - integrity sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA== - dependencies: - es-errors "^1.3.0" - object-inspect "^1.13.3" - -side-channel-map@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/side-channel-map/-/side-channel-map-1.0.1.tgz#d6bb6b37902c6fef5174e5f533fab4c732a26f42" - integrity sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA== - dependencies: - call-bound "^1.0.2" - es-errors "^1.3.0" - get-intrinsic "^1.2.5" - object-inspect "^1.13.3" - -side-channel-weakmap@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz#11dda19d5368e40ce9ec2bdc1fb0ecbc0790ecea" - integrity sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A== - dependencies: - call-bound "^1.0.2" - es-errors "^1.3.0" - get-intrinsic "^1.2.5" - object-inspect "^1.13.3" - side-channel-map "^1.0.1" - -side-channel@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.1.0.tgz#c3fcff9c4da932784873335ec9765fa94ff66bc9" - integrity sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw== - dependencies: - es-errors "^1.3.0" - object-inspect "^1.13.3" - side-channel-list "^1.0.0" - side-channel-map "^1.0.1" - side-channel-weakmap "^1.0.2" - signal-exit@^3.0.3, signal-exit@^3.0.7: version "3.0.7" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +signal-exit@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" + integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" @@ -2798,9 +2776,9 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== source-map@^0.7.4: - version "0.7.4" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656" - integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA== + version "0.7.6" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.6.tgz#a3658ab87e5b6429c8a1f3ba0083d4c61ca3ef02" + integrity sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ== sprintf-js@~1.0.2: version "1.0.3" @@ -2814,6 +2792,16 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" +statuses@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.2.tgz#8f75eecef765b5e1cfcdc080da59409ed424e382" + integrity sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw== + +strict-event-emitter@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz#1602ece81c51574ca39c6815e09f1a3e8550bd93" + integrity sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ== + string-length@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a" @@ -2831,13 +2819,6 @@ string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string_decoder@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" - integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== - dependencies: - safe-buffer "~5.2.0" - strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" @@ -2885,9 +2866,9 @@ symbol-tree@^3.2.4: integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw== tapable@^2.1.1, tapable@^2.2.0: - version "2.2.1" - resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" - integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== + version "2.2.2" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.2.tgz#ab4984340d30cb9989a490032f086dbb8b56d872" + integrity sha512-Re10+NauLTMCudc7T5WLFLAwDhQ0JWdrMK+9B2M8zR5hRExKmsRDCBA7/aV/pNJFltmBFO5BAMlQFi/vq3nKOg== terser-webpack-plugin@^5.3.11: version "5.3.14" @@ -2901,12 +2882,12 @@ terser-webpack-plugin@^5.3.11: terser "^5.31.1" terser@^5.31.1: - version "5.39.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.39.0.tgz#0e82033ed57b3ddf1f96708d123cca717d86ca3a" - integrity sha512-LBAhFyLho16harJoWMg/nZsQYgTrg5jXOn2nCYjRUcZZEdE3qa2zb8QEDRUGVZBW4rlazf2fxkg8tztybTaqWw== + version "5.43.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.43.1.tgz#88387f4f9794ff1a29e7ad61fb2932e25b4fdb6d" + integrity sha512-+6erLbBm0+LROX2sPXlUYx/ux5PyE9K/a92Wrt6oA+WDAoFTdpHE5tCYCI5PNzq2y8df4rA+QgHLJuR4jNymsg== dependencies: "@jridgewell/source-map" "^0.3.3" - acorn "^8.8.2" + acorn "^8.14.0" commander "^2.20.0" source-map-support "~0.5.20" @@ -2931,7 +2912,7 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -tough-cookie@^4.1.2: +tough-cookie@^4.1.2, tough-cookie@^4.1.4: version "4.1.4" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.4.tgz#945f1461b45b5a8c76821c33ea49c3ac192c1b36" integrity sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag== @@ -2948,25 +2929,19 @@ tr46@^3.0.0: dependencies: punycode "^2.1.1" -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" - integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== - -ts-jest@^29.1.1: - version "29.3.2" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.3.2.tgz#0576cdf0a507f811fe73dcd16d135ce89f8156cb" - integrity sha512-bJJkrWc6PjFVz5g2DGCNUo8z7oFEYaz1xP1NpeDU7KNLMWPpEyV8Chbpkn8xjzgRDpQhnGMyvyldoL7h8JXyug== +ts-jest@^29.3.4: + version "29.4.1" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.4.1.tgz#42d33beb74657751d315efb9a871fe99e3b9b519" + integrity sha512-SaeUtjfpg9Uqu8IbeDKtdaS0g8lS6FT6OzM3ezrDfErPJPHNDo/Ey+VFGP1bQIDfagYDLyRpd7O15XpG1Es2Uw== dependencies: bs-logger "^0.2.6" - ejs "^3.1.10" fast-json-stable-stringify "^2.1.0" - jest-util "^29.0.0" + handlebars "^4.7.8" json5 "^2.2.3" lodash.memoize "^4.1.2" make-error "^1.3.6" - semver "^7.7.1" - type-fest "^4.39.1" + semver "^7.7.2" + type-fest "^4.41.0" yargs-parser "^21.1.1" ts-loader@^9.5.1: @@ -2990,7 +2965,7 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -type-fest@^4.39.1: +type-fest@^4.26.1, type-fest@^4.41.0: version "4.41.0" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.41.0.tgz#6ae1c8e5731273c2bf1f58ad39cbae2c91a46c58" integrity sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA== @@ -3000,15 +2975,20 @@ typescript@~5.7.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.3.tgz#919b44a7dbb8583a9b856d162be24a54bf80073e" integrity sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw== +uglify-js@^3.1.4: + version "3.19.3" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.19.3.tgz#82315e9bbc6f2b25888858acd1fff8441035b77f" + integrity sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ== + undici-types@~5.26.4: version "5.26.5" resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici-types@~6.21.0: - version "6.21.0" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.21.0.tgz#691d00af3909be93a7faa13be61b3a5b50ef12cb" - integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ== +undici-types@~7.10.0: + version "7.10.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.10.0.tgz#4ac2e058ce56b462b056e629cc6a02393d3ff350" + integrity sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag== universalify@^0.2.0: version "0.2.0" @@ -3023,11 +3003,6 @@ update-browserslist-db@^1.1.3: escalade "^3.2.0" picocolors "^1.1.1" -url-join@4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" - integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== - url-parse@^1.5.3: version "1.5.10" resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1" @@ -3060,43 +3035,39 @@ walker@^1.0.8: makeerror "1.0.12" watchpack@^2.4.1: - version "2.4.2" - resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.2.tgz#2feeaed67412e7c33184e5a79ca738fbd38564da" - integrity sha512-TnbFSbcOCcDgjZ4piURLCbJ3nJhznVh9kw6F6iokjiFPl8ONxe9A6nMDVXDiNbrSfLILs6vB07F7wLBrwPYzJw== + version "2.4.4" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.4.tgz#473bda72f0850453da6425081ea46fc0d7602947" + integrity sha512-c5EGNOiyxxV5qmTtAB7rbiXxi1ooX1pQKMLX/MIabJjRA0SJBQOjKF+KSVfHkr9U1cADPon0mRiVe/riyaiDUA== dependencies: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" - integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== - webidl-conversions@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a" integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g== -webpack-sources@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" - integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== +webpack-sources@^3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.3.3.tgz#d4bf7f9909675d7a070ff14d0ef2a4f3c982c723" + integrity sha512-yd1RBzSGanHkitROoPFd6qsrxt+oFhg/129YzheDGqeustzX0vTZJZsSsQjVQC4yzBQ56K55XU8gaNCtIzOnTg== webpack@^5.97.1: - version "5.99.8" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.99.8.tgz#dd31a020b7c092d30c4c6d9a4edb95809e7f5946" - integrity sha512-lQ3CPiSTpfOnrEGeXDwoq5hIGzSjmwD72GdfVzF7CQAI7t47rJG9eDWvcEkEn3CUQymAElVvDg3YNTlCYj+qUQ== + version "5.101.2" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.101.2.tgz#08c222b7acfce7da95c593e2f88ea1638a07b344" + integrity sha512-4JLXU0tD6OZNVqlwzm3HGEhAHufSiyv+skb7q0d2367VDMzrU1Q/ZeepvkcHH0rZie6uqEtTQQe0OEOOluH3Mg== dependencies: "@types/eslint-scope" "^3.7.7" - "@types/estree" "^1.0.6" + "@types/estree" "^1.0.8" "@types/json-schema" "^7.0.15" "@webassemblyjs/ast" "^1.14.1" "@webassemblyjs/wasm-edit" "^1.14.1" "@webassemblyjs/wasm-parser" "^1.14.1" - acorn "^8.14.0" + acorn "^8.15.0" + acorn-import-phases "^1.0.3" browserslist "^4.24.0" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.17.1" + enhanced-resolve "^5.17.3" es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" @@ -3110,7 +3081,7 @@ webpack@^5.97.1: tapable "^2.1.1" terser-webpack-plugin "^5.3.11" watchpack "^2.4.1" - webpack-sources "^3.2.3" + webpack-sources "^3.3.3" whatwg-encoding@^2.0.0: version "2.0.0" @@ -3132,14 +3103,6 @@ whatwg-url@^11.0.0: tr46 "^3.0.0" webidl-conversions "^7.0.0" -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" - integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" - which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" @@ -3147,6 +3110,20 @@ which@^2.0.1: dependencies: isexe "^2.0.0" +wordwrap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== + +wrap-ansi@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" @@ -3170,9 +3147,9 @@ write-file-atomic@^4.0.2: signal-exit "^3.0.7" ws@^8.11.0: - version "8.18.2" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.2.tgz#42738b2be57ced85f46154320aabb51ab003705a" - integrity sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ== + version "8.18.3" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.3.tgz#b56b88abffde62791c639170400c93dcb0c95472" + integrity sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg== xml-name-validator@^4.0.0: version "4.0.0" @@ -3199,7 +3176,7 @@ yargs-parser@^21.1.1: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== -yargs@^17.3.1: +yargs@^17.3.1, yargs@^17.7.2: version "17.7.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269" integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w== @@ -3216,3 +3193,8 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +yoctocolors-cjs@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242" + integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==