@mastra/deployer-cloudflare 0.0.1-alpha.22 → 0.0.1-alpha.25
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 +25 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +98 -6
- package/dist/secrets-manager/index.d.ts +3 -2
- package/dist/secrets-manager/index.js +87 -0
- package/package.json +13 -17
- package/src/index.ts +3 -3
- package/src/secrets-manager/index.ts +3 -3
- package/tsconfig.json +1 -6
- package/vitest.config.ts +1 -1
- package/dist/deployer-cloudflare.cjs.development.js +0 -479
- package/dist/deployer-cloudflare.cjs.development.js.map +0 -1
- package/dist/deployer-cloudflare.cjs.production.min.js +0 -2
- package/dist/deployer-cloudflare.cjs.production.min.js.map +0 -1
- package/dist/deployer-cloudflare.esm.js +0 -475
- package/dist/deployer-cloudflare.esm.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/secrets-manager/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/deployer-cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.25
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 44c7c26: Rebuild
|
|
8
|
+
|
|
9
|
+
## 0.0.1-alpha.24
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [685108a]
|
|
14
|
+
- Updated dependencies [685108a]
|
|
15
|
+
- @mastra/deployer@0.0.1-alpha.22
|
|
16
|
+
- @mastra/core@0.1.27-alpha.78
|
|
17
|
+
|
|
18
|
+
## 0.0.1-alpha.23
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 2b75edf: mastra deployers tsup bundling
|
|
23
|
+
- Updated dependencies [8105fae]
|
|
24
|
+
- Updated dependencies [cfb966f]
|
|
25
|
+
- @mastra/core@0.1.27-alpha.77
|
|
26
|
+
- @mastra/deployer@0.0.1-alpha.21
|
|
27
|
+
|
|
3
28
|
## 0.0.1-alpha.22
|
|
4
29
|
|
|
5
30
|
### 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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,21 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/deployer-cloudflare.esm.js",
|
|
8
7
|
"types": "dist/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"default": "./dist/index.js"
|
|
18
|
-
}
|
|
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"
|
|
19
16
|
},
|
|
20
17
|
"./package.json": "./package.json"
|
|
21
18
|
},
|
|
@@ -29,21 +26,20 @@
|
|
|
29
26
|
"execa": "^9.3.1",
|
|
30
27
|
"wrangler": "^3.103.2",
|
|
31
28
|
"zod": "^3.24.1",
|
|
32
|
-
"@mastra/core": "0.1.27-alpha.
|
|
33
|
-
"@mastra/deployer": "0.0.1-alpha.
|
|
29
|
+
"@mastra/core": "0.1.27-alpha.78",
|
|
30
|
+
"@mastra/deployer": "0.0.1-alpha.22"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@babel/preset-env": "^7.26.0",
|
|
37
34
|
"@babel/preset-typescript": "^7.26.0",
|
|
38
35
|
"@tsconfig/recommended": "^1.0.7",
|
|
39
|
-
"@types/jsdom": "^21.1.7",
|
|
40
36
|
"@types/node": "^22.9.0",
|
|
41
|
-
"
|
|
42
|
-
"vitest": "^
|
|
37
|
+
"tsup": "^8.0.1",
|
|
38
|
+
"vitest": "^3.0.4"
|
|
43
39
|
},
|
|
44
40
|
"scripts": {
|
|
45
|
-
"build": "dts
|
|
46
|
-
"
|
|
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",
|
|
47
43
|
"test": "vitest run"
|
|
48
44
|
}
|
|
49
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class CloudflareDeployer extends MastraDeployer {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
writeFiles({ dir }: { dir: string }): void {
|
|
45
|
+
override writeFiles({ dir }: { dir: string }): void {
|
|
46
46
|
this.loadEnvVars();
|
|
47
47
|
|
|
48
48
|
this.writeIndex({ dir });
|
|
@@ -72,7 +72,7 @@ export class CloudflareDeployer extends MastraDeployer {
|
|
|
72
72
|
writeFileSync(join(dir, 'wrangler.json'), JSON.stringify(wranglerConfig));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
writeIndex({ dir }: { dir: string }): void {
|
|
75
|
+
override writeIndex({ dir }: { dir: string }): void {
|
|
76
76
|
writeFileSync(
|
|
77
77
|
join(dir, './index.mjs'),
|
|
78
78
|
`
|
|
@@ -89,7 +89,7 @@ export class CloudflareDeployer extends MastraDeployer {
|
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
|
|
92
|
+
override async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
|
|
93
93
|
const cmd = this.workerNamespace
|
|
94
94
|
? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}`
|
|
95
95
|
: 'npm exec -- wrangler deploy';
|
|
@@ -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);
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "bundler",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"rootDir": "./src"
|
|
7
|
-
},
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
8
3
|
"include": ["src/**/*"],
|
|
9
4
|
"exclude": ["node_modules", "**/*.test.ts"]
|
|
10
5
|
}
|