@deslop/auth 0.1.1290 → 0.1.1295
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/server.js +98 -15
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --max-old-space-size=16384 --heapsnapshot-near-heap-limit=3 --report-on-fatalerror
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as OS from "node:os";
|
|
4
|
+
import { userInfo } from "node:os";
|
|
4
5
|
import * as NodeChildProcess from "node:child_process";
|
|
5
6
|
import { Duplex, PassThrough, Readable, Transform, finished, pipeline } from "node:stream";
|
|
6
7
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
@@ -15,7 +16,7 @@ import { createZstdDecompress } from "node:zlib";
|
|
|
15
16
|
import * as NodeUrl from "node:url";
|
|
16
17
|
import { fileURLToPath } from "node:url";
|
|
17
18
|
import * as readline from "node:readline";
|
|
18
|
-
import { cwd, execPath } from "node:process";
|
|
19
|
+
import { cwd, execPath, platform } from "node:process";
|
|
19
20
|
import { createServer } from "node:http";
|
|
20
21
|
// \0rolldown/runtime.js
|
|
21
22
|
var __create = Object.create;
|
|
@@ -91981,7 +91982,7 @@ const decodeUnverified = /*#__PURE__*/ fnUntraced(function* (token) {
|
|
|
91981
91982
|
});
|
|
91982
91983
|
// ../../packages/runtime/src/auth/sessions.ts
|
|
91983
91984
|
const Stored = Struct({
|
|
91984
|
-
access: NonEmptyString,
|
|
91985
|
+
access: RedactedFromValue(NonEmptyString),
|
|
91985
91986
|
clientId: NonEmptyString,
|
|
91986
91987
|
createdAt: Finite,
|
|
91987
91988
|
expiresAt: Finite,
|
|
@@ -92032,7 +92033,7 @@ var Sessions = class Sessions extends Service$1()("@deslop/runtime/auth/sessions
|
|
|
92032
92033
|
const claims = yield* decodeUnknownEffect(AccessClaims)((yield* decodeUnverified(tokens.access_token)).claims);
|
|
92033
92034
|
const now = yield* currentTimeMillis;
|
|
92034
92035
|
return Stored.make({
|
|
92035
|
-
access: tokens.access_token,
|
|
92036
|
+
access: make$63(tokens.access_token),
|
|
92036
92037
|
clientId,
|
|
92037
92038
|
createdAt,
|
|
92038
92039
|
expiresAt: now + tokens.expires_in * 1e3,
|
|
@@ -92064,14 +92065,14 @@ var Sessions = class Sessions extends Service$1()("@deslop/runtime/auth/sessions
|
|
|
92064
92065
|
value
|
|
92065
92066
|
}))), { concurrency: "unbounded" });
|
|
92066
92067
|
for (const session of matchingSessions(saved, userId)) {
|
|
92067
|
-
if (yield* fresh(session.value)) return session.value.access;
|
|
92068
|
+
if (yield* fresh(session.value)) return value$2(session.value.access);
|
|
92068
92069
|
const renewed = yield* result$1(pipe(refreshed(session.key), rejected("AI access is temporarily unavailable")));
|
|
92069
|
-
if (renewed._tag === "Success") return renewed.success.access;
|
|
92070
|
+
if (renewed._tag === "Success") return value$2(renewed.success.access);
|
|
92070
92071
|
if (is$2(AuthError)(renewed.failure) && renewed.failure.error === "temporarily_unavailable") return yield* renewed.failure;
|
|
92071
92072
|
}
|
|
92072
92073
|
const now = yield* currentTimeMillis;
|
|
92073
92074
|
const bearer = getOrUndefined$1(filter$8(get$11(bearers, userId), (access) => access.expiresAt >= now + 6e4));
|
|
92074
|
-
if (bearer !== void 0) return bearer.token;
|
|
92075
|
+
if (bearer !== void 0) return value$2(bearer.token);
|
|
92075
92076
|
remove$5(bearers, userId);
|
|
92076
92077
|
return yield* AuthError.make({ message: `Open ${capitalize(split$2(new URL(app).hostname, ".")[0])} once so it can use AI for you` });
|
|
92077
92078
|
}, rejected("AI access is temporarily unavailable"));
|
|
@@ -92080,12 +92081,12 @@ var Sessions = class Sessions extends Service$1()("@deslop/runtime/auth/sessions
|
|
|
92080
92081
|
const key = yield* keyOf(id);
|
|
92081
92082
|
const saved = yield* fromOption(yield* store.get(key));
|
|
92082
92083
|
if (yield* fresh(saved)) return {
|
|
92083
|
-
token: saved.access,
|
|
92084
|
+
token: value$2(saved.access),
|
|
92084
92085
|
user: saved.user
|
|
92085
92086
|
};
|
|
92086
92087
|
const renewed = yield* refreshed(key);
|
|
92087
92088
|
return {
|
|
92088
|
-
token: renewed.access,
|
|
92089
|
+
token: value$2(renewed.access),
|
|
92089
92090
|
user: renewed.user
|
|
92090
92091
|
};
|
|
92091
92092
|
}, rejected("Sign in first")),
|
|
@@ -92105,7 +92106,7 @@ var Sessions = class Sessions extends Service$1()("@deslop/runtime/auth/sessions
|
|
|
92105
92106
|
remember: (token, claims) => sync(() => {
|
|
92106
92107
|
set$5(bearers, claims.sub, {
|
|
92107
92108
|
expiresAt: claims.exp * 1e3,
|
|
92108
|
-
token
|
|
92109
|
+
token: make$63(token)
|
|
92109
92110
|
});
|
|
92110
92111
|
}),
|
|
92111
92112
|
start: fn("Sessions.start")(function* (grant) {
|
|
@@ -92598,10 +92599,7 @@ var AppError = class extends TaggedError()("AppError", {
|
|
|
92598
92599
|
cause: optional$8(Defect()),
|
|
92599
92600
|
message: String$6
|
|
92600
92601
|
}) {};
|
|
92601
|
-
// ../../packages/runtime/src/cli/
|
|
92602
|
-
function systemdArgument(value) {
|
|
92603
|
-
return `"${pipe(value, replaceAll("\\", "\\\\"), replaceAll("\"", "\\\""), replaceAll("%", "%%"), replaceAll("$", "$$$$"), replaceAll("\n", "\\n"), replaceAll("\r", "\\r"))}"`;
|
|
92604
|
-
}
|
|
92602
|
+
// ../../packages/runtime/src/cli/command.ts
|
|
92605
92603
|
const execute = fnUntraced(function* (command, args) {
|
|
92606
92604
|
const process = yield* make$62(command, args, {
|
|
92607
92605
|
stderr: "pipe",
|
|
@@ -92615,6 +92613,86 @@ const execute = fnUntraced(function* (command, args) {
|
|
|
92615
92613
|
if (result.code !== 0) return yield* AppError.make({ message: `${command} failed: ${result.stderr}` });
|
|
92616
92614
|
return result.stdout;
|
|
92617
92615
|
}, scoped);
|
|
92616
|
+
// ../../packages/runtime/src/cli/launchd.ts
|
|
92617
|
+
function xml(value) {
|
|
92618
|
+
return pipe(value, replaceAll("&", "&"), replaceAll("<", "<"), replaceAll(">", ">"), replaceAll("\"", """), replaceAll("'", "'"));
|
|
92619
|
+
}
|
|
92620
|
+
function domain() {
|
|
92621
|
+
return `gui/${userInfo().uid}`;
|
|
92622
|
+
}
|
|
92623
|
+
function launchctl(...args) {
|
|
92624
|
+
return execute("launchctl", args);
|
|
92625
|
+
}
|
|
92626
|
+
function bootout(file) {
|
|
92627
|
+
return launchctl("bootout", domain(), file);
|
|
92628
|
+
}
|
|
92629
|
+
const loaded = fnUntraced(function* (target) {
|
|
92630
|
+
const process = yield* make$62("launchctl", ["print", target], {
|
|
92631
|
+
stderr: "pipe",
|
|
92632
|
+
stdout: "ignore"
|
|
92633
|
+
});
|
|
92634
|
+
const result = yield* all$1({
|
|
92635
|
+
code: process.exitCode,
|
|
92636
|
+
stderr: mkString(decodeText$1(process.stderr))
|
|
92637
|
+
}, { concurrency: "unbounded" });
|
|
92638
|
+
if (result.code === 113) return false;
|
|
92639
|
+
if (result.code !== 0) return yield* AppError.make({ message: `launchctl failed: ${result.stderr}` });
|
|
92640
|
+
return true;
|
|
92641
|
+
}, scoped);
|
|
92642
|
+
const agentDirectory = gen(function* () {
|
|
92643
|
+
return (yield* Path$1).join(yield* String$5("HOME"), "Library", "LaunchAgents");
|
|
92644
|
+
});
|
|
92645
|
+
const writeAgent = fnUntraced(function* (label, name, command, schedule) {
|
|
92646
|
+
const fs = yield* FileSystem;
|
|
92647
|
+
const path = yield* Path$1;
|
|
92648
|
+
const home = yield* String$5("HOME");
|
|
92649
|
+
const directory = yield* agentDirectory;
|
|
92650
|
+
const args = [
|
|
92651
|
+
execPath,
|
|
92652
|
+
`--env-file-if-exists=${home}/.deslop/${name}.env`,
|
|
92653
|
+
...drop$1(command, 1)
|
|
92654
|
+
];
|
|
92655
|
+
const file = path.join(directory, `${label}.plist`);
|
|
92656
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
92657
|
+
yield* fs.writeFileString(file, `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n<key>Label</key><string>${xml(label)}</string>\n<key>ProgramArguments</key>\n<array>\n${join$2(map$8(args, (arg) => `<string>${xml(arg)}</string>`), "\n")}\n</array>\n<key>EnvironmentVariables</key>\n<dict>\n<key>NODE_ENV</key><string>production</string>\n<key>PATH</key><string>${xml(`${home}/.vite-plus/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`)}</string>\n</dict>\n<key>Umask</key><integer>63</integer>\n${schedule}\n</dict>\n</plist>\n`, { mode: 384 });
|
|
92658
|
+
return file;
|
|
92659
|
+
});
|
|
92660
|
+
const installAgent = fnUntraced(function* (name, command) {
|
|
92661
|
+
const label = `deslop-${name}`;
|
|
92662
|
+
const target = `${domain()}/${label}`;
|
|
92663
|
+
const file = yield* writeAgent(label, name, command, "<key>RunAtLoad</key><true/>\n<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>\n<key>ThrottleInterval</key><integer>3</integer>");
|
|
92664
|
+
if (yield* loaded(target)) yield* bootout(file);
|
|
92665
|
+
yield* launchctl("bootstrap", domain(), file);
|
|
92666
|
+
return `${label}.plist installed\n`;
|
|
92667
|
+
});
|
|
92668
|
+
const installUpdateAgent = fnUntraced(function* (name, command) {
|
|
92669
|
+
const label = `deslop-${name}-update`;
|
|
92670
|
+
const target = `${domain()}/${label}`;
|
|
92671
|
+
const file = yield* writeAgent(label, name, command, "<key>StartInterval</key><integer>900</integer>");
|
|
92672
|
+
if (yield* loaded(target)) yield* bootout(file);
|
|
92673
|
+
yield* launchctl("bootstrap", domain(), file);
|
|
92674
|
+
});
|
|
92675
|
+
const uninstallAgents = fnUntraced(function* (name) {
|
|
92676
|
+
const fs = yield* FileSystem;
|
|
92677
|
+
const path = yield* Path$1;
|
|
92678
|
+
const directory = yield* agentDirectory;
|
|
92679
|
+
yield* forEach$1([`deslop-${name}-update`, `deslop-${name}`], fnUntraced(function* (label) {
|
|
92680
|
+
const file = path.join(directory, `${label}.plist`);
|
|
92681
|
+
if (yield* loaded(`${domain()}/${label}`)) yield* bootout(file);
|
|
92682
|
+
yield* fs.remove(file, { force: true });
|
|
92683
|
+
}), { concurrency: 1 });
|
|
92684
|
+
return `deslop-${name}.plist removed; application data preserved\n`;
|
|
92685
|
+
});
|
|
92686
|
+
function agentStatus(name) {
|
|
92687
|
+
return pipe(launchctl("print", `${domain()}/deslop-${name}`), map$5((output) => `${join$2(map$8(filter$6(split$2(output, "\n"), (line) => isSome(match$3(/^\s*(?:path|state|pid|last exit code|last terminating signal) =/u)(line))), trim), "\n")}\n`));
|
|
92688
|
+
}
|
|
92689
|
+
function restartAgent(name) {
|
|
92690
|
+
return pipe(launchctl("kickstart", "-k", `${domain()}/deslop-${name}`), timeout$1("30 seconds"));
|
|
92691
|
+
}
|
|
92692
|
+
// ../../packages/runtime/src/cli/service.ts
|
|
92693
|
+
function systemdArgument(value) {
|
|
92694
|
+
return `"${pipe(value, replaceAll("\\", "\\\\"), replaceAll("\"", "\\\""), replaceAll("%", "%%"), replaceAll("$", "$$$$"), replaceAll("\n", "\\n"), replaceAll("\r", "\\r"))}"`;
|
|
92695
|
+
}
|
|
92618
92696
|
function systemctl(...args) {
|
|
92619
92697
|
return execute("systemctl", ["--user", ...args]);
|
|
92620
92698
|
}
|
|
@@ -92622,6 +92700,7 @@ const unitDirectory = gen(function* () {
|
|
|
92622
92700
|
return (yield* Path$1).join(yield* String$5("HOME"), ".config", "systemd", "user");
|
|
92623
92701
|
});
|
|
92624
92702
|
const install = fnUntraced(function* (name, command, options) {
|
|
92703
|
+
if (platform === "darwin") return yield* installAgent(name, command);
|
|
92625
92704
|
const fs = yield* FileSystem;
|
|
92626
92705
|
const path = yield* Path$1;
|
|
92627
92706
|
const home = yield* String$5("HOME");
|
|
@@ -92638,6 +92717,7 @@ const install = fnUntraced(function* (name, command, options) {
|
|
|
92638
92717
|
return `${unit} installed\n`;
|
|
92639
92718
|
});
|
|
92640
92719
|
const installUpdates = fnUntraced(function* (name, command) {
|
|
92720
|
+
if (platform === "darwin") return yield* installUpdateAgent(name, command);
|
|
92641
92721
|
const fs = yield* FileSystem;
|
|
92642
92722
|
const path = yield* Path$1;
|
|
92643
92723
|
const directory = yield* unitDirectory;
|
|
@@ -92648,6 +92728,7 @@ const installUpdates = fnUntraced(function* (name, command) {
|
|
|
92648
92728
|
yield* systemctl("enable", "--now", `${unit}.timer`);
|
|
92649
92729
|
});
|
|
92650
92730
|
const uninstall = fnUntraced(function* (name) {
|
|
92731
|
+
if (platform === "darwin") return yield* uninstallAgents(name);
|
|
92651
92732
|
const fs = yield* FileSystem;
|
|
92652
92733
|
const path = yield* Path$1;
|
|
92653
92734
|
const directory = yield* unitDirectory;
|
|
@@ -92661,9 +92742,11 @@ const uninstall = fnUntraced(function* (name) {
|
|
|
92661
92742
|
return `deslop-${name}.service removed; application data preserved\n`;
|
|
92662
92743
|
});
|
|
92663
92744
|
function status(name) {
|
|
92745
|
+
if (platform === "darwin") return agentStatus(name);
|
|
92664
92746
|
return systemctl("show", `deslop-${name}.service`, "--property=LoadState,ActiveState,SubState,MainPID");
|
|
92665
92747
|
}
|
|
92666
92748
|
function restart(name) {
|
|
92749
|
+
if (platform === "darwin") return restartAgent(name);
|
|
92667
92750
|
return pipe(systemctl("restart", `deslop-${name}.service`), timeout$1("30 seconds"));
|
|
92668
92751
|
}
|
|
92669
92752
|
// ../../packages/runtime/src/cli/update.ts
|
|
@@ -93147,7 +93230,7 @@ function originFrom(headers, remote) {
|
|
|
93147
93230
|
function clientLabel(name) {
|
|
93148
93231
|
return pipe(name, replace(/\s*\([^)]*\)$/u, ""), trim, capitalize, liftPredicate(isNonEmpty$1), getOrElse(() => "Unknown client"));
|
|
93149
93232
|
}
|
|
93150
|
-
function platform(userAgent) {
|
|
93233
|
+
function platform$1(userAgent) {
|
|
93151
93234
|
if (includes("iPhone")(userAgent)) return some$1("iPhone");
|
|
93152
93235
|
if (includes("iPad")(userAgent)) return some$1("iPad");
|
|
93153
93236
|
if (includes("CFNetwork/")(userAgent)) return some$1("iPhone");
|
|
@@ -93169,7 +93252,7 @@ function deviceLabel(origin) {
|
|
|
93169
93252
|
return pipe(flatMap$7(fromUndefinedOr(origin.address), (address) => {
|
|
93170
93253
|
if (exists(parsedAddress(address), (ip) => isLinkLocal(ip) || isLoopback(ip) || isPrivateAddress(ip))) return some$1("dev");
|
|
93171
93254
|
return get$13(WORKERS, address);
|
|
93172
|
-
}), orElse$3(() => flatMap$7(fromUndefinedOr(origin.userAgent), platform)), getOrElse(() => origin.address ?? "unknown"));
|
|
93255
|
+
}), orElse$3(() => flatMap$7(fromUndefinedOr(origin.userAgent), platform$1)), getOrElse(() => origin.address ?? "unknown"));
|
|
93173
93256
|
}
|
|
93174
93257
|
function loopback(redirect) {
|
|
93175
93258
|
return filter$8(getSuccess(fromString(redirect)), (target) => target.protocol === "http:" && contains([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deslop/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1295",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/MP281X/deslop.git",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=26"
|
|
35
35
|
},
|
|
36
|
-
"fingerprint": "
|
|
36
|
+
"fingerprint": "89ef823add14f0d17f7af584110c04bf4739d954fa31cf77728000bc8a71967b"
|
|
37
37
|
}
|