@mastra/deployer-cloudflare 0.0.1-alpha.28 → 0.0.1-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.
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.1-alpha.28",
3
+ "version": "0.0.1-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
+ "module": "dist/deployer-cloudflare.esm.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
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"
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
+ }
16
19
  },
17
20
  "./package.json": "./package.json"
18
21
  },
@@ -20,26 +23,27 @@
20
23
  "author": "",
21
24
  "license": "ISC",
22
25
  "dependencies": {
23
- "cloudflare": "^4.0.0",
24
26
  "date-fns": "^4.1.0",
25
27
  "dotenv": "^16.3.1",
26
28
  "execa": "^9.3.1",
27
29
  "wrangler": "^3.103.2",
28
30
  "zod": "^3.24.1",
29
- "@mastra/core": "0.1.27-alpha.80",
30
- "@mastra/deployer": "0.0.1-alpha.25"
31
+ "@mastra/core": "0.1.27-alpha.67",
32
+ "@mastra/deployer": "0.0.1-alpha.3"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@babel/preset-env": "^7.26.0",
34
36
  "@babel/preset-typescript": "^7.26.0",
35
37
  "@tsconfig/recommended": "^1.0.7",
38
+ "@types/jsdom": "^21.1.7",
36
39
  "@types/node": "^22.9.0",
37
- "tsup": "^8.0.1",
38
- "vitest": "^3.0.4"
40
+ "@types/pg": "^8.11.10",
41
+ "dts-cli": "^2.0.5",
42
+ "vitest": "^2.1.8"
39
43
  },
40
44
  "scripts": {
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",
45
+ "build": "dts build",
46
+ "build:dev": "dts watch",
43
47
  "test": "vitest run"
44
48
  }
45
49
  }
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { MastraDeployer } from '@mastra/core';
2
- import { createChildProcessLogger } from '@mastra/deployer';
3
- import { Cloudflare } from 'cloudflare';
2
+ import * as child_process from 'child_process';
4
3
  import { writeFileSync } from 'fs';
5
4
  import { join } from 'path';
6
5
 
@@ -11,68 +10,52 @@ interface CFRoute {
11
10
  }
12
11
 
13
12
  export class CloudflareDeployer extends MastraDeployer {
14
- private cloudflare: Cloudflare | undefined;
15
13
  routes?: CFRoute[] = [];
16
- workerNamespace?: string;
17
14
  constructor({
18
15
  scope,
19
16
  env,
20
17
  projectName,
21
18
  routes,
22
- workerNamespace,
23
- auth,
24
19
  }: {
25
20
  env?: Record<string, any>;
26
21
  scope: string;
27
22
  projectName: string;
28
23
  routes?: CFRoute[];
29
- workerNamespace?: string;
30
- auth?: {
31
- apiToken: string;
32
- apiEmail: string;
33
- };
34
24
  }) {
35
25
  super({ scope, env, projectName });
36
26
 
37
27
  this.routes = routes;
38
- this.workerNamespace = workerNamespace;
39
-
40
- if (auth) {
41
- this.cloudflare = new Cloudflare(auth);
42
- }
43
28
  }
44
29
 
45
- override writeFiles({ dir }: { dir: string }): void {
30
+ writeFiles({ dir }: { dir: string }): void {
46
31
  this.loadEnvVars();
47
32
 
48
33
  this.writeIndex({ dir });
49
34
 
50
35
  const cfWorkerName = this.projectName || 'mastra';
51
36
 
52
- const wranglerConfig: Record<string, any> = {
53
- name: cfWorkerName,
54
- main: 'index.mjs',
55
- compatibility_date: '2024-12-02',
56
- compatibility_flags: ['nodejs_compat'],
57
- build: {
58
- command: 'npm install',
59
- },
60
- observability: {
61
- logs: {
62
- enabled: true,
37
+ writeFileSync(
38
+ join(dir, 'wrangler.json'),
39
+ JSON.stringify({
40
+ name: cfWorkerName,
41
+ main: 'index.mjs',
42
+ compatibility_date: '2024-12-02',
43
+ compatibility_flags: ['nodejs_compat'],
44
+ build: {
45
+ command: 'npm install',
63
46
  },
64
- },
65
- vars: this.env,
66
- };
67
-
68
- if (!this.workerNamespace && this.routes) {
69
- wranglerConfig.routes = this.routes;
70
- }
71
-
72
- writeFileSync(join(dir, 'wrangler.json'), JSON.stringify(wranglerConfig));
47
+ observability: {
48
+ logs: {
49
+ enabled: true,
50
+ },
51
+ },
52
+ routes: this.routes,
53
+ vars: this.env,
54
+ }),
55
+ );
73
56
  }
74
57
 
75
- override writeIndex({ dir }: { dir: string }): void {
58
+ writeIndex({ dir }: { dir: string }): void {
76
59
  writeFileSync(
77
60
  join(dir, './index.mjs'),
78
61
  `
@@ -89,46 +72,16 @@ export class CloudflareDeployer extends MastraDeployer {
89
72
  );
90
73
  }
91
74
 
92
- override async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
93
- const cmd = this.workerNamespace
94
- ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}`
95
- : 'npm exec -- wrangler deploy';
96
-
97
- const cpLogger = createChildProcessLogger({
98
- logger: this.logger,
99
- root: dir,
100
- });
101
-
102
- await cpLogger({
103
- cmd,
104
- args: [],
75
+ async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
76
+ child_process.execSync(`npm exec wrangler deploy`, {
77
+ cwd: dir,
78
+ stdio: 'inherit',
105
79
  env: {
106
80
  CLOUDFLARE_API_TOKEN: token,
107
81
  CLOUDFLARE_ACCOUNT_ID: this.scope,
108
82
  ...this.env,
109
- PATH: process.env.PATH!,
83
+ PATH: process.env.PATH,
110
84
  },
111
85
  });
112
86
  }
113
-
114
- async tagWorker({
115
- workerName,
116
- namespace,
117
- tags,
118
- scope,
119
- }: {
120
- scope: string;
121
- workerName: string;
122
- namespace: string;
123
- tags: string[];
124
- }): Promise<void> {
125
- if (!this.cloudflare) {
126
- throw new Error('Cloudflare Deployer not initialized');
127
- }
128
-
129
- await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
130
- account_id: scope,
131
- body: tags,
132
- });
133
- }
134
87
  }
@@ -33,7 +33,7 @@ export class CloudflareSecretsManager {
33
33
  }),
34
34
  });
35
35
 
36
- const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
36
+ const data = await response.json();
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()) as { success: boolean; result: any; errors: any[] };
75
+ const data = await response.json();
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()) as { success: boolean; result: any; errors: any[] };
98
+ const data = await response.json();
99
99
 
100
100
  if (!data.success) {
101
101
  throw new Error(data.errors[0].message);
package/tsconfig.json CHANGED
@@ -1,5 +1,10 @@
1
1
  {
2
- "extends": "../../tsconfig.node.json",
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "moduleResolution": "bundler",
5
+ "outDir": "./dist",
6
+ "rootDir": "./src"
7
+ },
3
8
  "include": ["src/**/*"],
4
9
  "exclude": ["node_modules", "**/*.test.ts"]
5
10
  }
package/vitest.config.ts CHANGED
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- environment: 'node',
5
+ globals: true,
6
6
  include: ['src/**/*.test.ts'],
7
7
  },
8
8
  });
@@ -1,87 +0,0 @@
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 };