/** * Generic integration storage — the default persistence surface for * `FactoryIntegration`s. * * Most integrations persist the same three shapes: an org-owned OAuth * **connection**, **subscriptions** binding external objects to * sessions/threads, and per-`(org, user)` **settings**. This built-in domain * stores all three in shared collections keyed by `integration_id`, so an * integration author writes zero schema, zero DDL, and zero queries — and * org scoping is enforced by construction through the pre-scoped handle * returned by {@link IntegrationStorage.forIntegration}. * * Source-control integrations additionally use the shared, provider-scoped * source-control domain for installations, projects, and sessions. * * Payloads (`data` / `config`) are JSON documents typed per-integration via * the handle's generics. JSON round-trips exactly what JSON can represent: * store timestamps inside payloads as epoch millis or ISO strings, not * `Date`s. */ import { FactoryStorageDomain } from '@mastra/core/storage'; import type { CollectionSchema } from '@mastra/core/storage'; import type { FactorySecretEncryption } from '../../../secret-encryption.js'; export declare const INTEGRATION_CONNECTIONS_SCHEMA: CollectionSchema; export declare const INTEGRATION_SUBSCRIPTIONS_SCHEMA: CollectionSchema; export declare const INTEGRATION_SETTINGS_SCHEMA: CollectionSchema; /** An integration's org-owned connection (typically the OAuth grant). */ export interface IntegrationConnection { id: string; orgId: string; /** Who connected it (audit only). */ userId: string | null; data: TData; metadata: Record; createdAt: Date; updatedAt: Date; } /** A subscription binding an external object to a session/thread. */ export interface IntegrationSubscription { id: string; orgId: string; targetKey: string; sessionId: string | null; resourceId: string | null; threadId: string | null; sessionScope: string | null; status: string; data: TData; createdAt: Date; updatedAt: Date; } export type CreateIntegrationSubscriptionInput = { orgId: string; targetKey: string; sessionId?: string | null; resourceId?: string | null; threadId?: string | null; sessionScope?: string | null; /** Defaults to `'active'`. */ status?: string; } & ({} extends TData ? { data?: TData; } : { data: TData; }); /** * Typed query surface pre-scoped to one `integration_id`. Every read and * write is automatically filtered/stamped with the integration id, so an * integration cannot reach another integration's rows. */ export interface IntegrationStorageHandle, TSettings = Record, TSubscription = Record> { readonly integrationId: string; connections: { /** The org's connection, or `null` when not connected. */ get(orgId: string): Promise | null>; /** Insert or replace the org's connection (one per org; `created_at` preserved on update). */ upsert(orgId: string, input: { userId?: string | null; data: TConnection; metadata?: Record; }): Promise; /** * Atomic read-modify-write of the connection's `data` payload (token * rotation etc.). Returns the updated connection, or `null` when the org * has no connection. */ update(orgId: string, fn: (data: TConnection) => TConnection): Promise | null>; /** Remove the org's connection. Returns whether a row was deleted. */ delete(orgId: string): Promise; }; subscriptions: { create(input: CreateIntegrationSubscriptionInput): Promise>; /** All subscriptions for an external object (webhook fan-out), optionally filtered by status. */ listByTarget(targetKey: string, opts?: { status?: string; }): Promise[]>; listBySession(sessionId: string): Promise[]>; listByThread(resourceId: string, threadId: string): Promise[]>; updateStatus(id: string, status: string): Promise; delete(id: string): Promise; /** Targeted cleanup, always org-scoped. Returns the number of rows deleted. */ deleteWhere(where: { orgId: string; targetKey?: string; sessionId?: string; }): Promise; }; settings: { /** The `(org, user)` config, or `null` when never saved. */ get(orgId: string, userId: string): Promise; /** Upsert the `(org, user)` config (`created_at` preserved on update). */ save(orgId: string, userId: string, config: TSettings): Promise; }; } /** * The built-in generic integration domain, written once against the * `FactoryStorageOps` surface — works on any `FactoryStorage` backend. */ export declare class IntegrationStorage extends FactoryStorageDomain { #private; private readonly encryption; constructor(encryption?: FactorySecretEncryption); init(): Promise; dangerouslyClearAll(): Promise; /** A typed handle pre-scoped to `integrationId`. */ forIntegration, TSettings = Record, TSubscription = Record>(integrationId: string): IntegrationStorageHandle; } //# sourceMappingURL=base.d.ts.map