import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdNotificationChannelsFeatureIdDeliveriesArgs = {projectId: string, featureId: string, recipient?: string | undefined, ruleId?: string | undefined, status?: ('QUEUED' | 'ACCEPTED' | 'FAILED' | 'UNKNOWN' | 'BUNDLED' | 'QUIET' | 'COOLDOWN' | 'DROPPED_OVERFLOW' | 'DROPPED_RATE_LIMIT' | 'EXPIRED' | 'SKIPPED_DISABLED' | 'SKIPPED_TARGET' | 'CANCELLED_CONFIG_CHANGED') | undefined, cursor?: string | undefined, size?: number | undefined}; export type GetApiRestApiV1ProjectsProjectIdNotificationChannelsFeatureIdDeliveriesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationDeliveryDTO = z.object({attempts: z.number().int().optional(), category: z.enum(["TRADING", "COPY_SKIPPED", "EXECUTION_ERROR", "ACCOUNT_CONNECTION", "RISK", "NEWS", "SIGNALS", "SYSTEM", "OTHER"]).optional(), channelType: z.enum(["TELEGRAM", "WEBHOOK", "SLACK", "MS_TEAMS", "DISCORD"]).optional(), createdAt: z.string().optional(), error: z.string().optional(), eventType: z.enum(["POSITION_OPENED", "POSITION_CLOSED", "POSITION_MODIFIED", "HISTORY_UPDATED", "TRADE_APPROVAL_REQUIRED", "TRADE_APPROVED", "UNMANAGED_POSITION_DETECTED", "COPY_SKIPPED", "ORDER_REJECTED", "INSUFFICIENT_MARGIN", "TRADE_FAILED_DISCONNECTED", "COPY_FAILED", "DUPLICATE_POSITION_DETECTED", "ACCOUNT_STARTED", "ACCOUNT_STOPPED", "ACCOUNT_CONNECTED", "ACCOUNT_DISCONNECTED", "ACCOUNT_LOGIN_FAILED", "ACCOUNT_TOKEN_EXPIRING", "ACCOUNT_RESTRICTED", "ACCOUNT_FALLBACK_MODE", "RISK_LIMIT_REACHED", "PROFIT_TARGET_REACHED", "LOSS_PROTECTED_EXIT", "GUARDRAIL_TRIGGERED", "COPIER_STOPPED_BY_RISK", "LIMIT_RESET", "BALANCE_ADJUSTMENT_DETECTED", "NEWS_EVENT_UPCOMING", "NEWS_EVENT_RELEASED", "NEWS_FILTER_ACTION_SCHEDULED", "NEWS_FILTER_ACTION_IMMINENT", "NEWS_FILTER_DAILY_AGENDA", "NEWS_FILTER_SKIPPED_COPY", "NEWS_FILTER_CLOSED_POSITION", "NEWS_FILTER_REOPENED", "NEWS_FILTER_REOPEN_SKIPPED", "NEWS_FILTER_HOLIDAY_MODE", "MARKET_NEWS_HIGH_IMPACT", "SIGNAL_RECEIVED", "SIGNAL_EXECUTED", "SIGNAL_REJECTED", "SIGNAL_AI_LIMIT_REACHED", "SIGNAL_SUBSCRIPTION_ENDED", "CONFIGURATION_ERROR", "CONFIGURATION_CHANGED", "MAINTENANCE_WINDOW", "PROXY_ISSUE", "EXPERT_ADVISOR_STARTED", "EXPERT_ADVISOR_STOPPED", "EXPERT_ADVISOR_WARNING", "LOG_RATE_LIMITED", "NOTIFICATION_CHANNEL_DISABLED", "GENERAL"]).optional(), featureId: z.string().optional(), id: z.string().optional(), logLevelId: z.number().int().optional(), projectId: z.string().optional(), recipient: z.string().optional(), ruleId: z.string().optional(), status: z.enum(["QUEUED", "ACCEPTED", "FAILED", "UNKNOWN", "BUNDLED", "QUIET", "COOLDOWN", "DROPPED_OVERFLOW", "DROPPED_RATE_LIMIT", "EXPIRED", "SKIPPED_DISABLED", "SKIPPED_TARGET", "CANCELLED_CONFIG_CHANGED"]).optional(), summary: z.string().optional(), test: z.boolean().optional(), updatedAt: z.string().optional()}); export const notificationDeliveryPageDTO = z.object({items: z.array(notificationDeliveryDTO).optional(), nextCursor: 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 }; /** * Delivery log of one channel * * GET /rest/api/v1/projects/{projectId}/notificationChannels/{featureId}/deliveries */ export const getApiRestApiV1ProjectsProjectIdNotificationChannelsFeatureIdDeliveries = async (args: GetApiRestApiV1ProjectsProjectIdNotificationChannelsFeatureIdDeliveriesArgs, options?: GetApiRestApiV1ProjectsProjectIdNotificationChannelsFeatureIdDeliveriesOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.recipient != null) query.append("recipient", String(args.recipient)) if (args.ruleId != null) query.append("ruleId", String(args.ruleId)) if (args.status != null) query.append("status", String(args.status)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.size != null) query.append("size", String(args.size)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/notificationChannels/${encodeURIComponent(String(args.featureId))}/deliveries${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(notificationDeliveryPageDTO, await res.json()) };