import {z} from 'zod' export type ResourceId = string; export type ProductTags = {applications?: (Array<'LO Connect' | 'Encompass Smart Client' | 'urn:elli:application:consumerconnect' | 'urn:elli:application:tpoconnect' | 'urn:elli:application:developerconnect'>) | undefined, categories?: (Array<'APPRAISAL' | 'FLOOD' | 'VERIF' | 'ClosingFees' | 'PRODUCTPRICING'>) | undefined, workflows?: (Array<'interactive' | 'automated'>) | undefined}; export type ProductCredentialPropertySchema = {id: string, type: 'string' | 'number' | 'boolean', title: string, required?: boolean | undefined, pattern?: string | undefined, minimum?: number | undefined, maximum?: number | undefined, secret?: boolean | undefined, scope?: ('user' | 'company') | undefined}; export type ProductCredentialSchema = Array; export type ProductWebhook = {resource: 'urn:elli:epc:transaction' | 'urn:elli:epc:transaction:event', url: string, signingkey: string, events: Array<'created' | 'updated'>}; export type ProductWebhooks = Array; export type ProductAccessEntitlements = {allow: Array, deny: Array}; export type ProductDataEntitlementsField = {fieldId?: string | undefined, jsonPath: string, description?: string | undefined}; export type ProductDataEntitlementsFields = Array; export type ProductRequestDataEntitlementsSchema = {fields: ProductDataEntitlementsFields}; export type ProductRequestType = string; export type ProductResourceType = string; export type ProductDataEntitlementsResources = Array; export type ProductDataEntitlementsResultFormat = 'application/vnd.productpricing-lock-1.0.0.json' | 'application/vnd.productpricing-extendlock-1.0.0.json' | 'application/vnd.productpricing-relock-1.0.0.json' | 'application/vnd.productpricing-cancellock-1.0.0.json' | 'application/vnd.productpricing-lock-and-confirm-1.0.0.json'; export type ProductDataEntitlementsResult = {action?: ('LOCK' | 'RELOCK' | 'EXTEND' | 'CANCEL' | 'LOCK_CONFIRM') | undefined, formats?: Array | undefined}; export type ProductDataEntitlementsResults = Array; export type ProductResponseDataEntitlementsSchema = {fields: ProductDataEntitlementsFields, resources?: ProductDataEntitlementsResources | undefined, results?: ProductDataEntitlementsResults | undefined}; export type ProductTransactionDataEntitlements = Array<{requestTypes: Array, request: ProductRequestDataEntitlementsSchema, response: ProductResponseDataEntitlementsSchema}>; export type ResourceCreatedUpdated = string; export type ProductDataEntitlements = {origin: ProductRequestDataEntitlementsSchema, transactions: ProductTransactionDataEntitlements, created?: ResourceCreatedUpdated | undefined, createdBy?: ResourceCreatedUpdated | undefined, updated?: ResourceCreatedUpdated | undefined, updatedBy?: ResourceCreatedUpdated | undefined}; export type ProductEntitlements = {access: ProductAccessEntitlements, data: ProductDataEntitlements}; export type ProductRequest = {name: unknown, listingName: unknown, requestTypes: unknown, interfaceUrl: unknown, adminInterfaceUrl?: unknown, tags?: ProductTags | undefined, credentials?: ProductCredentialSchema | undefined, webhooks: ProductWebhooks, extensionLimit?: number | undefined, entitlements: ProductEntitlements}; export type PatchApiProductsProductIdArgs = {Authorization: string, product_id: ResourceId, view?: ('id' | 'credential' | 'integrationType' | 'entitlement' | 'webhook' | 'complete') | undefined, body: ProductRequest}; export type PatchApiProductsProductIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceId = z.string(); export const productIdView = z.object({id: resourceId.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 }; /** * Update a specific product * * PATCH /products/{product_id} */ export const patchApiProductsProductId = async (args: PatchApiProductsProductIdArgs, options?: PatchApiProductsProductIdOptions) => { const {baseUrl = "https://api.elliemae.com/oauth2/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/merge-patch+json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.view != null) query.append("view", String(args.view)) const url = `${baseUrl.replace(/\/+$/, '')}/products/${encodeURIComponent(String(args.product_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(productIdView, await res.json()) };