@mastra/deployer-cloudflare 0.1.6-alpha.1 → 0.1.6-alpha.4

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.1 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.4 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 10411ms
9
+ TSC ⚡️ Build success in 9670ms
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 3419ms
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 6929ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
19
+ CJS Build start
17
20
  ESM dist/index.js 2.83 KB
18
21
  ESM dist/secrets-manager/index.js 2.38 KB
19
- ESM ⚡️ Build success in 130ms
22
+ ESM ⚡️ Build success in 224ms
23
+ CJS dist/index.cjs 2.86 KB
24
+ CJS dist/secrets-manager/index.cjs 2.42 KB
25
+ CJS ⚡️ Build success in 227ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @mastra/deployer-cloudflare
2
2
 
3
+ ## 0.1.6-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [dabecf4]
8
+ - @mastra/core@0.4.3-alpha.4
9
+ - @mastra/deployer@0.1.6-alpha.4
10
+
11
+ ## 0.1.6-alpha.3
12
+
13
+ ### Patch Changes
14
+
15
+ - bb4f447: Add support for commonjs
16
+ - Updated dependencies [0fd78ac]
17
+ - Updated dependencies [0d25b75]
18
+ - Updated dependencies [fd14a3f]
19
+ - Updated dependencies [3f369a2]
20
+ - Updated dependencies [4d4e1e1]
21
+ - Updated dependencies [bb4f447]
22
+ - @mastra/deployer@0.1.6-alpha.3
23
+ - @mastra/core@0.4.3-alpha.3
24
+
25
+ ## 0.1.6-alpha.2
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [2512a93]
30
+ - Updated dependencies [e62de74]
31
+ - @mastra/core@0.4.3-alpha.2
32
+ - @mastra/deployer@0.1.6-alpha.2
33
+
3
34
  ## 0.1.6-alpha.1
4
35
 
5
36
  ### 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';
@@ -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';
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.1.6-alpha.1",
3
+ "version": "0.1.6-alpha.4",
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,8 +40,8 @@
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.1",
32
- "@mastra/deployer": "^0.1.6-alpha.1"
43
+ "@mastra/core": "^0.4.3-alpha.4",
44
+ "@mastra/deployer": "^0.1.6-alpha.4"
33
45
  },
34
46
  "devDependencies": {
35
47
  "eslint": "^9.20.1",
@@ -41,7 +53,7 @@
41
53
  "@internal/lint": "0.0.0"
42
54
  },
43
55
  "scripts": {
44
- "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",
45
57
  "build:watch": "pnpm build --watch",
46
58
  "test": "vitest run",
47
59
  "lint": "eslint ."