@mastra/cloudflare 1.0.0-beta.11 → 1.0.0-beta.12

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,51 @@
1
1
  # @mastra/cloudflare
2
2
 
3
+ ## 1.0.0-beta.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Added new `listThreads` method for flexible thread filtering across all storage adapters. ([#11832](https://github.com/mastra-ai/mastra/pull/11832))
8
+
9
+ **New Features**
10
+ - Filter threads by `resourceId`, `metadata`, or both (with AND logic for metadata key-value pairs)
11
+ - All filter parameters are optional, allowing you to list all threads or filter as needed
12
+ - Full pagination and sorting support
13
+
14
+ **Example Usage**
15
+
16
+ ```typescript
17
+ // List all threads
18
+ const allThreads = await memory.listThreads({});
19
+
20
+ // Filter by resourceId only
21
+ const userThreads = await memory.listThreads({
22
+ filter: { resourceId: 'user-123' },
23
+ });
24
+
25
+ // Filter by metadata only
26
+ const supportThreads = await memory.listThreads({
27
+ filter: { metadata: { category: 'support' } },
28
+ });
29
+
30
+ // Filter by both with pagination
31
+ const filteredThreads = await memory.listThreads({
32
+ filter: {
33
+ resourceId: 'user-123',
34
+ metadata: { priority: 'high', status: 'open' },
35
+ },
36
+ orderBy: { field: 'updatedAt', direction: 'DESC' },
37
+ page: 0,
38
+ perPage: 20,
39
+ });
40
+ ```
41
+
42
+ **Security Improvements**
43
+ - Added validation to prevent SQL injection via malicious metadata keys
44
+ - Added pagination parameter validation to prevent integer overflow attacks
45
+
46
+ - Updated dependencies [[`ed3e3dd`](https://github.com/mastra-ai/mastra/commit/ed3e3ddec69d564fe2b125e083437f76331f1283), [`6833c69`](https://github.com/mastra-ai/mastra/commit/6833c69607418d257750bbcdd84638993d343539), [`47b1c16`](https://github.com/mastra-ai/mastra/commit/47b1c16a01c7ffb6765fe1e499b49092f8b7eba3), [`3a76a80`](https://github.com/mastra-ai/mastra/commit/3a76a80284cb71a0faa975abb3d4b2a9631e60cd), [`8538a0d`](https://github.com/mastra-ai/mastra/commit/8538a0d232619bf55dad7ddc2a8b0ca77c679a87), [`9312dcd`](https://github.com/mastra-ai/mastra/commit/9312dcd1c6f5b321929e7d382e763d95fdc030f5)]:
47
+ - @mastra/core@1.0.0-beta.25
48
+
3
49
  ## 1.0.0-beta.11
4
50
 
5
51
  ### Patch Changes
@@ -28,4 +28,4 @@ docs/
28
28
  ## Version
29
29
 
30
30
  Package: @mastra/cloudflare
31
- Version: 1.0.0-beta.11
31
+ Version: 1.0.0-beta.12
@@ -5,7 +5,7 @@ description: Documentation for @mastra/cloudflare. Includes links to type defini
5
5
 
6
6
  # @mastra/cloudflare Documentation
7
7
 
8
- > **Version**: 1.0.0-beta.11
8
+ > **Version**: 1.0.0-beta.12
9
9
  > **Package**: @mastra/cloudflare
10
10
 
11
11
  ## Quick Navigation
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.11",
2
+ "version": "1.0.0-beta.12",
3
3
  "package": "@mastra/cloudflare",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -620,21 +620,23 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
620
620
  return null;
621
621
  }
622
622
  }
623
- async listThreadsByResourceId(args) {
623
+ async listThreads(args) {
624
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
625
+ try {
626
+ this.validatePaginationInput(page, perPageInput ?? 100);
627
+ } catch (error$1) {
628
+ throw new error.MastraError(
629
+ {
630
+ id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS", "INVALID_PAGE"),
631
+ domain: error.ErrorDomain.STORAGE,
632
+ category: error.ErrorCategory.USER,
633
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
634
+ },
635
+ error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
636
+ );
637
+ }
638
+ const perPage = storage.normalizePerPage(perPageInput, 100);
624
639
  try {
625
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
626
- const perPage = storage.normalizePerPage(perPageInput, 100);
627
- if (page < 0) {
628
- throw new error.MastraError(
629
- {
630
- id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
631
- domain: error.ErrorDomain.STORAGE,
632
- category: error.ErrorCategory.USER,
633
- details: { page }
634
- },
635
- new Error("page must be >= 0")
636
- );
637
- }
638
640
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
639
641
  const { field, direction } = this.parseOrderBy(orderBy);
640
642
  const prefix = this.#db.namespacePrefix ? `${this.#db.namespacePrefix}:` : "";
@@ -643,7 +645,15 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
643
645
  for (const { name: key } of keyObjs) {
644
646
  const data = await this.#db.getKV(storage.TABLE_THREADS, key);
645
647
  if (!data) continue;
646
- if (data.resourceId !== resourceId) continue;
648
+ if (filter?.resourceId && data.resourceId !== filter.resourceId) {
649
+ continue;
650
+ }
651
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
652
+ const metadata = this.ensureMetadata(data.metadata);
653
+ if (!metadata) continue;
654
+ const matches = Object.entries(filter.metadata).every(([key2, value]) => metadata[key2] === value);
655
+ if (!matches) continue;
656
+ }
647
657
  threads.push(data);
648
658
  }
649
659
  threads.sort((a, b) => {
@@ -663,10 +673,10 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
663
673
  } catch (error$1) {
664
674
  throw new error.MastraError(
665
675
  {
666
- id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
676
+ id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS", "FAILED"),
667
677
  domain: error.ErrorDomain.STORAGE,
668
678
  category: error.ErrorCategory.THIRD_PARTY,
669
- text: "Failed to get threads by resource ID with pagination"
679
+ text: "Failed to list threads with filters"
670
680
  },
671
681
  error$1
672
682
  );