@mastra/factory 0.0.0-fix-thread-subscription-multi-instance-redis-streams-20260730204150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +695 -0
- package/LICENSE.md +30 -0
- package/README.md +27 -0
- package/dist/auth.d.ts +181 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +505 -0
- package/dist/auth.js.map +1 -0
- package/dist/capabilities/connection.d.ts +9 -0
- package/dist/capabilities/connection.d.ts.map +1 -0
- package/dist/capabilities/connection.js +1 -0
- package/dist/capabilities/intake.d.ts +140 -0
- package/dist/capabilities/intake.d.ts.map +1 -0
- package/dist/capabilities/intake.js +1 -0
- package/dist/capabilities/version-control.d.ts +245 -0
- package/dist/capabilities/version-control.d.ts.map +1 -0
- package/dist/capabilities/version-control.js +1 -0
- package/dist/factory.d.ts +156 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +483 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/integrations/base.d.ts +210 -0
- package/dist/integrations/base.d.ts.map +1 -0
- package/dist/integrations/base.js +1 -0
- package/dist/integrations/github/config.d.ts +60 -0
- package/dist/integrations/github/config.d.ts.map +1 -0
- package/dist/integrations/github/config.js +42 -0
- package/dist/integrations/github/config.js.map +1 -0
- package/dist/integrations/github/factory-session.d.ts +12 -0
- package/dist/integrations/github/factory-session.d.ts.map +1 -0
- package/dist/integrations/github/factory-session.js +37 -0
- package/dist/integrations/github/factory-session.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +191 -0
- package/dist/integrations/github/integration.d.ts.map +1 -0
- package/dist/integrations/github/integration.js +1077 -0
- package/dist/integrations/github/integration.js.map +1 -0
- package/dist/integrations/github/issue-triage.d.ts +27 -0
- package/dist/integrations/github/issue-triage.d.ts.map +1 -0
- package/dist/integrations/github/issue-triage.js +82 -0
- package/dist/integrations/github/issue-triage.js.map +1 -0
- package/dist/integrations/github/pat.d.ts +38 -0
- package/dist/integrations/github/pat.d.ts.map +1 -0
- package/dist/integrations/github/pat.js +59 -0
- package/dist/integrations/github/pat.js.map +1 -0
- package/dist/integrations/github/provenance.d.ts +27 -0
- package/dist/integrations/github/provenance.d.ts.map +1 -0
- package/dist/integrations/github/provenance.js +75 -0
- package/dist/integrations/github/provenance.js.map +1 -0
- package/dist/integrations/github/routes.d.ts +69 -0
- package/dist/integrations/github/routes.d.ts.map +1 -0
- package/dist/integrations/github/routes.js +1324 -0
- package/dist/integrations/github/routes.js.map +1 -0
- package/dist/integrations/github/rules.d.ts +78 -0
- package/dist/integrations/github/rules.d.ts.map +1 -0
- package/dist/integrations/github/rules.js +362 -0
- package/dist/integrations/github/rules.js.map +1 -0
- package/dist/integrations/github/sandbox-release.d.ts +38 -0
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -0
- package/dist/integrations/github/sandbox-release.js +74 -0
- package/dist/integrations/github/sandbox-release.js.map +1 -0
- package/dist/integrations/github/sandbox.d.ts +281 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -0
- package/dist/integrations/github/sandbox.js +547 -0
- package/dist/integrations/github/sandbox.js.map +1 -0
- package/dist/integrations/github/session-subscriptions.d.ts +26 -0
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/session-subscriptions.js +192 -0
- package/dist/integrations/github/session-subscriptions.js.map +1 -0
- package/dist/integrations/github/subscriptions.d.ts +54 -0
- package/dist/integrations/github/subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/subscriptions.js +62 -0
- package/dist/integrations/github/subscriptions.js.map +1 -0
- package/dist/integrations/github/token-refresh.d.ts +12 -0
- package/dist/integrations/github/token-refresh.d.ts.map +1 -0
- package/dist/integrations/github/token-refresh.js +24 -0
- package/dist/integrations/github/token-refresh.js.map +1 -0
- package/dist/integrations/github/webhook.d.ts +87 -0
- package/dist/integrations/github/webhook.d.ts.map +1 -0
- package/dist/integrations/github/webhook.js +397 -0
- package/dist/integrations/github/webhook.js.map +1 -0
- package/dist/integrations/linear/agent-tools.d.ts +34 -0
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
- package/dist/integrations/linear/agent-tools.js +85 -0
- package/dist/integrations/linear/agent-tools.js.map +1 -0
- package/dist/integrations/linear/integration.d.ts +233 -0
- package/dist/integrations/linear/integration.d.ts.map +1 -0
- package/dist/integrations/linear/integration.js +672 -0
- package/dist/integrations/linear/integration.js.map +1 -0
- package/dist/integrations/linear/routes.d.ts +61 -0
- package/dist/integrations/linear/routes.d.ts.map +1 -0
- package/dist/integrations/linear/routes.js +239 -0
- package/dist/integrations/linear/routes.js.map +1 -0
- package/dist/integrations/linear/rules.d.ts +42 -0
- package/dist/integrations/linear/rules.d.ts.map +1 -0
- package/dist/integrations/linear/rules.js +133 -0
- package/dist/integrations/linear/rules.js.map +1 -0
- package/dist/integrations/linear/storage.d.ts +65 -0
- package/dist/integrations/linear/storage.d.ts.map +1 -0
- package/dist/integrations/linear/storage.js +1 -0
- package/dist/integrations/platform/api-client.d.ts +26 -0
- package/dist/integrations/platform/api-client.d.ts.map +1 -0
- package/dist/integrations/platform/api-client.js +156 -0
- package/dist/integrations/platform/api-client.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +49 -0
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
- package/dist/integrations/platform/github/event-worker.js +348 -0
- package/dist/integrations/platform/github/event-worker.js.map +1 -0
- package/dist/integrations/platform/github/integration.d.ts +50 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -0
- package/dist/integrations/platform/github/integration.js +961 -0
- package/dist/integrations/platform/github/integration.js.map +1 -0
- package/dist/integrations/platform/linear/integration.d.ts +46 -0
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
- package/dist/integrations/platform/linear/integration.js +483 -0
- package/dist/integrations/platform/linear/integration.js.map +1 -0
- package/dist/integrations/workos/integration.d.ts +39 -0
- package/dist/integrations/workos/integration.d.ts.map +1 -0
- package/dist/integrations/workos/integration.js +91 -0
- package/dist/integrations/workos/integration.js.map +1 -0
- package/dist/routes/config.d.ts +235 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +972 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/custom-provider-source.d.ts +52 -0
- package/dist/routes/custom-provider-source.d.ts.map +1 -0
- package/dist/routes/custom-provider-source.js +124 -0
- package/dist/routes/custom-provider-source.js.map +1 -0
- package/dist/routes/fs.d.ts +151 -0
- package/dist/routes/fs.d.ts.map +1 -0
- package/dist/routes/fs.js +708 -0
- package/dist/routes/fs.js.map +1 -0
- package/dist/routes/intake.d.ts +23 -0
- package/dist/routes/intake.d.ts.map +1 -0
- package/dist/routes/intake.js +179 -0
- package/dist/routes/intake.js.map +1 -0
- package/dist/routes/oauth.d.ts +43 -0
- package/dist/routes/oauth.d.ts.map +1 -0
- package/dist/routes/oauth.js +463 -0
- package/dist/routes/oauth.js.map +1 -0
- package/dist/routes/projects.d.ts +19 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +461 -0
- package/dist/routes/projects.js.map +1 -0
- package/dist/routes/provider-credentials.d.ts +81 -0
- package/dist/routes/provider-credentials.d.ts.map +1 -0
- package/dist/routes/provider-credentials.js +86 -0
- package/dist/routes/provider-credentials.js.map +1 -0
- package/dist/routes/route.d.ts +48 -0
- package/dist/routes/route.d.ts.map +1 -0
- package/dist/routes/route.js +15 -0
- package/dist/routes/route.js.map +1 -0
- package/dist/routes/skills.d.ts +30 -0
- package/dist/routes/skills.d.ts.map +1 -0
- package/dist/routes/skills.js +168 -0
- package/dist/routes/skills.js.map +1 -0
- package/dist/routes/surface.d.ts +91 -0
- package/dist/routes/surface.d.ts.map +1 -0
- package/dist/routes/surface.js +260 -0
- package/dist/routes/surface.js.map +1 -0
- package/dist/routes/tenant-credentials.d.ts +74 -0
- package/dist/routes/tenant-credentials.d.ts.map +1 -0
- package/dist/routes/tenant-credentials.js +156 -0
- package/dist/routes/tenant-credentials.js.map +1 -0
- package/dist/routes/work-items.d.ts +40 -0
- package/dist/routes/work-items.d.ts.map +1 -0
- package/dist/routes/work-items.js +695 -0
- package/dist/routes/work-items.js.map +1 -0
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -0
- package/dist/rules/binding-context.js +28 -0
- package/dist/rules/binding-context.js.map +1 -0
- package/dist/rules/defaults.d.ts +9 -0
- package/dist/rules/defaults.d.ts.map +1 -0
- package/dist/rules/defaults.js +260 -0
- package/dist/rules/defaults.js.map +1 -0
- package/dist/rules/dispatcher.d.ts +42 -0
- package/dist/rules/dispatcher.d.ts.map +1 -0
- package/dist/rules/dispatcher.js +518 -0
- package/dist/rules/dispatcher.js.map +1 -0
- package/dist/rules/index.d.ts +7 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/processor.d.ts +54 -0
- package/dist/rules/processor.d.ts.map +1 -0
- package/dist/rules/processor.js +378 -0
- package/dist/rules/processor.js.map +1 -0
- package/dist/rules/resolve.d.ts +17 -0
- package/dist/rules/resolve.d.ts.map +1 -0
- package/dist/rules/resolve.js +30 -0
- package/dist/rules/resolve.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +60 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -0
- package/dist/rules/start-coordinator.js +194 -0
- package/dist/rules/start-coordinator.js.map +1 -0
- package/dist/rules/tools.d.ts +10 -0
- package/dist/rules/tools.d.ts.map +1 -0
- package/dist/rules/tools.js +58 -0
- package/dist/rules/tools.js.map +1 -0
- package/dist/rules/transition-service.d.ts +49 -0
- package/dist/rules/transition-service.d.ts.map +1 -0
- package/dist/rules/transition-service.js +232 -0
- package/dist/rules/transition-service.js.map +1 -0
- package/dist/rules/types.d.ts +234 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +38 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/rules/validation.d.ts +11 -0
- package/dist/rules/validation.d.ts.map +1 -0
- package/dist/rules/validation.js +308 -0
- package/dist/rules/validation.js.map +1 -0
- package/dist/sandbox/fleet.d.ts +222 -0
- package/dist/sandbox/fleet.d.ts.map +1 -0
- package/dist/sandbox/fleet.js +322 -0
- package/dist/sandbox/fleet.js.map +1 -0
- package/dist/sandbox/reattach.d.ts +3 -0
- package/dist/sandbox/reattach.d.ts.map +1 -0
- package/dist/sandbox/reattach.js +16 -0
- package/dist/sandbox/reattach.js.map +1 -0
- package/dist/server-error.d.ts +12 -0
- package/dist/server-error.d.ts.map +1 -0
- package/dist/server-error.js +16 -0
- package/dist/server-error.js.map +1 -0
- package/dist/skills/service.d.ts +48 -0
- package/dist/skills/service.d.ts.map +1 -0
- package/dist/skills/service.js +40 -0
- package/dist/skills/service.js.map +1 -0
- package/dist/spa-static.d.ts +33 -0
- package/dist/spa-static.d.ts.map +1 -0
- package/dist/spa-static.js +104 -0
- package/dist/spa-static.js.map +1 -0
- package/dist/state-signing.d.ts +59 -0
- package/dist/state-signing.d.ts.map +1 -0
- package/dist/state-signing.js +83 -0
- package/dist/state-signing.js.map +1 -0
- package/dist/storage/domains/audit/agent-audit.d.ts +27 -0
- package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
- package/dist/storage/domains/audit/agent-audit.js +66 -0
- package/dist/storage/domains/audit/agent-audit.js.map +1 -0
- package/dist/storage/domains/audit/base.d.ts +140 -0
- package/dist/storage/domains/audit/base.d.ts.map +1 -0
- package/dist/storage/domains/audit/base.js +184 -0
- package/dist/storage/domains/audit/base.js.map +1 -0
- package/dist/storage/domains/audit/domain.d.ts +69 -0
- package/dist/storage/domains/audit/domain.d.ts.map +1 -0
- package/dist/storage/domains/audit/domain.js +167 -0
- package/dist/storage/domains/audit/domain.js.map +1 -0
- package/dist/storage/domains/channel-identity/base.d.ts +96 -0
- package/dist/storage/domains/channel-identity/base.d.ts.map +1 -0
- package/dist/storage/domains/channel-identity/base.js +149 -0
- package/dist/storage/domains/channel-identity/base.js.map +1 -0
- package/dist/storage/domains/credentials/base.d.ts +134 -0
- package/dist/storage/domains/credentials/base.d.ts.map +1 -0
- package/dist/storage/domains/credentials/base.js +273 -0
- package/dist/storage/domains/credentials/base.js.map +1 -0
- package/dist/storage/domains/custom-providers/base.d.ts +57 -0
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
- package/dist/storage/domains/custom-providers/base.js +145 -0
- package/dist/storage/domains/custom-providers/base.js.map +1 -0
- package/dist/storage/domains/intake/base.d.ts +38 -0
- package/dist/storage/domains/intake/base.d.ts.map +1 -0
- package/dist/storage/domains/intake/base.js +80 -0
- package/dist/storage/domains/intake/base.js.map +1 -0
- package/dist/storage/domains/integrations/base.d.ts +126 -0
- package/dist/storage/domains/integrations/base.d.ts.map +1 -0
- package/dist/storage/domains/integrations/base.js +317 -0
- package/dist/storage/domains/integrations/base.js.map +1 -0
- package/dist/storage/domains/memory-settings/base.d.ts +62 -0
- package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
- package/dist/storage/domains/memory-settings/base.js +126 -0
- package/dist/storage/domains/memory-settings/base.js.map +1 -0
- package/dist/storage/domains/model-packs/base.d.ts +49 -0
- package/dist/storage/domains/model-packs/base.d.ts.map +1 -0
- package/dist/storage/domains/model-packs/base.js +96 -0
- package/dist/storage/domains/model-packs/base.js.map +1 -0
- package/dist/storage/domains/projects/base.d.ts +58 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -0
- package/dist/storage/domains/projects/base.js +111 -0
- package/dist/storage/domains/projects/base.js.map +1 -0
- package/dist/storage/domains/queue-health/base.d.ts +52 -0
- package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
- package/dist/storage/domains/queue-health/base.js +122 -0
- package/dist/storage/domains/queue-health/base.js.map +1 -0
- package/dist/storage/domains/source-control/base.d.ts +358 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -0
- package/dist/storage/domains/source-control/base.js +908 -0
- package/dist/storage/domains/source-control/base.js.map +1 -0
- package/dist/storage/domains/source-control/inmemory.d.ts +175 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/source-control/inmemory.js +377 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +412 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -0
- package/dist/storage/domains/work-items/base.js +1309 -0
- package/dist/storage/domains/work-items/base.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +101 -0
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
- package/dist/storage/domains/work-items/metrics.js +221 -0
- package/dist/storage/domains/work-items/metrics.js.map +1 -0
- package/dist/timing.d.ts +15 -0
- package/dist/timing.d.ts.map +1 -0
- package/dist/timing.js +34 -0
- package/dist/timing.js.map +1 -0
- package/dist/workspace.d.ts +24 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +286 -0
- package/dist/workspace.js.map +1 -0
- package/factory-skills/configure-factory-rules/SKILL.md +67 -0
- package/factory-skills/factory-plan/SKILL.md +61 -0
- package/factory-skills/factory-review/SKILL.md +155 -0
- package/factory-skills/factory-triage/SKILL.md +77 -0
- package/package.json +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","names":["#db"],"sources":["../../../../src/storage/domains/intake/base.ts"],"sourcesContent":["/**\n * Per-user intake selections for every configured intake integration.\n *\n * Integration ids are dynamic. Each integration contributes provider-neutral\n * sources through `FactoryIntegration.intake`; this domain only persists which\n * source ids the user selected.\n */\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nexport interface IntakeSelection {\n enabled: boolean;\n /** Provider-owned source ids; `null` means nothing is selected. */\n sourceIds: string[] | null;\n}\n\nexport type IntakeConfig = Record<string, IntakeSelection>;\n\nexport const DEFAULT_INTAKE_CONFIG: IntakeConfig = {};\n\nexport const INTAKE_SETTINGS_SCHEMA: CollectionSchema = {\n name: 'intake_settings',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n config: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'intake_settings_org_user_unique', columns: ['org_id', 'user_id'] }],\n};\n\nexport class IntakeStorage extends FactoryStorageDomain {\n constructor() {\n super('intake');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([INTAKE_SETTINGS_SCHEMA]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('intake_settings', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n async getConfig({\n orgId,\n userId,\n integrationIds,\n }: {\n orgId: string;\n userId: string;\n /**\n * When provided, the result contains exactly these integration ids, with\n * unset integrations defaulting to `{ enabled: true, sourceIds: null }`.\n */\n integrationIds?: string[];\n }): Promise<IntakeConfig> {\n const row = await this.#db.findOne<{ config: IntakeConfig }>('intake_settings', {\n org_id: orgId,\n user_id: userId,\n });\n const saved = structuredClone(row?.config ?? DEFAULT_INTAKE_CONFIG);\n if (!integrationIds) return saved;\n return Object.fromEntries(\n integrationIds.map(integrationId => [integrationId, saved[integrationId] ?? { enabled: true, sourceIds: null }]),\n );\n }\n\n async saveConfig({ orgId, userId, config }: { orgId: string; userId: string; config: IntakeConfig }): Promise<void> {\n const now = new Date();\n const where = { org_id: orgId, user_id: userId };\n const updated = await this.#db.updateMany('intake_settings', where, { config, updated_at: now });\n if (updated > 0) return;\n try {\n await this.#db.insertOne('intake_settings', { ...where, config, created_at: now, updated_at: now });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n await this.#db.updateMany('intake_settings', where, { config, updated_at: now });\n }\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,MAAa,wBAAsC,CAAC;AAEpD,MAAa,yBAA2C;CACtD,MAAM;CACN,SAA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,iBAAiB,uBAAuB,MAAM;GACpD,MAAM,KAAKA,IAAI,WAAW,mBAAmB,OAAO;IAAE;IAAQ,YAAY;GAAI,CAAC;EACjF;CACF;AACF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic integration storage — the default persistence surface for
|
|
3
|
+
* `FactoryIntegration`s.
|
|
4
|
+
*
|
|
5
|
+
* Most integrations persist the same three shapes: an org-owned OAuth
|
|
6
|
+
* **connection**, **subscriptions** binding external objects to
|
|
7
|
+
* sessions/threads, and per-`(org, user)` **settings**. This built-in domain
|
|
8
|
+
* stores all three in shared collections keyed by `integration_id`, so an
|
|
9
|
+
* integration author writes zero schema, zero DDL, and zero queries — and
|
|
10
|
+
* org scoping is enforced by construction through the pre-scoped handle
|
|
11
|
+
* returned by {@link IntegrationStorage.forIntegration}.
|
|
12
|
+
*
|
|
13
|
+
* Source-control integrations additionally use the shared, provider-scoped
|
|
14
|
+
* source-control domain for installations, projects, worktrees, and sandboxes.
|
|
15
|
+
*
|
|
16
|
+
* Payloads (`data` / `config`) are JSON documents typed per-integration via
|
|
17
|
+
* the handle's generics. JSON round-trips exactly what JSON can represent:
|
|
18
|
+
* store timestamps inside payloads as epoch millis or ISO strings, not
|
|
19
|
+
* `Date`s.
|
|
20
|
+
*/
|
|
21
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
22
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
23
|
+
export declare const INTEGRATION_CONNECTIONS_SCHEMA: CollectionSchema;
|
|
24
|
+
export declare const INTEGRATION_SUBSCRIPTIONS_SCHEMA: CollectionSchema;
|
|
25
|
+
export declare const INTEGRATION_SETTINGS_SCHEMA: CollectionSchema;
|
|
26
|
+
/** An integration's org-owned connection (typically the OAuth grant). */
|
|
27
|
+
export interface IntegrationConnection<TData> {
|
|
28
|
+
id: string;
|
|
29
|
+
orgId: string;
|
|
30
|
+
/** Who connected it (audit only). */
|
|
31
|
+
userId: string | null;
|
|
32
|
+
data: TData;
|
|
33
|
+
metadata: Record<string, unknown>;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
36
|
+
}
|
|
37
|
+
/** A subscription binding an external object to a session/thread. */
|
|
38
|
+
export interface IntegrationSubscription<TData> {
|
|
39
|
+
id: string;
|
|
40
|
+
orgId: string;
|
|
41
|
+
targetKey: string;
|
|
42
|
+
sessionId: string | null;
|
|
43
|
+
resourceId: string | null;
|
|
44
|
+
threadId: string | null;
|
|
45
|
+
sessionScope: string | null;
|
|
46
|
+
status: string;
|
|
47
|
+
data: TData;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
}
|
|
51
|
+
export type CreateIntegrationSubscriptionInput<TData> = {
|
|
52
|
+
orgId: string;
|
|
53
|
+
targetKey: string;
|
|
54
|
+
sessionId?: string | null;
|
|
55
|
+
resourceId?: string | null;
|
|
56
|
+
threadId?: string | null;
|
|
57
|
+
sessionScope?: string | null;
|
|
58
|
+
/** Defaults to `'active'`. */
|
|
59
|
+
status?: string;
|
|
60
|
+
} & ({} extends TData ? {
|
|
61
|
+
data?: TData;
|
|
62
|
+
} : {
|
|
63
|
+
data: TData;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Typed query surface pre-scoped to one `integration_id`. Every read and
|
|
67
|
+
* write is automatically filtered/stamped with the integration id, so an
|
|
68
|
+
* integration cannot reach another integration's rows.
|
|
69
|
+
*/
|
|
70
|
+
export interface IntegrationStorageHandle<TConnection = Record<string, unknown>, TSettings = Record<string, unknown>, TSubscription = Record<string, unknown>> {
|
|
71
|
+
readonly integrationId: string;
|
|
72
|
+
connections: {
|
|
73
|
+
/** The org's connection, or `null` when not connected. */
|
|
74
|
+
get(orgId: string): Promise<IntegrationConnection<TConnection> | null>;
|
|
75
|
+
/** Insert or replace the org's connection (one per org; `created_at` preserved on update). */
|
|
76
|
+
upsert(orgId: string, input: {
|
|
77
|
+
userId?: string | null;
|
|
78
|
+
data: TConnection;
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Atomic read-modify-write of the connection's `data` payload (token
|
|
83
|
+
* rotation etc.). Returns the updated connection, or `null` when the org
|
|
84
|
+
* has no connection.
|
|
85
|
+
*/
|
|
86
|
+
update(orgId: string, fn: (data: TConnection) => TConnection): Promise<IntegrationConnection<TConnection> | null>;
|
|
87
|
+
/** Remove the org's connection. Returns whether a row was deleted. */
|
|
88
|
+
delete(orgId: string): Promise<boolean>;
|
|
89
|
+
};
|
|
90
|
+
subscriptions: {
|
|
91
|
+
create(input: CreateIntegrationSubscriptionInput<TSubscription>): Promise<IntegrationSubscription<TSubscription>>;
|
|
92
|
+
/** All subscriptions for an external object (webhook fan-out), optionally filtered by status. */
|
|
93
|
+
listByTarget(targetKey: string, opts?: {
|
|
94
|
+
status?: string;
|
|
95
|
+
}): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
96
|
+
listBySession(sessionId: string): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
97
|
+
listByThread(resourceId: string, threadId: string): Promise<IntegrationSubscription<TSubscription>[]>;
|
|
98
|
+
updateStatus(id: string, status: string): Promise<void>;
|
|
99
|
+
delete(id: string): Promise<boolean>;
|
|
100
|
+
/** Targeted cleanup, always org-scoped. Returns the number of rows deleted. */
|
|
101
|
+
deleteWhere(where: {
|
|
102
|
+
orgId: string;
|
|
103
|
+
targetKey?: string;
|
|
104
|
+
sessionId?: string;
|
|
105
|
+
}): Promise<number>;
|
|
106
|
+
};
|
|
107
|
+
settings: {
|
|
108
|
+
/** The `(org, user)` config, or `null` when never saved. */
|
|
109
|
+
get(orgId: string, userId: string): Promise<TSettings | null>;
|
|
110
|
+
/** Upsert the `(org, user)` config (`created_at` preserved on update). */
|
|
111
|
+
save(orgId: string, userId: string, config: TSettings): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The built-in generic integration domain, written once against the
|
|
116
|
+
* `FactoryStorageOps` surface — works on any `FactoryStorage` backend.
|
|
117
|
+
*/
|
|
118
|
+
export declare class IntegrationStorage extends FactoryStorageDomain {
|
|
119
|
+
#private;
|
|
120
|
+
constructor();
|
|
121
|
+
init(): Promise<void>;
|
|
122
|
+
dangerouslyClearAll(): Promise<void>;
|
|
123
|
+
/** A typed handle pre-scoped to `integrationId`. */
|
|
124
|
+
forIntegration<TConnection = Record<string, unknown>, TSettings = Record<string, unknown>, TSubscription = Record<string, unknown>>(integrationId: string): IntegrationStorageHandle<TConnection, TSettings, TSubscription>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/integrations/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,eAAO,MAAM,8BAA8B,EAAE,gBAc5C,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,gBAqB9C,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,gBAczC,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,qBAAqB,CAAC,KAAK;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,qEAAqE;AACrE,MAAM,WAAW,uBAAuB,CAAC,KAAK;IAC5C,EAA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AAO,CAAC,CAAC;QACrC,+EAA+E;QAC/E,WAAW,CAAC,KAAK,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;KAChG,CAAC;IACF,QAAQ,EAAE;QACR,4DAA4D;QAC5D,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;QAC9D,0EAA0E;QAC1E,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACvE,CAAC;CACH;AA4BD;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,oBAAoB;;;IAKpD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAU1C,oDAAoD;IACpD,cAAc,CACZ,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,aAAa,EAAE,MAAM,GAAG,wBAAwB,CAAC,WAAW,EAAE,SAAS,EAAE,aAAa,CAAC;CAmL1F"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
2
|
+
//#region src/storage/domains/integrations/base.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generic integration storage — the default persistence surface for
|
|
5
|
+
* `FactoryIntegration`s.
|
|
6
|
+
*
|
|
7
|
+
* Most integrations persist the same three shapes: an org-owned OAuth
|
|
8
|
+
* **connection**, **subscriptions** binding external objects to
|
|
9
|
+
* sessions/threads, and per-`(org, user)` **settings**. This built-in domain
|
|
10
|
+
* stores all three in shared collections keyed by `integration_id`, so an
|
|
11
|
+
* integration author writes zero schema, zero DDL, and zero queries — and
|
|
12
|
+
* org scoping is enforced by construction through the pre-scoped handle
|
|
13
|
+
* returned by {@link IntegrationStorage.forIntegration}.
|
|
14
|
+
*
|
|
15
|
+
* Source-control integrations additionally use the shared, provider-scoped
|
|
16
|
+
* source-control domain for installations, projects, worktrees, and sandboxes.
|
|
17
|
+
*
|
|
18
|
+
* Payloads (`data` / `config`) are JSON documents typed per-integration via
|
|
19
|
+
* the handle's generics. JSON round-trips exactly what JSON can represent:
|
|
20
|
+
* store timestamps inside payloads as epoch millis or ISO strings, not
|
|
21
|
+
* `Date`s.
|
|
22
|
+
*/
|
|
23
|
+
const INTEGRATION_CONNECTIONS_SCHEMA = {
|
|
24
|
+
name: "integration_connections",
|
|
25
|
+
columns: {
|
|
26
|
+
id: { type: "uuid-pk" },
|
|
27
|
+
integration_id: { type: "text" },
|
|
28
|
+
org_id: { type: "text" },
|
|
29
|
+
/** Who connected it (audit only — never scopes reads). */
|
|
30
|
+
user_id: {
|
|
31
|
+
type: "text",
|
|
32
|
+
nullable: true
|
|
33
|
+
},
|
|
34
|
+
data: { type: "json" },
|
|
35
|
+
metadata: { type: "json" },
|
|
36
|
+
created_at: { type: "timestamp" },
|
|
37
|
+
updated_at: { type: "timestamp" }
|
|
38
|
+
},
|
|
39
|
+
uniqueIndexes: [{
|
|
40
|
+
name: "integration_connections_integration_org_unique",
|
|
41
|
+
columns: ["integration_id", "org_id"]
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
const INTEGRATION_SUBSCRIPTIONS_SCHEMA = {
|
|
45
|
+
name: "integration_subscriptions",
|
|
46
|
+
columns: {
|
|
47
|
+
id: { type: "uuid-pk" },
|
|
48
|
+
integration_id: { type: "text" },
|
|
49
|
+
org_id: { type: "text" },
|
|
50
|
+
/** Canonical external-object key the integration derives (e.g. `pr:{installation}:{repo}:{number}`). */
|
|
51
|
+
target_key: { type: "text" },
|
|
52
|
+
session_id: {
|
|
53
|
+
type: "text",
|
|
54
|
+
nullable: true
|
|
55
|
+
},
|
|
56
|
+
resource_id: {
|
|
57
|
+
type: "text",
|
|
58
|
+
nullable: true
|
|
59
|
+
},
|
|
60
|
+
thread_id: {
|
|
61
|
+
type: "text",
|
|
62
|
+
nullable: true
|
|
63
|
+
},
|
|
64
|
+
session_scope: {
|
|
65
|
+
type: "text",
|
|
66
|
+
nullable: true
|
|
67
|
+
},
|
|
68
|
+
status: { type: "text" },
|
|
69
|
+
data: { type: "json" },
|
|
70
|
+
created_at: { type: "timestamp" },
|
|
71
|
+
updated_at: { type: "timestamp" }
|
|
72
|
+
},
|
|
73
|
+
indexes: [{
|
|
74
|
+
name: "integration_subscriptions_target_idx",
|
|
75
|
+
columns: ["integration_id", "target_key"]
|
|
76
|
+
}, {
|
|
77
|
+
name: "integration_subscriptions_org_idx",
|
|
78
|
+
columns: ["integration_id", "org_id"]
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
const INTEGRATION_SETTINGS_SCHEMA = {
|
|
82
|
+
name: "integration_settings",
|
|
83
|
+
columns: {
|
|
84
|
+
id: { type: "uuid-pk" },
|
|
85
|
+
integration_id: { type: "text" },
|
|
86
|
+
org_id: { type: "text" },
|
|
87
|
+
user_id: { type: "text" },
|
|
88
|
+
config: { type: "json" },
|
|
89
|
+
created_at: { type: "timestamp" },
|
|
90
|
+
updated_at: { type: "timestamp" }
|
|
91
|
+
},
|
|
92
|
+
uniqueIndexes: [{
|
|
93
|
+
name: "integration_settings_integration_org_user_unique",
|
|
94
|
+
columns: [
|
|
95
|
+
"integration_id",
|
|
96
|
+
"org_id",
|
|
97
|
+
"user_id"
|
|
98
|
+
]
|
|
99
|
+
}]
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The built-in generic integration domain, written once against the
|
|
103
|
+
* `FactoryStorageOps` surface — works on any `FactoryStorage` backend.
|
|
104
|
+
*/
|
|
105
|
+
var IntegrationStorage = class extends FactoryStorageDomain {
|
|
106
|
+
constructor() {
|
|
107
|
+
super("integrations");
|
|
108
|
+
}
|
|
109
|
+
async init() {
|
|
110
|
+
await this.ensureCollections([
|
|
111
|
+
INTEGRATION_CONNECTIONS_SCHEMA,
|
|
112
|
+
INTEGRATION_SUBSCRIPTIONS_SCHEMA,
|
|
113
|
+
INTEGRATION_SETTINGS_SCHEMA
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
async dangerouslyClearAll() {
|
|
117
|
+
await this.ops.deleteMany("integration_subscriptions", {});
|
|
118
|
+
await this.ops.deleteMany("integration_settings", {});
|
|
119
|
+
await this.ops.deleteMany("integration_connections", {});
|
|
120
|
+
}
|
|
121
|
+
get #db() {
|
|
122
|
+
return this.ops;
|
|
123
|
+
}
|
|
124
|
+
/** A typed handle pre-scoped to `integrationId`. */
|
|
125
|
+
forIntegration(integrationId) {
|
|
126
|
+
if (!integrationId) throw new Error("[IntegrationStorage] integrationId is required.");
|
|
127
|
+
const db = () => this.#db;
|
|
128
|
+
const scoped = { integration_id: integrationId };
|
|
129
|
+
const mapConnection = (row) => ({
|
|
130
|
+
id: row.id,
|
|
131
|
+
orgId: row.org_id,
|
|
132
|
+
userId: row.user_id,
|
|
133
|
+
data: row.data,
|
|
134
|
+
metadata: row.metadata ?? {},
|
|
135
|
+
createdAt: row.created_at,
|
|
136
|
+
updatedAt: row.updated_at
|
|
137
|
+
});
|
|
138
|
+
const mapSubscription = (row) => ({
|
|
139
|
+
id: row.id,
|
|
140
|
+
orgId: row.org_id,
|
|
141
|
+
targetKey: row.target_key,
|
|
142
|
+
sessionId: row.session_id,
|
|
143
|
+
resourceId: row.resource_id,
|
|
144
|
+
threadId: row.thread_id,
|
|
145
|
+
sessionScope: row.session_scope,
|
|
146
|
+
status: row.status,
|
|
147
|
+
data: row.data,
|
|
148
|
+
createdAt: row.created_at,
|
|
149
|
+
updatedAt: row.updated_at
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
integrationId,
|
|
153
|
+
connections: {
|
|
154
|
+
get: async (orgId) => {
|
|
155
|
+
const row = await db().findOne("integration_connections", {
|
|
156
|
+
...scoped,
|
|
157
|
+
org_id: orgId
|
|
158
|
+
});
|
|
159
|
+
return row ? mapConnection(row) : null;
|
|
160
|
+
},
|
|
161
|
+
upsert: async (orgId, input) => {
|
|
162
|
+
const where = {
|
|
163
|
+
...scoped,
|
|
164
|
+
org_id: orgId
|
|
165
|
+
};
|
|
166
|
+
const update = async () => db().updateMany("integration_connections", where, {
|
|
167
|
+
user_id: input.userId ?? null,
|
|
168
|
+
data: input.data,
|
|
169
|
+
metadata: input.metadata ?? {},
|
|
170
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
171
|
+
});
|
|
172
|
+
let lastError;
|
|
173
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
174
|
+
if (await update() > 0) return;
|
|
175
|
+
const now = /* @__PURE__ */ new Date();
|
|
176
|
+
try {
|
|
177
|
+
await db().insertOne("integration_connections", {
|
|
178
|
+
...where,
|
|
179
|
+
user_id: input.userId ?? null,
|
|
180
|
+
data: input.data,
|
|
181
|
+
metadata: input.metadata ?? {},
|
|
182
|
+
created_at: now,
|
|
183
|
+
updated_at: now
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
188
|
+
lastError = error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
throw lastError;
|
|
192
|
+
},
|
|
193
|
+
update: async (orgId, fn) => {
|
|
194
|
+
const row = await db().updateAtomic("integration_connections", {
|
|
195
|
+
...scoped,
|
|
196
|
+
org_id: orgId
|
|
197
|
+
}, (current) => ({
|
|
198
|
+
data: fn(current.data),
|
|
199
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
200
|
+
}));
|
|
201
|
+
return row ? mapConnection(row) : null;
|
|
202
|
+
},
|
|
203
|
+
delete: async (orgId) => {
|
|
204
|
+
return await db().deleteMany("integration_connections", {
|
|
205
|
+
...scoped,
|
|
206
|
+
org_id: orgId
|
|
207
|
+
}) > 0;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
subscriptions: {
|
|
211
|
+
create: async (input) => {
|
|
212
|
+
const now = /* @__PURE__ */ new Date();
|
|
213
|
+
const row = await db().insertOne("integration_subscriptions", {
|
|
214
|
+
...scoped,
|
|
215
|
+
org_id: input.orgId,
|
|
216
|
+
target_key: input.targetKey,
|
|
217
|
+
session_id: input.sessionId ?? null,
|
|
218
|
+
resource_id: input.resourceId ?? null,
|
|
219
|
+
thread_id: input.threadId ?? null,
|
|
220
|
+
session_scope: input.sessionScope ?? null,
|
|
221
|
+
status: input.status ?? "active",
|
|
222
|
+
data: input.data ?? {},
|
|
223
|
+
created_at: now,
|
|
224
|
+
updated_at: now
|
|
225
|
+
});
|
|
226
|
+
return mapSubscription(row);
|
|
227
|
+
},
|
|
228
|
+
listByTarget: async (targetKey, opts) => {
|
|
229
|
+
return (await db().findMany("integration_subscriptions", {
|
|
230
|
+
...scoped,
|
|
231
|
+
target_key: targetKey,
|
|
232
|
+
...opts?.status !== void 0 ? { status: opts.status } : {}
|
|
233
|
+
}, { orderBy: [["created_at", "asc"]] })).map(mapSubscription);
|
|
234
|
+
},
|
|
235
|
+
listBySession: async (sessionId) => {
|
|
236
|
+
return (await db().findMany("integration_subscriptions", {
|
|
237
|
+
...scoped,
|
|
238
|
+
session_id: sessionId
|
|
239
|
+
}, { orderBy: [["created_at", "asc"]] })).map(mapSubscription);
|
|
240
|
+
},
|
|
241
|
+
listByThread: async (resourceId, threadId) => {
|
|
242
|
+
return (await db().findMany("integration_subscriptions", {
|
|
243
|
+
...scoped,
|
|
244
|
+
resource_id: resourceId,
|
|
245
|
+
thread_id: threadId
|
|
246
|
+
}, { orderBy: [["created_at", "asc"]] })).map(mapSubscription);
|
|
247
|
+
},
|
|
248
|
+
updateStatus: async (id, status) => {
|
|
249
|
+
await db().updateMany("integration_subscriptions", {
|
|
250
|
+
...scoped,
|
|
251
|
+
id
|
|
252
|
+
}, {
|
|
253
|
+
status,
|
|
254
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
delete: async (id) => {
|
|
258
|
+
return await db().deleteMany("integration_subscriptions", {
|
|
259
|
+
...scoped,
|
|
260
|
+
id
|
|
261
|
+
}) > 0;
|
|
262
|
+
},
|
|
263
|
+
deleteWhere: async (where) => {
|
|
264
|
+
return db().deleteMany("integration_subscriptions", {
|
|
265
|
+
...scoped,
|
|
266
|
+
org_id: where.orgId,
|
|
267
|
+
...where.targetKey !== void 0 ? { target_key: where.targetKey } : {},
|
|
268
|
+
...where.sessionId !== void 0 ? { session_id: where.sessionId } : {}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
settings: {
|
|
273
|
+
get: async (orgId, userId) => {
|
|
274
|
+
const row = await db().findOne("integration_settings", {
|
|
275
|
+
...scoped,
|
|
276
|
+
org_id: orgId,
|
|
277
|
+
user_id: userId
|
|
278
|
+
});
|
|
279
|
+
return row ? structuredClone(row.config) : null;
|
|
280
|
+
},
|
|
281
|
+
save: async (orgId, userId, config) => {
|
|
282
|
+
const where = {
|
|
283
|
+
...scoped,
|
|
284
|
+
org_id: orgId,
|
|
285
|
+
user_id: userId
|
|
286
|
+
};
|
|
287
|
+
const update = async () => db().updateMany("integration_settings", where, {
|
|
288
|
+
config,
|
|
289
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
290
|
+
});
|
|
291
|
+
let lastError;
|
|
292
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
293
|
+
if (await update() > 0) return;
|
|
294
|
+
const now = /* @__PURE__ */ new Date();
|
|
295
|
+
try {
|
|
296
|
+
await db().insertOne("integration_settings", {
|
|
297
|
+
...where,
|
|
298
|
+
config,
|
|
299
|
+
created_at: now,
|
|
300
|
+
updated_at: now
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
305
|
+
lastError = error;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
throw lastError;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
//#endregion
|
|
315
|
+
export { INTEGRATION_CONNECTIONS_SCHEMA, INTEGRATION_SETTINGS_SCHEMA, INTEGRATION_SUBSCRIPTIONS_SCHEMA, IntegrationStorage };
|
|
316
|
+
|
|
317
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","names":["#db"],"sources":["../../../../src/storage/domains/integrations/base.ts"],"sourcesContent":["/**\n * Generic integration storage — the default persistence surface for\n * `FactoryIntegration`s.\n *\n * Most integrations persist the same three shapes: an org-owned OAuth\n * **connection**, **subscriptions** binding external objects to\n * sessions/threads, and per-`(org, user)` **settings**. This built-in domain\n * stores all three in shared collections keyed by `integration_id`, so an\n * integration author writes zero schema, zero DDL, and zero queries — and\n * org scoping is enforced by construction through the pre-scoped handle\n * returned by {@link IntegrationStorage.forIntegration}.\n *\n * Source-control integrations additionally use the shared, provider-scoped\n * source-control domain for installations, projects, worktrees, and sandboxes.\n *\n * Payloads (`data` / `config`) are JSON documents typed per-integration via\n * the handle's generics. JSON round-trips exactly what JSON can represent:\n * store timestamps inside payloads as epoch millis or ISO strings, not\n * `Date`s.\n */\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nexport const INTEGRATION_CONNECTIONS_SCHEMA: CollectionSchema = {\n name: 'integration_connections',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n /** Who connected it (audit only — never scopes reads). */\n user_id: { type: 'text', nullable: true },\n data: { type: 'json' },\n metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'integration_connections_integration_org_unique', columns: ['integration_id', 'org_id'] }],\n};\n\nexport const INTEGRATION_SUBSCRIPTIONS_SCHEMA: CollectionSchema = {\n name: 'integration_subscriptions',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n /** Canonical external-object key the integration derives (e.g. `pr:{installation}:{repo}:{number}`). */\n target_key: { type: 'text' },\n session_id: { type: 'text', nullable: true },\n resource_id: { type: 'text', nullable: true },\n thread_id: { type: 'text', nullable: true },\n session_scope: { type: 'text', nullable: true },\n status: { type: 'text' },\n data: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n indexes: [\n { name: 'integration_subscriptions_target_idx', columns: ['integration_id', 'target_key'] },\n { name: 'integration_subscriptions_org_idx', columns: ['integration_id', 'org_id'] },\n ],\n};\n\nexport const INTEGRATION_SETTINGS_SCHEMA: CollectionSchema = {\n name: 'integration_settings',\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n config: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'integration_settings_integration_org_user_unique', columns: ['integration_id', 'org_id', 'user_id'] },\n ],\n};\n\n/** An integration's org-owned connection (typically the OAuth grant). */\nexport interface IntegrationConnection<TData> {\n id: string;\n orgId: string;\n /** Who connected it (audit only). */\n userId: string | null;\n data: TData;\n metadata: Record<string, unknown>;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/** A subscription binding an external object to a session/thread. */\nexport interface IntegrationSubscription<TData> {\n id: string;\n orgId: string;\n targetKey: string;\n sessionId: string | null;\n resourceId: string | null;\n threadId: string | null;\n sessionScope: string | null;\n status: string;\n data: TData;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport type CreateIntegrationSubscriptionInput<TData> = {\n orgId: string;\n targetKey: string;\n sessionId?: string | null;\n resourceId?: string | null;\n threadId?: string | null;\n sessionScope?: string | null;\n /** Defaults to `'active'`. */\n status?: string;\n} & ({} extends TData ? { data?: TData } : { data: TData });\n\n/**\n * Typed query surface pre-scoped to one `integration_id`. Every read and\n * write is automatically filtered/stamped with the integration id, so an\n * integration cannot reach another integration's rows.\n */\nexport interface IntegrationStorageHandle<\n TConnection = Record<string, unknown>,\n TSettings = Record<string, unknown>,\n TSubscription = Record<string, unknown>,\n> {\n readonly integrationId: string;\n connections: {\n /** The org's connection, or `null` when not connected. */\n get(orgId: string): Promise<IntegrationConnection<TConnection> | null>;\n /** Insert or replace the org's connection (one per org; `created_at` preserved on update). */\n upsert(\n orgId: string,\n input: { userId?: string | null; data: TConnection; metadata?: Record<string, unknown> },\n ): Promise<void>;\n /**\n * Atomic read-modify-write of the connection's `data` payload (token\n * rotation etc.). Returns the updated connection, or `null` when the org\n * has no connection.\n */\n update(orgId: string, fn: (data: TConnection) => TConnection): Promise<IntegrationConnection<TConnection> | null>;\n /** Remove the org's connection. Returns whether a row was deleted. */\n delete(orgId: string): Promise<boolean>;\n };\n subscriptions: {\n create(input: CreateIntegrationSubscriptionInput<TSubscription>): Promise<IntegrationSubscription<TSubscription>>;\n /** All subscriptions for an external object (webhook fan-out), optionally filtered by status. */\n listByTarget(targetKey: string, opts?: { status?: string }): Promise<IntegrationSubscription<TSubscription>[]>;\n listBySession(sessionId: string): Promise<IntegrationSubscription<TSubscription>[]>;\n listByThread(resourceId: string, threadId: string): Promise<IntegrationSubscription<TSubscription>[]>;\n updateStatus(id: string, status: string): Promise<void>;\n delete(id: string): Promise<boolean>;\n /** Targeted cleanup, always org-scoped. Returns the number of rows deleted. */\n deleteWhere(where: { orgId: string; targetKey?: string; sessionId?: string }): Promise<number>;\n };\n settings: {\n /** The `(org, user)` config, or `null` when never saved. */\n get(orgId: string, userId: string): Promise<TSettings | null>;\n /** Upsert the `(org, user)` config (`created_at` preserved on update). */\n save(orgId: string, userId: string, config: TSettings): Promise<void>;\n };\n}\n\ninterface ConnectionRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n user_id: string | null;\n data: unknown;\n metadata: Record<string, unknown>;\n created_at: Date;\n updated_at: Date;\n}\n\ninterface SubscriptionRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n target_key: string;\n session_id: string | null;\n resource_id: string | null;\n thread_id: string | null;\n session_scope: string | null;\n status: string;\n data: unknown;\n created_at: Date;\n updated_at: Date;\n}\n\n/**\n * The built-in generic integration domain, written once against the\n * `FactoryStorageOps` surface — works on any `FactoryStorage` backend.\n */\nexport class IntegrationStorage extends FactoryStorageDomain {\n constructor() {\n super('integrations');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n INTEGRATION_CONNECTIONS_SCHEMA,\n INTEGRATION_SUBSCRIPTIONS_SCHEMA,\n INTEGRATION_SETTINGS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('integration_subscriptions', {});\n await this.ops.deleteMany('integration_settings', {});\n await this.ops.deleteMany('integration_connections', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n /** A typed handle pre-scoped to `integrationId`. */\n forIntegration<\n TConnection = Record<string, unknown>,\n TSettings = Record<string, unknown>,\n TSubscription = Record<string, unknown>,\n >(integrationId: string): IntegrationStorageHandle<TConnection, TSettings, TSubscription> {\n if (!integrationId) throw new Error('[IntegrationStorage] integrationId is required.');\n const db = () => this.#db;\n const scoped = { integration_id: integrationId };\n\n const mapConnection = (row: ConnectionRow): IntegrationConnection<TConnection> => ({\n id: row.id,\n orgId: row.org_id,\n userId: row.user_id,\n data: row.data as TConnection,\n metadata: row.metadata ?? {},\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n });\n\n const mapSubscription = (row: SubscriptionRow): IntegrationSubscription<TSubscription> => ({\n id: row.id,\n orgId: row.org_id,\n targetKey: row.target_key,\n sessionId: row.session_id,\n resourceId: row.resource_id,\n threadId: row.thread_id,\n sessionScope: row.session_scope,\n status: row.status,\n data: row.data as TSubscription,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n });\n\n return {\n integrationId,\n connections: {\n get: async orgId => {\n const row = await db().findOne<ConnectionRow>('integration_connections', { ...scoped, org_id: orgId });\n return row ? mapConnection(row) : null;\n },\n upsert: async (orgId, input) => {\n const where = { ...scoped, org_id: orgId };\n const update = async () =>\n db().updateMany('integration_connections', where, {\n user_id: input.userId ?? null,\n data: input.data,\n metadata: input.metadata ?? {},\n updated_at: new Date(),\n });\n\n let lastError: unknown;\n for (let attempt = 0; attempt < 2; attempt++) {\n if ((await update()) > 0) return;\n\n const now = new Date();\n try {\n await db().insertOne<ConnectionRow>('integration_connections', {\n ...where,\n user_id: input.userId ?? null,\n data: input.data,\n metadata: input.metadata ?? {},\n created_at: now,\n updated_at: now,\n });\n return;\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n lastError = error;\n }\n }\n throw lastError;\n },\n update: async (orgId, fn) => {\n const row = await db().updateAtomic<ConnectionRow>(\n 'integration_connections',\n { ...scoped, org_id: orgId },\n current => ({ data: fn(current.data as TConnection), updated_at: new Date() }),\n );\n return row ? mapConnection(row) : null;\n },\n delete: async orgId => {\n const deleted = await db().deleteMany('integration_connections', { ...scoped, org_id: orgId });\n return deleted > 0;\n },\n },\n subscriptions: {\n create: async input => {\n const now = new Date();\n const row = await db().insertOne<SubscriptionRow>('integration_subscriptions', {\n ...scoped,\n org_id: input.orgId,\n target_key: input.targetKey,\n session_id: input.sessionId ?? null,\n resource_id: input.resourceId ?? null,\n thread_id: input.threadId ?? null,\n session_scope: input.sessionScope ?? null,\n status: input.status ?? 'active',\n data: input.data ?? {},\n created_at: now,\n updated_at: now,\n });\n return mapSubscription(row);\n },\n listByTarget: async (targetKey, opts) => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, target_key: targetKey, ...(opts?.status !== undefined ? { status: opts.status } : {}) },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n listBySession: async sessionId => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, session_id: sessionId },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n listByThread: async (resourceId, threadId) => {\n const rows = await db().findMany<SubscriptionRow>(\n 'integration_subscriptions',\n { ...scoped, resource_id: resourceId, thread_id: threadId },\n { orderBy: [['created_at', 'asc']] },\n );\n return rows.map(mapSubscription);\n },\n updateStatus: async (id, status) => {\n await db().updateMany('integration_subscriptions', { ...scoped, id }, { status, updated_at: new Date() });\n },\n delete: async id => {\n const deleted = await db().deleteMany('integration_subscriptions', { ...scoped, id });\n return deleted > 0;\n },\n deleteWhere: async where => {\n return db().deleteMany('integration_subscriptions', {\n ...scoped,\n org_id: where.orgId,\n ...(where.targetKey !== undefined ? { target_key: where.targetKey } : {}),\n ...(where.sessionId !== undefined ? { session_id: where.sessionId } : {}),\n });\n },\n },\n settings: {\n get: async (orgId, userId) => {\n const row = await db().findOne<{ config: TSettings }>('integration_settings', {\n ...scoped,\n org_id: orgId,\n user_id: userId,\n });\n return row ? structuredClone(row.config) : null;\n },\n save: async (orgId, userId, config) => {\n const where = { ...scoped, org_id: orgId, user_id: userId };\n const update = async () =>\n db().updateMany('integration_settings', where, {\n config,\n updated_at: new Date(),\n });\n\n let lastError: unknown;\n for (let attempt = 0; attempt < 2; attempt++) {\n if ((await update()) > 0) return;\n\n const now = new Date();\n try {\n await db().insertOne('integration_settings', {\n ...where,\n config,\n created_at: now,\n updated_at: now,\n });\n return;\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n lastError = error;\n }\n }\n throw lastError;\n },\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,iCAAm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M,cAAc,KAAA,IAAY,EAAE,YAAY,MAAM,UAAU,IAAI,CAAC;MACvE,GAAI,MAAM,cAAc,KAAA,IAAY,EAAE,YAAY,MAAM,UAAU,IAAI,CAAC;KACzE,CAAC;IACH;GACF;GACA,UAAU;IACR,KAAK,OAAO,OAAO,WAAW;KAC5B,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,QAA+B,wBAAwB;MAC5E,GAAG;MACH,QAAQ;MACR,SAAS;KACX,CAAC;KACD,OAAO,MAAM,gBAAgB,IAAI,MAAM,IAAI;IAC7C;IACA,MAAM,OAAO,OAAO,QAAQ,WAAW;KACrC,MAAM,QAAQ;MAAE,GAAG;MAAQ,QAAQ;MAAO,SAAS;KAAO;KAC1D,MAAM,SAAS,YACb,GAAG,CAAC,CAAC,WAAW,wBAAwB,OAAO;MAC7C;MACA,4BAAY,IAAI,KAAK;KACvB,CAAC;KAEH,IAAI;KACJ,KAAK,IAAI,UAAU,GAAG,UAAU,GAAG,WAAW;MAC5C,IAAK,MAAM,OAAO,IAAK,GAAG;MAE1B,MAAM,sBAAM,IAAI,KAAK;MACrB,IAAI;OACF,MAAM,GAAG,CAAC,CAAC,UAAU,wBAAwB;QAC3C,GAAG;QACH;QACA,YAAY;QACZ,YAAY;OACd,CAAC;OACD;MACF,SAAS,OAAO;OACd,IAAI,EAAE,iBAAiB,uBAAuB,MAAM;OACpD,YAAY;MACd;KACF;KACA,MAAM;IACR;GACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
2
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
3
|
+
/**
|
|
4
|
+
* A user's persisted memory (observational-memory) configuration. The
|
|
5
|
+
* DB-backed tenant counterpart of the local `settings.json` OM fields
|
|
6
|
+
* (`observerModelOverride`, `reflectorModelOverride`, `omObservationThreshold`,
|
|
7
|
+
* `omReflectionThreshold`, `omObserveAttachments`): one row per `(org, user)`,
|
|
8
|
+
* every knob nullable so only explicitly-changed values are stored.
|
|
9
|
+
*/
|
|
10
|
+
export interface MemorySettingsRecord {
|
|
11
|
+
orgId: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
observerModelId: string | null;
|
|
14
|
+
reflectorModelId: string | null;
|
|
15
|
+
observationThreshold: number | null;
|
|
16
|
+
reflectionThreshold: number | null;
|
|
17
|
+
observeAttachments: 'auto' | boolean | null;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
}
|
|
21
|
+
/** Partial update — only the provided knobs are written. */
|
|
22
|
+
export interface MemorySettingsPatch {
|
|
23
|
+
observerModelId?: string;
|
|
24
|
+
reflectorModelId?: string;
|
|
25
|
+
observationThreshold?: number;
|
|
26
|
+
reflectionThreshold?: number;
|
|
27
|
+
observeAttachments?: 'auto' | boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Knobs written only when the stored value is still unset (`NULL`). The check
|
|
31
|
+
* happens inside the backend's atomic-update primitive, so a concurrent
|
|
32
|
+
* explicit write to the same knob is never clobbered by a fill.
|
|
33
|
+
*/
|
|
34
|
+
export interface MemorySettingsFillIfUnset {
|
|
35
|
+
observerModelId?: string;
|
|
36
|
+
reflectorModelId?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const MEMORY_SETTINGS_SCHEMA: CollectionSchema;
|
|
39
|
+
export declare class MemorySettingsStorage extends FactoryStorageDomain {
|
|
40
|
+
#private;
|
|
41
|
+
constructor();
|
|
42
|
+
init(): Promise<void>;
|
|
43
|
+
dangerouslyClearAll(): Promise<void>;
|
|
44
|
+
get({ orgId, userId }: {
|
|
45
|
+
orgId: string;
|
|
46
|
+
userId: string;
|
|
47
|
+
}): Promise<MemorySettingsRecord | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Upsert the user's row, writing only the knobs present in `patch`.
|
|
50
|
+
* `fillIfUnset` knobs are written only where the stored value is still
|
|
51
|
+
* `NULL`, decided inside the atomic update so concurrent explicit writes
|
|
52
|
+
* win over fills. Concurrent first writes are resolved via the shared
|
|
53
|
+
* insert-then-catch-unique-violation pattern (see `queue_health`).
|
|
54
|
+
*/
|
|
55
|
+
patch({ orgId, userId, patch, fillIfUnset, }: {
|
|
56
|
+
orgId: string;
|
|
57
|
+
userId: string;
|
|
58
|
+
patch: MemorySettingsPatch;
|
|
59
|
+
fillIfUnset?: MemorySettingsFillIfUnset;
|
|
60
|
+
}): Promise<MemorySettingsRecord>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory-settings/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,kBAAkB,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IAC5C,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACv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