@mastra/deployer-cloudflare 0.0.0-storage-20250225005900 → 0.0.0-trigger-playground-ui-package-20250506151043
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/{LICENSE → LICENSE.md} +3 -1
- package/dist/_tsup-dts-rollup.d.cts +69 -0
- package/dist/_tsup-dts-rollup.d.ts +5 -1
- package/dist/index.cjs +186 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.js +92 -23
- package/{src/secrets-manager/index.ts → dist/secrets-manager/index.cjs} +31 -52
- package/dist/secrets-manager/index.d.cts +1 -0
- package/package.json +38 -22
- package/.turbo/turbo-build.log +0 -20
- package/CHANGELOG.md +0 -939
- package/global.d.ts +0 -1
- package/src/index.ts +0 -148
- package/src/secrets-manager/index.test.ts +0 -230
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/{LICENSE → LICENSE.md}
RENAMED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { analyzeBundle } from '@mastra/deployer/analyze';
|
|
2
|
+
import { Deployer } from '@mastra/deployer';
|
|
3
|
+
import { InputOptions } from 'rollup';
|
|
4
|
+
|
|
5
|
+
declare interface CFRoute {
|
|
6
|
+
pattern: string;
|
|
7
|
+
zone_name: string;
|
|
8
|
+
custom_domain?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare class CloudflareDeployer extends Deployer {
|
|
12
|
+
private cloudflare;
|
|
13
|
+
routes?: CFRoute[];
|
|
14
|
+
workerNamespace?: string;
|
|
15
|
+
scope: string;
|
|
16
|
+
env?: Record<string, any>;
|
|
17
|
+
projectName?: string;
|
|
18
|
+
constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
|
|
19
|
+
env?: Record<string, any>;
|
|
20
|
+
scope: string;
|
|
21
|
+
projectName?: string;
|
|
22
|
+
routes?: CFRoute[];
|
|
23
|
+
workerNamespace?: string;
|
|
24
|
+
auth: {
|
|
25
|
+
apiToken: string;
|
|
26
|
+
apiEmail?: string;
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
writeFiles(outputDirectory: string): Promise<void>;
|
|
30
|
+
private getEntry;
|
|
31
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
32
|
+
getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
|
|
33
|
+
bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
34
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
35
|
+
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
36
|
+
scope: string;
|
|
37
|
+
workerName: string;
|
|
38
|
+
namespace: string;
|
|
39
|
+
tags: string[];
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare class CloudflareSecretsManager {
|
|
45
|
+
accountId: string;
|
|
46
|
+
apiToken: string;
|
|
47
|
+
baseUrl: string;
|
|
48
|
+
constructor({ accountId, apiToken }: {
|
|
49
|
+
accountId: string;
|
|
50
|
+
apiToken: string;
|
|
51
|
+
});
|
|
52
|
+
createSecret({ workerId, secretName, secretValue, }: {
|
|
53
|
+
workerId: string;
|
|
54
|
+
secretName: string;
|
|
55
|
+
secretValue: string;
|
|
56
|
+
}): Promise<any>;
|
|
57
|
+
createProjectSecrets({ workerId, customerId, envVars, }: {
|
|
58
|
+
workerId: string;
|
|
59
|
+
customerId: string;
|
|
60
|
+
envVars: Record<string, string>;
|
|
61
|
+
}): Promise<any>;
|
|
62
|
+
deleteSecret({ workerId, secretName }: {
|
|
63
|
+
workerId: string;
|
|
64
|
+
secretName: string;
|
|
65
|
+
}): Promise<any>;
|
|
66
|
+
listSecrets(workerId: string): Promise<any>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { }
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { analyzeBundle } from '@mastra/deployer/analyze';
|
|
1
2
|
import { Deployer } from '@mastra/deployer';
|
|
3
|
+
import { InputOptions } from 'rollup';
|
|
2
4
|
|
|
3
5
|
declare interface CFRoute {
|
|
4
6
|
pattern: string;
|
|
@@ -27,7 +29,8 @@ export declare class CloudflareDeployer extends Deployer {
|
|
|
27
29
|
writeFiles(outputDirectory: string): Promise<void>;
|
|
28
30
|
private getEntry;
|
|
29
31
|
prepare(outputDirectory: string): Promise<void>;
|
|
30
|
-
|
|
32
|
+
getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
|
|
33
|
+
bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
31
34
|
deploy(outputDirectory: string): Promise<void>;
|
|
32
35
|
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
33
36
|
scope: string;
|
|
@@ -35,6 +38,7 @@ export declare class CloudflareDeployer extends Deployer {
|
|
|
35
38
|
namespace: string;
|
|
36
39
|
tags: string[];
|
|
37
40
|
}): Promise<void>;
|
|
41
|
+
lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export declare class CloudflareSecretsManager {
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('fs/promises');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var deployer = require('@mastra/deployer');
|
|
6
|
+
var virtual = require('@rollup/plugin-virtual');
|
|
7
|
+
var cloudflare = require('cloudflare');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var virtual__default = /*#__PURE__*/_interopDefault(virtual);
|
|
12
|
+
|
|
13
|
+
// src/index.ts
|
|
14
|
+
var CloudflareDeployer = class extends deployer.Deployer {
|
|
15
|
+
cloudflare;
|
|
16
|
+
routes = [];
|
|
17
|
+
workerNamespace;
|
|
18
|
+
scope;
|
|
19
|
+
env;
|
|
20
|
+
projectName;
|
|
21
|
+
constructor({
|
|
22
|
+
scope,
|
|
23
|
+
env,
|
|
24
|
+
projectName = "mastra",
|
|
25
|
+
routes,
|
|
26
|
+
workerNamespace,
|
|
27
|
+
auth
|
|
28
|
+
}) {
|
|
29
|
+
super({ name: "CLOUDFLARE" });
|
|
30
|
+
this.scope = scope;
|
|
31
|
+
this.projectName = projectName;
|
|
32
|
+
this.routes = routes;
|
|
33
|
+
this.workerNamespace = workerNamespace;
|
|
34
|
+
if (env) {
|
|
35
|
+
this.env = env;
|
|
36
|
+
}
|
|
37
|
+
this.cloudflare = new cloudflare.Cloudflare(auth);
|
|
38
|
+
}
|
|
39
|
+
async writeFiles(outputDirectory) {
|
|
40
|
+
const env = await this.loadEnvVars();
|
|
41
|
+
const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
|
|
42
|
+
const cfWorkerName = this.projectName;
|
|
43
|
+
const wranglerConfig = {
|
|
44
|
+
name: cfWorkerName,
|
|
45
|
+
main: "./index.mjs",
|
|
46
|
+
compatibility_date: "2025-04-01",
|
|
47
|
+
compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
|
|
48
|
+
observability: {
|
|
49
|
+
logs: {
|
|
50
|
+
enabled: true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
vars: envsAsObject
|
|
54
|
+
};
|
|
55
|
+
if (!this.workerNamespace && this.routes) {
|
|
56
|
+
wranglerConfig.routes = this.routes;
|
|
57
|
+
}
|
|
58
|
+
await promises.writeFile(path.join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
|
|
59
|
+
}
|
|
60
|
+
getEntry() {
|
|
61
|
+
return `
|
|
62
|
+
import '#polyfills';
|
|
63
|
+
import { mastra } from '#mastra';
|
|
64
|
+
import { createHonoServer } from '#server';
|
|
65
|
+
import { evaluate } from '@mastra/core/eval';
|
|
66
|
+
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
67
|
+
import { TABLE_EVALS } from '@mastra/core/storage';
|
|
68
|
+
import { checkEvalStorageFields } from '@mastra/core/utils';
|
|
69
|
+
|
|
70
|
+
registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
|
|
71
|
+
evaluate({
|
|
72
|
+
agentName,
|
|
73
|
+
input,
|
|
74
|
+
metric,
|
|
75
|
+
output,
|
|
76
|
+
runId,
|
|
77
|
+
globalRunId: runId,
|
|
78
|
+
instructions,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (mastra.getStorage()) {
|
|
83
|
+
// start storage init in the background
|
|
84
|
+
mastra.getStorage().init();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
88
|
+
const storage = mastra.getStorage();
|
|
89
|
+
if (storage) {
|
|
90
|
+
// Check for required fields
|
|
91
|
+
const logger = mastra?.getLogger();
|
|
92
|
+
const areFieldsValid = checkEvalStorageFields(traceObject, logger);
|
|
93
|
+
if (!areFieldsValid) return;
|
|
94
|
+
|
|
95
|
+
await storage.insert({
|
|
96
|
+
tableName: TABLE_EVALS,
|
|
97
|
+
record: {
|
|
98
|
+
input: traceObject.input,
|
|
99
|
+
output: traceObject.output,
|
|
100
|
+
result: JSON.stringify(traceObject.result || {}),
|
|
101
|
+
agent_name: traceObject.agentName,
|
|
102
|
+
metric_name: traceObject.metricName,
|
|
103
|
+
instructions: traceObject.instructions,
|
|
104
|
+
test_info: null,
|
|
105
|
+
global_run_id: traceObject.globalRunId,
|
|
106
|
+
run_id: traceObject.runId,
|
|
107
|
+
created_at: new Date().toISOString(),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export default {
|
|
114
|
+
fetch: async (request, env, context) => {
|
|
115
|
+
const app = await createHonoServer(mastra)
|
|
116
|
+
return app.fetch(request, env, context);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
async prepare(outputDirectory) {
|
|
122
|
+
await super.prepare(outputDirectory);
|
|
123
|
+
await this.writeFiles(outputDirectory);
|
|
124
|
+
}
|
|
125
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
|
|
126
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
|
|
127
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
128
|
+
inputOptions.plugins = [
|
|
129
|
+
virtual__default.default({
|
|
130
|
+
"#polyfills": `
|
|
131
|
+
process.versions = process.versions || {};
|
|
132
|
+
process.versions.node = '${process.versions.node}';
|
|
133
|
+
`
|
|
134
|
+
}),
|
|
135
|
+
...inputOptions.plugins
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
return inputOptions;
|
|
139
|
+
}
|
|
140
|
+
async bundle(entryFile, outputDirectory, toolsPaths) {
|
|
141
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
142
|
+
}
|
|
143
|
+
async deploy(outputDirectory) {
|
|
144
|
+
const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
|
|
145
|
+
const cpLogger = deployer.createChildProcessLogger({
|
|
146
|
+
logger: this.logger,
|
|
147
|
+
root: path.join(outputDirectory, this.outputDir)
|
|
148
|
+
});
|
|
149
|
+
await cpLogger({
|
|
150
|
+
cmd,
|
|
151
|
+
args: [],
|
|
152
|
+
env: {
|
|
153
|
+
CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
|
|
154
|
+
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
155
|
+
...this.env,
|
|
156
|
+
PATH: process.env.PATH
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async tagWorker({
|
|
161
|
+
workerName,
|
|
162
|
+
namespace,
|
|
163
|
+
tags,
|
|
164
|
+
scope
|
|
165
|
+
}) {
|
|
166
|
+
if (!this.cloudflare) {
|
|
167
|
+
throw new Error("Cloudflare Deployer not initialized");
|
|
168
|
+
}
|
|
169
|
+
await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
|
|
170
|
+
account_id: scope,
|
|
171
|
+
body: tags
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
175
|
+
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
176
|
+
const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
|
|
177
|
+
if (hasLibsql) {
|
|
178
|
+
this.logger.error(
|
|
179
|
+
"Cloudflare Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead @mastra/cloudflare-d1"
|
|
180
|
+
);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
exports.CloudflareDeployer = CloudflareDeployer;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CloudflareDeployer } from './_tsup-dts-rollup.cjs';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { writeFile } from 'fs/promises';
|
|
2
|
+
import { join } from 'path';
|
|
1
3
|
import { Deployer, createChildProcessLogger } from '@mastra/deployer';
|
|
2
|
-
import '@
|
|
3
|
-
import '@rollup/plugin-virtual';
|
|
4
|
+
import virtual from '@rollup/plugin-virtual';
|
|
4
5
|
import { Cloudflare } from 'cloudflare';
|
|
5
|
-
import { writeFileSync } from 'fs';
|
|
6
|
-
import { join } from 'path';
|
|
7
6
|
|
|
8
7
|
// src/index.ts
|
|
9
8
|
var CloudflareDeployer = class extends Deployer {
|
|
@@ -37,9 +36,9 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
37
36
|
const cfWorkerName = this.projectName;
|
|
38
37
|
const wranglerConfig = {
|
|
39
38
|
name: cfWorkerName,
|
|
40
|
-
main: "index.mjs",
|
|
41
|
-
compatibility_date: "
|
|
42
|
-
compatibility_flags: ["nodejs_compat"],
|
|
39
|
+
main: "./index.mjs",
|
|
40
|
+
compatibility_date: "2025-04-01",
|
|
41
|
+
compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
|
|
43
42
|
observability: {
|
|
44
43
|
logs: {
|
|
45
44
|
enabled: true
|
|
@@ -50,36 +49,96 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
50
49
|
if (!this.workerNamespace && this.routes) {
|
|
51
50
|
wranglerConfig.routes = this.routes;
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
|
|
54
53
|
}
|
|
55
54
|
getEntry() {
|
|
56
55
|
return `
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
56
|
+
import '#polyfills';
|
|
57
|
+
import { mastra } from '#mastra';
|
|
58
|
+
import { createHonoServer } from '#server';
|
|
59
|
+
import { evaluate } from '@mastra/core/eval';
|
|
60
|
+
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
61
|
+
import { TABLE_EVALS } from '@mastra/core/storage';
|
|
62
|
+
import { checkEvalStorageFields } from '@mastra/core/utils';
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
|
|
65
|
+
evaluate({
|
|
66
|
+
agentName,
|
|
67
|
+
input,
|
|
68
|
+
metric,
|
|
69
|
+
output,
|
|
70
|
+
runId,
|
|
71
|
+
globalRunId: runId,
|
|
72
|
+
instructions,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (mastra.getStorage()) {
|
|
77
|
+
// start storage init in the background
|
|
78
|
+
mastra.getStorage().init();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
82
|
+
const storage = mastra.getStorage();
|
|
83
|
+
if (storage) {
|
|
84
|
+
// Check for required fields
|
|
85
|
+
const logger = mastra?.getLogger();
|
|
86
|
+
const areFieldsValid = checkEvalStorageFields(traceObject, logger);
|
|
87
|
+
if (!areFieldsValid) return;
|
|
88
|
+
|
|
89
|
+
await storage.insert({
|
|
90
|
+
tableName: TABLE_EVALS,
|
|
91
|
+
record: {
|
|
92
|
+
input: traceObject.input,
|
|
93
|
+
output: traceObject.output,
|
|
94
|
+
result: JSON.stringify(traceObject.result || {}),
|
|
95
|
+
agent_name: traceObject.agentName,
|
|
96
|
+
metric_name: traceObject.metricName,
|
|
97
|
+
instructions: traceObject.instructions,
|
|
98
|
+
test_info: null,
|
|
99
|
+
global_run_id: traceObject.globalRunId,
|
|
100
|
+
run_id: traceObject.runId,
|
|
101
|
+
created_at: new Date().toISOString(),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export default {
|
|
108
|
+
fetch: async (request, env, context) => {
|
|
109
|
+
const app = await createHonoServer(mastra)
|
|
110
|
+
return app.fetch(request, env, context);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
69
113
|
`;
|
|
70
114
|
}
|
|
71
115
|
async prepare(outputDirectory) {
|
|
72
116
|
await super.prepare(outputDirectory);
|
|
73
117
|
await this.writeFiles(outputDirectory);
|
|
74
118
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
119
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
|
|
120
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
|
|
121
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
122
|
+
inputOptions.plugins = [
|
|
123
|
+
virtual({
|
|
124
|
+
"#polyfills": `
|
|
125
|
+
process.versions = process.versions || {};
|
|
126
|
+
process.versions.node = '${process.versions.node}';
|
|
127
|
+
`
|
|
128
|
+
}),
|
|
129
|
+
...inputOptions.plugins
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
return inputOptions;
|
|
133
|
+
}
|
|
134
|
+
async bundle(entryFile, outputDirectory, toolsPaths) {
|
|
135
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
77
136
|
}
|
|
78
137
|
async deploy(outputDirectory) {
|
|
79
|
-
const cmd = this.workerNamespace ? `npm exec -- wrangler deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler deploy";
|
|
138
|
+
const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
|
|
80
139
|
const cpLogger = createChildProcessLogger({
|
|
81
140
|
logger: this.logger,
|
|
82
|
-
root: outputDirectory
|
|
141
|
+
root: join(outputDirectory, this.outputDir)
|
|
83
142
|
});
|
|
84
143
|
await cpLogger({
|
|
85
144
|
cmd,
|
|
@@ -106,6 +165,16 @@ export default {
|
|
|
106
165
|
body: tags
|
|
107
166
|
});
|
|
108
167
|
}
|
|
168
|
+
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
169
|
+
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
170
|
+
const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
|
|
171
|
+
if (hasLibsql) {
|
|
172
|
+
this.logger.error(
|
|
173
|
+
"Cloudflare Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead @mastra/cloudflare-d1"
|
|
174
|
+
);
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
109
178
|
};
|
|
110
179
|
|
|
111
180
|
export { CloudflareDeployer };
|
|
@@ -1,110 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/secrets-manager/index.ts
|
|
4
|
+
var CloudflareSecretsManager = class {
|
|
5
|
+
accountId;
|
|
6
|
+
apiToken;
|
|
7
|
+
baseUrl;
|
|
8
|
+
constructor({ accountId, apiToken }) {
|
|
7
9
|
this.accountId = accountId;
|
|
8
10
|
this.apiToken = apiToken;
|
|
9
|
-
this.baseUrl =
|
|
11
|
+
this.baseUrl = "https://api.cloudflare.com/client/v4";
|
|
10
12
|
}
|
|
11
|
-
|
|
12
13
|
async createSecret({
|
|
13
14
|
workerId,
|
|
14
15
|
secretName,
|
|
15
|
-
secretValue
|
|
16
|
-
}: {
|
|
17
|
-
workerId: string;
|
|
18
|
-
secretName: string;
|
|
19
|
-
secretValue: string;
|
|
16
|
+
secretValue
|
|
20
17
|
}) {
|
|
21
18
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
|
|
22
|
-
|
|
23
19
|
try {
|
|
24
20
|
const response = await fetch(url, {
|
|
25
|
-
method:
|
|
21
|
+
method: "PUT",
|
|
26
22
|
headers: {
|
|
27
23
|
Authorization: `Bearer ${this.apiToken}`,
|
|
28
|
-
|
|
24
|
+
"Content-Type": "application/json"
|
|
29
25
|
},
|
|
30
26
|
body: JSON.stringify({
|
|
31
27
|
name: secretName,
|
|
32
|
-
text: secretValue
|
|
33
|
-
})
|
|
28
|
+
text: secretValue
|
|
29
|
+
})
|
|
34
30
|
});
|
|
35
|
-
|
|
36
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
37
|
-
|
|
31
|
+
const data = await response.json();
|
|
38
32
|
if (!data.success) {
|
|
39
33
|
throw new Error(data.errors[0].message);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
return data.result;
|
|
43
36
|
} catch (error) {
|
|
44
|
-
console.error(
|
|
37
|
+
console.error("Failed to create secret:", error);
|
|
45
38
|
throw error;
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
async createProjectSecrets({
|
|
50
42
|
workerId,
|
|
51
43
|
customerId,
|
|
52
|
-
envVars
|
|
53
|
-
}: {
|
|
54
|
-
workerId: string;
|
|
55
|
-
customerId: string;
|
|
56
|
-
envVars: Record<string, string>;
|
|
44
|
+
envVars
|
|
57
45
|
}) {
|
|
58
46
|
const secretName = `PROJECT_${customerId.toUpperCase()}`;
|
|
59
47
|
const secretValue = JSON.stringify(envVars);
|
|
60
|
-
|
|
61
48
|
return this.createSecret({ workerId, secretName, secretValue });
|
|
62
49
|
}
|
|
63
|
-
|
|
64
|
-
async deleteSecret({ workerId, secretName }: { workerId: string; secretName: string }) {
|
|
50
|
+
async deleteSecret({ workerId, secretName }) {
|
|
65
51
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;
|
|
66
|
-
|
|
67
52
|
try {
|
|
68
53
|
const response = await fetch(url, {
|
|
69
|
-
method:
|
|
54
|
+
method: "DELETE",
|
|
70
55
|
headers: {
|
|
71
|
-
Authorization: `Bearer ${this.apiToken}
|
|
72
|
-
}
|
|
56
|
+
Authorization: `Bearer ${this.apiToken}`
|
|
57
|
+
}
|
|
73
58
|
});
|
|
74
|
-
|
|
75
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
76
|
-
|
|
59
|
+
const data = await response.json();
|
|
77
60
|
if (!data.success) {
|
|
78
61
|
throw new Error(data.errors[0].message);
|
|
79
62
|
}
|
|
80
|
-
|
|
81
63
|
return data.result;
|
|
82
64
|
} catch (error) {
|
|
83
|
-
console.error(
|
|
65
|
+
console.error("Failed to delete secret:", error);
|
|
84
66
|
throw error;
|
|
85
67
|
}
|
|
86
68
|
}
|
|
87
|
-
|
|
88
|
-
async listSecrets(workerId: string) {
|
|
69
|
+
async listSecrets(workerId) {
|
|
89
70
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
|
|
90
|
-
|
|
91
71
|
try {
|
|
92
72
|
const response = await fetch(url, {
|
|
93
73
|
headers: {
|
|
94
|
-
Authorization: `Bearer ${this.apiToken}
|
|
95
|
-
}
|
|
74
|
+
Authorization: `Bearer ${this.apiToken}`
|
|
75
|
+
}
|
|
96
76
|
});
|
|
97
|
-
|
|
98
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
99
|
-
|
|
77
|
+
const data = await response.json();
|
|
100
78
|
if (!data.success) {
|
|
101
79
|
throw new Error(data.errors[0].message);
|
|
102
80
|
}
|
|
103
|
-
|
|
104
81
|
return data.result;
|
|
105
82
|
} catch (error) {
|
|
106
|
-
console.error(
|
|
83
|
+
console.error("Failed to list secrets:", error);
|
|
107
84
|
throw error;
|
|
108
85
|
}
|
|
109
86
|
}
|
|
110
|
-
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.CloudflareSecretsManager = CloudflareSecretsManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CloudflareSecretsManager } from '../_tsup-dts-rollup.cjs';
|
package/package.json
CHANGED
|
@@ -1,46 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-trigger-playground-ui-package-20250506151043",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"main": "dist/index.js",
|
|
7
10
|
"types": "dist/index.d.ts",
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/index.d.cts",
|
|
19
|
+
"default": "./dist/index.cjs"
|
|
20
|
+
}
|
|
12
21
|
},
|
|
13
22
|
"./secrets-manager": {
|
|
14
|
-
"
|
|
15
|
-
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/secrets-manager/index.d.ts",
|
|
25
|
+
"default": "./dist/secrets-manager/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/secrets-manager/index.d.cts",
|
|
29
|
+
"default": "./dist/secrets-manager/index.cjs"
|
|
30
|
+
}
|
|
16
31
|
},
|
|
17
32
|
"./package.json": "./package.json"
|
|
18
33
|
},
|
|
19
34
|
"keywords": [],
|
|
20
35
|
"author": "",
|
|
21
|
-
"license": "
|
|
36
|
+
"license": "Elastic-2.0",
|
|
22
37
|
"dependencies": {
|
|
38
|
+
"@babel/core": "^7.26.10",
|
|
23
39
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
24
|
-
"cloudflare": "^4.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"zod": "^3.24.1",
|
|
31
|
-
"@mastra/core": "^0.0.0-storage-20250225005900",
|
|
32
|
-
"@mastra/deployer": "^0.0.0-storage-20250225005900"
|
|
40
|
+
"cloudflare": "^4.1.0",
|
|
41
|
+
"rollup": "^4.35.0",
|
|
42
|
+
"wrangler": "^4.4.0",
|
|
43
|
+
"zod": "^3.24.2",
|
|
44
|
+
"@mastra/core": "0.0.0-trigger-playground-ui-package-20250506151043",
|
|
45
|
+
"@mastra/deployer": "0.0.0-trigger-playground-ui-package-20250506151043"
|
|
33
46
|
},
|
|
34
47
|
"devDependencies": {
|
|
35
|
-
"@microsoft/api-extractor": "^7.
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
48
|
+
"@microsoft/api-extractor": "^7.52.5",
|
|
49
|
+
"@types/node": "^20.17.27",
|
|
50
|
+
"eslint": "^9.23.0",
|
|
51
|
+
"tsup": "^8.4.0",
|
|
52
|
+
"typescript": "^5.8.2",
|
|
53
|
+
"vitest": "^3.1.2",
|
|
54
|
+
"@internal/lint": "0.0.0-trigger-playground-ui-package-20250506151043"
|
|
40
55
|
},
|
|
41
56
|
"scripts": {
|
|
42
|
-
"build": "tsup src/index.ts src/secrets-manager/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
57
|
+
"build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
43
58
|
"build:watch": "pnpm build --watch",
|
|
44
|
-
"test": "vitest run"
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"lint": "eslint ."
|
|
45
61
|
}
|
|
46
62
|
}
|