import {z} from 'zod' export type InvitationRequest = {invitation: {role: 'organisation_admin' | 'organisation_member' | 'team_admin' | 'team_member' | 'mock_api_admin' | 'mock_api_editor' | 'mock_api_user' | 'api_template_admin' | 'api_template_editor' | 'api_template_user' | 'api_template_catalogue_admin' | 'api_template_catalogue_editor' | 'api_template_catalogue_user' | 'data_source_admin' | 'data_source_editor' | 'data_source_user' | 'key_admin' | 'key_editor' | 'key_user', aclObjectId?: (string | null) | undefined, recipientEmailAddress: string}}; export type CreateApiV1OrganisationsOrganisationIdInvitationsArgs = {body: InvitationRequest}; export type CreateApiV1OrganisationsOrganisationIdInvitationsOptions = {baseUrl?: string | undefined, tokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const invitationData = z.object({id: z.string(), senderId: z.string(), recipientEmailAddress: z.string(), newUser: z.boolean(), role: z.enum(["organisation_admin", "organisation_member", "team_admin", "team_member", "mock_api_admin", "mock_api_editor", "mock_api_user", "api_template_admin", "api_template_editor", "api_template_user", "api_template_catalogue_admin", "api_template_catalogue_editor", "api_template_catalogue_user", "data_source_admin", "data_source_editor", "data_source_user", "key_admin", "key_editor", "key_user"]), aclObjectId: z.string().nullable().optional(), created: z.string(), links: z.object({self: z.string()})}); export const invitation = z.object({invitation: invitationData}); 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 }; /** * Invite a user to an organisation * * POST /v1/organisations/{organisationId}/invitations */ export const createApiV1OrganisationsOrganisationIdInvitations = async (args: CreateApiV1OrganisationsOrganisationIdInvitationsArgs, options?: CreateApiV1OrganisationsOrganisationIdInvitationsOptions) => { const {baseUrl = "https://wmc.wiremockapi.cloud", fetch: fetchFn = fetch, tokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (tokenAuth !== undefined) headers.set("Authorization", tokenAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organisations/${encodeURIComponent(String(args.organisationId))}/invitations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(invitation, await res.json()) };