/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { collectExtraKeys as collectExtraKeys$, lazySchema as lazySchema$, safeParse, } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { smartUnion } from "../../types/smartUnion.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AuthType, AuthType$inboundSchema } from "./authtype.js"; import { ConnectionState, ConnectionState$inboundSchema, } from "./connectionstate.js"; import { ConsentRecord, ConsentRecord$inboundSchema } from "./consentrecord.js"; import { ConsentRecordInput, ConsentRecordInput$Outbound, ConsentRecordInput$outboundSchema, } from "./consentrecordinput.js"; import { ConsentState, ConsentState$inboundSchema, ConsentState$outboundSchema, } from "./consentstate.js"; import { CustomMapping, CustomMapping$inboundSchema } from "./custommapping.js"; import { CustomMappingInput, CustomMappingInput$Outbound, CustomMappingInput$outboundSchema, } from "./custommappinginput.js"; import { DataScopes, DataScopes$inboundSchema } from "./datascopes.js"; import { DataScopesInput, DataScopesInput$Outbound, DataScopesInput$outboundSchema, } from "./datascopesinput.js"; import { FormField, FormField$inboundSchema } from "./formfield.js"; import { FormFieldOption, FormFieldOption$inboundSchema, FormFieldOption$Outbound, FormFieldOption$outboundSchema, } from "./formfieldoption.js"; import { IntegrationState, IntegrationState$inboundSchema, } from "./integrationstate.js"; import { OAuthGrantType, OAuthGrantType$inboundSchema, } from "./oauthgranttype.js"; import { WebhookSubscription, WebhookSubscription$inboundSchema, } from "./webhooksubscription.js"; /** * Status of the connection. */ export const ConnectionStatus = { Live: "live", Upcoming: "upcoming", Requested: "requested", } as const; /** * Status of the connection. */ export type ConnectionStatus = OpenEnum; /** * Attach your own consumer specific metadata */ export type ConnectionMetadata = { /** * Normalized identifier of the authorized organization, copied from the connector-specific setting (e.g. Xero tenant_id, QuickBooks realm_id, NetSuite account_id). */ companyId?: string | undefined; additionalProperties?: { [k: string]: any } | undefined; }; export const Target = { CustomFields: "custom_fields", Resource: "resource", } as const; export type Target = OpenEnum; export type Value5 = string | number | number; export type ConnectionValue = | string | number | number | boolean | Array; export type Defaults = { target?: Target | undefined; id?: string | undefined; options?: Array | undefined; value?: | string | number | number | boolean | Array | undefined; }; export type Configuration = { resource?: string | undefined; defaults?: Array | undefined; }; /** * Operational health status of the connection */ export const Health = { Revoked: "revoked", MissingSettings: "missing_settings", NeedsConsent: "needs_consent", PendingConfirmation: "pending_confirmation", NeedsAuth: "needs_auth", PendingRefresh: "pending_refresh", Ok: "ok", Degraded: "degraded", } as const; /** * Operational health status of the connection */ export type Health = OpenEnum; export type Connection = { /** * The unique identifier of the connection. */ id?: string | undefined; /** * The ID of the service this connection belongs to. */ serviceId?: string | undefined; /** * The name of the connection */ name?: string | undefined; tagLine?: string | undefined; /** * The unified API category where the connection belongs to. */ unifiedApi?: string | undefined; /** * [Connection state flow](#section/Connection-state) */ state?: ConnectionState | undefined; /** * The current state of the Integration. */ integrationState?: IntegrationState | undefined; /** * Type of authorization used by the connector */ authType?: AuthType | undefined; /** * OAuth grant type used by the connector. More info: https://oauth.net/2/grant-types */ oauthGrantType?: OAuthGrantType | undefined; /** * Status of the connection. */ status?: ConnectionStatus | undefined; /** * Whether the connection is enabled or not. You can enable or disable a connection using the Update Connection API. */ enabled?: boolean | undefined; /** * The website URL of the connection */ website?: string | undefined; /** * A visual icon of the connection, that will be shown in the Vault */ icon?: string | undefined; /** * The logo of the connection, that will be shown in the Vault */ logo?: string | undefined; /** * The OAuth redirect URI. Redirect your users to this URI to let them authorize your app in the connector's UI. Before you can use this URI, you must add `redirect_uri` as a query parameter to the `authorize_url`. Be sure to URL encode the `redirect_uri` part. Your users will be redirected to this `redirect_uri` after they granted access to your app in the connector's UI. */ authorizeUrl?: string | null | undefined; /** * The OAuth revoke URI. Redirect your users to this URI to revoke this connection. Before you can use this URI, you must add `redirect_uri` as a query parameter. Your users will be redirected to this `redirect_uri` after they granted access to your app in the connector's UI. */ revokeUrl?: string | null | undefined; /** * Connection settings. Values will persist to `form_fields` with corresponding id */ settings?: { [k: string]: any } | null | undefined; /** * Attach your own consumer specific metadata */ metadata?: ConnectionMetadata | null | undefined; /** * The settings that are wanted to create a connection. */ formFields?: Array | undefined; configuration?: Array | undefined; configurableResources?: Array | undefined; resourceSchemaSupport?: Array | undefined; resourceSettingsSupport?: Array | undefined; validationSupport?: boolean | undefined; schemaSupport?: boolean | undefined; /** * List of settings that are required to be configured on integration before authorization can occur */ settingsRequiredForAuthorization?: Array | undefined; subscriptions?: Array | undefined; /** * Whether the connector has a guide available in the developer docs or not (https://docs.apideck.com/connectors/{service_id}/docs/consumer+connection). */ hasGuide?: boolean | undefined; /** * List of custom mappings configured for this connection */ customMappings?: Array | undefined; /** * The current consent state of the connection */ consentState?: ConsentState | undefined; /** * Immutable array of consent records for compliance and audit purposes */ consents?: Array | undefined; latestConsent?: ConsentRecord | undefined; applicationDataScopes?: DataScopes | undefined; /** * Operational health status of the connection */ health?: Health | undefined; /** * Unix timestamp in milliseconds when credentials will be deleted if token refresh continues to fail. A value of 0 indicates no active retention window (connection is healthy or not using OAuth token refresh). */ credentialsExpireAt?: number | undefined; /** * Unix timestamp in milliseconds of the last failed token refresh attempt. A value of 0 indicates no recent failures. This field is used internally to enforce cooldown periods between retry attempts. */ lastRefreshFailedAt?: number | undefined; /** * Unix timestamp in milliseconds of the last downstream unreachable error (502/504 network class). A value of 0 indicates no active error. Connection remains callable while this is set; health surfaces as 'degraded'. */ lastDownstreamErrorAt?: number | undefined; createdAt?: number | undefined; updatedAt?: number | null | undefined; }; /** * Attach your own consumer specific metadata */ export type ConnectionMetadataInput = { additionalProperties?: { [k: string]: any } | undefined; }; export type ConnectionDefaults = { id?: string | undefined; options?: Array | undefined; value?: | string | number | number | boolean | Array | undefined; }; export type ConnectionConfiguration = { resource?: string | undefined; defaults?: Array | undefined; }; export type ConnectionInput = { /** * Whether the connection is enabled or not. You can enable or disable a connection using the Update Connection API. */ enabled?: boolean | undefined; /** * Connection settings. Values will persist to `form_fields` with corresponding id */ settings?: { [k: string]: any } | null | undefined; /** * Attach your own consumer specific metadata */ metadata?: ConnectionMetadataInput | null | undefined; configuration?: Array | undefined; /** * List of custom mappings configured for this connection */ customMappings?: Array | undefined; /** * The current consent state of the connection */ consentState?: ConsentState | undefined; latestConsent?: ConsentRecordInput | undefined; applicationDataScopes?: DataScopesInput | undefined; }; /** @internal */ export const ConnectionStatus$inboundSchema: z.ZodType< ConnectionStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(ConnectionStatus) ); /** @internal */ export const ConnectionMetadata$inboundSchema: z.ZodType< ConnectionMetadata, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => collectExtraKeys$( z.object({ company_id: types.optional(types.string()), }).catchall(z.any()), "additionalProperties", true, ).transform((v) => { return remap$(v, { "company_id": "companyId", }); }) ); export function connectionMetadataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ConnectionMetadata$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ConnectionMetadata' from JSON`, ); } /** @internal */ export const Target$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(Target)); /** @internal */ export const Value5$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => smartUnion([types.string(), types.number(), types.number()]) ); /** @internal */ export type Value5$Outbound = string | number | number; /** @internal */ export const Value5$outboundSchema: z.ZodType< Value5$Outbound, z.ZodTypeDef, Value5 > = /* @__PURE__ */ lazySchema$(() => smartUnion([z.string(), z.number().int(), z.number()]) ); export function value5ToJSON(value5: Value5): string { return JSON.stringify(Value5$outboundSchema.parse(value5)); } export function value5FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Value5$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Value5' from JSON`, ); } /** @internal */ export const ConnectionValue$inboundSchema: z.ZodType< ConnectionValue, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => smartUnion([ types.string(), types.number(), types.number(), types.boolean(), z.array(smartUnion([types.string(), types.number(), types.number()])), ]) ); /** @internal */ export type ConnectionValue$Outbound = | string | number | number | boolean | Array; /** @internal */ export const ConnectionValue$outboundSchema: z.ZodType< ConnectionValue$Outbound, z.ZodTypeDef, ConnectionValue > = /* @__PURE__ */ lazySchema$(() => smartUnion([ z.string(), z.number().int(), z.number(), z.boolean(), z.array(smartUnion([z.string(), z.number().int(), z.number()])), ]) ); export function connectionValueToJSON( connectionValue: ConnectionValue, ): string { return JSON.stringify(ConnectionValue$outboundSchema.parse(connectionValue)); } export function connectionValueFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ConnectionValue$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ConnectionValue' from JSON`, ); } /** @internal */ export const Defaults$inboundSchema: z.ZodType< Defaults, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ target: types.optional(Target$inboundSchema), id: types.optional(types.string()), options: types.optional(z.array(FormFieldOption$inboundSchema)), value: types.optional( smartUnion([ types.string(), types.number(), types.number(), types.boolean(), z.array(smartUnion([types.string(), types.number(), types.number()])), ]), ), }) ); export function defaultsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Defaults$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Defaults' from JSON`, ); } /** @internal */ export const Configuration$inboundSchema: z.ZodType< Configuration, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ resource: types.optional(types.string()), defaults: types.optional(z.array(z.lazy(() => Defaults$inboundSchema))), }) ); export function configurationFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Configuration$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Configuration' from JSON`, ); } /** @internal */ export const Health$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(Health)); /** @internal */ export const Connection$inboundSchema: z.ZodType< Connection, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ id: types.optional(types.string()), service_id: types.optional(types.string()), name: types.optional(types.string()), tag_line: types.optional(types.string()), unified_api: types.optional(types.string()), state: types.optional(ConnectionState$inboundSchema), integration_state: types.optional(IntegrationState$inboundSchema), auth_type: types.optional(AuthType$inboundSchema), oauth_grant_type: types.optional(OAuthGrantType$inboundSchema), status: types.optional(ConnectionStatus$inboundSchema), enabled: types.optional(types.boolean()), website: types.optional(types.string()), icon: types.optional(types.string()), logo: types.optional(types.string()), authorize_url: z.nullable(types.string()).optional(), revoke_url: z.nullable(types.string()).optional(), settings: z.nullable(z.record(z.any())).optional(), metadata: z.nullable(z.lazy(() => ConnectionMetadata$inboundSchema)) .optional(), form_fields: types.optional(z.array(FormField$inboundSchema)), configuration: types.optional( z.array(z.lazy(() => Configuration$inboundSchema)), ), configurable_resources: types.optional(z.array(types.string())), resource_schema_support: types.optional(z.array(types.string())), resource_settings_support: types.optional(z.array(types.string())), validation_support: types.optional(types.boolean()), schema_support: types.optional(types.boolean()), settings_required_for_authorization: types.optional( z.array(types.string()), ), subscriptions: types.optional(z.array(WebhookSubscription$inboundSchema)), has_guide: types.optional(types.boolean()), custom_mappings: types.optional(z.array(CustomMapping$inboundSchema)), consent_state: types.optional(ConsentState$inboundSchema), consents: types.optional(z.array(ConsentRecord$inboundSchema)), latest_consent: types.optional(ConsentRecord$inboundSchema), application_data_scopes: types.optional(DataScopes$inboundSchema), health: types.optional(Health$inboundSchema), credentials_expire_at: types.optional(types.number()), last_refresh_failed_at: types.optional(types.number()), last_downstream_error_at: types.optional(types.number()), created_at: types.optional(types.number()), updated_at: z.nullable(types.number()).optional(), }).transform((v) => { return remap$(v, { "service_id": "serviceId", "tag_line": "tagLine", "unified_api": "unifiedApi", "integration_state": "integrationState", "auth_type": "authType", "oauth_grant_type": "oauthGrantType", "authorize_url": "authorizeUrl", "revoke_url": "revokeUrl", "form_fields": "formFields", "configurable_resources": "configurableResources", "resource_schema_support": "resourceSchemaSupport", "resource_settings_support": "resourceSettingsSupport", "validation_support": "validationSupport", "schema_support": "schemaSupport", "settings_required_for_authorization": "settingsRequiredForAuthorization", "has_guide": "hasGuide", "custom_mappings": "customMappings", "consent_state": "consentState", "latest_consent": "latestConsent", "application_data_scopes": "applicationDataScopes", "credentials_expire_at": "credentialsExpireAt", "last_refresh_failed_at": "lastRefreshFailedAt", "last_downstream_error_at": "lastDownstreamErrorAt", "created_at": "createdAt", "updated_at": "updatedAt", }); }) ); export function connectionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Connection$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Connection' from JSON`, ); } /** @internal */ export type ConnectionMetadataInput$Outbound = { [additionalProperties: string]: unknown; }; /** @internal */ export const ConnectionMetadataInput$outboundSchema: z.ZodType< ConnectionMetadataInput$Outbound, z.ZodTypeDef, ConnectionMetadataInput > = /* @__PURE__ */ lazySchema$(() => z.object({ additionalProperties: z.record(z.any()).optional(), }).transform((v) => { return { ...v.additionalProperties, ...remap$(v, { additionalProperties: null, }), }; }) ); export function connectionMetadataInputToJSON( connectionMetadataInput: ConnectionMetadataInput, ): string { return JSON.stringify( ConnectionMetadataInput$outboundSchema.parse(connectionMetadataInput), ); } /** @internal */ export type ConnectionDefaults$Outbound = { id?: string | undefined; options?: Array | undefined; value?: | string | number | number | boolean | Array | undefined; }; /** @internal */ export const ConnectionDefaults$outboundSchema: z.ZodType< ConnectionDefaults$Outbound, z.ZodTypeDef, ConnectionDefaults > = /* @__PURE__ */ lazySchema$(() => z.object({ id: z.string().optional(), options: z.array(FormFieldOption$outboundSchema).optional(), value: smartUnion([ z.string(), z.number().int(), z.number(), z.boolean(), z.array(smartUnion([z.string(), z.number().int(), z.number()])), ]).optional(), }) ); export function connectionDefaultsToJSON( connectionDefaults: ConnectionDefaults, ): string { return JSON.stringify( ConnectionDefaults$outboundSchema.parse(connectionDefaults), ); } /** @internal */ export type ConnectionConfiguration$Outbound = { resource?: string | undefined; defaults?: Array | undefined; }; /** @internal */ export const ConnectionConfiguration$outboundSchema: z.ZodType< ConnectionConfiguration$Outbound, z.ZodTypeDef, ConnectionConfiguration > = /* @__PURE__ */ lazySchema$(() => z.object({ resource: z.string().optional(), defaults: z.array(z.lazy(() => ConnectionDefaults$outboundSchema)) .optional(), }) ); export function connectionConfigurationToJSON( connectionConfiguration: ConnectionConfiguration, ): string { return JSON.stringify( ConnectionConfiguration$outboundSchema.parse(connectionConfiguration), ); } /** @internal */ export type ConnectionInput$Outbound = { enabled?: boolean | undefined; settings?: { [k: string]: any } | null | undefined; metadata?: ConnectionMetadataInput$Outbound | null | undefined; configuration?: Array | undefined; custom_mappings?: Array | undefined; consent_state?: string | undefined; latest_consent?: ConsentRecordInput$Outbound | undefined; application_data_scopes?: DataScopesInput$Outbound | undefined; }; /** @internal */ export const ConnectionInput$outboundSchema: z.ZodType< ConnectionInput$Outbound, z.ZodTypeDef, ConnectionInput > = /* @__PURE__ */ lazySchema$(() => z.object({ enabled: z.boolean().optional(), settings: z.nullable(z.record(z.any())).optional(), metadata: z.nullable(z.lazy(() => ConnectionMetadataInput$outboundSchema)) .optional(), configuration: z.array(z.lazy(() => ConnectionConfiguration$outboundSchema)) .optional(), customMappings: z.array(CustomMappingInput$outboundSchema).optional(), consentState: ConsentState$outboundSchema.optional(), latestConsent: ConsentRecordInput$outboundSchema.optional(), applicationDataScopes: DataScopesInput$outboundSchema.optional(), }).transform((v) => { return remap$(v, { customMappings: "custom_mappings", consentState: "consent_state", latestConsent: "latest_consent", applicationDataScopes: "application_data_scopes", }); }) ); export function connectionInputToJSON( connectionInput: ConnectionInput, ): string { return JSON.stringify(ConnectionInput$outboundSchema.parse(connectionInput)); }