@astram/guard 0.1.0 → 0.2.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 (34) hide show
  1. package/dist/auth/auth.controller.d.ts +102 -0
  2. package/dist/auth/auth.controller.d.ts.map +1 -0
  3. package/dist/auth/auth.controller.js +313 -0
  4. package/dist/auth/auth.module.d.ts +104 -0
  5. package/dist/auth/auth.module.d.ts.map +1 -0
  6. package/dist/auth/auth.module.js +318 -0
  7. package/dist/auth/connections.d.ts +61 -0
  8. package/dist/auth/connections.d.ts.map +1 -0
  9. package/dist/auth/connections.js +116 -0
  10. package/dist/auth/dto.d.ts +144 -0
  11. package/dist/auth/dto.d.ts.map +1 -0
  12. package/dist/auth/dto.js +29 -0
  13. package/dist/auth/pending-mfa-store.d.ts +72 -0
  14. package/dist/auth/pending-mfa-store.d.ts.map +1 -0
  15. package/dist/auth/pending-mfa-store.js +106 -0
  16. package/dist/auth/persistence.module.d.ts +42 -0
  17. package/dist/auth/persistence.module.d.ts.map +1 -0
  18. package/dist/auth/persistence.module.js +94 -0
  19. package/dist/auth/tokens.d.ts +62 -0
  20. package/dist/auth/tokens.d.ts.map +1 -0
  21. package/dist/auth/tokens.js +65 -0
  22. package/dist/authentication/mariadb-credential-resolver.d.ts +96 -0
  23. package/dist/authentication/mariadb-credential-resolver.d.ts.map +1 -0
  24. package/dist/authentication/mariadb-credential-resolver.js +156 -0
  25. package/dist/config/app-config.d.ts +134 -1
  26. package/dist/config/app-config.d.ts.map +1 -1
  27. package/dist/config/app-config.js +144 -2
  28. package/dist/index.d.ts +9 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +46 -1
  31. package/dist/module/shield.module.d.ts +51 -0
  32. package/dist/module/shield.module.d.ts.map +1 -1
  33. package/dist/module/shield.module.js +65 -4
  34. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"shield.module.d.ts","sourceRoot":"","sources":["../../src/module/shield.module.ts"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js");
14
14
  const boot_module_js_1 = require("../boot/boot.module.js");
15
15
  const config_module_js_1 = require("../config/config.module.js");
16
16
  const app_config_js_1 = require("../config/app-config.js");
17
+ // Static import is SAFE: auth.module.ts top-level-imports @astram/core as TYPES
18
+ // only (it loads core's ESM factory VALUES lazily inside its async provider
19
+ // factories — see auth.module.ts loadCore()). So pulling AuthModule here does NOT
20
+ // trigger a runtime `require('@astram/core')`; the opt-in gate below still ensures
21
+ // the enforcement-only path never INSTANTIATES it (no live pool/Redis, no HMAC
22
+ // gate, no core load).
23
+ const auth_module_js_1 = require("../auth/auth.module.js");
17
24
  /**
18
25
  * DI token for the Core decision authority (the ADR-0001 single decision
19
26
  * authority) that the enforcement guard consults. The consumer supplies the real
@@ -50,11 +57,33 @@ let ShieldModule = ShieldModule_1 = class ShieldModule {
50
57
  /** Register Shield with static options (the common path). */
51
58
  static forRoot(options = {}) {
52
59
  const config = options.config ?? (0, app_config_js_1.loadAppConfig)();
60
+ // Build the opt-in AuthModule ONCE so the SAME DynamicModule instance is both
61
+ // imported (composes) and re-exported (propagates its exported engine tokens
62
+ // app-wide through the @Global ShieldModule). Re-exporting the two Symbols
63
+ // directly is NOT valid Nest — a module may only re-export a whole imported
64
+ // module (or a token IT provides), so we export the AuthModule dynamic module.
65
+ // When auth is opted in, thread the consumer's optional credentialResolver into
66
+ // AuthModule (it binds the supplied instance under SHIELD_CREDENTIAL_RESOLVER;
67
+ // omitted → the default MariaDb store, unchanged). Without auth the resolver is
68
+ // irrelevant (no AuthModule composes) — a documented no-op.
69
+ const authModule = options.auth
70
+ ? auth_module_js_1.AuthModule.forRoot(
71
+ // Only pass the property when the consumer supplied one — under
72
+ // `exactOptionalPropertyTypes`, an explicit `undefined` is not assignable
73
+ // to the optional `credentialResolver`; a spread keeps it truly absent so
74
+ // AuthModule falls back to the default MariaDb binding.
75
+ options.credentialResolver
76
+ ? { credentialResolver: options.credentialResolver }
77
+ : {})
78
+ : undefined;
53
79
  return {
54
80
  module: ShieldModule_1,
55
81
  // Compose the framework modules — EnforcementModule holds the ONE APP_GUARD
56
82
  // binding; BootModule holds the boot-sequence hook. No re-declaration here.
57
- imports: [enforcement_module_js_1.EnforcementModule, boot_module_js_1.BootModule],
83
+ // AuthModule is OPT-IN (options.auth === true): only then does the app open a
84
+ // live pool/Redis + fire the fail-closed HMAC gate. Absent/false → the
85
+ // enforcement-only no-`.env` boot survives untouched.
86
+ imports: [enforcement_module_js_1.EnforcementModule, boot_module_js_1.BootModule, ...(authModule ? [authModule] : [])],
58
87
  providers: [
59
88
  { provide: config_module_js_1.APP_CONFIG, useValue: config },
60
89
  {
@@ -62,7 +91,14 @@ let ShieldModule = ShieldModule_1 = class ShieldModule {
62
91
  useValue: options.decisionAuthority ?? core_seam_js_1.stubDecisionAuthority,
63
92
  },
64
93
  ],
65
- exports: [config_module_js_1.APP_CONFIG, exports.SHIELD_DECISION_AUTHORITY],
94
+ // Re-export the composed AuthModule app-wide ONLY when auth is opted in — its
95
+ // own `exports` (SHIELD_AUTHENTICATOR / SHIELD_SESSION_AUTHORITY) then become
96
+ // visible to a consumer's controllers/services via the @Global seam.
97
+ exports: [
98
+ config_module_js_1.APP_CONFIG,
99
+ exports.SHIELD_DECISION_AUTHORITY,
100
+ ...(authModule ? [authModule] : []),
101
+ ],
66
102
  };
67
103
  }
68
104
  /**
@@ -92,12 +128,37 @@ let ShieldModule = ShieldModule_1 = class ShieldModule {
92
128
  useFactory: (opts) => opts.decisionAuthority ?? core_seam_js_1.stubDecisionAuthority,
93
129
  inject: [optionsToken],
94
130
  };
131
+ // Same one-instance opt-in AuthModule as forRoot (imported + re-exported).
132
+ // `credentialResolver` is STATIC on the async options (like `auth`) — a
133
+ // registration-time collaborator, threaded straight through here.
134
+ const authModule = options.auth
135
+ ? auth_module_js_1.AuthModule.forRoot(
136
+ // Only pass the property when the consumer supplied one — under
137
+ // `exactOptionalPropertyTypes`, an explicit `undefined` is not assignable
138
+ // to the optional `credentialResolver`; a spread keeps it truly absent so
139
+ // AuthModule falls back to the default MariaDb binding.
140
+ options.credentialResolver
141
+ ? { credentialResolver: options.credentialResolver }
142
+ : {})
143
+ : undefined;
95
144
  return {
96
145
  module: ShieldModule_1,
97
146
  // Same single-path composition as forRoot (+ the caller's option imports).
98
- imports: [enforcement_module_js_1.EnforcementModule, boot_module_js_1.BootModule, ...(options.imports ?? [])],
147
+ // AuthModule is OPT-IN via the STATIC `options.auth` flag (see the interface
148
+ // doc — the imports list is composed statically, so auth cannot be gated on
149
+ // the async-resolved options).
150
+ imports: [
151
+ enforcement_module_js_1.EnforcementModule,
152
+ boot_module_js_1.BootModule,
153
+ ...(authModule ? [authModule] : []),
154
+ ...(options.imports ?? []),
155
+ ],
99
156
  providers: [asyncOptionsProvider, configProvider, authorityProvider],
100
- exports: [config_module_js_1.APP_CONFIG, exports.SHIELD_DECISION_AUTHORITY],
157
+ exports: [
158
+ config_module_js_1.APP_CONFIG,
159
+ exports.SHIELD_DECISION_AUTHORITY,
160
+ ...(authModule ? [authModule] : []),
161
+ ],
101
162
  };
102
163
  }
103
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/guard",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
6
6
  "type": "commonjs",
@@ -19,16 +19,11 @@
19
19
  "publishConfig": {
20
20
  "access": "public"
21
21
  },
22
- "scripts": {
23
- "build": "tsc -p tsconfig.build.json",
24
- "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
25
- "test": "vitest run"
26
- },
27
22
  "dependencies": {
28
- "@astram/core": "workspace:*",
29
23
  "argon2": "^0.41.1",
30
24
  "ioredis": "^5.4.1",
31
- "mariadb": "^3.4.0"
25
+ "mariadb": "^3.4.0",
26
+ "@astram/core": "0.1.0"
32
27
  },
33
28
  "peerDependencies": {
34
29
  "@nestjs/common": "^11",
@@ -48,5 +43,10 @@
48
43
  "typescript": "^5.7.0",
49
44
  "unplugin-swc": "^1.5.1",
50
45
  "vitest": "^2.1.8"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
50
+ "test": "vitest run"
51
51
  }
52
- }
52
+ }