diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e2b82d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: ci + +on: [push] + +jobs: + compile: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up node + uses: actions/setup-node@v3 + + - name: Compile + run: yarn && yarn build + + publish: + needs: [ compile ] + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up node + uses: actions/setup-node@v3 + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Publish to npm + run: | + npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} + npm publish --access public + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..050eae0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +node_modules +.DS_Store +/dist +/Client.d.ts +/Client.js +/index.d.ts +/index.js +/api +/core +/errors +/serialization \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e62938d --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +node_modules +src +.gitignore +.github +.fernignore +.prettierrc.yml +tsconfig.json +yarn.lock \ No newline at end of file diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..0c06786 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,2 @@ +tabWidth: 4 +printWidth: 120 diff --git a/package.json b/package.json new file mode 100644 index 0000000..088c576 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "@fern-api/vocode", + "version": "0.0.3", + "private": false, + "repository": "https://github.com/fern-vocode/vocode-node", + "main": "./index.js", + "types": "./index.d.ts", + "scripts": { + "format": "prettier --write 'src/**/*.ts'", + "build": "tsc", + "prepack": "cp -rv dist/. ." + }, + "dependencies": { + "url-join": "4.0.1", + "@types/url-join": "4.0.1", + "@ungap/url-search-params": "0.2.2", + "axios": "1.4.0", + "js-base64": "3.7.2" + }, + "devDependencies": { + "@types/node": "17.0.33", + "prettier": "2.7.1", + "typescript": "4.6.4" + } +} \ No newline at end of file diff --git a/src/Client.ts b/src/Client.ts new file mode 100644 index 0000000..6be1116 --- /dev/null +++ b/src/Client.ts @@ -0,0 +1,65 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "./core"; +import { Numbers } from "./api/resources/numbers/client/Client"; +import { Calls } from "./api/resources/calls/client/Client"; +import { Usage } from "./api/resources/usage/client/Client"; +import { Actions } from "./api/resources/actions/client/Client"; +import { Agents } from "./api/resources/agents/client/Client"; +import { Voices } from "./api/resources/voices/client/Client"; +import { Webhooks } from "./api/resources/webhooks/client/Client"; + +export declare namespace VocodeClient { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class VocodeClient { + constructor(protected readonly _options: VocodeClient.Options) {} + + protected _numbers: Numbers | undefined; + + public get numbers(): Numbers { + return (this._numbers ??= new Numbers(this._options)); + } + + protected _calls: Calls | undefined; + + public get calls(): Calls { + return (this._calls ??= new Calls(this._options)); + } + + protected _usage: Usage | undefined; + + public get usage(): Usage { + return (this._usage ??= new Usage(this._options)); + } + + protected _actions: Actions | undefined; + + public get actions(): Actions { + return (this._actions ??= new Actions(this._options)); + } + + protected _agents: Agents | undefined; + + public get agents(): Agents { + return (this._agents ??= new Agents(this._options)); + } + + protected _voices: Voices | undefined; + + public get voices(): Voices { + return (this._voices ??= new Voices(this._options)); + } + + protected _webhooks: Webhooks | undefined; + + public get webhooks(): Webhooks { + return (this._webhooks ??= new Webhooks(this._options)); + } +} diff --git a/src/api/errors/UnprocessableEntityError.ts b/src/api/errors/UnprocessableEntityError.ts new file mode 100644 index 0000000..6ce414c --- /dev/null +++ b/src/api/errors/UnprocessableEntityError.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as errors from "../../errors"; +import * as Vocode from ".."; + +export class UnprocessableEntityError extends errors.VocodeError { + constructor(body: Vocode.HttpValidationError) { + super({ + statusCode: 422, + body: body, + }); + Object.setPrototypeOf(this, UnprocessableEntityError.prototype); + } +} diff --git a/src/api/errors/index.ts b/src/api/errors/index.ts new file mode 100644 index 0000000..58719cc --- /dev/null +++ b/src/api/errors/index.ts @@ -0,0 +1 @@ +export * from "./UnprocessableEntityError"; diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..1cb55b6 --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,3 @@ +export * from "./types"; +export * from "./errors"; +export * from "./resources"; diff --git a/src/api/resources/actions/client/Client.ts b/src/api/resources/actions/client/Client.ts new file mode 100644 index 0000000..006bf7e --- /dev/null +++ b/src/api/resources/actions/client/Client.ts @@ -0,0 +1,256 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import { default as URLSearchParams } from "@ungap/url-search-params"; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; + +export declare namespace Actions { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class Actions { + constructor(protected readonly _options: Actions.Options) {} + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getAction(request: Vocode.GetActionRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/actions"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.GetActionResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + public async listActions(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/actions/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.actions.listActions.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async createAction(request: Vocode.CreateActionRequest): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/actions/create"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + body: await serializers.CreateActionRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.CreateActionResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async updateAction(request: Vocode.UpdateActionRequest): Promise { + const { id, body: _body } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/actions/update"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + body: await serializers.UpdateActionRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.UpdateActionResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/actions/client/index.ts b/src/api/resources/actions/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/actions/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/actions/client/requests/GetActionRequest.ts b/src/api/resources/actions/client/requests/GetActionRequest.ts new file mode 100644 index 0000000..8d06491 --- /dev/null +++ b/src/api/resources/actions/client/requests/GetActionRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetActionRequest { + id: string; +} diff --git a/src/api/resources/actions/client/requests/UpdateActionRequest.ts b/src/api/resources/actions/client/requests/UpdateActionRequest.ts new file mode 100644 index 0000000..98e6759 --- /dev/null +++ b/src/api/resources/actions/client/requests/UpdateActionRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface UpdateActionRequest { + id: string; + body: Vocode.UpdateActionRequestBody; +} diff --git a/src/api/resources/actions/client/requests/index.ts b/src/api/resources/actions/client/requests/index.ts new file mode 100644 index 0000000..642e472 --- /dev/null +++ b/src/api/resources/actions/client/requests/index.ts @@ -0,0 +1,2 @@ +export { GetActionRequest } from "./GetActionRequest"; +export { UpdateActionRequest } from "./UpdateActionRequest"; diff --git a/src/api/resources/actions/index.ts b/src/api/resources/actions/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/actions/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/agents/client/Client.ts b/src/api/resources/agents/client/Client.ts new file mode 100644 index 0000000..0bc3803 --- /dev/null +++ b/src/api/resources/agents/client/Client.ts @@ -0,0 +1,256 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import { default as URLSearchParams } from "@ungap/url-search-params"; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; + +export declare namespace Agents { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class Agents { + constructor(protected readonly _options: Agents.Options) {} + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getAgent(request: Vocode.GetAgentRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/agents"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Agent.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + public async listAgents(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/agents/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.agents.listAgents.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async createAgent(request: Vocode.AgentParams): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/agents/create"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + body: await serializers.AgentParams.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Agent.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async updateAgent(request: Vocode.UpdateAgentRequest): Promise { + const { id, body: _body } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/agents/update"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + body: await serializers.AgentUpdateParams.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Agent.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/agents/client/index.ts b/src/api/resources/agents/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/agents/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/agents/client/requests/GetAgentRequest.ts b/src/api/resources/agents/client/requests/GetAgentRequest.ts new file mode 100644 index 0000000..6ffa266 --- /dev/null +++ b/src/api/resources/agents/client/requests/GetAgentRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetAgentRequest { + id: string; +} diff --git a/src/api/resources/agents/client/requests/UpdateAgentRequest.ts b/src/api/resources/agents/client/requests/UpdateAgentRequest.ts new file mode 100644 index 0000000..05e3f9c --- /dev/null +++ b/src/api/resources/agents/client/requests/UpdateAgentRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface UpdateAgentRequest { + id: string; + body: Vocode.AgentUpdateParams; +} diff --git a/src/api/resources/agents/client/requests/index.ts b/src/api/resources/agents/client/requests/index.ts new file mode 100644 index 0000000..4474428 --- /dev/null +++ b/src/api/resources/agents/client/requests/index.ts @@ -0,0 +1,2 @@ +export { GetAgentRequest } from "./GetAgentRequest"; +export { UpdateAgentRequest } from "./UpdateAgentRequest"; diff --git a/src/api/resources/agents/index.ts b/src/api/resources/agents/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/agents/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/calls/client/Client.ts b/src/api/resources/calls/client/Client.ts new file mode 100644 index 0000000..470dd57 --- /dev/null +++ b/src/api/resources/calls/client/Client.ts @@ -0,0 +1,258 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; +import { default as URLSearchParams } from "@ungap/url-search-params"; + +export declare namespace Calls { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +/** + * Manage calls. + */ +export class Calls { + constructor(protected readonly _options: Calls.Options) {} + + public async listCalls(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/calls/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.calls.listCalls.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getCall(request: Vocode.GetCallRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/calls"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Call.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async endCall(request: Vocode.EndCallRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/calls/end"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Call.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async createCall(request: Vocode.CreateCallRequest): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/calls/create"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + body: await serializers.CreateCallRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Call.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/calls/client/index.ts b/src/api/resources/calls/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/calls/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/calls/client/requests/CreateCallRequest.ts b/src/api/resources/calls/client/requests/CreateCallRequest.ts new file mode 100644 index 0000000..76b4dbf --- /dev/null +++ b/src/api/resources/calls/client/requests/CreateCallRequest.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface CreateCallRequest { + fromNumber: string; + toNumber: string; + goal: string; + agent: Vocode.CreateCallRequestAgent; +} diff --git a/src/api/resources/calls/client/requests/EndCallRequest.ts b/src/api/resources/calls/client/requests/EndCallRequest.ts new file mode 100644 index 0000000..e0da679 --- /dev/null +++ b/src/api/resources/calls/client/requests/EndCallRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface EndCallRequest { + id: string; +} diff --git a/src/api/resources/calls/client/requests/GetCallRequest.ts b/src/api/resources/calls/client/requests/GetCallRequest.ts new file mode 100644 index 0000000..d65ca1e --- /dev/null +++ b/src/api/resources/calls/client/requests/GetCallRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetCallRequest { + id: string; +} diff --git a/src/api/resources/calls/client/requests/index.ts b/src/api/resources/calls/client/requests/index.ts new file mode 100644 index 0000000..be92eb8 --- /dev/null +++ b/src/api/resources/calls/client/requests/index.ts @@ -0,0 +1,3 @@ +export { GetCallRequest } from "./GetCallRequest"; +export { EndCallRequest } from "./EndCallRequest"; +export { CreateCallRequest } from "./CreateCallRequest"; diff --git a/src/api/resources/calls/index.ts b/src/api/resources/calls/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/calls/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts new file mode 100644 index 0000000..6595779 --- /dev/null +++ b/src/api/resources/index.ts @@ -0,0 +1,13 @@ +export * as numbers from "./numbers"; +export * as calls from "./calls"; +export * as usage from "./usage"; +export * as actions from "./actions"; +export * as agents from "./agents"; +export * as voices from "./voices"; +export * as webhooks from "./webhooks"; +export * from "./numbers/client/requests"; +export * from "./calls/client/requests"; +export * from "./actions/client/requests"; +export * from "./agents/client/requests"; +export * from "./voices/client/requests"; +export * from "./webhooks/client/requests"; diff --git a/src/api/resources/numbers/client/Client.ts b/src/api/resources/numbers/client/Client.ts new file mode 100644 index 0000000..fee60ec --- /dev/null +++ b/src/api/resources/numbers/client/Client.ts @@ -0,0 +1,306 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; +import { default as URLSearchParams } from "@ungap/url-search-params"; + +export declare namespace Numbers { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +/** + * Operations with phone numbers. + */ +export class Numbers { + constructor(protected readonly _options: Numbers.Options) {} + + public async listNumbers(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/numbers/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.numbers.listNumbers.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getNumber(request: Vocode.GetNumberRequest): Promise { + const { phoneNumber } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("phone_number", phoneNumber); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/numbers"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.PhoneNumber.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + public async buyNumber(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/numbers/buy"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.PhoneNumber.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async updateNumber(request: Vocode.UpdateNumberRequest): Promise { + const { phoneNumber, ..._body } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("phone_number", phoneNumber); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/numbers/update"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + body: await serializers.UpdateNumberRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.PhoneNumber.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async cancelNumber(request: Vocode.CancelNumberRequest): Promise { + const { phoneNumber } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("phone_number", phoneNumber); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/numbers/cancel"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.PhoneNumber.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/numbers/client/index.ts b/src/api/resources/numbers/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/numbers/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/numbers/client/requests/CancelNumberRequest.ts b/src/api/resources/numbers/client/requests/CancelNumberRequest.ts new file mode 100644 index 0000000..0a6e722 --- /dev/null +++ b/src/api/resources/numbers/client/requests/CancelNumberRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface CancelNumberRequest { + phoneNumber: string; +} diff --git a/src/api/resources/numbers/client/requests/GetNumberRequest.ts b/src/api/resources/numbers/client/requests/GetNumberRequest.ts new file mode 100644 index 0000000..cf4deb7 --- /dev/null +++ b/src/api/resources/numbers/client/requests/GetNumberRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetNumberRequest { + phoneNumber: string; +} diff --git a/src/api/resources/numbers/client/requests/UpdateNumberRequest.ts b/src/api/resources/numbers/client/requests/UpdateNumberRequest.ts new file mode 100644 index 0000000..4c43693 --- /dev/null +++ b/src/api/resources/numbers/client/requests/UpdateNumberRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface UpdateNumberRequest { + phoneNumber: string; + inboundAgent: Vocode.UpdateNumberRequestInboundAgent; +} diff --git a/src/api/resources/numbers/client/requests/index.ts b/src/api/resources/numbers/client/requests/index.ts new file mode 100644 index 0000000..00fdfde --- /dev/null +++ b/src/api/resources/numbers/client/requests/index.ts @@ -0,0 +1,3 @@ +export { GetNumberRequest } from "./GetNumberRequest"; +export { UpdateNumberRequest } from "./UpdateNumberRequest"; +export { CancelNumberRequest } from "./CancelNumberRequest"; diff --git a/src/api/resources/numbers/index.ts b/src/api/resources/numbers/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/numbers/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/usage/client/Client.ts b/src/api/resources/usage/client/Client.ts new file mode 100644 index 0000000..3b1116c --- /dev/null +++ b/src/api/resources/usage/client/Client.ts @@ -0,0 +1,68 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; + +export declare namespace Usage { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class Usage { + constructor(protected readonly _options: Usage.Options) {} + + public async getUsage(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/usage"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Usage.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/usage/client/index.ts b/src/api/resources/usage/client/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/api/resources/usage/client/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/api/resources/usage/index.ts b/src/api/resources/usage/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/usage/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/voices/client/Client.ts b/src/api/resources/voices/client/Client.ts new file mode 100644 index 0000000..70101c1 --- /dev/null +++ b/src/api/resources/voices/client/Client.ts @@ -0,0 +1,256 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import { default as URLSearchParams } from "@ungap/url-search-params"; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; + +export declare namespace Voices { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class Voices { + constructor(protected readonly _options: Voices.Options) {} + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getVoice(request: Vocode.GetVoiceRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/voices"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.GetVoiceResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + public async listVoices(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/voices/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.voices.listVoices.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async createVoice(request: Vocode.CreateVoiceRequest): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/voices/create"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + body: await serializers.CreateVoiceRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.CreateVoiceResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async updateVoice(request: Vocode.UpdateVoiceRequest): Promise { + const { id, body: _body } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/voices/update"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + body: await serializers.UpdateVoiceRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.UpdateVoiceResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/voices/client/index.ts b/src/api/resources/voices/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/voices/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/voices/client/requests/GetVoiceRequest.ts b/src/api/resources/voices/client/requests/GetVoiceRequest.ts new file mode 100644 index 0000000..6bfeb81 --- /dev/null +++ b/src/api/resources/voices/client/requests/GetVoiceRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetVoiceRequest { + id: string; +} diff --git a/src/api/resources/voices/client/requests/UpdateVoiceRequest.ts b/src/api/resources/voices/client/requests/UpdateVoiceRequest.ts new file mode 100644 index 0000000..2270ce1 --- /dev/null +++ b/src/api/resources/voices/client/requests/UpdateVoiceRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface UpdateVoiceRequest { + id: string; + body: Vocode.UpdateVoiceRequestBody; +} diff --git a/src/api/resources/voices/client/requests/index.ts b/src/api/resources/voices/client/requests/index.ts new file mode 100644 index 0000000..de99bde --- /dev/null +++ b/src/api/resources/voices/client/requests/index.ts @@ -0,0 +1,2 @@ +export { GetVoiceRequest } from "./GetVoiceRequest"; +export { UpdateVoiceRequest } from "./UpdateVoiceRequest"; diff --git a/src/api/resources/voices/index.ts b/src/api/resources/voices/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/voices/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/resources/webhooks/client/Client.ts b/src/api/resources/webhooks/client/Client.ts new file mode 100644 index 0000000..960926b --- /dev/null +++ b/src/api/resources/webhooks/client/Client.ts @@ -0,0 +1,256 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../core"; +import * as Vocode from "../../.."; +import { default as URLSearchParams } from "@ungap/url-search-params"; +import urlJoin from "url-join"; +import * as serializers from "../../../../serialization"; +import * as errors from "../../../../errors"; + +export declare namespace Webhooks { + interface Options { + environment: core.Supplier; + token: core.Supplier; + } +} + +export class Webhooks { + constructor(protected readonly _options: Webhooks.Options) {} + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async getWebhook(request: Vocode.GetWebhookRequest): Promise { + const { id } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/webhooks"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Webhook.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + public async listWebhooks(): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/webhooks/list"), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.webhooks.listWebhooks.Response.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async createWebhook(request: Vocode.WebhookParams): Promise { + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/webhooks/create"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + body: await serializers.WebhookParams.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Webhook.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + /** + * @throws {@link Vocode.UnprocessableEntityError} + */ + public async updateWebhook(request: Vocode.UpdateWebhookRequest): Promise { + const { id, body: _body } = request; + const _queryParams = new URLSearchParams(); + _queryParams.append("id", id); + const _response = await core.fetcher({ + url: urlJoin(await core.Supplier.get(this._options.environment), "v1/webhooks/update"), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern-api/vocode", + "X-Fern-SDK-Version": "0.0.3", + }, + contentType: "application/json", + queryParameters: _queryParams, + body: await serializers.WebhookUpdateParams.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + timeoutMs: 60000, + }); + if (_response.ok) { + return await serializers.Webhook.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 422: + throw new Vocode.UnprocessableEntityError( + await serializers.HttpValidationError.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.VocodeError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.VocodeTimeoutError(); + case "unknown": + throw new errors.VocodeError({ + message: _response.error.errorMessage, + }); + } + } + + protected async _getAuthorizationHeader() { + return `Bearer ${await core.Supplier.get(this._options.token)}`; + } +} diff --git a/src/api/resources/webhooks/client/index.ts b/src/api/resources/webhooks/client/index.ts new file mode 100644 index 0000000..415726b --- /dev/null +++ b/src/api/resources/webhooks/client/index.ts @@ -0,0 +1 @@ +export * from "./requests"; diff --git a/src/api/resources/webhooks/client/requests/GetWebhookRequest.ts b/src/api/resources/webhooks/client/requests/GetWebhookRequest.ts new file mode 100644 index 0000000..ec42f4e --- /dev/null +++ b/src/api/resources/webhooks/client/requests/GetWebhookRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface GetWebhookRequest { + id: string; +} diff --git a/src/api/resources/webhooks/client/requests/UpdateWebhookRequest.ts b/src/api/resources/webhooks/client/requests/UpdateWebhookRequest.ts new file mode 100644 index 0000000..568c9f8 --- /dev/null +++ b/src/api/resources/webhooks/client/requests/UpdateWebhookRequest.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from "../../../.."; + +export interface UpdateWebhookRequest { + id: string; + body: Vocode.WebhookUpdateParams; +} diff --git a/src/api/resources/webhooks/client/requests/index.ts b/src/api/resources/webhooks/client/requests/index.ts new file mode 100644 index 0000000..a61dc77 --- /dev/null +++ b/src/api/resources/webhooks/client/requests/index.ts @@ -0,0 +1,2 @@ +export { GetWebhookRequest } from "./GetWebhookRequest"; +export { UpdateWebhookRequest } from "./UpdateWebhookRequest"; diff --git a/src/api/resources/webhooks/index.ts b/src/api/resources/webhooks/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/api/resources/webhooks/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/api/types/ActionConfig.ts b/src/api/types/ActionConfig.ts new file mode 100644 index 0000000..8d49dab --- /dev/null +++ b/src/api/types/ActionConfig.ts @@ -0,0 +1,5 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ActionConfig {} diff --git a/src/api/types/ActionType.ts b/src/api/types/ActionType.ts new file mode 100644 index 0000000..c06b00e --- /dev/null +++ b/src/api/types/ActionType.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type ActionType = "action_end_conversation" | "action_dtmf"; + +export const ActionType = { + ActionEndConversation: "action_end_conversation", + ActionDtmf: "action_dtmf", +} as const; diff --git a/src/api/types/Agent.ts b/src/api/types/Agent.ts new file mode 100644 index 0000000..c987108 --- /dev/null +++ b/src/api/types/Agent.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface Agent { + id: string; + userId: string; + prompt: string; + actions: Vocode.AgentActionsItem[]; + voice: Vocode.AgentVoice; + initialMessage?: string; + webhook?: Vocode.AgentWebhook; +} diff --git a/src/api/types/AgentActionsItem.ts b/src/api/types/AgentActionsItem.ts new file mode 100644 index 0000000..639856a --- /dev/null +++ b/src/api/types/AgentActionsItem.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentActionsItem = string | Vocode.EndConversationAction | Vocode.DtmfAction; diff --git a/src/api/types/AgentParams.ts b/src/api/types/AgentParams.ts new file mode 100644 index 0000000..078cb6a --- /dev/null +++ b/src/api/types/AgentParams.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface AgentParams { + prompt: string; + actions?: Vocode.AgentParamsActionsItem[]; + voice: Vocode.AgentParamsVoice; + initialMessage?: string; + webhook?: Vocode.AgentParamsWebhook; +} diff --git a/src/api/types/AgentParamsActionsItem.ts b/src/api/types/AgentParamsActionsItem.ts new file mode 100644 index 0000000..a3e6e9e --- /dev/null +++ b/src/api/types/AgentParamsActionsItem.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentParamsActionsItem = string | Vocode.EndConversationActionParams | Vocode.DtmfActionParams; diff --git a/src/api/types/AgentParamsVoice.ts b/src/api/types/AgentParamsVoice.ts new file mode 100644 index 0000000..362b406 --- /dev/null +++ b/src/api/types/AgentParamsVoice.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentParamsVoice = string | Vocode.AzureVoiceParams | Vocode.RimeVoiceParams | Vocode.ElevenLabsVoiceParams; diff --git a/src/api/types/AgentParamsWebhook.ts b/src/api/types/AgentParamsWebhook.ts new file mode 100644 index 0000000..a27ce2f --- /dev/null +++ b/src/api/types/AgentParamsWebhook.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentParamsWebhook = string | Vocode.WebhookParams; diff --git a/src/api/types/AgentUpdateParams.ts b/src/api/types/AgentUpdateParams.ts new file mode 100644 index 0000000..841d597 --- /dev/null +++ b/src/api/types/AgentUpdateParams.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface AgentUpdateParams { + prompt?: Vocode.AgentUpdateParamsPrompt; + actions?: Vocode.AgentUpdateParamsActions; + voice?: Vocode.AgentUpdateParamsVoice; + initialMessage?: Vocode.AgentUpdateParamsInitialMessage; + webhook?: Vocode.AgentUpdateParamsWebhook; +} diff --git a/src/api/types/AgentUpdateParamsActions.ts b/src/api/types/AgentUpdateParamsActions.ts new file mode 100644 index 0000000..3ce4448 --- /dev/null +++ b/src/api/types/AgentUpdateParamsActions.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsActions = Vocode.AgentUpdateParamsActionsAgentUpdateParamsActionsItem[] | Vocode.Undefined; diff --git a/src/api/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts b/src/api/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts new file mode 100644 index 0000000..1842101 --- /dev/null +++ b/src/api/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsActionsAgentUpdateParamsActionsItem = + | string + | Vocode.EndConversationActionUpdateParams + | Vocode.DtmfActionUpdateParams; diff --git a/src/api/types/AgentUpdateParamsInitialMessage.ts b/src/api/types/AgentUpdateParamsInitialMessage.ts new file mode 100644 index 0000000..31fd8d9 --- /dev/null +++ b/src/api/types/AgentUpdateParamsInitialMessage.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsInitialMessage = string | Vocode.Undefined; diff --git a/src/api/types/AgentUpdateParamsPrompt.ts b/src/api/types/AgentUpdateParamsPrompt.ts new file mode 100644 index 0000000..df7c56d --- /dev/null +++ b/src/api/types/AgentUpdateParamsPrompt.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsPrompt = string | Vocode.Undefined; diff --git a/src/api/types/AgentUpdateParamsVoice.ts b/src/api/types/AgentUpdateParamsVoice.ts new file mode 100644 index 0000000..3055f16 --- /dev/null +++ b/src/api/types/AgentUpdateParamsVoice.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsVoice = + | string + | Vocode.AzureVoiceUpdateParams + | Vocode.RimeVoiceUpdateParams + | Vocode.ElevenLabsVoiceUpdateParams + | Vocode.Undefined; diff --git a/src/api/types/AgentUpdateParamsWebhook.ts b/src/api/types/AgentUpdateParamsWebhook.ts new file mode 100644 index 0000000..6ae4ff1 --- /dev/null +++ b/src/api/types/AgentUpdateParamsWebhook.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentUpdateParamsWebhook = string | Vocode.WebhookUpdateParams | Vocode.Undefined; diff --git a/src/api/types/AgentVoice.ts b/src/api/types/AgentVoice.ts new file mode 100644 index 0000000..809c656 --- /dev/null +++ b/src/api/types/AgentVoice.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentVoice = string | Vocode.AzureVoice | Vocode.RimeVoice | Vocode.ElevenLabsVoice; diff --git a/src/api/types/AgentWebhook.ts b/src/api/types/AgentWebhook.ts new file mode 100644 index 0000000..d7fed67 --- /dev/null +++ b/src/api/types/AgentWebhook.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AgentWebhook = string | Vocode.Webhook; diff --git a/src/api/types/AzureVoice.ts b/src/api/types/AzureVoice.ts new file mode 100644 index 0000000..6d67896 --- /dev/null +++ b/src/api/types/AzureVoice.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface AzureVoice { + id: string; + userId: string; + type?: Vocode.VoiceType; + voiceName: string; + pitch?: number; + rate?: number; +} diff --git a/src/api/types/AzureVoiceParams.ts b/src/api/types/AzureVoiceParams.ts new file mode 100644 index 0000000..c400d77 --- /dev/null +++ b/src/api/types/AzureVoiceParams.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface AzureVoiceParams { + type: Vocode.VoiceType; + voiceName: string; + pitch?: number; + rate?: number; +} diff --git a/src/api/types/AzureVoiceUpdateParams.ts b/src/api/types/AzureVoiceUpdateParams.ts new file mode 100644 index 0000000..fd141d4 --- /dev/null +++ b/src/api/types/AzureVoiceUpdateParams.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface AzureVoiceUpdateParams { + type: Vocode.VoiceType; + voiceName?: Vocode.AzureVoiceUpdateParamsVoiceName; + pitch?: Vocode.AzureVoiceUpdateParamsPitch; + rate?: Vocode.AzureVoiceUpdateParamsRate; +} diff --git a/src/api/types/AzureVoiceUpdateParamsPitch.ts b/src/api/types/AzureVoiceUpdateParamsPitch.ts new file mode 100644 index 0000000..61555ca --- /dev/null +++ b/src/api/types/AzureVoiceUpdateParamsPitch.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AzureVoiceUpdateParamsPitch = number | Vocode.Undefined; diff --git a/src/api/types/AzureVoiceUpdateParamsRate.ts b/src/api/types/AzureVoiceUpdateParamsRate.ts new file mode 100644 index 0000000..3082c96 --- /dev/null +++ b/src/api/types/AzureVoiceUpdateParamsRate.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AzureVoiceUpdateParamsRate = number | Vocode.Undefined; diff --git a/src/api/types/AzureVoiceUpdateParamsVoiceName.ts b/src/api/types/AzureVoiceUpdateParamsVoiceName.ts new file mode 100644 index 0000000..bedc4e2 --- /dev/null +++ b/src/api/types/AzureVoiceUpdateParamsVoiceName.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type AzureVoiceUpdateParamsVoiceName = string | Vocode.Undefined; diff --git a/src/api/types/Call.ts b/src/api/types/Call.ts new file mode 100644 index 0000000..9e6eb00 --- /dev/null +++ b/src/api/types/Call.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface Call { + id: string; + userId: string; + toNumber: string; + fromNumber: string; + agent: Vocode.CallAgent; + goal?: string; + transcript?: string; + recordingUrl?: string; + status: Vocode.CallStatus; +} diff --git a/src/api/types/CallAgent.ts b/src/api/types/CallAgent.ts new file mode 100644 index 0000000..b3f1b64 --- /dev/null +++ b/src/api/types/CallAgent.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CallAgent = string | Vocode.Agent; diff --git a/src/api/types/CallStatus.ts b/src/api/types/CallStatus.ts new file mode 100644 index 0000000..b814deb --- /dev/null +++ b/src/api/types/CallStatus.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type CallStatus = "not_started" | "in_progress" | "error" | "ended"; + +export const CallStatus = { + NotStarted: "not_started", + InProgress: "in_progress", + Error: "error", + Ended: "ended", +} as const; diff --git a/src/api/types/CreateActionRequest.ts b/src/api/types/CreateActionRequest.ts new file mode 100644 index 0000000..777e9ff --- /dev/null +++ b/src/api/types/CreateActionRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CreateActionRequest = Vocode.EndConversationActionParams | Vocode.DtmfActionParams; diff --git a/src/api/types/CreateActionResponse.ts b/src/api/types/CreateActionResponse.ts new file mode 100644 index 0000000..1bc389d --- /dev/null +++ b/src/api/types/CreateActionResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CreateActionResponse = Vocode.EndConversationAction | Vocode.DtmfAction; diff --git a/src/api/types/CreateCallRequestAgent.ts b/src/api/types/CreateCallRequestAgent.ts new file mode 100644 index 0000000..d2b1fbe --- /dev/null +++ b/src/api/types/CreateCallRequestAgent.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CreateCallRequestAgent = string | Vocode.AgentParams; diff --git a/src/api/types/CreateVoiceRequest.ts b/src/api/types/CreateVoiceRequest.ts new file mode 100644 index 0000000..a454821 --- /dev/null +++ b/src/api/types/CreateVoiceRequest.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CreateVoiceRequest = Vocode.AzureVoiceParams | Vocode.RimeVoiceParams | Vocode.ElevenLabsVoiceParams; diff --git a/src/api/types/CreateVoiceResponse.ts b/src/api/types/CreateVoiceResponse.ts new file mode 100644 index 0000000..99ae830 --- /dev/null +++ b/src/api/types/CreateVoiceResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type CreateVoiceResponse = Vocode.AzureVoice | Vocode.RimeVoice | Vocode.ElevenLabsVoice; diff --git a/src/api/types/DtmfAction.ts b/src/api/types/DtmfAction.ts new file mode 100644 index 0000000..1541e4c --- /dev/null +++ b/src/api/types/DtmfAction.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface DtmfAction { + id: string; + userId: string; + type?: Vocode.ActionType; + config?: Vocode.ActionConfig; +} diff --git a/src/api/types/DtmfActionParams.ts b/src/api/types/DtmfActionParams.ts new file mode 100644 index 0000000..2425510 --- /dev/null +++ b/src/api/types/DtmfActionParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface DtmfActionParams { + type: Vocode.ActionType; + config?: Vocode.ActionConfig; +} diff --git a/src/api/types/DtmfActionUpdateParams.ts b/src/api/types/DtmfActionUpdateParams.ts new file mode 100644 index 0000000..065c2e1 --- /dev/null +++ b/src/api/types/DtmfActionUpdateParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface DtmfActionUpdateParams { + type: Vocode.ActionType; + config?: Vocode.DtmfActionUpdateParamsConfig; +} diff --git a/src/api/types/DtmfActionUpdateParamsConfig.ts b/src/api/types/DtmfActionUpdateParamsConfig.ts new file mode 100644 index 0000000..69e36ce --- /dev/null +++ b/src/api/types/DtmfActionUpdateParamsConfig.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type DtmfActionUpdateParamsConfig = Vocode.ActionConfig | Vocode.Undefined; diff --git a/src/api/types/ElevenLabsVoice.ts b/src/api/types/ElevenLabsVoice.ts new file mode 100644 index 0000000..d13db5d --- /dev/null +++ b/src/api/types/ElevenLabsVoice.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface ElevenLabsVoice { + id: string; + userId: string; + type?: Vocode.VoiceType; + voiceId: string; + stability?: number; + similarityBoost?: number; + apiKey: string; +} diff --git a/src/api/types/ElevenLabsVoiceParams.ts b/src/api/types/ElevenLabsVoiceParams.ts new file mode 100644 index 0000000..3dff2c4 --- /dev/null +++ b/src/api/types/ElevenLabsVoiceParams.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface ElevenLabsVoiceParams { + type: Vocode.VoiceType; + voiceId: string; + stability?: number; + similarityBoost?: number; + apiKey: string; +} diff --git a/src/api/types/ElevenLabsVoiceUpdateParams.ts b/src/api/types/ElevenLabsVoiceUpdateParams.ts new file mode 100644 index 0000000..9ca7750 --- /dev/null +++ b/src/api/types/ElevenLabsVoiceUpdateParams.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface ElevenLabsVoiceUpdateParams { + type: Vocode.VoiceType; + voiceId?: Vocode.ElevenLabsVoiceUpdateParamsVoiceId; + stability?: Vocode.ElevenLabsVoiceUpdateParamsStability; + similarityBoost?: Vocode.ElevenLabsVoiceUpdateParamsSimilarityBoost; + apiKey?: Vocode.ElevenLabsVoiceUpdateParamsApiKey; +} diff --git a/src/api/types/ElevenLabsVoiceUpdateParamsApiKey.ts b/src/api/types/ElevenLabsVoiceUpdateParamsApiKey.ts new file mode 100644 index 0000000..5ebbef3 --- /dev/null +++ b/src/api/types/ElevenLabsVoiceUpdateParamsApiKey.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ElevenLabsVoiceUpdateParamsApiKey = string | Vocode.Undefined; diff --git a/src/api/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts b/src/api/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts new file mode 100644 index 0000000..492d337 --- /dev/null +++ b/src/api/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ElevenLabsVoiceUpdateParamsSimilarityBoost = number | Vocode.Undefined; diff --git a/src/api/types/ElevenLabsVoiceUpdateParamsStability.ts b/src/api/types/ElevenLabsVoiceUpdateParamsStability.ts new file mode 100644 index 0000000..25aa28e --- /dev/null +++ b/src/api/types/ElevenLabsVoiceUpdateParamsStability.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ElevenLabsVoiceUpdateParamsStability = number | Vocode.Undefined; diff --git a/src/api/types/ElevenLabsVoiceUpdateParamsVoiceId.ts b/src/api/types/ElevenLabsVoiceUpdateParamsVoiceId.ts new file mode 100644 index 0000000..ded2f0e --- /dev/null +++ b/src/api/types/ElevenLabsVoiceUpdateParamsVoiceId.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ElevenLabsVoiceUpdateParamsVoiceId = string | Vocode.Undefined; diff --git a/src/api/types/EndConversationAction.ts b/src/api/types/EndConversationAction.ts new file mode 100644 index 0000000..6a80def --- /dev/null +++ b/src/api/types/EndConversationAction.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface EndConversationAction { + id: string; + userId: string; + type?: Vocode.ActionType; + config?: Vocode.ActionConfig; +} diff --git a/src/api/types/EndConversationActionParams.ts b/src/api/types/EndConversationActionParams.ts new file mode 100644 index 0000000..395a3b5 --- /dev/null +++ b/src/api/types/EndConversationActionParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface EndConversationActionParams { + type: Vocode.ActionType; + config?: Vocode.ActionConfig; +} diff --git a/src/api/types/EndConversationActionUpdateParams.ts b/src/api/types/EndConversationActionUpdateParams.ts new file mode 100644 index 0000000..e7dee29 --- /dev/null +++ b/src/api/types/EndConversationActionUpdateParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface EndConversationActionUpdateParams { + type: Vocode.ActionType; + config?: Vocode.EndConversationActionUpdateParamsConfig; +} diff --git a/src/api/types/EndConversationActionUpdateParamsConfig.ts b/src/api/types/EndConversationActionUpdateParamsConfig.ts new file mode 100644 index 0000000..034ca63 --- /dev/null +++ b/src/api/types/EndConversationActionUpdateParamsConfig.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type EndConversationActionUpdateParamsConfig = Vocode.ActionConfig | Vocode.Undefined; diff --git a/src/api/types/EventType.ts b/src/api/types/EventType.ts new file mode 100644 index 0000000..aa6f023 --- /dev/null +++ b/src/api/types/EventType.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type EventType = + | "event_message" + | "event_action" + | "event_phone_call_connected" + | "event_phone_call_ended" + | "event_transcript" + | "event_recording"; + +export const EventType = { + EventMessage: "event_message", + EventAction: "event_action", + EventPhoneCallConnected: "event_phone_call_connected", + EventPhoneCallEnded: "event_phone_call_ended", + EventTranscript: "event_transcript", + EventRecording: "event_recording", +} as const; diff --git a/src/api/types/GetActionResponse.ts b/src/api/types/GetActionResponse.ts new file mode 100644 index 0000000..9dcdd40 --- /dev/null +++ b/src/api/types/GetActionResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type GetActionResponse = Vocode.EndConversationAction | Vocode.DtmfAction; diff --git a/src/api/types/GetVoiceResponse.ts b/src/api/types/GetVoiceResponse.ts new file mode 100644 index 0000000..f2f9c32 --- /dev/null +++ b/src/api/types/GetVoiceResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type GetVoiceResponse = Vocode.AzureVoice | Vocode.RimeVoice | Vocode.ElevenLabsVoice; diff --git a/src/api/types/HttpMethod.ts b/src/api/types/HttpMethod.ts new file mode 100644 index 0000000..8f48d60 --- /dev/null +++ b/src/api/types/HttpMethod.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type HttpMethod = "GET" | "POST"; + +export const HttpMethod = { + Get: "GET", + Post: "POST", +} as const; diff --git a/src/api/types/HttpValidationError.ts b/src/api/types/HttpValidationError.ts new file mode 100644 index 0000000..7c2f587 --- /dev/null +++ b/src/api/types/HttpValidationError.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface HttpValidationError { + detail?: Vocode.ValidationError[]; +} diff --git a/src/api/types/ListActionsResponseItem.ts b/src/api/types/ListActionsResponseItem.ts new file mode 100644 index 0000000..0335978 --- /dev/null +++ b/src/api/types/ListActionsResponseItem.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ListActionsResponseItem = Vocode.EndConversationAction | Vocode.DtmfAction; diff --git a/src/api/types/ListVoicesResponseItem.ts b/src/api/types/ListVoicesResponseItem.ts new file mode 100644 index 0000000..eb8fcb0 --- /dev/null +++ b/src/api/types/ListVoicesResponseItem.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type ListVoicesResponseItem = Vocode.AzureVoice | Vocode.RimeVoice | Vocode.ElevenLabsVoice; diff --git a/src/api/types/PhoneNumber.ts b/src/api/types/PhoneNumber.ts new file mode 100644 index 0000000..1aba551 --- /dev/null +++ b/src/api/types/PhoneNumber.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface PhoneNumber { + id: string; + userId: string; + number: string; + active: boolean; + inboundAgent: Vocode.PhoneNumberInboundAgent; +} diff --git a/src/api/types/PhoneNumberInboundAgent.ts b/src/api/types/PhoneNumberInboundAgent.ts new file mode 100644 index 0000000..a655a46 --- /dev/null +++ b/src/api/types/PhoneNumberInboundAgent.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type PhoneNumberInboundAgent = string | Vocode.Agent; diff --git a/src/api/types/PlanType.ts b/src/api/types/PlanType.ts new file mode 100644 index 0000000..229a347 --- /dev/null +++ b/src/api/types/PlanType.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type PlanType = "free" | "developer" | "enterprise"; + +export const PlanType = { + Free: "free", + Developer: "developer", + Enterprise: "enterprise", +} as const; diff --git a/src/api/types/RimeVoice.ts b/src/api/types/RimeVoice.ts new file mode 100644 index 0000000..b39d3e3 --- /dev/null +++ b/src/api/types/RimeVoice.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface RimeVoice { + id: string; + userId: string; + type?: Vocode.VoiceType; + speaker: string; +} diff --git a/src/api/types/RimeVoiceParams.ts b/src/api/types/RimeVoiceParams.ts new file mode 100644 index 0000000..1c0bfb6 --- /dev/null +++ b/src/api/types/RimeVoiceParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface RimeVoiceParams { + type: Vocode.VoiceType; + speaker: string; +} diff --git a/src/api/types/RimeVoiceUpdateParams.ts b/src/api/types/RimeVoiceUpdateParams.ts new file mode 100644 index 0000000..9b5bf63 --- /dev/null +++ b/src/api/types/RimeVoiceUpdateParams.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface RimeVoiceUpdateParams { + type: Vocode.VoiceType; + speaker?: Vocode.RimeVoiceUpdateParamsSpeaker; +} diff --git a/src/api/types/RimeVoiceUpdateParamsSpeaker.ts b/src/api/types/RimeVoiceUpdateParamsSpeaker.ts new file mode 100644 index 0000000..2e901a1 --- /dev/null +++ b/src/api/types/RimeVoiceUpdateParamsSpeaker.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type RimeVoiceUpdateParamsSpeaker = string | Vocode.Undefined; diff --git a/src/api/types/Undefined.ts b/src/api/types/Undefined.ts new file mode 100644 index 0000000..95d7f41 --- /dev/null +++ b/src/api/types/Undefined.ts @@ -0,0 +1,5 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface Undefined {} diff --git a/src/api/types/UpdateActionRequestBody.ts b/src/api/types/UpdateActionRequestBody.ts new file mode 100644 index 0000000..664bb4a --- /dev/null +++ b/src/api/types/UpdateActionRequestBody.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type UpdateActionRequestBody = Vocode.EndConversationActionUpdateParams | Vocode.DtmfActionUpdateParams; diff --git a/src/api/types/UpdateActionResponse.ts b/src/api/types/UpdateActionResponse.ts new file mode 100644 index 0000000..3c87f5a --- /dev/null +++ b/src/api/types/UpdateActionResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type UpdateActionResponse = Vocode.EndConversationAction | Vocode.DtmfAction; diff --git a/src/api/types/UpdateNumberRequestInboundAgent.ts b/src/api/types/UpdateNumberRequestInboundAgent.ts new file mode 100644 index 0000000..3bb3d13 --- /dev/null +++ b/src/api/types/UpdateNumberRequestInboundAgent.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type UpdateNumberRequestInboundAgent = string | Vocode.AgentUpdateParams; diff --git a/src/api/types/UpdateVoiceRequestBody.ts b/src/api/types/UpdateVoiceRequestBody.ts new file mode 100644 index 0000000..d105578 --- /dev/null +++ b/src/api/types/UpdateVoiceRequestBody.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type UpdateVoiceRequestBody = + | Vocode.AzureVoiceUpdateParams + | Vocode.RimeVoiceUpdateParams + | Vocode.ElevenLabsVoiceUpdateParams; diff --git a/src/api/types/UpdateVoiceResponse.ts b/src/api/types/UpdateVoiceResponse.ts new file mode 100644 index 0000000..50d64bc --- /dev/null +++ b/src/api/types/UpdateVoiceResponse.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type UpdateVoiceResponse = Vocode.AzureVoice | Vocode.RimeVoice | Vocode.ElevenLabsVoice; diff --git a/src/api/types/Usage.ts b/src/api/types/Usage.ts new file mode 100644 index 0000000..4be1ca6 --- /dev/null +++ b/src/api/types/Usage.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface Usage { + userId: string; + planType: Vocode.PlanType; + monthlyUsageMinutes: number; + monthlyUsageLimitMinutes: number; +} diff --git a/src/api/types/ValidationError.ts b/src/api/types/ValidationError.ts new file mode 100644 index 0000000..35a6455 --- /dev/null +++ b/src/api/types/ValidationError.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface ValidationError { + loc: Vocode.ValidationErrorLocItem[]; + msg: string; + type: string; +} diff --git a/src/api/types/ValidationErrorLocItem.ts b/src/api/types/ValidationErrorLocItem.ts new file mode 100644 index 0000000..c97f7db --- /dev/null +++ b/src/api/types/ValidationErrorLocItem.ts @@ -0,0 +1,5 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type ValidationErrorLocItem = string | number; diff --git a/src/api/types/VoiceType.ts b/src/api/types/VoiceType.ts new file mode 100644 index 0000000..990b142 --- /dev/null +++ b/src/api/types/VoiceType.ts @@ -0,0 +1,15 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * An enumeration. + */ +export type VoiceType = "voice_base" | "voice_azure" | "voice_rime" | "voice_eleven_labs"; + +export const VoiceType = { + VoiceBase: "voice_base", + VoiceAzure: "voice_azure", + VoiceRime: "voice_rime", + VoiceElevenLabs: "voice_eleven_labs", +} as const; diff --git a/src/api/types/Webhook.ts b/src/api/types/Webhook.ts new file mode 100644 index 0000000..151bcf8 --- /dev/null +++ b/src/api/types/Webhook.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface Webhook { + id: string; + userId: string; + subscriptions: Vocode.EventType[]; + url: string; + method?: Vocode.HttpMethod; +} diff --git a/src/api/types/WebhookParams.ts b/src/api/types/WebhookParams.ts new file mode 100644 index 0000000..3011e70 --- /dev/null +++ b/src/api/types/WebhookParams.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface WebhookParams { + subscriptions: Vocode.EventType[]; + url: string; + method?: Vocode.HttpMethod; +} diff --git a/src/api/types/WebhookUpdateParams.ts b/src/api/types/WebhookUpdateParams.ts new file mode 100644 index 0000000..4fecb6d --- /dev/null +++ b/src/api/types/WebhookUpdateParams.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export interface WebhookUpdateParams { + subscriptions?: Vocode.WebhookUpdateParamsSubscriptions; + url?: Vocode.WebhookUpdateParamsUrl; + method?: Vocode.WebhookUpdateParamsMethod; +} diff --git a/src/api/types/WebhookUpdateParamsMethod.ts b/src/api/types/WebhookUpdateParamsMethod.ts new file mode 100644 index 0000000..be111e6 --- /dev/null +++ b/src/api/types/WebhookUpdateParamsMethod.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type WebhookUpdateParamsMethod = Vocode.HttpMethod | Vocode.Undefined; diff --git a/src/api/types/WebhookUpdateParamsSubscriptions.ts b/src/api/types/WebhookUpdateParamsSubscriptions.ts new file mode 100644 index 0000000..921a115 --- /dev/null +++ b/src/api/types/WebhookUpdateParamsSubscriptions.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type WebhookUpdateParamsSubscriptions = Vocode.EventType[] | Vocode.Undefined; diff --git a/src/api/types/WebhookUpdateParamsUrl.ts b/src/api/types/WebhookUpdateParamsUrl.ts new file mode 100644 index 0000000..38595ae --- /dev/null +++ b/src/api/types/WebhookUpdateParamsUrl.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Vocode from ".."; + +export type WebhookUpdateParamsUrl = string | Vocode.Undefined; diff --git a/src/api/types/index.ts b/src/api/types/index.ts new file mode 100644 index 0000000..0752b59 --- /dev/null +++ b/src/api/types/index.ts @@ -0,0 +1,76 @@ +export * from "./UpdateNumberRequestInboundAgent"; +export * from "./CreateCallRequestAgent"; +export * from "./GetActionResponse"; +export * from "./ListActionsResponseItem"; +export * from "./CreateActionRequest"; +export * from "./CreateActionResponse"; +export * from "./UpdateActionRequestBody"; +export * from "./UpdateActionResponse"; +export * from "./AgentParams"; +export * from "./AgentParamsActionsItem"; +export * from "./AgentParamsVoice"; +export * from "./AgentParamsWebhook"; +export * from "./AgentUpdateParams"; +export * from "./AgentUpdateParamsPrompt"; +export * from "./AgentUpdateParamsActions"; +export * from "./AgentUpdateParamsActionsAgentUpdateParamsActionsItem"; +export * from "./AgentUpdateParamsVoice"; +export * from "./AgentUpdateParamsInitialMessage"; +export * from "./AgentUpdateParamsWebhook"; +export * from "./GetVoiceResponse"; +export * from "./ListVoicesResponseItem"; +export * from "./CreateVoiceRequest"; +export * from "./CreateVoiceResponse"; +export * from "./UpdateVoiceRequestBody"; +export * from "./UpdateVoiceResponse"; +export * from "./WebhookParams"; +export * from "./WebhookUpdateParams"; +export * from "./WebhookUpdateParamsSubscriptions"; +export * from "./WebhookUpdateParamsUrl"; +export * from "./WebhookUpdateParamsMethod"; +export * from "./ActionConfig"; +export * from "./ActionType"; +export * from "./Agent"; +export * from "./AgentActionsItem"; +export * from "./AgentVoice"; +export * from "./AgentWebhook"; +export * from "./AzureVoice"; +export * from "./AzureVoiceParams"; +export * from "./AzureVoiceUpdateParams"; +export * from "./AzureVoiceUpdateParamsVoiceName"; +export * from "./AzureVoiceUpdateParamsPitch"; +export * from "./AzureVoiceUpdateParamsRate"; +export * from "./Call"; +export * from "./CallAgent"; +export * from "./CallStatus"; +export * from "./DtmfAction"; +export * from "./DtmfActionParams"; +export * from "./DtmfActionUpdateParams"; +export * from "./DtmfActionUpdateParamsConfig"; +export * from "./ElevenLabsVoice"; +export * from "./ElevenLabsVoiceParams"; +export * from "./ElevenLabsVoiceUpdateParams"; +export * from "./ElevenLabsVoiceUpdateParamsVoiceId"; +export * from "./ElevenLabsVoiceUpdateParamsStability"; +export * from "./ElevenLabsVoiceUpdateParamsSimilarityBoost"; +export * from "./ElevenLabsVoiceUpdateParamsApiKey"; +export * from "./EndConversationAction"; +export * from "./EndConversationActionParams"; +export * from "./EndConversationActionUpdateParams"; +export * from "./EndConversationActionUpdateParamsConfig"; +export * from "./EventType"; +export * from "./HttpMethod"; +export * from "./HttpValidationError"; +export * from "./PhoneNumber"; +export * from "./PhoneNumberInboundAgent"; +export * from "./PlanType"; +export * from "./RimeVoice"; +export * from "./RimeVoiceParams"; +export * from "./RimeVoiceUpdateParams"; +export * from "./RimeVoiceUpdateParamsSpeaker"; +export * from "./Undefined"; +export * from "./Usage"; +export * from "./ValidationError"; +export * from "./ValidationErrorLocItem"; +export * from "./VoiceType"; +export * from "./Webhook"; diff --git a/src/core/auth/BasicAuth.ts b/src/core/auth/BasicAuth.ts new file mode 100644 index 0000000..146df21 --- /dev/null +++ b/src/core/auth/BasicAuth.ts @@ -0,0 +1,31 @@ +import { Base64 } from "js-base64"; + +export interface BasicAuth { + username: string; + password: string; +} + +const BASIC_AUTH_HEADER_PREFIX = /^Basic /i; + +export const BasicAuth = { + toAuthorizationHeader: (basicAuth: BasicAuth | undefined): string | undefined => { + if (basicAuth == null) { + return undefined; + } + const token = Base64.encode(`${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 [username, password] = decoded.split(":", 2); + + if (username == null || password == null) { + throw new Error("Invalid basic auth"); + } + return { + username, + password, + }; + }, +}; diff --git a/src/core/auth/BearerToken.ts b/src/core/auth/BearerToken.ts new file mode 100644 index 0000000..fe987fc --- /dev/null +++ b/src/core/auth/BearerToken.ts @@ -0,0 +1,15 @@ +export type BearerToken = string; + +const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i; + +export const BearerToken = { + toAuthorizationHeader: (token: BearerToken | undefined): string | undefined => { + if (token == null) { + return undefined; + } + return `Bearer ${token}`; + }, + fromAuthorizationHeader: (header: string): BearerToken => { + return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim() as BearerToken; + }, +}; diff --git a/src/core/auth/index.ts b/src/core/auth/index.ts new file mode 100644 index 0000000..ee293b3 --- /dev/null +++ b/src/core/auth/index.ts @@ -0,0 +1,2 @@ +export { BasicAuth } from "./BasicAuth"; +export { BearerToken } from "./BearerToken"; diff --git a/src/core/fetcher/APIResponse.ts b/src/core/fetcher/APIResponse.ts new file mode 100644 index 0000000..ea838f3 --- /dev/null +++ b/src/core/fetcher/APIResponse.ts @@ -0,0 +1,11 @@ +export type APIResponse = SuccessfulResponse | FailedResponse; + +export interface SuccessfulResponse { + ok: true; + body: T; +} + +export interface FailedResponse { + ok: false; + error: T; +} diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts new file mode 100644 index 0000000..5fe7195 --- /dev/null +++ b/src/core/fetcher/Fetcher.ts @@ -0,0 +1,134 @@ +import { default as URLSearchParams } from "@ungap/url-search-params"; +import axios, { AxiosAdapter, AxiosError, AxiosProgressEvent } from "axios"; +import { APIResponse } from "./APIResponse"; + +export type FetchFunction = (args: Fetcher.Args) => Promise>; + +export declare namespace Fetcher { + export interface Args { + url: string; + method: string; + contentType?: string; + headers?: Record; + queryParameters?: URLSearchParams; + body?: unknown; + timeoutMs?: number; + withCredentials?: boolean; + responseType?: "json" | "blob"; + adapter?: AxiosAdapter; + onUploadProgress?: (event: AxiosProgressEvent) => void; + } + + export type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError; + + export interface FailedStatusCodeError { + reason: "status-code"; + statusCode: number; + body: unknown; + } + + export interface NonJsonError { + reason: "non-json"; + statusCode: number; + rawBody: string; + } + + export interface TimeoutError { + reason: "timeout"; + } + + export interface UnknownError { + reason: "unknown"; + errorMessage: string; + } +} + +async function fetcherImpl(args: Fetcher.Args): Promise> { + const headers: Record = {}; + if (args.body !== undefined && args.contentType != null) { + headers["Content-Type"] = args.contentType; + } + + if (args.headers != null) { + for (const [key, value] of Object.entries(args.headers)) { + if (value != null) { + headers[key] = value; + } + } + } + + try { + const response = await axios({ + url: args.url, + params: args.queryParameters, + method: args.method, + headers, + data: args.body, + validateStatus: () => true, + transformResponse: (response) => response, + timeout: args.timeoutMs, + transitional: { + clarifyTimeoutError: true, + }, + withCredentials: args.withCredentials, + adapter: args.adapter, + onUploadProgress: args.onUploadProgress, + maxBodyLength: Infinity, + maxContentLength: Infinity, + responseType: args.responseType ?? "json", + }); + + let body: unknown; + if (args.responseType === "blob") { + body = response.data; + } else if (response.data != null && response.data.length > 0) { + try { + body = JSON.parse(response.data) ?? undefined; + } catch { + return { + ok: false, + error: { + reason: "non-json", + statusCode: response.status, + rawBody: response.data, + }, + }; + } + } + + if (response.status >= 200 && response.status < 400) { + return { + ok: true, + body: body as R, + }; + } else { + return { + ok: false, + error: { + reason: "status-code", + statusCode: response.status, + body, + }, + }; + } + } catch (error) { + if ((error as AxiosError).code === "ETIMEDOUT") { + return { + ok: false, + error: { + reason: "timeout", + }, + }; + } + + return { + ok: false, + error: { + reason: "unknown", + errorMessage: (error as AxiosError).message, + }, + }; + } +} + +export const fetcher: FetchFunction = fetcherImpl; diff --git a/src/core/fetcher/Supplier.ts b/src/core/fetcher/Supplier.ts new file mode 100644 index 0000000..867c931 --- /dev/null +++ b/src/core/fetcher/Supplier.ts @@ -0,0 +1,11 @@ +export type Supplier = T | Promise | (() => T | Promise); + +export const Supplier = { + get: async (supplier: Supplier): Promise => { + if (typeof supplier === "function") { + return (supplier as () => T)(); + } else { + return supplier; + } + }, +}; diff --git a/src/core/fetcher/index.ts b/src/core/fetcher/index.ts new file mode 100644 index 0000000..6becab2 --- /dev/null +++ b/src/core/fetcher/index.ts @@ -0,0 +1,4 @@ +export type { APIResponse } from "./APIResponse"; +export { fetcher } from "./Fetcher"; +export type { Fetcher, FetchFunction } from "./Fetcher"; +export { Supplier } from "./Supplier"; diff --git a/src/core/index.ts b/src/core/index.ts new file mode 100644 index 0000000..82528c9 --- /dev/null +++ b/src/core/index.ts @@ -0,0 +1,3 @@ +export * as serialization from "./schemas"; +export * from "./fetcher"; +export * from "./auth"; diff --git a/src/core/schemas/Schema.ts b/src/core/schemas/Schema.ts new file mode 100644 index 0000000..3211fa4 --- /dev/null +++ b/src/core/schemas/Schema.ts @@ -0,0 +1,93 @@ +import { SchemaUtils } from "./builders"; +import { MaybePromise } from "./utils/MaybePromise"; + +export type Schema = BaseSchema & SchemaUtils; + +export type inferRaw = S extends Schema ? Raw : never; +export type inferParsed = S extends Schema ? Parsed : never; + +export interface BaseSchema { + parse: (raw: unknown, opts?: SchemaOptions) => MaybePromise>; + json: (parsed: unknown, opts?: SchemaOptions) => MaybePromise>; + getType: () => SchemaType | Promise; +} + +export const SchemaType = { + DATE: "date", + ENUM: "enum", + LIST: "list", + STRING_LITERAL: "stringLiteral", + OBJECT: "object", + ANY: "any", + BOOLEAN: "boolean", + NUMBER: "number", + STRING: "string", + UNKNOWN: "unknown", + RECORD: "record", + SET: "set", + UNION: "union", + UNDISCRIMINATED_UNION: "undiscriminatedUnion", + OPTIONAL: "optional", +} as const; +export type SchemaType = typeof SchemaType[keyof typeof SchemaType]; + +export type MaybeValid = Valid | Invalid; + +export interface Valid { + ok: true; + value: T; +} + +export interface Invalid { + ok: false; + errors: ValidationError[]; +} + +export interface ValidationError { + path: string[]; + message: string; +} + +export interface SchemaOptions { + /** + * how to handle unrecognized keys in objects + * + * @default "fail" + */ + unrecognizedObjectKeys?: "fail" | "passthrough" | "strip"; + + /** + * whether to fail when an unrecognized discriminant value is + * encountered in a union + * + * @default false + */ + allowUnrecognizedUnionMembers?: boolean; + + /** + * whether to fail when an unrecognized enum value is encountered + * + * @default false + */ + allowUnrecognizedEnumValues?: boolean; + + /** + * whether to allow data that doesn't conform to the schema. + * invalid data is passed through without transformation. + * + * when this is enabled, .parse() and .json() will always + * return `ok: true`. `.parseOrThrow()` and `.jsonOrThrow()` + * will never fail. + * + * @default false + */ + skipValidation?: boolean; + + /** + * each validation failure contains a "path" property, which is + * the breadcrumbs to the offending node in the JSON. you can supply + * a prefix that is prepended to all the errors' paths. this can be + * helpful for zurg's internal debug logging. + */ + breadcrumbsPrefix?: string[]; +} diff --git a/src/core/schemas/builders/date/date.ts b/src/core/schemas/builders/date/date.ts new file mode 100644 index 0000000..b70f24b --- /dev/null +++ b/src/core/schemas/builders/date/date.ts @@ -0,0 +1,65 @@ +import { BaseSchema, Schema, SchemaType } from "../../Schema"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { getSchemaUtils } from "../schema-utils"; + +// https://stackoverflow.com/questions/12756159/regex-and-iso8601-formatted-datetime +const ISO_8601_REGEX = + /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; + +export function date(): Schema { + const baseSchema: BaseSchema = { + parse: (raw, { breadcrumbsPrefix = [] } = {}) => { + if (typeof raw !== "string") { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(raw, "string"), + }, + ], + }; + } + if (!ISO_8601_REGEX.test(raw)) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(raw, "ISO 8601 date string"), + }, + ], + }; + } + return { + ok: true, + value: new Date(raw), + }; + }, + json: (date, { breadcrumbsPrefix = [] } = {}) => { + if (date instanceof Date) { + return { + ok: true, + value: date.toISOString(), + }; + } else { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(date, "Date object"), + }, + ], + }; + } + }, + getType: () => SchemaType.DATE, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; +} diff --git a/src/core/schemas/builders/date/index.ts b/src/core/schemas/builders/date/index.ts new file mode 100644 index 0000000..187b290 --- /dev/null +++ b/src/core/schemas/builders/date/index.ts @@ -0,0 +1 @@ +export { date } from "./date"; diff --git a/src/core/schemas/builders/enum/enum.ts b/src/core/schemas/builders/enum/enum.ts new file mode 100644 index 0000000..c1e24d6 --- /dev/null +++ b/src/core/schemas/builders/enum/enum.ts @@ -0,0 +1,43 @@ +import { Schema, SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; + +export function enum_(values: E): Schema { + const validValues = new Set(values); + + const schemaCreator = createIdentitySchemaCreator( + SchemaType.ENUM, + (value, { allowUnrecognizedEnumValues, breadcrumbsPrefix = [] } = {}) => { + if (typeof value !== "string") { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "string"), + }, + ], + }; + } + + if (!validValues.has(value) && !allowUnrecognizedEnumValues) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "enum"), + }, + ], + }; + } + + return { + ok: true, + value: value as U, + }; + } + ); + + return schemaCreator(); +} diff --git a/src/core/schemas/builders/enum/index.ts b/src/core/schemas/builders/enum/index.ts new file mode 100644 index 0000000..fe6faed --- /dev/null +++ b/src/core/schemas/builders/enum/index.ts @@ -0,0 +1 @@ +export { enum_ } from "./enum"; diff --git a/src/core/schemas/builders/index.ts b/src/core/schemas/builders/index.ts new file mode 100644 index 0000000..050cd2c --- /dev/null +++ b/src/core/schemas/builders/index.ts @@ -0,0 +1,13 @@ +export * from "./date"; +export * from "./enum"; +export * from "./lazy"; +export * from "./list"; +export * from "./literals"; +export * from "./object"; +export * from "./object-like"; +export * from "./primitives"; +export * from "./record"; +export * from "./schema-utils"; +export * from "./set"; +export * from "./undiscriminated-union"; +export * from "./union"; diff --git a/src/core/schemas/builders/lazy/index.ts b/src/core/schemas/builders/lazy/index.ts new file mode 100644 index 0000000..77420fb --- /dev/null +++ b/src/core/schemas/builders/lazy/index.ts @@ -0,0 +1,3 @@ +export { lazy } from "./lazy"; +export type { SchemaGetter } from "./lazy"; +export { lazyObject } from "./lazyObject"; diff --git a/src/core/schemas/builders/lazy/lazy.ts b/src/core/schemas/builders/lazy/lazy.ts new file mode 100644 index 0000000..a665472 --- /dev/null +++ b/src/core/schemas/builders/lazy/lazy.ts @@ -0,0 +1,34 @@ +import { BaseSchema, Schema } from "../../Schema"; +import { getSchemaUtils } from "../schema-utils"; + +export type SchemaGetter> = () => SchemaType | Promise; + +export function lazy(getter: SchemaGetter>): Schema { + const baseSchema = constructLazyBaseSchema(getter); + return { + ...baseSchema, + ...getSchemaUtils(baseSchema), + }; +} + +export function constructLazyBaseSchema( + getter: SchemaGetter> +): BaseSchema { + return { + parse: async (raw, opts) => (await getMemoizedSchema(getter)).parse(raw, opts), + json: async (parsed, opts) => (await getMemoizedSchema(getter)).json(parsed, opts), + getType: async () => (await getMemoizedSchema(getter)).getType(), + }; +} + +type MemoizedGetter> = SchemaGetter & { __zurg_memoized?: SchemaType }; + +export async function getMemoizedSchema>( + getter: SchemaGetter +): Promise { + const castedGetter = getter as MemoizedGetter; + if (castedGetter.__zurg_memoized == null) { + castedGetter.__zurg_memoized = await getter(); + } + return castedGetter.__zurg_memoized; +} diff --git a/src/core/schemas/builders/lazy/lazyObject.ts b/src/core/schemas/builders/lazy/lazyObject.ts new file mode 100644 index 0000000..e48c016 --- /dev/null +++ b/src/core/schemas/builders/lazy/lazyObject.ts @@ -0,0 +1,20 @@ +import { getObjectUtils } from "../object"; +import { getObjectLikeUtils } from "../object-like"; +import { BaseObjectSchema, ObjectSchema } from "../object/types"; +import { getSchemaUtils } from "../schema-utils"; +import { constructLazyBaseSchema, getMemoizedSchema, SchemaGetter } from "./lazy"; + +export function lazyObject(getter: SchemaGetter>): ObjectSchema { + const baseSchema: BaseObjectSchema = { + ...constructLazyBaseSchema(getter), + _getRawProperties: async () => (await getMemoizedSchema(getter))._getRawProperties(), + _getParsedProperties: async () => (await getMemoizedSchema(getter))._getParsedProperties(), + }; + + return { + ...baseSchema, + ...getSchemaUtils(baseSchema), + ...getObjectLikeUtils(baseSchema), + ...getObjectUtils(baseSchema), + }; +} diff --git a/src/core/schemas/builders/list/index.ts b/src/core/schemas/builders/list/index.ts new file mode 100644 index 0000000..25f4bcc --- /dev/null +++ b/src/core/schemas/builders/list/index.ts @@ -0,0 +1 @@ +export { list } from "./list"; diff --git a/src/core/schemas/builders/list/list.ts b/src/core/schemas/builders/list/list.ts new file mode 100644 index 0000000..b333321 --- /dev/null +++ b/src/core/schemas/builders/list/list.ts @@ -0,0 +1,74 @@ +import { BaseSchema, MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { MaybePromise } from "../../utils/MaybePromise"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { getSchemaUtils } from "../schema-utils"; + +export function list(schema: Schema): Schema { + const baseSchema: BaseSchema = { + parse: async (raw, opts) => + validateAndTransformArray(raw, (item, index) => + schema.parse(item, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `[${index}]`], + }) + ), + json: (parsed, opts) => + validateAndTransformArray(parsed, (item, index) => + schema.json(item, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `[${index}]`], + }) + ), + getType: () => SchemaType.LIST, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; +} + +async function validateAndTransformArray( + value: unknown, + transformItem: (item: Raw, index: number) => MaybePromise> +): Promise> { + if (!Array.isArray(value)) { + return { + ok: false, + errors: [ + { + message: getErrorMessageForIncorrectType(value, "list"), + path: [], + }, + ], + }; + } + + const maybeValidItems = await Promise.all(value.map((item, index) => transformItem(item, index))); + + return maybeValidItems.reduce>( + (acc, item) => { + if (acc.ok && item.ok) { + return { + ok: true, + value: [...acc.value, item.value], + }; + } + + const errors: ValidationError[] = []; + if (!acc.ok) { + errors.push(...acc.errors); + } + if (!item.ok) { + errors.push(...item.errors); + } + + return { + ok: false, + errors, + }; + }, + { ok: true, value: [] } + ); +} diff --git a/src/core/schemas/builders/literals/index.ts b/src/core/schemas/builders/literals/index.ts new file mode 100644 index 0000000..a4cd05c --- /dev/null +++ b/src/core/schemas/builders/literals/index.ts @@ -0,0 +1 @@ +export { stringLiteral } from "./stringLiteral"; diff --git a/src/core/schemas/builders/literals/stringLiteral.ts b/src/core/schemas/builders/literals/stringLiteral.ts new file mode 100644 index 0000000..3939b76 --- /dev/null +++ b/src/core/schemas/builders/literals/stringLiteral.ts @@ -0,0 +1,29 @@ +import { Schema, SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; + +export function stringLiteral(literal: V): Schema { + const schemaCreator = createIdentitySchemaCreator( + SchemaType.STRING_LITERAL, + (value, { breadcrumbsPrefix = [] } = {}) => { + if (value === literal) { + return { + ok: true, + value: literal, + }; + } else { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, `"${literal}"`), + }, + ], + }; + } + } + ); + + return schemaCreator(); +} diff --git a/src/core/schemas/builders/object-like/getObjectLikeUtils.ts b/src/core/schemas/builders/object-like/getObjectLikeUtils.ts new file mode 100644 index 0000000..270ea17 --- /dev/null +++ b/src/core/schemas/builders/object-like/getObjectLikeUtils.ts @@ -0,0 +1,79 @@ +import { BaseSchema } from "../../Schema"; +import { filterObject } from "../../utils/filterObject"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { isPlainObject } from "../../utils/isPlainObject"; +import { getSchemaUtils } from "../schema-utils"; +import { ObjectLikeSchema, ObjectLikeUtils } from "./types"; + +export function getObjectLikeUtils(schema: BaseSchema): ObjectLikeUtils { + return { + withParsedProperties: (properties) => withParsedProperties(schema, properties), + }; +} + +/** + * object-like utils are defined in one file to resolve issues with circular imports + */ + +export function withParsedProperties( + objectLike: BaseSchema, + properties: { [K in keyof Properties]: Properties[K] | ((parsed: ParsedObjectShape) => Properties[K]) } +): ObjectLikeSchema { + const objectSchema: BaseSchema = { + parse: async (raw, opts) => { + const parsedObject = await objectLike.parse(raw, opts); + if (!parsedObject.ok) { + return parsedObject; + } + + const additionalProperties = Object.entries(properties).reduce>( + (processed, [key, value]) => { + return { + ...processed, + [key]: typeof value === "function" ? value(parsedObject.value) : value, + }; + }, + {} + ); + + return { + ok: true, + value: { + ...parsedObject.value, + ...(additionalProperties as Properties), + }, + }; + }, + + json: (parsed, opts) => { + if (!isPlainObject(parsed)) { + return { + ok: false, + errors: [ + { + path: opts?.breadcrumbsPrefix ?? [], + message: getErrorMessageForIncorrectType(parsed, "object"), + }, + ], + }; + } + + // strip out added properties + const addedPropertyKeys = new Set(Object.keys(properties)); + const parsedWithoutAddedProperties = filterObject( + parsed, + Object.keys(parsed).filter((key) => !addedPropertyKeys.has(key)) + ); + + return objectLike.json(parsedWithoutAddedProperties as ParsedObjectShape, opts); + }, + + getType: () => objectLike.getType(), + }; + + return { + ...objectSchema, + ...getSchemaUtils(objectSchema), + ...getObjectLikeUtils(objectSchema), + }; +} diff --git a/src/core/schemas/builders/object-like/index.ts b/src/core/schemas/builders/object-like/index.ts new file mode 100644 index 0000000..c342e72 --- /dev/null +++ b/src/core/schemas/builders/object-like/index.ts @@ -0,0 +1,2 @@ +export { getObjectLikeUtils, withParsedProperties } from "./getObjectLikeUtils"; +export type { ObjectLikeSchema, ObjectLikeUtils } from "./types"; diff --git a/src/core/schemas/builders/object-like/types.ts b/src/core/schemas/builders/object-like/types.ts new file mode 100644 index 0000000..75b3698 --- /dev/null +++ b/src/core/schemas/builders/object-like/types.ts @@ -0,0 +1,11 @@ +import { BaseSchema, Schema } from "../../Schema"; + +export type ObjectLikeSchema = Schema & + BaseSchema & + ObjectLikeUtils; + +export interface ObjectLikeUtils { + withParsedProperties: >(properties: { + [K in keyof T]: T[K] | ((parsed: Parsed) => T[K]); + }) => ObjectLikeSchema; +} diff --git a/src/core/schemas/builders/object/index.ts b/src/core/schemas/builders/object/index.ts new file mode 100644 index 0000000..e6db5b5 --- /dev/null +++ b/src/core/schemas/builders/object/index.ts @@ -0,0 +1,17 @@ +export { getObjectUtils, object } from "./object"; +export { isProperty, property } from "./property"; +export type { Property } from "./property"; +export type { + BaseObjectSchema, + inferObjectSchemaFromPropertySchemas, + inferParsedObject, + inferParsedObjectFromPropertySchemas, + inferParsedPropertySchema, + inferRawKey, + inferRawObject, + inferRawObjectFromPropertySchemas, + inferRawPropertySchema, + ObjectSchema, + ObjectUtils, + PropertySchemas, +} from "./types"; diff --git a/src/core/schemas/builders/object/object.ts b/src/core/schemas/builders/object/object.ts new file mode 100644 index 0000000..4abadfb --- /dev/null +++ b/src/core/schemas/builders/object/object.ts @@ -0,0 +1,333 @@ +import { MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; +import { entries } from "../../utils/entries"; +import { filterObject } from "../../utils/filterObject"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { isPlainObject } from "../../utils/isPlainObject"; +import { keys } from "../../utils/keys"; +import { MaybePromise } from "../../utils/MaybePromise"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { partition } from "../../utils/partition"; +import { getObjectLikeUtils } from "../object-like"; +import { getSchemaUtils } from "../schema-utils"; +import { isProperty } from "./property"; +import { + BaseObjectSchema, + inferObjectSchemaFromPropertySchemas, + inferParsedObjectFromPropertySchemas, + inferRawObjectFromPropertySchemas, + ObjectSchema, + ObjectUtils, + PropertySchemas, +} from "./types"; + +interface ObjectPropertyWithRawKey { + rawKey: string; + parsedKey: string; + valueSchema: Schema; +} + +export function object>( + schemas: T +): inferObjectSchemaFromPropertySchemas { + const baseSchema: BaseObjectSchema< + inferRawObjectFromPropertySchemas, + inferParsedObjectFromPropertySchemas + > = { + _getRawProperties: () => + Promise.resolve( + Object.entries(schemas).map(([parsedKey, propertySchema]) => + isProperty(propertySchema) ? propertySchema.rawKey : parsedKey + ) as unknown as (keyof inferRawObjectFromPropertySchemas)[] + ), + _getParsedProperties: () => + Promise.resolve(keys(schemas) as unknown as (keyof inferParsedObjectFromPropertySchemas)[]), + + parse: async (raw, opts) => { + const rawKeyToProperty: Record = {}; + const requiredKeys: string[] = []; + + for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) { + const rawKey = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.rawKey : parsedKey; + const valueSchema: Schema = isProperty(schemaOrObjectProperty) + ? schemaOrObjectProperty.valueSchema + : schemaOrObjectProperty; + + const property: ObjectPropertyWithRawKey = { + rawKey, + parsedKey: parsedKey as string, + valueSchema, + }; + + rawKeyToProperty[rawKey] = property; + + if (await isSchemaRequired(valueSchema)) { + requiredKeys.push(rawKey); + } + } + + return validateAndTransformObject({ + value: raw, + requiredKeys, + getProperty: (rawKey) => { + const property = rawKeyToProperty[rawKey]; + if (property == null) { + return undefined; + } + return { + transformedKey: property.parsedKey, + transform: (propertyValue) => + property.valueSchema.parse(propertyValue, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), rawKey], + }), + }; + }, + unrecognizedObjectKeys: opts?.unrecognizedObjectKeys, + skipValidation: opts?.skipValidation, + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + + json: async (parsed, opts) => { + const requiredKeys: string[] = []; + + for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) { + const valueSchema: Schema = isProperty(schemaOrObjectProperty) + ? schemaOrObjectProperty.valueSchema + : schemaOrObjectProperty; + + if (await isSchemaRequired(valueSchema)) { + requiredKeys.push(parsedKey as string); + } + } + + return validateAndTransformObject({ + value: parsed, + requiredKeys, + getProperty: ( + parsedKey + ): + | { transformedKey: string; transform: (propertyValue: unknown) => MaybePromise> } + | undefined => { + const property = schemas[parsedKey as keyof T]; + + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (property == null) { + return undefined; + } + + if (isProperty(property)) { + return { + transformedKey: property.rawKey, + transform: (propertyValue) => + property.valueSchema.json(propertyValue, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), parsedKey], + }), + }; + } else { + return { + transformedKey: parsedKey, + transform: (propertyValue) => + property.json(propertyValue, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), parsedKey], + }), + }; + } + }, + unrecognizedObjectKeys: opts?.unrecognizedObjectKeys, + skipValidation: opts?.skipValidation, + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + + getType: () => SchemaType.OBJECT, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + ...getObjectLikeUtils(baseSchema), + ...getObjectUtils(baseSchema), + }; +} + +async function validateAndTransformObject({ + value, + requiredKeys, + getProperty, + unrecognizedObjectKeys = "fail", + skipValidation = false, + breadcrumbsPrefix = [], +}: { + value: unknown; + requiredKeys: string[]; + getProperty: ( + preTransformedKey: string + ) => { transformedKey: string; transform: (propertyValue: unknown) => MaybePromise> } | undefined; + unrecognizedObjectKeys: "fail" | "passthrough" | "strip" | undefined; + skipValidation: boolean | undefined; + breadcrumbsPrefix: string[] | undefined; +}): Promise> { + if (!isPlainObject(value)) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "object"), + }, + ], + }; + } + + const missingRequiredKeys = new Set(requiredKeys); + const errors: ValidationError[] = []; + const transformed: Record = {}; + + for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) { + const property = getProperty(preTransformedKey); + + if (property != null) { + missingRequiredKeys.delete(preTransformedKey); + + const value = await property.transform(preTransformedItemValue); + if (value.ok) { + transformed[property.transformedKey] = value.value; + } else { + transformed[preTransformedKey] = preTransformedItemValue; + errors.push(...value.errors); + } + } else { + switch (unrecognizedObjectKeys) { + case "fail": + errors.push({ + path: [...breadcrumbsPrefix, preTransformedKey], + message: `Unexpected key "${preTransformedKey}"`, + }); + break; + case "strip": + break; + case "passthrough": + transformed[preTransformedKey] = preTransformedItemValue; + break; + } + } + } + + errors.push( + ...requiredKeys + .filter((key) => missingRequiredKeys.has(key)) + .map((key) => ({ + path: breadcrumbsPrefix, + message: `Missing required key "${key}"`, + })) + ); + + if (errors.length === 0 || skipValidation) { + return { + ok: true, + value: transformed as Transformed, + }; + } else { + return { + ok: false, + errors, + }; + } +} + +export function getObjectUtils(schema: BaseObjectSchema): ObjectUtils { + return { + extend: (extension: ObjectSchema) => { + const baseSchema: BaseObjectSchema = { + _getParsedProperties: async () => [ + ...(await schema._getParsedProperties()), + ...(await extension._getParsedProperties()), + ], + _getRawProperties: async () => [ + ...(await schema._getRawProperties()), + ...(await extension._getRawProperties()), + ], + parse: async (raw, opts) => { + return validateAndTransformExtendedObject({ + extensionKeys: await extension._getRawProperties(), + value: raw, + transformBase: (rawBase) => schema.parse(rawBase, opts), + transformExtension: (rawExtension) => extension.parse(rawExtension, opts), + }); + }, + json: async (parsed, opts) => { + return validateAndTransformExtendedObject({ + extensionKeys: await extension._getParsedProperties(), + value: parsed, + transformBase: (parsedBase) => schema.json(parsedBase, opts), + transformExtension: (parsedExtension) => extension.json(parsedExtension, opts), + }); + }, + getType: () => SchemaType.OBJECT, + }; + + return { + ...baseSchema, + ...getSchemaUtils(baseSchema), + ...getObjectLikeUtils(baseSchema), + ...getObjectUtils(baseSchema), + }; + }, + }; +} + +async function validateAndTransformExtendedObject({ + extensionKeys, + value, + transformBase, + transformExtension, +}: { + extensionKeys: (keyof PreTransformedExtension)[]; + value: unknown; + transformBase: (value: unknown) => MaybePromise>; + transformExtension: (value: unknown) => MaybePromise>; +}): Promise> { + const extensionPropertiesSet = new Set(extensionKeys); + const [extensionProperties, baseProperties] = partition(keys(value), (key) => + extensionPropertiesSet.has(key as keyof PreTransformedExtension) + ); + + const transformedBase = await transformBase(filterObject(value, baseProperties)); + const transformedExtension = await transformExtension(filterObject(value, extensionProperties)); + + if (transformedBase.ok && transformedExtension.ok) { + return { + ok: true, + value: { + ...transformedBase.value, + ...transformedExtension.value, + }, + }; + } else { + return { + ok: false, + errors: [ + ...(transformedBase.ok ? [] : transformedBase.errors), + ...(transformedExtension.ok ? [] : transformedExtension.errors), + ], + }; + } +} + +async function isSchemaRequired(schema: Schema): Promise { + return !(await isSchemaOptional(schema)); +} + +async function isSchemaOptional(schema: Schema): Promise { + switch (await schema.getType()) { + case SchemaType.ANY: + case SchemaType.UNKNOWN: + case SchemaType.OPTIONAL: + return true; + default: + return false; + } +} diff --git a/src/core/schemas/builders/object/property.ts b/src/core/schemas/builders/object/property.ts new file mode 100644 index 0000000..d245c4b --- /dev/null +++ b/src/core/schemas/builders/object/property.ts @@ -0,0 +1,23 @@ +import { Schema } from "../../Schema"; + +export function property( + rawKey: RawKey, + valueSchema: Schema +): Property { + return { + rawKey, + valueSchema, + isProperty: true, + }; +} + +export interface Property { + rawKey: RawKey; + valueSchema: Schema; + isProperty: true; +} + +export function isProperty>(maybeProperty: unknown): maybeProperty is O { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + return (maybeProperty as O).isProperty; +} diff --git a/src/core/schemas/builders/object/types.ts b/src/core/schemas/builders/object/types.ts new file mode 100644 index 0000000..17cff4f --- /dev/null +++ b/src/core/schemas/builders/object/types.ts @@ -0,0 +1,72 @@ +import { BaseSchema, inferParsed, inferRaw, Schema } from "../../Schema"; +import { addQuestionMarksToNullableProperties } from "../../utils/addQuestionMarksToNullableProperties"; +import { ObjectLikeUtils } from "../object-like"; +import { SchemaUtils } from "../schema-utils"; +import { Property } from "./property"; + +export type ObjectSchema = BaseObjectSchema & + ObjectLikeUtils & + ObjectUtils & + SchemaUtils; + +export interface BaseObjectSchema extends BaseSchema { + _getRawProperties: () => Promise<(keyof Raw)[]>; + _getParsedProperties: () => Promise<(keyof Parsed)[]>; +} + +export interface ObjectUtils { + extend: ( + schemas: ObjectSchema + ) => ObjectSchema; +} + +export type inferRawObject> = O extends ObjectSchema ? Raw : never; + +export type inferParsedObject> = O extends ObjectSchema + ? Parsed + : never; + +export type inferObjectSchemaFromPropertySchemas> = ObjectSchema< + inferRawObjectFromPropertySchemas, + inferParsedObjectFromPropertySchemas +>; + +export type inferRawObjectFromPropertySchemas> = + addQuestionMarksToNullableProperties<{ + [ParsedKey in keyof T as inferRawKey]: inferRawPropertySchema; + }>; + +export type inferParsedObjectFromPropertySchemas> = + addQuestionMarksToNullableProperties<{ + [K in keyof T]: inferParsedPropertySchema; + }>; + +export type PropertySchemas = Record< + ParsedKeys, + Property | Schema +>; + +export type inferRawPropertySchema

| Schema> = P extends Property< + any, + infer Raw, + any +> + ? Raw + : P extends Schema + ? inferRaw

+ : never; + +export type inferParsedPropertySchema

| Schema> = P extends Property< + any, + any, + infer Parsed +> + ? Parsed + : P extends Schema + ? inferParsed

+ : never; + +export type inferRawKey< + ParsedKey extends string | number | symbol, + P extends Property | Schema +> = P extends Property ? Raw : ParsedKey; diff --git a/src/core/schemas/builders/primitives/any.ts b/src/core/schemas/builders/primitives/any.ts new file mode 100644 index 0000000..fcaeb04 --- /dev/null +++ b/src/core/schemas/builders/primitives/any.ts @@ -0,0 +1,4 @@ +import { SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; + +export const any = createIdentitySchemaCreator(SchemaType.ANY, (value) => ({ ok: true, value })); diff --git a/src/core/schemas/builders/primitives/boolean.ts b/src/core/schemas/builders/primitives/boolean.ts new file mode 100644 index 0000000..fad6056 --- /dev/null +++ b/src/core/schemas/builders/primitives/boolean.ts @@ -0,0 +1,25 @@ +import { SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; + +export const boolean = createIdentitySchemaCreator( + SchemaType.BOOLEAN, + (value, { breadcrumbsPrefix = [] } = {}) => { + if (typeof value === "boolean") { + return { + ok: true, + value, + }; + } else { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "boolean"), + }, + ], + }; + } + } +); diff --git a/src/core/schemas/builders/primitives/index.ts b/src/core/schemas/builders/primitives/index.ts new file mode 100644 index 0000000..788f941 --- /dev/null +++ b/src/core/schemas/builders/primitives/index.ts @@ -0,0 +1,5 @@ +export { any } from "./any"; +export { boolean } from "./boolean"; +export { number } from "./number"; +export { string } from "./string"; +export { unknown } from "./unknown"; diff --git a/src/core/schemas/builders/primitives/number.ts b/src/core/schemas/builders/primitives/number.ts new file mode 100644 index 0000000..c268945 --- /dev/null +++ b/src/core/schemas/builders/primitives/number.ts @@ -0,0 +1,25 @@ +import { SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; + +export const number = createIdentitySchemaCreator( + SchemaType.NUMBER, + (value, { breadcrumbsPrefix = [] } = {}) => { + if (typeof value === "number") { + return { + ok: true, + value, + }; + } else { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "number"), + }, + ], + }; + } + } +); diff --git a/src/core/schemas/builders/primitives/string.ts b/src/core/schemas/builders/primitives/string.ts new file mode 100644 index 0000000..949f1f2 --- /dev/null +++ b/src/core/schemas/builders/primitives/string.ts @@ -0,0 +1,25 @@ +import { SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; + +export const string = createIdentitySchemaCreator( + SchemaType.STRING, + (value, { breadcrumbsPrefix = [] } = {}) => { + if (typeof value === "string") { + return { + ok: true, + value, + }; + } else { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "string"), + }, + ], + }; + } + } +); diff --git a/src/core/schemas/builders/primitives/unknown.ts b/src/core/schemas/builders/primitives/unknown.ts new file mode 100644 index 0000000..4d52495 --- /dev/null +++ b/src/core/schemas/builders/primitives/unknown.ts @@ -0,0 +1,4 @@ +import { SchemaType } from "../../Schema"; +import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator"; + +export const unknown = createIdentitySchemaCreator(SchemaType.UNKNOWN, (value) => ({ ok: true, value })); diff --git a/src/core/schemas/builders/record/index.ts b/src/core/schemas/builders/record/index.ts new file mode 100644 index 0000000..82e25c5 --- /dev/null +++ b/src/core/schemas/builders/record/index.ts @@ -0,0 +1,2 @@ +export { record } from "./record"; +export type { BaseRecordSchema, RecordSchema } from "./types"; diff --git a/src/core/schemas/builders/record/record.ts b/src/core/schemas/builders/record/record.ts new file mode 100644 index 0000000..ac1cd22 --- /dev/null +++ b/src/core/schemas/builders/record/record.ts @@ -0,0 +1,131 @@ +import { MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; +import { entries } from "../../utils/entries"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { isPlainObject } from "../../utils/isPlainObject"; +import { MaybePromise } from "../../utils/MaybePromise"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { getSchemaUtils } from "../schema-utils"; +import { BaseRecordSchema, RecordSchema } from "./types"; + +export function record( + keySchema: Schema, + valueSchema: Schema +): RecordSchema { + const baseSchema: BaseRecordSchema = { + parse: async (raw, opts) => { + return validateAndTransformRecord({ + value: raw, + isKeyNumeric: (await keySchema.getType()) === SchemaType.NUMBER, + transformKey: (key) => + keySchema.parse(key, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`], + }), + transformValue: (value, key) => + valueSchema.parse(value, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`], + }), + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + json: async (parsed, opts) => { + return validateAndTransformRecord({ + value: parsed, + isKeyNumeric: (await keySchema.getType()) === SchemaType.NUMBER, + transformKey: (key) => + keySchema.json(key, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`], + }), + transformValue: (value, key) => + valueSchema.json(value, { + ...opts, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`], + }), + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + getType: () => SchemaType.RECORD, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; +} + +async function validateAndTransformRecord({ + value, + isKeyNumeric, + transformKey, + transformValue, + breadcrumbsPrefix = [], +}: { + value: unknown; + isKeyNumeric: boolean; + transformKey: (key: string | number) => MaybePromise>; + transformValue: (value: unknown, key: string | number) => MaybePromise>; + breadcrumbsPrefix: string[] | undefined; +}): Promise>> { + if (!isPlainObject(value)) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "object"), + }, + ], + }; + } + + return entries(value).reduce>>>( + async (accPromise, [stringKey, value]) => { + // skip nullish keys + if (value == null) { + return accPromise; + } + + const acc = await accPromise; + + let key: string | number = stringKey; + if (isKeyNumeric) { + const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN; + if (!isNaN(numberKey)) { + key = numberKey; + } + } + const transformedKey = await transformKey(key); + + const transformedValue = await transformValue(value, key); + + if (acc.ok && transformedKey.ok && transformedValue.ok) { + return { + ok: true, + value: { + ...acc.value, + [transformedKey.value]: transformedValue.value, + }, + }; + } + + const errors: ValidationError[] = []; + if (!acc.ok) { + errors.push(...acc.errors); + } + if (!transformedKey.ok) { + errors.push(...transformedKey.errors); + } + if (!transformedValue.ok) { + errors.push(...transformedValue.errors); + } + + return { + ok: false, + errors, + }; + }, + Promise.resolve({ ok: true, value: {} as Record }) + ); +} diff --git a/src/core/schemas/builders/record/types.ts b/src/core/schemas/builders/record/types.ts new file mode 100644 index 0000000..eb82cc7 --- /dev/null +++ b/src/core/schemas/builders/record/types.ts @@ -0,0 +1,17 @@ +import { BaseSchema } from "../../Schema"; +import { SchemaUtils } from "../schema-utils"; + +export type RecordSchema< + RawKey extends string | number, + RawValue, + ParsedKey extends string | number, + ParsedValue +> = BaseRecordSchema & + SchemaUtils, Record>; + +export type BaseRecordSchema< + RawKey extends string | number, + RawValue, + ParsedKey extends string | number, + ParsedValue +> = BaseSchema, Record>; diff --git a/src/core/schemas/builders/schema-utils/JsonError.ts b/src/core/schemas/builders/schema-utils/JsonError.ts new file mode 100644 index 0000000..2b89ca0 --- /dev/null +++ b/src/core/schemas/builders/schema-utils/JsonError.ts @@ -0,0 +1,9 @@ +import { ValidationError } from "../../Schema"; +import { stringifyValidationError } from "./stringifyValidationErrors"; + +export class JsonError extends Error { + constructor(public readonly errors: ValidationError[]) { + super(errors.map(stringifyValidationError).join("; ")); + Object.setPrototypeOf(this, JsonError.prototype); + } +} diff --git a/src/core/schemas/builders/schema-utils/ParseError.ts b/src/core/schemas/builders/schema-utils/ParseError.ts new file mode 100644 index 0000000..d056eb4 --- /dev/null +++ b/src/core/schemas/builders/schema-utils/ParseError.ts @@ -0,0 +1,9 @@ +import { ValidationError } from "../../Schema"; +import { stringifyValidationError } from "./stringifyValidationErrors"; + +export class ParseError extends Error { + constructor(public readonly errors: ValidationError[]) { + super(errors.map(stringifyValidationError).join("; ")); + Object.setPrototypeOf(this, ParseError.prototype); + } +} diff --git a/src/core/schemas/builders/schema-utils/getSchemaUtils.ts b/src/core/schemas/builders/schema-utils/getSchemaUtils.ts new file mode 100644 index 0000000..0c0d379 --- /dev/null +++ b/src/core/schemas/builders/schema-utils/getSchemaUtils.ts @@ -0,0 +1,99 @@ +import { BaseSchema, Schema, SchemaOptions, SchemaType } from "../../Schema"; +import { JsonError } from "./JsonError"; +import { ParseError } from "./ParseError"; + +export interface SchemaUtils { + optional: () => Schema; + transform: (transformer: SchemaTransformer) => Schema; + parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Promise; + jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Promise; +} + +export interface SchemaTransformer { + transform: (parsed: Parsed) => Transformed; + untransform: (transformed: any) => Parsed; +} + +export function getSchemaUtils(schema: BaseSchema): SchemaUtils { + return { + optional: () => optional(schema), + transform: (transformer) => transform(schema, transformer), + parseOrThrow: async (raw, opts) => { + const parsed = await schema.parse(raw, opts); + if (parsed.ok) { + return parsed.value; + } + throw new ParseError(parsed.errors); + }, + jsonOrThrow: async (parsed, opts) => { + const raw = await schema.json(parsed, opts); + if (raw.ok) { + return raw.value; + } + throw new JsonError(raw.errors); + }, + }; +} + +/** + * schema utils are defined in one file to resolve issues with circular imports + */ + +export function optional( + schema: BaseSchema +): Schema { + const baseSchema: BaseSchema = { + parse: (raw, opts) => { + if (raw == null) { + return { + ok: true, + value: undefined, + }; + } + return schema.parse(raw, opts); + }, + json: (parsed, opts) => { + if (parsed == null) { + return { + ok: true, + value: null, + }; + } + return schema.json(parsed, opts); + }, + getType: () => SchemaType.OPTIONAL, + }; + + return { + ...baseSchema, + ...getSchemaUtils(baseSchema), + }; +} + +export function transform( + schema: BaseSchema, + transformer: SchemaTransformer +): Schema { + const baseSchema: BaseSchema = { + parse: async (raw, opts) => { + const parsed = await schema.parse(raw, opts); + if (!parsed.ok) { + return parsed; + } + return { + ok: true, + value: transformer.transform(parsed.value), + }; + }, + json: async (transformed, opts) => { + const parsed = await transformer.untransform(transformed); + return schema.json(parsed, opts); + }, + getType: () => schema.getType(), + }; + + return { + ...baseSchema, + ...getSchemaUtils(baseSchema), + }; +} diff --git a/src/core/schemas/builders/schema-utils/index.ts b/src/core/schemas/builders/schema-utils/index.ts new file mode 100644 index 0000000..aa04e05 --- /dev/null +++ b/src/core/schemas/builders/schema-utils/index.ts @@ -0,0 +1,4 @@ +export { getSchemaUtils, optional, transform } from "./getSchemaUtils"; +export type { SchemaUtils } from "./getSchemaUtils"; +export { JsonError } from "./JsonError"; +export { ParseError } from "./ParseError"; diff --git a/src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts b/src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts new file mode 100644 index 0000000..4160f0a --- /dev/null +++ b/src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts @@ -0,0 +1,8 @@ +import { ValidationError } from "../../Schema"; + +export function stringifyValidationError(error: ValidationError): string { + if (error.path.length === 0) { + return error.message; + } + return `${error.path.join(" -> ")}: ${error.message}`; +} diff --git a/src/core/schemas/builders/set/index.ts b/src/core/schemas/builders/set/index.ts new file mode 100644 index 0000000..f3310e8 --- /dev/null +++ b/src/core/schemas/builders/set/index.ts @@ -0,0 +1 @@ +export { set } from "./set"; diff --git a/src/core/schemas/builders/set/set.ts b/src/core/schemas/builders/set/set.ts new file mode 100644 index 0000000..3113bcb --- /dev/null +++ b/src/core/schemas/builders/set/set.ts @@ -0,0 +1,43 @@ +import { BaseSchema, Schema, SchemaType } from "../../Schema"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { list } from "../list"; +import { getSchemaUtils } from "../schema-utils"; + +export function set(schema: Schema): Schema> { + const listSchema = list(schema); + const baseSchema: BaseSchema> = { + parse: async (raw, opts) => { + const parsedList = await listSchema.parse(raw, opts); + if (parsedList.ok) { + return { + ok: true, + value: new Set(parsedList.value), + }; + } else { + return parsedList; + } + }, + json: async (parsed, opts) => { + if (!(parsed instanceof Set)) { + return { + ok: false, + errors: [ + { + path: opts?.breadcrumbsPrefix ?? [], + message: getErrorMessageForIncorrectType(parsed, "Set"), + }, + ], + }; + } + const jsonList = await listSchema.json([...parsed], opts); + return jsonList; + }, + getType: () => SchemaType.SET, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; +} diff --git a/src/core/schemas/builders/undiscriminated-union/index.ts b/src/core/schemas/builders/undiscriminated-union/index.ts new file mode 100644 index 0000000..75b71cb --- /dev/null +++ b/src/core/schemas/builders/undiscriminated-union/index.ts @@ -0,0 +1,6 @@ +export type { + inferParsedUnidiscriminatedUnionSchema, + inferRawUnidiscriminatedUnionSchema, + UndiscriminatedUnionSchema, +} from "./types"; +export { undiscriminatedUnion } from "./undiscriminatedUnion"; diff --git a/src/core/schemas/builders/undiscriminated-union/types.ts b/src/core/schemas/builders/undiscriminated-union/types.ts new file mode 100644 index 0000000..43e7108 --- /dev/null +++ b/src/core/schemas/builders/undiscriminated-union/types.ts @@ -0,0 +1,10 @@ +import { inferParsed, inferRaw, Schema } from "../../Schema"; + +export type UndiscriminatedUnionSchema = Schema< + inferRawUnidiscriminatedUnionSchema, + inferParsedUnidiscriminatedUnionSchema +>; + +export type inferRawUnidiscriminatedUnionSchema = inferRaw; + +export type inferParsedUnidiscriminatedUnionSchema = inferParsed; diff --git a/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts b/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts new file mode 100644 index 0000000..9d1a589 --- /dev/null +++ b/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts @@ -0,0 +1,58 @@ +import { BaseSchema, MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; +import { MaybePromise } from "../../utils/MaybePromise"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { getSchemaUtils } from "../schema-utils"; +import { inferParsedUnidiscriminatedUnionSchema, inferRawUnidiscriminatedUnionSchema } from "./types"; + +export function undiscriminatedUnion, ...Schema[]]>( + schemas: Schemas +): Schema, inferParsedUnidiscriminatedUnionSchema> { + const baseSchema: BaseSchema< + inferRawUnidiscriminatedUnionSchema, + inferParsedUnidiscriminatedUnionSchema + > = { + parse: async (raw, opts) => { + return validateAndTransformUndiscriminatedUnion>( + (schema) => schema.parse(raw, opts), + schemas + ); + }, + json: async (parsed, opts) => { + return validateAndTransformUndiscriminatedUnion>( + (schema) => schema.json(parsed, opts), + schemas + ); + }, + getType: () => SchemaType.UNDISCRIMINATED_UNION, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; +} + +async function validateAndTransformUndiscriminatedUnion( + transform: (schema: Schema) => MaybePromise>, + schemas: Schema[] +): Promise> { + const errors: ValidationError[] = []; + for (const [index, schema] of schemas.entries()) { + const transformed = await transform(schema); + if (transformed.ok) { + return transformed; + } else { + for (const error of errors) { + errors.push({ + path: error.path, + message: `[Variant ${index}] ${error.message}`, + }); + } + } + } + + return { + ok: false, + errors, + }; +} diff --git a/src/core/schemas/builders/union/discriminant.ts b/src/core/schemas/builders/union/discriminant.ts new file mode 100644 index 0000000..55065bc --- /dev/null +++ b/src/core/schemas/builders/union/discriminant.ts @@ -0,0 +1,14 @@ +export function discriminant( + parsedDiscriminant: ParsedDiscriminant, + rawDiscriminant: RawDiscriminant +): Discriminant { + return { + parsedDiscriminant, + rawDiscriminant, + }; +} + +export interface Discriminant { + parsedDiscriminant: ParsedDiscriminant; + rawDiscriminant: RawDiscriminant; +} diff --git a/src/core/schemas/builders/union/index.ts b/src/core/schemas/builders/union/index.ts new file mode 100644 index 0000000..85fc008 --- /dev/null +++ b/src/core/schemas/builders/union/index.ts @@ -0,0 +1,10 @@ +export { discriminant } from "./discriminant"; +export type { Discriminant } from "./discriminant"; +export type { + inferParsedDiscriminant, + inferParsedUnion, + inferRawDiscriminant, + inferRawUnion, + UnionSubtypes, +} from "./types"; +export { union } from "./union"; diff --git a/src/core/schemas/builders/union/types.ts b/src/core/schemas/builders/union/types.ts new file mode 100644 index 0000000..6f82c86 --- /dev/null +++ b/src/core/schemas/builders/union/types.ts @@ -0,0 +1,26 @@ +import { inferParsedObject, inferRawObject, ObjectSchema } from "../object"; +import { Discriminant } from "./discriminant"; + +export type UnionSubtypes = { + [K in DiscriminantValues]: ObjectSchema; +}; + +export type inferRawUnion, U extends UnionSubtypes> = { + [K in keyof U]: Record, K> & inferRawObject; +}[keyof U]; + +export type inferParsedUnion, U extends UnionSubtypes> = { + [K in keyof U]: Record, K> & inferParsedObject; +}[keyof U]; + +export type inferRawDiscriminant> = D extends string + ? D + : D extends Discriminant + ? Raw + : never; + +export type inferParsedDiscriminant> = D extends string + ? D + : D extends Discriminant + ? Parsed + : never; diff --git a/src/core/schemas/builders/union/union.ts b/src/core/schemas/builders/union/union.ts new file mode 100644 index 0000000..ed659be --- /dev/null +++ b/src/core/schemas/builders/union/union.ts @@ -0,0 +1,173 @@ +import { BaseSchema, MaybeValid, SchemaType } from "../../Schema"; +import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; +import { isPlainObject } from "../../utils/isPlainObject"; +import { keys } from "../../utils/keys"; +import { MaybePromise } from "../../utils/MaybePromise"; +import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; +import { enum_ } from "../enum"; +import { ObjectSchema } from "../object"; +import { getObjectLikeUtils, ObjectLikeSchema } from "../object-like"; +import { getSchemaUtils } from "../schema-utils"; +import { Discriminant } from "./discriminant"; +import { inferParsedDiscriminant, inferParsedUnion, inferRawDiscriminant, inferRawUnion, UnionSubtypes } from "./types"; + +export function union, U extends UnionSubtypes>( + discriminant: D, + union: U +): ObjectLikeSchema, inferParsedUnion> { + const rawDiscriminant = + typeof discriminant === "string" ? discriminant : (discriminant.rawDiscriminant as inferRawDiscriminant); + const parsedDiscriminant = + typeof discriminant === "string" + ? discriminant + : (discriminant.parsedDiscriminant as inferParsedDiscriminant); + + const discriminantValueSchema = enum_(keys(union) as string[]); + + const baseSchema: BaseSchema, inferParsedUnion> = { + parse: async (raw, opts) => { + return transformAndValidateUnion({ + value: raw, + discriminant: rawDiscriminant, + transformedDiscriminant: parsedDiscriminant, + transformDiscriminantValue: (discriminantValue) => + discriminantValueSchema.parse(discriminantValue, { + allowUnrecognizedEnumValues: opts?.allowUnrecognizedUnionMembers, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), rawDiscriminant], + }), + getAdditionalPropertiesSchema: (discriminantValue) => union[discriminantValue], + allowUnrecognizedUnionMembers: opts?.allowUnrecognizedUnionMembers, + transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) => + additionalPropertiesSchema.parse(additionalProperties, opts), + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + json: async (parsed, opts) => { + return transformAndValidateUnion({ + value: parsed, + discriminant: parsedDiscriminant, + transformedDiscriminant: rawDiscriminant, + transformDiscriminantValue: (discriminantValue) => + discriminantValueSchema.json(discriminantValue, { + allowUnrecognizedEnumValues: opts?.allowUnrecognizedUnionMembers, + breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), parsedDiscriminant], + }), + getAdditionalPropertiesSchema: (discriminantValue) => union[discriminantValue], + allowUnrecognizedUnionMembers: opts?.allowUnrecognizedUnionMembers, + transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) => + additionalPropertiesSchema.json(additionalProperties, opts), + breadcrumbsPrefix: opts?.breadcrumbsPrefix, + }); + }, + getType: () => SchemaType.UNION, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + ...getObjectLikeUtils(baseSchema), + }; +} + +async function transformAndValidateUnion< + TransformedDiscriminant extends string, + TransformedDiscriminantValue extends string, + TransformedAdditionalProperties +>({ + value, + discriminant, + transformedDiscriminant, + transformDiscriminantValue, + getAdditionalPropertiesSchema, + allowUnrecognizedUnionMembers = false, + transformAdditionalProperties, + breadcrumbsPrefix = [], +}: { + value: unknown; + discriminant: string; + transformedDiscriminant: TransformedDiscriminant; + transformDiscriminantValue: (discriminantValue: unknown) => MaybePromise>; + getAdditionalPropertiesSchema: (discriminantValue: string) => ObjectSchema | undefined; + allowUnrecognizedUnionMembers: boolean | undefined; + transformAdditionalProperties: ( + additionalProperties: unknown, + additionalPropertiesSchema: ObjectSchema + ) => MaybePromise>; + breadcrumbsPrefix: string[] | undefined; +}): Promise< + MaybeValid & TransformedAdditionalProperties> +> { + if (!isPlainObject(value)) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: getErrorMessageForIncorrectType(value, "object"), + }, + ], + }; + } + + const { [discriminant]: discriminantValue, ...additionalProperties } = value; + + if (discriminantValue == null) { + return { + ok: false, + errors: [ + { + path: breadcrumbsPrefix, + message: `Missing discriminant ("${discriminant}")`, + }, + ], + }; + } + + const transformedDiscriminantValue = await transformDiscriminantValue(discriminantValue); + if (!transformedDiscriminantValue.ok) { + return { + ok: false, + errors: transformedDiscriminantValue.errors, + }; + } + + const additionalPropertiesSchema = getAdditionalPropertiesSchema(transformedDiscriminantValue.value); + + if (additionalPropertiesSchema == null) { + if (allowUnrecognizedUnionMembers) { + return { + ok: true, + value: { + [transformedDiscriminant]: transformedDiscriminantValue.value, + ...additionalProperties, + } as Record & TransformedAdditionalProperties, + }; + } else { + return { + ok: false, + errors: [ + { + path: [...breadcrumbsPrefix, discriminant], + message: "Unexpected discriminant value", + }, + ], + }; + } + } + + const transformedAdditionalProperties = await transformAdditionalProperties( + additionalProperties, + additionalPropertiesSchema + ); + if (!transformedAdditionalProperties.ok) { + return transformedAdditionalProperties; + } + + return { + ok: true, + value: { + [transformedDiscriminant]: discriminantValue, + ...transformedAdditionalProperties.value, + } as Record & TransformedAdditionalProperties, + }; +} diff --git a/src/core/schemas/index.ts b/src/core/schemas/index.ts new file mode 100644 index 0000000..5429d8b --- /dev/null +++ b/src/core/schemas/index.ts @@ -0,0 +1,2 @@ +export * from "./builders"; +export type { inferParsed, inferRaw, Schema, SchemaOptions } from "./Schema"; diff --git a/src/core/schemas/utils/MaybePromise.ts b/src/core/schemas/utils/MaybePromise.ts new file mode 100644 index 0000000..9cd354b --- /dev/null +++ b/src/core/schemas/utils/MaybePromise.ts @@ -0,0 +1 @@ +export type MaybePromise = T | Promise; diff --git a/src/core/schemas/utils/addQuestionMarksToNullableProperties.ts b/src/core/schemas/utils/addQuestionMarksToNullableProperties.ts new file mode 100644 index 0000000..4111d70 --- /dev/null +++ b/src/core/schemas/utils/addQuestionMarksToNullableProperties.ts @@ -0,0 +1,15 @@ +export type addQuestionMarksToNullableProperties = { + [K in OptionalKeys]?: T[K]; +} & Pick>; + +export type OptionalKeys = { + [K in keyof T]-?: undefined extends T[K] + ? K + : null extends T[K] + ? K + : 1 extends (any extends T[K] ? 0 : 1) + ? never + : K; +}[keyof T]; + +export type RequiredKeys = Exclude>; diff --git a/src/core/schemas/utils/createIdentitySchemaCreator.ts b/src/core/schemas/utils/createIdentitySchemaCreator.ts new file mode 100644 index 0000000..de107cf --- /dev/null +++ b/src/core/schemas/utils/createIdentitySchemaCreator.ts @@ -0,0 +1,21 @@ +import { getSchemaUtils } from "../builders/schema-utils"; +import { BaseSchema, MaybeValid, Schema, SchemaOptions, SchemaType } from "../Schema"; +import { maybeSkipValidation } from "./maybeSkipValidation"; + +export function createIdentitySchemaCreator( + schemaType: SchemaType, + validate: (value: unknown, opts?: SchemaOptions) => MaybeValid +): () => Schema { + return () => { + const baseSchema: BaseSchema = { + parse: validate, + json: validate, + getType: () => schemaType, + }; + + return { + ...maybeSkipValidation(baseSchema), + ...getSchemaUtils(baseSchema), + }; + }; +} diff --git a/src/core/schemas/utils/entries.ts b/src/core/schemas/utils/entries.ts new file mode 100644 index 0000000..e122952 --- /dev/null +++ b/src/core/schemas/utils/entries.ts @@ -0,0 +1,3 @@ +export function entries(object: T): [keyof T, T[keyof T]][] { + return Object.entries(object) as [keyof T, T[keyof T]][]; +} diff --git a/src/core/schemas/utils/filterObject.ts b/src/core/schemas/utils/filterObject.ts new file mode 100644 index 0000000..2c25a34 --- /dev/null +++ b/src/core/schemas/utils/filterObject.ts @@ -0,0 +1,10 @@ +export function filterObject(obj: T, keysToInclude: K[]): Pick { + const keysToIncludeSet = new Set(keysToInclude); + return Object.entries(obj).reduce((acc, [key, value]) => { + if (keysToIncludeSet.has(key as K)) { + acc[key as K] = value; + } + return acc; + // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter + }, {} as Pick); +} diff --git a/src/core/schemas/utils/getErrorMessageForIncorrectType.ts b/src/core/schemas/utils/getErrorMessageForIncorrectType.ts new file mode 100644 index 0000000..438012d --- /dev/null +++ b/src/core/schemas/utils/getErrorMessageForIncorrectType.ts @@ -0,0 +1,21 @@ +export function getErrorMessageForIncorrectType(value: unknown, expectedType: string): string { + return `Expected ${expectedType}. Received ${getTypeAsString(value)}.`; +} + +function getTypeAsString(value: unknown): string { + if (Array.isArray(value)) { + return "list"; + } + if (value === null) { + return "null"; + } + switch (typeof value) { + case "string": + return `"${value}"`; + case "number": + case "boolean": + case "undefined": + return `${value}`; + } + return typeof value; +} diff --git a/src/core/schemas/utils/isPlainObject.ts b/src/core/schemas/utils/isPlainObject.ts new file mode 100644 index 0000000..db82a72 --- /dev/null +++ b/src/core/schemas/utils/isPlainObject.ts @@ -0,0 +1,17 @@ +// borrowed from https://github.com/lodash/lodash/blob/master/isPlainObject.js +export function isPlainObject(value: unknown): value is Record { + if (typeof value !== "object" || value === null) { + return false; + } + + if (Object.getPrototypeOf(value) === null) { + return true; + } + + let proto = value; + while (Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto); + } + + return Object.getPrototypeOf(value) === proto; +} diff --git a/src/core/schemas/utils/keys.ts b/src/core/schemas/utils/keys.ts new file mode 100644 index 0000000..0186709 --- /dev/null +++ b/src/core/schemas/utils/keys.ts @@ -0,0 +1,3 @@ +export function keys(object: T): (keyof T)[] { + return Object.keys(object) as (keyof T)[]; +} diff --git a/src/core/schemas/utils/maybeSkipValidation.ts b/src/core/schemas/utils/maybeSkipValidation.ts new file mode 100644 index 0000000..99c02c3 --- /dev/null +++ b/src/core/schemas/utils/maybeSkipValidation.ts @@ -0,0 +1,39 @@ +import { BaseSchema, MaybeValid, SchemaOptions } from "../Schema"; +import { MaybePromise } from "./MaybePromise"; + +export function maybeSkipValidation, Raw, Parsed>(schema: S): S { + return { + ...schema, + json: transformAndMaybeSkipValidation(schema.json), + parse: transformAndMaybeSkipValidation(schema.parse), + }; +} + +function transformAndMaybeSkipValidation( + transform: (value: unknown, opts?: SchemaOptions) => MaybePromise> +): (value: unknown, opts?: SchemaOptions) => MaybePromise> { + return async (value, opts): Promise> => { + const transformed = await transform(value, opts); + const { skipValidation = false } = opts ?? {}; + if (!transformed.ok && skipValidation) { + // eslint-disable-next-line no-console + console.warn( + [ + "Failed to validate.", + ...transformed.errors.map( + (error) => + " - " + + (error.path.length > 0 ? `${error.path.join(".")}: ${error.message}` : error.message) + ), + ].join("\n") + ); + + return { + ok: true, + value: value as T, + }; + } else { + return transformed; + } + }; +} diff --git a/src/core/schemas/utils/partition.ts b/src/core/schemas/utils/partition.ts new file mode 100644 index 0000000..f58d6f3 --- /dev/null +++ b/src/core/schemas/utils/partition.ts @@ -0,0 +1,12 @@ +export function partition(items: readonly T[], predicate: (item: T) => boolean): [T[], T[]] { + const trueItems: T[] = [], + falseItems: T[] = []; + for (const item of items) { + if (predicate(item)) { + trueItems.push(item); + } else { + falseItems.push(item); + } + } + return [trueItems, falseItems]; +} diff --git a/src/errors/VocodeError.ts b/src/errors/VocodeError.ts new file mode 100644 index 0000000..5b66bd3 --- /dev/null +++ b/src/errors/VocodeError.ts @@ -0,0 +1,45 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export class VocodeError extends Error { + readonly statusCode?: number; + readonly body?: unknown; + + constructor({ message, statusCode, body }: { message?: string; statusCode?: number; body?: unknown }) { + super(buildMessage({ message, statusCode, body })); + Object.setPrototypeOf(this, VocodeError.prototype); + if (statusCode != null) { + this.statusCode = statusCode; + } + + if (body !== undefined) { + this.body = body; + } + } +} + +function buildMessage({ + message, + statusCode, + body, +}: { + message: string | undefined; + statusCode: number | undefined; + body: unknown | undefined; +}): string { + let lines: string[] = []; + if (message != null) { + lines.push(message); + } + + if (statusCode != null) { + lines.push(`Status code: ${statusCode.toString()}`); + } + + if (body != null) { + lines.push(`Body: ${JSON.stringify(body, undefined, 2)}`); + } + + return lines.join("\n"); +} diff --git a/src/errors/VocodeTimeoutError.ts b/src/errors/VocodeTimeoutError.ts new file mode 100644 index 0000000..13abbcb --- /dev/null +++ b/src/errors/VocodeTimeoutError.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export class VocodeTimeoutError extends Error { + constructor() { + super("Timeout"); + Object.setPrototypeOf(this, VocodeTimeoutError.prototype); + } +} diff --git a/src/errors/index.ts b/src/errors/index.ts new file mode 100644 index 0000000..00738d7 --- /dev/null +++ b/src/errors/index.ts @@ -0,0 +1,2 @@ +export { VocodeError } from "./VocodeError"; +export { VocodeTimeoutError } from "./VocodeTimeoutError"; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..3b1975b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +export * as Vocode from "./api"; +export { VocodeClient } from "./Client"; +export { VocodeError, VocodeTimeoutError } from "./errors"; diff --git a/src/serialization/index.ts b/src/serialization/index.ts new file mode 100644 index 0000000..3ce0a3e --- /dev/null +++ b/src/serialization/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./resources"; diff --git a/src/serialization/resources/actions/client/index.ts b/src/serialization/resources/actions/client/index.ts new file mode 100644 index 0000000..b188344 --- /dev/null +++ b/src/serialization/resources/actions/client/index.ts @@ -0,0 +1 @@ +export * as listActions from "./listActions"; diff --git a/src/serialization/resources/actions/client/listActions.ts b/src/serialization/resources/actions/client/listActions.ts new file mode 100644 index 0000000..0b48a5f --- /dev/null +++ b/src/serialization/resources/actions/client/listActions.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema< + serializers.actions.listActions.Response.Raw, + Vocode.ListActionsResponseItem[] +> = core.serialization.list(core.serialization.lazy(async () => (await import("../../..")).ListActionsResponseItem)); + +export declare namespace Response { + type Raw = serializers.ListActionsResponseItem.Raw[]; +} diff --git a/src/serialization/resources/actions/index.ts b/src/serialization/resources/actions/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/actions/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/resources/agents/client/index.ts b/src/serialization/resources/agents/client/index.ts new file mode 100644 index 0000000..0a5c2a4 --- /dev/null +++ b/src/serialization/resources/agents/client/index.ts @@ -0,0 +1 @@ +export * as listAgents from "./listAgents"; diff --git a/src/serialization/resources/agents/client/listAgents.ts b/src/serialization/resources/agents/client/listAgents.ts new file mode 100644 index 0000000..c86a513 --- /dev/null +++ b/src/serialization/resources/agents/client/listAgents.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema = + core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Agent)); + +export declare namespace Response { + type Raw = serializers.Agent.Raw[]; +} diff --git a/src/serialization/resources/agents/index.ts b/src/serialization/resources/agents/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/agents/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/resources/calls/client/index.ts b/src/serialization/resources/calls/client/index.ts new file mode 100644 index 0000000..c7a0c1a --- /dev/null +++ b/src/serialization/resources/calls/client/index.ts @@ -0,0 +1,2 @@ +export * as listCalls from "./listCalls"; +export * from "./requests"; diff --git a/src/serialization/resources/calls/client/listCalls.ts b/src/serialization/resources/calls/client/listCalls.ts new file mode 100644 index 0000000..a863aab --- /dev/null +++ b/src/serialization/resources/calls/client/listCalls.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema = + core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Call)); + +export declare namespace Response { + type Raw = serializers.Call.Raw[]; +} diff --git a/src/serialization/resources/calls/client/requests/CreateCallRequest.ts b/src/serialization/resources/calls/client/requests/CreateCallRequest.ts new file mode 100644 index 0000000..06e043d --- /dev/null +++ b/src/serialization/resources/calls/client/requests/CreateCallRequest.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../.."; +import * as Vocode from "../../../../../api"; +import * as core from "../../../../../core"; + +export const CreateCallRequest: core.serialization.Schema = + core.serialization.object({ + fromNumber: core.serialization.property("from_number", core.serialization.string()), + toNumber: core.serialization.property("to_number", core.serialization.string()), + goal: core.serialization.string(), + agent: core.serialization.lazy(async () => (await import("../../../..")).CreateCallRequestAgent), + }); + +export declare namespace CreateCallRequest { + interface Raw { + from_number: string; + to_number: string; + goal: string; + agent: serializers.CreateCallRequestAgent.Raw; + } +} diff --git a/src/serialization/resources/calls/client/requests/index.ts b/src/serialization/resources/calls/client/requests/index.ts new file mode 100644 index 0000000..08812a8 --- /dev/null +++ b/src/serialization/resources/calls/client/requests/index.ts @@ -0,0 +1 @@ +export { CreateCallRequest } from "./CreateCallRequest"; diff --git a/src/serialization/resources/calls/index.ts b/src/serialization/resources/calls/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/calls/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/resources/index.ts b/src/serialization/resources/index.ts new file mode 100644 index 0000000..2e75779 --- /dev/null +++ b/src/serialization/resources/index.ts @@ -0,0 +1,8 @@ +export * as numbers from "./numbers"; +export * as calls from "./calls"; +export * as actions from "./actions"; +export * as agents from "./agents"; +export * as voices from "./voices"; +export * as webhooks from "./webhooks"; +export * from "./numbers/client/requests"; +export * from "./calls/client/requests"; diff --git a/src/serialization/resources/numbers/client/index.ts b/src/serialization/resources/numbers/client/index.ts new file mode 100644 index 0000000..9000805 --- /dev/null +++ b/src/serialization/resources/numbers/client/index.ts @@ -0,0 +1,2 @@ +export * as listNumbers from "./listNumbers"; +export * from "./requests"; diff --git a/src/serialization/resources/numbers/client/listNumbers.ts b/src/serialization/resources/numbers/client/listNumbers.ts new file mode 100644 index 0000000..d90d168 --- /dev/null +++ b/src/serialization/resources/numbers/client/listNumbers.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema = + core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).PhoneNumber)); + +export declare namespace Response { + type Raw = serializers.PhoneNumber.Raw[]; +} diff --git a/src/serialization/resources/numbers/client/requests/UpdateNumberRequest.ts b/src/serialization/resources/numbers/client/requests/UpdateNumberRequest.ts new file mode 100644 index 0000000..1d1c4fa --- /dev/null +++ b/src/serialization/resources/numbers/client/requests/UpdateNumberRequest.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../.."; +import * as Vocode from "../../../../../api"; +import * as core from "../../../../../core"; + +export const UpdateNumberRequest: core.serialization.Schema< + serializers.UpdateNumberRequest.Raw, + Omit +> = core.serialization.object({ + inboundAgent: core.serialization.property( + "inbound_agent", + core.serialization.lazy(async () => (await import("../../../..")).UpdateNumberRequestInboundAgent) + ), +}); + +export declare namespace UpdateNumberRequest { + interface Raw { + inbound_agent: serializers.UpdateNumberRequestInboundAgent.Raw; + } +} diff --git a/src/serialization/resources/numbers/client/requests/index.ts b/src/serialization/resources/numbers/client/requests/index.ts new file mode 100644 index 0000000..71f4293 --- /dev/null +++ b/src/serialization/resources/numbers/client/requests/index.ts @@ -0,0 +1 @@ +export { UpdateNumberRequest } from "./UpdateNumberRequest"; diff --git a/src/serialization/resources/numbers/index.ts b/src/serialization/resources/numbers/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/numbers/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/resources/voices/client/index.ts b/src/serialization/resources/voices/client/index.ts new file mode 100644 index 0000000..3a16a85 --- /dev/null +++ b/src/serialization/resources/voices/client/index.ts @@ -0,0 +1 @@ +export * as listVoices from "./listVoices"; diff --git a/src/serialization/resources/voices/client/listVoices.ts b/src/serialization/resources/voices/client/listVoices.ts new file mode 100644 index 0000000..331d118 --- /dev/null +++ b/src/serialization/resources/voices/client/listVoices.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema< + serializers.voices.listVoices.Response.Raw, + Vocode.ListVoicesResponseItem[] +> = core.serialization.list(core.serialization.lazy(async () => (await import("../../..")).ListVoicesResponseItem)); + +export declare namespace Response { + type Raw = serializers.ListVoicesResponseItem.Raw[]; +} diff --git a/src/serialization/resources/voices/index.ts b/src/serialization/resources/voices/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/voices/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/resources/webhooks/client/index.ts b/src/serialization/resources/webhooks/client/index.ts new file mode 100644 index 0000000..67e1703 --- /dev/null +++ b/src/serialization/resources/webhooks/client/index.ts @@ -0,0 +1 @@ +export * as listWebhooks from "./listWebhooks"; diff --git a/src/serialization/resources/webhooks/client/listWebhooks.ts b/src/serialization/resources/webhooks/client/listWebhooks.ts new file mode 100644 index 0000000..13ef555 --- /dev/null +++ b/src/serialization/resources/webhooks/client/listWebhooks.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../.."; +import * as Vocode from "../../../../api"; +import * as core from "../../../../core"; + +export const Response: core.serialization.Schema = + core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Webhook)); + +export declare namespace Response { + type Raw = serializers.Webhook.Raw[]; +} diff --git a/src/serialization/resources/webhooks/index.ts b/src/serialization/resources/webhooks/index.ts new file mode 100644 index 0000000..5ec7692 --- /dev/null +++ b/src/serialization/resources/webhooks/index.ts @@ -0,0 +1 @@ +export * from "./client"; diff --git a/src/serialization/types/ActionConfig.ts b/src/serialization/types/ActionConfig.ts new file mode 100644 index 0000000..5cce17f --- /dev/null +++ b/src/serialization/types/ActionConfig.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ActionConfig: core.serialization.ObjectSchema = + core.serialization.object({}); + +export declare namespace ActionConfig { + interface Raw {} +} diff --git a/src/serialization/types/ActionType.ts b/src/serialization/types/ActionType.ts new file mode 100644 index 0000000..bcacfb7 --- /dev/null +++ b/src/serialization/types/ActionType.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ActionType: core.serialization.Schema = + core.serialization.enum_(["action_end_conversation", "action_dtmf"]); + +export declare namespace ActionType { + type Raw = "action_end_conversation" | "action_dtmf"; +} diff --git a/src/serialization/types/Agent.ts b/src/serialization/types/Agent.ts new file mode 100644 index 0000000..8c06135 --- /dev/null +++ b/src/serialization/types/Agent.ts @@ -0,0 +1,29 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const Agent: core.serialization.ObjectSchema = core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + prompt: core.serialization.string(), + actions: core.serialization.list(core.serialization.lazy(async () => (await import("..")).AgentActionsItem)), + voice: core.serialization.lazy(async () => (await import("..")).AgentVoice), + initialMessage: core.serialization.property("initial_message", core.serialization.string().optional()), + webhook: core.serialization.lazy(async () => (await import("..")).AgentWebhook).optional(), +}); + +export declare namespace Agent { + interface Raw { + id: string; + user_id: string; + prompt: string; + actions: serializers.AgentActionsItem.Raw[]; + voice: serializers.AgentVoice.Raw; + initial_message?: string | null; + webhook?: serializers.AgentWebhook.Raw | null; + } +} diff --git a/src/serialization/types/AgentActionsItem.ts b/src/serialization/types/AgentActionsItem.ts new file mode 100644 index 0000000..33df337 --- /dev/null +++ b/src/serialization/types/AgentActionsItem.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentActionsItem: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).EndConversationAction), + core.serialization.lazyObject(async () => (await import("..")).DtmfAction), + ]); + +export declare namespace AgentActionsItem { + type Raw = string | serializers.EndConversationAction.Raw | serializers.DtmfAction.Raw; +} diff --git a/src/serialization/types/AgentParams.ts b/src/serialization/types/AgentParams.ts new file mode 100644 index 0000000..80dc48e --- /dev/null +++ b/src/serialization/types/AgentParams.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentParams: core.serialization.ObjectSchema = + core.serialization.object({ + prompt: core.serialization.string(), + actions: core.serialization + .list(core.serialization.lazy(async () => (await import("..")).AgentParamsActionsItem)) + .optional(), + voice: core.serialization.lazy(async () => (await import("..")).AgentParamsVoice), + initialMessage: core.serialization.property("initial_message", core.serialization.string().optional()), + webhook: core.serialization.lazy(async () => (await import("..")).AgentParamsWebhook).optional(), + }); + +export declare namespace AgentParams { + interface Raw { + prompt: string; + actions?: serializers.AgentParamsActionsItem.Raw[] | null; + voice: serializers.AgentParamsVoice.Raw; + initial_message?: string | null; + webhook?: serializers.AgentParamsWebhook.Raw | null; + } +} diff --git a/src/serialization/types/AgentParamsActionsItem.ts b/src/serialization/types/AgentParamsActionsItem.ts new file mode 100644 index 0000000..548b93f --- /dev/null +++ b/src/serialization/types/AgentParamsActionsItem.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentParamsActionsItem: core.serialization.Schema< + serializers.AgentParamsActionsItem.Raw, + Vocode.AgentParamsActionsItem +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).EndConversationActionParams), + core.serialization.lazyObject(async () => (await import("..")).DtmfActionParams), +]); + +export declare namespace AgentParamsActionsItem { + type Raw = string | serializers.EndConversationActionParams.Raw | serializers.DtmfActionParams.Raw; +} diff --git a/src/serialization/types/AgentParamsVoice.ts b/src/serialization/types/AgentParamsVoice.ts new file mode 100644 index 0000000..23ca27c --- /dev/null +++ b/src/serialization/types/AgentParamsVoice.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentParamsVoice: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).AzureVoiceParams), + core.serialization.lazyObject(async () => (await import("..")).RimeVoiceParams), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoiceParams), + ]); + +export declare namespace AgentParamsVoice { + type Raw = + | string + | serializers.AzureVoiceParams.Raw + | serializers.RimeVoiceParams.Raw + | serializers.ElevenLabsVoiceParams.Raw; +} diff --git a/src/serialization/types/AgentParamsWebhook.ts b/src/serialization/types/AgentParamsWebhook.ts new file mode 100644 index 0000000..14d331e --- /dev/null +++ b/src/serialization/types/AgentParamsWebhook.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentParamsWebhook: core.serialization.Schema< + serializers.AgentParamsWebhook.Raw, + Vocode.AgentParamsWebhook +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).WebhookParams), +]); + +export declare namespace AgentParamsWebhook { + type Raw = string | serializers.WebhookParams.Raw; +} diff --git a/src/serialization/types/AgentUpdateParams.ts b/src/serialization/types/AgentUpdateParams.ts new file mode 100644 index 0000000..4f5f254 --- /dev/null +++ b/src/serialization/types/AgentUpdateParams.ts @@ -0,0 +1,31 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParams: core.serialization.ObjectSchema< + serializers.AgentUpdateParams.Raw, + Vocode.AgentUpdateParams +> = core.serialization.object({ + prompt: core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsPrompt).optional(), + actions: core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsActions).optional(), + voice: core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsVoice).optional(), + initialMessage: core.serialization.property( + "initial_message", + core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsInitialMessage).optional() + ), + webhook: core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsWebhook).optional(), +}); + +export declare namespace AgentUpdateParams { + interface Raw { + prompt?: serializers.AgentUpdateParamsPrompt.Raw | null; + actions?: serializers.AgentUpdateParamsActions.Raw | null; + voice?: serializers.AgentUpdateParamsVoice.Raw | null; + initial_message?: serializers.AgentUpdateParamsInitialMessage.Raw | null; + webhook?: serializers.AgentUpdateParamsWebhook.Raw | null; + } +} diff --git a/src/serialization/types/AgentUpdateParamsActions.ts b/src/serialization/types/AgentUpdateParamsActions.ts new file mode 100644 index 0000000..7dd9f7f --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsActions.ts @@ -0,0 +1,21 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsActions: core.serialization.Schema< + serializers.AgentUpdateParamsActions.Raw, + Vocode.AgentUpdateParamsActions +> = core.serialization.undiscriminatedUnion([ + core.serialization.list( + core.serialization.lazy(async () => (await import("..")).AgentUpdateParamsActionsAgentUpdateParamsActionsItem) + ), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AgentUpdateParamsActions { + type Raw = serializers.AgentUpdateParamsActionsAgentUpdateParamsActionsItem.Raw[] | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts b/src/serialization/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts new file mode 100644 index 0000000..1986edc --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsActionsAgentUpdateParamsActionsItem.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsActionsAgentUpdateParamsActionsItem: core.serialization.Schema< + serializers.AgentUpdateParamsActionsAgentUpdateParamsActionsItem.Raw, + Vocode.AgentUpdateParamsActionsAgentUpdateParamsActionsItem +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).EndConversationActionUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).DtmfActionUpdateParams), +]); + +export declare namespace AgentUpdateParamsActionsAgentUpdateParamsActionsItem { + type Raw = string | serializers.EndConversationActionUpdateParams.Raw | serializers.DtmfActionUpdateParams.Raw; +} diff --git a/src/serialization/types/AgentUpdateParamsInitialMessage.ts b/src/serialization/types/AgentUpdateParamsInitialMessage.ts new file mode 100644 index 0000000..0a0afc5 --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsInitialMessage.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsInitialMessage: core.serialization.Schema< + serializers.AgentUpdateParamsInitialMessage.Raw, + Vocode.AgentUpdateParamsInitialMessage +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AgentUpdateParamsInitialMessage { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AgentUpdateParamsPrompt.ts b/src/serialization/types/AgentUpdateParamsPrompt.ts new file mode 100644 index 0000000..c06af09 --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsPrompt.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsPrompt: core.serialization.Schema< + serializers.AgentUpdateParamsPrompt.Raw, + Vocode.AgentUpdateParamsPrompt +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AgentUpdateParamsPrompt { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AgentUpdateParamsVoice.ts b/src/serialization/types/AgentUpdateParamsVoice.ts new file mode 100644 index 0000000..6251259 --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsVoice.ts @@ -0,0 +1,27 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsVoice: core.serialization.Schema< + serializers.AgentUpdateParamsVoice.Raw, + Vocode.AgentUpdateParamsVoice +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).AzureVoiceUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).RimeVoiceUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoiceUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AgentUpdateParamsVoice { + type Raw = + | string + | serializers.AzureVoiceUpdateParams.Raw + | serializers.RimeVoiceUpdateParams.Raw + | serializers.ElevenLabsVoiceUpdateParams.Raw + | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AgentUpdateParamsWebhook.ts b/src/serialization/types/AgentUpdateParamsWebhook.ts new file mode 100644 index 0000000..21f468f --- /dev/null +++ b/src/serialization/types/AgentUpdateParamsWebhook.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentUpdateParamsWebhook: core.serialization.Schema< + serializers.AgentUpdateParamsWebhook.Raw, + Vocode.AgentUpdateParamsWebhook +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).WebhookUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AgentUpdateParamsWebhook { + type Raw = string | serializers.WebhookUpdateParams.Raw | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AgentVoice.ts b/src/serialization/types/AgentVoice.ts new file mode 100644 index 0000000..f6e3bd2 --- /dev/null +++ b/src/serialization/types/AgentVoice.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentVoice: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).AzureVoice), + core.serialization.lazyObject(async () => (await import("..")).RimeVoice), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoice), + ]); + +export declare namespace AgentVoice { + type Raw = string | serializers.AzureVoice.Raw | serializers.RimeVoice.Raw | serializers.ElevenLabsVoice.Raw; +} diff --git a/src/serialization/types/AgentWebhook.ts b/src/serialization/types/AgentWebhook.ts new file mode 100644 index 0000000..232de45 --- /dev/null +++ b/src/serialization/types/AgentWebhook.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AgentWebhook: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Webhook), + ]); + +export declare namespace AgentWebhook { + type Raw = string | serializers.Webhook.Raw; +} diff --git a/src/serialization/types/AzureVoice.ts b/src/serialization/types/AzureVoice.ts new file mode 100644 index 0000000..acbc7a4 --- /dev/null +++ b/src/serialization/types/AzureVoice.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoice: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + type: core.serialization.lazy(async () => (await import("..")).VoiceType).optional(), + voiceName: core.serialization.property("voice_name", core.serialization.string()), + pitch: core.serialization.number().optional(), + rate: core.serialization.number().optional(), + }); + +export declare namespace AzureVoice { + interface Raw { + id: string; + user_id: string; + type?: serializers.VoiceType.Raw | null; + voice_name: string; + pitch?: number | null; + rate?: number | null; + } +} diff --git a/src/serialization/types/AzureVoiceParams.ts b/src/serialization/types/AzureVoiceParams.ts new file mode 100644 index 0000000..c561e51 --- /dev/null +++ b/src/serialization/types/AzureVoiceParams.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoiceParams: core.serialization.ObjectSchema< + serializers.AzureVoiceParams.Raw, + Vocode.AzureVoiceParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + voiceName: core.serialization.property("voice_name", core.serialization.string()), + pitch: core.serialization.number().optional(), + rate: core.serialization.number().optional(), +}); + +export declare namespace AzureVoiceParams { + interface Raw { + type: serializers.VoiceType.Raw; + voice_name: string; + pitch?: number | null; + rate?: number | null; + } +} diff --git a/src/serialization/types/AzureVoiceUpdateParams.ts b/src/serialization/types/AzureVoiceUpdateParams.ts new file mode 100644 index 0000000..66055c2 --- /dev/null +++ b/src/serialization/types/AzureVoiceUpdateParams.ts @@ -0,0 +1,29 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoiceUpdateParams: core.serialization.ObjectSchema< + serializers.AzureVoiceUpdateParams.Raw, + Vocode.AzureVoiceUpdateParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + voiceName: core.serialization.property( + "voice_name", + core.serialization.lazy(async () => (await import("..")).AzureVoiceUpdateParamsVoiceName).optional() + ), + pitch: core.serialization.lazy(async () => (await import("..")).AzureVoiceUpdateParamsPitch).optional(), + rate: core.serialization.lazy(async () => (await import("..")).AzureVoiceUpdateParamsRate).optional(), +}); + +export declare namespace AzureVoiceUpdateParams { + interface Raw { + type: serializers.VoiceType.Raw; + voice_name?: serializers.AzureVoiceUpdateParamsVoiceName.Raw | null; + pitch?: serializers.AzureVoiceUpdateParamsPitch.Raw | null; + rate?: serializers.AzureVoiceUpdateParamsRate.Raw | null; + } +} diff --git a/src/serialization/types/AzureVoiceUpdateParamsPitch.ts b/src/serialization/types/AzureVoiceUpdateParamsPitch.ts new file mode 100644 index 0000000..01142df --- /dev/null +++ b/src/serialization/types/AzureVoiceUpdateParamsPitch.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoiceUpdateParamsPitch: core.serialization.Schema< + serializers.AzureVoiceUpdateParamsPitch.Raw, + Vocode.AzureVoiceUpdateParamsPitch +> = core.serialization.undiscriminatedUnion([ + core.serialization.number(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AzureVoiceUpdateParamsPitch { + type Raw = number | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AzureVoiceUpdateParamsRate.ts b/src/serialization/types/AzureVoiceUpdateParamsRate.ts new file mode 100644 index 0000000..cd0b888 --- /dev/null +++ b/src/serialization/types/AzureVoiceUpdateParamsRate.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoiceUpdateParamsRate: core.serialization.Schema< + serializers.AzureVoiceUpdateParamsRate.Raw, + Vocode.AzureVoiceUpdateParamsRate +> = core.serialization.undiscriminatedUnion([ + core.serialization.number(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AzureVoiceUpdateParamsRate { + type Raw = number | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/AzureVoiceUpdateParamsVoiceName.ts b/src/serialization/types/AzureVoiceUpdateParamsVoiceName.ts new file mode 100644 index 0000000..8fb8ea5 --- /dev/null +++ b/src/serialization/types/AzureVoiceUpdateParamsVoiceName.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const AzureVoiceUpdateParamsVoiceName: core.serialization.Schema< + serializers.AzureVoiceUpdateParamsVoiceName.Raw, + Vocode.AzureVoiceUpdateParamsVoiceName +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace AzureVoiceUpdateParamsVoiceName { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/Call.ts b/src/serialization/types/Call.ts new file mode 100644 index 0000000..91b8a32 --- /dev/null +++ b/src/serialization/types/Call.ts @@ -0,0 +1,33 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const Call: core.serialization.ObjectSchema = core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + toNumber: core.serialization.property("to_number", core.serialization.string()), + fromNumber: core.serialization.property("from_number", core.serialization.string()), + agent: core.serialization.lazy(async () => (await import("..")).CallAgent), + goal: core.serialization.string().optional(), + transcript: core.serialization.string().optional(), + recordingUrl: core.serialization.property("recording_url", core.serialization.string().optional()), + status: core.serialization.lazy(async () => (await import("..")).CallStatus), +}); + +export declare namespace Call { + interface Raw { + id: string; + user_id: string; + to_number: string; + from_number: string; + agent: serializers.CallAgent.Raw; + goal?: string | null; + transcript?: string | null; + recording_url?: string | null; + status: serializers.CallStatus.Raw; + } +} diff --git a/src/serialization/types/CallAgent.ts b/src/serialization/types/CallAgent.ts new file mode 100644 index 0000000..54590e7 --- /dev/null +++ b/src/serialization/types/CallAgent.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CallAgent: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Agent), + ]); + +export declare namespace CallAgent { + type Raw = string | serializers.Agent.Raw; +} diff --git a/src/serialization/types/CallStatus.ts b/src/serialization/types/CallStatus.ts new file mode 100644 index 0000000..451ce39 --- /dev/null +++ b/src/serialization/types/CallStatus.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CallStatus: core.serialization.Schema = + core.serialization.enum_(["not_started", "in_progress", "error", "ended"]); + +export declare namespace CallStatus { + type Raw = "not_started" | "in_progress" | "error" | "ended"; +} diff --git a/src/serialization/types/CreateActionRequest.ts b/src/serialization/types/CreateActionRequest.ts new file mode 100644 index 0000000..f5a9032 --- /dev/null +++ b/src/serialization/types/CreateActionRequest.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CreateActionRequest: core.serialization.Schema< + serializers.CreateActionRequest.Raw, + Vocode.CreateActionRequest +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationActionParams), + core.serialization.lazyObject(async () => (await import("..")).DtmfActionParams), +]); + +export declare namespace CreateActionRequest { + type Raw = serializers.EndConversationActionParams.Raw | serializers.DtmfActionParams.Raw; +} diff --git a/src/serialization/types/CreateActionResponse.ts b/src/serialization/types/CreateActionResponse.ts new file mode 100644 index 0000000..1f60ac1 --- /dev/null +++ b/src/serialization/types/CreateActionResponse.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CreateActionResponse: core.serialization.Schema< + serializers.CreateActionResponse.Raw, + Vocode.CreateActionResponse +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationAction), + core.serialization.lazyObject(async () => (await import("..")).DtmfAction), +]); + +export declare namespace CreateActionResponse { + type Raw = serializers.EndConversationAction.Raw | serializers.DtmfAction.Raw; +} diff --git a/src/serialization/types/CreateCallRequestAgent.ts b/src/serialization/types/CreateCallRequestAgent.ts new file mode 100644 index 0000000..1266767 --- /dev/null +++ b/src/serialization/types/CreateCallRequestAgent.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CreateCallRequestAgent: core.serialization.Schema< + serializers.CreateCallRequestAgent.Raw, + Vocode.CreateCallRequestAgent +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).AgentParams), +]); + +export declare namespace CreateCallRequestAgent { + type Raw = string | serializers.AgentParams.Raw; +} diff --git a/src/serialization/types/CreateVoiceRequest.ts b/src/serialization/types/CreateVoiceRequest.ts new file mode 100644 index 0000000..fddb15c --- /dev/null +++ b/src/serialization/types/CreateVoiceRequest.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CreateVoiceRequest: core.serialization.Schema< + serializers.CreateVoiceRequest.Raw, + Vocode.CreateVoiceRequest +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoiceParams), + core.serialization.lazyObject(async () => (await import("..")).RimeVoiceParams), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoiceParams), +]); + +export declare namespace CreateVoiceRequest { + type Raw = + | serializers.AzureVoiceParams.Raw + | serializers.RimeVoiceParams.Raw + | serializers.ElevenLabsVoiceParams.Raw; +} diff --git a/src/serialization/types/CreateVoiceResponse.ts b/src/serialization/types/CreateVoiceResponse.ts new file mode 100644 index 0000000..74c0f9a --- /dev/null +++ b/src/serialization/types/CreateVoiceResponse.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const CreateVoiceResponse: core.serialization.Schema< + serializers.CreateVoiceResponse.Raw, + Vocode.CreateVoiceResponse +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoice), + core.serialization.lazyObject(async () => (await import("..")).RimeVoice), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoice), +]); + +export declare namespace CreateVoiceResponse { + type Raw = serializers.AzureVoice.Raw | serializers.RimeVoice.Raw | serializers.ElevenLabsVoice.Raw; +} diff --git a/src/serialization/types/DtmfAction.ts b/src/serialization/types/DtmfAction.ts new file mode 100644 index 0000000..a24edfc --- /dev/null +++ b/src/serialization/types/DtmfAction.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const DtmfAction: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + type: core.serialization.lazy(async () => (await import("..")).ActionType).optional(), + config: core.serialization.lazyObject(async () => (await import("..")).ActionConfig).optional(), + }); + +export declare namespace DtmfAction { + interface Raw { + id: string; + user_id: string; + type?: serializers.ActionType.Raw | null; + config?: serializers.ActionConfig.Raw | null; + } +} diff --git a/src/serialization/types/DtmfActionParams.ts b/src/serialization/types/DtmfActionParams.ts new file mode 100644 index 0000000..513cdaf --- /dev/null +++ b/src/serialization/types/DtmfActionParams.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const DtmfActionParams: core.serialization.ObjectSchema< + serializers.DtmfActionParams.Raw, + Vocode.DtmfActionParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).ActionType), + config: core.serialization.lazyObject(async () => (await import("..")).ActionConfig).optional(), +}); + +export declare namespace DtmfActionParams { + interface Raw { + type: serializers.ActionType.Raw; + config?: serializers.ActionConfig.Raw | null; + } +} diff --git a/src/serialization/types/DtmfActionUpdateParams.ts b/src/serialization/types/DtmfActionUpdateParams.ts new file mode 100644 index 0000000..1b1f12e --- /dev/null +++ b/src/serialization/types/DtmfActionUpdateParams.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const DtmfActionUpdateParams: core.serialization.ObjectSchema< + serializers.DtmfActionUpdateParams.Raw, + Vocode.DtmfActionUpdateParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).ActionType), + config: core.serialization.lazy(async () => (await import("..")).DtmfActionUpdateParamsConfig).optional(), +}); + +export declare namespace DtmfActionUpdateParams { + interface Raw { + type: serializers.ActionType.Raw; + config?: serializers.DtmfActionUpdateParamsConfig.Raw | null; + } +} diff --git a/src/serialization/types/DtmfActionUpdateParamsConfig.ts b/src/serialization/types/DtmfActionUpdateParamsConfig.ts new file mode 100644 index 0000000..534bd80 --- /dev/null +++ b/src/serialization/types/DtmfActionUpdateParamsConfig.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const DtmfActionUpdateParamsConfig: core.serialization.Schema< + serializers.DtmfActionUpdateParamsConfig.Raw, + Vocode.DtmfActionUpdateParamsConfig +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).ActionConfig), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace DtmfActionUpdateParamsConfig { + type Raw = serializers.ActionConfig.Raw | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/ElevenLabsVoice.ts b/src/serialization/types/ElevenLabsVoice.ts new file mode 100644 index 0000000..bd83ee5 --- /dev/null +++ b/src/serialization/types/ElevenLabsVoice.ts @@ -0,0 +1,30 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoice: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + type: core.serialization.lazy(async () => (await import("..")).VoiceType).optional(), + voiceId: core.serialization.property("voice_id", core.serialization.string()), + stability: core.serialization.number().optional(), + similarityBoost: core.serialization.property("similarity_boost", core.serialization.number().optional()), + apiKey: core.serialization.property("api_key", core.serialization.string()), + }); + +export declare namespace ElevenLabsVoice { + interface Raw { + id: string; + user_id: string; + type?: serializers.VoiceType.Raw | null; + voice_id: string; + stability?: number | null; + similarity_boost?: number | null; + api_key: string; + } +} diff --git a/src/serialization/types/ElevenLabsVoiceParams.ts b/src/serialization/types/ElevenLabsVoiceParams.ts new file mode 100644 index 0000000..7d39e66 --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceParams.ts @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceParams: core.serialization.ObjectSchema< + serializers.ElevenLabsVoiceParams.Raw, + Vocode.ElevenLabsVoiceParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + voiceId: core.serialization.property("voice_id", core.serialization.string()), + stability: core.serialization.number().optional(), + similarityBoost: core.serialization.property("similarity_boost", core.serialization.number().optional()), + apiKey: core.serialization.property("api_key", core.serialization.string()), +}); + +export declare namespace ElevenLabsVoiceParams { + interface Raw { + type: serializers.VoiceType.Raw; + voice_id: string; + stability?: number | null; + similarity_boost?: number | null; + api_key: string; + } +} diff --git a/src/serialization/types/ElevenLabsVoiceUpdateParams.ts b/src/serialization/types/ElevenLabsVoiceUpdateParams.ts new file mode 100644 index 0000000..181af3c --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceUpdateParams.ts @@ -0,0 +1,39 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceUpdateParams: core.serialization.ObjectSchema< + serializers.ElevenLabsVoiceUpdateParams.Raw, + Vocode.ElevenLabsVoiceUpdateParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + voiceId: core.serialization.property( + "voice_id", + core.serialization.lazy(async () => (await import("..")).ElevenLabsVoiceUpdateParamsVoiceId).optional() + ), + stability: core.serialization + .lazy(async () => (await import("..")).ElevenLabsVoiceUpdateParamsStability) + .optional(), + similarityBoost: core.serialization.property( + "similarity_boost", + core.serialization.lazy(async () => (await import("..")).ElevenLabsVoiceUpdateParamsSimilarityBoost).optional() + ), + apiKey: core.serialization.property( + "api_key", + core.serialization.lazy(async () => (await import("..")).ElevenLabsVoiceUpdateParamsApiKey).optional() + ), +}); + +export declare namespace ElevenLabsVoiceUpdateParams { + interface Raw { + type: serializers.VoiceType.Raw; + voice_id?: serializers.ElevenLabsVoiceUpdateParamsVoiceId.Raw | null; + stability?: serializers.ElevenLabsVoiceUpdateParamsStability.Raw | null; + similarity_boost?: serializers.ElevenLabsVoiceUpdateParamsSimilarityBoost.Raw | null; + api_key?: serializers.ElevenLabsVoiceUpdateParamsApiKey.Raw | null; + } +} diff --git a/src/serialization/types/ElevenLabsVoiceUpdateParamsApiKey.ts b/src/serialization/types/ElevenLabsVoiceUpdateParamsApiKey.ts new file mode 100644 index 0000000..c336b1f --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceUpdateParamsApiKey.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceUpdateParamsApiKey: core.serialization.Schema< + serializers.ElevenLabsVoiceUpdateParamsApiKey.Raw, + Vocode.ElevenLabsVoiceUpdateParamsApiKey +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace ElevenLabsVoiceUpdateParamsApiKey { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts b/src/serialization/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts new file mode 100644 index 0000000..dd0d8f0 --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceUpdateParamsSimilarityBoost.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceUpdateParamsSimilarityBoost: core.serialization.Schema< + serializers.ElevenLabsVoiceUpdateParamsSimilarityBoost.Raw, + Vocode.ElevenLabsVoiceUpdateParamsSimilarityBoost +> = core.serialization.undiscriminatedUnion([ + core.serialization.number(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace ElevenLabsVoiceUpdateParamsSimilarityBoost { + type Raw = number | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/ElevenLabsVoiceUpdateParamsStability.ts b/src/serialization/types/ElevenLabsVoiceUpdateParamsStability.ts new file mode 100644 index 0000000..5fe312b --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceUpdateParamsStability.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceUpdateParamsStability: core.serialization.Schema< + serializers.ElevenLabsVoiceUpdateParamsStability.Raw, + Vocode.ElevenLabsVoiceUpdateParamsStability +> = core.serialization.undiscriminatedUnion([ + core.serialization.number(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace ElevenLabsVoiceUpdateParamsStability { + type Raw = number | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/ElevenLabsVoiceUpdateParamsVoiceId.ts b/src/serialization/types/ElevenLabsVoiceUpdateParamsVoiceId.ts new file mode 100644 index 0000000..370590a --- /dev/null +++ b/src/serialization/types/ElevenLabsVoiceUpdateParamsVoiceId.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ElevenLabsVoiceUpdateParamsVoiceId: core.serialization.Schema< + serializers.ElevenLabsVoiceUpdateParamsVoiceId.Raw, + Vocode.ElevenLabsVoiceUpdateParamsVoiceId +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace ElevenLabsVoiceUpdateParamsVoiceId { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/EndConversationAction.ts b/src/serialization/types/EndConversationAction.ts new file mode 100644 index 0000000..1da087e --- /dev/null +++ b/src/serialization/types/EndConversationAction.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const EndConversationAction: core.serialization.ObjectSchema< + serializers.EndConversationAction.Raw, + Vocode.EndConversationAction +> = core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + type: core.serialization.lazy(async () => (await import("..")).ActionType).optional(), + config: core.serialization.lazyObject(async () => (await import("..")).ActionConfig).optional(), +}); + +export declare namespace EndConversationAction { + interface Raw { + id: string; + user_id: string; + type?: serializers.ActionType.Raw | null; + config?: serializers.ActionConfig.Raw | null; + } +} diff --git a/src/serialization/types/EndConversationActionParams.ts b/src/serialization/types/EndConversationActionParams.ts new file mode 100644 index 0000000..17f6964 --- /dev/null +++ b/src/serialization/types/EndConversationActionParams.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const EndConversationActionParams: core.serialization.ObjectSchema< + serializers.EndConversationActionParams.Raw, + Vocode.EndConversationActionParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).ActionType), + config: core.serialization.lazyObject(async () => (await import("..")).ActionConfig).optional(), +}); + +export declare namespace EndConversationActionParams { + interface Raw { + type: serializers.ActionType.Raw; + config?: serializers.ActionConfig.Raw | null; + } +} diff --git a/src/serialization/types/EndConversationActionUpdateParams.ts b/src/serialization/types/EndConversationActionUpdateParams.ts new file mode 100644 index 0000000..70dc857 --- /dev/null +++ b/src/serialization/types/EndConversationActionUpdateParams.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const EndConversationActionUpdateParams: core.serialization.ObjectSchema< + serializers.EndConversationActionUpdateParams.Raw, + Vocode.EndConversationActionUpdateParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).ActionType), + config: core.serialization + .lazy(async () => (await import("..")).EndConversationActionUpdateParamsConfig) + .optional(), +}); + +export declare namespace EndConversationActionUpdateParams { + interface Raw { + type: serializers.ActionType.Raw; + config?: serializers.EndConversationActionUpdateParamsConfig.Raw | null; + } +} diff --git a/src/serialization/types/EndConversationActionUpdateParamsConfig.ts b/src/serialization/types/EndConversationActionUpdateParamsConfig.ts new file mode 100644 index 0000000..8f62354 --- /dev/null +++ b/src/serialization/types/EndConversationActionUpdateParamsConfig.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const EndConversationActionUpdateParamsConfig: core.serialization.Schema< + serializers.EndConversationActionUpdateParamsConfig.Raw, + Vocode.EndConversationActionUpdateParamsConfig +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).ActionConfig), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace EndConversationActionUpdateParamsConfig { + type Raw = serializers.ActionConfig.Raw | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/EventType.ts b/src/serialization/types/EventType.ts new file mode 100644 index 0000000..f5e4922 --- /dev/null +++ b/src/serialization/types/EventType.ts @@ -0,0 +1,27 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const EventType: core.serialization.Schema = + core.serialization.enum_([ + "event_message", + "event_action", + "event_phone_call_connected", + "event_phone_call_ended", + "event_transcript", + "event_recording", + ]); + +export declare namespace EventType { + type Raw = + | "event_message" + | "event_action" + | "event_phone_call_connected" + | "event_phone_call_ended" + | "event_transcript" + | "event_recording"; +} diff --git a/src/serialization/types/GetActionResponse.ts b/src/serialization/types/GetActionResponse.ts new file mode 100644 index 0000000..bd88593 --- /dev/null +++ b/src/serialization/types/GetActionResponse.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const GetActionResponse: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationAction), + core.serialization.lazyObject(async () => (await import("..")).DtmfAction), + ]); + +export declare namespace GetActionResponse { + type Raw = serializers.EndConversationAction.Raw | serializers.DtmfAction.Raw; +} diff --git a/src/serialization/types/GetVoiceResponse.ts b/src/serialization/types/GetVoiceResponse.ts new file mode 100644 index 0000000..e5436a5 --- /dev/null +++ b/src/serialization/types/GetVoiceResponse.ts @@ -0,0 +1,18 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const GetVoiceResponse: core.serialization.Schema = + core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoice), + core.serialization.lazyObject(async () => (await import("..")).RimeVoice), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoice), + ]); + +export declare namespace GetVoiceResponse { + type Raw = serializers.AzureVoice.Raw | serializers.RimeVoice.Raw | serializers.ElevenLabsVoice.Raw; +} diff --git a/src/serialization/types/HttpMethod.ts b/src/serialization/types/HttpMethod.ts new file mode 100644 index 0000000..ca38efe --- /dev/null +++ b/src/serialization/types/HttpMethod.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const HttpMethod: core.serialization.Schema = + core.serialization.enum_(["GET", "POST"]); + +export declare namespace HttpMethod { + type Raw = "GET" | "POST"; +} diff --git a/src/serialization/types/HttpValidationError.ts b/src/serialization/types/HttpValidationError.ts new file mode 100644 index 0000000..fdc1cd2 --- /dev/null +++ b/src/serialization/types/HttpValidationError.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const HttpValidationError: core.serialization.ObjectSchema< + serializers.HttpValidationError.Raw, + Vocode.HttpValidationError +> = core.serialization.object({ + detail: core.serialization + .list(core.serialization.lazyObject(async () => (await import("..")).ValidationError)) + .optional(), +}); + +export declare namespace HttpValidationError { + interface Raw { + detail?: serializers.ValidationError.Raw[] | null; + } +} diff --git a/src/serialization/types/ListActionsResponseItem.ts b/src/serialization/types/ListActionsResponseItem.ts new file mode 100644 index 0000000..fde0be7 --- /dev/null +++ b/src/serialization/types/ListActionsResponseItem.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ListActionsResponseItem: core.serialization.Schema< + serializers.ListActionsResponseItem.Raw, + Vocode.ListActionsResponseItem +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationAction), + core.serialization.lazyObject(async () => (await import("..")).DtmfAction), +]); + +export declare namespace ListActionsResponseItem { + type Raw = serializers.EndConversationAction.Raw | serializers.DtmfAction.Raw; +} diff --git a/src/serialization/types/ListVoicesResponseItem.ts b/src/serialization/types/ListVoicesResponseItem.ts new file mode 100644 index 0000000..4060cc6 --- /dev/null +++ b/src/serialization/types/ListVoicesResponseItem.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ListVoicesResponseItem: core.serialization.Schema< + serializers.ListVoicesResponseItem.Raw, + Vocode.ListVoicesResponseItem +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoice), + core.serialization.lazyObject(async () => (await import("..")).RimeVoice), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoice), +]); + +export declare namespace ListVoicesResponseItem { + type Raw = serializers.AzureVoice.Raw | serializers.RimeVoice.Raw | serializers.ElevenLabsVoice.Raw; +} diff --git a/src/serialization/types/PhoneNumber.ts b/src/serialization/types/PhoneNumber.ts new file mode 100644 index 0000000..c61eade --- /dev/null +++ b/src/serialization/types/PhoneNumber.ts @@ -0,0 +1,29 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const PhoneNumber: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + number: core.serialization.string(), + active: core.serialization.boolean(), + inboundAgent: core.serialization.property( + "inbound_agent", + core.serialization.lazy(async () => (await import("..")).PhoneNumberInboundAgent) + ), + }); + +export declare namespace PhoneNumber { + interface Raw { + id: string; + user_id: string; + number: string; + active: boolean; + inbound_agent: serializers.PhoneNumberInboundAgent.Raw; + } +} diff --git a/src/serialization/types/PhoneNumberInboundAgent.ts b/src/serialization/types/PhoneNumberInboundAgent.ts new file mode 100644 index 0000000..cc1d57d --- /dev/null +++ b/src/serialization/types/PhoneNumberInboundAgent.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const PhoneNumberInboundAgent: core.serialization.Schema< + serializers.PhoneNumberInboundAgent.Raw, + Vocode.PhoneNumberInboundAgent +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Agent), +]); + +export declare namespace PhoneNumberInboundAgent { + type Raw = string | serializers.Agent.Raw; +} diff --git a/src/serialization/types/PlanType.ts b/src/serialization/types/PlanType.ts new file mode 100644 index 0000000..714de09 --- /dev/null +++ b/src/serialization/types/PlanType.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const PlanType: core.serialization.Schema = core.serialization.enum_([ + "free", + "developer", + "enterprise", +]); + +export declare namespace PlanType { + type Raw = "free" | "developer" | "enterprise"; +} diff --git a/src/serialization/types/RimeVoice.ts b/src/serialization/types/RimeVoice.ts new file mode 100644 index 0000000..4deaa20 --- /dev/null +++ b/src/serialization/types/RimeVoice.ts @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const RimeVoice: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + type: core.serialization.lazy(async () => (await import("..")).VoiceType).optional(), + speaker: core.serialization.string(), + }); + +export declare namespace RimeVoice { + interface Raw { + id: string; + user_id: string; + type?: serializers.VoiceType.Raw | null; + speaker: string; + } +} diff --git a/src/serialization/types/RimeVoiceParams.ts b/src/serialization/types/RimeVoiceParams.ts new file mode 100644 index 0000000..69d08b6 --- /dev/null +++ b/src/serialization/types/RimeVoiceParams.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const RimeVoiceParams: core.serialization.ObjectSchema = + core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + speaker: core.serialization.string(), + }); + +export declare namespace RimeVoiceParams { + interface Raw { + type: serializers.VoiceType.Raw; + speaker: string; + } +} diff --git a/src/serialization/types/RimeVoiceUpdateParams.ts b/src/serialization/types/RimeVoiceUpdateParams.ts new file mode 100644 index 0000000..8e67d4e --- /dev/null +++ b/src/serialization/types/RimeVoiceUpdateParams.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const RimeVoiceUpdateParams: core.serialization.ObjectSchema< + serializers.RimeVoiceUpdateParams.Raw, + Vocode.RimeVoiceUpdateParams +> = core.serialization.object({ + type: core.serialization.lazy(async () => (await import("..")).VoiceType), + speaker: core.serialization.lazy(async () => (await import("..")).RimeVoiceUpdateParamsSpeaker).optional(), +}); + +export declare namespace RimeVoiceUpdateParams { + interface Raw { + type: serializers.VoiceType.Raw; + speaker?: serializers.RimeVoiceUpdateParamsSpeaker.Raw | null; + } +} diff --git a/src/serialization/types/RimeVoiceUpdateParamsSpeaker.ts b/src/serialization/types/RimeVoiceUpdateParamsSpeaker.ts new file mode 100644 index 0000000..d78c58c --- /dev/null +++ b/src/serialization/types/RimeVoiceUpdateParamsSpeaker.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const RimeVoiceUpdateParamsSpeaker: core.serialization.Schema< + serializers.RimeVoiceUpdateParamsSpeaker.Raw, + Vocode.RimeVoiceUpdateParamsSpeaker +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace RimeVoiceUpdateParamsSpeaker { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/Undefined.ts b/src/serialization/types/Undefined.ts new file mode 100644 index 0000000..46b7b75 --- /dev/null +++ b/src/serialization/types/Undefined.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const Undefined: core.serialization.ObjectSchema = + core.serialization.object({}); + +export declare namespace Undefined { + interface Raw {} +} diff --git a/src/serialization/types/UpdateActionRequestBody.ts b/src/serialization/types/UpdateActionRequestBody.ts new file mode 100644 index 0000000..ffb68e9 --- /dev/null +++ b/src/serialization/types/UpdateActionRequestBody.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const UpdateActionRequestBody: core.serialization.Schema< + serializers.UpdateActionRequestBody.Raw, + Vocode.UpdateActionRequestBody +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationActionUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).DtmfActionUpdateParams), +]); + +export declare namespace UpdateActionRequestBody { + type Raw = serializers.EndConversationActionUpdateParams.Raw | serializers.DtmfActionUpdateParams.Raw; +} diff --git a/src/serialization/types/UpdateActionResponse.ts b/src/serialization/types/UpdateActionResponse.ts new file mode 100644 index 0000000..e0b5326 --- /dev/null +++ b/src/serialization/types/UpdateActionResponse.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const UpdateActionResponse: core.serialization.Schema< + serializers.UpdateActionResponse.Raw, + Vocode.UpdateActionResponse +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).EndConversationAction), + core.serialization.lazyObject(async () => (await import("..")).DtmfAction), +]); + +export declare namespace UpdateActionResponse { + type Raw = serializers.EndConversationAction.Raw | serializers.DtmfAction.Raw; +} diff --git a/src/serialization/types/UpdateNumberRequestInboundAgent.ts b/src/serialization/types/UpdateNumberRequestInboundAgent.ts new file mode 100644 index 0000000..c19cd56 --- /dev/null +++ b/src/serialization/types/UpdateNumberRequestInboundAgent.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const UpdateNumberRequestInboundAgent: core.serialization.Schema< + serializers.UpdateNumberRequestInboundAgent.Raw, + Vocode.UpdateNumberRequestInboundAgent +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).AgentUpdateParams), +]); + +export declare namespace UpdateNumberRequestInboundAgent { + type Raw = string | serializers.AgentUpdateParams.Raw; +} diff --git a/src/serialization/types/UpdateVoiceRequestBody.ts b/src/serialization/types/UpdateVoiceRequestBody.ts new file mode 100644 index 0000000..55f950a --- /dev/null +++ b/src/serialization/types/UpdateVoiceRequestBody.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const UpdateVoiceRequestBody: core.serialization.Schema< + serializers.UpdateVoiceRequestBody.Raw, + Vocode.UpdateVoiceRequestBody +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoiceUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).RimeVoiceUpdateParams), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoiceUpdateParams), +]); + +export declare namespace UpdateVoiceRequestBody { + type Raw = + | serializers.AzureVoiceUpdateParams.Raw + | serializers.RimeVoiceUpdateParams.Raw + | serializers.ElevenLabsVoiceUpdateParams.Raw; +} diff --git a/src/serialization/types/UpdateVoiceResponse.ts b/src/serialization/types/UpdateVoiceResponse.ts new file mode 100644 index 0000000..04bf55a --- /dev/null +++ b/src/serialization/types/UpdateVoiceResponse.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const UpdateVoiceResponse: core.serialization.Schema< + serializers.UpdateVoiceResponse.Raw, + Vocode.UpdateVoiceResponse +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazyObject(async () => (await import("..")).AzureVoice), + core.serialization.lazyObject(async () => (await import("..")).RimeVoice), + core.serialization.lazyObject(async () => (await import("..")).ElevenLabsVoice), +]); + +export declare namespace UpdateVoiceResponse { + type Raw = serializers.AzureVoice.Raw | serializers.RimeVoice.Raw | serializers.ElevenLabsVoice.Raw; +} diff --git a/src/serialization/types/Usage.ts b/src/serialization/types/Usage.ts new file mode 100644 index 0000000..d9558e0 --- /dev/null +++ b/src/serialization/types/Usage.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const Usage: core.serialization.ObjectSchema = core.serialization.object({ + userId: core.serialization.property("user_id", core.serialization.string()), + planType: core.serialization.property( + "plan_type", + core.serialization.lazy(async () => (await import("..")).PlanType) + ), + monthlyUsageMinutes: core.serialization.property("monthly_usage_minutes", core.serialization.number()), + monthlyUsageLimitMinutes: core.serialization.property("monthly_usage_limit_minutes", core.serialization.number()), +}); + +export declare namespace Usage { + interface Raw { + user_id: string; + plan_type: serializers.PlanType.Raw; + monthly_usage_minutes: number; + monthly_usage_limit_minutes: number; + } +} diff --git a/src/serialization/types/ValidationError.ts b/src/serialization/types/ValidationError.ts new file mode 100644 index 0000000..8a9c12a --- /dev/null +++ b/src/serialization/types/ValidationError.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ValidationError: core.serialization.ObjectSchema = + core.serialization.object({ + loc: core.serialization.list(core.serialization.lazy(async () => (await import("..")).ValidationErrorLocItem)), + msg: core.serialization.string(), + type: core.serialization.string(), + }); + +export declare namespace ValidationError { + interface Raw { + loc: serializers.ValidationErrorLocItem.Raw[]; + msg: string; + type: string; + } +} diff --git a/src/serialization/types/ValidationErrorLocItem.ts b/src/serialization/types/ValidationErrorLocItem.ts new file mode 100644 index 0000000..78d65f9 --- /dev/null +++ b/src/serialization/types/ValidationErrorLocItem.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const ValidationErrorLocItem: core.serialization.Schema< + serializers.ValidationErrorLocItem.Raw, + Vocode.ValidationErrorLocItem +> = core.serialization.undiscriminatedUnion([core.serialization.string(), core.serialization.number()]); + +export declare namespace ValidationErrorLocItem { + type Raw = string | number; +} diff --git a/src/serialization/types/VoiceType.ts b/src/serialization/types/VoiceType.ts new file mode 100644 index 0000000..9536b5d --- /dev/null +++ b/src/serialization/types/VoiceType.ts @@ -0,0 +1,14 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const VoiceType: core.serialization.Schema = + core.serialization.enum_(["voice_base", "voice_azure", "voice_rime", "voice_eleven_labs"]); + +export declare namespace VoiceType { + type Raw = "voice_base" | "voice_azure" | "voice_rime" | "voice_eleven_labs"; +} diff --git a/src/serialization/types/Webhook.ts b/src/serialization/types/Webhook.ts new file mode 100644 index 0000000..d907f5a --- /dev/null +++ b/src/serialization/types/Webhook.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const Webhook: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + userId: core.serialization.property("user_id", core.serialization.string()), + subscriptions: core.serialization.list(core.serialization.lazy(async () => (await import("..")).EventType)), + url: core.serialization.string(), + method: core.serialization.lazy(async () => (await import("..")).HttpMethod).optional(), + }); + +export declare namespace Webhook { + interface Raw { + id: string; + user_id: string; + subscriptions: serializers.EventType.Raw[]; + url: string; + method?: serializers.HttpMethod.Raw | null; + } +} diff --git a/src/serialization/types/WebhookParams.ts b/src/serialization/types/WebhookParams.ts new file mode 100644 index 0000000..72d7b11 --- /dev/null +++ b/src/serialization/types/WebhookParams.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const WebhookParams: core.serialization.ObjectSchema = + core.serialization.object({ + subscriptions: core.serialization.list(core.serialization.lazy(async () => (await import("..")).EventType)), + url: core.serialization.string(), + method: core.serialization.lazy(async () => (await import("..")).HttpMethod).optional(), + }); + +export declare namespace WebhookParams { + interface Raw { + subscriptions: serializers.EventType.Raw[]; + url: string; + method?: serializers.HttpMethod.Raw | null; + } +} diff --git a/src/serialization/types/WebhookUpdateParams.ts b/src/serialization/types/WebhookUpdateParams.ts new file mode 100644 index 0000000..783517d --- /dev/null +++ b/src/serialization/types/WebhookUpdateParams.ts @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const WebhookUpdateParams: core.serialization.ObjectSchema< + serializers.WebhookUpdateParams.Raw, + Vocode.WebhookUpdateParams +> = core.serialization.object({ + subscriptions: core.serialization + .lazy(async () => (await import("..")).WebhookUpdateParamsSubscriptions) + .optional(), + url: core.serialization.lazy(async () => (await import("..")).WebhookUpdateParamsUrl).optional(), + method: core.serialization.lazy(async () => (await import("..")).WebhookUpdateParamsMethod).optional(), +}); + +export declare namespace WebhookUpdateParams { + interface Raw { + subscriptions?: serializers.WebhookUpdateParamsSubscriptions.Raw | null; + url?: serializers.WebhookUpdateParamsUrl.Raw | null; + method?: serializers.WebhookUpdateParamsMethod.Raw | null; + } +} diff --git a/src/serialization/types/WebhookUpdateParamsMethod.ts b/src/serialization/types/WebhookUpdateParamsMethod.ts new file mode 100644 index 0000000..2f6b339 --- /dev/null +++ b/src/serialization/types/WebhookUpdateParamsMethod.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const WebhookUpdateParamsMethod: core.serialization.Schema< + serializers.WebhookUpdateParamsMethod.Raw, + Vocode.WebhookUpdateParamsMethod +> = core.serialization.undiscriminatedUnion([ + core.serialization.lazy(async () => (await import("..")).HttpMethod), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace WebhookUpdateParamsMethod { + type Raw = serializers.HttpMethod.Raw | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/WebhookUpdateParamsSubscriptions.ts b/src/serialization/types/WebhookUpdateParamsSubscriptions.ts new file mode 100644 index 0000000..a63cadf --- /dev/null +++ b/src/serialization/types/WebhookUpdateParamsSubscriptions.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const WebhookUpdateParamsSubscriptions: core.serialization.Schema< + serializers.WebhookUpdateParamsSubscriptions.Raw, + Vocode.WebhookUpdateParamsSubscriptions +> = core.serialization.undiscriminatedUnion([ + core.serialization.list(core.serialization.lazy(async () => (await import("..")).EventType)), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace WebhookUpdateParamsSubscriptions { + type Raw = serializers.EventType.Raw[] | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/WebhookUpdateParamsUrl.ts b/src/serialization/types/WebhookUpdateParamsUrl.ts new file mode 100644 index 0000000..d662992 --- /dev/null +++ b/src/serialization/types/WebhookUpdateParamsUrl.ts @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from ".."; +import * as Vocode from "../../api"; +import * as core from "../../core"; + +export const WebhookUpdateParamsUrl: core.serialization.Schema< + serializers.WebhookUpdateParamsUrl.Raw, + Vocode.WebhookUpdateParamsUrl +> = core.serialization.undiscriminatedUnion([ + core.serialization.string(), + core.serialization.lazyObject(async () => (await import("..")).Undefined), +]); + +export declare namespace WebhookUpdateParamsUrl { + type Raw = string | serializers.Undefined.Raw; +} diff --git a/src/serialization/types/index.ts b/src/serialization/types/index.ts new file mode 100644 index 0000000..0752b59 --- /dev/null +++ b/src/serialization/types/index.ts @@ -0,0 +1,76 @@ +export * from "./UpdateNumberRequestInboundAgent"; +export * from "./CreateCallRequestAgent"; +export * from "./GetActionResponse"; +export * from "./ListActionsResponseItem"; +export * from "./CreateActionRequest"; +export * from "./CreateActionResponse"; +export * from "./UpdateActionRequestBody"; +export * from "./UpdateActionResponse"; +export * from "./AgentParams"; +export * from "./AgentParamsActionsItem"; +export * from "./AgentParamsVoice"; +export * from "./AgentParamsWebhook"; +export * from "./AgentUpdateParams"; +export * from "./AgentUpdateParamsPrompt"; +export * from "./AgentUpdateParamsActions"; +export * from "./AgentUpdateParamsActionsAgentUpdateParamsActionsItem"; +export * from "./AgentUpdateParamsVoice"; +export * from "./AgentUpdateParamsInitialMessage"; +export * from "./AgentUpdateParamsWebhook"; +export * from "./GetVoiceResponse"; +export * from "./ListVoicesResponseItem"; +export * from "./CreateVoiceRequest"; +export * from "./CreateVoiceResponse"; +export * from "./UpdateVoiceRequestBody"; +export * from "./UpdateVoiceResponse"; +export * from "./WebhookParams"; +export * from "./WebhookUpdateParams"; +export * from "./WebhookUpdateParamsSubscriptions"; +export * from "./WebhookUpdateParamsUrl"; +export * from "./WebhookUpdateParamsMethod"; +export * from "./ActionConfig"; +export * from "./ActionType"; +export * from "./Agent"; +export * from "./AgentActionsItem"; +export * from "./AgentVoice"; +export * from "./AgentWebhook"; +export * from "./AzureVoice"; +export * from "./AzureVoiceParams"; +export * from "./AzureVoiceUpdateParams"; +export * from "./AzureVoiceUpdateParamsVoiceName"; +export * from "./AzureVoiceUpdateParamsPitch"; +export * from "./AzureVoiceUpdateParamsRate"; +export * from "./Call"; +export * from "./CallAgent"; +export * from "./CallStatus"; +export * from "./DtmfAction"; +export * from "./DtmfActionParams"; +export * from "./DtmfActionUpdateParams"; +export * from "./DtmfActionUpdateParamsConfig"; +export * from "./ElevenLabsVoice"; +export * from "./ElevenLabsVoiceParams"; +export * from "./ElevenLabsVoiceUpdateParams"; +export * from "./ElevenLabsVoiceUpdateParamsVoiceId"; +export * from "./ElevenLabsVoiceUpdateParamsStability"; +export * from "./ElevenLabsVoiceUpdateParamsSimilarityBoost"; +export * from "./ElevenLabsVoiceUpdateParamsApiKey"; +export * from "./EndConversationAction"; +export * from "./EndConversationActionParams"; +export * from "./EndConversationActionUpdateParams"; +export * from "./EndConversationActionUpdateParamsConfig"; +export * from "./EventType"; +export * from "./HttpMethod"; +export * from "./HttpValidationError"; +export * from "./PhoneNumber"; +export * from "./PhoneNumberInboundAgent"; +export * from "./PlanType"; +export * from "./RimeVoice"; +export * from "./RimeVoiceParams"; +export * from "./RimeVoiceUpdateParams"; +export * from "./RimeVoiceUpdateParamsSpeaker"; +export * from "./Undefined"; +export * from "./Usage"; +export * from "./ValidationError"; +export * from "./ValidationErrorLocItem"; +export * from "./VoiceType"; +export * from "./Webhook"; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e65fa53 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "extendedDiagnostics": true, + "strict": true, + "target": "ES6", + "module": "CommonJS", + "moduleResolution": "node", + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true, + "noUnusedParameters": true, + "outDir": "dist", + "rootDir": "src", + "baseUrl": "src" + }, + "include": [ + "src" + ], + "exclude": [] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..a79fdb4 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,95 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/node@17.0.33": + version "17.0.33" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.33.tgz#3c1879b276dc63e73030bb91165e62a4509cd506" + integrity sha512-miWq2m2FiQZmaHfdZNcbpp9PuXg34W5JZ5CrJ/BaS70VuhoJENBEQybeiYSaPBRNq6KQGnjfEnc/F3PN++D+XQ== + +"@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== + +"@ungap/url-search-params@0.2.2": + version "0.2.2" + resolved "https://registry.yarnpkg.com/@ungap/url-search-params/-/url-search-params-0.2.2.tgz#2de3bdec21476a9b70ef11fd7b794752f9afa04c" + integrity sha512-qQsguKXZVKdCixOHX9jqnX/K/1HekPDpGKyEcXHT+zR6EjGA7S4boSuelL4uuPv6YfhN0n8c4UxW+v/Z3gM2iw== + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + +axios@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" + integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + +follow-redirects@^1.15.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + +js-base64@3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745" + integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ== + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +prettier@2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + +typescript@4.6.4: + version "4.6.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9" + integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg== + +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==