@deslop/scope 0.1.1223 → 0.1.1228

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 (2) hide show
  1. package/dist/server.js +54 -9
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -51040,6 +51040,23 @@ const compressBody = /*#__PURE__*/ dual((args) => isHttpClientRequest(args[0]),
51040
51040
  return map$5(compressBody$1(self.body, algorithm, options), (body) => body === self.body ? self : makeWith$1(self.method, self.url, self.urlParams, self.hash, set$1(updateContentLength(self.headers, body), "content-encoding", algorithm), body));
51041
51041
  });
51042
51042
  /**
51043
+ * Sets a JSON request body using unsafe JSON encoding.
51044
+ *
51045
+ * **When to use**
51046
+ *
51047
+ * Use when the request body is known to be JSON-serializable and a synchronous
51048
+ * `HttpClientRequest` result is needed.
51049
+ *
51050
+ * **Gotchas**
51051
+ *
51052
+ * JSON encoding may throw instead of failing in the Effect error channel.
51053
+ *
51054
+ * @stability unstable
51055
+ * @category combinators
51056
+ * @since 4.0.0
51057
+ */
51058
+ const bodyJsonUnsafe = /*#__PURE__*/ dual(2, (self, body) => setBody$1(self, jsonUnsafe$1(body)));
51059
+ /**
51043
51060
  * Builds a `URL` from the request URL, query parameters, and hash, returning `Option.none()` if the URL is invalid.
51044
51061
  *
51045
51062
  * @stability unstable
@@ -85386,6 +85403,8 @@ const SecureOrigin = Origin.check(makeFilter((value) => {
85386
85403
  const Port = String$6.check(isPattern(/^\d{1,5}$/u), makeFilter((value) => exists(parse$2(value), (port) => port >= 1 && port <= 65535), { expected: "a port between 1 and 65535" }));
85387
85404
  const AppVersion = String$6.check(isPattern(/^0\.1\.\d+$/u));
85388
85405
  const RuntimeConfig = Struct({
85406
+ auth: optionalKey(String$6),
85407
+ name: String$6,
85389
85408
  traces: String$6,
85390
85409
  version: AppVersion
85391
85410
  });
@@ -86293,7 +86312,7 @@ function layerKeyValueStore(directory) {
86293
86312
  unwrap$7(map$5(dataDirectory, layerKeyValueStore));
86294
86313
  const layerProtocol = mergeAll$1(layerSchemaBinary(), succeed$6(MaxBodySize)(mebibytes(10)));
86295
86314
  const layerTelemetry = unwrap$7(gen(function* () {
86296
- const name = yield* appName;
86315
+ const name = (yield* packageMetadata).name;
86297
86316
  return match$8(yield* option(String$5("OTEL_URL")), {
86298
86317
  onNone: () => empty$10,
86299
86318
  onSome: (url) => layerOtlp(`${name}-server`, url, "server")
@@ -86318,10 +86337,17 @@ const layerRoutes = use((router) => gen(function* () {
86318
86337
  })
86319
86338
  });
86320
86339
  });
86321
- yield* router.add("GET", "/api/runtime", flatMap$2(packageMetadata, (metadata) => schemaJson(RuntimeConfig)({
86322
- traces,
86323
- version: metadata.version
86324
- })));
86340
+ yield* router.add("GET", "/api/runtime", gen(function* () {
86341
+ return yield* schemaJson(RuntimeConfig)({
86342
+ ...match$8(issuer, {
86343
+ onNone: () => ({}),
86344
+ onSome: (origin) => ({ auth: origin })
86345
+ }),
86346
+ name: yield* appName,
86347
+ traces,
86348
+ version: (yield* packageMetadata).version
86349
+ });
86350
+ }));
86325
86351
  yield* router.add("GET", "/auth/sign-in", toIssuer({}));
86326
86352
  yield* router.add("GET", "/auth/sign-out", toIssuer({ "sign-out": "" }));
86327
86353
  yield* router.add("GET", "/auth/user", gen(function* () {
@@ -86333,6 +86359,22 @@ const layerRoutes = use((router) => gen(function* () {
86333
86359
  }, { headers: { "cache-control": "no-store" } });
86334
86360
  }));
86335
86361
  }));
86362
+ const layerAnnounce = effectDiscard(gen(function* () {
86363
+ const origin = new URL(yield* String$5("APP_URL")).origin;
86364
+ const client = filterStatusOk(yield* HttpClient);
86365
+ yield* match$8(yield* option(String$5("AUTH_URL")), {
86366
+ onNone: () => void_$1,
86367
+ onSome: fnUntraced(function* (issuer) {
86368
+ yield* pipe(post(new URL("/api/apps", issuer).href), bodyJsonUnsafe({ origin }), client.execute, delay("2 seconds"), retry({
86369
+ schedule: spaced("1 minute"),
86370
+ times: 60
86371
+ }), ignore$1({
86372
+ log: "Warn",
86373
+ message: "Auth did not list this app"
86374
+ }), forkScoped);
86375
+ })
86376
+ });
86377
+ }));
86336
86378
  function layerIcon(icon) {
86337
86379
  return add("GET", "/icon", succeed$5(text(icon, {
86338
86380
  contentType: "image/svg+xml",
@@ -86439,17 +86481,20 @@ function systemctl(...args) {
86439
86481
  const unitDirectory = gen(function* () {
86440
86482
  return (yield* Path$1).join(yield* String$5("HOME"), ".config", "systemd", "user");
86441
86483
  });
86442
- const install = fnUntraced(function* (name, command) {
86484
+ const install = fnUntraced(function* (name, command, options) {
86443
86485
  const fs = yield* FileSystem;
86444
86486
  const path = yield* Path$1;
86445
86487
  const home = yield* String$5("HOME");
86446
86488
  const directory = yield* unitDirectory;
86447
86489
  const unit = `deslop-${name}.service`;
86448
86490
  yield* fs.makeDirectory(directory, { recursive: true });
86449
- yield* fs.writeFileString(path.join(directory, unit), `[Unit]\nDescription=Deslop ${name}\nAfter=network-online.target\n\n[Service]\nType=simple\nEnvironment=NODE_ENV=production\nEnvironment=${systemdArgument(`PATH=${home}/.vite-plus/bin:/usr/local/bin:/usr/bin:/bin`)}\nEnvironmentFile=-${systemdArgument(`${home}/.deslop/${name}.env`)}\nExecStart=${join$2(map$8(command, systemdArgument), " ")}\nRestart=on-failure\nRestartSec=3\nUMask=0077\n\n[Install]\nWantedBy=default.target\n`, { mode: 384 });
86491
+ yield* fs.writeFileString(path.join(directory, unit), `[Unit]\nDescription=Deslop ${name}\nAfter=network-online.target\n\n[Service]\nType=simple\nEnvironment=NODE_ENV=production\nEnvironment=${systemdArgument(`PATH=${home}/.vite-plus/bin:/usr/local/bin:/usr/bin:/bin`)}\nEnvironmentFile=-${replaceAll("%", "%%")(`${home}/.deslop/${name}.env`)}\nExecStart=${join$2(map$8(command, systemdArgument), " ")}\nRestart=on-failure\nRestartSec=3\nUMask=0077\n\n[Install]\nWantedBy=default.target\n`, { mode: 384 });
86450
86492
  yield* systemctl("daemon-reload");
86451
86493
  yield* systemctl("enable", unit);
86452
- yield* systemctl("restart", unit);
86494
+ yield* systemctl(match$1(options?.restart === false, {
86495
+ onFalse: () => "restart",
86496
+ onTrue: () => "start"
86497
+ }), unit);
86453
86498
  return `${unit} installed\n`;
86454
86499
  });
86455
86500
  const installUpdates = fnUntraced(function* (name, command) {
@@ -86572,7 +86617,7 @@ const provider = fnUntraced(function* (given) {
86572
86617
  });
86573
86618
  const layerPlatform = mergeAll$1(layer$3, layer$16, layer$13);
86574
86619
  function server(app) {
86575
- return pipe(serve(pipe(mergeAll$1(app.routes, layerRoutes, layerIcon(app.icon), layerWeb), provide$2(Auth.layer)), {
86620
+ return pipe(serve(pipe(mergeAll$1(app.routes, layerRoutes, layerIcon(app.icon), layerWeb, layerAnnounce), provide$2(Auth.layer)), {
86576
86621
  disableLogger: true,
86577
86622
  middleware: (http) => guard(app.middleware?.(http) ?? http)
86578
86623
  }), provide$2(mergeAll$1(layerProtocol, match$1(app.telemetry === false, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deslop/scope",
3
- "version": "0.1.1223",
3
+ "version": "0.1.1228",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MP281X/deslop",
@@ -31,5 +31,5 @@
31
31
  "engines": {
32
32
  "node": ">=26"
33
33
  },
34
- "fingerprint": "9ca31803c8c95cd5b8e0e26078bcc5a1cc5c4201c91111e2942ca39fe508cac1"
34
+ "fingerprint": "763e00c7c5f4f244233a2062bc61311fe78b2133b21400e5ceb1d4f7eaf8e33d"
35
35
  }