@mastra/deployer-cloudflare 0.0.1-alpha.3 → 0.0.1-alpha.31

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,234 @@
1
1
  # @mastra/deployer-cloudflare
2
2
 
3
+ ## 0.0.1-alpha.31
4
+
5
+ ### Patch Changes
6
+
7
+ - 9625602: Use mastra core splitted bundles in other packages
8
+ - Updated dependencies [2ab57d6]
9
+ - Updated dependencies [30322ce]
10
+ - Updated dependencies [78eec7c]
11
+ - Updated dependencies [9625602]
12
+ - Updated dependencies [8769a62]
13
+ - @mastra/deployer@0.0.1-alpha.28
14
+ - @mastra/core@0.2.0-alpha.83
15
+
16
+ ## 0.0.1-alpha.30
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [73d112c]
21
+ - Updated dependencies [ac8c61a]
22
+ - @mastra/deployer@0.0.1-alpha.27
23
+ - @mastra/core@0.1.27-alpha.82
24
+
25
+ ## 0.0.1-alpha.29
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [9fb3039]
30
+ - @mastra/core@0.1.27-alpha.81
31
+ - @mastra/deployer@0.0.1-alpha.26
32
+
33
+ ## 0.0.1-alpha.28
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [327ece7]
38
+ - @mastra/core@0.1.27-alpha.80
39
+ - @mastra/deployer@0.0.1-alpha.25
40
+
41
+ ## 0.0.1-alpha.27
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [21fe536]
46
+ - @mastra/core@0.1.27-alpha.79
47
+ - @mastra/deployer@0.0.1-alpha.24
48
+
49
+ ## 0.0.1-alpha.26
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [88f18d7]
54
+ - @mastra/deployer@0.0.1-alpha.23
55
+
56
+ ## 0.0.1-alpha.25
57
+
58
+ ### Patch Changes
59
+
60
+ - 44c7c26: Rebuild
61
+
62
+ ## 0.0.1-alpha.24
63
+
64
+ ### Patch Changes
65
+
66
+ - Updated dependencies [685108a]
67
+ - Updated dependencies [685108a]
68
+ - @mastra/deployer@0.0.1-alpha.22
69
+ - @mastra/core@0.1.27-alpha.78
70
+
71
+ ## 0.0.1-alpha.23
72
+
73
+ ### Patch Changes
74
+
75
+ - 2b75edf: mastra deployers tsup bundling
76
+ - Updated dependencies [8105fae]
77
+ - Updated dependencies [cfb966f]
78
+ - @mastra/core@0.1.27-alpha.77
79
+ - @mastra/deployer@0.0.1-alpha.21
80
+
81
+ ## 0.0.1-alpha.22
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [ae7bf94]
86
+ - Updated dependencies [ae7bf94]
87
+ - @mastra/deployer@0.0.1-alpha.20
88
+ - @mastra/core@0.1.27-alpha.76
89
+
90
+ ## 0.0.1-alpha.21
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [23dcb23]
95
+ - Updated dependencies [7064554]
96
+ - @mastra/core@0.1.27-alpha.75
97
+ - @mastra/deployer@0.0.1-alpha.19
98
+
99
+ ## 0.0.1-alpha.20
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies [7b87567]
104
+ - @mastra/core@0.1.27-alpha.74
105
+ - @mastra/deployer@0.0.1-alpha.18
106
+
107
+ ## 0.0.1-alpha.19
108
+
109
+ ### Patch Changes
110
+
111
+ - Updated dependencies [3427b95]
112
+ - @mastra/core@0.1.27-alpha.73
113
+ - @mastra/deployer@0.0.1-alpha.17
114
+
115
+ ## 0.0.1-alpha.18
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [e4d4ede]
120
+ - Updated dependencies [06b2c0a]
121
+ - @mastra/core@0.1.27-alpha.72
122
+ - @mastra/deployer@0.0.1-alpha.16
123
+
124
+ ## 0.0.1-alpha.17
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies [d9c8dd0]
129
+ - @mastra/deployer@0.0.1-alpha.15
130
+ - @mastra/core@0.1.27-alpha.71
131
+
132
+ ## 0.0.1-alpha.16
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [ad2cd74]
137
+ - @mastra/deployer@0.0.1-alpha.14
138
+
139
+ ## 0.0.1-alpha.15
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [a1774e7]
144
+ - @mastra/deployer@0.0.1-alpha.13
145
+
146
+ ## 0.0.1-alpha.14
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [28dceab]
151
+ - @mastra/deployer@0.0.1-alpha.12
152
+
153
+ ## 0.0.1-alpha.13
154
+
155
+ ### Patch Changes
156
+
157
+ - bdaf834: publish packages
158
+ - Updated dependencies [bdaf834]
159
+ - @mastra/deployer@0.0.1-alpha.11
160
+
161
+ ## 0.0.1-alpha.12
162
+
163
+ ### Patch Changes
164
+
165
+ - Updated dependencies [dd6d87f]
166
+ - Updated dependencies [04434b6]
167
+ - @mastra/core@0.1.27-alpha.70
168
+ - @mastra/deployer@0.0.1-alpha.10
169
+
170
+ ## 0.0.1-alpha.11
171
+
172
+ ### Patch Changes
173
+
174
+ - 9066f95: CF deployer fixes
175
+ - Updated dependencies [9066f95]
176
+ - @mastra/deployer@0.0.1-alpha.9
177
+
178
+ ## 0.0.1-alpha.10
179
+
180
+ ### Patch Changes
181
+
182
+ - 0d5a03d: Vector store modules
183
+
184
+ ## 0.0.1-alpha.9
185
+
186
+ ### Patch Changes
187
+
188
+ - Updated dependencies [b425845]
189
+ - @mastra/deployer@0.0.1-alpha.8
190
+
191
+ ## 0.0.1-alpha.8
192
+
193
+ ### Patch Changes
194
+
195
+ - 1944807: Unified logger and major step in better logs
196
+ - c7abf8e: Optional CF worker tagging
197
+ - Updated dependencies [1944807]
198
+ - Updated dependencies [9ade36e]
199
+ - @mastra/deployer@0.0.1-alpha.7
200
+ - @mastra/core@0.1.27-alpha.69
201
+
202
+ ## 0.0.1-alpha.7
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies [291fe57]
207
+ - Updated dependencies [1a41fbf]
208
+ - @mastra/deployer@0.0.1-alpha.6
209
+
210
+ ## 0.0.1-alpha.6
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [0be7181]
215
+ - Updated dependencies [0be7181]
216
+ - @mastra/core@0.1.27-alpha.68
217
+ - @mastra/deployer@0.0.1-alpha.5
218
+
219
+ ## 0.0.1-alpha.5
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [7babd5c]
224
+ - @mastra/deployer@0.0.1-alpha.4
225
+
226
+ ## 0.0.1-alpha.4
227
+
228
+ ### Patch Changes
229
+
230
+ - 026ca5d: Optional dispatcher namespace configuration for cloudflare deployments
231
+
3
232
  ## 0.0.1-alpha.3
4
233
 
5
234
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @mastra/deployer-cloudflare
2
+
3
+ A Cloudflare Workers deployer for Mastra applications.
4
+
5
+ ## Features
6
+
7
+ - Deploy Mastra applications to Cloudflare Workers
8
+ - Configure custom domains and routes
9
+ - Support for worker namespaces
10
+ - Automatic environment variable configuration
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @mastra/deployer-cloudflare
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ The Cloudflare deployer is used as part of the Mastra framework:
21
+
22
+ ```typescript
23
+ import { Mastra } from '@mastra/core';
24
+ import { CloudflareDeployer } from '@mastra/deployer-cloudflare';
25
+
26
+ const deployer = new CloudflareDeployer({
27
+ scope: 'your-account-id',
28
+ projectName: 'your-project-name',
29
+ routes: [
30
+ {
31
+ pattern: 'example.com/*',
32
+ zone_name: 'example.com',
33
+ custom_domain: true,
34
+ },
35
+ ],
36
+ workerNamespace: 'your-namespace',
37
+ auth: {
38
+ apiToken: 'your-api-token',
39
+ apiEmail: 'your-email',
40
+ },
41
+ });
42
+
43
+ const mastra = new Mastra({
44
+ deployer,
45
+ // ... other Mastra configuration options
46
+ });
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ ### Constructor Options
52
+
53
+ - `scope` (required): Your Cloudflare account ID
54
+ - `projectName`: Name of your worker project
55
+ - `routes`: Array of route configurations for your worker
56
+ - `pattern`: URL pattern to match
57
+ - `zone_name`: Domain zone name
58
+ - `custom_domain`: Whether to use a custom domain
59
+ - `workerNamespace`: Namespace for your worker
60
+ - `auth`: Cloudflare authentication details
61
+ - `apiToken`: Your Cloudflare API token
62
+ - `apiEmail`: Your Cloudflare account email
63
+
64
+ ## Environment Variables
65
+
66
+ The deployer will automatically load environment variables from:
67
+
68
+ - `.env` files in your project
69
+ - Environment variables passed through the Mastra configuration
70
+
71
+ ## Routes
72
+
73
+ Routes can be configured to direct traffic to your worker based on URL patterns and domains:
74
+
75
+ ```typescript
76
+ const routes = [
77
+ {
78
+ pattern: 'api.example.com/*',
79
+ zone_name: 'example.com',
80
+ custom_domain: true,
81
+ },
82
+ {
83
+ pattern: 'example.com/api/*',
84
+ zone_name: 'example.com',
85
+ },
86
+ ];
87
+ ```
88
+
89
+ Each route requires:
90
+
91
+ - `pattern`: URL pattern to match
92
+ - `zone_name`: Domain zone name
93
+ - `custom_domain`: (optional) Set to true to use a custom domain
94
+
95
+ ## Requirements
96
+
97
+ - Cloudflare account with Workers enabled
98
+ - API token with appropriate permissions
99
+ - Domain(s) configured in Cloudflare (for custom domains)
package/dist/index.d.ts CHANGED
@@ -1,16 +1,24 @@
1
- import { MastraDeployer } from '@mastra/core';
1
+ import { MastraDeployer } from '@mastra/core/deployer';
2
+
2
3
  interface CFRoute {
3
4
  pattern: string;
4
5
  zone_name: string;
5
6
  custom_domain?: boolean;
6
7
  }
7
- export declare class CloudflareDeployer extends MastraDeployer {
8
+ declare class CloudflareDeployer extends MastraDeployer {
9
+ private cloudflare;
8
10
  routes?: CFRoute[];
9
- constructor({ scope, env, projectName, routes, }: {
11
+ workerNamespace?: string;
12
+ constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
10
13
  env?: Record<string, any>;
11
14
  scope: string;
12
15
  projectName: string;
13
16
  routes?: CFRoute[];
17
+ workerNamespace?: string;
18
+ auth?: {
19
+ apiToken: string;
20
+ apiEmail: string;
21
+ };
14
22
  });
15
23
  writeFiles({ dir }: {
16
24
  dir: string;
@@ -22,6 +30,12 @@ export declare class CloudflareDeployer extends MastraDeployer {
22
30
  dir: string;
23
31
  token: string;
24
32
  }): Promise<void>;
33
+ tagWorker({ workerName, namespace, tags, scope, }: {
34
+ scope: string;
35
+ workerName: string;
36
+ namespace: string;
37
+ tags: string[];
38
+ }): Promise<void>;
25
39
  }
26
- export {};
27
- //# sourceMappingURL=index.d.ts.map
40
+
41
+ export { CloudflareDeployer };
package/dist/index.js CHANGED
@@ -1,8 +1,100 @@
1
+ import { MastraDeployer } from '@mastra/core/deployer';
2
+ import { createChildProcessLogger } from '@mastra/deployer';
3
+ import { Cloudflare } from 'cloudflare';
4
+ import { writeFileSync } from 'fs';
5
+ import { join } from 'path';
1
6
 
2
- 'use strict'
7
+ // src/index.ts
8
+ var CloudflareDeployer = class extends MastraDeployer {
9
+ cloudflare;
10
+ routes = [];
11
+ workerNamespace;
12
+ constructor({
13
+ scope,
14
+ env,
15
+ projectName,
16
+ routes,
17
+ workerNamespace,
18
+ auth
19
+ }) {
20
+ super({ scope, env, projectName });
21
+ this.routes = routes;
22
+ this.workerNamespace = workerNamespace;
23
+ if (auth) {
24
+ this.cloudflare = new Cloudflare(auth);
25
+ }
26
+ }
27
+ writeFiles({ dir }) {
28
+ this.loadEnvVars();
29
+ this.writeIndex({ dir });
30
+ const cfWorkerName = this.projectName || "mastra";
31
+ const wranglerConfig = {
32
+ name: cfWorkerName,
33
+ main: "index.mjs",
34
+ compatibility_date: "2024-12-02",
35
+ compatibility_flags: ["nodejs_compat"],
36
+ build: {
37
+ command: "npm install"
38
+ },
39
+ observability: {
40
+ logs: {
41
+ enabled: true
42
+ }
43
+ },
44
+ vars: this.env
45
+ };
46
+ if (!this.workerNamespace && this.routes) {
47
+ wranglerConfig.routes = this.routes;
48
+ }
49
+ writeFileSync(join(dir, "wrangler.json"), JSON.stringify(wranglerConfig));
50
+ }
51
+ writeIndex({ dir }) {
52
+ writeFileSync(
53
+ join(dir, "./index.mjs"),
54
+ `
55
+ export default {
56
+ fetch: async (request, env, context) => {
57
+ Object.keys(env).forEach(key => {
58
+ process.env[key] = env[key]
59
+ })
60
+ const { app } = await import('./hono.mjs');
61
+ return app.fetch(request, env, context);
62
+ }
63
+ }
64
+ `
65
+ );
66
+ }
67
+ async deploy({ dir, token }) {
68
+ const cmd = this.workerNamespace ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler deploy";
69
+ const cpLogger = createChildProcessLogger({
70
+ logger: this.logger,
71
+ root: dir
72
+ });
73
+ await cpLogger({
74
+ cmd,
75
+ args: [],
76
+ env: {
77
+ CLOUDFLARE_API_TOKEN: token,
78
+ CLOUDFLARE_ACCOUNT_ID: this.scope,
79
+ ...this.env,
80
+ PATH: process.env.PATH
81
+ }
82
+ });
83
+ }
84
+ async tagWorker({
85
+ workerName,
86
+ namespace,
87
+ tags,
88
+ scope
89
+ }) {
90
+ if (!this.cloudflare) {
91
+ throw new Error("Cloudflare Deployer not initialized");
92
+ }
93
+ await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
94
+ account_id: scope,
95
+ body: tags
96
+ });
97
+ }
98
+ };
3
99
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./deployer-cloudflare.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./deployer-cloudflare.cjs.development.js')
8
- }
100
+ export { CloudflareDeployer };
@@ -1,4 +1,4 @@
1
- export declare class CloudflareSecretsManager {
1
+ declare class CloudflareSecretsManager {
2
2
  accountId: string;
3
3
  apiToken: string;
4
4
  baseUrl: string;
@@ -22,4 +22,5 @@ export declare class CloudflareSecretsManager {
22
22
  }): Promise<any>;
23
23
  listSecrets(workerId: string): Promise<any>;
24
24
  }
25
- //# sourceMappingURL=index.d.ts.map
25
+
26
+ export { CloudflareSecretsManager };
@@ -0,0 +1,87 @@
1
+ // src/secrets-manager/index.ts
2
+ var CloudflareSecretsManager = class {
3
+ accountId;
4
+ apiToken;
5
+ baseUrl;
6
+ constructor({ accountId, apiToken }) {
7
+ this.accountId = accountId;
8
+ this.apiToken = apiToken;
9
+ this.baseUrl = "https://api.cloudflare.com/client/v4";
10
+ }
11
+ async createSecret({
12
+ workerId,
13
+ secretName,
14
+ secretValue
15
+ }) {
16
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
17
+ try {
18
+ const response = await fetch(url, {
19
+ method: "PUT",
20
+ headers: {
21
+ Authorization: `Bearer ${this.apiToken}`,
22
+ "Content-Type": "application/json"
23
+ },
24
+ body: JSON.stringify({
25
+ name: secretName,
26
+ text: secretValue
27
+ })
28
+ });
29
+ const data = await response.json();
30
+ if (!data.success) {
31
+ throw new Error(data.errors[0].message);
32
+ }
33
+ return data.result;
34
+ } catch (error) {
35
+ console.error("Failed to create secret:", error);
36
+ throw error;
37
+ }
38
+ }
39
+ async createProjectSecrets({
40
+ workerId,
41
+ customerId,
42
+ envVars
43
+ }) {
44
+ const secretName = `PROJECT_${customerId.toUpperCase()}`;
45
+ const secretValue = JSON.stringify(envVars);
46
+ return this.createSecret({ workerId, secretName, secretValue });
47
+ }
48
+ async deleteSecret({ workerId, secretName }) {
49
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;
50
+ try {
51
+ const response = await fetch(url, {
52
+ method: "DELETE",
53
+ headers: {
54
+ Authorization: `Bearer ${this.apiToken}`
55
+ }
56
+ });
57
+ const data = await response.json();
58
+ if (!data.success) {
59
+ throw new Error(data.errors[0].message);
60
+ }
61
+ return data.result;
62
+ } catch (error) {
63
+ console.error("Failed to delete secret:", error);
64
+ throw error;
65
+ }
66
+ }
67
+ async listSecrets(workerId) {
68
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
69
+ try {
70
+ const response = await fetch(url, {
71
+ headers: {
72
+ Authorization: `Bearer ${this.apiToken}`
73
+ }
74
+ });
75
+ const data = await response.json();
76
+ if (!data.success) {
77
+ throw new Error(data.errors[0].message);
78
+ }
79
+ return data.result;
80
+ } catch (error) {
81
+ console.error("Failed to list secrets:", error);
82
+ throw error;
83
+ }
84
+ }
85
+ };
86
+
87
+ export { CloudflareSecretsManager };
package/package.json CHANGED
@@ -1,21 +1,18 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.31",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
- "module": "dist/deployer-cloudflare.esm.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/deployer-cloudflare.esm.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
18
- }
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./secrets-manager": {
14
+ "types": "./dist/secrets-manager/index.d.ts",
15
+ "default": "./dist/secrets-manager/index.js"
19
16
  },
20
17
  "./package.json": "./package.json"
21
18
  },
@@ -23,27 +20,26 @@
23
20
  "author": "",
24
21
  "license": "ISC",
25
22
  "dependencies": {
23
+ "cloudflare": "^4.0.0",
26
24
  "date-fns": "^4.1.0",
27
25
  "dotenv": "^16.3.1",
28
26
  "execa": "^9.3.1",
29
27
  "wrangler": "^3.103.2",
30
28
  "zod": "^3.24.1",
31
- "@mastra/core": "0.1.27-alpha.67",
32
- "@mastra/deployer": "0.0.1-alpha.3"
29
+ "@mastra/core": "0.2.0-alpha.83",
30
+ "@mastra/deployer": "0.0.1-alpha.28"
33
31
  },
34
32
  "devDependencies": {
35
33
  "@babel/preset-env": "^7.26.0",
36
34
  "@babel/preset-typescript": "^7.26.0",
37
35
  "@tsconfig/recommended": "^1.0.7",
38
- "@types/jsdom": "^21.1.7",
39
36
  "@types/node": "^22.9.0",
40
- "@types/pg": "^8.11.10",
41
- "dts-cli": "^2.0.5",
42
- "vitest": "^2.1.8"
37
+ "tsup": "^8.0.1",
38
+ "vitest": "^3.0.4"
43
39
  },
44
40
  "scripts": {
45
- "build": "dts build",
46
- "build:dev": "dts watch",
41
+ "build": "tsup-node src/index.ts src/secrets-manager/index.ts --format esm --dts --clean --treeshake",
42
+ "dev": "tsup-node src/index.ts src/secrets-manager/index.ts --format esm --dts --clean --treeshake --watch",
47
43
  "test": "vitest run"
48
44
  }
49
45
  }