@mastra/deployer-cloudflare 0.0.1-alpha.0
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 +9 -0
- package/LICENSE +44 -0
- 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 +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/secrets-manager/index.d.ts +25 -0
- package/dist/secrets-manager/index.d.ts.map +1 -0
- package/package.json +49 -0
- package/src/index.ts +83 -0
- package/src/secrets-manager/index.test.ts +230 -0
- package/src/secrets-manager/index.ts +110 -0
- package/tsconfig.json +10 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { MastraDeployer } from '@mastra/core';
|
|
2
|
+
import * as child_process from 'child_process';
|
|
3
|
+
import { writeFileSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
7
|
+
try {
|
|
8
|
+
var i = n[a](c),
|
|
9
|
+
u = i.value;
|
|
10
|
+
} catch (n) {
|
|
11
|
+
return void e(n);
|
|
12
|
+
}
|
|
13
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(n) {
|
|
16
|
+
return function () {
|
|
17
|
+
var t = this,
|
|
18
|
+
e = arguments;
|
|
19
|
+
return new Promise(function (r, o) {
|
|
20
|
+
var a = n.apply(t, e);
|
|
21
|
+
function _next(n) {
|
|
22
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
23
|
+
}
|
|
24
|
+
function _throw(n) {
|
|
25
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
26
|
+
}
|
|
27
|
+
_next(void 0);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function _extends() {
|
|
32
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
33
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
34
|
+
var t = arguments[e];
|
|
35
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
36
|
+
}
|
|
37
|
+
return n;
|
|
38
|
+
}, _extends.apply(null, arguments);
|
|
39
|
+
}
|
|
40
|
+
function _inheritsLoose(t, o) {
|
|
41
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
42
|
+
}
|
|
43
|
+
function _regeneratorRuntime() {
|
|
44
|
+
_regeneratorRuntime = function () {
|
|
45
|
+
return e;
|
|
46
|
+
};
|
|
47
|
+
var t,
|
|
48
|
+
e = {},
|
|
49
|
+
r = Object.prototype,
|
|
50
|
+
n = r.hasOwnProperty,
|
|
51
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
52
|
+
t[e] = r.value;
|
|
53
|
+
},
|
|
54
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
55
|
+
a = i.iterator || "@@iterator",
|
|
56
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
57
|
+
u = i.toStringTag || "@@toStringTag";
|
|
58
|
+
function define(t, e, r) {
|
|
59
|
+
return Object.defineProperty(t, e, {
|
|
60
|
+
value: r,
|
|
61
|
+
enumerable: !0,
|
|
62
|
+
configurable: !0,
|
|
63
|
+
writable: !0
|
|
64
|
+
}), t[e];
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
define({}, "");
|
|
68
|
+
} catch (t) {
|
|
69
|
+
define = function (t, e, r) {
|
|
70
|
+
return t[e] = r;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function wrap(t, e, r, n) {
|
|
74
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
75
|
+
a = Object.create(i.prototype),
|
|
76
|
+
c = new Context(n || []);
|
|
77
|
+
return o(a, "_invoke", {
|
|
78
|
+
value: makeInvokeMethod(t, r, c)
|
|
79
|
+
}), a;
|
|
80
|
+
}
|
|
81
|
+
function tryCatch(t, e, r) {
|
|
82
|
+
try {
|
|
83
|
+
return {
|
|
84
|
+
type: "normal",
|
|
85
|
+
arg: t.call(e, r)
|
|
86
|
+
};
|
|
87
|
+
} catch (t) {
|
|
88
|
+
return {
|
|
89
|
+
type: "throw",
|
|
90
|
+
arg: t
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
e.wrap = wrap;
|
|
95
|
+
var h = "suspendedStart",
|
|
96
|
+
l = "suspendedYield",
|
|
97
|
+
f = "executing",
|
|
98
|
+
s = "completed",
|
|
99
|
+
y = {};
|
|
100
|
+
function Generator() {}
|
|
101
|
+
function GeneratorFunction() {}
|
|
102
|
+
function GeneratorFunctionPrototype() {}
|
|
103
|
+
var p = {};
|
|
104
|
+
define(p, a, function () {
|
|
105
|
+
return this;
|
|
106
|
+
});
|
|
107
|
+
var d = Object.getPrototypeOf,
|
|
108
|
+
v = d && d(d(values([])));
|
|
109
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
110
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
111
|
+
function defineIteratorMethods(t) {
|
|
112
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
113
|
+
define(t, e, function (t) {
|
|
114
|
+
return this._invoke(e, t);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function AsyncIterator(t, e) {
|
|
119
|
+
function invoke(r, o, i, a) {
|
|
120
|
+
var c = tryCatch(t[r], t, o);
|
|
121
|
+
if ("throw" !== c.type) {
|
|
122
|
+
var u = c.arg,
|
|
123
|
+
h = u.value;
|
|
124
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
125
|
+
invoke("next", t, i, a);
|
|
126
|
+
}, function (t) {
|
|
127
|
+
invoke("throw", t, i, a);
|
|
128
|
+
}) : e.resolve(h).then(function (t) {
|
|
129
|
+
u.value = t, i(u);
|
|
130
|
+
}, function (t) {
|
|
131
|
+
return invoke("throw", t, i, a);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
a(c.arg);
|
|
135
|
+
}
|
|
136
|
+
var r;
|
|
137
|
+
o(this, "_invoke", {
|
|
138
|
+
value: function (t, n) {
|
|
139
|
+
function callInvokeWithMethodAndArg() {
|
|
140
|
+
return new e(function (e, r) {
|
|
141
|
+
invoke(t, n, e, r);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function makeInvokeMethod(e, r, n) {
|
|
149
|
+
var o = h;
|
|
150
|
+
return function (i, a) {
|
|
151
|
+
if (o === f) throw Error("Generator is already running");
|
|
152
|
+
if (o === s) {
|
|
153
|
+
if ("throw" === i) throw a;
|
|
154
|
+
return {
|
|
155
|
+
value: t,
|
|
156
|
+
done: !0
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
for (n.method = i, n.arg = a;;) {
|
|
160
|
+
var c = n.delegate;
|
|
161
|
+
if (c) {
|
|
162
|
+
var u = maybeInvokeDelegate(c, n);
|
|
163
|
+
if (u) {
|
|
164
|
+
if (u === y) continue;
|
|
165
|
+
return u;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
169
|
+
if (o === h) throw o = s, n.arg;
|
|
170
|
+
n.dispatchException(n.arg);
|
|
171
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
172
|
+
o = f;
|
|
173
|
+
var p = tryCatch(e, r, n);
|
|
174
|
+
if ("normal" === p.type) {
|
|
175
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
176
|
+
return {
|
|
177
|
+
value: p.arg,
|
|
178
|
+
done: n.done
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function maybeInvokeDelegate(e, r) {
|
|
186
|
+
var n = r.method,
|
|
187
|
+
o = e.iterator[n];
|
|
188
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
189
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
190
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
191
|
+
var a = i.arg;
|
|
192
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
193
|
+
}
|
|
194
|
+
function pushTryEntry(t) {
|
|
195
|
+
var e = {
|
|
196
|
+
tryLoc: t[0]
|
|
197
|
+
};
|
|
198
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
199
|
+
}
|
|
200
|
+
function resetTryEntry(t) {
|
|
201
|
+
var e = t.completion || {};
|
|
202
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
203
|
+
}
|
|
204
|
+
function Context(t) {
|
|
205
|
+
this.tryEntries = [{
|
|
206
|
+
tryLoc: "root"
|
|
207
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
208
|
+
}
|
|
209
|
+
function values(e) {
|
|
210
|
+
if (e || "" === e) {
|
|
211
|
+
var r = e[a];
|
|
212
|
+
if (r) return r.call(e);
|
|
213
|
+
if ("function" == typeof e.next) return e;
|
|
214
|
+
if (!isNaN(e.length)) {
|
|
215
|
+
var o = -1,
|
|
216
|
+
i = function next() {
|
|
217
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
218
|
+
return next.value = t, next.done = !0, next;
|
|
219
|
+
};
|
|
220
|
+
return i.next = i;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
224
|
+
}
|
|
225
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
226
|
+
value: GeneratorFunctionPrototype,
|
|
227
|
+
configurable: !0
|
|
228
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
229
|
+
value: GeneratorFunction,
|
|
230
|
+
configurable: !0
|
|
231
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
232
|
+
var e = "function" == typeof t && t.constructor;
|
|
233
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
234
|
+
}, e.mark = function (t) {
|
|
235
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
236
|
+
}, e.awrap = function (t) {
|
|
237
|
+
return {
|
|
238
|
+
__await: t
|
|
239
|
+
};
|
|
240
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
241
|
+
return this;
|
|
242
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
243
|
+
void 0 === i && (i = Promise);
|
|
244
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
245
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
246
|
+
return t.done ? t.value : a.next();
|
|
247
|
+
});
|
|
248
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
249
|
+
return this;
|
|
250
|
+
}), define(g, "toString", function () {
|
|
251
|
+
return "[object Generator]";
|
|
252
|
+
}), e.keys = function (t) {
|
|
253
|
+
var e = Object(t),
|
|
254
|
+
r = [];
|
|
255
|
+
for (var n in e) r.push(n);
|
|
256
|
+
return r.reverse(), function next() {
|
|
257
|
+
for (; r.length;) {
|
|
258
|
+
var t = r.pop();
|
|
259
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
260
|
+
}
|
|
261
|
+
return next.done = !0, next;
|
|
262
|
+
};
|
|
263
|
+
}, e.values = values, Context.prototype = {
|
|
264
|
+
constructor: Context,
|
|
265
|
+
reset: function (e) {
|
|
266
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
267
|
+
},
|
|
268
|
+
stop: function () {
|
|
269
|
+
this.done = !0;
|
|
270
|
+
var t = this.tryEntries[0].completion;
|
|
271
|
+
if ("throw" === t.type) throw t.arg;
|
|
272
|
+
return this.rval;
|
|
273
|
+
},
|
|
274
|
+
dispatchException: function (e) {
|
|
275
|
+
if (this.done) throw e;
|
|
276
|
+
var r = this;
|
|
277
|
+
function handle(n, o) {
|
|
278
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
279
|
+
}
|
|
280
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
281
|
+
var i = this.tryEntries[o],
|
|
282
|
+
a = i.completion;
|
|
283
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
284
|
+
if (i.tryLoc <= this.prev) {
|
|
285
|
+
var c = n.call(i, "catchLoc"),
|
|
286
|
+
u = n.call(i, "finallyLoc");
|
|
287
|
+
if (c && u) {
|
|
288
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
289
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
290
|
+
} else if (c) {
|
|
291
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
292
|
+
} else {
|
|
293
|
+
if (!u) throw Error("try statement without catch or finally");
|
|
294
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
abrupt: function (t, e) {
|
|
300
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
301
|
+
var o = this.tryEntries[r];
|
|
302
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
303
|
+
var i = o;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
308
|
+
var a = i ? i.completion : {};
|
|
309
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
310
|
+
},
|
|
311
|
+
complete: function (t, e) {
|
|
312
|
+
if ("throw" === t.type) throw t.arg;
|
|
313
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
314
|
+
},
|
|
315
|
+
finish: function (t) {
|
|
316
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
317
|
+
var r = this.tryEntries[e];
|
|
318
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
catch: function (t) {
|
|
322
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
323
|
+
var r = this.tryEntries[e];
|
|
324
|
+
if (r.tryLoc === t) {
|
|
325
|
+
var n = r.completion;
|
|
326
|
+
if ("throw" === n.type) {
|
|
327
|
+
var o = n.arg;
|
|
328
|
+
resetTryEntry(r);
|
|
329
|
+
}
|
|
330
|
+
return o;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
throw Error("illegal catch attempt");
|
|
334
|
+
},
|
|
335
|
+
delegateYield: function (e, r, n) {
|
|
336
|
+
return this.delegate = {
|
|
337
|
+
iterator: values(e),
|
|
338
|
+
resultName: r,
|
|
339
|
+
nextLoc: n
|
|
340
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
341
|
+
}
|
|
342
|
+
}, e;
|
|
343
|
+
}
|
|
344
|
+
function _setPrototypeOf(t, e) {
|
|
345
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
346
|
+
return t.__proto__ = e, t;
|
|
347
|
+
}, _setPrototypeOf(t, e);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
var CloudflareDeployer = /*#__PURE__*/function (_MastraDeployer) {
|
|
351
|
+
function CloudflareDeployer(_ref) {
|
|
352
|
+
var _this;
|
|
353
|
+
var scope = _ref.scope,
|
|
354
|
+
env = _ref.env,
|
|
355
|
+
projectName = _ref.projectName,
|
|
356
|
+
routes = _ref.routes;
|
|
357
|
+
_this = _MastraDeployer.call(this, {
|
|
358
|
+
scope: scope,
|
|
359
|
+
env: env,
|
|
360
|
+
projectName: projectName
|
|
361
|
+
}) || this;
|
|
362
|
+
_this.routes = [];
|
|
363
|
+
_this.routes = routes;
|
|
364
|
+
return _this;
|
|
365
|
+
}
|
|
366
|
+
_inheritsLoose(CloudflareDeployer, _MastraDeployer);
|
|
367
|
+
var _proto = CloudflareDeployer.prototype;
|
|
368
|
+
_proto.writeFiles = function writeFiles(_ref2) {
|
|
369
|
+
var dir = _ref2.dir;
|
|
370
|
+
this.loadEnvVars();
|
|
371
|
+
this.writeIndex({
|
|
372
|
+
dir: dir
|
|
373
|
+
});
|
|
374
|
+
var cfWorkerName = this.projectName || 'mastra';
|
|
375
|
+
writeFileSync(join(dir, 'wrangler.json'), JSON.stringify({
|
|
376
|
+
name: cfWorkerName,
|
|
377
|
+
main: 'index.mjs',
|
|
378
|
+
compatibility_date: '2024-12-02',
|
|
379
|
+
compatibility_flags: ['nodejs_compat'],
|
|
380
|
+
build: {
|
|
381
|
+
command: 'npm install'
|
|
382
|
+
},
|
|
383
|
+
observability: {
|
|
384
|
+
logs: {
|
|
385
|
+
enabled: true
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
routes: this.routes,
|
|
389
|
+
vars: this.env
|
|
390
|
+
}));
|
|
391
|
+
};
|
|
392
|
+
_proto.writeIndex = function writeIndex(_ref3) {
|
|
393
|
+
var dir = _ref3.dir;
|
|
394
|
+
writeFileSync(join(dir, './index.mjs'), "\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n ");
|
|
395
|
+
};
|
|
396
|
+
_proto.deploy = /*#__PURE__*/function () {
|
|
397
|
+
var _deploy = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref4) {
|
|
398
|
+
var dir, token;
|
|
399
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
400
|
+
while (1) switch (_context.prev = _context.next) {
|
|
401
|
+
case 0:
|
|
402
|
+
dir = _ref4.dir, token = _ref4.token;
|
|
403
|
+
child_process.execSync("npm exec wrangler deploy", {
|
|
404
|
+
cwd: dir,
|
|
405
|
+
stdio: 'inherit',
|
|
406
|
+
env: _extends({
|
|
407
|
+
CLOUDFLARE_API_TOKEN: token,
|
|
408
|
+
CLOUDFLARE_ACCOUNT_ID: this.scope
|
|
409
|
+
}, this.env, {
|
|
410
|
+
PATH: process.env.PATH
|
|
411
|
+
})
|
|
412
|
+
});
|
|
413
|
+
case 2:
|
|
414
|
+
case "end":
|
|
415
|
+
return _context.stop();
|
|
416
|
+
}
|
|
417
|
+
}, _callee, this);
|
|
418
|
+
}));
|
|
419
|
+
function deploy(_x) {
|
|
420
|
+
return _deploy.apply(this, arguments);
|
|
421
|
+
}
|
|
422
|
+
return deploy;
|
|
423
|
+
}();
|
|
424
|
+
return CloudflareDeployer;
|
|
425
|
+
}(MastraDeployer);
|
|
426
|
+
|
|
427
|
+
export { CloudflareDeployer };
|
|
428
|
+
//# sourceMappingURL=deployer-cloudflare.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployer-cloudflare.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { MastraDeployer } from '@mastra/core';\nimport * as child_process from 'child_process';\nimport { writeFileSync } from 'fs';\nimport { join } from 'path';\n\ninterface CFRoute {\n pattern: string;\n zone_name: string;\n}\n\nexport class CloudflareDeployer extends MastraDeployer {\n routes?: CFRoute[] = [];\n constructor({\n scope,\n env,\n projectName,\n routes,\n }: {\n env?: Record<string, any>;\n scope: string;\n projectName: string;\n routes?: CFRoute[];\n }) {\n super({ scope, env, projectName });\n\n this.routes = routes;\n }\n\n writeFiles({ dir }: { dir: string }): void {\n this.loadEnvVars();\n\n this.writeIndex({ dir });\n\n const cfWorkerName = this.projectName || 'mastra';\n\n writeFileSync(\n join(dir, 'wrangler.json'),\n JSON.stringify({\n name: cfWorkerName,\n main: 'index.mjs',\n compatibility_date: '2024-12-02',\n compatibility_flags: ['nodejs_compat'],\n build: {\n command: 'npm install',\n },\n observability: {\n logs: {\n enabled: true,\n },\n },\n routes: this.routes,\n vars: this.env,\n }),\n );\n }\n\n writeIndex({ dir }: { dir: string }): void {\n writeFileSync(\n join(dir, './index.mjs'),\n `\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n `,\n );\n }\n\n async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {\n child_process.execSync(`npm exec wrangler deploy`, {\n cwd: dir,\n stdio: 'inherit',\n env: {\n CLOUDFLARE_API_TOKEN: token,\n CLOUDFLARE_ACCOUNT_ID: this.scope,\n ...this.env,\n PATH: process.env.PATH,\n },\n });\n }\n}\n"],"names":["CloudflareDeployer","_MastraDeployer","_ref","_this","scope","env","projectName","routes","call","_inheritsLoose","_proto","prototype","writeFiles","_ref2","dir","loadEnvVars","writeIndex","cfWorkerName","writeFileSync","join","JSON","stringify","name","main","compatibility_date","compatibility_flags","build","command","observability","logs","enabled","vars","_ref3","deploy","_deploy","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref4","token","wrap","_callee$","_context","prev","next","child_process","execSync","cwd","stdio","_extends","CLOUDFLARE_API_TOKEN","CLOUDFLARE_ACCOUNT_ID","PATH","process","stop","_x","apply","arguments","MastraDeployer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUaA,IAAAA,kBAAmB,0BAAAC,eAAA,EAAA;EAE9B,SAAAD,kBAAAA,CAAAE,IAAA,EAUC;AAAA,IAAA,IAAAC,KAAA,CAAA;AAAA,IAAA,IATCC,KAAK,GAAAF,IAAA,CAALE,KAAK;MACLC,GAAG,GAAAH,IAAA,CAAHG,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AA,CAAA;AAAA,UAAA,KAAA,KAAA;YAAA,OAAAV,QAAA,CAAAY,IAAA,EAAA,CAAA;AAAA,SAAA;AAAA,OAAA,EAAAjB,OAAA,EAAA,IAAA,CAAA,CAAA;KACJ,CAAA,CAAA,CAAA;IAAA,SAXKL,MAAMA,CAAAuB,EAAA,EAAA;AAAA,MAAA,OAAAtB,OAAA,CAAAuB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAANzB,MAAM,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAAjC,kBAAA,CAAA;AAAA,CAAA,CA5D0B2D,cAAc;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MastraDeployer } from '@mastra/core';
|
|
2
|
+
interface CFRoute {
|
|
3
|
+
pattern: string;
|
|
4
|
+
zone_name: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class CloudflareDeployer extends MastraDeployer {
|
|
7
|
+
routes?: CFRoute[];
|
|
8
|
+
constructor({ scope, env, projectName, routes, }: {
|
|
9
|
+
env?: Record<string, any>;
|
|
10
|
+
scope: string;
|
|
11
|
+
projectName: string;
|
|
12
|
+
routes?: CFRoute[];
|
|
13
|
+
});
|
|
14
|
+
writeFiles({ dir }: {
|
|
15
|
+
dir: string;
|
|
16
|
+
}): void;
|
|
17
|
+
writeIndex({ dir }: {
|
|
18
|
+
dir: string;
|
|
19
|
+
}): void;
|
|
20
|
+
deploy({ dir, token }: {
|
|
21
|
+
dir: string;
|
|
22
|
+
token: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAK9C,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,MAAM,CAAC,EAAE,OAAO,EAAE,CAAM;gBACZ,EACV,KAAK,EACL,GAAG,EACH,WAAW,EACX,MAAM,GACP,EAAE;QACD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;KACpB;IAMD,UAAU,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IA4B1C,UAAU,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAcpC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAY5E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/deployer-cloudflare",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/deployer-cloudflare.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
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
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"date-fns": "^4.1.0",
|
|
27
|
+
"dotenv": "^16.3.1",
|
|
28
|
+
"execa": "^9.3.1",
|
|
29
|
+
"wrangler": "^3.103.2",
|
|
30
|
+
"zod": "^3.24.1",
|
|
31
|
+
"@mastra/deployer": "0.0.1-alpha.0",
|
|
32
|
+
"@mastra/core": "0.1.27-alpha.66"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@babel/preset-env": "^7.26.0",
|
|
36
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
37
|
+
"@tsconfig/recommended": "^1.0.7",
|
|
38
|
+
"@types/jsdom": "^21.1.7",
|
|
39
|
+
"@types/node": "^22.9.0",
|
|
40
|
+
"@types/pg": "^8.11.10",
|
|
41
|
+
"dts-cli": "^2.0.5",
|
|
42
|
+
"vitest": "^2.1.8"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "dts build",
|
|
46
|
+
"build:dev": "dts watch",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { MastraDeployer } from '@mastra/core';
|
|
2
|
+
import * as child_process from 'child_process';
|
|
3
|
+
import { writeFileSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
interface CFRoute {
|
|
7
|
+
pattern: string;
|
|
8
|
+
zone_name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class CloudflareDeployer extends MastraDeployer {
|
|
12
|
+
routes?: CFRoute[] = [];
|
|
13
|
+
constructor({
|
|
14
|
+
scope,
|
|
15
|
+
env,
|
|
16
|
+
projectName,
|
|
17
|
+
routes,
|
|
18
|
+
}: {
|
|
19
|
+
env?: Record<string, any>;
|
|
20
|
+
scope: string;
|
|
21
|
+
projectName: string;
|
|
22
|
+
routes?: CFRoute[];
|
|
23
|
+
}) {
|
|
24
|
+
super({ scope, env, projectName });
|
|
25
|
+
|
|
26
|
+
this.routes = routes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
writeFiles({ dir }: { dir: string }): void {
|
|
30
|
+
this.loadEnvVars();
|
|
31
|
+
|
|
32
|
+
this.writeIndex({ dir });
|
|
33
|
+
|
|
34
|
+
const cfWorkerName = this.projectName || 'mastra';
|
|
35
|
+
|
|
36
|
+
writeFileSync(
|
|
37
|
+
join(dir, 'wrangler.json'),
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
name: cfWorkerName,
|
|
40
|
+
main: 'index.mjs',
|
|
41
|
+
compatibility_date: '2024-12-02',
|
|
42
|
+
compatibility_flags: ['nodejs_compat'],
|
|
43
|
+
build: {
|
|
44
|
+
command: 'npm install',
|
|
45
|
+
},
|
|
46
|
+
observability: {
|
|
47
|
+
logs: {
|
|
48
|
+
enabled: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
routes: this.routes,
|
|
52
|
+
vars: this.env,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
writeIndex({ dir }: { dir: string }): void {
|
|
58
|
+
writeFileSync(
|
|
59
|
+
join(dir, './index.mjs'),
|
|
60
|
+
`
|
|
61
|
+
export default {
|
|
62
|
+
fetch: async (event, context) => {
|
|
63
|
+
const { app } = await import('./hono.mjs');
|
|
64
|
+
return app.fetch(event, context);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {
|
|
72
|
+
child_process.execSync(`npm exec wrangler deploy`, {
|
|
73
|
+
cwd: dir,
|
|
74
|
+
stdio: 'inherit',
|
|
75
|
+
env: {
|
|
76
|
+
CLOUDFLARE_API_TOKEN: token,
|
|
77
|
+
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
78
|
+
...this.env,
|
|
79
|
+
PATH: process.env.PATH,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|