@mastra/deployer-cloudflare 0.0.1-alpha.24 → 0.0.1-alpha.28

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,34 @@
1
1
  # @mastra/deployer-cloudflare
2
2
 
3
+ ## 0.0.1-alpha.28
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [327ece7]
8
+ - @mastra/core@0.1.27-alpha.80
9
+ - @mastra/deployer@0.0.1-alpha.25
10
+
11
+ ## 0.0.1-alpha.27
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [21fe536]
16
+ - @mastra/core@0.1.27-alpha.79
17
+ - @mastra/deployer@0.0.1-alpha.24
18
+
19
+ ## 0.0.1-alpha.26
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [88f18d7]
24
+ - @mastra/deployer@0.0.1-alpha.23
25
+
26
+ ## 0.0.1-alpha.25
27
+
28
+ ### Patch Changes
29
+
30
+ - 44c7c26: Rebuild
31
+
3
32
  ## 0.0.1-alpha.24
4
33
 
5
34
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
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 {
8
9
  private cloudflare;
9
10
  routes?: CFRoute[];
10
11
  workerNamespace?: string;
@@ -36,5 +37,5 @@ export declare class CloudflareDeployer extends MastraDeployer {
36
37
  tags: string[];
37
38
  }): Promise<void>;
38
39
  }
39
- export {};
40
- //# 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.1-alpha.24",
3
+ "version": "0.0.1-alpha.28",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,8 +26,8 @@
26
26
  "execa": "^9.3.1",
27
27
  "wrangler": "^3.103.2",
28
28
  "zod": "^3.24.1",
29
- "@mastra/deployer": "0.0.1-alpha.22",
30
- "@mastra/core": "0.1.27-alpha.78"
29
+ "@mastra/core": "0.1.27-alpha.80",
30
+ "@mastra/deployer": "0.0.1-alpha.25"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/preset-env": "^7.26.0",
@@ -33,7 +33,7 @@ export class CloudflareSecretsManager {
33
33
  }),
34
34
  });
35
35
 
36
- const data = await response.json();
36
+ const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
37
37
 
38
38
  if (!data.success) {
39
39
  throw new Error(data.errors[0].message);
@@ -72,7 +72,7 @@ export class CloudflareSecretsManager {
72
72
  },
73
73
  });
74
74
 
75
- const data = await response.json();
75
+ const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
76
76
 
77
77
  if (!data.success) {
78
78
  throw new Error(data.errors[0].message);
@@ -95,7 +95,7 @@ export class CloudflareSecretsManager {
95
95
  },
96
96
  });
97
97
 
98
- const data = await response.json();
98
+ const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
99
99
 
100
100
  if (!data.success) {
101
101
  throw new Error(data.errors[0].message);