@mastra/deployer-cloudflare 0.1.6-alpha.0 → 0.1.6-alpha.3

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,19 +1,25 @@
1
1
 
2
- > @mastra/deployer-cloudflare@0.1.6-alpha.0 build /home/runner/work/mastra/mastra/deployers/cloudflare
3
- > tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake
2
+ > @mastra/deployer-cloudflare@0.1.6-alpha.3 build /home/runner/work/mastra/mastra/deployers/cloudflare
3
+ > tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts, src/secrets-manager/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 11256ms
9
+ TSC ⚡️ Build success in 9638ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/deployers/cloudflare/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 4325ms
14
+ Analysis will use the bundled TypeScript version 5.7.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/deployers/cloudflare/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 6296ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
17
- ESM dist/index.js 2.89 KB
19
+ CJS Build start
20
+ CJS dist/index.cjs 2.86 KB
21
+ CJS dist/secrets-manager/index.cjs 2.42 KB
22
+ CJS ⚡️ Build success in 214ms
23
+ ESM dist/index.js 2.83 KB
18
24
  ESM dist/secrets-manager/index.js 2.38 KB
19
- ESM ⚡️ Build success in 269ms
25
+ ESM ⚡️ Build success in 215ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @mastra/deployer-cloudflare
2
2
 
3
+ ## 0.1.6-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb4f447: Add support for commonjs
8
+ - Updated dependencies [0fd78ac]
9
+ - Updated dependencies [0d25b75]
10
+ - Updated dependencies [fd14a3f]
11
+ - Updated dependencies [3f369a2]
12
+ - Updated dependencies [4d4e1e1]
13
+ - Updated dependencies [bb4f447]
14
+ - @mastra/deployer@0.1.6-alpha.3
15
+ - @mastra/core@0.4.3-alpha.3
16
+
17
+ ## 0.1.6-alpha.2
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [2512a93]
22
+ - Updated dependencies [e62de74]
23
+ - @mastra/core@0.4.3-alpha.2
24
+ - @mastra/deployer@0.1.6-alpha.2
25
+
26
+ ## 0.1.6-alpha.1
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [0d185b1]
31
+ - Updated dependencies [ed55f1d]
32
+ - Updated dependencies [80cdd76]
33
+ - Updated dependencies [8d13b14]
34
+ - Updated dependencies [3ee4831]
35
+ - Updated dependencies [108793c]
36
+ - Updated dependencies [5f28f44]
37
+ - @mastra/core@0.4.3-alpha.1
38
+ - @mastra/deployer@0.1.6-alpha.1
39
+
3
40
  ## 0.1.6-alpha.0
4
41
 
5
42
  ### Patch Changes
@@ -0,0 +1,65 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ declare interface CFRoute {
4
+ pattern: string;
5
+ zone_name: string;
6
+ custom_domain?: boolean;
7
+ }
8
+
9
+ export declare class CloudflareDeployer extends Deployer {
10
+ private cloudflare;
11
+ routes?: CFRoute[];
12
+ workerNamespace?: string;
13
+ scope: string;
14
+ env?: Record<string, any>;
15
+ projectName?: string;
16
+ constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
17
+ env?: Record<string, any>;
18
+ scope: string;
19
+ projectName?: string;
20
+ routes?: CFRoute[];
21
+ workerNamespace?: string;
22
+ auth: {
23
+ apiToken: string;
24
+ apiEmail?: string;
25
+ };
26
+ });
27
+ writeFiles(outputDirectory: string): Promise<void>;
28
+ private getEntry;
29
+ prepare(outputDirectory: string): Promise<void>;
30
+ bundle(entryFile: string, outputDirectory: string): Promise<void>;
31
+ deploy(outputDirectory: string): Promise<void>;
32
+ tagWorker({ workerName, namespace, tags, scope, }: {
33
+ scope: string;
34
+ workerName: string;
35
+ namespace: string;
36
+ tags: string[];
37
+ }): Promise<void>;
38
+ }
39
+
40
+ export declare class CloudflareSecretsManager {
41
+ accountId: string;
42
+ apiToken: string;
43
+ baseUrl: string;
44
+ constructor({ accountId, apiToken }: {
45
+ accountId: string;
46
+ apiToken: string;
47
+ });
48
+ createSecret({ workerId, secretName, secretValue, }: {
49
+ workerId: string;
50
+ secretName: string;
51
+ secretValue: string;
52
+ }): Promise<any>;
53
+ createProjectSecrets({ workerId, customerId, envVars, }: {
54
+ workerId: string;
55
+ customerId: string;
56
+ envVars: Record<string, string>;
57
+ }): Promise<any>;
58
+ deleteSecret({ workerId, secretName }: {
59
+ workerId: string;
60
+ secretName: string;
61
+ }): Promise<any>;
62
+ listSecrets(workerId: string): Promise<any>;
63
+ }
64
+
65
+ export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var deployer = require('@mastra/deployer');
6
+ var cloudflare = require('cloudflare');
7
+
8
+ // src/index.ts
9
+ var CloudflareDeployer = class extends deployer.Deployer {
10
+ cloudflare;
11
+ routes = [];
12
+ workerNamespace;
13
+ scope;
14
+ env;
15
+ projectName;
16
+ constructor({
17
+ scope,
18
+ env,
19
+ projectName = "mastra",
20
+ routes,
21
+ workerNamespace,
22
+ auth
23
+ }) {
24
+ super({ name: "CLOUDFLARE" });
25
+ this.scope = scope;
26
+ this.projectName = projectName;
27
+ this.routes = routes;
28
+ this.workerNamespace = workerNamespace;
29
+ if (env) {
30
+ this.env = env;
31
+ }
32
+ this.cloudflare = new cloudflare.Cloudflare(auth);
33
+ }
34
+ async writeFiles(outputDirectory) {
35
+ const env = await this.loadEnvVars();
36
+ const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
37
+ const cfWorkerName = this.projectName;
38
+ const wranglerConfig = {
39
+ name: cfWorkerName,
40
+ main: "index.mjs",
41
+ compatibility_date: "2024-12-02",
42
+ compatibility_flags: ["nodejs_compat"],
43
+ observability: {
44
+ logs: {
45
+ enabled: true
46
+ }
47
+ },
48
+ vars: envsAsObject
49
+ };
50
+ if (!this.workerNamespace && this.routes) {
51
+ wranglerConfig.routes = this.routes;
52
+ }
53
+ fs.writeFileSync(path.join(outputDirectory, "wrangler.json"), JSON.stringify(wranglerConfig));
54
+ }
55
+ getEntry() {
56
+ return `
57
+ export default {
58
+ 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
+ const app = await createHonoServer(mastra)
66
+ return app.fetch(request, env, context);
67
+ }
68
+ }
69
+ `;
70
+ }
71
+ async prepare(outputDirectory) {
72
+ await super.prepare(outputDirectory);
73
+ await this.writeFiles(outputDirectory);
74
+ }
75
+ async bundle(entryFile, outputDirectory) {
76
+ return this._bundle(this.getEntry(), entryFile, outputDirectory);
77
+ }
78
+ async deploy(outputDirectory) {
79
+ const cmd = this.workerNamespace ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler deploy";
80
+ const cpLogger = deployer.createChildProcessLogger({
81
+ logger: this.logger,
82
+ root: outputDirectory
83
+ });
84
+ await cpLogger({
85
+ cmd,
86
+ args: [],
87
+ env: {
88
+ CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
89
+ CLOUDFLARE_ACCOUNT_ID: this.scope,
90
+ ...this.env,
91
+ PATH: process.env.PATH
92
+ }
93
+ });
94
+ }
95
+ async tagWorker({
96
+ workerName,
97
+ namespace,
98
+ tags,
99
+ scope
100
+ }) {
101
+ if (!this.cloudflare) {
102
+ throw new Error("Cloudflare Deployer not initialized");
103
+ }
104
+ await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
105
+ account_id: scope,
106
+ body: tags
107
+ });
108
+ }
109
+ };
110
+
111
+ exports.CloudflareDeployer = CloudflareDeployer;
@@ -0,0 +1 @@
1
+ export { CloudflareDeployer } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
- import { Deployer, createChildProcessLogger } from '@mastra/deployer';
2
- import '@mastra/deployer/build';
3
- import '@rollup/plugin-virtual';
4
- import { Cloudflare } from 'cloudflare';
5
1
  import { writeFileSync } from 'fs';
6
2
  import { join } from 'path';
3
+ import { Deployer, createChildProcessLogger } from '@mastra/deployer';
4
+ import { Cloudflare } from 'cloudflare';
7
5
 
8
6
  // src/index.ts
9
7
  var CloudflareDeployer = class extends Deployer {
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ // src/secrets-manager/index.ts
4
+ var CloudflareSecretsManager = class {
5
+ accountId;
6
+ apiToken;
7
+ baseUrl;
8
+ constructor({ accountId, apiToken }) {
9
+ this.accountId = accountId;
10
+ this.apiToken = apiToken;
11
+ this.baseUrl = "https://api.cloudflare.com/client/v4";
12
+ }
13
+ async createSecret({
14
+ workerId,
15
+ secretName,
16
+ secretValue
17
+ }) {
18
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
19
+ try {
20
+ const response = await fetch(url, {
21
+ method: "PUT",
22
+ headers: {
23
+ Authorization: `Bearer ${this.apiToken}`,
24
+ "Content-Type": "application/json"
25
+ },
26
+ body: JSON.stringify({
27
+ name: secretName,
28
+ text: secretValue
29
+ })
30
+ });
31
+ const data = await response.json();
32
+ if (!data.success) {
33
+ throw new Error(data.errors[0].message);
34
+ }
35
+ return data.result;
36
+ } catch (error) {
37
+ console.error("Failed to create secret:", error);
38
+ throw error;
39
+ }
40
+ }
41
+ async createProjectSecrets({
42
+ workerId,
43
+ customerId,
44
+ envVars
45
+ }) {
46
+ const secretName = `PROJECT_${customerId.toUpperCase()}`;
47
+ const secretValue = JSON.stringify(envVars);
48
+ return this.createSecret({ workerId, secretName, secretValue });
49
+ }
50
+ async deleteSecret({ workerId, secretName }) {
51
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;
52
+ try {
53
+ const response = await fetch(url, {
54
+ method: "DELETE",
55
+ headers: {
56
+ Authorization: `Bearer ${this.apiToken}`
57
+ }
58
+ });
59
+ const data = await response.json();
60
+ if (!data.success) {
61
+ throw new Error(data.errors[0].message);
62
+ }
63
+ return data.result;
64
+ } catch (error) {
65
+ console.error("Failed to delete secret:", error);
66
+ throw error;
67
+ }
68
+ }
69
+ async listSecrets(workerId) {
70
+ const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
71
+ try {
72
+ const response = await fetch(url, {
73
+ headers: {
74
+ Authorization: `Bearer ${this.apiToken}`
75
+ }
76
+ });
77
+ const data = await response.json();
78
+ if (!data.success) {
79
+ throw new Error(data.errors[0].message);
80
+ }
81
+ return data.result;
82
+ } catch (error) {
83
+ console.error("Failed to list secrets:", error);
84
+ throw error;
85
+ }
86
+ }
87
+ };
88
+
89
+ exports.CloudflareSecretsManager = CloudflareSecretsManager;
@@ -0,0 +1 @@
1
+ export { CloudflareSecretsManager } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@internal/lint/eslint';
2
+
3
+ const config = await createConfig();
4
+
5
+ /** @type {import("eslint").Linter.Config[]} */
6
+ export default [...config];
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.1.6-alpha.0",
3
+ "version": "0.1.6-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
12
18
  },
13
19
  "./secrets-manager": {
14
- "types": "./dist/secrets-manager/index.d.ts",
15
- "default": "./dist/secrets-manager/index.js"
20
+ "import": {
21
+ "types": "./dist/secrets-manager/index.d.ts",
22
+ "default": "./dist/secrets-manager/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/secrets-manager/index.d.cts",
26
+ "default": "./dist/secrets-manager/index.cjs"
27
+ }
16
28
  },
17
29
  "./package.json": "./package.json"
18
30
  },
@@ -28,19 +40,22 @@
28
40
  "rollup-plugin-shim": "^1.0.0",
29
41
  "wrangler": "^3.103.2",
30
42
  "zod": "^3.24.1",
31
- "@mastra/core": "^0.4.3-alpha.0",
32
- "@mastra/deployer": "^0.1.6-alpha.0"
43
+ "@mastra/core": "^0.4.3-alpha.3",
44
+ "@mastra/deployer": "^0.1.6-alpha.3"
33
45
  },
34
46
  "devDependencies": {
47
+ "eslint": "^9.20.1",
35
48
  "@microsoft/api-extractor": "^7.49.2",
36
49
  "@types/node": "^22.13.1",
37
50
  "tsup": "^8.0.1",
38
51
  "typescript": "^5.7.3",
39
- "vitest": "^3.0.4"
52
+ "vitest": "^3.0.4",
53
+ "@internal/lint": "0.0.0"
40
54
  },
41
55
  "scripts": {
42
- "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake",
56
+ "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
43
57
  "build:watch": "pnpm build --watch",
44
- "test": "vitest run"
58
+ "test": "vitest run",
59
+ "lint": "eslint ."
45
60
  }
46
61
  }
package/src/index.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { Deployer, createChildProcessLogger } from '@mastra/deployer';
2
- import { getBundler } from '@mastra/deployer/build';
3
- import virtual from '@rollup/plugin-virtual';
4
- import { Cloudflare } from 'cloudflare';
5
1
  import { writeFileSync } from 'fs';
6
2
  import { join } from 'path';
7
3
 
4
+ import { Deployer, createChildProcessLogger } from '@mastra/deployer';
5
+ import { Cloudflare } from 'cloudflare';
6
+
8
7
  interface CFRoute {
9
8
  pattern: string;
10
9
  zone_name: string;