@deslop/auth 0.1.1550 → 0.1.1569

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 CHANGED
@@ -88360,7 +88360,7 @@ const toolJsonSchema = (schema, strict) => {
88360
88360
  * @category layers
88361
88361
  * @since 4.0.0
88362
88362
  */
88363
- const toolkit = (toolkit, options) => effectDiscard(registerToolkit(toolkit, options));
88363
+ const toolkit$1 = (toolkit, options) => effectDiscard(registerToolkit(toolkit, options));
88364
88364
  const makeUriMatcher = () => {
88365
88365
  const router = make$46({
88366
88366
  ignoreTrailingSlash: true,
@@ -98880,7 +98880,30 @@ const FieldOption = /*#__PURE__*/ fieldEvolve({
98880
98880
  jsonCreate: /*#__PURE__*/ map$2(optionalOption),
98881
98881
  jsonUpdate: /*#__PURE__*/ map$2(optionalOption)
98882
98882
  });
98883
- // src/contracts.ts
98883
+ // src/tailnet/contract.ts
98884
+ function exactNumbers(_key, value, context) {
98885
+ if (isNumber(value)) return context?.source;
98886
+ return value;
98887
+ }
98888
+ const TailnetUserId = String$6.check(isPattern(/^\d+$/u));
98889
+ const Profile = Struct$2({
98890
+ DisplayName: String$6,
98891
+ ID: TailnetUserId,
98892
+ LoginName: String$6
98893
+ });
98894
+ const Node = Struct$2({ Tags: optionalKey(NullOr(ArraySchema(String$6))) });
98895
+ const WhoisJson = fromJsonString(Struct$2({
98896
+ Node,
98897
+ UserProfile: Profile
98898
+ }), { reviver: exactNumbers });
98899
+ const StatusJson = fromJsonString(Struct$2({
98900
+ Self: Struct$2({
98901
+ ...Node.fields,
98902
+ UserID: TailnetUserId
98903
+ }),
98904
+ User: Record$1(TailnetUserId, Profile)
98905
+ }), { reviver: exactNumbers });
98906
+ // src/people/contract.ts
98884
98907
  const Role = Literals([
98885
98908
  "Admin",
98886
98909
  "Member",
@@ -98891,10 +98914,6 @@ const Account = Struct$2({
98891
98914
  fullName: OptionFromOptionalKey(String$6),
98892
98915
  role: Role
98893
98916
  });
98894
- const SignedAccount = Struct$2({
98895
- ...Account.fields,
98896
- signOut: Boolean$5
98897
- });
98898
98917
  const Person = Struct$2({
98899
98918
  ...Account.fields,
98900
98919
  since: OptionFromNullOr(DateTimeUtcFromMillis)
@@ -98903,13 +98922,6 @@ const AdmitParams = Struct$2({
98903
98922
  allow: Boolean$5,
98904
98923
  id: UserId
98905
98924
  });
98906
- var ListedSession = class extends Class("ListedSession")({
98907
- address: FieldOption(String$6),
98908
- browser: String$6,
98909
- id: String$6,
98910
- lastSeenAt: DateTimeUtcFromMillis,
98911
- current: Boolean$5
98912
- }) {};
98913
98925
  const PeopleRpcs = make$32(make$36("people.watch", {
98914
98926
  error: AuthError,
98915
98927
  stream: true,
@@ -98919,28 +98931,57 @@ const PeopleRpcs = make$32(make$36("people.watch", {
98919
98931
  payload: AdmitParams,
98920
98932
  success: Person
98921
98933
  }).middleware(RpcAdmin)).middleware(RpcAuth);
98934
+ const MemberStatus = Literals(["Waiting", "Allowed"]);
98935
+ var Member = class extends Class("Member")({
98936
+ fullName: FieldOption(String$6),
98937
+ id: User.fields.id,
98938
+ name: User.fields.name,
98939
+ since: FieldOption(DateTimeUtcFromMillis),
98940
+ status: FieldOption(MemberStatus),
98941
+ tailnet: BooleanFromBit
98942
+ }) {
98943
+ static table = "members";
98944
+ };
98945
+ var Binding = class extends Class("Binding")({
98946
+ tailnetId: TailnetUserId,
98947
+ userId: User.fields.id
98948
+ }) {
98949
+ static table = "tailnet_bindings";
98950
+ };
98951
+ const IdentityRpcs = make$32(make$36("people.account", {
98952
+ error: AuthError,
98953
+ stream: true,
98954
+ success: Struct$2({
98955
+ ...Account.fields,
98956
+ signOut: Boolean$5
98957
+ })
98958
+ }));
98959
+ // src/sessions/contract.ts
98960
+ var ListedSession = class extends Class("ListedSession")({
98961
+ address: FieldOption(String$6),
98962
+ browser: String$6,
98963
+ id: String$6,
98964
+ lastSeenAt: DateTimeUtcFromMillis,
98965
+ current: Boolean$5
98966
+ }) {};
98922
98967
  const SessionsRpcs = make$32(make$36("sessions.watch", {
98923
98968
  error: AuthError,
98924
98969
  stream: true,
98925
98970
  success: ArraySchema(ListedSession)
98926
98971
  })).middleware(RpcAuth);
98927
- const IdentityRpcs = make$32(make$36("people.account", {
98928
- error: AuthError,
98929
- stream: true,
98930
- success: SignedAccount
98931
- }));
98972
+ var CookieSession = class extends Class("CookieSession")({
98973
+ address: FieldOption(String$6),
98974
+ browser: String$6,
98975
+ createdAt: DateTimeUtcFromMillis,
98976
+ id: String$6,
98977
+ lastSeenAt: DateTimeUtcFromMillis,
98978
+ userId: UserId
98979
+ }) {
98980
+ static table = "cookie_sessions";
98981
+ };
98982
+ // src/contracts.ts
98932
98983
  const RpcContracts = PeopleRpcs.merge(SessionsRpcs, IdentityRpcs);
98933
- function parentDomain(canonical) {
98934
- return pipe(new URL(canonical).hostname, split$1("."), drop$1(1), join$3("."));
98935
- }
98936
- function returnTarget(next, canonical, local) {
98937
- return pipe(getSuccess(fromString(next)), filter$5((target) => {
98938
- if (target.username !== "" || target.password !== "") return false;
98939
- if (local) return target.origin === new URL(canonical).origin;
98940
- return target.protocol === "https:" && (target.hostname === parentDomain(canonical) || endsWith(`.${parentDomain(canonical)}`)(target.hostname));
98941
- }), map$13((target) => target.href));
98942
- }
98943
- // src/server/github/schema.ts
98984
+ // src/github/contract.ts
98944
98985
  const GitHubOAuthState = pipe(NonEmptyString, brand("OAuthState"));
98945
98986
  const GitHubClientId = pipe(String$6, brand("GitHubClientId"));
98946
98987
  const AppSignIn = Struct$2({ app: Literals([
@@ -98971,7 +99012,7 @@ const GitHubUser = Struct$2({
98971
99012
  login: NonEmptyString,
98972
99013
  name: OptionFromOptionalNullOr(String$6)
98973
99014
  });
98974
- // src/server/github/pending.ts
99015
+ // src/github/pending.ts
98975
99016
  const NONCE = 24;
98976
99017
  const pendingSignIns = gen(function* () {
98977
99018
  const aead = yield* Aead;
@@ -99003,7 +99044,7 @@ const pendingSignIns = gen(function* () {
99003
99044
  })
99004
99045
  };
99005
99046
  });
99006
- // src/server/github/token.ts
99047
+ // src/github/token.ts
99007
99048
  function accessTokenOf(token) {
99008
99049
  if (!is$2(GitHubRefusal)(token)) return succeed$5(token.access_token);
99009
99050
  if (token.error === "bad_verification_code") return fail$7(AuthError.make({ message: "The sign-in expired; sign in again" }));
@@ -99016,7 +99057,7 @@ function accessTokenOf(token) {
99016
99057
  message: `GitHub could not finish the sign-in: ${token.error}`
99017
99058
  }));
99018
99059
  }
99019
- // src/server/github/service.ts
99060
+ // src/github/server.ts
99020
99061
  const HEADERS = {
99021
99062
  accept: "application/vnd.github+json",
99022
99063
  "user-agent": "@deslop/auth"
@@ -99033,7 +99074,7 @@ function unavailable$1(message) {
99033
99074
  message
99034
99075
  }));
99035
99076
  }
99036
- var GitHub = class GitHub extends Service$1()("@deslop/auth/server/github/service/GitHub") {
99077
+ var GitHub = class GitHub extends Service$1()("@deslop/auth/github/server/GitHub") {
99037
99078
  static layer = effect(GitHub, gen(function* () {
99038
99079
  const CALLBACK = new URL("/auth/github/callback", yield* String$5("APP_URL")).href;
99039
99080
  const sealing = yield* pendingSignIns;
@@ -99118,75 +99159,7 @@ var GitHub = class GitHub extends Service$1()("@deslop/auth/server/github/servic
99118
99159
  });
99119
99160
  }));
99120
99161
  };
99121
- // src/server/http.ts
99122
- function authResponse(effect) {
99123
- return pipe(effect, catchIf$2(is$2(AuthError), (error) => succeed$5(text(error.message, failureOptions(error, 401)))), map$7(setHeader("cache-control", "no-store")));
99124
- }
99125
- // src/server/people/roles.ts
99126
- const ROLE_ORDER = {
99127
- Admin: 1,
99128
- Member: 2,
99129
- Waiting: 0
99130
- };
99131
- function isAdmin(admins, id) {
99132
- return some(admins, (admin) => `github:${admin}` === id);
99133
- }
99134
- function isLetIn(member, browser) {
99135
- return contains$2(member.status, "Allowed") || !browser && member.tailnet;
99136
- }
99137
- const authorizeMember = fnUntraced(function* (admins, id, row, browser) {
99138
- if (isAdmin(admins, id)) return {
99139
- admin: true,
99140
- id,
99141
- name: match$8(row, {
99142
- onNone: () => id,
99143
- onSome: (member) => member.name
99144
- })
99145
- };
99146
- return yield* pipe(row, filter$5((member) => isLetIn(member, browser)), match$8({
99147
- onNone: () => AuthError.make({
99148
- error: "access_denied",
99149
- message: "An admin has not allowed this account yet"
99150
- }),
99151
- onSome: (member) => succeed$5({
99152
- admin: false,
99153
- id: member.id,
99154
- name: member.name
99155
- })
99156
- }));
99157
- });
99158
- function roleOf(admins, id, row, browser) {
99159
- if (isAdmin(admins, id)) return "Admin";
99160
- if (exists(row, (found) => isLetIn(found, browser))) return "Member";
99161
- return "Waiting";
99162
- }
99163
- function listedRoleOf(admins, row) {
99164
- if (isAdmin(admins, row.id)) return "Admin";
99165
- if (contains$2(row.status, "Waiting")) return "Waiting";
99166
- return "Member";
99167
- }
99168
- function personOf(admins, row) {
99169
- return Person.make({
99170
- admin: isAdmin(admins, row.id),
99171
- ...pick(row, ["id", "name"]),
99172
- fullName: filter$5(row.fullName, isNonEmpty$1),
99173
- role: listedRoleOf(admins, row),
99174
- since: row.since
99175
- });
99176
- }
99177
- function listPeople(rows, admins) {
99178
- const known = map$10(rows, (row) => personOf(admins, row));
99179
- const knownIds = fromIterable(map$10(known, (person) => person.id));
99180
- return sort([...pipe(admins, filter$3((id) => !has(knownIds, `github:${id}`)), map$10((id) => Person.make({
99181
- admin: true,
99182
- fullName: none(),
99183
- id: UserId.make(`github:${id}`),
99184
- name: `GitHub ${id}`,
99185
- role: "Admin",
99186
- since: none()
99187
- }))), ...known], mapInput(Order$4, (person) => ROLE_ORDER[person.role]));
99188
- }
99189
- // src/server/people/migrations.ts
99162
+ // src/people/migrations.ts
99190
99163
  const peopleMigrations = effectDiscard(make$26({})({
99191
99164
  loader: fromRecord({
99192
99165
  "0001_members": flatMap$3(SqlClient, (sql) => sql`CREATE TABLE members (id TEXT PRIMARY KEY, name TEXT NOT NULL, fullName TEXT, incarnation TEXT NOT NULL, since INTEGER NOT NULL, status TEXT NOT NULL) STRICT`),
@@ -99223,48 +99196,7 @@ const peopleMigrations = effectDiscard(make$26({})({
99223
99196
  }),
99224
99197
  table: "members_migrations"
99225
99198
  }));
99226
- // src/server/tailnet/schema.ts
99227
- function exactNumbers(_key, value, context) {
99228
- if (isNumber(value)) return context?.source;
99229
- return value;
99230
- }
99231
- const TailnetUserId = String$6.check(isPattern(/^\d+$/u));
99232
- const Profile = Struct$2({
99233
- DisplayName: String$6,
99234
- ID: TailnetUserId,
99235
- LoginName: String$6
99236
- });
99237
- const Node = Struct$2({ Tags: optionalKey(NullOr(ArraySchema(String$6))) });
99238
- const WhoisJson = fromJsonString(Struct$2({
99239
- Node,
99240
- UserProfile: Profile
99241
- }), { reviver: exactNumbers });
99242
- const StatusJson = fromJsonString(Struct$2({
99243
- Self: Struct$2({
99244
- ...Node.fields,
99245
- UserID: TailnetUserId
99246
- }),
99247
- User: Record$1(TailnetUserId, Profile)
99248
- }), { reviver: exactNumbers });
99249
- // src/server/people/schema.ts
99250
- const MemberStatus = Literals(["Waiting", "Allowed"]);
99251
- var Member = class extends Class("Member")({
99252
- fullName: FieldOption(String$6),
99253
- id: User.fields.id,
99254
- name: User.fields.name,
99255
- since: FieldOption(DateTimeUtcFromMillis),
99256
- status: FieldOption(MemberStatus),
99257
- tailnet: BooleanFromBit
99258
- }) {
99259
- static table = "members";
99260
- };
99261
- var Binding = class extends Class("Binding")({
99262
- tailnetId: TailnetUserId,
99263
- userId: User.fields.id
99264
- }) {
99265
- static table = "tailnet_bindings";
99266
- };
99267
- // src/server/sessions/migrations.ts
99199
+ // src/sessions/migrations.ts
99268
99200
  const sessionsMigrations = effectDiscard(make$26({})({
99269
99201
  loader: fromRecord({
99270
99202
  "0001_cookie_sessions": flatMap$3(SqlClient, (sql) => sql`CREATE TABLE cookie_sessions (id TEXT PRIMARY KEY, userId TEXT NOT NULL, address TEXT, browser TEXT NOT NULL, createdAt INTEGER NOT NULL, lastSeenAt INTEGER NOT NULL) STRICT`),
@@ -99272,19 +99204,8 @@ const sessionsMigrations = effectDiscard(make$26({})({
99272
99204
  }),
99273
99205
  table: "cookie_sessions_migrations"
99274
99206
  }));
99275
- // src/server/sessions/schema.ts
99276
- var CookieSession = class extends Class("CookieSession")({
99277
- address: FieldOption(String$6),
99278
- browser: String$6,
99279
- createdAt: DateTimeUtcFromMillis,
99280
- id: String$6,
99281
- lastSeenAt: DateTimeUtcFromMillis,
99282
- userId: UserId
99283
- }) {
99284
- static table = "cookie_sessions";
99285
- };
99286
- // src/server/sessions/service.ts
99287
- var Sessions = class Sessions extends Service$1()("@deslop/auth/server/sessions/service/Sessions") {
99207
+ // src/sessions/server.ts
99208
+ var Sessions = class Sessions extends Service$1()("@deslop/auth/sessions/server/Sessions") {
99288
99209
  static migrations = sessionsMigrations;
99289
99210
  static layer = provide$2(effect(Sessions, gen(function* () {
99290
99211
  const sql = yield* SqlClient;
@@ -99351,13 +99272,76 @@ var Sessions = class Sessions extends Service$1()("@deslop/auth/server/sessions/
99351
99272
  });
99352
99273
  })), Sessions.migrations);
99353
99274
  };
99354
- // src/server/people/service.ts
99275
+ // src/people/server.ts
99276
+ const ROLE_ORDER = {
99277
+ Admin: 1,
99278
+ Member: 2,
99279
+ Waiting: 0
99280
+ };
99355
99281
  const adminIds = gen(function* () {
99356
99282
  const listed = Array$1(GitHubIdFromString, "GITHUB_ADMINS");
99357
99283
  if (yield* localAuth) return yield* withDefault$2(listed, [GitHubId.make(0)]);
99358
99284
  return yield* listed;
99359
99285
  });
99360
- var People = class People extends Service$1()("@deslop/auth/server/people/service/People") {
99286
+ function isAdmin(admins, id) {
99287
+ return some(admins, (admin) => `github:${admin}` === id);
99288
+ }
99289
+ function isLetIn(member, browser) {
99290
+ return contains$2(member.status, "Allowed") || !browser && member.tailnet;
99291
+ }
99292
+ const authorizeMember = fnUntraced(function* (admins, id, row, browser) {
99293
+ if (isAdmin(admins, id)) return {
99294
+ admin: true,
99295
+ id,
99296
+ name: match$8(row, {
99297
+ onNone: () => id,
99298
+ onSome: (member) => member.name
99299
+ })
99300
+ };
99301
+ return yield* pipe(row, filter$5((member) => isLetIn(member, browser)), match$8({
99302
+ onNone: () => AuthError.make({
99303
+ error: "access_denied",
99304
+ message: "An admin has not allowed this account yet"
99305
+ }),
99306
+ onSome: (member) => succeed$5({
99307
+ admin: false,
99308
+ id: member.id,
99309
+ name: member.name
99310
+ })
99311
+ }));
99312
+ });
99313
+ function roleOf(admins, id, row, browser) {
99314
+ if (isAdmin(admins, id)) return "Admin";
99315
+ if (exists(row, (found) => isLetIn(found, browser))) return "Member";
99316
+ return "Waiting";
99317
+ }
99318
+ function listedRoleOf(admins, row) {
99319
+ if (isAdmin(admins, row.id)) return "Admin";
99320
+ if (contains$2(row.status, "Waiting")) return "Waiting";
99321
+ return "Member";
99322
+ }
99323
+ function personOf(admins, row) {
99324
+ return Person.make({
99325
+ admin: isAdmin(admins, row.id),
99326
+ ...pick(row, ["id", "name"]),
99327
+ fullName: filter$5(row.fullName, isNonEmpty$1),
99328
+ role: listedRoleOf(admins, row),
99329
+ since: row.since
99330
+ });
99331
+ }
99332
+ function listPeople(rows, admins) {
99333
+ const known = map$10(rows, (row) => personOf(admins, row));
99334
+ const knownIds = fromIterable(map$10(known, (person) => person.id));
99335
+ return sort([...pipe(admins, filter$3((id) => !has(knownIds, `github:${id}`)), map$10((id) => Person.make({
99336
+ admin: true,
99337
+ fullName: none(),
99338
+ id: UserId.make(`github:${id}`),
99339
+ name: `GitHub ${id}`,
99340
+ role: "Admin",
99341
+ since: none()
99342
+ }))), ...known], mapInput(Order$4, (person) => ROLE_ORDER[person.role]));
99343
+ }
99344
+ var People = class People extends Service$1()("@deslop/auth/people/server/People") {
99361
99345
  static migrations = peopleMigrations;
99362
99346
  static layer = provide$2(effect(People, gen(function* () {
99363
99347
  const sql = yield* SqlClient;
@@ -99453,7 +99437,7 @@ var People = class People extends Service$1()("@deslop/auth/server/people/servic
99453
99437
  });
99454
99438
  })), People.migrations);
99455
99439
  };
99456
- // src/server/tailnet/service.ts
99440
+ // src/tailnet/server.ts
99457
99441
  function unavailable(message) {
99458
99442
  return mapError$2((cause) => {
99459
99443
  if (is$2(AppError)(cause) && includes("peer not found")(cause.message)) return AuthError.make({
@@ -99467,7 +99451,7 @@ function unavailable(message) {
99467
99451
  });
99468
99452
  });
99469
99453
  }
99470
- var Tailnet = class Tailnet extends Service$1()("@deslop/auth/server/tailnet/service/Tailnet") {
99454
+ var Tailnet = class Tailnet extends Service$1()("@deslop/auth/tailnet/server/Tailnet") {
99471
99455
  static layer = effect(Tailnet, gen(function* () {
99472
99456
  const spawner = yield* ChildProcessSpawner;
99473
99457
  const status = yield* makeWith(() => pipe(executeProcess("tailscale", ["status", "--json"], { timeout: "10 seconds" }), flatMap$3(decodeUnknownEffect(StatusJson)), provideService$2(ChildProcessSpawner, spawner), unavailable("Cannot read the tailnet owner")), {
@@ -99494,7 +99478,7 @@ var Tailnet = class Tailnet extends Service$1()("@deslop/auth/server/tailnet/ser
99494
99478
  });
99495
99479
  }));
99496
99480
  };
99497
- // src/server/identity/service.ts
99481
+ // src/identity/server.ts
99498
99482
  function isMachine(address) {
99499
99483
  return some(values(networkInterfaces()), (entries) => entries !== void 0 && some(entries, (entry) => entry.address === address));
99500
99484
  }
@@ -99502,7 +99486,7 @@ const TAILNET = [fromStringUnsafe("100.64.0.0/10"), fromStringUnsafe("fd7a:115c:
99502
99486
  function isTailnet(address) {
99503
99487
  return exists(getSuccess(ipFromString(address)), (ip) => some(TAILNET, (network) => contains(network, ip)));
99504
99488
  }
99505
- var Identity = class Identity extends Service$1()("@deslop/auth/server/identity/service/Identity") {
99489
+ var Identity = class Identity extends Service$1()("@deslop/auth/identity/server/Identity") {
99506
99490
  static layer = effect(Identity, gen(function* () {
99507
99491
  const people = yield* People;
99508
99492
  const sessions = yield* Sessions;
@@ -99594,8 +99578,19 @@ var Identity = class Identity extends Service$1()("@deslop/auth/server/identity/
99594
99578
  return Identity.of({ resolve });
99595
99579
  }));
99596
99580
  };
99597
- // src/server/identity/http.ts
99598
- const IdentityHttp = use((router) => gen(function* () {
99581
+ // src/identity/handlers.ts
99582
+ function authResponse(effect) {
99583
+ return pipe(effect, catchIf$2(is$2(AuthError), (error) => succeed$5(text(error.message, failureOptions(error, 401)))), map$7(setHeader("cache-control", "no-store")));
99584
+ }
99585
+ const identityHandlers = IdentityRpcs.toLayer(gen(function* () {
99586
+ const identity = yield* Identity;
99587
+ const sql = yield* SqlClient;
99588
+ return { "people.account": (_, options) => buffer$1(sql.reactive(["people", "sessions"], identity.resolve(identifyRequestOf(options.headers), true)), {
99589
+ capacity: 1,
99590
+ strategy: "sliding"
99591
+ }) };
99592
+ }));
99593
+ const identityHttp = use((router) => gen(function* () {
99599
99594
  const identity = yield* Identity;
99600
99595
  yield* router.add("POST", IDENTIFY_PATH, authResponse(gen(function* () {
99601
99596
  if (!isMachine((yield* HttpServerRequest).headers["x-deslop-client"] ?? "")) return text("Only this machine may identify callers", { status: 403 });
@@ -99606,31 +99601,8 @@ const IdentityHttp = use((router) => gen(function* () {
99606
99601
  }))));
99607
99602
  })));
99608
99603
  }));
99609
- // src/server/identity/rpcs.ts
99610
- const IdentityRpcHandlers = IdentityRpcs.toLayer(gen(function* () {
99611
- const identity = yield* Identity;
99612
- const sql = yield* SqlClient;
99613
- return { "people.account": (_, options) => buffer$1(sql.reactive(["people", "sessions"], identity.resolve(identifyRequestOf(options.headers), true)), {
99614
- capacity: 1,
99615
- strategy: "sliding"
99616
- }) };
99617
- }));
99618
- // src/server/people/rpcs.ts
99619
- const PeopleRpcHandlers = PeopleRpcs.toLayer(gen(function* () {
99620
- const people = yield* People;
99621
- const sql = yield* SqlClient;
99622
- return {
99623
- "people.admit": fnUntraced(function* (input) {
99624
- return yield* people.admit(input, yield* CurrentAdmin);
99625
- }),
99626
- "people.watch": () => unwrap$4(map$7(CurrentAdmin, (admin) => buffer$1(sql.reactive(["people"], people.list(admin)), {
99627
- capacity: 1,
99628
- strategy: "sliding"
99629
- })))
99630
- };
99631
- }));
99632
- // src/server/people/tools.ts
99633
- const PeopleTools = make$13(make$14("list_people", {
99604
+ // src/people/handlers.ts
99605
+ const peopleTools = make$13(make$14("list_people", {
99634
99606
  dependencies: [CurrentUser],
99635
99607
  description: "List people and access requests. Only admins may list people.",
99636
99608
  failure: AuthError,
@@ -99643,7 +99615,7 @@ const PeopleTools = make$13(make$14("list_people", {
99643
99615
  parameters: Struct$2({ id: UserId }),
99644
99616
  success: Person
99645
99617
  }).annotate(Destructive, true).annotate(Strict, true));
99646
- const PeopleToolHandlers = PeopleTools.toLayer(map$7(People, (people) => ({
99618
+ const peopleToolHandlers = peopleTools.toLayer(map$7(People, (people) => ({
99647
99619
  list_people: fnUntraced(function* () {
99648
99620
  return { people: yield* people.list(yield* requireAdmin(yield* CurrentUser, "Only an admin can manage people")) };
99649
99621
  }),
@@ -99651,31 +99623,21 @@ const PeopleToolHandlers = PeopleTools.toLayer(map$7(People, (people) => ({
99651
99623
  return yield* people.remove(input.id, yield* requireAdmin(yield* CurrentUser, "Only an admin can manage people"));
99652
99624
  })
99653
99625
  })));
99654
- // src/server/sessions/rpcs.ts
99655
- const SessionsRpcHandlers = SessionsRpcs.toLayer(gen(function* () {
99656
- const sessions = yield* Sessions;
99626
+ const peopleHandlers = PeopleRpcs.toLayer(gen(function* () {
99627
+ const people = yield* People;
99657
99628
  const sql = yield* SqlClient;
99658
- return { "sessions.watch": (_, options) => unwrap$4(gen(function* () {
99659
- const user = yield* CurrentUser;
99660
- const own = yield* match$8(identifyRequestOf(options.headers).session, {
99661
- onNone: () => succeedNone,
99662
- onSome: sessions.current
99663
- });
99664
- const listed = map$7(sessions.list(user.id), map$10((row) => ListedSession.make({
99665
- address: row.address,
99666
- browser: row.browser,
99667
- current: exists(own, (found) => found.id === row.id),
99668
- id: row.id,
99669
- lastSeenAt: row.lastSeenAt
99670
- })));
99671
- return pipe(tick("1 minute"), switchMap(() => sql.reactive(["sessions"], listed)), changesWith(toEquivalence(ArraySchema(ListedSession))), buffer$1({
99629
+ return {
99630
+ "people.admit": fnUntraced(function* (input) {
99631
+ return yield* people.admit(input, yield* CurrentAdmin);
99632
+ }),
99633
+ "people.watch": () => unwrap$4(map$7(CurrentAdmin, (admin) => buffer$1(sql.reactive(["people"], people.list(admin)), {
99672
99634
  capacity: 1,
99673
99635
  strategy: "sliding"
99674
- }));
99675
- })) };
99636
+ })))
99637
+ };
99676
99638
  }));
99677
- // src/server/sessions/tools.ts
99678
- const SessionTools = make$13(make$14("list_sessions", {
99639
+ // src/sessions/handlers.ts
99640
+ const sessionsTools = make$13(make$14("list_sessions", {
99679
99641
  dependencies: [CurrentUser],
99680
99642
  description: "List your browser sessions, newest activity first.",
99681
99643
  failure: AuthError,
@@ -99688,7 +99650,7 @@ const SessionTools = make$13(make$14("list_sessions", {
99688
99650
  parameters: Struct$2({ id: String$6 }),
99689
99651
  success: Struct$2({ id: String$6 })
99690
99652
  }).annotate(Destructive, true).annotate(Strict, true));
99691
- const SessionToolHandlers = SessionTools.toLayer(map$7(Sessions, (sessions) => ({
99653
+ const sessionsToolHandlers = sessionsTools.toLayer(map$7(Sessions, (sessions) => ({
99692
99654
  list_sessions: fnUntraced(function* () {
99693
99655
  return { sessions: yield* sessions.list((yield* CurrentUser).id) };
99694
99656
  }),
@@ -99697,11 +99659,44 @@ const SessionToolHandlers = SessionTools.toLayer(map$7(Sessions, (sessions) => (
99697
99659
  return { id: input.id };
99698
99660
  })
99699
99661
  })));
99700
- // src/server/sign-ins/service.ts
99662
+ const sessionsHandlers = SessionsRpcs.toLayer(gen(function* () {
99663
+ const sessions = yield* Sessions;
99664
+ const sql = yield* SqlClient;
99665
+ return { "sessions.watch": (_, options) => unwrap$4(gen(function* () {
99666
+ const user = yield* CurrentUser;
99667
+ const own = yield* match$8(identifyRequestOf(options.headers).session, {
99668
+ onNone: () => succeedNone,
99669
+ onSome: sessions.current
99670
+ });
99671
+ const listed = map$7(sessions.list(user.id), map$10((row) => ListedSession.make({
99672
+ address: row.address,
99673
+ browser: row.browser,
99674
+ current: exists(own, (found) => found.id === row.id),
99675
+ id: row.id,
99676
+ lastSeenAt: row.lastSeenAt
99677
+ })));
99678
+ return pipe(tick("1 minute"), switchMap(() => sql.reactive(["sessions"], listed)), changesWith(toEquivalence(ArraySchema(ListedSession))), buffer$1({
99679
+ capacity: 1,
99680
+ strategy: "sliding"
99681
+ }));
99682
+ })) };
99683
+ }));
99684
+ // src/sign-ins/shared.ts
99685
+ function parentDomain(canonical) {
99686
+ return pipe(new URL(canonical).hostname, split$1("."), drop$1(1), join$3("."));
99687
+ }
99688
+ function returnTarget(next, canonical, local) {
99689
+ return pipe(getSuccess(fromString(next)), filter$5((target) => {
99690
+ if (target.username !== "" || target.password !== "") return false;
99691
+ if (local) return target.origin === new URL(canonical).origin;
99692
+ return target.protocol === "https:" && (target.hostname === parentDomain(canonical) || endsWith(`.${parentDomain(canonical)}`)(target.hostname));
99693
+ }), map$13((target) => target.href));
99694
+ }
99695
+ // src/sign-ins/server.ts
99701
99696
  function loginCookie(state) {
99702
99697
  return `__Host-login-${state}`;
99703
99698
  }
99704
- var SignIns = class SignIns extends Service$1()("@deslop/auth/server/sign-ins/service/SignIns") {
99699
+ var SignIns = class SignIns extends Service$1()("@deslop/auth/sign-ins/server/SignIns") {
99705
99700
  static layer = effect(SignIns, gen(function* () {
99706
99701
  const github = yield* GitHub;
99707
99702
  const people = yield* People;
@@ -99800,7 +99795,7 @@ var SignIns = class SignIns extends Service$1()("@deslop/auth/server/sign-ins/se
99800
99795
  });
99801
99796
  }));
99802
99797
  };
99803
- // src/server/sign-ins/http.ts
99798
+ // src/sign-ins/handlers.ts
99804
99799
  const COOKIE = {
99805
99800
  httpOnly: true,
99806
99801
  path: "/",
@@ -99808,7 +99803,7 @@ const COOKIE = {
99808
99803
  secure: true
99809
99804
  };
99810
99805
  const association = { webcredentials: { apps: flatMap$6(AppSignIn.fields.app.literals, (slug) => map$10(["", ".dev"], (suffix) => `99K7MQUK7F.xyz.mp281x.${slug}${suffix}`)) } };
99811
- const SignInsHttp = use((router) => gen(function* () {
99806
+ const signInsHttp = use((router) => gen(function* () {
99812
99807
  const signIns = yield* SignIns;
99813
99808
  const canonical = yield* String$5("APP_URL");
99814
99809
  const sessionCookie = {
@@ -99842,20 +99837,20 @@ const SignInsHttp = use((router) => gen(function* () {
99842
99837
  }));
99843
99838
  // src/web/icon.svg
99844
99839
  var icon_default = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\" shape-rendering=\"crispEdges\"><path fill=\"#000\" fill-opacity=\".18\" d=\"M12 41h1v1h-1zM10 42h3v1h-3zM8 43h4v1h-4zM10 44h4v1h-4zM12 45h4v1h-4zM14 46h4v1h-4zM16 47h4v1h-4zM51 47h1v1h-1zM18 48h4v1h-4zM51 48h3v1h-3zM20 49h4v1h-4zM52 49h4v1h-4zM22 50h4v1h-4zM50 50h4v1h-4zM24 51h4v1h-4zM48 51h4v1h-4zM26 52h4v1h-4zM46 52h4v1h-4zM28 53h4v1h-4zM44 53h4v1h-4zM30 54h4v1h-4zM42 54h4v1h-4zM32 55h4v1h-4zM40 55h4v1h-4zM34 56h8v1h-8zM36 57h4v1h-4z\"/><path fill=\"#000\" fill-opacity=\".38\" d=\"M12 43h2v1h-2zM14 44h1v1h-1zM16 45h1v1h-1zM18 46h1v1h-1zM20 47h1v1h-1zM22 48h1v1h-1zM24 49h1v1h-1zM50 49h2v1h-2zM26 50h1v1h-1zM49 50h1v1h-1zM28 51h1v1h-1zM47 51h1v1h-1zM30 52h1v1h-1zM45 52h1v1h-1zM32 53h1v1h-1zM43 53h1v1h-1zM34 54h1v1h-1zM41 54h1v1h-1zM36 55h1v1h-1zM39 55h1v1h-1z\"/><path fill=\"#565961\" d=\"M25 7h4v1h-4zM24 8h1v1h-1zM29 8h2v1h-2zM24 9h1v1h-1zM31 9h2v1h-2zM24 10h1v1h-1zM33 10h2v1h-2zM23 11h1v1h-1zM35 11h2v1h-2zM23 12h1v1h-1zM37 12h2v1h-2zM23 13h1v1h-1zM39 13h1v1h-1zM23 14h1v1h-1zM29 14h2v1h-2zM39 14h1v1h-1zM23 15h1v1h-1zM29 15h1v1h-1zM31 15h2v1h-2zM39 15h1v1h-1zM23 16h1v1h-1zM29 16h1v1h-1zM33 16h2v1h-2zM39 16h1v1h-1zM29 17h1v1h-1zM34 17h1v1h-1zM40 17h1v1h-1zM34 18h1v1h-1zM40 18h1v1h-1zM34 19h1v1h-1zM40 19h1v1h-1zM40 20h1v1h-1zM40 21h1v1h-1zM40 22h1v1h-1z\"/><path fill=\"#dcdfe6\" d=\"M25 8h2v1h-2zM27 9h2v1h-2zM29 10h2v1h-2zM31 11h2v1h-2zM33 12h2v1h-2zM35 13h4v1h-4z\"/><path fill=\"#c8cbd6\" d=\"M27 8h2v1h-2zM29 9h2v1h-2zM31 10h2v1h-2zM33 11h2v1h-2zM35 12h2v1h-2zM37 17h2v1h-2z\"/><path fill=\"#B4B8C4\" d=\"M25 9h2v1h-2zM25 10h4v1h-4zM24 11h7v1h-7zM24 12h9v1h-9zM24 13h3v1h-3zM29 13h6v1h-6zM24 14h3v1h-3zM31 14h6v1h-6zM24 15h3v1h-3zM33 15h4v1h-4zM24 16h3v1h-3zM35 16h2v1h-2zM24 17h3v1h-3zM35 17h2v1h-2zM24 18h3v1h-3zM35 18h3v1h-3zM24 19h3v1h-3zM35 19h3v1h-3zM24 20h3v1h-3zM35 20h3v1h-3zM24 21h3v1h-3zM35 21h3v1h-3zM24 22h3v1h-3zM35 22h3v1h-3zM25 23h2v1h-2zM35 23h3v1h-3zM35 24h3v1h-3zM35 25h3v1h-3zM35 26h3v1h-3zM35 27h3v1h-3zM35 28h3v1h-3zM37 29h1v1h-1z\"/><path fill=\"#868a95\" d=\"M27 13h2v1h-2zM27 14h2v1h-2zM37 14h2v1h-2zM27 15h2v1h-2zM37 15h2v1h-2zM27 16h2v1h-2zM37 16h2v1h-2zM27 17h2v1h-2zM39 17h1v1h-1zM27 18h2v1h-2zM38 18h2v1h-2zM27 19h2v1h-2zM38 19h2v1h-2zM27 20h2v1h-2zM38 20h2v1h-2zM27 21h2v1h-2zM38 21h2v1h-2zM27 22h2v1h-2zM38 22h2v1h-2zM27 23h2v1h-2zM38 23h2v1h-2zM38 24h2v1h-2zM38 25h2v1h-2zM38 26h2v1h-2zM38 27h2v1h-2zM38 28h2v1h-2zM38 29h1v1h-1z\"/><path fill=\"#434d61\" d=\"M23 17h1v1h-1zM21 18h2v1h-2zM29 18h2v1h-2zM19 19h2v1h-2zM31 19h2v1h-2zM17 20h2v1h-2zM33 20h2v1h-2zM15 21h2v1h-2zM14 22h1v1h-1zM13 23h1v1h-1zM40 23h1v1h-1zM13 24h1v1h-1zM41 24h2v1h-2zM13 25h1v1h-1zM43 25h2v1h-2zM13 26h1v1h-1zM45 26h2v1h-2zM13 27h1v1h-1zM47 27h2v1h-2zM13 28h1v1h-1zM49 28h1v1h-1zM13 29h1v1h-1zM50 29h1v1h-1zM13 30h1v1h-1zM50 30h1v1h-1zM13 31h1v1h-1zM50 31h1v1h-1zM13 32h1v1h-1zM50 32h1v1h-1zM13 33h1v1h-1zM50 33h1v1h-1zM13 34h1v1h-1zM50 34h1v1h-1zM13 35h1v1h-1zM50 35h1v1h-1zM13 36h1v1h-1zM50 36h1v1h-1zM13 37h1v1h-1zM50 37h1v1h-1zM13 38h1v1h-1zM50 38h1v1h-1zM13 39h1v1h-1zM50 39h1v1h-1zM13 40h1v1h-1zM50 40h1v1h-1zM13 41h1v1h-1zM50 41h1v1h-1zM13 42h1v1h-1zM50 42h1v1h-1zM14 43h1v1h-1zM50 43h1v1h-1zM15 44h2v1h-2zM50 44h1v1h-1zM17 45h2v1h-2zM50 45h1v1h-1zM19 46h2v1h-2zM50 46h1v1h-1zM21 47h2v1h-2zM50 47h1v1h-1zM23 48h2v1h-2zM49 48h2v1h-2zM25 49h2v1h-2zM47 49h3v1h-3zM27 50h2v1h-2zM45 50h4v1h-4zM29 51h2v1h-2zM43 51h4v1h-4zM31 52h2v1h-2zM41 52h4v1h-4zM33 53h2v1h-2zM39 53h4v1h-4zM35 54h2v1h-2zM38 54h3v1h-3zM37 55h2v1h-2z\"/><path fill=\"#b2bed9\" d=\"M23 18h1v1h-1zM21 19h3v1h-3zM29 19h2v1h-2zM19 20h5v1h-5zM29 20h4v1h-4zM17 21h7v1h-7zM29 21h6v1h-6zM15 22h9v1h-9zM29 22h6v1h-6zM17 23h8v1h-8zM29 23h6v1h-6zM19 24h16v1h-16zM40 24h1v1h-1zM21 25h14v1h-14zM40 25h3v1h-3zM23 26h12v1h-12zM40 26h5v1h-5zM25 27h10v1h-10zM40 27h7v1h-7zM27 28h8v1h-8zM40 28h9v1h-9zM29 29h8v1h-8zM39 29h8v1h-8zM31 30h14v1h-14zM33 31h10v1h-10zM35 32h6v1h-6zM37 33h2v1h-2zM37 35h1v1h-1zM37 36h1v1h-1zM37 37h1v1h-1zM37 38h1v1h-1zM37 39h1v1h-1zM37 40h1v1h-1zM37 41h1v1h-1zM37 42h1v1h-1zM37 43h1v1h-1zM37 44h1v1h-1zM37 45h1v1h-1zM37 46h1v1h-1zM37 47h1v1h-1zM37 48h1v1h-1zM37 49h1v1h-1zM37 50h1v1h-1zM37 51h1v1h-1zM37 52h1v1h-1zM37 53h1v1h-1z\"/><path fill=\"#9CABCA\" d=\"M14 23h1v1h-1zM14 24h3v1h-3zM14 25h5v1h-5zM14 26h7v1h-7zM14 27h9v1h-9zM14 28h11v1h-11zM14 29h13v1h-13zM14 30h15v1h-15zM14 31h17v1h-17zM14 32h12v1h-12zM27 32h6v1h-6zM14 33h11v1h-11zM28 33h7v1h-7zM14 34h11v1h-11zM29 34h8v1h-8zM14 35h12v1h-12zM29 35h8v1h-8zM14 36h12v1h-12zM28 36h9v1h-9zM14 37h12v1h-12zM28 37h9v1h-9zM14 38h13v1h-13zM28 38h9v1h-9zM14 39h23v1h-23zM14 40h23v1h-23zM14 41h23v1h-23zM15 42h22v1h-22zM17 43h20v1h-20zM19 44h18v1h-18zM21 45h16v1h-16zM23 46h14v1h-14zM25 47h12v1h-12zM27 48h10v1h-10zM29 49h8v1h-8zM31 50h6v1h-6zM33 51h4v1h-4zM35 52h2v1h-2z\"/><path fill=\"#c9d1e5\" d=\"M15 23h2v1h-2zM17 24h2v1h-2zM19 25h2v1h-2zM21 26h2v1h-2zM23 27h2v1h-2zM25 28h2v1h-2zM27 29h2v1h-2zM47 29h2v1h-2zM29 30h2v1h-2zM45 30h2v1h-2zM31 31h2v1h-2zM43 31h2v1h-2zM33 32h2v1h-2zM41 32h2v1h-2zM35 33h2v1h-2zM39 33h2v1h-2zM37 34h2v1h-2z\"/><path fill=\"#707d99\" d=\"M49 29h1v1h-1zM47 30h3v1h-3zM45 31h5v1h-5zM43 32h7v1h-7zM41 33h9v1h-9zM39 34h11v1h-11zM38 35h12v1h-12zM38 36h12v1h-12zM38 37h12v1h-12zM38 38h12v1h-12zM38 39h12v1h-12zM38 40h12v1h-12zM38 41h12v1h-12zM38 42h12v1h-12zM38 43h12v1h-12zM38 44h12v1h-12zM38 45h12v1h-12zM38 46h12v1h-12zM38 47h12v1h-12zM38 48h11v1h-11zM38 49h9v1h-9zM38 50h7v1h-7zM38 51h5v1h-5zM38 52h3v1h-3zM38 53h1v1h-1z\"/><path fill=\"#16161D\" d=\"M26 32h1v1h-1zM25 33h3v1h-3zM25 34h4v1h-4zM26 35h3v1h-3zM26 36h2v1h-2zM26 37h2v1h-2zM27 38h1v1h-1z\"/><path fill=\"#8795b2\" d=\"M14 42h1v1h-1zM15 43h2v1h-2zM17 44h2v1h-2zM19 45h2v1h-2zM21 46h2v1h-2zM23 47h2v1h-2zM25 48h2v1h-2zM27 49h2v1h-2zM29 50h2v1h-2zM31 51h2v1h-2zM33 52h2v1h-2zM35 53h2v1h-2zM37 54h1v1h-1z\"/></svg>";
99845
- // src/server/main.ts
99840
+ // src/server.ts
99846
99841
  const layerServices = pipe(SignIns.layer, provideMerge(Identity.layer), provide$2(Tailnet.layer), provideMerge(People.layer), provideMerge(mergeAll$1(Sessions.layer, GitHub.layer)), provide$2(succeed$6(RequestInit, { redirect: "error" })));
99847
- const tools = merge(PeopleTools, SessionTools);
99842
+ const toolkit = merge(peopleTools, sessionsTools);
99848
99843
  runApp({
99849
99844
  auth: provide$2(effectContext(map$7(Identity, (identity) => Auth.makeContext((headers) => withSpan(identity.resolve(identifyRequestOf(headers)), "Identity.account")))), layerServices),
99850
99845
  icon: icon_default,
99851
99846
  middleware: (app) => map$7(app, setHeader("content-security-policy", "frame-ancestors 'none'")),
99852
- routes: provide$2(mergeAll$1(IdentityHttp, SignInsHttp, layerRpc({
99847
+ routes: provide$2(mergeAll$1(identityHttp, signInsHttp, layerRpc({
99853
99848
  group: RpcContracts,
99854
- handlers: mergeAll$1(IdentityRpcHandlers, PeopleRpcHandlers, SessionsRpcHandlers)
99849
+ handlers: mergeAll$1(identityHandlers, peopleHandlers, sessionsHandlers)
99855
99850
  }), layerMcp({
99856
- contracts: tools,
99851
+ contracts: toolkit,
99857
99852
  instructions: "Manage people as an admin, and list or sign out your browser sessions.",
99858
- registrations: provide$2(toolkit(tools), merge$4(PeopleToolHandlers, SessionToolHandlers))
99853
+ registrations: provide$2(toolkit$1(toolkit), merge$4(peopleToolHandlers, sessionsToolHandlers))
99859
99854
  })), layerServices),
99860
99855
  settings: {
99861
99856
  GITHUB_ADMINS: {