import {z} from 'zod' export type GetApiV2AccessProfilesArgs = {teamId: string, pageSize?: number | undefined, pageToken?: string | undefined, workflowId?: string | undefined}; export type GetApiV2AccessProfilesOptions = {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 svflowPublicapiListAccessProfilesResponse = z.object({data: z.array(svflowPubapimodelsAccessProfile).optional(), nextPageToken: z.string().nullable().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 }; /** * List Access Profiles * * GET /v2/access-profiles */ export const getApiV2AccessProfiles = async (args: GetApiV2AccessProfilesArgs, options?: GetApiV2AccessProfilesOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.workflowId != null) query.append("workflowId", String(args.workflowId)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(svflowPublicapiListAccessProfilesResponse, await res.json()) };