import {z} from 'zod' export type LandscapeActionType = 'comment-create' | 'comment-delete' | 'comment-reply-create' | 'comment-reply-delete' | 'comment-reply-update' | 'comment-update' | 'diagram-content-create' | 'diagram-content-delete' | 'diagram-content-update' | 'diagram-content-view' | 'diagram-create' | 'diagram-delete' | 'diagram-export' | 'diagram-group-create' | 'diagram-group-delete' | 'diagram-group-update' | 'diagram-update' | 'domain-create' | 'domain-delete' | 'domain-update' | 'draft-create' | 'draft-delete' | 'draft-merge' | 'draft-task-create' | 'draft-update' | 'draft-view' | 'flow-create' | 'flow-delete' | 'flow-update' | 'flow-view' | 'landscape-copy' | 'landscape-create' | 'landscape-delete' | 'landscape-duplicate' | 'landscape-export' | 'landscape-import' | 'landscape-update' | 'model-connection-create' | 'model-connection-delete' | 'model-connection-update' | 'model-connections-export' | 'model-object-create' | 'model-object-delete' | 'model-object-dependencies-export' | 'model-object-update' | 'model-objects-export' | 'share-link-create' | 'share-link-delete' | 'share-link-update' | 'tag-create' | 'tag-delete' | 'tag-group-create' | 'tag-group-delete' | 'tag-group-update' | 'tag-update' | 'version-create' | 'version-delete' | 'version-revert-create'; export type AuthType = 'user' | 'api-key' | 'notification-key' | 'service'; export type ActionLogStatsFilter = {actionType?: (LandscapeActionType | Array) | undefined, endAtDate?: string | undefined, entityId?: (string | Array) | undefined, performedBy?: (AuthType | Array) | undefined, performedById?: (string | Array) | undefined, startAtDate?: string | undefined}; export type ActionLogStatsPeriod = 'day' | 'week' | 'month' | 'year' | 'all'; export type GetApiLandscapesLandscapeIdActionLogsStatsByEntityArgs = {landscapeId: string, filter?: ActionLogStatsFilter | undefined, period?: ActionLogStatsPeriod | undefined}; export type GetApiLandscapesLandscapeIdActionLogsStatsByEntityOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const authType = z.enum(["user", "api-key", "notification-key", "service"]); export const actionLogStatsContributor = z.object({contributedAt: z.string(), count: z.number(), id: z.string(), name: z.string().optional(), type: authType}); export const actionLogStatsItemByEntity = z.object({contributors: z.record(z.string(), actionLogStatsContributor), count: z.number(), entityId: z.string()}); export const actionLogStatsDateByEntity = z.object({date: z.string(), entities: z.record(z.string(), actionLogStatsItemByEntity)}); export const actionLogStatsListByEntity = z.object({contributors: z.record(z.string(), actionLogStatsContributor), dates: z.array(actionLogStatsDateByEntity), totalCount: z.number()}); 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 }; /** * By Entity * * GET /landscapes/{landscapeId}/action-logs/stats/by-entity * * Also accepts auth: BearerAuth */ export const getApiLandscapesLandscapeIdActionLogsStatsByEntity = async (args: GetApiLandscapesLandscapeIdActionLogsStatsByEntityArgs, options?: GetApiLandscapesLandscapeIdActionLogsStatsByEntityOptions) => { const {baseUrl = "https://api.icepanel.io/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.period != null) query.append("period", String(args.period)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/landscapes/${encodeURIComponent(String(args.landscapeId))}/action-logs/stats/by-entity${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(actionLogStatsListByEntity, await res.json()) };