@mastra/deployer-cloudflare 0.0.1-alpha.29 → 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/CHANGELOG.md +0 -207
- package/dist/deployer-cloudflare.cjs.development.js +451 -0
- package/dist/deployer-cloudflare.cjs.development.js.map +1 -0
- package/dist/deployer-cloudflare.cjs.production.min.js +2 -0
- package/dist/deployer-cloudflare.cjs.production.min.js.map +1 -0
- package/dist/deployer-cloudflare.esm.js +428 -0
- package/dist/deployer-cloudflare.esm.js.map +1 -0
- package/dist/index.d.ts +4 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -98
- package/dist/secrets-manager/index.d.ts +2 -3
- package/dist/secrets-manager/index.d.ts.map +1 -0
- package/package.json +18 -14
- package/src/index.ts +26 -73
- package/src/secrets-manager/index.ts +3 -3
- package/tsconfig.json +6 -1
- package/vitest.config.ts +1 -1
- package/README.md +0 -99
- package/dist/secrets-manager/index.js +0 -87
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
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
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
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.
|
|
30
|
-
"@mastra/deployer": "0.0.1-alpha.
|
|
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
|
-
"
|
|
38
|
-
"
|
|
40
|
+
"@types/pg": "^8.11.10",
|
|
41
|
+
"dts-cli": "^2.0.5",
|
|
42
|
+
"vitest": "^2.1.8"
|
|
39
43
|
},
|
|
40
44
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev": "
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
observability: {
|
|
48
|
+
logs: {
|
|
49
|
+
enabled: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
routes: this.routes,
|
|
53
|
+
vars: this.env,
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
73
56
|
}
|
|
74
57
|
|
|
75
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
: '
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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.
|
|
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
package/README.md
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# @mastra/deployer-cloudflare
|
|
2
|
-
|
|
3
|
-
A Cloudflare Workers deployer for Mastra applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Deploy Mastra applications to Cloudflare Workers
|
|
8
|
-
- Configure custom domains and routes
|
|
9
|
-
- Support for worker namespaces
|
|
10
|
-
- Automatic environment variable configuration
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
pnpm add @mastra/deployer-cloudflare
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
The Cloudflare deployer is used as part of the Mastra framework:
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { Mastra } from '@mastra/core';
|
|
24
|
-
import { CloudflareDeployer } from '@mastra/deployer-cloudflare';
|
|
25
|
-
|
|
26
|
-
const deployer = new CloudflareDeployer({
|
|
27
|
-
scope: 'your-account-id',
|
|
28
|
-
projectName: 'your-project-name',
|
|
29
|
-
routes: [
|
|
30
|
-
{
|
|
31
|
-
pattern: 'example.com/*',
|
|
32
|
-
zone_name: 'example.com',
|
|
33
|
-
custom_domain: true,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
workerNamespace: 'your-namespace',
|
|
37
|
-
auth: {
|
|
38
|
-
apiToken: 'your-api-token',
|
|
39
|
-
apiEmail: 'your-email',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const mastra = new Mastra({
|
|
44
|
-
deployer,
|
|
45
|
-
// ... other Mastra configuration options
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Configuration
|
|
50
|
-
|
|
51
|
-
### Constructor Options
|
|
52
|
-
|
|
53
|
-
- `scope` (required): Your Cloudflare account ID
|
|
54
|
-
- `projectName`: Name of your worker project
|
|
55
|
-
- `routes`: Array of route configurations for your worker
|
|
56
|
-
- `pattern`: URL pattern to match
|
|
57
|
-
- `zone_name`: Domain zone name
|
|
58
|
-
- `custom_domain`: Whether to use a custom domain
|
|
59
|
-
- `workerNamespace`: Namespace for your worker
|
|
60
|
-
- `auth`: Cloudflare authentication details
|
|
61
|
-
- `apiToken`: Your Cloudflare API token
|
|
62
|
-
- `apiEmail`: Your Cloudflare account email
|
|
63
|
-
|
|
64
|
-
## Environment Variables
|
|
65
|
-
|
|
66
|
-
The deployer will automatically load environment variables from:
|
|
67
|
-
|
|
68
|
-
- `.env` files in your project
|
|
69
|
-
- Environment variables passed through the Mastra configuration
|
|
70
|
-
|
|
71
|
-
## Routes
|
|
72
|
-
|
|
73
|
-
Routes can be configured to direct traffic to your worker based on URL patterns and domains:
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
const routes = [
|
|
77
|
-
{
|
|
78
|
-
pattern: 'api.example.com/*',
|
|
79
|
-
zone_name: 'example.com',
|
|
80
|
-
custom_domain: true,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
pattern: 'example.com/api/*',
|
|
84
|
-
zone_name: 'example.com',
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Each route requires:
|
|
90
|
-
|
|
91
|
-
- `pattern`: URL pattern to match
|
|
92
|
-
- `zone_name`: Domain zone name
|
|
93
|
-
- `custom_domain`: (optional) Set to true to use a custom domain
|
|
94
|
-
|
|
95
|
-
## Requirements
|
|
96
|
-
|
|
97
|
-
- Cloudflare account with Workers enabled
|
|
98
|
-
- API token with appropriate permissions
|
|
99
|
-
- Domain(s) configured in Cloudflare (for custom domains)
|
|
@@ -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 };
|