@jskit-ai/auth-provider-local-db-core 0.1.50 → 0.1.52
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/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-provider-local-db-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
9
|
-
"./server/providers/
|
|
9
|
+
"./server/providers/AuthLocalDatabaseBackendProvider": "./src/server/providers/AuthLocalDatabaseBackendProvider.js",
|
|
10
10
|
"./server/lib/index": "./src/server/lib/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/auth-provider-local-core": "0.1.
|
|
14
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
13
|
+
"@jskit-ai/auth-provider-local-core": "0.1.61",
|
|
14
|
+
"@jskit-ai/database-runtime": "0.1.160"
|
|
15
15
|
},
|
|
16
16
|
"description": "Database-backed local auth storage backend for JSKIT local auth.",
|
|
17
17
|
"jskit": {
|
|
18
18
|
"kind": "runtime",
|
|
19
19
|
"capabilities": {
|
|
20
20
|
"provides": [
|
|
21
|
-
"auth.local.backend
|
|
21
|
+
"auth.local.backend"
|
|
22
22
|
],
|
|
23
23
|
"requires": [
|
|
24
24
|
"runtime.database"
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"server": {
|
|
29
29
|
"providers": [
|
|
30
30
|
{
|
|
31
|
-
"entrypoint": "src/server/providers/
|
|
32
|
-
"export": "
|
|
31
|
+
"entrypoint": "src/server/providers/AuthLocalDatabaseBackendProvider.js",
|
|
32
|
+
"export": "AuthLocalDatabaseBackendProvider"
|
|
33
33
|
}
|
|
34
34
|
]
|
|
35
35
|
},
|
|
@@ -42,19 +42,13 @@
|
|
|
42
42
|
"tableOwnership": {
|
|
43
43
|
"tables": [
|
|
44
44
|
{
|
|
45
|
-
"tableName": "auth_local_users"
|
|
46
|
-
"provenance": "auth-provider-local-db-core",
|
|
47
|
-
"ownerKind": "package"
|
|
45
|
+
"tableName": "auth_local_users"
|
|
48
46
|
},
|
|
49
47
|
{
|
|
50
|
-
"tableName": "auth_local_sessions"
|
|
51
|
-
"provenance": "auth-provider-local-db-core",
|
|
52
|
-
"ownerKind": "package"
|
|
48
|
+
"tableName": "auth_local_sessions"
|
|
53
49
|
},
|
|
54
50
|
{
|
|
55
|
-
"tableName": "auth_local_recovery"
|
|
56
|
-
"provenance": "auth-provider-local-db-core",
|
|
57
|
-
"ownerKind": "package"
|
|
51
|
+
"tableName": "auth_local_recovery"
|
|
58
52
|
}
|
|
59
53
|
]
|
|
60
54
|
}
|
|
@@ -62,62 +56,20 @@
|
|
|
62
56
|
"apiSummary": {
|
|
63
57
|
"surfaces": [
|
|
64
58
|
{
|
|
65
|
-
"subpath": "./server/providers/
|
|
66
|
-
"summary": "
|
|
59
|
+
"subpath": "./server/providers/AuthLocalDatabaseBackendProvider",
|
|
60
|
+
"summary": "Provides the database-backed local authentication repository contract."
|
|
67
61
|
},
|
|
68
62
|
{
|
|
69
63
|
"subpath": "./server/lib/index",
|
|
70
64
|
"summary": "Exports the DB local auth backend factory."
|
|
71
65
|
}
|
|
72
66
|
],
|
|
73
|
-
"
|
|
74
|
-
"server": [
|
|
75
|
-
"auth.local.backend"
|
|
76
|
-
],
|
|
77
|
-
"client": []
|
|
78
|
-
}
|
|
67
|
+
"capability": "auth.local.backend"
|
|
79
68
|
}
|
|
80
69
|
},
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
},
|
|
85
|
-
"services": [],
|
|
86
|
-
"steps": []
|
|
87
|
-
},
|
|
88
|
-
"mutations": {
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"runtime": {
|
|
91
|
-
"@jskit-ai/auth-provider-local-core": "0.1.59",
|
|
92
|
-
"@jskit-ai/database-runtime": "0.1.158"
|
|
93
|
-
},
|
|
94
|
-
"dev": {}
|
|
95
|
-
},
|
|
96
|
-
"packageJson": {
|
|
97
|
-
"scripts": {}
|
|
98
|
-
},
|
|
99
|
-
"procfile": {},
|
|
100
|
-
"files": [
|
|
101
|
-
{
|
|
102
|
-
"op": "install-migration",
|
|
103
|
-
"from": "templates/migrations/auth_local_db_initial.cjs",
|
|
104
|
-
"toDir": "migrations",
|
|
105
|
-
"extension": ".cjs",
|
|
106
|
-
"reason": "Install DB-backed local auth credential, session, and recovery tables.",
|
|
107
|
-
"category": "auth-local-db",
|
|
108
|
-
"id": "auth-local-db-initial-schema"
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
"text": [
|
|
112
|
-
{
|
|
113
|
-
"file": ".env",
|
|
114
|
-
"op": "upsert-env",
|
|
115
|
-
"key": "AUTH_LOCAL_BACKEND",
|
|
116
|
-
"value": "db",
|
|
117
|
-
"reason": "Use the database-backed local auth backend.",
|
|
118
|
-
"category": "runtime-config",
|
|
119
|
-
"id": "auth-local-backend-db"
|
|
120
|
-
}
|
|
70
|
+
"migrations": {
|
|
71
|
+
"directories": [
|
|
72
|
+
"migrations"
|
|
121
73
|
]
|
|
122
74
|
}
|
|
123
75
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineProvider } from "@jskit-ai/kernel/shared/capabilities";
|
|
2
|
+
import { createLocalDbBackend } from "../lib/dbBackend.js";
|
|
3
|
+
|
|
4
|
+
const AuthLocalDatabaseBackendProvider = defineProvider({
|
|
5
|
+
id: "auth.local.database-backend",
|
|
6
|
+
requires: {
|
|
7
|
+
database: "runtime.database"
|
|
8
|
+
},
|
|
9
|
+
provides: {
|
|
10
|
+
backend: "auth.local.backend"
|
|
11
|
+
},
|
|
12
|
+
setup({ database }) {
|
|
13
|
+
return {
|
|
14
|
+
backend: createLocalDbBackend({
|
|
15
|
+
knex: database.knex,
|
|
16
|
+
transactionManager: database.transactionManager
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export { AuthLocalDatabaseBackendProvider };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { createCapabilityRuntime, defineProvider } from "@jskit-ai/kernel/shared/capabilities";
|
|
5
|
+
import { AuthExtensionsProvider } from "@jskit-ai/auth-core/server/providers/AuthExtensionsProvider";
|
|
6
6
|
import { createLocalAuthService, hashPassword } from "@jskit-ai/auth-provider-local-core/server/lib/index";
|
|
7
|
-
import {
|
|
7
|
+
import { AuthLocalProvider } from "@jskit-ai/auth-provider-local-core/server/providers/AuthLocalProvider";
|
|
8
8
|
import { createLocalDbBackend, LOCAL_AUTH_DB_TABLES } from "../src/server/lib/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { AuthLocalDatabaseBackendProvider } from "../src/server/providers/AuthLocalDatabaseBackendProvider.js";
|
|
10
10
|
import packageJson from "../package.json" with { type: "json" };
|
|
11
11
|
|
|
12
12
|
const packageMetadata = packageJson.jskit;
|
|
@@ -469,11 +469,10 @@ test("local auth DB backend still supports lazy profile projection", async () =>
|
|
|
469
469
|
assert.equal(registered.actor.profileSource, "users");
|
|
470
470
|
});
|
|
471
471
|
|
|
472
|
-
test("package metadata
|
|
473
|
-
|
|
474
|
-
assert.
|
|
475
|
-
assert.equal(packageMetadata
|
|
476
|
-
assert.deepEqual(packageMetadata.ci.services, []);
|
|
472
|
+
test("package metadata declares portable local auth DB migrations without install mutations", () => {
|
|
473
|
+
assert.deepEqual(packageMetadata.migrations, { directories: ["migrations"] });
|
|
474
|
+
assert.equal(Object.hasOwn(packageMetadata, "mutations"), false);
|
|
475
|
+
assert.equal(Object.hasOwn(packageMetadata, "ci"), false);
|
|
477
476
|
assert.deepEqual(
|
|
478
477
|
packageMetadata.metadata.jskit.tableOwnership.tables.map((table) => table.tableName),
|
|
479
478
|
[
|
|
@@ -484,32 +483,50 @@ test("package metadata installs portable local auth DB migrations", () => {
|
|
|
484
483
|
);
|
|
485
484
|
});
|
|
486
485
|
|
|
487
|
-
test("
|
|
486
|
+
test("installing the DB backend capability makes local auth database-backed", async () => {
|
|
488
487
|
const knex = createMemoryKnex();
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
488
|
+
let authService = null;
|
|
489
|
+
const probe = defineProvider({
|
|
490
|
+
id: "test.auth.local-db.probe",
|
|
491
|
+
requires: { authService: "auth.service" },
|
|
492
|
+
setup({ authService: service }) {
|
|
493
|
+
authService = service;
|
|
494
|
+
return {};
|
|
495
|
+
}
|
|
497
496
|
});
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
497
|
+
const runtime = createCapabilityRuntime({
|
|
498
|
+
inputs: {
|
|
499
|
+
"runtime.app-root": process.cwd(),
|
|
500
|
+
"runtime.env": {
|
|
501
|
+
AUTH_LOCAL_SESSION_SECRET: "test-secret",
|
|
502
|
+
AUTH_LOCAL_RECOVERY_DEV_OUTPUT: "response",
|
|
503
|
+
APP_PUBLIC_URL: "http://localhost:5173",
|
|
504
|
+
NODE_ENV: "test"
|
|
505
|
+
},
|
|
506
|
+
"runtime.logger": console,
|
|
507
|
+
"runtime.database": {
|
|
508
|
+
knex,
|
|
509
|
+
transactionManager: {
|
|
510
|
+
inTransaction(work) {
|
|
511
|
+
return knex.transaction(work);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
},
|
|
501
516
|
providers: [
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
517
|
+
AuthExtensionsProvider,
|
|
518
|
+
AuthLocalDatabaseBackendProvider,
|
|
519
|
+
AuthLocalProvider,
|
|
520
|
+
probe
|
|
505
521
|
]
|
|
506
522
|
});
|
|
507
|
-
|
|
508
|
-
assert.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
523
|
+
await runtime.start();
|
|
524
|
+
assert.deepEqual(runtime.diagnostics().providerOrder, [
|
|
525
|
+
"auth.extensions",
|
|
526
|
+
"auth.local.database-backend",
|
|
527
|
+
"auth.local",
|
|
528
|
+
"test.auth.local-db.probe"
|
|
529
|
+
]);
|
|
513
530
|
const registered = await authService.register({
|
|
514
531
|
email: "provider-db@example.com",
|
|
515
532
|
password: "provider password value",
|
|
@@ -518,50 +535,15 @@ test("provider registration wires DB backend for AUTH_LOCAL_BACKEND=db", async (
|
|
|
518
535
|
assert.equal(registered.actor.email, "provider-db@example.com");
|
|
519
536
|
});
|
|
520
537
|
|
|
521
|
-
test("local auth DB
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
app.start({
|
|
533
|
-
providers: [AuthLocalServiceProvider]
|
|
534
|
-
}),
|
|
535
|
-
(error) =>
|
|
536
|
-
/AUTH_LOCAL_BACKEND="db" requires a package or app provider that registers auth\.local\.backend/.test(
|
|
537
|
-
String(error.details?.cause?.message || error.message || "")
|
|
538
|
-
)
|
|
539
|
-
);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
test("local auth DB provider rejects ambiguous backend ownership in DB mode", async () => {
|
|
543
|
-
const app = createApplication();
|
|
544
|
-
app.instance("jskit.env", {
|
|
545
|
-
AUTH_PROVIDER: "local",
|
|
546
|
-
AUTH_LOCAL_BACKEND: "db",
|
|
547
|
-
NODE_ENV: "test"
|
|
548
|
-
});
|
|
549
|
-
app.instance("auth.local.backend", {
|
|
550
|
-
async withTransaction() {}
|
|
551
|
-
});
|
|
552
|
-
app.instance("jskit.database.knex", createMemoryKnex());
|
|
553
|
-
|
|
554
|
-
await assert.rejects(
|
|
555
|
-
() =>
|
|
556
|
-
app.start({
|
|
557
|
-
providers: [
|
|
558
|
-
DatabaseRuntimeServiceProvider,
|
|
559
|
-
AuthLocalDbBackendServiceProvider
|
|
560
|
-
]
|
|
561
|
-
}),
|
|
562
|
-
(error) =>
|
|
563
|
-
/auth-provider-local-db-core to own auth\.local\.backend/.test(
|
|
564
|
-
String(error.details?.cause?.message || error.message || "")
|
|
565
|
-
)
|
|
566
|
-
);
|
|
538
|
+
test("local auth DB backend rejects competing capability ownership", () => {
|
|
539
|
+
assert.throws(() => createCapabilityRuntime({
|
|
540
|
+
inputs: {
|
|
541
|
+
"auth.local.backend": { async withTransaction() {} },
|
|
542
|
+
"runtime.database": {
|
|
543
|
+
knex: createMemoryKnex(),
|
|
544
|
+
transactionManager: { async inTransaction(work) { return work(); } }
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
providers: [AuthLocalDatabaseBackendProvider]
|
|
548
|
+
}), /auth\.local\.backend.*supplied both/);
|
|
567
549
|
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { resolveLocalBackendMode } from "@jskit-ai/auth-provider-local-core/server/providers/AuthLocalServiceProvider";
|
|
2
|
-
import { createLocalDbBackend } from "../lib/dbBackend.js";
|
|
3
|
-
|
|
4
|
-
class AuthLocalDbBackendServiceProvider {
|
|
5
|
-
static id = "auth.provider.local.db";
|
|
6
|
-
|
|
7
|
-
register(app) {
|
|
8
|
-
if (!app || typeof app.singleton !== "function" || typeof app.has !== "function") {
|
|
9
|
-
throw new Error("AuthLocalDbBackendServiceProvider requires application singleton()/has().");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const backendMode = resolveLocalBackendMode(app);
|
|
13
|
-
if (backendMode !== "db") {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (app.has("auth.local.backend")) {
|
|
18
|
-
throw new Error('AUTH_LOCAL_BACKEND="db" requires auth-provider-local-db-core to own auth.local.backend.');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
app.singleton("auth.local.backend", (scope) => createLocalDbBackend({
|
|
22
|
-
knex: scope.make("jskit.database.knex"),
|
|
23
|
-
transactionManager: scope.make("jskit.database.transactionManager")
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { AuthLocalDbBackendServiceProvider };
|
|
File without changes
|