@somewhere-tech/cli 0.29.0 → 0.29.1
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/dist/commands/deploy.js +33 -8
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +123 -43
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/project.js +2 -1
- package/dist/commands/project.js.map +1 -1
- package/dist/commands/promote.js +11 -12
- package/dist/commands/promote.js.map +1 -1
- package/dist/commands/rollback.js +1 -1
- package/dist/commands/rollback.js.map +1 -1
- package/dist/commands/status.js +2 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/lib/output.js +2 -2
- package/dist/lib/output.js.map +1 -1
- package/dist/local/compiler.js +40 -5
- package/dist/local/compiler.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/runtime/VENDOR.json +7 -0
- package/runtime/compiler/VENDOR.json +5 -1
- package/runtime/platform-context.mjs +5422 -1802
- package/runtime/sw-init.mjs +51 -5
package/runtime/sw-init.mjs
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
// VENDORED from worker/src/utils/function-bundle.ts (SW_INIT_JS) @
|
|
1
|
+
// VENDORED from worker/src/utils/function-bundle.ts (SW_INIT_JS) @ 3326a8d8
|
|
2
2
|
// — the exact runtime deployed functions run against. Do not edit by hand;
|
|
3
3
|
// re-sync with: node scripts/extract-runtime.mjs <monorepo>
|
|
4
4
|
// Generated by somewhere.tech deploy pipeline. Sets up the global
|
|
5
5
|
// surfaces user modules need at module-load time.
|
|
6
6
|
globalThis.sw = globalThis.sw || {};
|
|
7
7
|
|
|
8
|
+
// USER_ENV is the canonical, deploy-baked source behind each request's
|
|
9
|
+
// sw.env. Capture this initializer in index.mjs before customer modules load,
|
|
10
|
+
// then remove it from the public global surface. This intentionally restores
|
|
11
|
+
// only customer-owned values after workerd denies automatic raw env reflection.
|
|
12
|
+
globalThis.sw.__wireProcessEnv = function __sw_wireProcessEnv(runtimeEnv) {
|
|
13
|
+
if (typeof process !== 'object' || process === null ||
|
|
14
|
+
typeof process.env !== 'object' || process.env === null) {
|
|
15
|
+
const error = new Error('process.env could not be initialized from project environment variables.');
|
|
16
|
+
error.code = 'PROCESS_ENV_INIT_FAILED';
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let userEnv;
|
|
21
|
+
try {
|
|
22
|
+
userEnv = runtimeEnv && runtimeEnv.USER_ENV ? JSON.parse(runtimeEnv.USER_ENV) : {};
|
|
23
|
+
} catch (_) {
|
|
24
|
+
const error = new Error('process.env could not be initialized from project environment variables.');
|
|
25
|
+
error.code = 'PROCESS_ENV_INIT_FAILED';
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
if (!userEnv || typeof userEnv !== 'object' || Array.isArray(userEnv)) {
|
|
29
|
+
const error = new Error('process.env could not be initialized from project environment variables.');
|
|
30
|
+
error.code = 'PROCESS_ENV_INIT_FAILED';
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const key of Object.keys(process.env)) delete process.env[key];
|
|
35
|
+
for (const key of Object.keys(userEnv)) process.env[key] = String(userEnv[key]);
|
|
36
|
+
};
|
|
37
|
+
|
|
8
38
|
/** Parse "10/minute" / "60/hour" / "1000/day" into { max, windowSeconds }. */
|
|
9
39
|
function __sw_parseRateLimit(spec) {
|
|
10
40
|
if (typeof spec !== 'string') return null;
|
|
@@ -85,7 +115,10 @@ function __sw_corsHeaders(corsCfg, request) {
|
|
|
85
115
|
return {
|
|
86
116
|
'Access-Control-Allow-Origin': allowed,
|
|
87
117
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
88
|
-
|
|
118
|
+
// Pragma/Cache-Control: headless browsers + CI automation attach
|
|
119
|
+
// "Pragma: no-cache" to every fetch; omitting them fails the preflight
|
|
120
|
+
// for those clients only (tsk_abbfd574).
|
|
121
|
+
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Pragma, Cache-Control',
|
|
89
122
|
'Vary': 'Origin',
|
|
90
123
|
};
|
|
91
124
|
}
|
|
@@ -183,20 +216,33 @@ globalThis.sw.endpoint = function (config) {
|
|
|
183
216
|
try {
|
|
184
217
|
var r = await sw.rateLimit.check(rlKey, rateLimit.max, rateLimit.windowSeconds);
|
|
185
218
|
if (!r || r.allowed === false) {
|
|
186
|
-
var retry =
|
|
219
|
+
var retry = rateLimit.windowSeconds;
|
|
220
|
+
if (r && (r.retry_after || r.retry_after_s)) retry = r.retry_after || r.retry_after_s;
|
|
221
|
+
else if (r && r.reset) retry = Math.max(1, Math.ceil(r.reset - (Date.now() / 1000)));
|
|
222
|
+
var code = (r && r.error) || 'RATE_LIMITED';
|
|
223
|
+
var message = (r && r.message) || 'Too many requests.';
|
|
187
224
|
return __sw_mergeHeaders(
|
|
188
225
|
new Response(
|
|
189
|
-
JSON.stringify({ ok: false, error:
|
|
226
|
+
JSON.stringify({ ok: false, error: code, message: message, retry_after: retry }),
|
|
190
227
|
{ status: 429, headers: { 'Content-Type': 'application/json', 'Retry-After': String(retry) } }
|
|
191
228
|
),
|
|
192
229
|
corsHeaders
|
|
193
230
|
);
|
|
194
231
|
}
|
|
195
|
-
} catch (
|
|
232
|
+
} catch (rlErr) {
|
|
196
233
|
// fail-loudly + fail-CLOSED (tsk_9f22): if the rate-limit check
|
|
197
234
|
// itself errors we used to let the request through — silently
|
|
198
235
|
// disabling the limiter. Block instead. A rate-limited endpoint
|
|
199
236
|
// must never serve unthrottled just because the limiter hiccuped.
|
|
237
|
+
// Log the underlying failure — swallowing it hid a 403
|
|
238
|
+
// capability denial behind "temporarily unavailable" for 9 days
|
|
239
|
+
// (tsk_8fec0de9). A 403 here means the runtime key was minted
|
|
240
|
+
// without project:rate-limit; that is permanent until redeploy,
|
|
241
|
+
// not transient.
|
|
242
|
+
console.error(
|
|
243
|
+
'sw.endpoint rate-limit check failed (failing closed with 503 RATE_LIMIT_UNAVAILABLE):',
|
|
244
|
+
rlErr && rlErr.code, rlErr && rlErr.status, rlErr && rlErr.message
|
|
245
|
+
);
|
|
200
246
|
return __sw_mergeHeaders(
|
|
201
247
|
new Response(
|
|
202
248
|
JSON.stringify({ ok: false, error: 'RATE_LIMIT_UNAVAILABLE', message: 'Rate limiting is temporarily unavailable; this request was blocked. Retry shortly.' }),
|