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

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,221 @@
1
1
  # @mastra/deployer-cloudflare
2
2
 
3
+ ## 0.0.1-alpha.30
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [73d112c]
8
+ - Updated dependencies [ac8c61a]
9
+ - @mastra/deployer@0.0.1-alpha.27
10
+ - @mastra/core@0.1.27-alpha.82
11
+
12
+ ## 0.0.1-alpha.29
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [9fb3039]
17
+ - @mastra/core@0.1.27-alpha.81
18
+ - @mastra/deployer@0.0.1-alpha.26
19
+
20
+ ## 0.0.1-alpha.28
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [327ece7]
25
+ - @mastra/core@0.1.27-alpha.80
26
+ - @mastra/deployer@0.0.1-alpha.25
27
+
28
+ ## 0.0.1-alpha.27
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [21fe536]
33
+ - @mastra/core@0.1.27-alpha.79
34
+ - @mastra/deployer@0.0.1-alpha.24
35
+
36
+ ## 0.0.1-alpha.26
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [88f18d7]
41
+ - @mastra/deployer@0.0.1-alpha.23
42
+
43
+ ## 0.0.1-alpha.25
44
+
45
+ ### Patch Changes
46
+
47
+ - 44c7c26: Rebuild
48
+
49
+ ## 0.0.1-alpha.24
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [685108a]
54
+ - Updated dependencies [685108a]
55
+ - @mastra/deployer@0.0.1-alpha.22
56
+ - @mastra/core@0.1.27-alpha.78
57
+
58
+ ## 0.0.1-alpha.23
59
+
60
+ ### Patch Changes
61
+
62
+ - 2b75edf: mastra deployers tsup bundling
63
+ - Updated dependencies [8105fae]
64
+ - Updated dependencies [cfb966f]
65
+ - @mastra/core@0.1.27-alpha.77
66
+ - @mastra/deployer@0.0.1-alpha.21
67
+
68
+ ## 0.0.1-alpha.22
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [ae7bf94]
73
+ - Updated dependencies [ae7bf94]
74
+ - @mastra/deployer@0.0.1-alpha.20
75
+ - @mastra/core@0.1.27-alpha.76
76
+
77
+ ## 0.0.1-alpha.21
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies [23dcb23]
82
+ - Updated dependencies [7064554]
83
+ - @mastra/core@0.1.27-alpha.75
84
+ - @mastra/deployer@0.0.1-alpha.19
85
+
86
+ ## 0.0.1-alpha.20
87
+
88
+ ### Patch Changes
89
+
90
+ - Updated dependencies [7b87567]
91
+ - @mastra/core@0.1.27-alpha.74
92
+ - @mastra/deployer@0.0.1-alpha.18
93
+
94
+ ## 0.0.1-alpha.19
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [3427b95]
99
+ - @mastra/core@0.1.27-alpha.73
100
+ - @mastra/deployer@0.0.1-alpha.17
101
+
102
+ ## 0.0.1-alpha.18
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies [e4d4ede]
107
+ - Updated dependencies [06b2c0a]
108
+ - @mastra/core@0.1.27-alpha.72
109
+ - @mastra/deployer@0.0.1-alpha.16
110
+
111
+ ## 0.0.1-alpha.17
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies [d9c8dd0]
116
+ - @mastra/deployer@0.0.1-alpha.15
117
+ - @mastra/core@0.1.27-alpha.71
118
+
119
+ ## 0.0.1-alpha.16
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [ad2cd74]
124
+ - @mastra/deployer@0.0.1-alpha.14
125
+
126
+ ## 0.0.1-alpha.15
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [a1774e7]
131
+ - @mastra/deployer@0.0.1-alpha.13
132
+
133
+ ## 0.0.1-alpha.14
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies [28dceab]
138
+ - @mastra/deployer@0.0.1-alpha.12
139
+
140
+ ## 0.0.1-alpha.13
141
+
142
+ ### Patch Changes
143
+
144
+ - bdaf834: publish packages
145
+ - Updated dependencies [bdaf834]
146
+ - @mastra/deployer@0.0.1-alpha.11
147
+
148
+ ## 0.0.1-alpha.12
149
+
150
+ ### Patch Changes
151
+
152
+ - Updated dependencies [dd6d87f]
153
+ - Updated dependencies [04434b6]
154
+ - @mastra/core@0.1.27-alpha.70
155
+ - @mastra/deployer@0.0.1-alpha.10
156
+
157
+ ## 0.0.1-alpha.11
158
+
159
+ ### Patch Changes
160
+
161
+ - 9066f95: CF deployer fixes
162
+ - Updated dependencies [9066f95]
163
+ - @mastra/deployer@0.0.1-alpha.9
164
+
165
+ ## 0.0.1-alpha.10
166
+
167
+ ### Patch Changes
168
+
169
+ - 0d5a03d: Vector store modules
170
+
171
+ ## 0.0.1-alpha.9
172
+
173
+ ### Patch Changes
174
+
175
+ - Updated dependencies [b425845]
176
+ - @mastra/deployer@0.0.1-alpha.8
177
+
178
+ ## 0.0.1-alpha.8
179
+
180
+ ### Patch Changes
181
+
182
+ - 1944807: Unified logger and major step in better logs
183
+ - c7abf8e: Optional CF worker tagging
184
+ - Updated dependencies [1944807]
185
+ - Updated dependencies [9ade36e]
186
+ - @mastra/deployer@0.0.1-alpha.7
187
+ - @mastra/core@0.1.27-alpha.69
188
+
189
+ ## 0.0.1-alpha.7
190
+
191
+ ### Patch Changes
192
+
193
+ - Updated dependencies [291fe57]
194
+ - Updated dependencies [1a41fbf]
195
+ - @mastra/deployer@0.0.1-alpha.6
196
+
197
+ ## 0.0.1-alpha.6
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies [0be7181]
202
+ - Updated dependencies [0be7181]
203
+ - @mastra/core@0.1.27-alpha.68
204
+ - @mastra/deployer@0.0.1-alpha.5
205
+
206
+ ## 0.0.1-alpha.5
207
+
208
+ ### Patch Changes
209
+
210
+ - Updated dependencies [7babd5c]
211
+ - @mastra/deployer@0.0.1-alpha.4
212
+
213
+ ## 0.0.1-alpha.4
214
+
215
+ ### Patch Changes
216
+
217
+ - 026ca5d: Optional dispatcher namespace configuration for cloudflare deployments
218
+
3
219
  ## 0.0.1-alpha.3
4
220
 
5
221
  ### 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
1
  import { MastraDeployer } from '@mastra/core';
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';
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.30",
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.1.27-alpha.82",
30
+ "@mastra/deployer": "0.0.1-alpha.27"
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
  }