import {z} from 'zod' export type GetApiApiV1ActivityActivityIdChangesArgs = {'X-SimpleLocalize-Token': string, activityId: string}; export type GetApiApiV1ActivityActivityIdChangesOptions = {baseUrl?: string | undefined, ProjectAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const contentChangeRequest = z.object({action: z.enum(["CREATE_KEY", "DELETE_KEY", "CHANGE_KEY", "CHANGE_TRANSLATION", "CHANGE_REVIEW_STATUS", "CREATE_LANGUAGE", "CHANGE_LANGUAGE", "DELETE_LANGUAGE", "CREATE_CUSTOMER", "CHANGE_CUSTOMER", "DELETE_CUSTOMER"]).optional(), key: z.string().optional(), namespace: z.string().optional(), oldNamespace: z.string().optional(), oldKey: z.string().optional(), newNamespace: z.string().optional(), newKey: z.string().optional(), word: z.string().optional(), oldWord: z.string().optional(), language: z.string().optional(), overrideKey: z.string().optional(), reviewStatus: z.enum(["NOT_REVIEWED", "REVIEWED", "REVIEWED", "NOT_REVIEWED", ""]).optional(), deprecatedAt: z.string().optional(), occurred: z.string().optional(), autoTranslatedBy: z.string().optional()}); export const getApiApiV1ActivityActivityIdChangesResponse = z.object({msg: z.string().optional(), status: z.number().int().optional(), data: z.array(contentChangeRequest).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 activity changes * * GET /api/v1/activity/{activityId}/changes */ export const getApiApiV1ActivityActivityIdChanges = async (args: GetApiApiV1ActivityActivityIdChangesArgs, options?: GetApiApiV1ActivityActivityIdChangesOptions) => { const {baseUrl = "https://api.simplelocalize.io", fetch: fetchFn = fetch, ProjectAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-SimpleLocalize-Token'] != null) headers.set("X-SimpleLocalize-Token", String(args['X-SimpleLocalize-Token'])) if (ProjectAPIKey !== undefined) headers.set("X-SimpleLocalize-Token", ProjectAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/activity/${encodeURIComponent(String(args.activityId))}/changes${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(getApiApiV1ActivityActivityIdChangesResponse, await res.json()) };