@mastra/pg 1.9.4-alpha.0 → 1.9.4

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed workflow snapshot sanitization in `@mastra/pg` for strings containing escaped surrogate patterns like `[^\ud800-\udfff]`. This prevents invalid JSON escape sequences that caused PostgreSQL `jsonb` writes to fail with error `22P02`. ([#15923](https://github.com/mastra-ai/mastra/pull/15923))
8
+
9
+ Fixes #15920
10
+
11
+ - Added platform channels framework with ChannelProvider interface, ChannelsStorage domain, and ChannelConnectResult discriminated union supporting OAuth, deep link, and immediate connection flows. Channels can be registered on the Mastra instance and expose connect/disconnect/list APIs for platform integrations. ([#15876](https://github.com/mastra-ai/mastra/pull/15876))
12
+
13
+ - Updated dependencies [[`1723e09`](https://github.com/mastra-ai/mastra/commit/1723e099829892419ddbfe49287acfeac2522724), [`629f9e9`](https://github.com/mastra-ai/mastra/commit/629f9e9a7e56aa8f129515a3923c5813298790c7), [`25168fb`](https://github.com/mastra-ai/mastra/commit/25168fb9c1de9db7f8171df4f58ceb842c53aa29), [`ab34b5a`](https://github.com/mastra-ai/mastra/commit/ab34b5a2191b8e4353df1dbf7b9155e7d6628d79), [`5fb6c2a`](https://github.com/mastra-ai/mastra/commit/5fb6c2a95c1843cc231704b91354311fc1f34a71), [`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4), [`394f0cf`](https://github.com/mastra-ai/mastra/commit/394f0cfc31e6b4d801219fdef2e9cc69e5bc8682), [`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`3d7f709`](https://github.com/mastra-ai/mastra/commit/3d7f709b615e588050bb6283c4ee5cfe2978cbde), [`48a42f1`](https://github.com/mastra-ai/mastra/commit/48a42f114a4006a95e0b7a1b5ad1a24815a175c2), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`2c83efc`](https://github.com/mastra-ai/mastra/commit/2c83efc4482b3efe50830e3b8b4ba9a8d219edff), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e), [`282a10c`](https://github.com/mastra-ai/mastra/commit/282a10c9446e9922afe80e10e3770481c8ac8a28), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
14
+ - @mastra/core@1.31.0
15
+
16
+ ## 1.9.4-alpha.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Added platform channels framework with ChannelProvider interface, ChannelsStorage domain, and ChannelConnectResult discriminated union supporting OAuth, deep link, and immediate connection flows. Channels can be registered on the Mastra instance and expose connect/disconnect/list APIs for platform integrations. ([#15876](https://github.com/mastra-ai/mastra/pull/15876))
21
+
22
+ - Updated dependencies [[`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e)]:
23
+ - @mastra/core@1.31.0-alpha.3
24
+
3
25
  ## 1.9.4-alpha.0
4
26
 
5
27
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.9.4-alpha.0"
6
+ version: "1.9.4"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.4-alpha.0",
2
+ "version": "1.9.4",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -4658,6 +4658,202 @@ var BlobsPG = class extends storage.BlobStore {
4658
4658
  };
4659
4659
  }
4660
4660
  };
4661
+ var ChannelsPG = class _ChannelsPG extends storage.ChannelsStorage {
4662
+ #db;
4663
+ #schema;
4664
+ #skipDefaultIndexes;
4665
+ #indexes;
4666
+ static MANAGED_TABLES = [storage.TABLE_CHANNEL_INSTALLATIONS, storage.TABLE_CHANNEL_CONFIG];
4667
+ constructor(config) {
4668
+ super();
4669
+ const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
4670
+ this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
4671
+ this.#schema = schemaName || "public";
4672
+ this.#skipDefaultIndexes = skipDefaultIndexes;
4673
+ this.#indexes = indexes?.filter((idx) => _ChannelsPG.MANAGED_TABLES.includes(idx.table));
4674
+ }
4675
+ async init() {
4676
+ await this.#db.createTable({
4677
+ tableName: storage.TABLE_CHANNEL_INSTALLATIONS,
4678
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_CHANNEL_INSTALLATIONS]
4679
+ });
4680
+ await this.#db.createTable({
4681
+ tableName: storage.TABLE_CHANNEL_CONFIG,
4682
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_CHANNEL_CONFIG]
4683
+ });
4684
+ await this.createDefaultIndexes();
4685
+ await this.createCustomIndexes();
4686
+ }
4687
+ static getDefaultIndexDefs(schemaPrefix) {
4688
+ return [
4689
+ {
4690
+ name: `${schemaPrefix}idx_channel_installations_webhook`,
4691
+ table: storage.TABLE_CHANNEL_INSTALLATIONS,
4692
+ columns: ["webhookId"],
4693
+ unique: true
4694
+ },
4695
+ {
4696
+ name: `${schemaPrefix}idx_channel_installations_platform_agent`,
4697
+ table: storage.TABLE_CHANNEL_INSTALLATIONS,
4698
+ columns: ["platform", "agentId"]
4699
+ }
4700
+ ];
4701
+ }
4702
+ static getExportDDL(schemaName) {
4703
+ const statements = [];
4704
+ const parsedSchema = schemaName ? utils.parseSqlIdentifier(schemaName, "schema name") : "";
4705
+ const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
4706
+ for (const tableName of _ChannelsPG.MANAGED_TABLES) {
4707
+ statements.push(
4708
+ generateTableSQL({
4709
+ tableName,
4710
+ schema: storage.TABLE_SCHEMAS[tableName],
4711
+ schemaName,
4712
+ includeAllConstraints: true
4713
+ })
4714
+ );
4715
+ }
4716
+ for (const idx of _ChannelsPG.getDefaultIndexDefs(schemaPrefix)) {
4717
+ statements.push(generateIndexSQL(idx, schemaName));
4718
+ }
4719
+ return statements;
4720
+ }
4721
+ getDefaultIndexDefinitions() {
4722
+ const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
4723
+ return _ChannelsPG.getDefaultIndexDefs(schemaPrefix);
4724
+ }
4725
+ async createDefaultIndexes() {
4726
+ if (this.#skipDefaultIndexes) return;
4727
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
4728
+ try {
4729
+ await this.#db.createIndex(indexDef);
4730
+ } catch (error) {
4731
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
4732
+ }
4733
+ }
4734
+ }
4735
+ async createCustomIndexes() {
4736
+ if (!this.#indexes || this.#indexes.length === 0) return;
4737
+ for (const indexDef of this.#indexes) {
4738
+ try {
4739
+ await this.#db.createIndex(indexDef);
4740
+ } catch (error) {
4741
+ this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
4742
+ }
4743
+ }
4744
+ }
4745
+ async dangerouslyClearAll() {
4746
+ await this.#db.clearTable({ tableName: storage.TABLE_CHANNEL_INSTALLATIONS });
4747
+ await this.#db.clearTable({ tableName: storage.TABLE_CHANNEL_CONFIG });
4748
+ }
4749
+ async saveInstallation(installation) {
4750
+ const schemaName = getSchemaName2(this.#schema);
4751
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4752
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4753
+ await this.#db.client.none(
4754
+ `INSERT INTO ${tableName} ("id", "platform", "agentId", "status", "webhookId", "data", "configHash", "error", "createdAt", "updatedAt")
4755
+ VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7, $8, $9, $10)
4756
+ ON CONFLICT ("id") DO UPDATE SET
4757
+ "platform" = EXCLUDED."platform",
4758
+ "agentId" = EXCLUDED."agentId",
4759
+ "status" = EXCLUDED."status",
4760
+ "webhookId" = EXCLUDED."webhookId",
4761
+ "data" = EXCLUDED."data",
4762
+ "configHash" = EXCLUDED."configHash",
4763
+ "error" = EXCLUDED."error",
4764
+ "updatedAt" = EXCLUDED."updatedAt"`,
4765
+ [
4766
+ installation.id,
4767
+ installation.platform,
4768
+ installation.agentId,
4769
+ installation.status,
4770
+ installation.webhookId ?? null,
4771
+ JSON.stringify(installation.data),
4772
+ installation.configHash ?? null,
4773
+ installation.error ?? null,
4774
+ installation.createdAt?.toISOString() ?? now,
4775
+ now
4776
+ ]
4777
+ );
4778
+ }
4779
+ async getInstallation(id) {
4780
+ const schemaName = getSchemaName2(this.#schema);
4781
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4782
+ const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
4783
+ return row ? this.#parseInstallationRow(row) : null;
4784
+ }
4785
+ async getInstallationByAgent(platform, agentId) {
4786
+ const schemaName = getSchemaName2(this.#schema);
4787
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4788
+ const row = await this.#db.client.oneOrNone(
4789
+ `SELECT * FROM ${tableName} WHERE "platform" = $1 AND "agentId" = $2 ORDER BY CASE "status" WHEN 'active' THEN 0 WHEN 'pending' THEN 1 ELSE 2 END, "updatedAt" DESC LIMIT 1`,
4790
+ [platform, agentId]
4791
+ );
4792
+ return row ? this.#parseInstallationRow(row) : null;
4793
+ }
4794
+ async getInstallationByWebhookId(webhookId) {
4795
+ const schemaName = getSchemaName2(this.#schema);
4796
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4797
+ const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "webhookId" = $1`, [webhookId]);
4798
+ return row ? this.#parseInstallationRow(row) : null;
4799
+ }
4800
+ async listInstallations(platform) {
4801
+ const schemaName = getSchemaName2(this.#schema);
4802
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4803
+ const rows = await this.#db.client.manyOrNone(
4804
+ `SELECT * FROM ${tableName} WHERE "platform" = $1 ORDER BY "createdAt" DESC`,
4805
+ [platform]
4806
+ );
4807
+ return rows.map((row) => this.#parseInstallationRow(row));
4808
+ }
4809
+ async deleteInstallation(id) {
4810
+ const schemaName = getSchemaName2(this.#schema);
4811
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_INSTALLATIONS, schemaName });
4812
+ await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
4813
+ }
4814
+ async saveConfig(config) {
4815
+ const schemaName = getSchemaName2(this.#schema);
4816
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
4817
+ await this.#db.client.none(
4818
+ `INSERT INTO ${tableName} ("platform", "data", "updatedAt")
4819
+ VALUES ($1, $2::jsonb, $3)
4820
+ ON CONFLICT ("platform") DO UPDATE SET
4821
+ "data" = EXCLUDED."data",
4822
+ "updatedAt" = EXCLUDED."updatedAt"`,
4823
+ [config.platform, JSON.stringify(config.data), config.updatedAt.toISOString()]
4824
+ );
4825
+ }
4826
+ async getConfig(platform) {
4827
+ const schemaName = getSchemaName2(this.#schema);
4828
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
4829
+ const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1`, [platform]);
4830
+ if (!row) return null;
4831
+ return {
4832
+ platform: row.platform,
4833
+ data: typeof row.data === "string" ? JSON.parse(row.data) : row.data,
4834
+ updatedAt: new Date(row.updatedAt)
4835
+ };
4836
+ }
4837
+ async deleteConfig(platform) {
4838
+ const schemaName = getSchemaName2(this.#schema);
4839
+ const tableName = getTableName2({ indexName: storage.TABLE_CHANNEL_CONFIG, schemaName });
4840
+ await this.#db.client.none(`DELETE FROM ${tableName} WHERE "platform" = $1`, [platform]);
4841
+ }
4842
+ #parseInstallationRow(row) {
4843
+ return {
4844
+ id: row.id,
4845
+ platform: row.platform,
4846
+ agentId: row.agentId,
4847
+ status: row.status,
4848
+ webhookId: row.webhookId || void 0,
4849
+ data: typeof row.data === "string" ? JSON.parse(row.data) : row.data,
4850
+ configHash: row.configHash || void 0,
4851
+ error: row.error || void 0,
4852
+ createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
4853
+ updatedAt: row.updatedAt instanceof Date ? row.updatedAt : new Date(row.updatedAt)
4854
+ };
4855
+ }
4856
+ };
4661
4857
  function jsonbArg(value) {
4662
4858
  return value === void 0 || value === null ? null : JSON.stringify(value);
4663
4859
  }
@@ -14034,7 +14230,8 @@ var ALL_DOMAINS = [
14034
14230
  WorkflowsPG,
14035
14231
  DatasetsPG,
14036
14232
  ExperimentsPG,
14037
- BackgroundTasksPG
14233
+ BackgroundTasksPG,
14234
+ ChannelsPG
14038
14235
  ];
14039
14236
  function exportSchemas(schemaName) {
14040
14237
  const statements = [];
@@ -14089,7 +14286,8 @@ var PostgresStore = class extends storage.MastraCompositeStore {
14089
14286
  blobs: new BlobsPG(domainConfig),
14090
14287
  datasets: new DatasetsPG(domainConfig),
14091
14288
  experiments: new ExperimentsPG(domainConfig),
14092
- backgroundTasks: new BackgroundTasksPG(domainConfig)
14289
+ backgroundTasks: new BackgroundTasksPG(domainConfig),
14290
+ channels: new ChannelsPG(domainConfig)
14093
14291
  };
14094
14292
  } catch (e) {
14095
14293
  throw new error.MastraError(
@@ -14281,6 +14479,7 @@ Example Complex Query:
14281
14479
  exports.AgentsPG = AgentsPG;
14282
14480
  exports.BackgroundTasksPG = BackgroundTasksPG;
14283
14481
  exports.BlobsPG = BlobsPG;
14482
+ exports.ChannelsPG = ChannelsPG;
14284
14483
  exports.DatasetsPG = DatasetsPG;
14285
14484
  exports.ExperimentsPG = ExperimentsPG;
14286
14485
  exports.MCPClientsPG = MCPClientsPG;