import {z} from 'zod' export type GetApiWorkspacesWorkspaceIdPlansPlanIdArgs = {workspace_id: number, plan_id: number}; export type GetApiWorkspacesWorkspaceIdPlansPlanIdOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const modelsCampaign = z.object({discount: z.number().int().optional(), end: z.string().optional(), key: z.string().optional(), name: z.string().optional(), start: z.string().optional()}); export const billingPricesStruct = z.object({actual: z.number().int().optional(), base: z.number().int().optional(), with_tax: z.number().int().optional()}); export const billingFancyPricingPlan = z.object({actual_price_in_usd_cents: z.number().int().optional(), campaign: modelsCampaign.optional(), list_price_in_usd_cents: z.number().int().optional(), name: z.string().optional(), period: z.number().int().optional(), price_point_handle: z.string().optional(), prices_month: billingPricesStruct.optional(), prices_period: billingPricesStruct.optional(), pricing_plan_id: z.number().int().optional()}); export const billingFancyPlan = z.object({name: z.string().optional(), plan_id: z.number().int().optional(), pricing_plans: z.array(billingFancyPricingPlan).optional()}); export const getApiWorkspacesWorkspaceIdPlansPlanIdResponse = z.array(billingFancyPlan); 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 }; /** * WorkspacePlan * * GET /workspaces/{workspace_id}/plans/{plan_id} */ export const getApiWorkspacesWorkspaceIdPlansPlanId = async (args: GetApiWorkspacesWorkspaceIdPlansPlanIdArgs, options: GetApiWorkspacesWorkspaceIdPlansPlanIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/plans/${encodeURIComponent(String(args.plan_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(getApiWorkspacesWorkspaceIdPlansPlanIdResponse, await res.json()) };