@smplcty/auth 3.0.0 → 4.0.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.
- package/README.md +8 -6
- package/dist/dev-otp.d.ts.map +1 -1
- package/dist/dev-otp.js +0 -1
- package/dist/dev-otp.js.map +1 -1
- package/package.json +2 -2
- package/schema/tables/communication_channels.yaml +1 -1
- package/schema/tables/dev_otp_enrollments.yaml +0 -6
- package/schema/tables/roles.yaml +11 -14
- package/schema/tables/user_communication_methods.yaml +1 -1
- package/schema/tables/users.yaml +9 -8
package/README.md
CHANGED
|
@@ -371,8 +371,8 @@ console.log(await qrcode.toString(uri, { type: 'terminal', small: true }));
|
|
|
371
371
|
console.log(`\nManual entry secret: ${secret}\n`);
|
|
372
372
|
console.log('After scanning, run this SQL against your database:');
|
|
373
373
|
console.log(`
|
|
374
|
-
INSERT INTO dev_otp_enrollments (user_communication_method_id, totp_secret
|
|
375
|
-
SELECT ucm.user_communication_method_id, '${secret}'
|
|
374
|
+
INSERT INTO dev_otp_enrollments (user_communication_method_id, totp_secret)
|
|
375
|
+
SELECT ucm.user_communication_method_id, '${secret}'
|
|
376
376
|
FROM user_communication_methods ucm
|
|
377
377
|
JOIN communication_channels cc ON cc.communication_channel_id = ucm.communication_channel_id
|
|
378
378
|
WHERE cc.name = 'phone' AND ucm.code = '${phone}';
|
|
@@ -455,12 +455,12 @@ The library ships its schema as schema-flow YAML inside the package at `@smplcty
|
|
|
455
455
|
```
|
|
456
456
|
@smplcty/auth/schema/
|
|
457
457
|
├── tables/
|
|
458
|
-
│ ├── users.yaml # + audit; seeds the app-init service user (
|
|
458
|
+
│ ├── users.yaml # + audit; seeds the app-init service user (matched by name)
|
|
459
459
|
│ ├── tenants.yaml # + audit; slug (sub-domain), allow_otp (SSO-only switch)
|
|
460
460
|
│ ├── roles.yaml # + audit; seeds 'user' (default), 'settings', 'security'
|
|
461
461
|
│ ├── user_roles.yaml # + audit; tenant_id NULL = wildcard / all tenants
|
|
462
|
-
│ ├── communication_channels.yaml
|
|
463
|
-
│ ├── user_communication_methods.yaml
|
|
462
|
+
│ ├── communication_channels.yaml # + audit
|
|
463
|
+
│ ├── user_communication_methods.yaml # + audit
|
|
464
464
|
│ ├── auth_domains.yaml # + audit; tenant's IdP(s), 1:N, resolved by id (display_name = button)
|
|
465
465
|
│ ├── sessions.yaml # PK = token hash; last_seen_at; geo
|
|
466
466
|
│ └── dev_otp_enrollments.yaml
|
|
@@ -473,6 +473,8 @@ The library ships its schema as schema-flow YAML inside the package at `@smplcty
|
|
|
473
473
|
|
|
474
474
|
### Consuming with [`@smplcty/schema-flow`](https://www.npmjs.com/package/@smplcty/schema-flow)
|
|
475
475
|
|
|
476
|
+
Requires **`@smplcty/schema-flow >= 0.12.0`** — the shipped seeds assign no primary keys (the app-init user and the standard roles are matched by their natural keys, `name`/`kind`), which earlier versions don't fully support.
|
|
477
|
+
|
|
476
478
|
Import auth's schema and `@smplcty/schema-std` from your schema-flow config. See the reference [`schema-flow.config.yaml`](schema-flow.config.yaml):
|
|
477
479
|
|
|
478
480
|
```yaml
|
|
@@ -482,7 +484,7 @@ default:
|
|
|
482
484
|
- package: '@smplcty/auth' # identity/tenant/auth_domains tables + resolve_session/current_user_id
|
|
483
485
|
```
|
|
484
486
|
|
|
485
|
-
The `audit` mixin makes `created_by`/`updated_by` NOT NULL, stamped from `app.actor_id`. Rows seeded during migration have no request actor, so the shipped `post/` script back-fills them to the seeded `app-init` service user (
|
|
487
|
+
The `audit` mixin makes `created_by`/`updated_by` NOT NULL, stamped from `app.actor_id`. Rows seeded during migration have no request actor, so the shipped `post/` script back-fills them to the seeded `app-init` service user (resolved by name, not a fixed id) before the NOT NULL tighten phase — see the config for details.
|
|
486
488
|
|
|
487
489
|
### Soft delete
|
|
488
490
|
|
package/dist/dev-otp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-otp.d.ts","sourceRoot":"","sources":["../src/dev-otp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-otp.d.ts","sourceRoot":"","sources":["../src/dev-otp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA0C5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiCnH;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMzG;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAevG"}
|
package/dist/dev-otp.js
CHANGED
package/dist/dev-otp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-otp.js","sourceRoot":"","sources":["../src/dev-otp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,mEAAmE;AACnE,sEAAsE;AACtE,qEAAqE;AACrE,6DAA6D;AAC7D,oCAAoC;AACpC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,MAAM,iBAAiB,GAAG
|
|
1
|
+
{"version":3,"file":"dev-otp.js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M,IAAI,iBAAiB,CAAC,kCAAkC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO,KAAK,EAAE,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,iBAAiB,CAAC,mCAAmC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,WAAW,CAAC;QACjB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smplcty/auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Robust, type-safe session and role-based authentication primitives for PostgreSQL apps using Row-Level Security.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@eslint/js": "^10.0.1",
|
|
107
107
|
"@release-it/keep-a-changelog": "^7.1.0",
|
|
108
|
-
"@smplcty/schema-flow": "^0.
|
|
108
|
+
"@smplcty/schema-flow": "^0.12.0",
|
|
109
109
|
"@smplcty/twilio": "^0.1.1",
|
|
110
110
|
"@testcontainers/postgresql": "^12.0.2",
|
|
111
111
|
"@types/node": "^25.9.3",
|
|
@@ -18,12 +18,6 @@ columns:
|
|
|
18
18
|
type: text
|
|
19
19
|
nullable: false
|
|
20
20
|
|
|
21
|
-
# Human label for the enrollment — useful when an admin needs to
|
|
22
|
-
# know whose phone this is. Examples: "Sam's iPhone", "Mark's 1Password vault".
|
|
23
|
-
- name: label
|
|
24
|
-
type: text
|
|
25
|
-
nullable: false
|
|
26
|
-
|
|
27
21
|
- name: enrolled_at
|
|
28
22
|
type: timestamptz
|
|
29
23
|
nullable: false
|
package/schema/tables/roles.yaml
CHANGED
|
@@ -34,30 +34,27 @@ indexes:
|
|
|
34
34
|
unique: true
|
|
35
35
|
where: 'deleted_at IS NULL'
|
|
36
36
|
name: roles_name_key
|
|
37
|
-
# The canonical role names shipped with @smplcty/auth.
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
37
|
+
# The canonical role names shipped with @smplcty/auth. The library never
|
|
38
|
+
# references roles by id — it always looks them up by name — so no ids are
|
|
39
|
+
# pinned here: the seeds carry no role_id, and schema-flow matches them by
|
|
40
|
+
# their natural columns (the partial-unique index on `name` backstops any
|
|
41
|
+
# duplicate). Consumers add their own roles by name; there are no reserved
|
|
42
|
+
# id ranges to avoid.
|
|
43
43
|
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
44
|
+
# seeds_on_conflict: DO NOTHING, so re-running this migration against an
|
|
45
|
+
# already-seeded database is a no-op.
|
|
46
46
|
seeds:
|
|
47
|
-
-
|
|
48
|
-
name: 'user'
|
|
47
|
+
- name: 'user'
|
|
49
48
|
display_name: 'User'
|
|
50
49
|
description: 'Standard signed-in user.'
|
|
51
50
|
is_default: true
|
|
52
51
|
is_privilege: false
|
|
53
|
-
-
|
|
54
|
-
name: 'settings'
|
|
52
|
+
- name: 'settings'
|
|
55
53
|
display_name: 'Settings'
|
|
56
54
|
description: 'Account and organisation settings access.'
|
|
57
55
|
is_default: false
|
|
58
56
|
is_privilege: false
|
|
59
|
-
-
|
|
60
|
-
name: 'security'
|
|
57
|
+
- name: 'security'
|
|
61
58
|
display_name: 'Security'
|
|
62
59
|
description: 'Security administration.'
|
|
63
60
|
is_default: false
|
package/schema/tables/users.yaml
CHANGED
|
@@ -21,14 +21,15 @@ columns:
|
|
|
21
21
|
nullable: false
|
|
22
22
|
default: "'human'"
|
|
23
23
|
check: "kind IN ('human', 'service')"
|
|
24
|
-
# The bootstrap principal
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# own
|
|
24
|
+
# The bootstrap principal: the app-init service user. It's the actor every
|
|
25
|
+
# migration-time seed (this row, the standard roles, any consumer seeds) is
|
|
26
|
+
# attributed to via app.actor_id, resolved by name — `audit_backfill_by`
|
|
27
|
+
# looks it up with `WHERE name = 'app-init' AND kind = 'service'`, never by a
|
|
28
|
+
# fixed id. It seeds first (users seed before tables that FK to it) and stamps
|
|
29
|
+
# its own created_by (the self-reference resolves because the row exists by the
|
|
30
|
+
# time the FK is checked). No id is pinned: the seed has no primary key, so
|
|
31
|
+
# schema-flow matches it on (name, kind) and re-runs are a no-op.
|
|
30
32
|
seeds:
|
|
31
|
-
-
|
|
32
|
-
name: 'app-init'
|
|
33
|
+
- name: 'app-init'
|
|
33
34
|
kind: 'service'
|
|
34
35
|
seeds_on_conflict: 'DO NOTHING'
|