import {z} from 'zod' export type JobId = string; export type FotaV2JobExecutionEvents = 'QUEUED' | 'IN_PROGRESS' | 'FAILED' | 'SUCCEEDED' | 'TIMED_OUT' | 'CANCELLED' | 'REJECTED' | 'DOWNLOADING'; export type PageLimit = number; export type PageNextToken = string; export type GetApiFotaJobExecutionStatusesJobIdArgs = {jobId: JobId, status?: FotaV2JobExecutionEvents | undefined, pageLimit?: PageLimit | undefined, pageNextToken?: PageNextToken | undefined}; export type GetApiFotaJobExecutionStatusesJobIdOptions = {baseUrl?: string | undefined, SimpleToken?: string | undefined, fetch?: typeof fetch | undefined}; export const deviceId = z.string(); export const fOTAJobExecutionState = z.object({deviceId: deviceId, status: z.string(), statusDetail: z.string().optional(), lastUpdatedAt: z.string().optional()}); export const paginatedResultFOTAJobExecutionState = z.object({items: z.array(fOTAJobExecutionState), total: z.number().int().gte(0).optional(), pageNextToken: z.string().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 }; /** * ListFOTAJobExecutionStatuses * * GET /fota-job-execution-statuses/{jobId} */ export const getApiFotaJobExecutionStatusesJobId = async (args: GetApiFotaJobExecutionStatusesJobIdArgs, options?: GetApiFotaJobExecutionStatusesJobIdOptions) => { const {baseUrl = "https://api.nrfcloud.com/v1", fetch: fetchFn = fetch, SimpleToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.pageLimit != null) query.append("pageLimit", String(args.pageLimit)) if (args.pageNextToken != null) query.append("pageNextToken", String(args.pageNextToken)) if (SimpleToken !== undefined) headers.set('authorization', `Bearer ${SimpleToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/fota-job-execution-statuses/${encodeURIComponent(String(args.jobId))}${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(paginatedResultFOTAJobExecutionState, await res.json()) };