@remit/auth-service 0.0.15 → 0.1.0

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.
@@ -1,6 +1,6 @@
1
1
  // The five better-auth identity tables, in the shape better-auth's drizzle
2
2
  // adapter emits with `provider: "sqlite"`. Used to generate the committed
3
- // sqlite migrations (deploy/vps/migrations-sqlite/auth).
3
+ // sqlite migrations (deploy/vps/migrations-sqlite/app).
4
4
  //
5
5
  // Hand-maintained, deliberately. The `@better-auth/cli generate` command no
6
6
  // longer emits this shape: it writes `mode: "timestamp_ms"` where these columns
@@ -10,7 +10,14 @@
10
10
  // every deployed instance and rewrite all five tables. Match better-auth's
11
11
  // runtime expectations by hand when a version bump changes them, and let
12
12
  // vps-migrations-drift.sqlite.test.ts catch the migration side.
13
- import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
13
+ import { sql } from "drizzle-orm";
14
+ import {
15
+ index,
16
+ integer,
17
+ sqliteTable,
18
+ text,
19
+ uniqueIndex,
20
+ } from "drizzle-orm/sqlite-core";
14
21
 
15
22
  export const auth_user = sqliteTable("auth_user", {
16
23
  id: text("id").primaryKey(),
@@ -27,6 +34,10 @@ export const auth_user = sqliteTable("auth_user", {
27
34
  .$defaultFn(() => /* @__PURE__ */ new Date())
28
35
  .$onUpdate(() => /* @__PURE__ */ new Date())
29
36
  .notNull(),
37
+ disabled: integer("disabled", { mode: "boolean" }).default(false).notNull(),
38
+ lastSignInAt: integer("last_sign_in_at", { mode: "timestamp" })
39
+ .default(sql`0`)
40
+ .notNull(),
30
41
  });
31
42
 
32
43
  export const auth_session = sqliteTable(
@@ -104,4 +115,39 @@ export const auth_jwks = sqliteTable("auth_jwks", {
104
115
  privateKey: text("private_key").notNull(),
105
116
  createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
106
117
  expiresAt: integer("expires_at", { mode: "timestamp" }),
118
+ alg: text("alg"),
119
+ crv: text("crv"),
107
120
  });
121
+
122
+ // Not better-auth tables: the self-host People operations own these
123
+ // (packages/auth-service/src/people.ts). Times are epoch milliseconds.
124
+ export const identity_audit_event = sqliteTable(
125
+ "identity_audit_event",
126
+ {
127
+ auditEventId: text("audit_event_id").primaryKey(),
128
+ occurredAt: integer("occurred_at", { mode: "timestamp_ms" }).notNull(),
129
+ actor: text("actor").notNull(),
130
+ target: text("target").notNull(),
131
+ action: text("action").notNull(),
132
+ outcome: text("outcome").notNull(),
133
+ clientIp: text("client_ip").notNull(),
134
+ },
135
+ (table) => [
136
+ index("identity_audit_event_occurred_at_idx").on(table.occurredAt),
137
+ ],
138
+ );
139
+
140
+ export const identity_step_up = sqliteTable(
141
+ "identity_step_up",
142
+ {
143
+ digest: text("digest").notNull(),
144
+ callerUserId: text("caller_user_id").notNull(),
145
+ action: text("action").notNull(),
146
+ targetUserId: text("target_user_id").notNull(),
147
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
148
+ },
149
+ (table) => [
150
+ uniqueIndex("identity_step_up_digest_idx").on(table.digest),
151
+ index("identity_step_up_caller_idx").on(table.callerUserId),
152
+ ],
153
+ );
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
3
  import { createAuth } from "./auth.js";
4
4
  import { resolveSelfSignUpEnabled } from "./config.js";
5
+ import { openIdentityStore } from "./identity-store.js";
5
6
 
6
7
  describe("resolveSelfSignUpEnabled", () => {
7
8
  it("defaults to enabled when unset or blank", () => {
@@ -35,28 +36,11 @@ const baseConfig = {
35
36
  };
36
37
 
37
38
  describe("createAuth self-signup gate", () => {
38
- it("flips better-auth disableSignUp from the selfSignUpEnabled flag", async () => {
39
- const open = await createAuth({ ...baseConfig, selfSignUpEnabled: true });
40
- const closed = await createAuth({
41
- ...baseConfig,
42
- selfSignUpEnabled: false,
43
- });
44
- assert.equal(open.options.emailAndPassword?.disableSignUp, false);
45
- assert.equal(closed.options.emailAndPassword?.disableSignUp, true);
46
- });
47
-
48
- it("drives the sqlite drizzle provider", async () => {
49
- const auth = await createAuth({
50
- connectionString: ":memory:",
51
- secret: baseConfig.secret,
52
- baseURL: baseConfig.baseURL,
53
- selfSignUpEnabled: true,
54
- });
55
- assert.equal(auth.options.emailAndPassword?.disableSignUp, false);
56
- });
57
-
58
39
  it("rejects a signup request server-side when disabled, before any DB access", async () => {
59
- const auth = await createAuth({ ...baseConfig, selfSignUpEnabled: false });
40
+ const auth = await createAuth(
41
+ { ...baseConfig, selfSignUpEnabled: false, signInEnabled: true },
42
+ await openIdentityStore(baseConfig.connectionString),
43
+ );
60
44
  const request = new Request(
61
45
  "http://localhost:3000/api/auth/sign-up/email",
62
46
  {
package/src/verifier.ts CHANGED
@@ -10,6 +10,8 @@ export {
10
10
  AUTH_BASE_PATH,
11
11
  AUTH_JWKS_PATH,
12
12
  AUTH_TOKEN_PATH,
13
+ resolveSelfSignUpEnabled,
14
+ resolveSignInEnabled,
13
15
  resolveVerifierConfig,
14
16
  type VerifierConfig,
15
17
  } from "./config.js";
@@ -1,16 +0,0 @@
1
- // The instance-owner singleton, used to generate the committed SQLite
2
- // migrations (deploy/vps/migrations-sqlite/meta).
3
- import { sql } from "drizzle-orm";
4
- import { check, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
5
-
6
- export const instance_owner = sqliteTable(
7
- "instance_owner",
8
- {
9
- id: integer("id").primaryKey().default(1),
10
- userId: text("user_id").notNull(),
11
- claimedAt: integer("claimed_at", { mode: "timestamp" })
12
- .$defaultFn(() => /* @__PURE__ */ new Date())
13
- .notNull(),
14
- },
15
- (table) => [check("instance_owner_singleton", sql`${table.id} = 1`)],
16
- );