wirl 0.2.5 → 0.2.6

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 (3) hide show
  1. package/bin.js +2240 -1989
  2. package/package.json +1 -1
  3. package/serve-module.mjs +26 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirl",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Deploy an internal app somewhere real, privately. One command; sharing by email; API keys declared, never pasted.",
5
5
  "keywords": [
6
6
  "deploy",
package/serve-module.mjs CHANGED
@@ -315,6 +315,7 @@ var handler = loaded?.default?.fetch;
315
315
  if (typeof handler !== "function") die(`${modulePath} has no default export with a fetch.`);
316
316
  var localDb = process.env.WIRL_LOCAL_DB;
317
317
  var env = localDb ? { DB: createLocalDatabase(localDb) } : {};
318
+ if (process.env.WIRL_DEPLOYMENT) env.WIRL_DEPLOYMENT = process.env.WIRL_DEPLOYMENT;
318
319
  var devIdentity = null;
319
320
  if (process.env.WIRL_DEV_IDENTITY) {
320
321
  try {
@@ -326,6 +327,7 @@ if (process.env.WIRL_DEV_IDENTITY) {
326
327
  var SCHEDULE_PREFIX = "/__wirl/schedule/";
327
328
  var FLOW_PREFIX = "/__wirl/flow/";
328
329
  var FLOW_ONLY_HEADERS = ["x-wirl-flow", "x-wirl-step", "x-wirl-n", "x-wirl-idempotency-key"];
330
+ var OWNER_EMAIL_HEADER = "x-wirl-app-owner-email";
329
331
  var STEP_WORD = /^[A-Za-z0-9_-]{1,100}$/;
330
332
  function flowStepOf(body) {
331
333
  let posted = null;
@@ -345,15 +347,25 @@ function idempotencyKeyOf(appId, { run, n, step }) {
345
347
  var VISITOR_HEADERS = ["x-wirl-user-id", "x-wirl-user-email", "x-wirl-user-name", "x-wirl-role"];
346
348
  var publicPaths = [];
347
349
  if (process.env.WIRL_DEV_PUBLIC_PATHS) {
350
+ let given;
348
351
  try {
349
- publicPaths = JSON.parse(process.env.WIRL_DEV_PUBLIC_PATHS);
352
+ given = JSON.parse(process.env.WIRL_DEV_PUBLIC_PATHS);
350
353
  } catch {
351
354
  die("WIRL_DEV_PUBLIC_PATHS is not valid JSON.");
352
355
  }
356
+ publicPaths = (Array.isArray(given) ? given : []).flatMap((entry) => {
357
+ if (typeof entry === "string") return [{ path: entry, verify: null }];
358
+ if (entry !== null && typeof entry === "object" && typeof entry.path === "string") {
359
+ const verify = typeof entry.verify === "string" && entry.verify !== "" && entry.verify !== "none" ? entry.verify : null;
360
+ return [{ path: entry.path, verify }];
361
+ }
362
+ return [];
363
+ });
353
364
  }
354
- var isPublicPath = (pathname) => publicPaths.some(
355
- (path) => path.endsWith("/*") ? pathname.startsWith(path.slice(0, -1)) : pathname === path
356
- );
365
+ var publicPathFor = (pathname) => publicPaths.find(
366
+ ({ path }) => path.endsWith("/*") ? pathname.startsWith(path.slice(0, -1)) : pathname === path
367
+ ) ?? null;
368
+ var isPublicPath = (pathname) => publicPathFor(pathname) !== null;
357
369
  var staticFiles = null;
358
370
  if (process.env.WIRL_DEV_STATIC) {
359
371
  try {
@@ -455,11 +467,16 @@ createServer(async (incoming, outgoing) => {
455
467
  const pathname = (incoming.url ?? "/").split("?")[0] ?? "/";
456
468
  let flowStep = null;
457
469
  for (const name of FLOW_ONLY_HEADERS) headers.delete(name);
470
+ headers.delete(OWNER_EMAIL_HEADER);
471
+ headers.delete("x-wirl-dev");
472
+ headers.delete("x-wirl-verified");
473
+ const ownerEmail = typeof devIdentity.email === "string" ? devIdentity.email : "";
458
474
  if (pathname.startsWith(SCHEDULE_PREFIX)) {
459
475
  for (const name of VISITOR_HEADERS) headers.set(name, "");
460
476
  headers.set("x-wirl-schedule", pathname.slice(SCHEDULE_PREFIX.length));
461
477
  headers.set("x-wirl-run", "dev");
462
478
  headers.set("x-wirl-attempt", "1");
479
+ if (ownerEmail !== "") headers.set(OWNER_EMAIL_HEADER, ownerEmail);
463
480
  } else if (pathname.startsWith(FLOW_PREFIX)) {
464
481
  for (const name of VISITOR_HEADERS) headers.set(name, "");
465
482
  flowStep = flowStepOf(Buffer.concat(chunks));
@@ -468,9 +485,14 @@ createServer(async (incoming, outgoing) => {
468
485
  headers.set("x-wirl-step", flowStep.step);
469
486
  headers.set("x-wirl-n", String(flowStep.n));
470
487
  headers.set("x-wirl-attempt", String(flowStep.attempt));
488
+ if (ownerEmail !== "") headers.set(OWNER_EMAIL_HEADER, ownerEmail);
471
489
  } else if (isPublicPath(pathname)) {
472
490
  for (const name of VISITOR_HEADERS) headers.set(name, "");
473
491
  headers.set("x-wirl-public", "1");
492
+ const { verify } = publicPathFor(pathname);
493
+ if (verify !== null) headers.set("x-wirl-verified", verify);
494
+ else headers.delete("x-wirl-verified");
495
+ headers.set("x-wirl-dev", "1");
474
496
  } else {
475
497
  fillIn("x-wirl-user-id", devIdentity.userId ?? "");
476
498
  fillIn("x-wirl-user-email", devIdentity.email ?? "");