@rubytech/create-maxy-code 0.1.450 → 0.1.451
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/package.json +1 -1
- package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js +39 -6
- package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts +1 -0
- package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts.map +1 -1
- package/payload/platform/lib/storage-broker/dist/cf-exec.js +24 -2
- package/payload/platform/lib/storage-broker/dist/cf-exec.js.map +1 -1
- package/payload/platform/lib/storage-broker/src/__tests__/cf-exec.test.ts +45 -7
- package/payload/platform/lib/storage-broker/src/cf-exec.ts +33 -6
- package/payload/platform/plugins/storage-broker/PLUGIN.md +4 -0
- package/payload/server/{chunk-MUHCRGUF.js → chunk-TTKYHVA7.js} +19 -2
- package/payload/server/server.js +2 -2
- package/payload/server/{src-OYNQ3ISB.js → src-FBUXV2FV.js} +1 -1
package/package.json
CHANGED
|
@@ -15,10 +15,11 @@ function recordingRun(stdout) {
|
|
|
15
15
|
};
|
|
16
16
|
return { run, calls };
|
|
17
17
|
}
|
|
18
|
-
// r2List
|
|
19
|
-
// A run that throws proves
|
|
18
|
+
// r2List and d1Create hit the Cloudflare API, not wrangler, so they need a
|
|
19
|
+
// fetch seam. A run that throws proves they never shell wrangler — in
|
|
20
|
+
// particular that no `--json` reaches a `wrangler d1 create` invocation.
|
|
20
21
|
const throwingRun = async () => {
|
|
21
|
-
throw new Error("
|
|
22
|
+
throw new Error("must not shell wrangler");
|
|
22
23
|
};
|
|
23
24
|
function recordingFetch(response) {
|
|
24
25
|
const calls = [];
|
|
@@ -46,10 +47,42 @@ function recordingFetch(response) {
|
|
|
46
47
|
"wrangler", "d1", "execute", "gls-leads", "--remote", "--json", "--command", "SELECT 1",
|
|
47
48
|
]);
|
|
48
49
|
});
|
|
49
|
-
(0, node_test_1.default)("d1Create
|
|
50
|
-
const {
|
|
51
|
-
|
|
50
|
+
(0, node_test_1.default)("d1Create creates the database via the D1 API with the house token, never wrangler", async () => {
|
|
51
|
+
const { fetchFn, calls } = recordingFetch({
|
|
52
|
+
ok: true,
|
|
53
|
+
status: 200,
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
success: true,
|
|
56
|
+
errors: [],
|
|
57
|
+
messages: [],
|
|
58
|
+
result: { uuid: "new-db", name: "gls-new", created_at: "2026-01-01T00:00:00Z" },
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
const cf = (0, cf_exec_js_1.makeCfExec)(cred, throwingRun, fetchFn);
|
|
52
62
|
strict_1.default.deepEqual(await cf.d1Create("gls-new"), { uuid: "new-db" });
|
|
63
|
+
strict_1.default.equal(calls[0].url, "https://api.cloudflare.com/client/v4/accounts/acc-h/d1/database");
|
|
64
|
+
strict_1.default.equal(calls[0].init.method, "POST");
|
|
65
|
+
strict_1.default.equal(calls[0].init.headers.Authorization, "Bearer cfat_x");
|
|
66
|
+
strict_1.default.equal(calls[0].init.headers["Content-Type"], "application/json");
|
|
67
|
+
strict_1.default.deepEqual(JSON.parse(calls[0].init.body ?? ""), { name: "gls-new" });
|
|
68
|
+
});
|
|
69
|
+
(0, node_test_1.default)("d1Create throws with the API error body on a non-2xx response", async () => {
|
|
70
|
+
const { fetchFn } = recordingFetch({
|
|
71
|
+
ok: false,
|
|
72
|
+
status: 403,
|
|
73
|
+
body: JSON.stringify({ success: false, errors: [{ code: 10000, message: "Authentication error" }] }),
|
|
74
|
+
});
|
|
75
|
+
const cf = (0, cf_exec_js_1.makeCfExec)(cred, throwingRun, fetchFn);
|
|
76
|
+
await strict_1.default.rejects(() => cf.d1Create("gls-new"), /403[\s\S]*Authentication error/);
|
|
77
|
+
});
|
|
78
|
+
(0, node_test_1.default)("d1Create throws on a 200 whose body is not a success envelope, retaining the body", async () => {
|
|
79
|
+
const { fetchFn } = recordingFetch({
|
|
80
|
+
ok: true,
|
|
81
|
+
status: 200,
|
|
82
|
+
body: JSON.stringify({ unexpected: "shape" }),
|
|
83
|
+
});
|
|
84
|
+
const cf = (0, cf_exec_js_1.makeCfExec)(cred, throwingRun, fetchFn);
|
|
85
|
+
await strict_1.default.rejects(() => cf.d1Create("gls-new"), /unexpected/);
|
|
53
86
|
});
|
|
54
87
|
(0, node_test_1.default)("r2Create shells wrangler r2 bucket create", async () => {
|
|
55
88
|
const { run, calls } = recordingRun("");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cf-exec.test.js","sourceRoot":"","sources":["../../src/__tests__/cf-exec.test.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,gEAAwC;AACxC,8CAAqE;AAErE,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAExD,SAAS,YAAY,CAAC,MAAc;IAClC,MAAM,KAAK,GAAwE,EAAE,CAAC;IACtF,MAAM,GAAG,GAAU,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,CAAC;IACF,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"cf-exec.test.js","sourceRoot":"","sources":["../../src/__tests__/cf-exec.test.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,gEAAwC;AACxC,8CAAqE;AAErE,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAExD,SAAS,YAAY,CAAC,MAAc;IAClC,MAAM,KAAK,GAAwE,EAAE,CAAC;IACtF,MAAM,GAAG,GAAU,KAAK,EAAE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AAA,mBAAI,EAAC,iFAAiF,EAAE,KAAK,IAAI,EAAE;IACjG,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;QACjC,EAAE,EAAE,IAAI;QACR,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;KAC9C,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,IAAA,uBAAU,EAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,gBAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,YAAY,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC;AAEH,IAAA,mBAAI,EAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;IAC1D,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,EAAE,GAAG,IAAA,uBAAU,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,gBAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cf-exec.d.ts","sourceRoot":"","sources":["../src/cf-exec.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,KAAK,GAAG,CAClB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACxB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cf-exec.d.ts","sourceRoot":"","sources":["../src/cf-exec.ts"],"names":[],"mappings":"AAK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@@ -38,8 +38,30 @@ function makeCfExec(cred, run = defaultRun, fetchFn = defaultFetch) {
|
|
|
38
38
|
return parseJson(stdout, "d1 list");
|
|
39
39
|
},
|
|
40
40
|
async d1Create(name) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// `wrangler d1 create` has no --json flag (unlike `d1 list`/`d1 execute`),
|
|
42
|
+
// so shelling it with --json is always rejected. The D1 API creates the
|
|
43
|
+
// database and returns its record — incl. the uuid — as JSON directly.
|
|
44
|
+
const url = `https://api.cloudflare.com/client/v4/accounts/${cred.accountId}/d1/database`;
|
|
45
|
+
const res = await fetchFn(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${cred.apiToken}`,
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify({ name }),
|
|
52
|
+
});
|
|
53
|
+
const body = await res.text();
|
|
54
|
+
if (!res.ok) {
|
|
55
|
+
throw new Error(`storage-broker: d1 create failed: ${res.status}\n${body}`);
|
|
56
|
+
}
|
|
57
|
+
const parsed = parseJson(body, "d1 create");
|
|
58
|
+
// Require an explicit success envelope with a uuid. A 2xx whose body is
|
|
59
|
+
// not a well-formed `success:true` response is an anomaly to surface with
|
|
60
|
+
// its body, never a silently uuid-less create.
|
|
61
|
+
if (parsed.success !== true || typeof parsed.result?.uuid !== "string") {
|
|
62
|
+
throw new Error(`storage-broker: d1 create API error: ${body}`);
|
|
63
|
+
}
|
|
64
|
+
return { uuid: parsed.result.uuid };
|
|
43
65
|
},
|
|
44
66
|
async d1Query(name, sql) {
|
|
45
67
|
const { stdout } = await run("npx", ["wrangler", "d1", "execute", name, "--remote", "--json", "--command", sql], env);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cf-exec.js","sourceRoot":"","sources":["../src/cf-exec.ts"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,iFAAiF;AACjF,iFAAiF;;
|
|
1
|
+
{"version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EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,IAAI;YACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -13,14 +13,18 @@ function recordingRun(stdout: string) {
|
|
|
13
13
|
return { run, calls };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// r2List
|
|
17
|
-
// A run that throws proves
|
|
16
|
+
// r2List and d1Create hit the Cloudflare API, not wrangler, so they need a
|
|
17
|
+
// fetch seam. A run that throws proves they never shell wrangler — in
|
|
18
|
+
// particular that no `--json` reaches a `wrangler d1 create` invocation.
|
|
18
19
|
const throwingRun: RunFn = async () => {
|
|
19
|
-
throw new Error("
|
|
20
|
+
throw new Error("must not shell wrangler");
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
function recordingFetch(response: { ok: boolean; status: number; body: string }) {
|
|
23
|
-
const calls: Array<{
|
|
24
|
+
const calls: Array<{
|
|
25
|
+
url: string;
|
|
26
|
+
init: { method: string; headers: Record<string, string>; body?: string };
|
|
27
|
+
}> = [];
|
|
24
28
|
const fetchFn: FetchFn = async (url, init) => {
|
|
25
29
|
calls.push({ url, init });
|
|
26
30
|
return { ok: response.ok, status: response.status, text: async () => response.body };
|
|
@@ -48,10 +52,44 @@ test("d1Query runs execute --remote with the SQL", async () => {
|
|
|
48
52
|
]);
|
|
49
53
|
});
|
|
50
54
|
|
|
51
|
-
test("d1Create
|
|
52
|
-
const {
|
|
53
|
-
|
|
55
|
+
test("d1Create creates the database via the D1 API with the house token, never wrangler", async () => {
|
|
56
|
+
const { fetchFn, calls } = recordingFetch({
|
|
57
|
+
ok: true,
|
|
58
|
+
status: 200,
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
success: true,
|
|
61
|
+
errors: [],
|
|
62
|
+
messages: [],
|
|
63
|
+
result: { uuid: "new-db", name: "gls-new", created_at: "2026-01-01T00:00:00Z" },
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
const cf = makeCfExec(cred, throwingRun, fetchFn);
|
|
54
67
|
assert.deepEqual(await cf.d1Create("gls-new"), { uuid: "new-db" });
|
|
68
|
+
assert.equal(calls[0].url, "https://api.cloudflare.com/client/v4/accounts/acc-h/d1/database");
|
|
69
|
+
assert.equal(calls[0].init.method, "POST");
|
|
70
|
+
assert.equal(calls[0].init.headers.Authorization, "Bearer cfat_x");
|
|
71
|
+
assert.equal(calls[0].init.headers["Content-Type"], "application/json");
|
|
72
|
+
assert.deepEqual(JSON.parse(calls[0].init.body ?? ""), { name: "gls-new" });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("d1Create throws with the API error body on a non-2xx response", async () => {
|
|
76
|
+
const { fetchFn } = recordingFetch({
|
|
77
|
+
ok: false,
|
|
78
|
+
status: 403,
|
|
79
|
+
body: JSON.stringify({ success: false, errors: [{ code: 10000, message: "Authentication error" }] }),
|
|
80
|
+
});
|
|
81
|
+
const cf = makeCfExec(cred, throwingRun, fetchFn);
|
|
82
|
+
await assert.rejects(() => cf.d1Create("gls-new"), /403[\s\S]*Authentication error/);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("d1Create throws on a 200 whose body is not a success envelope, retaining the body", async () => {
|
|
86
|
+
const { fetchFn } = recordingFetch({
|
|
87
|
+
ok: true,
|
|
88
|
+
status: 200,
|
|
89
|
+
body: JSON.stringify({ unexpected: "shape" }),
|
|
90
|
+
});
|
|
91
|
+
const cf = makeCfExec(cred, throwingRun, fetchFn);
|
|
92
|
+
await assert.rejects(() => cf.d1Create("gls-new"), /unexpected/);
|
|
55
93
|
});
|
|
56
94
|
|
|
57
95
|
test("r2Create shells wrangler r2 bucket create", async () => {
|
|
@@ -11,12 +11,13 @@ export type RunFn = (
|
|
|
11
11
|
env: Record<string, string>,
|
|
12
12
|
) => Promise<{ stdout: string }>;
|
|
13
13
|
|
|
14
|
-
// The HTTP seam for the Cloudflare API. Injectable so r2List
|
|
15
|
-
// without a network. Minimal subset of the global fetch:
|
|
16
|
-
// once via text() and
|
|
14
|
+
// The HTTP seam for the Cloudflare API. Injectable so r2List and d1Create are
|
|
15
|
+
// unit-testable without a network. Minimal subset of the global fetch: callers
|
|
16
|
+
// read the body once via text() and branch on ok/status. `body` is set for the
|
|
17
|
+
// POST paths (d1Create); GET paths (r2List) omit it.
|
|
17
18
|
export type FetchFn = (
|
|
18
19
|
url: string,
|
|
19
|
-
init: { method: string; headers: Record<string, string
|
|
20
|
+
init: { method: string; headers: Record<string, string>; body?: string },
|
|
20
21
|
) => Promise<{ ok: boolean; status: number; text(): Promise<string> }>;
|
|
21
22
|
|
|
22
23
|
export interface CfExec {
|
|
@@ -68,8 +69,34 @@ export function makeCfExec(
|
|
|
68
69
|
return parseJson(stdout, "d1 list") as { name: string; uuid: string }[];
|
|
69
70
|
},
|
|
70
71
|
async d1Create(name) {
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
// `wrangler d1 create` has no --json flag (unlike `d1 list`/`d1 execute`),
|
|
73
|
+
// so shelling it with --json is always rejected. The D1 API creates the
|
|
74
|
+
// database and returns its record — incl. the uuid — as JSON directly.
|
|
75
|
+
const url = `https://api.cloudflare.com/client/v4/accounts/${cred.accountId}/d1/database`;
|
|
76
|
+
const res = await fetchFn(url, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
Authorization: `Bearer ${cred.apiToken}`,
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({ name }),
|
|
83
|
+
});
|
|
84
|
+
const body = await res.text();
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
throw new Error(`storage-broker: d1 create failed: ${res.status}\n${body}`);
|
|
87
|
+
}
|
|
88
|
+
const parsed = parseJson(body, "d1 create") as {
|
|
89
|
+
success?: boolean;
|
|
90
|
+
errors?: unknown;
|
|
91
|
+
result?: { uuid?: string };
|
|
92
|
+
};
|
|
93
|
+
// Require an explicit success envelope with a uuid. A 2xx whose body is
|
|
94
|
+
// not a well-formed `success:true` response is an anomaly to surface with
|
|
95
|
+
// its body, never a silently uuid-less create.
|
|
96
|
+
if (parsed.success !== true || typeof parsed.result?.uuid !== "string") {
|
|
97
|
+
throw new Error(`storage-broker: d1 create API error: ${body}`);
|
|
98
|
+
}
|
|
99
|
+
return { uuid: parsed.result.uuid };
|
|
73
100
|
},
|
|
74
101
|
async d1Query(name, sql) {
|
|
75
102
|
const { stdout } = await run(
|
|
@@ -46,3 +46,7 @@ The isolation boundary for per-account Cloudflare D1 and R2 on a multi-tenant in
|
|
|
46
46
|
- `storage-r2-bucket-create` — create an R2 bucket, registered to the caller.
|
|
47
47
|
|
|
48
48
|
A request against a database or bucket the caller does not own returns an authorization error, not another account's data.
|
|
49
|
+
|
|
50
|
+
## Wrangler resolution
|
|
51
|
+
|
|
52
|
+
The broker service shells wrangler through `npx wrangler`, never bare `wrangler`, for every D1 operation and R2 bucket creation. The brand server PATH carries no global wrangler install; only `npx wrangler` resolves, so a bare `wrangler` call ENOENTs those operations on a real install. R2 bucket listing is exempt: it reads the Cloudflare R2 API directly, not wrangler.
|
|
@@ -98,8 +98,25 @@ function makeCfExec(cred, run = defaultRun, fetchFn = defaultFetch) {
|
|
|
98
98
|
return parseJson(stdout, "d1 list");
|
|
99
99
|
},
|
|
100
100
|
async d1Create(name) {
|
|
101
|
-
const
|
|
102
|
-
|
|
101
|
+
const url = `https://api.cloudflare.com/client/v4/accounts/${cred.accountId}/d1/database`;
|
|
102
|
+
const res = await fetchFn(url, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `Bearer ${cred.apiToken}`,
|
|
106
|
+
"Content-Type": "application/json"
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify({ name })
|
|
109
|
+
});
|
|
110
|
+
const body = await res.text();
|
|
111
|
+
if (!res.ok) {
|
|
112
|
+
throw new Error(`storage-broker: d1 create failed: ${res.status}
|
|
113
|
+
${body}`);
|
|
114
|
+
}
|
|
115
|
+
const parsed = parseJson(body, "d1 create");
|
|
116
|
+
if (parsed.success !== true || typeof parsed.result?.uuid !== "string") {
|
|
117
|
+
throw new Error(`storage-broker: d1 create API error: ${body}`);
|
|
118
|
+
}
|
|
119
|
+
return { uuid: parsed.result.uuid };
|
|
103
120
|
},
|
|
104
121
|
async d1Query(name, sql) {
|
|
105
122
|
const { stdout } = await run(
|
package/payload/server/server.js
CHANGED
|
@@ -118,7 +118,7 @@ import {
|
|
|
118
118
|
readHouseCredential,
|
|
119
119
|
registerResource,
|
|
120
120
|
resolveOwner
|
|
121
|
-
} from "./chunk-
|
|
121
|
+
} from "./chunk-TTKYHVA7.js";
|
|
122
122
|
import {
|
|
123
123
|
__commonJS,
|
|
124
124
|
__toESM
|
|
@@ -8679,7 +8679,7 @@ app3.post("/r2/create", async (c) => {
|
|
|
8679
8679
|
});
|
|
8680
8680
|
var storage_broker_default = app3;
|
|
8681
8681
|
async function runStorageAudit(root) {
|
|
8682
|
-
const { reconcileStorage } = await import("./src-
|
|
8682
|
+
const { reconcileStorage } = await import("./src-FBUXV2FV.js");
|
|
8683
8683
|
const session = getSession();
|
|
8684
8684
|
try {
|
|
8685
8685
|
const cf = makeCfExec(readHouseCredential(root));
|