import {z} from 'zod' export type JsonNode = Record; export type GridsterItemDTO = {cols?: number | undefined, dragEnabled?: boolean | undefined, maxItemCols?: number | undefined, maxItemRows?: number | undefined, minItemCols?: number | undefined, minItemRows?: number | undefined, resizeEnabled?: boolean | undefined, rows?: number | undefined, x?: number | undefined, y?: number | undefined}; export type WidgetConfigDTO = {config?: JsonNode | undefined, gridsterItem: GridsterItemDTO, id?: string | undefined, title?: string | undefined, type: 'ACCOUNT_STATUS' | 'REAL_TIME_PNL' | 'ACCOUNT' | 'TERMINAL' | 'OPEN_INVOICES' | 'PROJECT_BALANCE' | 'FINANCIAL_OVERVIEW' | 'LOGS' | 'AUDIT_LOGS' | 'NOTES' | 'DIVIDER' | 'CLOCK' | 'WEATHER'}; export type UserDashboardConfigDTO = {createdAt?: string | undefined, description?: string | undefined, id?: string | undefined, isDefault?: boolean | undefined, modifiedAt?: string | undefined, name: string, projectId?: string | undefined, sortOrder?: number | undefined, widgets?: Array | undefined}; export type CreateApiRestApiV1ProjectsProjectIdDashboardsArgs = {projectId: string, body: UserDashboardConfigDTO}; export type CreateApiRestApiV1ProjectsProjectIdDashboardsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jsonNode = z.object({}); export const gridsterItemDTO = z.object({cols: z.number().int().optional(), dragEnabled: z.boolean().optional(), maxItemCols: z.number().int().optional(), maxItemRows: z.number().int().optional(), minItemCols: z.number().int().optional(), minItemRows: z.number().int().optional(), resizeEnabled: z.boolean().optional(), rows: z.number().int().optional(), x: z.number().int().optional(), y: z.number().int().optional()}); export const widgetConfigDTO = z.object({config: jsonNode.optional(), gridsterItem: gridsterItemDTO, id: z.string().optional(), title: z.string().max(100).optional(), type: z.enum(["ACCOUNT_STATUS", "REAL_TIME_PNL", "ACCOUNT", "TERMINAL", "OPEN_INVOICES", "PROJECT_BALANCE", "FINANCIAL_OVERVIEW", "LOGS", "AUDIT_LOGS", "NOTES", "DIVIDER", "CLOCK", "WEATHER"])}); export const userDashboardConfigDTO = z.object({createdAt: z.string().optional(), description: z.string().max(500).optional(), id: z.string().optional(), isDefault: z.boolean().optional(), modifiedAt: z.string().optional(), name: z.string().min(1).max(100), projectId: z.string().optional(), sortOrder: z.number().int().optional(), widgets: z.array(widgetConfigDTO).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 }; /** * Create a dashboard * * POST /rest/api/v1/projects/{projectId}/dashboards */ export const createApiRestApiV1ProjectsProjectIdDashboards = async (args: CreateApiRestApiV1ProjectsProjectIdDashboardsArgs, options?: CreateApiRestApiV1ProjectsProjectIdDashboardsOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/dashboards${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(userDashboardConfigDTO, await res.json()) };