import {z} from 'zod' export type GetApiOrganizationOrganizationIdModuleArgs = {sort?: (Array<'createdBy' | '-createdBy' | 'description' | '-description' | 'downloadQuantity' | '-downloadQuantity' | 'name' | '-name' | 'provider' | '-provider' | 'registryPath' | '-registryPath' | 'source' | '-source' | 'updatedBy' | '-updatedBy' | 'id' | '-id'>) | undefined, 'fields[module]'?: (Array<'createdBy' | 'createdDate' | 'description' | 'downloadQuantity' | 'name' | 'provider' | 'registryPath' | 'source' | 'updatedBy' | 'updatedDate' | 'versions' | 'organization' | 'ssh' | 'vcs'>) | undefined, include?: (Array<'organization' | 'ssh' | 'vcs'>) | undefined, 'filter[module]'?: string | undefined, 'page[number]'?: number | undefined, 'page[size]'?: number | undefined, 'page[offset]'?: number | undefined, 'page[limit]'?: number | undefined, 'page[totals]'?: string | undefined}; export type GetApiOrganizationOrganizationIdModuleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const module = z.object({type: z.string().optional(), id: z.string().optional(), attributes: z.object({createdBy: z.string().optional(), createdDate: z.string().optional(), description: z.string().optional(), downloadQuantity: z.number().int().optional(), name: z.string().optional(), provider: z.string().optional(), registryPath: z.string().optional(), source: z.string().optional(), updatedBy: z.string().optional(), updatedDate: z.string().optional(), versions: z.array(z.object({})).optional()}).optional(), relationships: z.object({organization: z.object({id: z.string().optional(), type: z.literal("organization").optional()}).optional(), ssh: z.object({id: z.string().optional(), type: z.literal("ssh").optional()}).optional(), vcs: z.object({id: z.string().optional(), type: z.literal("vcs").optional()}).optional()}).optional()}); export const getApiOrganizationOrganizationIdModuleResponse = z.object({data: z.array(module).optional(), included: z.array(z.object({attributes: z.object({}).optional(), id: z.string().optional(), relationships: z.object({}).optional(), type: z.string().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 }; /** * Returns the relationship module * * GET /organization/{organizationId}/module */ export const getApiOrganizationOrganizationIdModule = async (args: GetApiOrganizationOrganizationIdModuleArgs, options: GetApiOrganizationOrganizationIdModuleOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") for (const item of args.sort ?? []) query.append("sort", String(item)) for (const item of args['fields[module]'] ?? []) query.append("fields[module]", String(item)) for (const item of args.include ?? []) query.append("include", String(item)) if (args['filter[module]'] != null) query.append("filter[module]", String(args['filter[module]'])) if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[offset]'] != null) query.append("page[offset]", String(args['page[offset]'])) if (args['page[limit]'] != null) query.append("page[limit]", String(args['page[limit]'])) if (args['page[totals]'] != null) query.append("page[totals]", String(args['page[totals]'])) const url = `${baseUrl.replace(/\/+$/, '')}/organization/${encodeURIComponent(String(args.organizationId))}/module${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(getApiOrganizationOrganizationIdModuleResponse, await res.json()) };