import {z} from 'zod' export type CreateApiApiDashboardDashboardIdCustomersArgs = {dashboardId: string, body: Array}; export type CreateApiApiDashboardDashboardIdCustomersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jsonNode = z.unknown(); export const resourceExportData = z.object({link: z.string().optional(), title: z.string().optional(), type: z.enum(["LWM2M_MODEL", "JKS", "PKCS_12", "JS_MODULE", "IMAGE", "DASHBOARD", "GENERAL"]).optional(), subType: z.enum(["IMAGE", "SCADA_SYMBOL", "EXTENSION", "MODULE"]).optional(), resourceKey: z.string().optional(), fileName: z.string().optional(), publicResourceKey: z.string().optional(), isPublic: z.boolean().optional(), mediaType: z.string().optional(), data: z.string().optional(), public: z.boolean().optional()}); export const dashboardId = z.object({id: z.string(), entityType: z.literal("DASHBOARD")}); export const tenantId = z.object({id: z.string(), entityType: z.literal("TENANT")}); export const customerId = z.object({id: z.string(), entityType: z.literal("CUSTOMER")}); export const shortCustomerInfo = z.object({customerId: customerId.optional(), title: z.string().optional(), isPublic: z.boolean().optional(), public: z.boolean().optional()}); export const dashboard = z.object({title: z.string(), image: z.string().optional(), mobileHide: z.boolean().optional(), mobileOrder: z.number().int().optional(), configuration: jsonNode.optional(), name: z.string().optional(), resources: z.array(resourceExportData).optional(), id: dashboardId.optional(), createdTime: z.number().int().optional(), tenantId: tenantId.optional(), assignedCustomers: z.array(shortCustomerInfo).optional(), version: z.number().int().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 }; /** * Update the Dashboard Customers (updateDashboardCustomers) * * POST /api/dashboard/{dashboardId}/customers */ export const createApiApiDashboardDashboardIdCustomers = async (args: CreateApiApiDashboardDashboardIdCustomersArgs, options?: CreateApiApiDashboardDashboardIdCustomersOptions) => { const {baseUrl = "https://demo.thingsboard.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/dashboard/${encodeURIComponent(String(args.dashboardId))}/customers${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dashboard, await res.json()) };