@vynelix/nestjs-multi-auth 1.0.2 → 1.0.3

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 (129) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/dist/auth/auth.module.js +28 -28
  4. package/dist/auth/auth.module.js.map +1 -1
  5. package/dist/auth/core/database-otp.provider.js +14 -4
  6. package/dist/auth/core/database-otp.provider.js.map +1 -1
  7. package/dist/auth/decorator/current-user.decorator.d.ts +1 -1
  8. package/dist/auth/interfaces/auth-module-async-options.interface.d.ts +2 -0
  9. package/dist/auth/strategies/local-auth.strategy.js +1 -0
  10. package/dist/auth/strategies/local-auth.strategy.js.map +1 -1
  11. package/dist/database/typeorm/entities/entities.d.ts +1 -1
  12. package/dist/database/typeorm/migrations/auth-entities.d.ts +1 -1
  13. package/dist/database/typeorm/repositories/auth-identifier.repository.js +11 -6
  14. package/dist/database/typeorm/repositories/auth-identifier.repository.js.map +1 -1
  15. package/dist/database/typeorm/repositories/otp-token.repository.js +2 -1
  16. package/dist/database/typeorm/repositories/otp-token.repository.js.map +1 -1
  17. package/dist/tsconfig.tsbuildinfo +1 -1
  18. package/package.json +1 -1
  19. package/dist/auth/auth-type.enum.d.ts +0 -22
  20. package/dist/auth/auth-type.enum.js +0 -32
  21. package/dist/auth/auth-type.enum.js.map +0 -1
  22. package/dist/auth/core/cookie-namespace.resolver.d.ts +0 -8
  23. package/dist/auth/core/cookie-namespace.resolver.js +0 -48
  24. package/dist/auth/core/cookie-namespace.resolver.js.map +0 -1
  25. package/dist/auth/current-user-interface.d.ts +0 -4
  26. package/dist/auth/current-user-interface.js +0 -4
  27. package/dist/auth/current-user-interface.js.map +0 -1
  28. package/dist/auth/current-user.decorator.d.ts +0 -2
  29. package/dist/auth/current-user.decorator.js +0 -16
  30. package/dist/auth/current-user.decorator.js.map +0 -1
  31. package/dist/auth/dto/auth-response.dto.d.ts +0 -17
  32. package/dist/auth/dto/auth-response.dto.js +0 -83
  33. package/dist/auth/dto/auth-response.dto.js.map +0 -1
  34. package/dist/auth/dto/identifier-response.dto.d.ts +0 -8
  35. package/dist/auth/dto/identifier-response.dto.js +0 -46
  36. package/dist/auth/dto/identifier-response.dto.js.map +0 -1
  37. package/dist/auth/dto/login.dto.d.ts +0 -11
  38. package/dist/auth/dto/login.dto.js +0 -68
  39. package/dist/auth/dto/login.dto.js.map +0 -1
  40. package/dist/auth/dto/mfa.dto.d.ts +0 -8
  41. package/dist/auth/dto/mfa.dto.js +0 -51
  42. package/dist/auth/dto/mfa.dto.js.map +0 -1
  43. package/dist/auth/dto/oauth-provider-response.dto.d.ts +0 -5
  44. package/dist/auth/dto/oauth-provider-response.dto.js +0 -30
  45. package/dist/auth/dto/oauth-provider-response.dto.js.map +0 -1
  46. package/dist/auth/dto/refresh-token.dto.d.ts +0 -3
  47. package/dist/auth/dto/refresh-token.dto.js +0 -28
  48. package/dist/auth/dto/refresh-token.dto.js.map +0 -1
  49. package/dist/auth/dto/signup.dto.d.ts +0 -13
  50. package/dist/auth/dto/signup.dto.js +0 -70
  51. package/dist/auth/dto/signup.dto.js.map +0 -1
  52. package/dist/auth/dto/verify.dto.d.ts +0 -7
  53. package/dist/auth/dto/verify.dto.js +0 -48
  54. package/dist/auth/dto/verify.dto.js.map +0 -1
  55. package/dist/auth/entities/auth-identify.entity.d.ts +0 -33
  56. package/dist/auth/entities/auth-identify.entity.js +0 -73
  57. package/dist/auth/entities/auth-identify.entity.js.map +0 -1
  58. package/dist/auth/entities/auth.entity.d.ts +0 -45
  59. package/dist/auth/entities/auth.entity.js +0 -129
  60. package/dist/auth/entities/auth.entity.js.map +0 -1
  61. package/dist/auth/entities/base.entity.d.ts +0 -6
  62. package/dist/auth/entities/base.entity.js +0 -41
  63. package/dist/auth/entities/base.entity.js.map +0 -1
  64. package/dist/auth/entities/entities.d.ts +0 -7
  65. package/dist/auth/entities/entities.js +0 -18
  66. package/dist/auth/entities/entities.js.map +0 -1
  67. package/dist/auth/entities/mfa-method.entity.d.ts +0 -23
  68. package/dist/auth/entities/mfa-method.entity.js +0 -69
  69. package/dist/auth/entities/mfa-method.entity.js.map +0 -1
  70. package/dist/auth/entities/oauth-provider.entity.d.ts +0 -38
  71. package/dist/auth/entities/oauth-provider.entity.js +0 -88
  72. package/dist/auth/entities/oauth-provider.entity.js.map +0 -1
  73. package/dist/auth/entities/otp-token.entity.d.ts +0 -22
  74. package/dist/auth/entities/otp-token.entity.js +0 -61
  75. package/dist/auth/entities/otp-token.entity.js.map +0 -1
  76. package/dist/auth/entities/session.entity.d.ts +0 -21
  77. package/dist/auth/entities/session.entity.js +0 -71
  78. package/dist/auth/entities/session.entity.js.map +0 -1
  79. package/dist/auth/entities/session_log.entity.d.ts +0 -31
  80. package/dist/auth/entities/session_log.entity.js +0 -85
  81. package/dist/auth/entities/session_log.entity.js.map +0 -1
  82. package/dist/auth/interfaces/auth-user-service.interface.d.ts +0 -13
  83. package/dist/auth/interfaces/auth-user-service.interface.js +0 -7
  84. package/dist/auth/interfaces/auth-user-service.interface.js.map +0 -1
  85. package/dist/auth/interfaces/current-user.decorator.d.ts +0 -2
  86. package/dist/auth/interfaces/current-user.decorator.js +0 -16
  87. package/dist/auth/interfaces/current-user.decorator.js.map +0 -1
  88. package/dist/auth/jwt-payload-interface.d.ts +0 -4
  89. package/dist/auth/jwt-payload-interface.js +0 -3
  90. package/dist/auth/jwt-payload-interface.js.map +0 -1
  91. package/dist/auth/jwt.strategy.d.ts +0 -13
  92. package/dist/auth/jwt.strategy.js +0 -60
  93. package/dist/auth/jwt.strategy.js.map +0 -1
  94. package/dist/auth/strategies/company.strategy.d.ts +0 -0
  95. package/dist/auth/strategies/company.strategy.js +0 -1
  96. package/dist/auth/strategies/company.strategy.js.map +0 -1
  97. package/dist/auth/strategies/google.strategy.d.ts +0 -7
  98. package/dist/auth/strategies/google.strategy.js +0 -23
  99. package/dist/auth/strategies/google.strategy.js.map +0 -1
  100. package/dist/auth/strategies/oauth/oauth-strategy.interface.d.ts +0 -14
  101. package/dist/auth/strategies/oauth/oauth-strategy.interface.js +0 -3
  102. package/dist/auth/strategies/oauth/oauth-strategy.interface.js.map +0 -1
  103. package/dist/auth/strategies/otp.strategy.d.ts +0 -7
  104. package/dist/auth/strategies/otp.strategy.js +0 -23
  105. package/dist/auth/strategies/otp.strategy.js.map +0 -1
  106. package/dist/auth/strategies/password.strategy.d.ts +0 -14
  107. package/dist/auth/strategies/password.strategy.js +0 -130
  108. package/dist/auth/strategies/password.strategy.js.map +0 -1
  109. package/dist/migrations/auth-entities.d.ts +0 -7
  110. package/dist/migrations/auth-entities.js +0 -18
  111. package/dist/migrations/auth-entities.js.map +0 -1
  112. package/dist/migrations/auth-schema.initializer.d.ts +0 -9
  113. package/dist/migrations/auth-schema.initializer.js +0 -36
  114. package/dist/migrations/auth-schema.initializer.js.map +0 -1
  115. package/dist/migrations/auth.migration.v1.d.ts +0 -12
  116. package/dist/migrations/auth.migration.v1.js +0 -157
  117. package/dist/migrations/auth.migration.v1.js.map +0 -1
  118. package/dist/migrations/auth.migration.v2.d.ts +0 -8
  119. package/dist/migrations/auth.migration.v2.js +0 -39
  120. package/dist/migrations/auth.migration.v2.js.map +0 -1
  121. package/dist/migrations/auth.migrations.d.ts +0 -2
  122. package/dist/migrations/auth.migrations.js +0 -8
  123. package/dist/migrations/auth.migrations.js.map +0 -1
  124. package/dist/migrations/migration.runner.d.ts +0 -9
  125. package/dist/migrations/migration.runner.js +0 -67
  126. package/dist/migrations/migration.runner.js.map +0 -1
  127. package/dist/migrations/migration.service.d.ts +0 -9
  128. package/dist/migrations/migration.service.js +0 -75
  129. package/dist/migrations/migration.service.js.map +0 -1
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OtpAuthStrategy = void 0;
10
- const common_1 = require("@nestjs/common");
11
- let OtpAuthStrategy = class OtpAuthStrategy {
12
- async registerCredentials(dto, uid) {
13
- throw new Error('Not implemented');
14
- }
15
- async login(dto) {
16
- throw new Error('Not implemented');
17
- }
18
- };
19
- exports.OtpAuthStrategy = OtpAuthStrategy;
20
- exports.OtpAuthStrategy = OtpAuthStrategy = __decorate([
21
- (0, common_1.Injectable)()
22
- ], OtpAuthStrategy);
23
- //# sourceMappingURL=otp.strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"otp.strategy.js","sourceRoot":"","sources":["../../../src/auth/strategies/otp.strategy.ts"],"names":[],"mappings":";;;;;;;;;AAEA,2CAA4C;AAMrC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,KAAK,CAAC,mBAAmB,CAAC,GAAc,EAAE,GAAY;QAEpD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAa;QAEvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AAVY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAU3B"}
@@ -1,14 +0,0 @@
1
- import { DataSource, Repository } from 'typeorm';
2
- import { LoginDto } from '../dto/login.dto';
3
- import { SignupDto } from '../dto/signup.dto';
4
- import { Auth } from '../entities/auth.entity';
5
- import { AuthIdentifier } from '../entities/auth-identify.entity';
6
- export declare class LocalAuthStrategy {
7
- private readonly dataSource;
8
- private authRepo;
9
- private identifierRepo;
10
- constructor(dataSource: DataSource, authRepo: Repository<Auth>, identifierRepo: Repository<AuthIdentifier>);
11
- private readonly logger;
12
- registerCredentials(dto: SignupDto, uid?: string): Promise<Auth>;
13
- login(dto: LoginDto): Promise<Auth>;
14
- }
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var LocalAuthStrategy_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.LocalAuthStrategy = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const typeorm_1 = require("typeorm");
19
- const typeorm_2 = require("@nestjs/typeorm");
20
- const bcrypt = require("bcrypt");
21
- const auth_entity_1 = require("../entities/auth.entity");
22
- const auth_identify_entity_1 = require("../entities/auth-identify.entity");
23
- const auth_type_enum_1 = require("../auth-type.enum");
24
- let LocalAuthStrategy = LocalAuthStrategy_1 = class LocalAuthStrategy {
25
- constructor(dataSource, authRepo, identifierRepo) {
26
- this.dataSource = dataSource;
27
- this.authRepo = authRepo;
28
- this.identifierRepo = identifierRepo;
29
- this.logger = new common_1.Logger(LocalAuthStrategy_1.name);
30
- }
31
- async registerCredentials(dto, uid) {
32
- if (!dto.email && !dto.phone && !dto.username) {
33
- throw new common_1.BadRequestException('Email, phone or username is required');
34
- }
35
- if (!dto.password) {
36
- throw new common_1.BadRequestException('Password is required');
37
- }
38
- const identifiersToCheck = [];
39
- if (dto.email)
40
- identifiersToCheck.push(dto.email.toLowerCase());
41
- if (dto.phone)
42
- identifiersToCheck.push(dto.phone);
43
- if (dto.username)
44
- identifiersToCheck.push(dto.username.toLowerCase());
45
- return this.dataSource.transaction(async (manager) => {
46
- const authIdentifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
47
- const authRepo = manager.getRepository(auth_entity_1.Auth);
48
- const existing = await authIdentifierRepo.findOne({
49
- where: { value: (0, typeorm_1.In)(identifiersToCheck) },
50
- });
51
- if (existing) {
52
- throw new common_1.BadRequestException('Unable to signup with those credentials. Try changing email, phone or username');
53
- }
54
- const hash = await bcrypt.hash(dto.password, 10);
55
- const identityUid = uid || crypto.randomUUID();
56
- const newAuth = authRepo.create({
57
- uid: identityUid,
58
- strategy: dto.method || auth_type_enum_1.AuthStrategy.LOCAL,
59
- secretHash: hash,
60
- isActive: true,
61
- isPrimary: true,
62
- });
63
- const newIdentifiers = [];
64
- if (dto.email) {
65
- newIdentifiers.push(authIdentifierRepo.create({
66
- type: auth_identify_entity_1.IdentifierType.EMAIL,
67
- value: dto.email.toLowerCase(),
68
- }));
69
- }
70
- if (dto.phone) {
71
- newIdentifiers.push(authIdentifierRepo.create({
72
- type: auth_identify_entity_1.IdentifierType.PHONE,
73
- value: dto.phone,
74
- }));
75
- }
76
- if (dto.username) {
77
- newIdentifiers.push(authIdentifierRepo.create({
78
- type: auth_identify_entity_1.IdentifierType.USERNAME,
79
- value: dto.username.toLowerCase(),
80
- }));
81
- }
82
- newAuth.identifiers = newIdentifiers;
83
- return await authRepo.save(newAuth);
84
- });
85
- }
86
- async login(dto) {
87
- if (!dto.password) {
88
- throw new common_1.BadRequestException('Password is required');
89
- }
90
- const identifierValue = dto.emailOrPhone || dto.email || dto.phone || dto.username;
91
- if (!identifierValue) {
92
- throw new common_1.BadRequestException('Email, phone or username is required');
93
- }
94
- const identifier = await this.identifierRepo.findOne({
95
- where: { value: identifierValue.toLowerCase() },
96
- relations: ['auth'],
97
- });
98
- if (!identifier || !identifier.auth) {
99
- throw new common_1.UnauthorizedException('Invalid credentials');
100
- }
101
- const auth = identifier.auth;
102
- if (auth.strategy !== auth_type_enum_1.AuthStrategy.LOCAL) {
103
- throw new common_1.UnauthorizedException('Please login with your Social Account');
104
- }
105
- const authWithSecret = await this.authRepo.findOne({
106
- where: { id: auth.id },
107
- select: ['id', 'secretHash'],
108
- });
109
- if (!authWithSecret || !authWithSecret.secretHash) {
110
- throw new common_1.UnauthorizedException('Invalid credentials');
111
- }
112
- const valid = await bcrypt.compare(dto.password, authWithSecret.secretHash);
113
- if (!valid) {
114
- throw new common_1.UnauthorizedException('Invalid credentials');
115
- }
116
- auth.lastUsedAt = new Date();
117
- await this.authRepo.save(auth);
118
- return auth;
119
- }
120
- };
121
- exports.LocalAuthStrategy = LocalAuthStrategy;
122
- exports.LocalAuthStrategy = LocalAuthStrategy = LocalAuthStrategy_1 = __decorate([
123
- (0, common_1.Injectable)(),
124
- __param(1, (0, typeorm_2.InjectRepository)(auth_entity_1.Auth)),
125
- __param(2, (0, typeorm_2.InjectRepository)(auth_identify_entity_1.AuthIdentifier)),
126
- __metadata("design:paramtypes", [typeorm_1.DataSource,
127
- typeorm_1.Repository,
128
- typeorm_1.Repository])
129
- ], LocalAuthStrategy);
130
- //# sourceMappingURL=password.strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"password.strategy.js","sourceRoot":"","sources":["../../../src/auth/strategies/password.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAKwB;AACxB,qCAAqD;AACrD,6CAAmD;AACnD,iCAAiC;AAKjC,yDAA+C;AAC/C,2EAG0C;AAG1C,sDAAiD;AAM1C,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,YACmB,UAAsB,EACf,QAAkC,EAE1D,cAAkD;QAHjC,eAAU,GAAV,UAAU,C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AAC;YAElD,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;QAGD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QAC5E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;QAID,IAAI,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AArJY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,0BAAgB,EAAC,kBAAI,CAAC,CAAA;IACtB,WAAA,IAAA,0BAAgB,EAAC,qCAAc,CAAC,CAAA;qCAFJ,oBAAU;QACG,oBAAU;QAE5B,oBAAU;GALzB,oBAAoB,CAqJhC"}
@@ -1,7 +0,0 @@
1
- import { Auth } from '../auth/entities/auth.entity';
2
- import { AuthIdentifier } from '../auth/entities/auth-identify.entity';
3
- import { OAuthProvider } from '../auth/entities/oauth-provider.entity';
4
- import { MfaMethod } from '../auth/entities/mfa-method.entity';
5
- import { OtpToken } from '../auth/entities/otp-token.entity';
6
- import { Session } from '../auth/entities/session.entity';
7
- export declare const AuthEntities: (typeof Auth | typeof OAuthProvider | typeof AuthIdentifier | typeof OtpToken | typeof MfaMethod | typeof Session)[];
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthEntities = void 0;
4
- const auth_entity_1 = require("../auth/entities/auth.entity");
5
- const auth_identify_entity_1 = require("../auth/entities/auth-identify.entity");
6
- const oauth_provider_entity_1 = require("../auth/entities/oauth-provider.entity");
7
- const mfa_method_entity_1 = require("../auth/entities/mfa-method.entity");
8
- const otp_token_entity_1 = require("../auth/entities/otp-token.entity");
9
- const session_entity_1 = require("../auth/entities/session.entity");
10
- exports.AuthEntities = [
11
- auth_entity_1.Auth,
12
- auth_identify_entity_1.AuthIdentifier,
13
- oauth_provider_entity_1.OAuthProvider,
14
- mfa_method_entity_1.MfaMethod,
15
- otp_token_entity_1.OtpToken,
16
- session_entity_1.Session,
17
- ];
18
- //# sourceMappingURL=auth-entities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-entities.js","sourceRoot":"","sources":["../../src/migrations/auth-entities.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;AACpD,gFAAuE;AACvE,kFAAuE;AACvE,0EAA+D;AAC/D,wEAA6D;AAC7D,oEAA0D;AAE7C,QAAA,YAAY,GAAG;IAC1B,kBAAI;IACJ,qCAAc;IACd,qCAAa;IACb,6BAAS;IACT,2BAAQ;IACR,wBAAO;CACR,CAAC"}
@@ -1,9 +0,0 @@
1
- import { OnModuleInit } from "@nestjs/common";
2
- import { AuthMigrationService } from "./migration.service";
3
- import { AuthModuleOptions } from "../auth/interfaces/auth-module-options.interface";
4
- export declare class AuthSchemaInitializer implements OnModuleInit {
5
- private migrationService;
6
- private options;
7
- constructor(migrationService: AuthMigrationService, options: AuthModuleOptions);
8
- onModuleInit(): Promise<void>;
9
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AuthSchemaInitializer = void 0;
16
- const common_1 = require("@nestjs/common");
17
- const migration_service_1 = require("./migration.service");
18
- const auth_module_1 = require("../auth/auth.module");
19
- let AuthSchemaInitializer = class AuthSchemaInitializer {
20
- constructor(migrationService, options) {
21
- this.migrationService = migrationService;
22
- this.options = options;
23
- }
24
- async onModuleInit() {
25
- if (this.options.autoMigrate) {
26
- await this.migrationService.runMigrations();
27
- }
28
- }
29
- };
30
- exports.AuthSchemaInitializer = AuthSchemaInitializer;
31
- exports.AuthSchemaInitializer = AuthSchemaInitializer = __decorate([
32
- (0, common_1.Injectable)(),
33
- __param(1, (0, common_1.Inject)(auth_module_1.AUTH_MODULE_OPTIONS)),
34
- __metadata("design:paramtypes", [migration_service_1.AuthMigrationService, Object])
35
- ], AuthSchemaInitializer);
36
- //# sourceMappingURL=auth-schema.initializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-schema.initializer.js","sourceRoot":"","sources":["../../src/migrations/auth-schema.initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2DAA2D;AAC3D,qDAA0D;AAInD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAC9B,YACY,gBAAsC,EACT,OAA0B;QADvD,qBAAgB,GAAhB,gBAAgB,CAAsB;QACT,YAAO,GAAP,OAAO,CAAmB;IAC/D,CAAC;IAEL,KAAK,CAAC,YAAY;QACd,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,CAAC;QAChD,CAAC;IACL,CAAC;CACJ,CAAA;AAXY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;qCADF,wCAAoB;GAFzC,qBAAqB,CAWjC"}
@@ -1,12 +0,0 @@
1
- import { QueryRunner } from 'typeorm';
2
- export interface AuthMigration {
3
- version: number;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }
7
- export declare class AuthMigrationV1 implements AuthMigration {
8
- down(queryRunner: QueryRunner): Promise<void>;
9
- static version: number;
10
- get version(): number;
11
- up(queryRunner: QueryRunner): Promise<void>;
12
- }
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthMigrationV1 = void 0;
4
- class AuthMigrationV1 {
5
- down(queryRunner) {
6
- throw new Error('Method not implemented.');
7
- }
8
- get version() { return AuthMigrationV1.version; }
9
- async up(queryRunner) {
10
- await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
11
- // Create Enum Types
12
- await queryRunner.query(`
13
- DO $$
14
- BEGIN
15
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'auth_strategy_enum') THEN
16
- CREATE TYPE "auth_strategy_enum" AS ENUM('EMAIL', 'PHONE', 'USERNAME', 'GOOGLE', 'FACEBOOK', 'APPLE', 'LOCAL', 'OAUTH');
17
- END IF;
18
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'auth_identifier_type_enum') THEN
19
- CREATE TYPE "auth_identifier_type_enum" AS ENUM('EMAIL', 'PHONE', 'USERNAME');
20
- END IF;
21
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'oauth_provider_type_enum') THEN
22
- CREATE TYPE "oauth_provider_type_enum" AS ENUM('GOOGLE', 'FACEBOOK', 'APPLE');
23
- END IF;
24
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'mfa_method_type_enum') THEN
25
- CREATE TYPE "mfa_method_type_enum" AS ENUM('TOTP', 'SMS', 'EMAIL');
26
- END IF;
27
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'otp_token_purpose_enum') THEN
28
- CREATE TYPE "otp_token_purpose_enum" AS ENUM('VERIFY_EMAIL', 'VERIFY_PHONE', 'PASSWORD_RESET', 'LOGIN_2FA');
29
- END IF;
30
- END $$;
31
- `);
32
- // 1. auth table
33
- await queryRunner.query(`
34
- CREATE TABLE IF NOT EXISTS "auth" (
35
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
36
- "uid" character varying,
37
- "strategy" "auth_strategy_enum" NOT NULL,
38
- "secretHash" character varying,
39
- "isPrimary" boolean NOT NULL DEFAULT false,
40
- "isVerified" boolean NOT NULL DEFAULT false,
41
- "isActive" boolean NOT NULL DEFAULT true,
42
- "meta" jsonb,
43
- "lastUsedAt" TIMESTAMP,
44
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
45
- "updatedAt" TIMESTAMP NOT NULL DEFAULT now(),
46
- "deletedAt" TIMESTAMP,
47
- CONSTRAINT "PK_auth" PRIMARY KEY ("id")
48
- )
49
- `);
50
- // 2. auth_identifiers table
51
- await queryRunner.query(`
52
- CREATE TABLE IF NOT EXISTS "auth_identifiers" (
53
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
54
- "authId" uuid,
55
- "type" "auth_identifier_type_enum" NOT NULL,
56
- "value" character varying NOT NULL,
57
- "source" "auth_strategy_enum" NOT NULL DEFAULT 'LOCAL',
58
- "isVerified" boolean NOT NULL DEFAULT false,
59
- "verifiedBy" character varying,
60
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
61
- "updatedAt" TIMESTAMP NOT NULL DEFAULT now(),
62
- "deletedAt" TIMESTAMP,
63
- CONSTRAINT "PK_auth_identifiers" PRIMARY KEY ("id")
64
- )
65
- `);
66
- // 3. oauth_providers table
67
- await queryRunner.query(`
68
- CREATE TABLE IF NOT EXISTS "oauth_providers" (
69
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
70
- "authId" uuid,
71
- "provider" "oauth_provider_type_enum" NOT NULL,
72
- "providerUserId" character varying NOT NULL,
73
- "accessToken" character varying,
74
- "refreshToken" character varying,
75
- "expiresAt" TIMESTAMP,
76
- "displayName" character varying,
77
- "avatarUrl" character varying,
78
- "emailVerified" boolean,
79
- "rawProfile" jsonb,
80
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
81
- "updatedAt" TIMESTAMP NOT NULL DEFAULT now(),
82
- "deletedAt" TIMESTAMP,
83
- CONSTRAINT "PK_oauth_providers" PRIMARY KEY ("id")
84
- )
85
- `);
86
- // 4. auth_mfa_methods table
87
- await queryRunner.query(`
88
- CREATE TABLE IF NOT EXISTS "auth_mfa_methods" (
89
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
90
- "uid" character varying NOT NULL,
91
- "type" "mfa_method_type_enum" NOT NULL,
92
- "secret" character varying NOT NULL,
93
- "isEnabled" boolean NOT NULL DEFAULT false,
94
- "isDefault" boolean NOT NULL DEFAULT false,
95
- "lastUsedAt" TIMESTAMP,
96
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
97
- CONSTRAINT "PK_auth_mfa_methods" PRIMARY KEY ("id")
98
- )
99
- `);
100
- // 5. otp_tokens table
101
- await queryRunner.query(`
102
- CREATE TABLE IF NOT EXISTS "otp_tokens" (
103
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
104
- "identifier" character varying NOT NULL,
105
- "purpose" "otp_token_purpose_enum" NOT NULL,
106
- "codeHash" character varying NOT NULL,
107
- "expiresAt" TIMESTAMP NOT NULL,
108
- "isUsed" boolean NOT NULL DEFAULT false,
109
- "requestUserId" character varying,
110
- "requestAuthId" character varying,
111
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
112
- "updatedAt" TIMESTAMP NOT NULL DEFAULT now(),
113
- "deletedAt" TIMESTAMP,
114
- CONSTRAINT "PK_otp_tokens" PRIMARY KEY ("id")
115
- )
116
- `);
117
- // 6. sessions table
118
- await queryRunner.query(`
119
- CREATE TABLE IF NOT EXISTS "sessions" (
120
- "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
121
- "uid" character varying NOT NULL,
122
- "refreshTokenHash" character varying NOT NULL,
123
- "userAgent" character varying,
124
- "deviceFingerprint" character varying,
125
- "ipAddress" character varying,
126
- "expiresAt" TIMESTAMP NOT NULL,
127
- "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
128
- CONSTRAINT "PK_sessions" PRIMARY KEY ("id")
129
- )
130
- `);
131
- // Indexes
132
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_uid" ON "auth" ("uid")`);
133
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_strategy" ON "auth" ("strategy")`);
134
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_isActive" ON "auth" ("isActive")`);
135
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_identifiers_authId" ON "auth_identifiers" ("authId")`);
136
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_identifiers_value" ON "auth_identifiers" ("value")`);
137
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_oauth_providers_authId" ON "oauth_providers" ("authId")`);
138
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_auth_mfa_methods_uid" ON "auth_mfa_methods" ("uid")`);
139
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_otp_tokens_identifier" ON "otp_tokens" ("identifier")`);
140
- await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_sessions_uid" ON "sessions" ("uid")`);
141
- // Foreign Keys
142
- await queryRunner.query(`
143
- DO $$
144
- BEGIN
145
- IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_auth_identifiers_authId') THEN
146
- ALTER TABLE "auth_identifiers" ADD CONSTRAINT "FK_auth_identifiers_authId" FOREIGN KEY ("authId") REFERENCES "auth"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
147
- END IF;
148
- IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_oauth_providers_authId') THEN
149
- ALTER TABLE "oauth_providers" ADD CONSTRAINT "FK_oauth_providers_authId" FOREIGN KEY ("authId") REFERENCES "auth"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
150
- END IF;
151
- END $$;
152
- `);
153
- }
154
- }
155
- exports.AuthMigrationV1 = AuthMigrationV1;
156
- AuthMigrationV1.version = 1;
157
- //# sourceMappingURL=auth.migration.v1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.migration.v1.js","sourceRoot":"","sources":["../../src/migrations/auth.migration.v1.ts"],"names":[],"mappings":";;;AAQA,MAAa,eAAe;IAC1B,IAAI,CAAC,WAAwB;QAC3B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAEjD,KAAK,CAAC,EAAE,CAAC,WAAwB;QAC/B,MAAM,WAAW,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAEtE,oBAAoB;QACpB,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;KAmBvB,CAAC,CAAC;QAEH,gBAAgB;QAChB,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;KAgBvB,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;KAcvB,CAAC,CAAC;QAEH,2BAA2B;QAC3B,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;KAkBvB,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;KAYvB,CAAC,CAAC;QAEH,sBAAsB;QACtB,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;KAevB,CAAC,CAAC;QAEH,oBAAoB;QACpB,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;KAYvB,CAAC,CAAC;QAEH,UAAU;QACV,MAAM,WAAW,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACvF,MAAM,WAAW,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAC;QACjG,MAAM,WAAW,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAC;QACjG,MAAM,WAAW,CAAC,KAAK,CAAC,2FAA2F,CAAC,CAAC;QACrH,MAAM,WAAW,CAAC,KAAK,CAAC,yFAAyF,CAAC,CAAC;QACnH,MAAM,WAAW,CAAC,KAAK,CAAC,yFAAyF,CAAC,CAAC;QACnH,MAAM,WAAW,CAAC,KAAK,CAAC,qFAAqF,CAAC,CAAC;QAC/G,MAAM,WAAW,CAAC,KAAK,CAAC,uFAAuF,CAAC,CAAC;QACjH,MAAM,WAAW,CAAC,KAAK,CAAC,qEAAqE,CAAC,CAAC;QAE/F,eAAe;QACf,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;KAUvB,CAAC,CAAC;IACL,CAAC;;AAhKH,0CAiKC;AA7JQ,uBAAO,GAAG,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { QueryRunner } from 'typeorm';
2
- import { AuthMigration } from './auth.migration.v1';
3
- export declare class AuthMigrationV2 implements AuthMigration {
4
- static version: number;
5
- get version(): number;
6
- up(queryRunner: QueryRunner): Promise<void>;
7
- down(queryRunner: QueryRunner): Promise<void>;
8
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthMigrationV2 = void 0;
4
- class AuthMigrationV2 {
5
- get version() { return AuthMigrationV2.version; }
6
- async up(queryRunner) {
7
- const tables = ['oauth_provider', 'auth_identifier', 'mfa_method', 'otp_token', 'session'];
8
- for (const table of tables) {
9
- // Check if authId column exists
10
- const hasColumn = await queryRunner.query(`
11
- SELECT column_name
12
- FROM information_schema.columns
13
- WHERE table_name = '${table}' AND column_name = 'authId'
14
- `);
15
- if (hasColumn.length === 0) {
16
- // Add column
17
- await queryRunner.query(`ALTER TABLE "${table}" ADD COLUMN "authId" uuid`);
18
- // Add Foreign Key constraint (ignoring if it already might exist for some reason)
19
- try {
20
- await queryRunner.query(`
21
- ALTER TABLE "${table}"
22
- ADD CONSTRAINT "FK_${table}_authId"
23
- FOREIGN KEY ("authId") REFERENCES "auth"("id")
24
- ON DELETE CASCADE ON UPDATE NO ACTION
25
- `);
26
- }
27
- catch (e) {
28
- // Constraint might already exist
29
- }
30
- }
31
- }
32
- }
33
- async down(queryRunner) {
34
- // Optionally remove columns, but typically we don't want to lose data in a down migration if it's not strictly necessary.
35
- }
36
- }
37
- exports.AuthMigrationV2 = AuthMigrationV2;
38
- AuthMigrationV2.version = 2;
39
- //# sourceMappingURL=auth.migration.v2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.migration.v2.js","sourceRoot":"","sources":["../../src/migrations/auth.migration.v2.ts"],"names":[],"mappings":";;;AAGA,MAAa,eAAe;IAE1B,IAAI,OAAO,KAAK,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAEjD,KAAK,CAAC,EAAE,CAAC,WAAwB;QAC/B,MAAM,MAAM,GAAG,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAE3F,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,gCAAgC;YAChC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC;;;8BAGlB,KAAK;OAC5B,CAAC,CAAC;YAEH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,aAAa;gBACb,MAAM,WAAW,CAAC,KAAK,CAAC,gBAAgB,KAAK,4BAA4B,CAAC,CAAC;gBAE3E,kFAAkF;gBAClF,IAAI,CAAC;oBACH,MAAM,WAAW,CAAC,KAAK,CAAC;2BACP,KAAK;iCACC,KAAK;;;WAG3B,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,iCAAiC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,WAAwB;QACjC,0HAA0H;IAC5H,CAAC;;AApCH,0CAqCC;AApCQ,uBAAO,GAAG,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import { AuthMigrationV1 } from "./auth.migration.v1";
2
- export declare const AuthMigrations: (typeof AuthMigrationV1)[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthMigrations = void 0;
4
- const auth_migration_v1_1 = require("./auth.migration.v1");
5
- exports.AuthMigrations = [
6
- auth_migration_v1_1.AuthMigrationV1,
7
- ];
8
- //# sourceMappingURL=auth.migrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.migrations.js","sourceRoot":"","sources":["../../src/migrations/auth.migrations.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEzC,QAAA,cAAc,GAAG;IAC1B,mCAAe;CAClB,CAAC"}
@@ -1,9 +0,0 @@
1
- import { DataSource, QueryRunner } from "typeorm";
2
- export declare class AuthMigrationService {
3
- private dataSource;
4
- constructor(dataSource: DataSource);
5
- runMigrations(): Promise<void>;
6
- ensureMetaTable(qr: QueryRunner): Promise<void>;
7
- getCurrentVersion(qr: QueryRunner): Promise<number>;
8
- updateVersion(qr: QueryRunner, version: number): Promise<void>;
9
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AuthMigrationService = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const typeorm_1 = require("typeorm");
15
- const auth_migrations_1 = require("./auth.migrations");
16
- let AuthMigrationService = class AuthMigrationService {
17
- constructor(dataSource) {
18
- this.dataSource = dataSource;
19
- }
20
- async runMigrations() {
21
- const queryRunner = this.dataSource.createQueryRunner();
22
- await queryRunner.connect();
23
- await this.ensureMetaTable(queryRunner);
24
- const currentVersion = await this.getCurrentVersion(queryRunner);
25
- const pendingMigrations = auth_migrations_1.AuthMigrations.filter((m) => m.prototype.version > currentVersion);
26
- for (const MigrationClass of pendingMigrations) {
27
- const migration = new MigrationClass();
28
- await queryRunner.startTransaction();
29
- try {
30
- await migration.up(queryRunner);
31
- await this.updateVersion(queryRunner, migration.version);
32
- await queryRunner.commitTransaction();
33
- }
34
- catch (err) {
35
- await queryRunner.rollbackTransaction();
36
- throw err;
37
- }
38
- }
39
- await queryRunner.release();
40
- }
41
- async ensureMetaTable(qr) {
42
- await qr.query(`
43
- CREATE TABLE IF NOT EXISTS auth_schema_meta (
44
- id SERIAL PRIMARY KEY,
45
- version INT NOT NULL,
46
- updated_at TIMESTAMP DEFAULT now()
47
- )
48
- `);
49
- }
50
- async getCurrentVersion(qr) {
51
- const result = await qr.query(`
52
- SELECT version FROM auth_schema_meta ORDER BY version DESC LIMIT 1
53
- `);
54
- return result.length > 0 ? result[0].version : 0;
55
- }
56
- async updateVersion(qr, version) {
57
- await qr.query(`
58
- INSERT INTO auth_schema_meta (version) VALUES ($1)
59
- `, [version]);
60
- }
61
- };
62
- exports.AuthMigrationService = AuthMigrationService;
63
- exports.AuthMigrationService = AuthMigrationService = __decorate([
64
- (0, common_1.Injectable)(),
65
- __metadata("design:paramtypes", [typeorm_1.DataSource])
66
- ], AuthMigrationService);
67
- //# sourceMappingURL=migration.runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration.runner.js","sourceRoot":"","sources":["../../src/migrations/migration.runner.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAkD;AAClD,uDAAmD;AAG5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAI,CAAC;IAE/C,KAAK,CAAC,aAAa;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;QAExD,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAE5B,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAExC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAEjE,MAAM,iBAAiB,GAAG,gCAAc,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,GAAG,cAAc,CAC9C,CAAC;QAEF,KAAK,MAAM,cAAc,IAAI,iBAAiB,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;YAEvC,MAAM,WAAW,CAAC,gBAAgB,EAAE,CAAC;YAErC,IAAI,CAAC;gBACD,MAAM,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;gBAEhC,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;gBAEzD,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;YAC1C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;gBACxC,MAAM,GAAG,CAAC;YACd,CAAC;QACL,CAAC;QAED,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAe;QACjC,MAAM,EAAE,CAAC,KAAK,CAAC;;;;;;SAMd,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EAAe;QACnC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC;;SAE7B,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,OAAe;QAChD,MAAM,EAAE,CAAC,KAAK,CAAC;;SAEd,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAClB,CAAC;CACJ,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAEuB,oBAAU;GADjC,oBAAoB,CA2DhC"}
@@ -1,9 +0,0 @@
1
- import { DataSource, QueryRunner } from "typeorm";
2
- export declare class AuthMigrationService {
3
- private dataSource;
4
- constructor(dataSource: DataSource);
5
- runMigrations(): Promise<void>;
6
- ensureMetaTable(qr?: QueryRunner): Promise<void>;
7
- getCurrentVersion(qr?: QueryRunner): Promise<number>;
8
- updateVersion(qr?: QueryRunner, version?: number): Promise<void>;
9
- }