@anarchitects/auth-nest 0.4.2 → 0.5.1

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 (104) hide show
  1. package/README.md +110 -37
  2. package/package.json +25 -12
  3. package/src/application/application.module-definition.d.ts +4 -21
  4. package/src/application/application.module-definition.js.map +1 -1
  5. package/src/application/application.module.d.ts +5 -22
  6. package/src/application/application.module.js +59 -8
  7. package/src/application/application.module.js.map +1 -1
  8. package/src/application/factories/ability.factory.js +3 -3
  9. package/src/application/factories/ability.factory.js.map +1 -1
  10. package/src/application/index.d.ts +8 -4
  11. package/src/application/index.js +7 -4
  12. package/src/application/index.js.map +1 -1
  13. package/src/application/resource-authorization.tokens.d.ts +1 -0
  14. package/src/application/resource-authorization.tokens.js +5 -0
  15. package/src/application/resource-authorization.tokens.js.map +1 -0
  16. package/src/application/resource-authorization.types.d.ts +16 -0
  17. package/src/application/resource-authorization.types.js +3 -0
  18. package/src/application/resource-authorization.types.js.map +1 -0
  19. package/src/application/services/auth-engine.port.d.ts +42 -0
  20. package/src/application/services/auth-engine.port.js +12 -0
  21. package/src/application/services/auth-engine.port.js.map +1 -0
  22. package/src/application/services/auth-orchestration.service.d.ts +41 -0
  23. package/src/application/services/auth-orchestration.service.js +161 -0
  24. package/src/application/services/auth-orchestration.service.js.map +1 -0
  25. package/src/application/services/jwt-auth.service.d.ts +6 -36
  26. package/src/application/services/jwt-auth.service.js +8 -201
  27. package/src/application/services/jwt-auth.service.js.map +1 -1
  28. package/src/application/services/persisted-policy-rule.d.ts +2 -0
  29. package/src/application/services/persisted-policy-rule.js +20 -0
  30. package/src/application/services/persisted-policy-rule.js.map +1 -0
  31. package/src/application/services/policies.service.js +7 -10
  32. package/src/application/services/policies.service.js.map +1 -1
  33. package/src/application/services/resource-authorization.d.ts +5 -0
  34. package/src/application/services/resource-authorization.js +18 -0
  35. package/src/application/services/resource-authorization.js.map +1 -0
  36. package/src/application/strategies/{jwt/strategy.d.ts → jwt-strategy.d.ts} +2 -1
  37. package/src/application/strategies/{jwt/strategy.js → jwt-strategy.js} +6 -4
  38. package/src/application/strategies/jwt-strategy.js.map +1 -0
  39. package/src/auth.module.d.ts +4 -11
  40. package/src/auth.module.js +40 -24
  41. package/src/auth.module.js.map +1 -1
  42. package/src/config/auth.config.d.ts +64 -0
  43. package/src/config/auth.config.js +115 -7
  44. package/src/config/auth.config.js.map +1 -1
  45. package/src/config/index.d.ts +1 -0
  46. package/src/config/index.js +1 -0
  47. package/src/config/index.js.map +1 -1
  48. package/src/config/module-options.d.ts +108 -0
  49. package/src/config/module-options.js +111 -0
  50. package/src/config/module-options.js.map +1 -0
  51. package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.d.ts +21 -0
  52. package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js +180 -0
  53. package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js.map +1 -0
  54. package/src/infrastructure-engine/better-auth/better-auth-spike.harness.d.ts +17 -0
  55. package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js +32 -0
  56. package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js.map +1 -0
  57. package/src/infrastructure-engine/better-auth/better-auth.module-loader.d.ts +7 -0
  58. package/src/infrastructure-engine/better-auth/better-auth.module-loader.js +15 -0
  59. package/src/infrastructure-engine/better-auth/better-auth.module-loader.js.map +1 -0
  60. package/src/infrastructure-engine/better-auth/dynamic-import.d.ts +1 -0
  61. package/src/infrastructure-engine/better-auth/dynamic-import.js +9 -0
  62. package/src/infrastructure-engine/better-auth/dynamic-import.js.map +1 -0
  63. package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.d.ts +22 -0
  64. package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.js +131 -0
  65. package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.js.map +1 -0
  66. package/src/infrastructure-mailer/index.d.ts +1 -0
  67. package/src/infrastructure-mailer/mailer.module.d.ts +4 -0
  68. package/src/infrastructure-mailer/mailer.module.js +31 -6
  69. package/src/infrastructure-mailer/mailer.module.js.map +1 -1
  70. package/src/infrastructure-persistence/index.d.ts +1 -0
  71. package/src/infrastructure-persistence/persistence.module-definition.d.ts +4 -9
  72. package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -1
  73. package/src/infrastructure-persistence/persistence.module.d.ts +4 -2
  74. package/src/infrastructure-persistence/persistence.module.js +21 -4
  75. package/src/infrastructure-persistence/persistence.module.js.map +1 -1
  76. package/src/presentation/authorized-resource.request.d.ts +7 -0
  77. package/src/presentation/authorized-resource.request.js +16 -0
  78. package/src/presentation/authorized-resource.request.js.map +1 -0
  79. package/src/presentation/decorators/authorize-resource.decorator.d.ts +3 -0
  80. package/src/presentation/decorators/authorize-resource.decorator.js +9 -0
  81. package/src/presentation/decorators/authorize-resource.decorator.js.map +1 -0
  82. package/src/presentation/decorators/authorized-resource.decorator.d.ts +2 -0
  83. package/src/presentation/decorators/authorized-resource.decorator.js +32 -0
  84. package/src/presentation/decorators/authorized-resource.decorator.js.map +1 -0
  85. package/src/presentation/decorators/policies.decorator.d.ts +2 -2
  86. package/src/presentation/decorators/policies.decorator.js.map +1 -1
  87. package/src/presentation/guards/policies.guard.js +6 -5
  88. package/src/presentation/guards/policies.guard.js.map +1 -1
  89. package/src/presentation/guards/resource-authorization.guard.d.ts +11 -0
  90. package/src/presentation/guards/resource-authorization.guard.js +55 -0
  91. package/src/presentation/guards/resource-authorization.guard.js.map +1 -0
  92. package/src/presentation/guards/route-policy-matcher.d.ts +1 -0
  93. package/src/presentation/guards/route-policy-matcher.js +6 -0
  94. package/src/presentation/guards/route-policy-matcher.js.map +1 -0
  95. package/src/presentation/index.d.ts +5 -0
  96. package/src/presentation/index.js +4 -0
  97. package/src/presentation/index.js.map +1 -1
  98. package/src/presentation/presentation.module.d.ts +4 -0
  99. package/src/presentation/presentation.module.js +43 -2
  100. package/src/presentation/presentation.module.js.map +1 -1
  101. package/src/presentation/route-policy.d.ts +1 -0
  102. package/src/presentation/route-policy.js +3 -0
  103. package/src/presentation/route-policy.js.map +1 -0
  104. package/src/application/strategies/jwt/strategy.js.map +0 -1
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertCanAccessResource = exports.toPolicySubject = void 0;
4
+ const ability_1 = require("@casl/ability");
5
+ const common_1 = require("@nestjs/common");
6
+ const toPolicySubject = (subjectType, resource) => (0, ability_1.subject)(subjectType, resource);
7
+ exports.toPolicySubject = toPolicySubject;
8
+ const assertCanAccessResource = (ability, action, subjectType, resource, field) => {
9
+ const policySubject = (0, exports.toPolicySubject)(subjectType, resource);
10
+ const isAllowed = field
11
+ ? ability.can(action, policySubject, field)
12
+ : ability.can(action, policySubject);
13
+ if (!isAllowed) {
14
+ throw new common_1.ForbiddenException();
15
+ }
16
+ };
17
+ exports.assertCanAccessResource = assertCanAccessResource;
18
+ //# sourceMappingURL=resource-authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-authorization.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/resource-authorization.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AACxC,2CAAoD;AAI7C,MAAM,eAAe,GAAG,CAC7B,WAAoB,EACpB,QAAW,EACX,EAAE,CAAC,IAAA,iBAAO,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAHvB,QAAA,eAAe,mBAGQ;AAE7B,MAAM,uBAAuB,GAAG,CACrC,OAAmB,EACnB,MAAc,EACd,WAAoB,EACpB,QAAW,EACX,KAAc,EACR,EAAE;IACR,MAAM,aAAa,GAAG,IAAA,uBAAe,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC7D,MAAM,SAAS,GAAG,KAAK;QACrB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,CAAC;QAC3C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAEvC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,2BAAkB,EAAE,CAAC;IACjC,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,uBAAuB,2BAelC"}
@@ -1,10 +1,11 @@
1
1
  import { Role } from '@anarchitects/auth-ts/models';
2
2
  import { Strategy } from 'passport-jwt';
3
+ import { AuthConfig } from '../../config';
3
4
  declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
4
5
  validate(...args: any[]): unknown;
5
6
  };
6
7
  export declare class JwtStrategy extends JwtStrategy_base {
7
- constructor();
8
+ constructor(authConfig: AuthConfig);
8
9
  validate(payload: {
9
10
  sub: string;
10
11
  roles: Role[];
@@ -5,12 +5,13 @@ const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const passport_1 = require("@nestjs/passport");
7
7
  const passport_jwt_1 = require("passport-jwt");
8
+ const config_1 = require("../../config");
8
9
  let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
9
- constructor() {
10
+ constructor(authConfig) {
10
11
  super({
11
12
  jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
12
13
  ignoreExpiration: false,
13
- secretOrKey: process.env['JWT_SECRET'] || 'defaultSecret',
14
+ secretOrKey: authConfig.jwtSecret,
14
15
  });
15
16
  }
16
17
  async validate(payload) {
@@ -20,6 +21,7 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
20
21
  exports.JwtStrategy = JwtStrategy;
21
22
  exports.JwtStrategy = JwtStrategy = tslib_1.__decorate([
22
23
  (0, common_1.Injectable)(),
23
- tslib_1.__metadata("design:paramtypes", [])
24
+ tslib_1.__param(0, (0, config_1.InjectAuthConfig)()),
25
+ tslib_1.__metadata("design:paramtypes", [Object])
24
26
  ], JwtStrategy);
25
- //# sourceMappingURL=strategy.js.map
27
+ //# sourceMappingURL=jwt-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-strategy.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/strategies/jwt-strategy.ts"],"names":[],"mappings":";;;;AACA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAoD;AACpD,yCAA4D;AAGrD,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD,YAAgC,UAAsB;QACpD,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,UAAU,CAAC,SAAS;SAClC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuC;QACpD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACvD,CAAC;CACF,CAAA;AAZY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAEE,mBAAA,IAAA,yBAAgB,GAAE,CAAA;;GADpB,WAAW,CAYvB"}
@@ -1,14 +1,7 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
- import { AuthApplicationModule } from './application';
3
- import { AuthPersistenceModule } from './infrastructure-persistence';
4
- export type AuthModuleFeatures = {
5
- mailer?: boolean;
6
- };
7
- export type AuthModuleOptions = {
8
- application: Parameters<typeof AuthApplicationModule.forRoot>[0];
9
- persistence: Parameters<typeof AuthPersistenceModule.forRoot>[0];
10
- features?: AuthModuleFeatures;
11
- };
2
+ import type { AuthModuleOptions } from './config';
3
+ export type { AuthModuleFeatures, AuthModuleOptions } from './config';
12
4
  export declare class AuthModule {
13
- static forRoot(options: AuthModuleOptions): DynamicModule;
5
+ static forRoot(options?: AuthModuleOptions): DynamicModule;
6
+ static forRootFromConfig(overrides?: AuthModuleOptions): DynamicModule;
14
7
  }
@@ -5,35 +5,51 @@ exports.AuthModule = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const common_1 = require("@nestjs/common");
7
7
  const config_1 = require("@nestjs/config");
8
- const application_1 = require("./application");
9
- const config_2 = require("./config");
10
8
  const infrastructure_mailer_1 = require("./infrastructure-mailer");
11
- const infrastructure_persistence_1 = require("./infrastructure-persistence");
12
9
  const presentation_1 = require("./presentation");
10
+ const config_2 = require("./config");
13
11
  let AuthModule = AuthModule_1 = class AuthModule {
14
- static forRoot(options) {
15
- const mailerEnabled = options.features?.mailer ?? true;
16
- const applicationModule = application_1.AuthApplicationModule.forRoot(options.application);
17
- const persistenceModule = infrastructure_persistence_1.AuthPersistenceModule.forRoot(options.persistence);
18
- const imports = [
19
- config_1.ConfigModule.forFeature(config_2.authConfig),
20
- applicationModule,
21
- persistenceModule,
22
- presentation_1.AuthPresentationModule,
23
- ];
24
- const exports = [
25
- applicationModule,
26
- persistenceModule,
27
- presentation_1.AuthPresentationModule,
28
- ];
29
- if (mailerEnabled) {
30
- imports.push(infrastructure_mailer_1.AuthMailerModule);
31
- exports.push(infrastructure_mailer_1.AuthMailerModule);
32
- }
12
+ static forRoot(options = {}) {
13
+ const presentationModule = presentation_1.AuthPresentationModule.forRoot(options.presentation);
14
+ const mailerModule = infrastructure_mailer_1.AuthMailerModule.forRoot(options.mailer);
33
15
  return {
34
16
  module: AuthModule_1,
35
- imports,
36
- exports,
17
+ imports: [presentationModule, mailerModule],
18
+ exports: [presentationModule, mailerModule],
19
+ };
20
+ }
21
+ static forRootFromConfig(overrides = {}) {
22
+ const configOptions = (0, config_2.mapAuthConfigToAuthModuleOptions)((0, config_2.authConfig)());
23
+ const moduleDefinition = this.forRoot({
24
+ ...configOptions,
25
+ ...overrides,
26
+ presentation: {
27
+ ...configOptions.presentation,
28
+ ...overrides.presentation,
29
+ application: {
30
+ ...configOptions.presentation?.application,
31
+ ...overrides.presentation?.application,
32
+ encryption: {
33
+ ...configOptions.presentation?.application?.encryption,
34
+ ...overrides.presentation?.application?.encryption,
35
+ },
36
+ persistence: {
37
+ ...configOptions.presentation?.application?.persistence,
38
+ ...overrides.presentation?.application?.persistence,
39
+ },
40
+ },
41
+ },
42
+ mailer: {
43
+ ...configOptions.mailer,
44
+ ...overrides.mailer,
45
+ },
46
+ });
47
+ return {
48
+ ...moduleDefinition,
49
+ imports: [
50
+ config_1.ConfigModule.forFeature(config_2.authConfig),
51
+ ...(moduleDefinition.imports ?? []),
52
+ ],
37
53
  };
38
54
  }
39
55
  };
@@ -1 +1 @@
1
- {"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../../../../libs/auth/nest/src/auth.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAAuD;AACvD,2CAA8C;AAC9C,+CAAsD;AACtD,qCAAsC;AACtC,mEAA2D;AAC3D,6EAAqE;AACrE,iDAAwD;AAajD,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAC,OAA0B;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,IAAI,CAAC;QACvD,MAAM,iBAAiB,GAAG,mCAAqB,CAAC,OAAO,CACrD,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,iBAAiB,GAAG,kDAAqB,CAAC,OAAO,CACrD,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,OAAO,GAAG;YACd,qBAAY,CAAC,UAAU,CAAC,mBAAU,CAAC;YACnC,iBAAiB;YACjB,iBAAiB;YACjB,qCAAsB;SACvB,CAAC;QACF,MAAM,OAAO,GAAG;YACd,iBAAiB;YACjB,iBAAiB;YACjB,qCAAsB;SACvB,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,wCAAgB,CAAC,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,wCAAgB,CAAC,CAAC;QACjC,CAAC;QAED,OAAO;YACL,MAA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AE,WAAW,EAAE,UAAU;qBACnD;oBACD,WAAW,EAAE;wBACX,GAAG,aAAa,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW;wBACvD,GAAG,SAAS,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW;qBACpD;iBACF;aACF;YACD,MAAM,EAAE;gBACN,GAAG,aAAa,CAAC,MAAM;gBACvB,GAAG,SAAS,CAAC,MAAM;aACpB;SACF,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,gBAAgB;YACnB,OAAO,EAAE;gBACP,qBAAY,CAAC,UAAU,CAAC,mBAAU,CAAC;gBACnC,GAAG,CAAC,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC;aACpC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAhDY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAgDtB"}
@@ -1,4 +1,16 @@
1
1
  import { ConfigType } from '@nestjs/config';
2
+ import type { CommonMailerProvider } from '@anarchitects/common-nest-mailer';
3
+ export declare const DEFAULT_AUTH_JWT_SECRET = "default_jwt_secret";
4
+ export declare const DEFAULT_AUTH_JWT_EXPIRATION = "3600s";
5
+ export declare const DEFAULT_AUTH_JWT_AUDIENCE = "your_audience";
6
+ export declare const DEFAULT_AUTH_JWT_ISSUER = "your_issuer";
7
+ export declare const DEFAULT_AUTH_ENCRYPTION_ALGORITHM = "bcrypt";
8
+ export declare const DEFAULT_AUTH_ENCRYPTION_KEY = "default_encryption_key";
9
+ export declare const DEFAULT_AUTH_PERSISTENCE = "typeorm";
10
+ export declare const DEFAULT_AUTH_MAILER_PROVIDER = "node";
11
+ export declare const DEFAULT_AUTH_STRATEGIES: readonly ["jwt"];
12
+ export declare const DEFAULT_AUTH_ENGINE = "legacy-jwt";
13
+ export declare const DEFAULT_AUTH_SESSION_MODE = "jwt";
2
14
  export declare const authConfig: (() => {
3
15
  jwtSecret: string;
4
16
  jwtExpiration: string;
@@ -6,6 +18,32 @@ export declare const authConfig: (() => {
6
18
  jwtIssuer: string;
7
19
  encryptionAlgorithm: string;
8
20
  encryptionKey: string;
21
+ persistence: string;
22
+ mailerProvider: CommonMailerProvider;
23
+ authStrategies: string[];
24
+ engine: "legacy-jwt" | "better-auth";
25
+ sessionMode: "jwt" | "session";
26
+ features: {
27
+ passkeys: boolean;
28
+ social: boolean;
29
+ oidc: boolean;
30
+ };
31
+ spike: {
32
+ baseUrl: string;
33
+ secret: string;
34
+ proofHarnessEnabled: boolean;
35
+ socialProviders: {
36
+ github: {
37
+ clientId: string | undefined;
38
+ clientSecret: string | undefined;
39
+ };
40
+ };
41
+ passkeys: {
42
+ rpID: string;
43
+ rpName: string;
44
+ origin: string | undefined;
45
+ };
46
+ };
9
47
  }) & import("@nestjs/config").ConfigFactoryKeyHost<{
10
48
  jwtSecret: string;
11
49
  jwtExpiration: string;
@@ -13,6 +51,32 @@ export declare const authConfig: (() => {
13
51
  jwtIssuer: string;
14
52
  encryptionAlgorithm: string;
15
53
  encryptionKey: string;
54
+ persistence: string;
55
+ mailerProvider: CommonMailerProvider;
56
+ authStrategies: string[];
57
+ engine: "legacy-jwt" | "better-auth";
58
+ sessionMode: "jwt" | "session";
59
+ features: {
60
+ passkeys: boolean;
61
+ social: boolean;
62
+ oidc: boolean;
63
+ };
64
+ spike: {
65
+ baseUrl: string;
66
+ secret: string;
67
+ proofHarnessEnabled: boolean;
68
+ socialProviders: {
69
+ github: {
70
+ clientId: string | undefined;
71
+ clientSecret: string | undefined;
72
+ };
73
+ };
74
+ passkeys: {
75
+ rpID: string;
76
+ rpName: string;
77
+ origin: string | undefined;
78
+ };
79
+ };
16
80
  }>;
17
81
  export type AuthConfig = ConfigType<typeof authConfig>;
18
82
  export declare const InjectAuthConfig: () => PropertyDecorator & ParameterDecorator;
@@ -1,16 +1,124 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectAuthConfig = exports.authConfig = void 0;
3
+ exports.InjectAuthConfig = exports.authConfig = exports.DEFAULT_AUTH_SESSION_MODE = exports.DEFAULT_AUTH_ENGINE = exports.DEFAULT_AUTH_STRATEGIES = exports.DEFAULT_AUTH_MAILER_PROVIDER = exports.DEFAULT_AUTH_PERSISTENCE = exports.DEFAULT_AUTH_ENCRYPTION_KEY = exports.DEFAULT_AUTH_ENCRYPTION_ALGORITHM = exports.DEFAULT_AUTH_JWT_ISSUER = exports.DEFAULT_AUTH_JWT_AUDIENCE = exports.DEFAULT_AUTH_JWT_EXPIRATION = exports.DEFAULT_AUTH_JWT_SECRET = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const config_1 = require("@nestjs/config");
6
6
  const AUTH_CONFIG_KEY = 'auth';
7
+ exports.DEFAULT_AUTH_JWT_SECRET = 'default_jwt_secret';
8
+ exports.DEFAULT_AUTH_JWT_EXPIRATION = '3600s';
9
+ exports.DEFAULT_AUTH_JWT_AUDIENCE = 'your_audience';
10
+ exports.DEFAULT_AUTH_JWT_ISSUER = 'your_issuer';
11
+ exports.DEFAULT_AUTH_ENCRYPTION_ALGORITHM = 'bcrypt';
12
+ exports.DEFAULT_AUTH_ENCRYPTION_KEY = 'default_encryption_key';
13
+ exports.DEFAULT_AUTH_PERSISTENCE = 'typeorm';
14
+ exports.DEFAULT_AUTH_MAILER_PROVIDER = 'node';
15
+ exports.DEFAULT_AUTH_STRATEGIES = ['jwt'];
16
+ exports.DEFAULT_AUTH_ENGINE = 'legacy-jwt';
17
+ exports.DEFAULT_AUTH_SESSION_MODE = 'jwt';
18
+ const parseBoolean = (value, fallback = false) => {
19
+ if (value === undefined) {
20
+ return fallback;
21
+ }
22
+ switch (value.trim().toLowerCase()) {
23
+ case '1':
24
+ case 'true':
25
+ case 'yes':
26
+ case 'on':
27
+ return true;
28
+ case '0':
29
+ case 'false':
30
+ case 'no':
31
+ case 'off':
32
+ return false;
33
+ default:
34
+ throw new Error(`Unsupported boolean value: ${value}`);
35
+ }
36
+ };
37
+ const parseMailerProvider = () => {
38
+ const value = process.env['AUTH_MAILER_PROVIDER'];
39
+ if (value === undefined) {
40
+ return exports.DEFAULT_AUTH_MAILER_PROVIDER;
41
+ }
42
+ switch (value) {
43
+ case 'node':
44
+ case 'noop':
45
+ return value;
46
+ default:
47
+ throw new Error(`Unsupported mailer provider: ${value}`);
48
+ }
49
+ };
50
+ const parseAuthStrategies = () => {
51
+ const raw = process.env['AUTH_STRATEGIES'];
52
+ if (!raw) {
53
+ return [...exports.DEFAULT_AUTH_STRATEGIES];
54
+ }
55
+ const parsed = raw
56
+ .split(',')
57
+ .map((strategy) => strategy.trim())
58
+ .filter((strategy) => strategy.length > 0);
59
+ return parsed.length > 0 ? parsed : [...exports.DEFAULT_AUTH_STRATEGIES];
60
+ };
61
+ const parseAuthEngine = () => {
62
+ const value = process.env['AUTH_ENGINE'];
63
+ if (value === undefined) {
64
+ return exports.DEFAULT_AUTH_ENGINE;
65
+ }
66
+ switch (value) {
67
+ case 'legacy-jwt':
68
+ case 'better-auth':
69
+ return value;
70
+ default:
71
+ throw new Error(`Unsupported auth engine: ${value}`);
72
+ }
73
+ };
74
+ const parseSessionMode = () => {
75
+ const value = process.env['AUTH_SESSION_MODE'];
76
+ if (value === undefined) {
77
+ return exports.DEFAULT_AUTH_SESSION_MODE;
78
+ }
79
+ switch (value) {
80
+ case 'jwt':
81
+ case 'session':
82
+ return value;
83
+ default:
84
+ throw new Error(`Unsupported auth session mode: ${value}`);
85
+ }
86
+ };
7
87
  exports.authConfig = (0, config_1.registerAs)(AUTH_CONFIG_KEY, () => ({
8
- jwtSecret: process.env['AUTH_JWT_SECRET'] || 'default_jwt_secret',
9
- jwtExpiration: process.env['AUTH_JWT_EXPIRATION'] || '3600s',
10
- jwtAudience: process.env['AUTH_JWT_AUDIENCE'] || 'your_audience',
11
- jwtIssuer: process.env['AUTH_JWT_ISSUER'] || 'your_issuer',
12
- encryptionAlgorithm: process.env['AUTH_ENCRYPTION_ALGORITHM'] || 'bcrypt',
13
- encryptionKey: process.env['AUTH_ENCRYPTION_KEY'] || 'default_encryption_key',
88
+ jwtSecret: process.env['AUTH_JWT_SECRET'] ?? exports.DEFAULT_AUTH_JWT_SECRET,
89
+ jwtExpiration: process.env['AUTH_JWT_EXPIRATION'] ?? exports.DEFAULT_AUTH_JWT_EXPIRATION,
90
+ jwtAudience: process.env['AUTH_JWT_AUDIENCE'] ?? exports.DEFAULT_AUTH_JWT_AUDIENCE,
91
+ jwtIssuer: process.env['AUTH_JWT_ISSUER'] ?? exports.DEFAULT_AUTH_JWT_ISSUER,
92
+ encryptionAlgorithm: process.env['AUTH_ENCRYPTION_ALGORITHM'] ??
93
+ exports.DEFAULT_AUTH_ENCRYPTION_ALGORITHM,
94
+ encryptionKey: process.env['AUTH_ENCRYPTION_KEY'] ?? exports.DEFAULT_AUTH_ENCRYPTION_KEY,
95
+ persistence: process.env['AUTH_PERSISTENCE'] ?? exports.DEFAULT_AUTH_PERSISTENCE,
96
+ mailerProvider: parseMailerProvider(),
97
+ authStrategies: parseAuthStrategies(),
98
+ engine: parseAuthEngine(),
99
+ sessionMode: parseSessionMode(),
100
+ features: {
101
+ passkeys: parseBoolean(process.env['AUTH_FEATURE_PASSKEYS']),
102
+ social: parseBoolean(process.env['AUTH_FEATURE_SOCIAL']),
103
+ oidc: parseBoolean(process.env['AUTH_FEATURE_OIDC']),
104
+ },
105
+ spike: {
106
+ baseUrl: process.env['AUTH_SPIKE_BASE_URL'] ?? 'http://localhost:3000/api/auth',
107
+ secret: process.env['AUTH_SPIKE_SECRET'] ??
108
+ 'better-auth-spike-secret-32-chars-minimum',
109
+ proofHarnessEnabled: parseBoolean(process.env['AUTH_SPIKE_PROOF_HARNESS']),
110
+ socialProviders: {
111
+ github: {
112
+ clientId: process.env['AUTH_SOCIAL_GITHUB_CLIENT_ID'],
113
+ clientSecret: process.env['AUTH_SOCIAL_GITHUB_CLIENT_SECRET'],
114
+ },
115
+ },
116
+ passkeys: {
117
+ rpID: process.env['AUTH_PASSKEY_RP_ID'] ?? 'localhost',
118
+ rpName: process.env['AUTH_PASSKEY_RP_NAME'] ?? 'Anarchitecture Auth Spike',
119
+ origin: process.env['AUTH_PASSKEY_ORIGIN'],
120
+ },
121
+ },
14
122
  }));
15
123
  const InjectAuthConfig = () => (0, common_1.Inject)(exports.authConfig.KEY);
16
124
  exports.InjectAuthConfig = InjectAuthConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.config.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/auth.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,2CAAwD;AAExD,MAAM,eAAe,GAAG,MAAM,CAAC;AAElB,QAAA,UAAU,GAAG,IAAA,mBAAU,EAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3D,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,oBAAoB;IACjE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,OAAO;IAC5D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,eAAe;IAChE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,aAAa;IAC1D,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,IAAI,QAAQ;IACzE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,wBAAwB;CAC9E,CAAC,CAAC,CAAC;AAIG,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,kBAAU,CAAC,GAAG,CAAC,CAAC;AAAhD,QAAA,gBAAgB,oBAAgC"}
1
+ {"version":3,"file":"auth.config.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/auth.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,2CAAwD;AAGxD,MAAM,eAAe,GAAG,MAAM,CAAC;AAClB,QAAA,uBAAuB,GAAG,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AAgC;QACxE,MAAM,EACJ,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;YAChC,2CAA2C;QAC7C,mBAAmB,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC1E,eAAe,EAAE;YACf,MAAM,EAAE;gBACN,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC;gBACrD,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC;aAC9D;SACF;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,WAAW;YACtD,MAAM,EACJ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,2BAA2B;YACpE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;SAC3C;KACF;CACF,CAAC,CAAC,CAAC;AAIG,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,kBAAU,CAAC,GAAG,CAAC,CAAC;AAAhD,QAAA,gBAAgB,oBAAgC"}
@@ -1 +1,2 @@
1
1
  export * from './auth.config';
2
+ export * from './module-options';
@@ -2,4 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./auth.config"), exports);
5
+ tslib_1.__exportStar(require("./module-options"), exports);
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,2DAAiC"}
@@ -0,0 +1,108 @@
1
+ import type { CommonMailerProvider } from '@anarchitects/common-nest-mailer';
2
+ import type { AuthConfig } from './auth.config';
3
+ import type { ResourceAuthorizationOptions } from '../application/resource-authorization.types';
4
+ export type AuthEngine = 'legacy-jwt' | 'better-auth';
5
+ export type AuthSessionMode = 'jwt' | 'session';
6
+ export type AuthSpikeSocialProviderConfig = {
7
+ clientId?: string;
8
+ clientSecret?: string;
9
+ };
10
+ export type AuthSpikeOptions = {
11
+ baseUrl?: string;
12
+ secret?: string;
13
+ proofHarnessEnabled?: boolean;
14
+ socialProviders?: {
15
+ github?: AuthSpikeSocialProviderConfig;
16
+ };
17
+ passkeys?: {
18
+ rpID?: string;
19
+ rpName?: string;
20
+ origin?: string;
21
+ };
22
+ };
23
+ export type ResolvedAuthSpikeOptions = {
24
+ baseUrl: string;
25
+ secret: string;
26
+ proofHarnessEnabled: boolean;
27
+ socialProviders: {
28
+ github?: AuthSpikeSocialProviderConfig;
29
+ };
30
+ passkeys: {
31
+ rpID: string;
32
+ rpName: string;
33
+ origin?: string;
34
+ };
35
+ };
36
+ export type AuthPersistenceModuleOptions = {
37
+ persistence?: string;
38
+ };
39
+ export type ResolvedAuthPersistenceModuleOptions = {
40
+ persistence: string;
41
+ };
42
+ export type AuthMailerModuleOptions = {
43
+ provider?: CommonMailerProvider;
44
+ };
45
+ export type ResolvedAuthMailerModuleOptions = {
46
+ provider: CommonMailerProvider;
47
+ };
48
+ export type AuthApplicationModuleOptions = {
49
+ authStrategies?: string[];
50
+ engine?: AuthEngine;
51
+ sessionMode?: AuthSessionMode;
52
+ features?: {
53
+ passkeys?: boolean;
54
+ social?: boolean;
55
+ oidc?: boolean;
56
+ };
57
+ spike?: AuthSpikeOptions;
58
+ encryption?: {
59
+ algorithm?: 'bcrypt' | 'argon2';
60
+ key?: string;
61
+ };
62
+ persistence?: AuthPersistenceModuleOptions;
63
+ resourceAuthorization?: ResourceAuthorizationOptions;
64
+ };
65
+ export type ResolvedAuthApplicationModuleOptions = {
66
+ authStrategies: string[];
67
+ engine: AuthEngine;
68
+ sessionMode: AuthSessionMode;
69
+ features: {
70
+ passkeys: boolean;
71
+ social: boolean;
72
+ oidc: boolean;
73
+ };
74
+ spike: ResolvedAuthSpikeOptions;
75
+ encryption: {
76
+ algorithm: 'bcrypt' | 'argon2';
77
+ key: string;
78
+ };
79
+ persistence: ResolvedAuthPersistenceModuleOptions;
80
+ resourceAuthorization: Required<ResourceAuthorizationOptions>;
81
+ };
82
+ export type AuthPresentationModuleOptions = {
83
+ application?: AuthApplicationModuleOptions;
84
+ };
85
+ export type ResolvedAuthPresentationModuleOptions = {
86
+ application: ResolvedAuthApplicationModuleOptions;
87
+ };
88
+ export type AuthModuleFeatures = {
89
+ provider?: CommonMailerProvider;
90
+ };
91
+ export type AuthModuleOptions = {
92
+ presentation?: AuthPresentationModuleOptions;
93
+ mailer?: AuthMailerModuleOptions;
94
+ };
95
+ export type ResolvedAuthModuleOptions = {
96
+ presentation: ResolvedAuthPresentationModuleOptions;
97
+ mailer: ResolvedAuthMailerModuleOptions;
98
+ };
99
+ export declare const resolveAuthPersistenceModuleOptions: (options?: AuthPersistenceModuleOptions) => ResolvedAuthPersistenceModuleOptions;
100
+ export declare const resolveAuthMailerModuleOptions: (options?: AuthMailerModuleOptions) => ResolvedAuthMailerModuleOptions;
101
+ export declare const resolveAuthApplicationModuleOptions: (options?: AuthApplicationModuleOptions) => ResolvedAuthApplicationModuleOptions;
102
+ export declare const resolveAuthPresentationModuleOptions: (options?: AuthPresentationModuleOptions) => ResolvedAuthPresentationModuleOptions;
103
+ export declare const resolveAuthModuleOptions: (options?: AuthModuleOptions) => ResolvedAuthModuleOptions;
104
+ export declare const mapAuthConfigToPersistenceModuleOptions: (config: AuthConfig) => AuthPersistenceModuleOptions;
105
+ export declare const mapAuthConfigToMailerModuleOptions: (config: AuthConfig) => AuthMailerModuleOptions;
106
+ export declare const mapAuthConfigToApplicationModuleOptions: (config: AuthConfig) => AuthApplicationModuleOptions;
107
+ export declare const mapAuthConfigToPresentationModuleOptions: (config: AuthConfig) => AuthPresentationModuleOptions;
108
+ export declare const mapAuthConfigToAuthModuleOptions: (config: AuthConfig) => AuthModuleOptions;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAuthConfigToAuthModuleOptions = exports.mapAuthConfigToPresentationModuleOptions = exports.mapAuthConfigToApplicationModuleOptions = exports.mapAuthConfigToMailerModuleOptions = exports.mapAuthConfigToPersistenceModuleOptions = exports.resolveAuthModuleOptions = exports.resolveAuthPresentationModuleOptions = exports.resolveAuthApplicationModuleOptions = exports.resolveAuthMailerModuleOptions = exports.resolveAuthPersistenceModuleOptions = void 0;
4
+ const auth_config_1 = require("./auth.config");
5
+ const resolveAuthPersistenceModuleOptions = (options = {}) => ({
6
+ persistence: options.persistence ?? auth_config_1.DEFAULT_AUTH_PERSISTENCE,
7
+ });
8
+ exports.resolveAuthPersistenceModuleOptions = resolveAuthPersistenceModuleOptions;
9
+ const resolveAuthMailerModuleOptions = (options = {}) => ({
10
+ provider: options.provider ?? auth_config_1.DEFAULT_AUTH_MAILER_PROVIDER,
11
+ });
12
+ exports.resolveAuthMailerModuleOptions = resolveAuthMailerModuleOptions;
13
+ const resolveAuthApplicationModuleOptions = (options = {}) => ({
14
+ authStrategies: options.authStrategies ?? [...auth_config_1.DEFAULT_AUTH_STRATEGIES],
15
+ engine: options.engine ?? 'legacy-jwt',
16
+ sessionMode: options.sessionMode ?? 'jwt',
17
+ features: {
18
+ passkeys: options.features?.passkeys ?? false,
19
+ social: options.features?.social ?? false,
20
+ oidc: options.features?.oidc ?? false,
21
+ },
22
+ spike: {
23
+ baseUrl: options.spike?.baseUrl ?? 'http://localhost:3000/api/auth',
24
+ secret: options.spike?.secret ?? 'better-auth-spike-secret-32-chars-minimum',
25
+ proofHarnessEnabled: options.spike?.proofHarnessEnabled ?? false,
26
+ socialProviders: {
27
+ github: options.spike?.socialProviders?.github
28
+ ? {
29
+ clientId: options.spike.socialProviders.github.clientId,
30
+ clientSecret: options.spike.socialProviders.github.clientSecret,
31
+ }
32
+ : undefined,
33
+ },
34
+ passkeys: {
35
+ rpID: options.spike?.passkeys?.rpID ?? 'localhost',
36
+ rpName: options.spike?.passkeys?.rpName ?? 'Anarchitecture Auth Spike',
37
+ origin: options.spike?.passkeys?.origin,
38
+ },
39
+ },
40
+ encryption: {
41
+ algorithm: options.encryption?.algorithm ??
42
+ auth_config_1.DEFAULT_AUTH_ENCRYPTION_ALGORITHM,
43
+ key: options.encryption?.key ?? auth_config_1.DEFAULT_AUTH_ENCRYPTION_KEY,
44
+ },
45
+ persistence: (0, exports.resolveAuthPersistenceModuleOptions)(options.persistence),
46
+ resourceAuthorization: {
47
+ loaders: { ...(options.resourceAuthorization?.loaders ?? {}) },
48
+ },
49
+ });
50
+ exports.resolveAuthApplicationModuleOptions = resolveAuthApplicationModuleOptions;
51
+ const resolveAuthPresentationModuleOptions = (options = {}) => ({
52
+ application: (0, exports.resolveAuthApplicationModuleOptions)(options.application),
53
+ });
54
+ exports.resolveAuthPresentationModuleOptions = resolveAuthPresentationModuleOptions;
55
+ const resolveAuthModuleOptions = (options = {}) => ({
56
+ presentation: (0, exports.resolveAuthPresentationModuleOptions)(options.presentation),
57
+ mailer: (0, exports.resolveAuthMailerModuleOptions)(options.mailer),
58
+ });
59
+ exports.resolveAuthModuleOptions = resolveAuthModuleOptions;
60
+ const mapAuthConfigToPersistenceModuleOptions = (config) => ({
61
+ persistence: config.persistence ?? auth_config_1.DEFAULT_AUTH_PERSISTENCE,
62
+ });
63
+ exports.mapAuthConfigToPersistenceModuleOptions = mapAuthConfigToPersistenceModuleOptions;
64
+ const mapAuthConfigToMailerModuleOptions = (config) => ({
65
+ provider: config.mailerProvider ?? auth_config_1.DEFAULT_AUTH_MAILER_PROVIDER,
66
+ });
67
+ exports.mapAuthConfigToMailerModuleOptions = mapAuthConfigToMailerModuleOptions;
68
+ const mapAuthConfigToApplicationModuleOptions = (config) => ({
69
+ authStrategies: config.authStrategies ?? [...auth_config_1.DEFAULT_AUTH_STRATEGIES],
70
+ engine: config.engine ?? 'legacy-jwt',
71
+ sessionMode: config.sessionMode ?? 'jwt',
72
+ features: {
73
+ passkeys: config.features?.passkeys ?? false,
74
+ social: config.features?.social ?? false,
75
+ oidc: config.features?.oidc ?? false,
76
+ },
77
+ spike: {
78
+ baseUrl: config.spike?.baseUrl ?? 'http://localhost:3000/api/auth',
79
+ secret: config.spike?.secret ?? 'better-auth-spike-secret-32-chars-minimum',
80
+ proofHarnessEnabled: config.spike?.proofHarnessEnabled ?? false,
81
+ socialProviders: {
82
+ github: config.spike?.socialProviders?.github
83
+ ? {
84
+ clientId: config.spike.socialProviders.github.clientId,
85
+ clientSecret: config.spike.socialProviders.github.clientSecret,
86
+ }
87
+ : undefined,
88
+ },
89
+ passkeys: {
90
+ rpID: config.spike?.passkeys?.rpID ?? 'localhost',
91
+ rpName: config.spike?.passkeys?.rpName ?? 'Anarchitecture Auth Spike',
92
+ origin: config.spike?.passkeys?.origin,
93
+ },
94
+ },
95
+ encryption: {
96
+ algorithm: config.encryptionAlgorithm,
97
+ key: config.encryptionKey ?? auth_config_1.DEFAULT_AUTH_ENCRYPTION_KEY,
98
+ },
99
+ persistence: (0, exports.mapAuthConfigToPersistenceModuleOptions)(config),
100
+ });
101
+ exports.mapAuthConfigToApplicationModuleOptions = mapAuthConfigToApplicationModuleOptions;
102
+ const mapAuthConfigToPresentationModuleOptions = (config) => ({
103
+ application: (0, exports.mapAuthConfigToApplicationModuleOptions)(config),
104
+ });
105
+ exports.mapAuthConfigToPresentationModuleOptions = mapAuthConfigToPresentationModuleOptions;
106
+ const mapAuthConfigToAuthModuleOptions = (config) => ({
107
+ presentation: (0, exports.mapAuthConfigToPresentationModuleOptions)(config),
108
+ mailer: (0, exports.mapAuthConfigToMailerModuleOptions)(config),
109
+ });
110
+ exports.mapAuthConfigToAuthModuleOptions = mapAuthConfigToAuthModuleOptions;
111
+ //# sourceMappingURL=module-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-options.js","sourceRoot":"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