@o3co/create-auth-provider 0.15.0 → 0.16.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.
Files changed (41) hide show
  1. package/README.ja.md +93 -47
  2. package/README.md +92 -46
  3. package/package.json +1 -1
  4. package/templates/standalone/.env.example +12 -0
  5. package/templates/standalone/Dockerfile +1 -1
  6. package/templates/standalone/README.ja.md +516 -154
  7. package/templates/standalone/README.md +218 -91
  8. package/templates/standalone/config/application.conf +26 -3
  9. package/templates/standalone/gitignore +3 -2
  10. package/templates/standalone/package.json +1 -1
  11. package/templates/standalone/src/__tests__/access-token-lifetime-alias.test.mts +49 -15
  12. package/templates/standalone/src/__tests__/all-modules-composition.fixture.mts +1103 -0
  13. package/templates/standalone/src/__tests__/all-modules-composition.multi.test.mts +241 -0
  14. package/templates/standalone/src/__tests__/all-modules-composition.test.mts +1100 -0
  15. package/templates/standalone/src/__tests__/documented-env-overrides.test.mts +19 -5
  16. package/templates/standalone/src/__tests__/federation-grants-composition.test.mts +64 -3
  17. package/templates/standalone/src/__tests__/federation-grants-survive-logout.test.mts +15 -0
  18. package/templates/standalone/src/__tests__/federation-token-refresh-outage.test.mts +133 -0
  19. package/templates/standalone/src/__tests__/google-federation-config-module.test.mts +28 -0
  20. package/templates/standalone/src/__tests__/google-session.fixture.mts +304 -0
  21. package/templates/standalone/src/__tests__/host-routes.test.mts +141 -0
  22. package/templates/standalone/src/__tests__/listen.test.mts +128 -0
  23. package/templates/standalone/src/__tests__/logger-projection.test.mts +77 -0
  24. package/templates/standalone/src/__tests__/metrics.test.mts +20 -5
  25. package/templates/standalone/src/__tests__/post-logout-redirect.test.mts +187 -0
  26. package/templates/standalone/src/__tests__/redis-connection-error-log.test.mts +139 -0
  27. package/templates/standalone/src/__tests__/replica-safety.test.mts +13 -3
  28. package/templates/standalone/src/__tests__/router-error-answers.test.mts +149 -0
  29. package/templates/standalone/src/__tests__/shutdown.test.mts +157 -20
  30. package/templates/standalone/src/__tests__/smoke.test.mts +39 -20
  31. package/templates/standalone/src/__tests__/store-credential.test.mts +276 -0
  32. package/templates/standalone/src/app.mts +21 -50
  33. package/templates/standalone/src/buildModules.mts +33 -16
  34. package/templates/standalone/src/listen.mts +66 -0
  35. package/templates/standalone/src/logger.mts +7 -4
  36. package/templates/standalone/src/modules.mts +42 -8
  37. package/templates/standalone/src/routes.mts +95 -0
  38. package/templates/standalone/src/shutdown.mts +20 -14
  39. package/templates/versions.json +15 -15
  40. package/templates/standalone/src/__tests__/terminal-error.test.mts +0 -96
  41. package/templates/standalone/src/terminalError.mts +0 -60
@@ -27,7 +27,7 @@
27
27
  */
28
28
 
29
29
  import { fileURLToPath } from "node:url";
30
- import { type AppConfig, AppConfigSchema } from "@o3co/auth-provider-core";
30
+ import { type AppConfig, AppConfigSchema, type Logger } from "@o3co/auth-provider-core";
31
31
  import { parseFile } from "@o3co/ts.hocon";
32
32
  import { validate } from "@o3co/ts.hocon/zod";
33
33
  import { afterEach, describe, expect, it, vi } from "vitest";
@@ -54,15 +54,47 @@ function loadShipped(env: Record<string, string> = {}): AppConfig {
54
54
  );
55
55
  }
56
56
 
57
- /** Every console warning `buildModules` emits about the deprecated key. */
58
- function aliasWarnings(config: AppConfig): string[] {
59
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
60
- buildModules(config);
61
- return warn.mock.calls
62
- .map((call) => String(call[0]))
63
- .filter((message) => message.includes("oauth.accessToken.expiresIn"));
57
+ /** What `buildModules` hands the logger it is given, per level. */
58
+ function logged(config: AppConfig): Array<{ level: string; args: unknown[] }> {
59
+ const calls: Array<{ level: string; args: unknown[] }> = [];
60
+ const record =
61
+ (level: string) =>
62
+ (...args: unknown[]): void => {
63
+ calls.push({ level, args });
64
+ };
65
+ const logger: Logger = {
66
+ trace: record("trace"),
67
+ debug: record("debug"),
68
+ info: record("info"),
69
+ warn: record("warn"),
70
+ error: record("error"),
71
+ fatal: record("fatal"),
72
+ child: () => logger,
73
+ };
74
+ buildModules(config, { logger });
75
+ return calls;
64
76
  }
65
77
 
78
+ /** The one line the alias is reported by: object-first, an event name, at warn. */
79
+ const ALIAS_WARNING = {
80
+ level: "warn",
81
+ args: [
82
+ {
83
+ key: "oauth.accessToken.expiresIn",
84
+ env: "OAUTH_ACCESS_TOKEN_EXPIRES_IN",
85
+ replacement: "oauth.accessToken.defaultExpiresIn",
86
+ replacementEnv: "OAUTH_ACCESS_TOKEN_DEFAULT_EXPIRES_IN",
87
+ },
88
+ "config_key_deprecated",
89
+ ],
90
+ };
91
+
92
+ /** Every line `buildModules` writes about the deprecated key. */
93
+ const aliasWarnings = (config: AppConfig) =>
94
+ logged(config).filter(
95
+ ({ args }) => (args[0] as { key?: unknown } | undefined)?.key === "oauth.accessToken.expiresIn",
96
+ );
97
+
66
98
  describe("the deprecated access-token lifetime alias", () => {
67
99
  afterEach(() => {
68
100
  vi.restoreAllMocks();
@@ -81,12 +113,8 @@ describe("the deprecated access-token lifetime alias", () => {
81
113
  );
82
114
  });
83
115
 
84
- it("warns once when OAUTH_ACCESS_TOKEN_EXPIRES_IN still decides the default", () => {
85
- const warnings = aliasWarnings(loadShipped({ OAUTH_ACCESS_TOKEN_EXPIRES_IN: "900" }));
86
- expect(warnings).toHaveLength(1);
87
- expect(warnings[0]).toMatch(/deprecated/);
88
- expect(warnings[0]).toMatch(/oauth\.accessToken\.defaultExpiresIn/);
89
- expect(warnings[0]).toMatch(/OAUTH_ACCESS_TOKEN_DEFAULT_EXPIRES_IN/);
116
+ it("warns once, object-first, when OAUTH_ACCESS_TOKEN_EXPIRES_IN still decides the default", () => {
117
+ expect(logged(loadShipped({ OAUTH_ACCESS_TOKEN_EXPIRES_IN: "900" }))).toEqual([ALIAS_WARNING]);
90
118
  });
91
119
 
92
120
  it("warns for a hand-built configuration that overrides only the old key", () => {
@@ -96,6 +124,12 @@ describe("the deprecated access-token lifetime alias", () => {
96
124
  ...config,
97
125
  oauth: { ...config.oauth, accessToken: { expiresIn: 900 } },
98
126
  }),
99
- ).toHaveLength(1);
127
+ ).toEqual([ALIAS_WARNING]);
128
+ });
129
+
130
+ it("writes the same line through consoleLogger when no logger is handed over", () => {
131
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
132
+ buildModules(loadShipped({ OAUTH_ACCESS_TOKEN_EXPIRES_IN: "900" }));
133
+ expect(warn.mock.calls).toEqual([ALIAS_WARNING.args]);
100
134
  });
101
135
  });