import {z} from 'zod' export type SvflowPubapimodelsAccessProfileGroupMatchType = 'ACCESS_PROFILE_GROUP_MATCH_TYPE_UNSPECIFIED' | 'ACCESS_PROFILE_GROUP_MATCH_TYPE_ANY' | 'ACCESS_PROFILE_GROUP_MATCH_TYPE_ALL'; export type SvflowPubapimodelsAccessProfileGroupCriteria = {matchType?: SvflowPubapimodelsAccessProfileGroupMatchType | undefined, includedGroupIds?: Array | undefined, excludedGroupIds?: Array | undefined}; export type SvauthModelsTeamRole = 'TEAM_ROLE_UNSPECIFIED' | 'TEAM_ROLE_MANAGER' | 'TEAM_ROLE_AGENT' | 'TEAM_ROLE_BUILDER' | 'TEAM_ROLE_VIEWER' | 'TEAM_ROLE_CONTRIBUTOR' | 'TEAM_ROLE_DRAFTER' | 'TEAM_ROLE_READONLY_AGENT' | 'TEAM_ROLE_APP_BUILDER'; export type SvflowPubapimodelsAccessProfileCurrentTeamCriteria = {teamRoles?: Array | undefined}; export type SvflowPubapimodelsAccessProfileMatchingCriteria = {groups?: SvflowPubapimodelsAccessProfileGroupCriteria | undefined, currentTeam?: SvflowPubapimodelsAccessProfileCurrentTeamCriteria | undefined}; export type SvflowPubapimodelsAccessProfileAppResourceRoleGrant = {appResourceRoleId?: string | undefined, useTeamDefaultAccessProfile?: boolean | undefined}; export type SvflowPubapimodelsAccessProfileWorkflowGrant = {workflowId?: string | undefined}; export type SvflowPubapimodelsAccessProfileGrants = {appResourceRoles?: Array | undefined, workflows?: Array | undefined}; export type SvflowPublicapiCreateAccessProfileRequest = {teamId: string, name: string, description?: (string | null) | undefined, matchingCriteria?: SvflowPubapimodelsAccessProfileMatchingCriteria | undefined, grants?: SvflowPubapimodelsAccessProfileGrants | undefined}; export type CreateApiV2AccessProfilesArgs = {body: SvflowPublicapiCreateAccessProfileRequest}; export type CreateApiV2AccessProfilesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const googleProtobufTimestamp = z.string(); export const svflowPubapimodelsAccessProfileGroupMatchType = z.enum(["ACCESS_PROFILE_GROUP_MATCH_TYPE_UNSPECIFIED", "ACCESS_PROFILE_GROUP_MATCH_TYPE_ANY", "ACCESS_PROFILE_GROUP_MATCH_TYPE_ALL"]); export const svflowPubapimodelsAccessProfileGroupCriteria = z.object({matchType: svflowPubapimodelsAccessProfileGroupMatchType.optional(), includedGroupIds: z.array(z.string()).optional(), excludedGroupIds: z.array(z.string()).optional()}); export const svauthModelsTeamRole = z.enum(["TEAM_ROLE_UNSPECIFIED", "TEAM_ROLE_MANAGER", "TEAM_ROLE_AGENT", "TEAM_ROLE_BUILDER", "TEAM_ROLE_VIEWER", "TEAM_ROLE_CONTRIBUTOR", "TEAM_ROLE_DRAFTER", "TEAM_ROLE_READONLY_AGENT", "TEAM_ROLE_APP_BUILDER"]); export const svflowPubapimodelsAccessProfileCurrentTeamCriteria = z.object({teamRoles: z.array(svauthModelsTeamRole).optional()}); export const svflowPubapimodelsAccessProfileMatchingCriteria = z.object({groups: svflowPubapimodelsAccessProfileGroupCriteria.optional(), currentTeam: svflowPubapimodelsAccessProfileCurrentTeamCriteria.optional()}); export const svflowPubapimodelsAccessProfileAppResourceRoleGrant = z.object({appResourceRoleId: z.string().optional(), useTeamDefaultAccessProfile: z.boolean().optional()}); export const svflowPubapimodelsAccessProfileWorkflowGrant = z.object({workflowId: z.string().optional()}); export const svflowPubapimodelsAccessProfileGrants = z.object({appResourceRoles: z.array(svflowPubapimodelsAccessProfileAppResourceRoleGrant).optional(), workflows: z.array(svflowPubapimodelsAccessProfileWorkflowGrant).optional()}); export const svflowPubapimodelsAccessProfile = z.object({id: z.string().optional(), teamId: z.string().optional(), name: z.string().optional(), description: z.string().nullable().optional(), isTeamDefault: z.boolean().optional(), createdAt: googleProtobufTimestamp.optional(), matchingCriteria: svflowPubapimodelsAccessProfileMatchingCriteria.optional(), grants: svflowPubapimodelsAccessProfileGrants.optional(), builtinProfileType: z.string().optional()}); export const svflowPublicapiCreateAccessProfileResponse = z.object({data: svflowPubapimodelsAccessProfile.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 }; /** * Create Access Profile * * POST /v2/access-profiles */ export const createApiV2AccessProfiles = async (args: CreateApiV2AccessProfilesArgs, options?: CreateApiV2AccessProfilesOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/access-profiles${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(svflowPublicapiCreateAccessProfileResponse, await res.json()) };