@mastra/deployer-cloudflare 0.0.0-storage-20250225005900 → 0.0.0-vnextWorkflows-20250416071310

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.
@@ -1,4 +1,6 @@
1
- Elastic License 2.0 (ELv2)
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
2
4
 
3
5
  **Acceptance**
4
6
  By using the software, you agree to all of the terms and conditions below.
@@ -0,0 +1,68 @@
1
+ import type { analyzeBundle } from '@mastra/deployer/analyze';
2
+ import { Deployer } from '@mastra/deployer';
3
+ import { InputOptions } from 'rollup';
4
+
5
+ declare interface CFRoute {
6
+ pattern: string;
7
+ zone_name: string;
8
+ custom_domain?: boolean;
9
+ }
10
+
11
+ export declare class CloudflareDeployer extends Deployer {
12
+ private cloudflare;
13
+ routes?: CFRoute[];
14
+ workerNamespace?: string;
15
+ scope: string;
16
+ env?: Record<string, any>;
17
+ projectName?: string;
18
+ constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
19
+ env?: Record<string, any>;
20
+ scope: string;
21
+ projectName?: string;
22
+ routes?: CFRoute[];
23
+ workerNamespace?: string;
24
+ auth: {
25
+ apiToken: string;
26
+ apiEmail?: string;
27
+ };
28
+ });
29
+ writeFiles(outputDirectory: string): Promise<void>;
30
+ private getEntry;
31
+ prepare(outputDirectory: string): Promise<void>;
32
+ getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
33
+ bundle(entryFile: string, outputDirectory: string): Promise<void>;
34
+ deploy(outputDirectory: string): Promise<void>;
35
+ tagWorker({ workerName, namespace, tags, scope, }: {
36
+ scope: string;
37
+ workerName: string;
38
+ namespace: string;
39
+ tags: string[];
40
+ }): Promise<void>;
41
+ }
42
+
43
+ export declare class CloudflareSecretsManager {
44
+ accountId: string;
45
+ apiToken: string;
46
+ baseUrl: string;
47
+ constructor({ accountId, apiToken }: {
48
+ accountId: string;
49
+ apiToken: string;
50
+ });
51
+ createSecret({ workerId, secretName, secretValue, }: {
52
+ workerId: string;
53
+ secretName: string;
54
+ secretValue: string;
55
+ }): Promise<any>;
56
+ createProjectSecrets({ workerId, customerId, envVars, }: {
57
+ workerId: string;
58
+ customerId: string;
59
+ envVars: Record<string, string>;
60
+ }): Promise<any>;
61
+ deleteSecret({ workerId, secretName }: {
62
+ workerId: string;
63
+ secretName: string;
64
+ }): Promise<any>;
65
+ listSecrets(workerId: string): Promise<any>;
66
+ }
67
+
68
+ export { }
@@ -1,4 +1,6 @@
1
+ import type { analyzeBundle } from '@mastra/deployer/analyze';
1
2
  import { Deployer } from '@mastra/deployer';
3
+ import { InputOptions } from 'rollup';
2
4
 
3
5
  declare interface CFRoute {
4
6
  pattern: string;
@@ -27,6 +29,7 @@ export declare class CloudflareDeployer extends Deployer {
27
29
  writeFiles(outputDirectory: string): Promise<void>;
28
30
  private getEntry;
29
31
  prepare(outputDirectory: string): Promise<void>;
32
+ getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
30
33
  bundle(entryFile: string, outputDirectory: string): Promise<void>;
31
34
  deploy(outputDirectory: string): Promise<void>;
32
35
  tagWorker({ workerName, namespace, tags, scope, }: {
package/dist/index.cjs ADDED
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ var promises = require('fs/promises');
4
+ var path = require('path');
5
+ var deployer = require('@mastra/deployer');
6
+ var virtual = require('@rollup/plugin-virtual');
7
+ var cloudflare = require('cloudflare');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var virtual__default = /*#__PURE__*/_interopDefault(virtual);
12
+
13
+ // src/index.ts
14
+ var CloudflareDeployer = class extends deployer.Deployer {
15
+ cloudflare;
16
+ routes = [];
17
+ workerNamespace;
18
+ scope;
19
+ env;
20
+ projectName;
21
+ constructor({
22
+ scope,
23
+ env,
24
+ projectName = "mastra",
25
+ routes,
26
+ workerNamespace,
27
+ auth
28
+ }) {
29
+ super({ name: "CLOUDFLARE" });
30
+ this.scope = scope;
31
+ this.projectName = projectName;
32
+ this.routes = routes;
33
+ this.workerNamespace = workerNamespace;
34
+ if (env) {
35
+ this.env = env;
36
+ }
37
+ this.cloudflare = new cloudflare.Cloudflare(auth);
38
+ }
39
+ async writeFiles(outputDirectory) {
40
+ const env = await this.loadEnvVars();
41
+ const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
42
+ const cfWorkerName = this.projectName;
43
+ const wranglerConfig = {
44
+ name: cfWorkerName,
45
+ main: "./index.mjs",
46
+ compatibility_date: "2025-04-01",
47
+ compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
48
+ observability: {
49
+ logs: {
50
+ enabled: true
51
+ }
52
+ },
53
+ vars: envsAsObject
54
+ };
55
+ if (!this.workerNamespace && this.routes) {
56
+ wranglerConfig.routes = this.routes;
57
+ }
58
+ await promises.writeFile(path.join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
59
+ }
60
+ getEntry() {
61
+ return `
62
+ import '#polyfills';
63
+ import { mastra } from '#mastra';
64
+ import { createHonoServer } from '#server';
65
+
66
+ export default {
67
+ fetch: async (request, env, context) => {
68
+ const app = await createHonoServer(mastra)
69
+ return app.fetch(request, env, context);
70
+ }
71
+ }
72
+ `;
73
+ }
74
+ async prepare(outputDirectory) {
75
+ await super.prepare(outputDirectory);
76
+ await this.writeFiles(outputDirectory);
77
+ }
78
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
79
+ const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
80
+ if (Array.isArray(inputOptions.plugins)) {
81
+ inputOptions.plugins = [
82
+ virtual__default.default({
83
+ "#polyfills": `
84
+ process.versions = process.versions || {};
85
+ process.versions.node = '${process.versions.node}';
86
+ `
87
+ }),
88
+ ...inputOptions.plugins
89
+ ];
90
+ }
91
+ return inputOptions;
92
+ }
93
+ async bundle(entryFile, outputDirectory) {
94
+ return this._bundle(this.getEntry(), entryFile, outputDirectory);
95
+ }
96
+ async deploy(outputDirectory) {
97
+ const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
98
+ const cpLogger = deployer.createChildProcessLogger({
99
+ logger: this.logger,
100
+ root: path.join(outputDirectory, this.outputDir)
101
+ });
102
+ await cpLogger({
103
+ cmd,
104
+ args: [],
105
+ env: {
106
+ CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
107
+ CLOUDFLARE_ACCOUNT_ID: this.scope,
108
+ ...this.env,
109
+ PATH: process.env.PATH
110
+ }
111
+ });
112
+ }
113
+ async tagWorker({
114
+ workerName,
115
+ namespace,
116
+ tags,
117
+ scope
118
+ }) {
119
+ if (!this.cloudflare) {
120
+ throw new Error("Cloudflare Deployer not initialized");
121
+ }
122
+ await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
123
+ account_id: scope,
124
+ body: tags
125
+ });
126
+ }
127
+ };
128
+
129
+ exports.CloudflareDeployer = CloudflareDeployer;
@@ -0,0 +1 @@
1
+ export { CloudflareDeployer } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
+ import { writeFile } from 'fs/promises';
2
+ import { join } from 'path';
1
3
  import { Deployer, createChildProcessLogger } from '@mastra/deployer';
2
- import '@mastra/deployer/build';
3
- import '@rollup/plugin-virtual';
4
+ import virtual from '@rollup/plugin-virtual';
4
5
  import { Cloudflare } from 'cloudflare';
5
- import { writeFileSync } from 'fs';
6
- import { join } from 'path';
7
6
 
8
7
  // src/index.ts
9
8
  var CloudflareDeployer = class extends Deployer {
@@ -37,9 +36,9 @@ var CloudflareDeployer = class extends Deployer {
37
36
  const cfWorkerName = this.projectName;
38
37
  const wranglerConfig = {
39
38
  name: cfWorkerName,
40
- main: "index.mjs",
41
- compatibility_date: "2024-12-02",
42
- compatibility_flags: ["nodejs_compat"],
39
+ main: "./index.mjs",
40
+ compatibility_date: "2025-04-01",
41
+ compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
43
42
  observability: {
44
43
  logs: {
45
44
  enabled: true
@@ -50,18 +49,16 @@ var CloudflareDeployer = class extends Deployer {
50
49
  if (!this.workerNamespace && this.routes) {
51
50
  wranglerConfig.routes = this.routes;
52
51
  }
53
- writeFileSync(join(outputDirectory, "wrangler.json"), JSON.stringify(wranglerConfig));
52
+ await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
54
53
  }
55
54
  getEntry() {
56
55
  return `
56
+ import '#polyfills';
57
+ import { mastra } from '#mastra';
58
+ import { createHonoServer } from '#server';
59
+
57
60
  export default {
58
61
  fetch: async (request, env, context) => {
59
- Object.keys(env).forEach(key => {
60
- process.env[key] = env[key]
61
- })
62
-
63
- const { mastra } = await import('#mastra')
64
- const { createHonoServer } = await import('#server')
65
62
  const app = await createHonoServer(mastra)
66
63
  return app.fetch(request, env, context);
67
64
  }
@@ -72,14 +69,29 @@ export default {
72
69
  await super.prepare(outputDirectory);
73
70
  await this.writeFiles(outputDirectory);
74
71
  }
72
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
73
+ const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
74
+ if (Array.isArray(inputOptions.plugins)) {
75
+ inputOptions.plugins = [
76
+ virtual({
77
+ "#polyfills": `
78
+ process.versions = process.versions || {};
79
+ process.versions.node = '${process.versions.node}';
80
+ `
81
+ }),
82
+ ...inputOptions.plugins
83
+ ];
84
+ }
85
+ return inputOptions;
86
+ }
75
87
  async bundle(entryFile, outputDirectory) {
76
88
  return this._bundle(this.getEntry(), entryFile, outputDirectory);
77
89
  }
78
90
  async deploy(outputDirectory) {
79
- const cmd = this.workerNamespace ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler deploy";
91
+ const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
80
92
  const cpLogger = createChildProcessLogger({
81
93
  logger: this.logger,
82
- root: outputDirectory
94
+ root: join(outputDirectory, this.outputDir)
83
95
  });
84
96
  await cpLogger({
85
97
  cmd,
@@ -1,110 +1,89 @@
1
- export class CloudflareSecretsManager {
2
- accountId: string;
3
- apiToken: string;
4
- baseUrl: string;
5
-
6
- constructor({ accountId, apiToken }: { accountId: string; apiToken: string }) {
1
+ 'use strict';
2
+
3
+ // src/secrets-manager/index.ts
4
+ var CloudflareSecretsManager = class {
5
+ accountId;
6
+ apiToken;
7
+ baseUrl;
8
+ constructor({ accountId, apiToken }) {
7
9
  this.accountId = accountId;
8
10
  this.apiToken = apiToken;
9
- this.baseUrl = 'https://api.cloudflare.com/client/v4';
11
+ this.baseUrl = "https://api.cloudflare.com/client/v4";
10
12
  }
11
-
12
13
  async createSecret({
13
14
  workerId,
14
15
  secretName,
15
- secretValue,
16
- }: {
17
- workerId: string;
18
- secretName: string;
19
- secretValue: string;
16
+ secretValue
20
17
  }) {
21
18
  const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
22
-
23
19
  try {
24
20
  const response = await fetch(url, {
25
- method: 'PUT',
21
+ method: "PUT",
26
22
  headers: {
27
23
  Authorization: `Bearer ${this.apiToken}`,
28
- 'Content-Type': 'application/json',
24
+ "Content-Type": "application/json"
29
25
  },
30
26
  body: JSON.stringify({
31
27
  name: secretName,
32
- text: secretValue,
33
- }),
28
+ text: secretValue
29
+ })
34
30
  });
35
-
36
- const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
37
-
31
+ const data = await response.json();
38
32
  if (!data.success) {
39
33
  throw new Error(data.errors[0].message);
40
34
  }
41
-
42
35
  return data.result;
43
36
  } catch (error) {
44
- console.error('Failed to create secret:', error);
37
+ console.error("Failed to create secret:", error);
45
38
  throw error;
46
39
  }
47
40
  }
48
-
49
41
  async createProjectSecrets({
50
42
  workerId,
51
43
  customerId,
52
- envVars,
53
- }: {
54
- workerId: string;
55
- customerId: string;
56
- envVars: Record<string, string>;
44
+ envVars
57
45
  }) {
58
46
  const secretName = `PROJECT_${customerId.toUpperCase()}`;
59
47
  const secretValue = JSON.stringify(envVars);
60
-
61
48
  return this.createSecret({ workerId, secretName, secretValue });
62
49
  }
63
-
64
- async deleteSecret({ workerId, secretName }: { workerId: string; secretName: string }) {
50
+ async deleteSecret({ workerId, secretName }) {
65
51
  const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;
66
-
67
52
  try {
68
53
  const response = await fetch(url, {
69
- method: 'DELETE',
54
+ method: "DELETE",
70
55
  headers: {
71
- Authorization: `Bearer ${this.apiToken}`,
72
- },
56
+ Authorization: `Bearer ${this.apiToken}`
57
+ }
73
58
  });
74
-
75
- const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
76
-
59
+ const data = await response.json();
77
60
  if (!data.success) {
78
61
  throw new Error(data.errors[0].message);
79
62
  }
80
-
81
63
  return data.result;
82
64
  } catch (error) {
83
- console.error('Failed to delete secret:', error);
65
+ console.error("Failed to delete secret:", error);
84
66
  throw error;
85
67
  }
86
68
  }
87
-
88
- async listSecrets(workerId: string) {
69
+ async listSecrets(workerId) {
89
70
  const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
90
-
91
71
  try {
92
72
  const response = await fetch(url, {
93
73
  headers: {
94
- Authorization: `Bearer ${this.apiToken}`,
95
- },
74
+ Authorization: `Bearer ${this.apiToken}`
75
+ }
96
76
  });
97
-
98
- const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
99
-
77
+ const data = await response.json();
100
78
  if (!data.success) {
101
79
  throw new Error(data.errors[0].message);
102
80
  }
103
-
104
81
  return data.result;
105
82
  } catch (error) {
106
- console.error('Failed to list secrets:', error);
83
+ console.error("Failed to list secrets:", error);
107
84
  throw error;
108
85
  }
109
86
  }
110
- }
87
+ };
88
+
89
+ exports.CloudflareSecretsManager = CloudflareSecretsManager;
@@ -0,0 +1 @@
1
+ export { CloudflareSecretsManager } from '../_tsup-dts-rollup.cjs';
package/package.json CHANGED
@@ -1,46 +1,64 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.0-storage-20250225005900",
3
+ "version": "0.0.0-vnextWorkflows-20250416071310",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "main": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "exports": {
9
12
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
12
21
  },
13
22
  "./secrets-manager": {
14
- "types": "./dist/secrets-manager/index.d.ts",
15
- "default": "./dist/secrets-manager/index.js"
23
+ "import": {
24
+ "types": "./dist/secrets-manager/index.d.ts",
25
+ "default": "./dist/secrets-manager/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/secrets-manager/index.d.cts",
29
+ "default": "./dist/secrets-manager/index.cjs"
30
+ }
16
31
  },
17
32
  "./package.json": "./package.json"
18
33
  },
19
34
  "keywords": [],
20
35
  "author": "",
21
- "license": "ISC",
36
+ "license": "Elastic-2.0",
22
37
  "dependencies": {
23
38
  "@rollup/plugin-virtual": "^3.0.2",
24
- "cloudflare": "^4.0.0",
39
+ "cloudflare": "^4.1.0",
25
40
  "date-fns": "^4.1.0",
26
- "execa": "^9.3.1",
41
+ "execa": "^9.5.2",
27
42
  "rollup-plugin-polyfill-node": "^0.13.0",
28
43
  "rollup-plugin-shim": "^1.0.0",
29
- "wrangler": "^3.103.2",
30
- "zod": "^3.24.1",
31
- "@mastra/core": "^0.0.0-storage-20250225005900",
32
- "@mastra/deployer": "^0.0.0-storage-20250225005900"
44
+ "wrangler": "^4.4.0",
45
+ "zod": "^3.24.2",
46
+ "@mastra/core": "0.0.0-vnextWorkflows-20250416071310",
47
+ "@mastra/deployer": "0.0.0-vnextWorkflows-20250416071310"
33
48
  },
34
49
  "devDependencies": {
35
- "@microsoft/api-extractor": "^7.49.2",
36
- "@types/node": "^22.13.1",
37
- "tsup": "^8.0.1",
38
- "typescript": "^5.7.3",
39
- "vitest": "^3.0.4"
50
+ "@microsoft/api-extractor": "^7.52.1",
51
+ "@types/node": "^20.17.27",
52
+ "eslint": "^9.23.0",
53
+ "tsup": "^8.4.0",
54
+ "typescript": "^5.8.2",
55
+ "vitest": "^3.0.9",
56
+ "@internal/lint": "0.0.2"
40
57
  },
41
58
  "scripts": {
42
- "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake",
59
+ "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
43
60
  "build:watch": "pnpm build --watch",
44
- "test": "vitest run"
61
+ "test": "vitest run",
62
+ "lint": "eslint ."
45
63
  }
46
64
  }
@@ -1,20 +0,0 @@
1
-
2
- 
3
- > @mastra/deployer-cloudflare@0.1.5-alpha.1 build /Users/ward/projects/mastra/mastra/deployers/cloudflare
4
- > tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake
5
-
6
- CLI Building entry: src/index.ts, src/secrets-manager/index.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.3.6
9
- TSC Build start
10
- TSC ⚡️ Build success in 2330ms
11
- DTS Build start
12
- CLI Target: es2022
13
- Analysis will use the bundled TypeScript version 5.7.3
14
- Writing package typings: /Users/ward/projects/mastra/mastra/deployers/cloudflare/dist/_tsup-dts-rollup.d.ts
15
- DTS ⚡️ Build success in 831ms
16
- CLI Cleaning output folder
17
- ESM Build start
18
- ESM dist/index.js 2.89 KB
19
- ESM dist/secrets-manager/index.js 2.38 KB
20
- ESM ⚡️ Build success in 57ms