@mastra/deployer-cloudflare 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-model-providers-api-20251030210744

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +4235 -0
  2. package/LICENSE.md +11 -42
  3. package/dist/babel/mastra-instance-wrapper.d.ts +24 -0
  4. package/dist/babel/mastra-instance-wrapper.d.ts.map +1 -0
  5. package/dist/babel/postgres-store-instance-checker.d.ts +21 -0
  6. package/dist/babel/postgres-store-instance-checker.d.ts.map +1 -0
  7. package/dist/index.cjs +170 -90
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.ts +48 -1
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +153 -91
  12. package/dist/index.js.map +1 -0
  13. package/dist/plugins/__fixtures__/basic.d.ts +5 -0
  14. package/dist/plugins/__fixtures__/basic.d.ts.map +1 -0
  15. package/dist/plugins/__fixtures__/empty-mastra.d.ts +3 -0
  16. package/dist/plugins/__fixtures__/empty-mastra.d.ts.map +1 -0
  17. package/dist/plugins/__fixtures__/multiple-postgres-stores.d.ts +6 -0
  18. package/dist/plugins/__fixtures__/multiple-postgres-stores.d.ts.map +1 -0
  19. package/dist/plugins/mastra-instance-wrapper.d.ts +3 -0
  20. package/dist/plugins/mastra-instance-wrapper.d.ts.map +1 -0
  21. package/dist/plugins/postgres-store-instance-checker.d.ts +3 -0
  22. package/dist/plugins/postgres-store-instance-checker.d.ts.map +1 -0
  23. package/dist/secrets-manager/index.cjs +2 -0
  24. package/dist/secrets-manager/index.cjs.map +1 -0
  25. package/dist/secrets-manager/index.d.ts +25 -1
  26. package/dist/secrets-manager/index.d.ts.map +1 -0
  27. package/dist/secrets-manager/index.js +2 -0
  28. package/dist/secrets-manager/index.js.map +1 -0
  29. package/package.json +39 -22
  30. package/dist/_tsup-dts-rollup.d.cts +0 -68
  31. package/dist/_tsup-dts-rollup.d.ts +0 -68
  32. package/dist/index.d.cts +0 -1
  33. package/dist/secrets-manager/index.d.cts +0 -1
package/dist/index.js CHANGED
@@ -1,34 +1,134 @@
1
1
  import { writeFile } from 'fs/promises';
2
2
  import { join } from 'path';
3
- import { Deployer, createChildProcessLogger } from '@mastra/deployer';
3
+ import { Deployer } from '@mastra/deployer';
4
4
  import virtual from '@rollup/plugin-virtual';
5
- import { Cloudflare } from 'cloudflare';
5
+ import * as babel from '@babel/core';
6
+ import { transformSync } from '@babel/core';
7
+
8
+ // src/index.ts
9
+ function mastraInstanceWrapper() {
10
+ const exportName = "mastra";
11
+ const className = "Mastra";
12
+ const t = babel.types;
13
+ return {
14
+ name: "wrap-mastra",
15
+ visitor: {
16
+ ExportNamedDeclaration(path) {
17
+ if (t.isVariableDeclaration(path.node?.declaration)) {
18
+ for (const declaration of path.node.declaration.declarations) {
19
+ if (t.isIdentifier(declaration?.id, { name: exportName }) && t.isNewExpression(declaration?.init) && t.isIdentifier(declaration.init.callee, { name: className })) {
20
+ declaration.init = t.arrowFunctionExpression([], declaration.init);
21
+ break;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ };
28
+ }
29
+
30
+ // src/plugins/mastra-instance-wrapper.ts
31
+ function mastraInstanceWrapper2(mastraEntryFile) {
32
+ return {
33
+ name: "mastra-wrapper",
34
+ transform(code, id) {
35
+ if (id !== mastraEntryFile) {
36
+ return null;
37
+ }
38
+ const result = transformSync(code, {
39
+ filename: id,
40
+ babelrc: false,
41
+ configFile: false,
42
+ plugins: [mastraInstanceWrapper]
43
+ });
44
+ if (!result?.code) {
45
+ throw new Error("mastra-wrapper plugin did not return code, there is likely a bug in the plugin.");
46
+ }
47
+ return {
48
+ code: result.code,
49
+ map: result?.map
50
+ };
51
+ }
52
+ };
53
+ }
54
+ function postgresStoreInstanceChecker() {
55
+ const t = babel.types;
56
+ const instances = [];
57
+ return {
58
+ name: "postgresstore-instance-checker",
59
+ visitor: {
60
+ NewExpression(path, state) {
61
+ if (t.isIdentifier(path.node.callee) && path.node.callee.name === "PostgresStore") {
62
+ const filename = state.file?.opts?.filename || "unknown file";
63
+ const location = path.node.loc ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}` : "unknown location";
64
+ instances.push({
65
+ path,
66
+ location
67
+ });
68
+ }
69
+ }
70
+ },
71
+ post() {
72
+ if (instances.length > 1) {
73
+ const errorMessage = [
74
+ `Found ${instances.length} PostgresStore instantiations:`,
75
+ ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),
76
+ "Only one PostgresStore instance should be created per Cloudflare Worker."
77
+ ].join("\n");
78
+ const lastInstance = instances[instances.length - 1];
79
+ throw lastInstance?.path.buildCodeFrameError(errorMessage);
80
+ }
81
+ }
82
+ };
83
+ }
84
+
85
+ // src/plugins/postgres-store-instance-checker.ts
86
+ function postgresStoreInstanceChecker2() {
87
+ return {
88
+ name: "postgres-store-instance-checker",
89
+ transform(code, id) {
90
+ const result = transformSync(code, {
91
+ filename: id,
92
+ babelrc: false,
93
+ configFile: false,
94
+ plugins: [postgresStoreInstanceChecker]
95
+ });
96
+ if (!result || typeof result.code !== "string") {
97
+ return null;
98
+ }
99
+ return {
100
+ code: result.code,
101
+ map: result.map ?? null
102
+ };
103
+ }
104
+ };
105
+ }
6
106
 
7
107
  // src/index.ts
8
108
  var CloudflareDeployer = class extends Deployer {
9
- cloudflare;
10
109
  routes = [];
11
110
  workerNamespace;
12
- scope;
13
111
  env;
14
112
  projectName;
113
+ d1Databases;
114
+ kvNamespaces;
15
115
  constructor({
16
- scope,
17
116
  env,
18
117
  projectName = "mastra",
19
118
  routes,
20
119
  workerNamespace,
21
- auth
120
+ d1Databases,
121
+ kvNamespaces
22
122
  }) {
23
123
  super({ name: "CLOUDFLARE" });
24
- this.scope = scope;
25
124
  this.projectName = projectName;
26
125
  this.routes = routes;
27
126
  this.workerNamespace = workerNamespace;
28
127
  if (env) {
29
128
  this.env = env;
30
129
  }
31
- this.cloudflare = new Cloudflare(auth);
130
+ if (d1Databases) this.d1Databases = d1Databases;
131
+ if (kvNamespaces) this.kvNamespaces = kvNamespaces;
32
132
  }
33
133
  async writeFiles(outputDirectory) {
34
134
  const env = await this.loadEnvVars();
@@ -49,64 +149,31 @@ var CloudflareDeployer = class extends Deployer {
49
149
  if (!this.workerNamespace && this.routes) {
50
150
  wranglerConfig.routes = this.routes;
51
151
  }
152
+ if (this.d1Databases?.length) {
153
+ wranglerConfig.d1_databases = this.d1Databases;
154
+ }
155
+ if (this.kvNamespaces?.length) {
156
+ wranglerConfig.kv_namespaces = this.kvNamespaces;
157
+ }
52
158
  await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
53
159
  }
54
160
  getEntry() {
55
161
  return `
56
162
  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';
63
-
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
- });
163
+ import { scoreTracesWorkflow } from '@mastra/core/scores/scoreTraces';
106
164
 
107
165
  export default {
108
166
  fetch: async (request, env, context) => {
109
- const app = await createHonoServer(mastra)
167
+ const { mastra } = await import('#mastra');
168
+ const { tools } = await import('#tools');
169
+ const {createHonoServer, getToolExports} = await import('#server');
170
+ const _mastra = mastra();
171
+
172
+ if (_mastra.getStorage()) {
173
+ _mastra.__registerInternalWorkflow(scoreTracesWorkflow);
174
+ }
175
+
176
+ const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });
110
177
  return app.fetch(request, env, context);
111
178
  }
112
179
  }
@@ -116,8 +183,12 @@ var CloudflareDeployer = class extends Deployer {
116
183
  await super.prepare(outputDirectory);
117
184
  await this.writeFiles(outputDirectory);
118
185
  }
119
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
120
- const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
186
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, { enableSourcemap = false } = {}) {
187
+ const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
188
+ enableSourcemap,
189
+ enableEsmShim: false
190
+ });
191
+ const hasPostgresStore = await this.deps.checkDependencies(["@mastra/pg"]) === `ok`;
121
192
  if (Array.isArray(inputOptions.plugins)) {
122
193
  inputOptions.plugins = [
123
194
  virtual({
@@ -126,45 +197,36 @@ process.versions = process.versions || {};
126
197
  process.versions.node = '${process.versions.node}';
127
198
  `
128
199
  }),
129
- ...inputOptions.plugins
200
+ ...inputOptions.plugins,
201
+ mastraInstanceWrapper2(mastraEntryFile)
130
202
  ];
203
+ if (hasPostgresStore) {
204
+ inputOptions.plugins.push(postgresStoreInstanceChecker2());
205
+ }
131
206
  }
132
207
  return inputOptions;
133
208
  }
134
- async bundle(entryFile, outputDirectory, toolsPaths) {
135
- return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
209
+ async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
210
+ return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);
136
211
  }
137
- async deploy(outputDirectory) {
138
- const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
139
- const cpLogger = createChildProcessLogger({
140
- logger: this.logger,
141
- root: join(outputDirectory, this.outputDir)
142
- });
143
- await cpLogger({
144
- cmd,
145
- args: [],
146
- env: {
147
- CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
148
- CLOUDFLARE_ACCOUNT_ID: this.scope,
149
- ...this.env,
150
- PATH: process.env.PATH
151
- }
152
- });
212
+ async deploy() {
213
+ this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
153
214
  }
154
- async tagWorker({
155
- workerName,
156
- namespace,
157
- tags,
158
- scope
159
- }) {
160
- if (!this.cloudflare) {
161
- throw new Error("Cloudflare Deployer not initialized");
215
+ async tagWorker() {
216
+ throw new Error("tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.");
217
+ }
218
+ async lint(entryFile, outputDirectory, toolsPaths) {
219
+ await super.lint(entryFile, outputDirectory, toolsPaths);
220
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
221
+ if (hasLibsql) {
222
+ this.logger.error(
223
+ "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."
224
+ );
225
+ process.exit(1);
162
226
  }
163
- await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
164
- account_id: scope,
165
- body: tags
166
- });
167
227
  }
168
228
  };
169
229
 
170
230
  export { CloudflareDeployer };
231
+ //# sourceMappingURL=index.js.map
232
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/babel/mastra-instance-wrapper.ts","../src/plugins/mastra-instance-wrapper.ts","../src/babel/postgres-store-instance-checker.ts","../src/plugins/postgres-store-instance-checker.ts","../src/index.ts"],"names":["mastraInstanceWrapper","babel2","postgresStoreInstanceChecker","transformSync"],"mappings":";;;;;;;;AAwBO,SAAS,qBAAA,GAAmC;AACjD,EAAA,MAAM,UAAA,GAAa,QAAA;AACnB,EAAA,MAAM,SAAA,GAAY,QAAA;AAClB,EAAA,MAAM,CAAA,GAAU,KAAA,CAAA,KAAA;AAEhB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,OAAA,EAAS;AAAA,MACP,uBAAuB,IAAA,EAAM;AAC3B,QAAA,IAAI,CAAA,CAAE,qBAAA,CAAsB,IAAA,CAAK,IAAA,EAAM,WAAW,CAAA,EAAG;AACnD,UAAA,KAAA,MAAW,WAAA,IAAe,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,YAAA,EAAc;AAC5D,YAAA,IACE,CAAA,CAAE,aAAa,WAAA,EAAa,EAAA,EAAI,EAAE,IAAA,EAAM,UAAA,EAAY,CAAA,IACpD,CAAA,CAAE,eAAA,CAAgB,aAAa,IAAI,CAAA,IACnC,CAAA,CAAE,YAAA,CAAa,WAAA,CAAY,IAAA,CAAK,QAAQ,EAAE,IAAA,EAAM,SAAA,EAAW,CAAA,EAC3D;AACA,cAAA,WAAA,CAAY,OAAO,CAAA,CAAE,uBAAA,CAAwB,EAAC,EAAG,YAAY,IAAI,CAAA;AAEjE,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA;AACF,GACF;AACF;;;AC7CO,SAASA,uBAAsB,eAAA,EAAiC;AACrE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,CAAU,MAAM,EAAA,E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,QACV;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\n\n/**\n * Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.\n *\n * This plugin:\n * 1. Identifies named exports of the 'mastra' variable\n * 2. Checks if the export is a new instance of the 'Mastra' class\n * 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization\n * in the Cloudflare Workers environment\n *\n * The transformation ensures the Mastra instance is properly scoped and initialized\n * for each request in the Cloudflare Workers environment.\n *\n * @returns {PluginObj} A Babel plugin object with a visitor that performs the transformation\n *\n * @example\n * // Before transformation:\n * export const mastra = new Mastra();\n *\n * // After transformation:\n * export const mastra = () => new Mastra();\n */\nexport function mastraInstanceWrapper(): PluginObj {\n const exportName = 'mastra';\n const className = 'Mastra';\n const t = babel.types;\n\n return {\n name: 'wrap-mastra',\n visitor: {\n ExportNamedDeclaration(path) {\n if (t.isVariableDeclaration(path.node?.declaration)) {\n for (const declaration of path.node.declaration.declarations) {\n if (\n t.isIdentifier(declaration?.id, { name: exportName }) &&\n t.isNewExpression(declaration?.init) &&\n t.isIdentifier(declaration.init.callee, { name: className })\n ) {\n declaration.init = t.arrowFunctionExpression([], declaration.init);\n // there should be only one \"mastra\" export, so we can exit the loop\n break;\n }\n }\n }\n },\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';\n\nexport function mastraInstanceWrapper(mastraEntryFile: string): Plugin {\n return {\n name: 'mastra-wrapper',\n transform(code, id) {\n if (id !== mastraEntryFile) {\n return null;\n }\n\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [mastraInstanceWrapperBabel],\n });\n\n if (!result?.code) {\n throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');\n }\n\n return {\n code: result.code,\n map: result?.map,\n };\n },\n };\n}\n","import type { NodePath, PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\nimport type { NewExpression } from '@babel/types';\n\n/**\n * Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.\n *\n * This plugin:\n * 1. Scans for all `new PostgresStore()` instantiations\n * 2. Records their file locations\n * 3. Throws an error if multiple instances are found\n *\n * Cloudflare Workers should only create one PostgresStore instance to avoid connection\n * pool exhaustion and ensure proper resource management.\n *\n * @returns {PluginObj} A Babel plugin object that validates PostgresStore usage\n *\n * @example\n * // Throws error if multiple instances found:\n * const store1 = new PostgresStore();\n * const store2 = new PostgresStore(); // Error thrown here\n */\nexport function postgresStoreInstanceChecker(): PluginObj {\n const t = babel.types;\n const instances: { path: NodePath<NewExpression>; location: string }[] = [];\n\n return {\n name: 'postgresstore-instance-checker',\n visitor: {\n NewExpression(path, state) {\n if (t.isIdentifier(path.node.callee) && path.node.callee.name === 'PostgresStore') {\n const filename = state.file?.opts?.filename || 'unknown file';\n const location = path.node.loc\n ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`\n : 'unknown location';\n\n instances.push({\n path,\n location,\n });\n }\n },\n },\n post() {\n if (instances.length > 1) {\n const errorMessage = [\n `Found ${instances.length} PostgresStore instantiations:`,\n ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),\n 'Only one PostgresStore instance should be created per Cloudflare Worker.',\n ].join('\\n');\n\n const lastInstance = instances[instances.length - 1];\n throw lastInstance?.path.buildCodeFrameError(errorMessage);\n }\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { postgresStoreInstanceChecker as postgresStoreInstanceCheckerBabel } from '../babel/postgres-store-instance-checker';\n\nexport function postgresStoreInstanceChecker(): Plugin {\n return {\n name: 'postgres-store-instance-checker',\n transform(code, id) {\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [postgresStoreInstanceCheckerBabel],\n });\n\n // If Babel didn't transform anything or returned no code, pass through original source.\n if (!result || typeof result.code !== 'string') {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n","import { writeFile } from 'fs/promises';\nimport { join } from 'path';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport virtual from '@rollup/plugin-virtual';\nimport { mastraInstanceWrapper } from './plugins/mastra-instance-wrapper';\nimport { postgresStoreInstanceChecker } from './plugins/postgres-store-instance-checker';\n\ninterface CFRoute {\n pattern: string;\n zone_name: string;\n custom_domain?: boolean;\n}\n\ninterface D1DatabaseBinding {\n binding: string;\n database_name: string;\n database_id: string;\n preview_database_id?: string;\n}\n\ninterface KVNamespaceBinding {\n binding: string;\n id: string;\n}\n\nexport class CloudflareDeployer extends Deployer {\n routes?: CFRoute[] = [];\n workerNamespace?: string;\n env?: Record<string, any>;\n projectName?: string;\n d1Databases?: D1DatabaseBinding[];\n kvNamespaces?: KVNamespaceBinding[];\n\n constructor({\n env,\n projectName = 'mastra',\n routes,\n workerNamespace,\n d1Databases,\n kvNamespaces,\n }: {\n env?: Record<string, any>;\n projectName?: string;\n routes?: CFRoute[];\n workerNamespace?: string;\n d1Databases?: D1DatabaseBinding[];\n kvNamespaces?: KVNamespaceBinding[];\n }) {\n super({ name: 'CLOUDFLARE' });\n\n this.projectName = projectName;\n this.routes = routes;\n this.workerNamespace = workerNamespace;\n\n if (env) {\n this.env = env;\n }\n\n if (d1Databases) this.d1Databases = d1Databases;\n if (kvNamespaces) this.kvNamespaces = kvNamespaces;\n }\n\n async writeFiles(outputDirectory: string): Promise<void> {\n const env = await this.loadEnvVars();\n const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);\n\n const cfWorkerName = this.projectName;\n\n const wranglerConfig: Record<string, any> = {\n name: cfWorkerName,\n main: './index.mjs',\n compatibility_date: '2025-04-01',\n compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],\n observability: {\n logs: {\n enabled: true,\n },\n },\n vars: envsAsObject,\n };\n\n if (!this.workerNamespace && this.routes) {\n wranglerConfig.routes = this.routes;\n }\n\n if (this.d1Databases?.length) {\n wranglerConfig.d1_databases = this.d1Databases;\n }\n if (this.kvNamespaces?.length) {\n wranglerConfig.kv_namespaces = this.kvNamespaces;\n }\n await writeFile(join(outputDirectory, this.outputDir, 'wrangler.json'), JSON.stringify(wranglerConfig));\n }\n\n private getEntry(): string {\n return `\n import '#polyfills';\n import { scoreTracesWorkflow } from '@mastra/core/scores/scoreTraces';\n\n export default {\n fetch: async (request, env, context) => {\n const { mastra } = await import('#mastra');\n const { tools } = await import('#tools');\n const {createHonoServer, getToolExports} = await import('#server');\n const _mastra = mastra();\n\n if (_mastra.getStorage()) {\n _mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });\n return app.fetch(request, env, context);\n }\n }\n`;\n }\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n await this.writeFiles(outputDirectory);\n }\n\n async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n { enableSourcemap = false }: { enableSourcemap?: boolean } = {},\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n enableSourcemap,\n enableEsmShim: false,\n });\n\n const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins = [\n virtual({\n '#polyfills': `\nprocess.versions = process.versions || {};\nprocess.versions.node = '${process.versions.node}';\n `,\n }),\n ...inputOptions.plugins,\n mastraInstanceWrapper(mastraEntryFile),\n ];\n\n if (hasPostgresStore) {\n inputOptions.plugins.push(postgresStoreInstanceChecker());\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.');\n }\n\n async tagWorker(): Promise<void> {\n throw new Error('tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n '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.',\n );\n process.exit(1);\n }\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export const mastra: Mastra<{
2
+ weatherAgent: any;
3
+ }, Record<string, import("@mastra/core/workflows").Workflow<any, any, any, any, any, any, any>>, Record<string, import("@mastra/core/vector").MastraVector<import("@mastra/core/vector/filter").VectorFilter>>, Record<string, import("@mastra/core/tts").MastraTTS>, import("@mastra/core/logger").ConsoleLogger, Record<string, import("@mastra/core/mcp").MCPServerBase>, Record<string, import("@mastra/core/scores").MastraScorer<any, any, any, any>>>;
4
+ import { Mastra } from '@mastra/core/mastra';
5
+ //# sourceMappingURL=basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../../src/plugins/__fixtures__/basic.js"],"names":[],"mappings":"AAOA;;6bAuBG;uBA7BoB,qBAAqB"}
@@ -0,0 +1,3 @@
1
+ export const mastra: Mastra<Record<string, import("@mastra/core/agent").Agent<any, import("@mastra/core/agent").ToolsInput>>, Record<string, import("@mastra/core/workflows").Workflow<any, any, any, any, any, any, any>>, Record<string, import("@mastra/core/vector").MastraVector<import("@mastra/core/vector/filter").VectorFilter>>, Record<string, import("@mastra/core/tts").MastraTTS>, import("@mastra/core/logger").IMastraLogger, Record<string, import("@mastra/core/mcp").MCPServerBase>, Record<string, import("@mastra/core/scores").MastraScorer<any, any, any, any>>>;
2
+ import { Mastra } from '@mastra/core/mastra';
3
+ //# sourceMappingURL=empty-mastra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empty-mastra.d.ts","sourceRoot":"","sources":["../../../src/plugins/__fixtures__/empty-mastra.js"],"names":[],"mappings":"AACA,wjBAAmC;uBADZ,qBAAqB"}
@@ -0,0 +1,6 @@
1
+ export const storage: any;
2
+ export const mastra: Mastra<{
3
+ weatherAgent: any;
4
+ }, Record<string, import("@mastra/core/workflows").Workflow<any, any, any, any, any, any, any>>, Record<string, import("@mastra/core/vector").MastraVector<import("@mastra/core/vector/filter").VectorFilter>>, Record<string, import("@mastra/core/tts").MastraTTS>, import("@mastra/core/logger").ConsoleLogger, Record<string, import("@mastra/core/mcp").MCPServerBase>, Record<string, import("@mastra/core/scores").MastraScorer<any, any, any, any>>>;
5
+ import { Mastra } from '@mastra/core/mastra';
6
+ //# sourceMappingURL=multiple-postgres-stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiple-postgres-stores.d.ts","sourceRoot":"","sources":["../../../src/plugins/__fixtures__/multiple-postgres-stores.js"],"names":[],"mappings":"AAOA,0BAEG;AAEH;;6bAuBG;uBAjCoB,qBAAqB"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'rollup';
2
+ export declare function mastraInstanceWrapper(mastraEntryFile: string): Plugin;
3
+ //# sourceMappingURL=mastra-instance-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mastra-instance-wrapper.d.ts","sourceRoot":"","sources":["../../src/plugins/mastra-instance-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAyBrE"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'rollup';
2
+ export declare function postgresStoreInstanceChecker(): Plugin;
3
+ //# sourceMappingURL=postgres-store-instance-checker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-store-instance-checker.d.ts","sourceRoot":"","sources":["../../src/plugins/postgres-store-instance-checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,wBAAgB,4BAA4B,IAAI,MAAM,CAsBrD"}
@@ -87,3 +87,5 @@ var CloudflareSecretsManager = class {
87
87
  };
88
88
 
89
89
  exports.CloudflareSecretsManager = CloudflareSecretsManager;
90
+ //# sourceMappingURL=index.cjs.map
91
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/secrets-manager/index.ts"],"names":[],"mappings":";;;AAAO,IAAM,2BAAN,MAA+B;AAAA,EACpC,SAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EAEA,WAAA,CAAY,EAAE,SAAA,EAAW,QAAA,EAAS,EAA4C;AAC5E,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAChB,IAAA,IAAA,CAAK,OAAA,GAAU,sCAAA;AAAA,EACjB;AAAA,EAEA,MAAM,YAAA,CAAa;AAAA,IACjB,QAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF,EAIG;AACD,IAAA,MAAM,GAAA,GAAM,GAAG,IAAA,CAAK,OAAO,aAAa,IAAA,CAAK,SAAS,oBAAoB,QAAQ,CAAA,QAAA,CAAA;AAElF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,QAChC,MAAA,EAAQ,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A,EACF;AACF","file":"index.cjs","sourcesContent":["export class CloudflareSecretsManager {\n accountId: string;\n apiToken: string;\n baseUrl: string;\n\n constructor({ accountId, apiToken }: { accountId: string; apiToken: string }) {\n this.accountId = accountId;\n this.apiToken = apiToken;\n this.baseUrl = 'https://api.cloudflare.com/client/v4';\n }\n\n async createSecret({\n workerId,\n secretName,\n secretValue,\n }: {\n workerId: string;\n secretName: string;\n secretValue: string;\n }) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;\n\n try {\n const response = await fetch(url, {\n method: 'PUT',\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: secretName,\n text: secretValue,\n }),\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to create secret:', error);\n throw error;\n }\n }\n\n async createProjectSecrets({\n workerId,\n customerId,\n envVars,\n }: {\n workerId: string;\n customerId: string;\n envVars: Record<string, string>;\n }) {\n const secretName = `PROJECT_${customerId.toUpperCase()}`;\n const secretValue = JSON.stringify(envVars);\n\n return this.createSecret({ workerId, secretName, secretValue });\n }\n\n async deleteSecret({ workerId, secretName }: { workerId: string; secretName: string }) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;\n\n try {\n const response = await fetch(url, {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n },\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to delete secret:', error);\n throw error;\n }\n }\n\n async listSecrets(workerId: string) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;\n\n try {\n const response = await fetch(url, {\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n },\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to list secrets:', error);\n throw error;\n }\n }\n}\n"]}
@@ -1 +1,25 @@
1
- export { CloudflareSecretsManager } from '../_tsup-dts-rollup.js';
1
+ export declare class CloudflareSecretsManager {
2
+ accountId: string;
3
+ apiToken: string;
4
+ baseUrl: string;
5
+ constructor({ accountId, apiToken }: {
6
+ accountId: string;
7
+ apiToken: string;
8
+ });
9
+ createSecret({ workerId, secretName, secretValue, }: {
10
+ workerId: string;
11
+ secretName: string;
12
+ secretValue: string;
13
+ }): Promise<any>;
14
+ createProjectSecrets({ workerId, customerId, envVars, }: {
15
+ workerId: string;
16
+ customerId: string;
17
+ envVars: Record<string, string>;
18
+ }): Promise<any>;
19
+ deleteSecret({ workerId, secretName }: {
20
+ workerId: string;
21
+ secretName: string;
22
+ }): Promise<any>;
23
+ listSecrets(workerId: string): Promise<any>;
24
+ }
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/secrets-manager/index.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAwB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;gBAEJ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;IAMtE,YAAY,CAAC,EACjB,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB;IA6BK,oBAAoB,CAAC,EACzB,QAAQ,EACR,UAAU,EACV,OAAO,GACR,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC;IAOK,YAAY,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAwB/E,WAAW,CAAC,QAAQ,EAAE,MAAM;CAsBnC"}
@@ -85,3 +85,5 @@ var CloudflareSecretsManager = class {
85
85
  };
86
86
 
87
87
  export { CloudflareSecretsManager };
88
+ //# sourceMappingURL=index.js.map
89
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/secrets-manager/index.ts"],"names":[],"mappings":";AAAO,IAAM,2BAAN,MAA+B;AAAA,EACpC,SAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EAEA,WAAA,CAAY,EAAE,SAAA,EAAW,QAAA,EAAS,EAA4C;AAC5E,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAChB,IAAA,IAAA,CAAK,OAAA,GAAU,sCAAA;AAAA,EACjB;AAAA,EAEA,MAAM,YAAA,CAAa;AAAA,IACjB,QAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF,EAIG;AACD,IAAA,MAAM,GAAA,GAAM,GAAG,IAAA,CAAK,OAAO,aAAa,IAAA,CAAK,SAAS,oBAAoB,QAAQ,CAAA,QAAA,CAAA;AAElF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,QAChC,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,QAAQ,CAAA,CAAA;AAAA,UACtC,cAAA,EAAgB;AAAA,SAClB;AAAA,QACA,IAAA,EAAM,KAA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;AAED,MAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AAElC,MAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACjB,QAAA,MAAM,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,CAAC,EAAE,OAAO,CAAA;AAAA,MACxC;AAEA,MAAA,OAAO,IAAA,CAAK,MAAA;AAAA,IACd,SAAS,KAAA,EAAO;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,4BAA4B,KAAK,CAAA;AAC/C,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAM,YAAY,QAAA,EAAkB;AAClC,IAAA,MAAM,GAAA,GAAM,GAAG,IAAA,CAAK,OAAO,aAAa,IAAA,CAAK,SAAS,oBAAoB,QAAQ,CAAA,QAAA,CAAA;AAElF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,QAChC,OAAA,EAAS;AAAA,UACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,QAAQ,CAAA;AAAA;AACxC,OACD,CAAA;AAED,MAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AAElC,MAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACjB,QAAA,MAAM,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,CAAC,EAAE,OAAO,CAAA;AAAA,MACxC;AAEA,MAAA,OAAO,IAAA,CAAK,MAAA;AAAA,IACd,SAAS,KAAA,EAAO;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,2BAA2B,KAAK,CAAA;AAC9C,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,EACF;AACF","file":"index.js","sourcesContent":["export class CloudflareSecretsManager {\n accountId: string;\n apiToken: string;\n baseUrl: string;\n\n constructor({ accountId, apiToken }: { accountId: string; apiToken: string }) {\n this.accountId = accountId;\n this.apiToken = apiToken;\n this.baseUrl = 'https://api.cloudflare.com/client/v4';\n }\n\n async createSecret({\n workerId,\n secretName,\n secretValue,\n }: {\n workerId: string;\n secretName: string;\n secretValue: string;\n }) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;\n\n try {\n const response = await fetch(url, {\n method: 'PUT',\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: secretName,\n text: secretValue,\n }),\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to create secret:', error);\n throw error;\n }\n }\n\n async createProjectSecrets({\n workerId,\n customerId,\n envVars,\n }: {\n workerId: string;\n customerId: string;\n envVars: Record<string, string>;\n }) {\n const secretName = `PROJECT_${customerId.toUpperCase()}`;\n const secretValue = JSON.stringify(envVars);\n\n return this.createSecret({ workerId, secretName, secretValue });\n }\n\n async deleteSecret({ workerId, secretName }: { workerId: string; secretName: string }) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;\n\n try {\n const response = await fetch(url, {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n },\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to delete secret:', error);\n throw error;\n }\n }\n\n async listSecrets(workerId: string) {\n const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;\n\n try {\n const response = await fetch(url, {\n headers: {\n Authorization: `Bearer ${this.apiToken}`,\n },\n });\n\n const data = (await response.json()) as { success: boolean; result: any; errors: any[] };\n\n if (!data.success) {\n throw new Error(data.errors[0].message);\n }\n\n return data.result;\n } catch (error) {\n console.error('Failed to list secrets:', error);\n throw error;\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.0-remove-cloud-span-transform-20250425214156",
3
+ "version": "0.0.0-remove-unused-model-providers-api-20251030210744",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist"
7
+ "dist",
8
+ "CHANGELOG.md"
8
9
  ],
9
10
  "main": "dist/index.js",
10
11
  "types": "dist/index.d.ts",
@@ -15,7 +16,7 @@
15
16
  "default": "./dist/index.js"
16
17
  },
17
18
  "require": {
18
- "types": "./dist/index.d.cts",
19
+ "types": "./dist/index.d.ts",
19
20
  "default": "./dist/index.cjs"
20
21
  }
21
22
  },
@@ -25,7 +26,7 @@
25
26
  "default": "./dist/secrets-manager/index.js"
26
27
  },
27
28
  "require": {
28
- "types": "./dist/secrets-manager/index.d.cts",
29
+ "types": "./dist/secrets-manager/index.d.ts",
29
30
  "default": "./dist/secrets-manager/index.cjs"
30
31
  }
31
32
  },
@@ -33,29 +34,45 @@
33
34
  },
34
35
  "keywords": [],
35
36
  "author": "",
36
- "license": "Elastic-2.0",
37
+ "license": "Apache-2.0",
37
38
  "dependencies": {
38
- "@babel/core": "^7.26.10",
39
- "@rollup/plugin-virtual": "^3.0.2",
40
- "cloudflare": "^4.1.0",
41
- "rollup": "^4.35.0",
42
- "wrangler": "^4.4.0",
43
- "zod": "^3.24.2",
44
- "@mastra/deployer": "0.0.0-remove-cloud-span-transform-20250425214156",
45
- "@mastra/core": "0.0.0-remove-cloud-span-transform-20250425214156"
39
+ "@babel/core": "^7.28.5",
40
+ "@rollup/plugin-virtual": "3.0.2",
41
+ "cloudflare": "^4.5.0",
42
+ "rollup": "~4.50.2",
43
+ "rollup-plugin-esbuild": "^6.2.1",
44
+ "@mastra/deployer": "0.0.0-remove-unused-model-providers-api-20251030210744"
46
45
  },
47
46
  "devDependencies": {
48
- "@microsoft/api-extractor": "^7.52.1",
49
- "@types/node": "^20.17.27",
50
- "eslint": "^9.23.0",
51
- "tsup": "^8.4.0",
52
- "typescript": "^5.8.2",
53
- "vitest": "^3.0.9",
54
- "@internal/lint": "0.0.2"
47
+ "@babel/types": "^7.28.4",
48
+ "@microsoft/api-extractor": "^7.52.8",
49
+ "@types/babel__core": "^7.20.5",
50
+ "@types/node": "^20.19.0",
51
+ "eslint": "^9.37.0",
52
+ "tsup": "^8.5.0",
53
+ "typescript": "^5.8.3",
54
+ "vitest": "^3.2.4",
55
+ "zod": "^3.25.76",
56
+ "@mastra/core": "0.0.0-remove-unused-model-providers-api-20251030210744",
57
+ "@internal/types-builder": "0.0.0-remove-unused-model-providers-api-20251030210744",
58
+ "@internal/lint": "0.0.0-remove-unused-model-providers-api-20251030210744"
59
+ },
60
+ "homepage": "https://mastra.ai",
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "git+https://github.com/mastra-ai/mastra.git",
64
+ "directory": "deployers/cloudflare"
65
+ },
66
+ "bugs": {
67
+ "url": "https://github.com/mastra-ai/mastra/issues"
68
+ },
69
+ "peerDependencies": {
70
+ "zod": "^3.25.0 || ^4.0.0",
71
+ "@mastra/core": "0.0.0-remove-unused-model-providers-api-20251030210744"
55
72
  },
56
73
  "scripts": {
57
- "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
58
- "build:watch": "pnpm build --watch",
74
+ "build": "tsup --silent --config tsup.config.ts",
75
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
59
76
  "test": "vitest run",
60
77
  "lint": "eslint ."
61
78
  }
@@ -1,68 +0,0 @@
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
- }
42
-
43
- export declare class CloudflareSecretsManager {
44
- accountId: string;
45
- apiToken: string;
46
- baseUrl: string;
47
- constructor({ accountId, apiToken }: {
48
- accountId: string;
49
- apiToken: string;
50
- });
51
- createSecret({ workerId, secretName, secretValue, }: {
52
- workerId: string;
53
- secretName: string;
54
- secretValue: string;
55
- }): Promise<any>;
56
- createProjectSecrets({ workerId, customerId, envVars, }: {
57
- workerId: string;
58
- customerId: string;
59
- envVars: Record<string, string>;
60
- }): Promise<any>;
61
- deleteSecret({ workerId, secretName }: {
62
- workerId: string;
63
- secretName: string;
64
- }): Promise<any>;
65
- listSecrets(workerId: string): Promise<any>;
66
- }
67
-
68
- export { }