import {z} from 'zod' export type GetApiV0WorkflowsWorkflowIdArgs = {'workflow-id': string}; export type GetApiV0WorkflowsWorkflowIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0WorkflowsWorkflowIdResponse = z.object({"workflow-url": z.string(), "display-name": z.string().min(1), description: z.string(), "legal-person-type": z.enum(["individual", "corporation"]), "created-at": z.string(), "disabled?": z.boolean(), "required-claim-types": z.record(z.string(), z.array(z.enum(["mobile-number", "properties-origins-of-deposits", "individual-identity", "sole-trader", "property-types", "commercial-property-industries", "uk-company-register", "individual-income", "business-website", "initial-deposit", "international-payments-countries", "company-telephone-number", "managed-properties", "business-size", "entity-address", "person-with-significant-control", "business-industry", "tax-residencies", "tenant-cash-payments", "verified-bank-account", "company-email-address", "tax-residency", "uk-financial-services-register", "non-tenant-balance", "business-description", "hmrc-register", "external-risk-rating", "nfe-classification", "vat-registration", "entity-name", "hmo-license", "business-email-address", "client-money-protection-scheme", "fca-mutuals-register", "individual-sources-of-funds", "nominal-person-with-significant-control", "hmo-verification", "commercial-property-ratio", "governing-body-member", "business-address", "employment", "annual-turnover", "purposes-of-account", "sic-codes", "international-operations-countries", "balance-sheet-size", "us-citizen", "role-titles", "sources-of-funds", "senior-manager-function-holder", "business-owner", "business-telephone-number", "individual-email-address", "tax-identification-numbers-by-country", "business-start-date", "contact-details", "reliance-verification", "ultimate-beneficial-owner", "aeoi-entity-classification", "business-name", "individual-purposes-of-account", "nationality", "trading-name", "number-of-employees", "social-media", "trading-address", "company-website", "director", "complex-business-structure", "alternative-number", "cash-payments", "fca-fs-register-firm", "tax-identification-number", "fca-fs-register-individual", "individual-residence", "business-type"]))).optional(), "workflow-rules": z.array(z.enum(["allow-zero-directors", "allow-missing-directors"])).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get workflow * * GET /v0/workflows/{workflow-id} */ export const getApiV0WorkflowsWorkflowId = async (args: GetApiV0WorkflowsWorkflowIdArgs, options?: GetApiV0WorkflowsWorkflowIdOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/workflows/${encodeURIComponent(String(args['workflow-id']))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV0WorkflowsWorkflowIdResponse, await res.json()) };