import {z} from 'zod' export type GetApiApiOnboardingDeploymentsDeploymentIdChecklistArgs = {deploymentId: string}; export type GetApiApiOnboardingDeploymentsDeploymentIdChecklistOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosOnboardingV1OnboardingTask = z.object({type: z.enum(["TASK_TYPE_COMPLETE_TOUR", "TASK_TYPE_SCAN_CODE", "TASK_TYPE_TRIAGE_FIRST_PARTY", "TASK_TYPE_TRIAGE_DEPENDENCY", "TASK_TYPE_SET_UP_RECURRING_SCAN", "TASK_TYPE_CONFIGURE_IGNORES", "TASK_TYPE_JOIN_SLACK", "TASK_TYPE_CUSTOMIZE_RULES", "TASK_TYPE_ENABLE_INTEGRATION", "TASK_TYPE_ADD_TEAM_MEMBER", "TASK_TYPE_WRITE_CUSTOM_RULE", "TASK_TYPE_SETUP_SCM_PROVIDER", "TASK_TYPE_ENABLE_ASSISTANT", "TASK_TYPE_ENABLE_SEMGREP_MULTIMODAL"]).optional(), state: z.enum(["TASK_STATE_COMPLETE", "TASK_STATE_INCOMPLETE", "TASK_STATE_LOCKED"]).optional(), level: z.enum(["TASK_LEVEL_ORG", "TASK_LEVEL_USER"]).optional()}); export const protosOnboardingV1GetChecklistStatusResponse = z.object({taskStatus: z.array(protosOnboardingV1OnboardingTask).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 /api/onboarding/deployments/{deploymentId}/checklist * * Also accepts auth: SemgrepJWT */ export const getApiApiOnboardingDeploymentsDeploymentIdChecklist = async (args: GetApiApiOnboardingDeploymentsDeploymentIdChecklistArgs, options: GetApiApiOnboardingDeploymentsDeploymentIdChecklistOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/onboarding/deployments/${encodeURIComponent(String(args.deploymentId))}/checklist${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(protosOnboardingV1GetChecklistStatusResponse, await res.json()) };