@somewhere-tech/cli 0.31.16 → 0.31.18
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/browser.js +1 -1
- package/dist/commands/browser.js.map +1 -1
- package/dist/commands/check.js +1 -2
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/db.js +8 -5
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/dev.js +18 -383
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/status.js +0 -36
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/typecheck.js +1 -1
- package/dist/commands/typecheck.js.map +1 -1
- package/dist/commands/verify.js +1 -1
- package/dist/commands/verify.js.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/{local → lib}/browser-run.js +1 -1
- package/dist/lib/browser-run.js.map +1 -0
- package/dist/lib/chrome.js.map +1 -0
- package/dist/lib/envfile-write.js +2 -2
- package/dist/lib/envfile-write.js.map +1 -1
- package/dist/lib/frontend-dev.js +122 -0
- package/dist/lib/frontend-dev.js.map +1 -0
- package/dist/lib/init-agent-guide.js +15 -19
- package/dist/lib/init-agent-guide.js.map +1 -1
- package/dist/lib/init-green-template.js +1 -1
- package/dist/lib/project-urls.js +13 -0
- package/dist/lib/project-urls.js.map +1 -1
- package/npm-shrinkwrap.json +2 -17
- package/package.json +3 -5
- package/runtime/VENDOR.json +0 -2
- package/dist/commands/exec.js +0 -145
- package/dist/commands/exec.js.map +0 -1
- package/dist/local/browser-run.js.map +0 -1
- package/dist/local/chrome.js.map +0 -1
- package/dist/local/compiler-core.js +0 -51
- package/dist/local/compiler-core.js.map +0 -1
- package/dist/local/compiler.js +0 -683
- package/dist/local/compiler.js.map +0 -1
- package/dist/local/dev-server.js +0 -517
- package/dist/local/dev-server.js.map +0 -1
- package/dist/local/envfile.js +0 -40
- package/dist/local/envfile.js.map +0 -1
- package/dist/local/loader.js +0 -299
- package/dist/local/loader.js.map +0 -1
- package/dist/local/loopback.js +0 -129
- package/dist/local/loopback.js.map +0 -1
- package/dist/local/request-timing.js +0 -101
- package/dist/local/request-timing.js.map +0 -1
- package/dist/local/router.js +0 -114
- package/dist/local/router.js.map +0 -1
- package/dist/local/runtime.js +0 -345
- package/dist/local/runtime.js.map +0 -1
- package/dist/local/server.js +0 -309
- package/dist/local/server.js.map +0 -1
- package/dist/local/telemetry-filter.js +0 -120
- package/dist/local/telemetry-filter.js.map +0 -1
- package/node_modules/esbuild-wasm/LICENSE.md +0 -21
- package/node_modules/esbuild-wasm/README.md +0 -3
- package/node_modules/esbuild-wasm/bin/esbuild +0 -91
- package/node_modules/esbuild-wasm/esbuild.wasm +0 -0
- package/node_modules/esbuild-wasm/esm/browser.d.ts +0 -705
- package/node_modules/esbuild-wasm/esm/browser.js +0 -2393
- package/node_modules/esbuild-wasm/esm/browser.min.js +0 -20
- package/node_modules/esbuild-wasm/lib/browser.d.ts +0 -705
- package/node_modules/esbuild-wasm/lib/browser.js +0 -2438
- package/node_modules/esbuild-wasm/lib/browser.min.js +0 -22
- package/node_modules/esbuild-wasm/lib/main.d.ts +0 -705
- package/node_modules/esbuild-wasm/lib/main.js +0 -2051
- package/node_modules/esbuild-wasm/package.json +0 -19
- package/node_modules/esbuild-wasm/wasm_exec.js +0 -561
- package/node_modules/esbuild-wasm/wasm_exec_node.js +0 -39
- package/runtime/compiler/VENDOR.json +0 -64
- package/runtime/compiler/compile-core.cjs +0 -2007
- package/runtime/compiler/graph-contract.cjs +0 -124
- package/runtime/compiler/typed-functions.cjs +0 -575
- package/runtime/platform-context.mjs +0 -8193
- package/runtime/sw-init.mjs +0 -283
- /package/dist/{local → lib}/chrome.js +0 -0
package/runtime/sw-init.mjs
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
// VENDORED from worker/src/utils/function-bundle.ts (SW_INIT_JS) @ 28d67b0a
|
|
2
|
-
// — the exact runtime deployed functions run against. Do not edit by hand;
|
|
3
|
-
// re-sync with: node scripts/extract-runtime.mjs <monorepo>
|
|
4
|
-
// Generated by somewhere.tech deploy pipeline. Sets up the global
|
|
5
|
-
// surfaces user modules need at module-load time.
|
|
6
|
-
globalThis.sw = globalThis.sw || {};
|
|
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
|
-
|
|
38
|
-
/** Parse "10/minute" / "60/hour" / "1000/day" into { max, windowSeconds }. */
|
|
39
|
-
function __sw_parseRateLimit(spec) {
|
|
40
|
-
if (typeof spec !== 'string') return null;
|
|
41
|
-
var m = spec.match(/^\s*(\d+)\s*\/\s*(second|minute|hour|day)s?\s*$/i);
|
|
42
|
-
if (!m) return null;
|
|
43
|
-
var window = { second: 1, minute: 60, hour: 3600, day: 86400 }[m[2].toLowerCase()];
|
|
44
|
-
return { max: Number(m[1]), windowSeconds: window };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Best-effort client IP for rate-limit keying when no user is authed. */
|
|
48
|
-
function __sw_clientIp(request) {
|
|
49
|
-
var h = request.headers;
|
|
50
|
-
return (
|
|
51
|
-
h.get('cf-connecting-ip') ||
|
|
52
|
-
h.get('x-forwarded-for')?.split(',')[0]?.trim() ||
|
|
53
|
-
h.get('x-real-ip') ||
|
|
54
|
-
'anon'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Validate `value` against a small declarative schema. Returns an
|
|
60
|
-
* array of error messages (empty if valid). Supports leaf strings as
|
|
61
|
-
* type names ('string', 'email', 'number', 'boolean', 'array',
|
|
62
|
-
* 'object'), trailing '?' for optional, and nested objects. Designed
|
|
63
|
-
* for body validation, not arbitrary JSON Schema.
|
|
64
|
-
*/
|
|
65
|
-
function __sw_validate(value, schema, path) {
|
|
66
|
-
path = path || '';
|
|
67
|
-
var errs = [];
|
|
68
|
-
if (typeof schema === 'string') {
|
|
69
|
-
var optional = schema.endsWith('?');
|
|
70
|
-
var type = optional ? schema.slice(0, -1) : schema;
|
|
71
|
-
if (value === undefined || value === null) {
|
|
72
|
-
if (!optional) errs.push(path + ': required');
|
|
73
|
-
return errs;
|
|
74
|
-
}
|
|
75
|
-
if (type === 'string' && typeof value !== 'string') errs.push(path + ': must be a string');
|
|
76
|
-
else if (type === 'email') {
|
|
77
|
-
if (typeof value !== 'string' || !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(value)) errs.push(path + ': must be a valid email');
|
|
78
|
-
}
|
|
79
|
-
else if (type === 'number' && typeof value !== 'number') errs.push(path + ': must be a number');
|
|
80
|
-
else if (type === 'boolean' && typeof value !== 'boolean') errs.push(path + ': must be a boolean');
|
|
81
|
-
else if (type === 'array' && !Array.isArray(value)) errs.push(path + ': must be an array');
|
|
82
|
-
else if (type === 'object' && (typeof value !== 'object' || value === null || Array.isArray(value))) errs.push(path + ': must be an object');
|
|
83
|
-
return errs;
|
|
84
|
-
}
|
|
85
|
-
if (schema && typeof schema === 'object') {
|
|
86
|
-
if (value === null || value === undefined || typeof value !== 'object' || Array.isArray(value)) {
|
|
87
|
-
errs.push((path || 'body') + ': must be an object');
|
|
88
|
-
return errs;
|
|
89
|
-
}
|
|
90
|
-
for (var key of Object.keys(schema)) {
|
|
91
|
-
var sub = path ? path + '.' + key : key;
|
|
92
|
-
errs = errs.concat(__sw_validate(value[key], schema[key], sub));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return errs;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Build CORS headers off the config. 'same-origin' returns no
|
|
99
|
-
* Access-Control-* — that's the default browsers enforce when no
|
|
100
|
-
* header is present, exactly what we want. */
|
|
101
|
-
function __sw_corsHeaders(corsCfg, request) {
|
|
102
|
-
if (!corsCfg || corsCfg === 'same-origin') return {};
|
|
103
|
-
var origin = request.headers.get('origin') || '';
|
|
104
|
-
var allowed;
|
|
105
|
-
if (corsCfg === '*') allowed = '*';
|
|
106
|
-
else if (Array.isArray(corsCfg)) {
|
|
107
|
-
var hit = corsCfg.find(function (o) {
|
|
108
|
-
return o === origin || origin.endsWith('.' + o);
|
|
109
|
-
});
|
|
110
|
-
if (!hit) return {};
|
|
111
|
-
allowed = origin;
|
|
112
|
-
} else {
|
|
113
|
-
return {};
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
'Access-Control-Allow-Origin': allowed,
|
|
117
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
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',
|
|
122
|
-
'Vary': 'Origin',
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function __sw_jsonError(status, code, message, extras) {
|
|
127
|
-
var body = Object.assign({ ok: false, error: code, message: message }, extras || {});
|
|
128
|
-
return new Response(JSON.stringify(body), {
|
|
129
|
-
status: status,
|
|
130
|
-
headers: { 'Content-Type': 'application/json' },
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function __sw_mergeHeaders(response, extra) {
|
|
135
|
-
if (!extra || Object.keys(extra).length === 0) return response;
|
|
136
|
-
var headers = new Headers(response.headers);
|
|
137
|
-
for (var k of Object.keys(extra)) headers.set(k, extra[k]);
|
|
138
|
-
return new Response(response.body, {
|
|
139
|
-
status: response.status,
|
|
140
|
-
statusText: response.statusText,
|
|
141
|
-
headers: headers,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* sw.endpoint({ auth, body, rateLimit, cors, handler }) → handler.
|
|
147
|
-
*
|
|
148
|
-
* Returns an async (request, sw) => Response | object that the shim
|
|
149
|
-
* dispatches to like any other default-export handler. Pipeline:
|
|
150
|
-
*
|
|
151
|
-
* 1. CORS preflight — answer OPTIONS with 204 + allow headers.
|
|
152
|
-
* 2. Auth — required throws 401, optional enriches user when present.
|
|
153
|
-
* 3. Body validation — parses JSON, validates against schema.
|
|
154
|
-
* 4. Rate limit — per-(user|ip)-per-path counter via sw.rateLimit.
|
|
155
|
-
* 5. Handler — { body, user, headers, params, request } + sw.
|
|
156
|
-
* 6. Error wrap — clean JSON { ok:false, error, message }.
|
|
157
|
-
* 7. CORS — append Access-Control-* to the response.
|
|
158
|
-
*/
|
|
159
|
-
globalThis.sw.endpoint = function (config) {
|
|
160
|
-
config = config || {};
|
|
161
|
-
if (typeof config.handler !== 'function') {
|
|
162
|
-
throw new Error('sw.endpoint: handler is required (an async function).');
|
|
163
|
-
}
|
|
164
|
-
var auth = config.auth || 'none';
|
|
165
|
-
var bodySchema = config.body || null;
|
|
166
|
-
var rateLimit = __sw_parseRateLimit(config.rateLimit);
|
|
167
|
-
var cors = config.cors || 'same-origin';
|
|
168
|
-
|
|
169
|
-
return async function endpointHandler(request, sw) {
|
|
170
|
-
var corsHeaders = __sw_corsHeaders(cors, request);
|
|
171
|
-
if (request.method === 'OPTIONS') {
|
|
172
|
-
return new Response(null, { status: 204, headers: corsHeaders });
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Auth.
|
|
176
|
-
var user = null;
|
|
177
|
-
if (auth === 'required') {
|
|
178
|
-
try {
|
|
179
|
-
user = await sw.auth.requireUser(request);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
return __sw_mergeHeaders(
|
|
182
|
-
__sw_jsonError(e.status || 401, e.code || 'AUTH_REQUIRED', e.message || 'Sign in required.'),
|
|
183
|
-
corsHeaders
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
} else if (auth === 'optional') {
|
|
187
|
-
try { user = await sw.auth.fromRequest(request); } catch (_) { /* swallow */ }
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Body validation (skipped on GET/DELETE/HEAD — no body expected).
|
|
191
|
-
var body = null;
|
|
192
|
-
if (bodySchema && request.method !== 'GET' && request.method !== 'DELETE' && request.method !== 'HEAD') {
|
|
193
|
-
try { body = await request.json(); }
|
|
194
|
-
catch (_) {
|
|
195
|
-
return __sw_mergeHeaders(
|
|
196
|
-
__sw_jsonError(400, 'INVALID_JSON', 'Request body must be valid JSON.'),
|
|
197
|
-
corsHeaders
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
var errors = __sw_validate(body, bodySchema, '');
|
|
201
|
-
if (errors.length) {
|
|
202
|
-
return __sw_mergeHeaders(
|
|
203
|
-
__sw_jsonError(400, 'VALIDATION_ERROR', errors.join('; '), { fields: errors }),
|
|
204
|
-
corsHeaders
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Rate limit. Key by user id when authed (sticky across IPs);
|
|
210
|
-
// by client IP otherwise. Path is included so two endpoints don't
|
|
211
|
-
// share a bucket.
|
|
212
|
-
if (rateLimit) {
|
|
213
|
-
var pathname = '';
|
|
214
|
-
try { pathname = new URL(request.url).pathname; } catch (_) {}
|
|
215
|
-
var rlKey = 'endpoint:' + (user?.id || __sw_clientIp(request)) + ':' + pathname;
|
|
216
|
-
try {
|
|
217
|
-
var r = await sw.rateLimit.check(rlKey, rateLimit.max, rateLimit.windowSeconds);
|
|
218
|
-
if (!r || r.allowed === false) {
|
|
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.';
|
|
224
|
-
return __sw_mergeHeaders(
|
|
225
|
-
new Response(
|
|
226
|
-
JSON.stringify({ ok: false, error: code, message: message, retry_after: retry }),
|
|
227
|
-
{ status: 429, headers: { 'Content-Type': 'application/json', 'Retry-After': String(retry) } }
|
|
228
|
-
),
|
|
229
|
-
corsHeaders
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
} catch (rlErr) {
|
|
233
|
-
// fail-loudly + fail-CLOSED (tsk_9f22): if the rate-limit check
|
|
234
|
-
// itself errors we used to let the request through — silently
|
|
235
|
-
// disabling the limiter. Block instead. A rate-limited endpoint
|
|
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
|
-
);
|
|
246
|
-
return __sw_mergeHeaders(
|
|
247
|
-
new Response(
|
|
248
|
-
JSON.stringify({ ok: false, error: 'RATE_LIMIT_UNAVAILABLE', message: 'Rate limiting is temporarily unavailable; this request was blocked. Retry shortly.' }),
|
|
249
|
-
{ status: 503, headers: { 'Content-Type': 'application/json', 'Retry-After': String(rateLimit.windowSeconds) } }
|
|
250
|
-
),
|
|
251
|
-
corsHeaders
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Handler. Catches any throw, surfacing { status, code } when
|
|
257
|
-
// present so handler code can throw rich errors without manual
|
|
258
|
-
// Response building.
|
|
259
|
-
try {
|
|
260
|
-
var result = await config.handler(
|
|
261
|
-
{ body: body, user: user, headers: request.headers, params: request.params || {}, request: request },
|
|
262
|
-
sw
|
|
263
|
-
);
|
|
264
|
-
var response;
|
|
265
|
-
if (result instanceof Response) {
|
|
266
|
-
response = result;
|
|
267
|
-
} else if (result === undefined || result === null) {
|
|
268
|
-
response = new Response(null, { status: 204 });
|
|
269
|
-
} else {
|
|
270
|
-
response = new Response(JSON.stringify(result), {
|
|
271
|
-
status: 200,
|
|
272
|
-
headers: { 'Content-Type': 'application/json' },
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return __sw_mergeHeaders(response, corsHeaders);
|
|
276
|
-
} catch (e) {
|
|
277
|
-
return __sw_mergeHeaders(
|
|
278
|
-
__sw_jsonError(e.status || 500, e.code || 'HANDLER_ERROR', e.message || String(e)),
|
|
279
|
-
corsHeaders
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
};
|
|
File without changes
|