import {z} from 'zod' export type WorkspaceConfigUpdateRequest = {user_inbox_preference_enabled?: boolean | undefined, sms_vendor_type?: ('basic' | 'dlt') | undefined, user_tenancy_mode?: ('shared' | 'exclusive') | undefined, user_tenancy_channel_fallback_mode?: ('all' | 'allowlist') | undefined, user_tenancy_channel_fallback?: Array | undefined, user_tenancy_channel_fallback_applies_to_default_tenant?: boolean | undefined}; export type PatchApiV1WorkspaceWorkspaceSlugConfigArgs = {workspace_slug: string, body: WorkspaceConfigUpdateRequest}; export type PatchApiV1WorkspaceWorkspaceSlugConfigOptions = {baseUrl?: string | undefined, ServiceTokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceConfig = z.object({user_inbox_preference_enabled: z.boolean().optional(), sms_vendor_type: z.enum(["basic", "dlt"]).optional(), user_tenancy_mode: z.enum(["shared", "exclusive"]).optional(), user_tenancy_channel_fallback_mode: z.enum(["all", "allowlist"]).optional(), user_tenancy_channel_fallback: z.array(z.string()).optional(), user_tenancy_channel_fallback_applies_to_default_tenant: z.boolean().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 Workspace Config * * PATCH /v1/workspace/{workspace_slug}/config/ */ export const patchApiV1WorkspaceWorkspaceSlugConfig = async (args: PatchApiV1WorkspaceWorkspaceSlugConfigArgs, options?: PatchApiV1WorkspaceWorkspaceSlugConfigOptions) => { const {baseUrl = "https://management-api.suprsend.com", fetch: fetchFn = fetch, ServiceTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ServiceTokenAuth !== undefined) headers.set("Authorization", ServiceTokenAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspace/${encodeURIComponent(String(args.workspace_slug))}/config/${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(workspaceConfig, await res.json()) };