@deslop/opm 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
@@ -44833,6 +44833,23 @@ const compressBody = /*#__PURE__*/ dual((args) => isHttpClientRequest(args[0]),
44833
44833
  */
44834
44834
  const bodyJson = /*#__PURE__*/ dual(2, (self, body) => map$6(json$1(body), (body) => setBody$1(self, body)));
44835
44835
  /**
44836
+ * Sets a JSON request body using unsafe JSON encoding.
44837
+ *
44838
+ * **When to use**
44839
+ *
44840
+ * Use when the request body is known to be JSON-serializable and a synchronous
44841
+ * `HttpClientRequest` result is needed.
44842
+ *
44843
+ * **Gotchas**
44844
+ *
44845
+ * JSON encoding may throw instead of failing in the Effect error channel.
44846
+ *
44847
+ * @stability unstable
44848
+ * @category combinators
44849
+ * @since 4.0.0
44850
+ */
44851
+ const bodyJsonUnsafe = /*#__PURE__*/ dual(2, (self, body) => setBody$1(self, jsonUnsafe$1(body)));
44852
+ /**
44836
44853
  * Builds a `URL` from the request URL, query parameters, and hash, returning `Option.none()` if the URL is invalid.
44837
44854
  *
44838
44855
  * @stability unstable
@@ -70926,6 +70943,8 @@ const SecureOrigin = Origin.check(makeFilter((value) => {
70926
70943
  const Port = String$6.check(isPattern(/^\d{1,5}$/u), makeFilter((value) => exists(parse$9(value), (port) => port >= 1 && port <= 65535), { expected: "a port between 1 and 65535" }));
70927
70944
  const AppVersion = String$6.check(isPattern(/^0\.1\.\d+$/u));
70928
70945
  const RuntimeConfig = Struct({
70946
+ auth: optionalKey(String$6),
70947
+ name: String$6,
70929
70948
  traces: String$6,
70930
70949
  version: AppVersion
70931
70950
  });
@@ -71810,7 +71829,7 @@ function layerKeyValueStore(directory) {
71810
71829
  unwrap$8(map$6(dataDirectory, layerKeyValueStore));
71811
71830
  const layerProtocol = mergeAll$1(layerSchemaBinary(), succeed$6(MaxBodySize)(mebibytes(10)));
71812
71831
  const layerTelemetry = unwrap$8(gen(function* () {
71813
- const name = yield* appName;
71832
+ const name = (yield* packageMetadata).name;
71814
71833
  return match$8(yield* option(String$5("OTEL_URL")), {
71815
71834
  onNone: () => empty$10,
71816
71835
  onSome: (url) => layerOtlp(`${name}-server`, url, "server")
@@ -71835,10 +71854,17 @@ const layerRoutes = use((router) => gen(function* () {
71835
71854
  })
71836
71855
  });
71837
71856
  });
71838
- yield* router.add("GET", "/api/runtime", flatMap$3(packageMetadata, (metadata) => schemaJson(RuntimeConfig)({
71839
- traces,
71840
- version: metadata.version
71841
- })));
71857
+ yield* router.add("GET", "/api/runtime", gen(function* () {
71858
+ return yield* schemaJson(RuntimeConfig)({
71859
+ ...match$8(issuer, {
71860
+ onNone: () => ({}),
71861
+ onSome: (origin) => ({ auth: origin })
71862
+ }),
71863
+ name: yield* appName,
71864
+ traces,
71865
+ version: (yield* packageMetadata).version
71866
+ });
71867
+ }));
71842
71868
  yield* router.add("GET", "/auth/sign-in", toIssuer({}));
71843
71869
  yield* router.add("GET", "/auth/sign-out", toIssuer({ "sign-out": "" }));
71844
71870
  yield* router.add("GET", "/auth/user", gen(function* () {
@@ -71850,6 +71876,22 @@ const layerRoutes = use((router) => gen(function* () {
71850
71876
  }, { headers: { "cache-control": "no-store" } });
71851
71877
  }));
71852
71878
  }));
71879
+ const layerAnnounce = effectDiscard(gen(function* () {
71880
+ const origin = new URL(yield* String$5("APP_URL")).origin;
71881
+ const client = filterStatusOk(yield* HttpClient);
71882
+ yield* match$8(yield* option(String$5("AUTH_URL")), {
71883
+ onNone: () => void_$1,
71884
+ onSome: fnUntraced(function* (issuer) {
71885
+ yield* pipe(post(new URL("/api/apps", issuer).href), bodyJsonUnsafe({ origin }), client.execute, delay("2 seconds"), retry({
71886
+ schedule: spaced("1 minute"),
71887
+ times: 60
71888
+ }), ignore$1({
71889
+ log: "Warn",
71890
+ message: "Auth did not list this app"
71891
+ }), forkScoped);
71892
+ })
71893
+ });
71894
+ }));
71853
71895
  function layerIcon(icon) {
71854
71896
  return add$1("GET", "/icon", succeed$5(text$2(icon, {
71855
71897
  contentType: "image/svg+xml",
@@ -71926,17 +71968,20 @@ function systemctl(...args) {
71926
71968
  const unitDirectory = gen(function* () {
71927
71969
  return (yield* Path$1).join(yield* String$5("HOME"), ".config", "systemd", "user");
71928
71970
  });
71929
- const install = fnUntraced(function* (name, command) {
71971
+ const install = fnUntraced(function* (name, command, options) {
71930
71972
  const fs = yield* FileSystem;
71931
71973
  const path = yield* Path$1;
71932
71974
  const home = yield* String$5("HOME");
71933
71975
  const directory = yield* unitDirectory;
71934
71976
  const unit = `deslop-${name}.service`;
71935
71977
  yield* fs.makeDirectory(directory, { recursive: true });
71936
- 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$9(command, systemdArgument), " ")}\nRestart=on-failure\nRestartSec=3\nUMask=0077\n\n[Install]\nWantedBy=default.target\n`, { mode: 384 });
71978
+ 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$9(command, systemdArgument), " ")}\nRestart=on-failure\nRestartSec=3\nUMask=0077\n\n[Install]\nWantedBy=default.target\n`, { mode: 384 });
71937
71979
  yield* systemctl("daemon-reload");
71938
71980
  yield* systemctl("enable", unit);
71939
- yield* systemctl("restart", unit);
71981
+ yield* systemctl(match$1(options?.restart === false, {
71982
+ onFalse: () => "restart",
71983
+ onTrue: () => "start"
71984
+ }), unit);
71940
71985
  return `${unit} installed\n`;
71941
71986
  });
71942
71987
  const installUpdates = fnUntraced(function* (name, command) {
@@ -72059,7 +72104,7 @@ const provider = fnUntraced(function* (given) {
72059
72104
  });
72060
72105
  const layerPlatform = mergeAll$1(layer$4, layer$12, layer$15);
72061
72106
  function server(app) {
72062
- return pipe(serve(pipe(mergeAll$1(app.routes, layerRoutes, layerIcon(app.icon), layerWeb), provide$2(Auth.layer)), {
72107
+ return pipe(serve(pipe(mergeAll$1(app.routes, layerRoutes, layerIcon(app.icon), layerWeb, layerAnnounce), provide$2(Auth.layer)), {
72063
72108
  disableLogger: true,
72064
72109
  middleware: (http) => guard(app.middleware?.(http) ?? http)
72065
72110
  }), provide$2(mergeAll$1(layerProtocol, match$1(app.telemetry === false, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deslop/opm",
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": "30572f69cee0078e4bd9c8f929a460b6e448db7624f390e9bd3256482f5a50ab"
34
+ "fingerprint": "f0a6a219dba5d2aae0c294b8d8ab5585d8b21cb2300eb0a363494c17e03a8261"
35
35
  }