/** * Alerts Resource * * CRUD operations, alert items management, validation, and generation. * * This is the base (unscoped) resource. For scope-scoped SDKs, use: * - MexAlertsResource - Mexico-scoped with flattened MX fields * - AVIAlertsResource - Mexico AVI-scoped with flattened AVI fields * - JYSAlertsResource - Mexico JYS-scoped with flattened JYS fields * - TSCAlertsResource - Mexico TSC-scoped with flattened TSC fields */ import type { AcknowledgmentDownloadUrl, AcknowledgmentUploadUrl, AlertClientItemFilter, AlertDefaultsInput, AlertFilter, AlertItemFilter, AlertItemSort, AlertSort, AlertTransactionItemFilter, AtomicBatchResult, ClientSort, CreateAlertInput, CreateAlertItemInput, GenerateResult, GetAcknowledgmentUploadUrlInput, ListOptions, PaginatedResponse, PartialBatchResult, ReportType, ResourceTagResponse, SplitOptions, TransactionSort, UpdateAlertInput, UpdateAlertItemInput, UpdateAlertStatusInput, UpsertAlertInput, UpsertResult, ValidationResult } from "@artu-ai/shared"; import { Alert, AlertClientItem, type AlertClientItemData, type AlertData, AlertItem, type AlertItemData, AlertTransactionItem, type AlertTransactionItemData } from "../models"; import { AlertItemsResource } from "./alert-items"; import { BaseResource } from "./base"; export type { AlertFilter, AlertItemFilter, AlertItemSort }; /** * Add items result */ export interface AddItemsResult { added: number; items: AlertItem[]; } /** * Base resource manager for alert operations. * * Provides: * - CRUD operations (create, retrieve, update, delete) * - Alert items management (add, update, remove items) * - Validation and generation * * @example * ```typescript * // Create a alert with full nested format * const alert = await sdk.alerts.create({ * scopeData: { * MX: { * actividadVulnerable: { * AVI: { mesReportado: "202401" } * } * } * } * }); * * // Add items to the alert * await sdk.alerts.addItem(alert.id, { * transactionId: "txn_123", * }); * * // Validate the alert * const result = await sdk.alerts.validate(alert.id); * if (result.valid) { * // Generate XML * const xml = await sdk.alerts.generate(alert.id); * } * ``` */ export declare class AlertsResource extends BaseResource { protected scopeFilterKey: "scope" | "scopes" | null; /** * Top-level alert items sub-resource. * Provides list/count/iterate across all alerts. * * @example * ```typescript * const items = await sdk.alerts.items.list(); * const count = await sdk.alerts.items.count({ alertId: { eq: "..." } }); * ``` */ readonly items: AlertItemsResource; constructor(config: import("./base").ResourceConfig); /** * Creates a new alert. * * @param data - Alert creation data in nested format * @returns The created alert model */ create(data: CreateAlertInput): Promise; /** * Retrieves a alert by ID. */ retrieve(id: string, opts?: { crossScope?: boolean; }): Promise; /** * Retrieves the raw, un-instantiated alert payload by ID. * * The API call is identical across every scope; only the client-side * reshape differs. The React SDK caches this single scope-agnostic payload * and lets each scope derive its own shape via `materialize`, avoiding N * redundant fetches in nested scope-overview components. * * Intentionally does NOT pass `requireScope` (unlike `retrieve`): that is a * client-supplied optional narrowing filter, not the authorization boundary. * Tenant isolation is enforced server-side by RLS and applies identically * here. A shared, id-keyed payload cannot carry a per-scope filter without * leaking one scope's narrowing onto the others sharing the cache entry. * * @param id - Alert ID * @returns The raw API payload (`AlertData`) — not a model instance */ retrieveRaw(id: string): Promise; /** * Retrieves a alert by metadata key/value. */ retrieveByMetadata(key: string, value: string, opts?: { crossScope?: boolean; }): Promise; /** * Retrieves a alert by externalId. */ retrieveByExternalId(externalId: string, opts?: { crossScope?: boolean; }): Promise; /** * Updates a alert. */ update(id: string, data: UpdateAlertInput): Promise; /** * Updates an alert's lifecycle status. * * Use this to manually transition an alert to a new state (e.g., InReview, Resolved, Dismissed). * System-managed states (ReportValidating, ReportValid, ReportInvalid) cannot be set directly. */ updateStatus(alertId: string, data: UpdateAlertStatusInput): Promise; /** * Marks an alert as filed. * * Requires the alert to be in `report_valid` state with a current report, * and an acknowledgment file must already be uploaded at the deterministic * storage path via `getAcknowledgmentUploadUrl`. Terminal transition — * the alert cannot be transitioned further once filed. */ markAsFiled(alertId: string): Promise; /** * Gets a presigned upload URL for uploading an alert's acknowledgment file. * * The file is stored at a deterministic path derived from the alert's * organization, environment, and ID. Call `markAsFiled` after uploading. * * @param alertId - The alert ID * @param data - Upload options (contentType) * @returns Presigned upload URL with expiry */ getAcknowledgmentUploadUrl(alertId: string, data: GetAcknowledgmentUploadUrlInput): Promise; /** * Gets a presigned download URL for an alert's acknowledgment file. * * The alert must have been filed (i.e., `isFiled === true`) for this to succeed. * The returned URL is valid for a limited time (configured by the storage provider). * * @param alertId - The alert ID * @returns Presigned URL with filename, contentType, and expiry * @throws If the alert has not been filed */ getAcknowledgmentDownloadUrl(alertId: string): Promise; /** * Deletes a alert. */ delete(id: string): Promise; /** * Lists alerts with optional filtering and pagination. */ list(options?: ListOptions & { crossScope?: boolean; }): Promise>; /** * Counts alerts matching the given filter. * * @param filter - Optional filter criteria * @returns The count of matching alerts */ count(filter?: AlertFilter, options?: { crossScope?: boolean; }): Promise; /** * Returns an async iterator over all alerts matching the filter. */ iterate(options?: { filter?: AlertFilter; sort?: TSort; pageSize?: number; crossScope?: boolean; }): AsyncGenerator; /** * Adds an item to a alert. */ addItem(alertId: string, data: CreateAlertItemInput): Promise; /** * Gets a specific alert item. */ getItem(alertId: string, itemId: string): Promise; /** * Updates a alert item. */ updateItem(alertId: string, itemId: string, data: UpdateAlertItemInput): Promise; /** * Removes an item from a alert. */ removeItem(alertId: string, itemId: string): Promise; /** * Lists items in a alert with filtering, sorting, and pagination. */ listItems(alertId: string, options?: ListOptions): Promise>; /** * Lists transactions linked to an alert. * Returns the same TransactionResponse shape as the regular transactions list. */ listTransactionItems(alertId: string, options?: ListOptions): Promise>; /** * Lists unique clients related to an alert. * Includes clients linked directly and clients linked through transactions. */ listClients(alertId: string, options?: ListOptions): Promise>; /** * Adds multiple items to a alert. * Validates all items upfront - fails fast if any item is invalid. */ addItems(alertId: string, items: CreateAlertItemInput[]): Promise; /** * Removes multiple items from a alert. */ removeItems(alertId: string, itemIds: string[]): Promise<{ removed: number; }>; /** * Validates an alert and its items. * * Requires reportType and optional scope-specific defaults. * For scoped SDKs, use the scoped resource which provides a simpler API. * * The reportType must be valid for this resource's scope (client-side pre-flight check). * The server enforces the same constraint authoritatively. * * @param alertId - The alert ID to validate * @param reportType - The report type (e.g., "mex.actividad-vulnerable.avi") * @param defaults - Scope-specific defaults for validation (optional) */ validateReport(alertId: string, reportType: ReportType, defaults?: TDefaults): Promise; /** * Validates and generates the alert output (e.g., XML for Mexico alerts). * * Performs validation first: * - If validation fails, returns `{ status: "validation_failed", validation: {...} }` * - If validation passes, returns `{ status: "success", reports: [...], ... }` * * Large alerts can be split into multiple reports using the `split` option: * - `strategy: "minimize"` (default): Pack items efficiently to minimize parts * - `strategy: "by_client"`: One report per client * * Use `validateReport` for dry-run/preview validation without generating output. * * The reportType must be valid for this resource's scope (client-side pre-flight check). * The server enforces the same constraint authoritatively. * * @param alertId - The alert ID to generate * @param reportType - The report type (e.g., "mex.actividad-vulnerable.avi") * @param defaults - Scope-specific defaults for generation (optional) * @param options - Optional generation options including split strategy * @returns GenerateResult with status "success" or "validation_failed" */ generateReport(alertId: string, reportType: ReportType, defaults?: TDefaults, options?: { split?: SplitOptions; }): Promise; /** * Merges tenant details into alert defaults. * Tenant values fill gaps; client-provided defaults always win. */ private mergeTenantDefaults; /** * Creates or updates a alert by externalId. * * If a alert with the given externalId exists, it will be updated. * Otherwise, a new alert will be created. * * @param data - Alert upsert data (must include externalId) * @returns The created or updated alert with action indicator */ upsertByExternalId(data: UpsertAlertInput): Promise>; /** * Creates or updates multiple alerts by externalId in a single request. * * @param alerts - Array of alert upsert data (each must include externalId) * @param options - Batch options (atomic: true by default) * @returns Atomic result with data array, or partial result with succeeded/failed */ upsertManyByExternalId(alerts: UpsertAlertInput[], options?: { atomic?: true; }): Promise>>; upsertManyByExternalId(alerts: UpsertAlertInput[], options: { atomic: false; }): Promise>>; /** * Creates multiple alerts in a single request. * * @param alerts - Array of alert creation data * @param options - Batch options (atomic: true by default) * @returns Atomic result with data array, or partial result with succeeded/failed */ createMany(alerts: CreateAlertInput[], options?: { atomic?: true; }): Promise>; createMany(alerts: CreateAlertInput[], options: { atomic: false; }): Promise>; /** * Updates multiple alerts in a single request. * * @param updates - Array of { id, data } updates * @param options - Batch options (atomic: true by default) * @returns Atomic result with data array, or partial result with succeeded/failed */ updateMany(updates: { id: string; data: UpdateAlertInput; }[], options?: { atomic?: true; }): Promise>; updateMany(updates: { id: string; data: UpdateAlertInput; }[], options: { atomic: false; }): Promise>; /** * Adds tags to a alert. */ addTags(id: string, tagIds: string[]): Promise; /** * Removes tags from a alert. */ removeTags(id: string, tagIds: string[]): Promise; /** * Replaces all tags on a alert. */ setTags(id: string, tagIds: string[]): Promise; /** * Lists all tags on a alert. */ listTags(id: string): Promise; /** * Creates the AlertItemsResource sub-resource. * Uses an arrow function callback so subclass overrides of * `instantiateItem` are correctly dispatched at runtime. */ protected createItemsResource(): AlertItemsResource; /** * Instantiates a Alert model from API response data. * Subclasses override this to return their specific model type. */ protected instantiate(data: AlertData): Alert; /** * Public, pure transform from a raw alert payload to this scope's model. * Wraps the protected `instantiate` so the React SDK can apply it inside a * TanStack Query `select`. Subclasses override `instantiate` (and `materialize`), * so each scope materializes its own model type. */ materialize(data: AlertData): Alert; /** * Instantiates a AlertItem model from API response data. * Subclasses override this to return their specific model type. */ protected instantiateItem(data: AlertItemData): AlertItem; /** * Instantiates an AlertTransactionItem model from API response data. * Subclasses override this to return their specific model type. */ protected instantiateTransactionItem(data: AlertTransactionItemData): AlertTransactionItem; /** * Instantiates an AlertClientItem model from API response data. * Subclasses override this to return their specific model type. */ protected instantiateClientItem(data: AlertClientItemData): AlertClientItem; }