@o3co/auth-provider-foundation 0.3.0 → 0.4.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.ja.md +3 -3
- package/README.md +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +12 -1
- package/dist/repositories/__tests__/registerBuiltinAdapters.test.mjs +49 -13
- package/package.json +2 -2
package/README.ja.md
CHANGED
|
@@ -23,8 +23,8 @@ npm install redis
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
function registerBuiltinAdapters(factories: {
|
|
26
|
-
userFactory:
|
|
27
|
-
codeFactory:
|
|
26
|
+
userFactory: AdapterFactory<UserRepository>;
|
|
27
|
+
codeFactory: AdapterFactory<CodeRepository>;
|
|
28
28
|
pathResolver?: PathResolver; // 任意 — "redis" モジュールのパス解決に使用
|
|
29
29
|
}): void;
|
|
30
30
|
```
|
|
@@ -110,5 +110,5 @@ const codeRepo = await codeFactory.create({
|
|
|
110
110
|
|
|
111
111
|
## 関連
|
|
112
112
|
|
|
113
|
-
- [`@o3co/auth-provider-core`](../core/README.md) — コアインターフェース(`UserRepository`、`CodeRepository`、`
|
|
113
|
+
- [`@o3co/auth-provider-core`](../core/README.md) — コアインターフェース(`UserRepository`、`CodeRepository`、`AdapterFactory`、`createAdapterFactory`、`BuilderContext`、`PathResolver`)
|
|
114
114
|
- [auth.provider](../../README.md) — リポジトリ全体のドキュメント
|
package/README.md
CHANGED
|
@@ -23,8 +23,8 @@ Registers the built-in adapter factories into the provided factory instances.
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
function registerBuiltinAdapters(factories: {
|
|
26
|
-
userFactory:
|
|
27
|
-
codeFactory:
|
|
26
|
+
userFactory: AdapterFactory<UserRepository>;
|
|
27
|
+
codeFactory: AdapterFactory<CodeRepository>;
|
|
28
28
|
pathResolver?: PathResolver; // optional — used to resolve the "redis" module path
|
|
29
29
|
}): void;
|
|
30
30
|
```
|
|
@@ -110,5 +110,5 @@ const codeRepo = await codeFactory.create({
|
|
|
110
110
|
|
|
111
111
|
## See Also
|
|
112
112
|
|
|
113
|
-
- [`@o3co/auth-provider-core`](../core/README.md) — Core interfaces (`UserRepository`, `CodeRepository`, `
|
|
113
|
+
- [`@o3co/auth-provider-core`](../core/README.md) — Core interfaces (`UserRepository`, `CodeRepository`, `AdapterFactory`, `createAdapterFactory`, `BuilderContext`, `PathResolver`)
|
|
114
114
|
- [auth.provider](../../README.md) — Top-level repository documentation
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CodeRepository, PathResolver,
|
|
1
|
+
import type { AdapterFactory, CodeRepository, PathResolver, UserRepository } from "@o3co/auth-provider-core";
|
|
2
2
|
export declare const registerBuiltinAdapters: (factories: {
|
|
3
|
-
userFactory:
|
|
4
|
-
codeFactory:
|
|
3
|
+
userFactory: AdapterFactory<UserRepository>;
|
|
4
|
+
codeFactory: AdapterFactory<CodeRepository>;
|
|
5
5
|
pathResolver?: PathResolver;
|
|
6
6
|
}) => void;
|
|
7
7
|
export { HttpUserRepository } from "./repositories/HttpUserRepository.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACX,cAAc,EACd,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,EACd,MAAM,0BAA0B,CAAC;AAIlC,eAAO,MAAM,uBAAuB,GAAI,WAAW;IAClD,WAAW,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;IAC5C,WAAW,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;IAC5C,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B,KAAG,IAiCH,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -27,7 +27,18 @@ export const registerBuiltinAdapters = (factories) => {
|
|
|
27
27
|
return new HttpUserRepository({
|
|
28
28
|
authenticateUrl: config.authenticateUrl,
|
|
29
29
|
authenticateByTokenUrl: config.authenticateByTokenUrl,
|
|
30
|
-
timeout:
|
|
30
|
+
timeout: (() => {
|
|
31
|
+
if (typeof config.timeout === "number" && Number.isFinite(config.timeout)) {
|
|
32
|
+
return config.timeout;
|
|
33
|
+
}
|
|
34
|
+
if (typeof config.timeout === "string") {
|
|
35
|
+
const n = Number(config.timeout);
|
|
36
|
+
if (Number.isFinite(n) && n > 0) {
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return 5000;
|
|
41
|
+
})(),
|
|
31
42
|
});
|
|
32
43
|
});
|
|
33
44
|
factories.codeFactory.register("redis", (config) => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { AdapterFactoryError, createAdapterFactory, } from "@o3co/auth-provider-core";
|
|
17
17
|
import { HttpResponse, http } from "msw";
|
|
18
18
|
import { setupServer } from "msw/node";
|
|
19
19
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
@@ -38,20 +38,40 @@ afterEach(() => server.resetHandlers());
|
|
|
38
38
|
afterAll(() => server.close());
|
|
39
39
|
describe("registerBuiltinAdapters", () => {
|
|
40
40
|
it("registers 'http' type in userFactory", async () => {
|
|
41
|
-
const userFactory =
|
|
42
|
-
const codeFactory =
|
|
41
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
42
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
43
43
|
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
44
|
-
|
|
44
|
+
try {
|
|
45
|
+
await userFactory.create({ type: "unknown" });
|
|
46
|
+
throw new Error("should have thrown");
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
expect(err).toBeInstanceOf(AdapterFactoryError);
|
|
50
|
+
const e = err;
|
|
51
|
+
expect(e.reason).toBe("unknown");
|
|
52
|
+
expect(e.kind).toBe("UserRepository");
|
|
53
|
+
expect(e.registered).toContain("http");
|
|
54
|
+
}
|
|
45
55
|
});
|
|
46
56
|
it("registers 'redis' type in codeFactory", async () => {
|
|
47
|
-
const userFactory =
|
|
48
|
-
const codeFactory =
|
|
57
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
58
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
49
59
|
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
50
|
-
|
|
60
|
+
try {
|
|
61
|
+
await codeFactory.create({ type: "unknown" });
|
|
62
|
+
throw new Error("should have thrown");
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
expect(err).toBeInstanceOf(AdapterFactoryError);
|
|
66
|
+
const e = err;
|
|
67
|
+
expect(e.reason).toBe("unknown");
|
|
68
|
+
expect(e.kind).toBe("CodeRepository");
|
|
69
|
+
expect(e.registered).toContain("redis");
|
|
70
|
+
}
|
|
51
71
|
});
|
|
52
72
|
it("http builder creates a working HttpUserRepository", async () => {
|
|
53
|
-
const userFactory =
|
|
54
|
-
const codeFactory =
|
|
73
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
74
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
55
75
|
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
56
76
|
const repo = await userFactory.create({
|
|
57
77
|
type: "http",
|
|
@@ -67,15 +87,31 @@ describe("registerBuiltinAdapters", () => {
|
|
|
67
87
|
const invalid = await repo.authenticate("alice", "wrong");
|
|
68
88
|
expect(invalid).toBeNull();
|
|
69
89
|
});
|
|
90
|
+
it("http builder coerces string timeout to number (env-override path)", async () => {
|
|
91
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
92
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
93
|
+
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
94
|
+
const repo = await userFactory.create({
|
|
95
|
+
type: "http",
|
|
96
|
+
authenticateUrl: `${BASE_URL}/auth`,
|
|
97
|
+
authenticateByTokenUrl: `${BASE_URL}/auth/token`,
|
|
98
|
+
timeout: "1234", // string, as HOCON env override produces
|
|
99
|
+
});
|
|
100
|
+
expect(repo).toBeDefined();
|
|
101
|
+
// HttpUserRepository doesn't expose timeout publicly; we verify it didn't throw
|
|
102
|
+
// and works via the MSW fixture. The coercion path is internal.
|
|
103
|
+
const user = await repo.authenticate("alice", "pass");
|
|
104
|
+
expect(user).not.toBeNull();
|
|
105
|
+
});
|
|
70
106
|
it("http builder throws when authenticateUrl is missing", async () => {
|
|
71
|
-
const userFactory =
|
|
72
|
-
const codeFactory =
|
|
107
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
108
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
73
109
|
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
74
110
|
await expect(userFactory.create({ type: "http", timeout: 5000 })).rejects.toThrow(/authenticateUrl/);
|
|
75
111
|
});
|
|
76
112
|
it("redis builder throws when endpointUri is missing", async () => {
|
|
77
|
-
const userFactory =
|
|
78
|
-
const codeFactory =
|
|
113
|
+
const userFactory = createAdapterFactory("UserRepository");
|
|
114
|
+
const codeFactory = createAdapterFactory("CodeRepository");
|
|
79
115
|
registerBuiltinAdapters({ userFactory, codeFactory });
|
|
80
116
|
await expect(codeFactory.create({ type: "redis" })).rejects.toThrow(/endpointUri/);
|
|
81
117
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3co/auth-provider-foundation",
|
|
3
3
|
"description": "Production adapters for auth.provider",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.mjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"redis": "^5.10.0",
|
|
44
44
|
"pino": "^10.3.1",
|
|
45
45
|
"vitest": "^4.1.2",
|
|
46
|
-
"@o3co/auth-provider-core": "0.
|
|
46
|
+
"@o3co/auth-provider-core": "0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"prebuild": "rimraf dist",
|