import {z} from 'zod' export type GetApiApiV1ProjectsProjectTokenContributorsArgs = {projectToken: string}; export type GetApiApiV1ProjectsProjectTokenContributorsOptions = {baseUrl?: string | undefined, PersonalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const permission = z.object({key: z.literal("AUTO_TRANSLATE, CHANGE_TRANSLATIONS, REVIEW_TRANSLATIONS, PUBLISH_TRANSLATIONS, MANAGE_TRANSLATION_KEYS, MANAGE_LANGUAGES, IMPORT_FILES, EXPORT_FILES, VIEW_ACTIVITY, ACCESS_COMMENTS, CHANGE_CUSTOMER_TRANSLATIONS, REVIEW_CUSTOMER_TRANSLATIONS, CHANGE_DESCRIPTION"), access: z.enum(["ALLOW", "DENY"])}); export const assignedLanguage = z.object({key: z.string(), access: z.enum(["ALLOW", "DENY"])}); export const assignedTag = z.object({name: z.string(), access: z.enum(["ALLOW", "DENY"])}); export const assignedCustomer = z.object({key: z.string(), access: z.enum(["ALLOW", "DENY"])}); export const apiProjectContributor = z.object({name: z.string().optional(), email: z.string().optional(), status: z.enum(["INVITED", "ACCEPTED"]).optional(), role: z.enum(["OWNER", "ADMIN", "DEVELOPER", "TRANSLATOR"]).optional(), permissions: z.array(permission).optional(), assignedLanguages: z.array(assignedLanguage).optional(), defaultLanguageAccess: z.enum(["WRITE_READ", "READ", "HIDDEN"]).optional(), assignedTags: z.array(assignedTag).optional(), defaultTagAccess: z.enum(["WRITE_READ", "HIDDEN"]).optional(), assignedCustomers: z.array(assignedCustomer).optional(), defaultCustomerAccess: z.enum(["WRITE_READ", "HIDDEN"]).optional()}); export const getApiApiV1ProjectsProjectTokenContributorsResponse = z.object({msg: z.string().optional(), status: z.number().int().optional(), data: z.array(apiProjectContributor).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 project contributors * * GET /api/v1/projects/{projectToken}/contributors */ export const getApiApiV1ProjectsProjectTokenContributors = async (args: GetApiApiV1ProjectsProjectTokenContributorsArgs, options?: GetApiApiV1ProjectsProjectTokenContributorsOptions) => { const {baseUrl = "https://api.simplelocalize.io", fetch: fetchFn = fetch, PersonalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (PersonalAccessToken !== undefined) headers.set("Authorization", PersonalAccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectToken))}/contributors${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(getApiApiV1ProjectsProjectTokenContributorsResponse, await res.json()) };