import {z} from 'zod' export type GetApiOrganizationsOrganizationIdArgs = {organization_id: string}; export type GetApiOrganizationsOrganizationIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const organization = z.object({id: z.string().optional(), type: z.enum(["fixed", "flexible"]).optional(), owner_id: z.string().optional(), namespace: z.string().optional(), name: z.string().optional(), label: z.string().optional(), country: z.string().max(2).optional(), capabilities: z.array(z.string()).optional(), vendor: z.string().optional(), billing_account_id: z.string().optional(), billing_legacy: z.boolean().optional(), security_contact: z.string().optional(), status: z.enum(["active", "restricted", "suspended", "deleted"]).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), _links: z.object({self: z.object({href: z.string().optional()}).optional(), update: z.object({href: z.string().optional(), method: z.string().optional()}).optional(), delete: z.object({href: z.string().optional(), method: z.string().optional()}).optional(), members: z.object({href: z.string().optional()}).optional(), "create-member": z.object({href: z.string().optional(), method: z.string().optional()}).optional(), address: z.object({href: z.string().optional()}).optional(), profile: z.object({href: z.string().optional()}).optional(), "payment-source": z.object({href: z.string().optional()}).optional(), orders: z.object({href: z.string().optional()}).optional(), vouchers: z.object({href: z.string().optional()}).optional(), "apply-voucher": z.object({href: z.string().optional(), method: z.string().optional()}).optional(), subscriptions: z.object({href: z.string().optional()}).optional(), "create-subscription": z.object({href: z.string().optional(), method: z.string().optional()}).optional(), "estimate-subscription": z.object({href: z.string().optional()}).optional(), "mfa-enforcement": z.object({href: z.string().optional()}).optional()}).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 organization * * GET /organizations/{organization_id} */ export const getApiOrganizationsOrganizationId = async (args: GetApiOrganizationsOrganizationIdArgs, options?: GetApiOrganizationsOrganizationIdOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_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(organization, await res.json()) };