2026-04-14-8 auth and commercial
This commit is contained in:
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import { OnModuleInit } from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
export declare class AuthModule implements OnModuleInit {
|
||||
private readonly authService;
|
||||
private readonly configService;
|
||||
constructor(authService: AuthService, configService: ConfigService);
|
||||
onModuleInit(): Promise<void>;
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
const tenant_entity_1 = require("./entities/tenant.entity");
|
||||
const api_key_entity_1 = require("./entities/api-key.entity");
|
||||
const redis_module_1 = require("../common/redis.module");
|
||||
const config_1 = require("@nestjs/config");
|
||||
let AuthModule = class AuthModule {
|
||||
authService;
|
||||
configService;
|
||||
constructor(authService, configService) {
|
||||
this.authService = authService;
|
||||
this.configService = configService;
|
||||
}
|
||||
async onModuleInit() {
|
||||
const defaultKey = this.configService.get('MAP_API_KEY');
|
||||
if (defaultKey) {
|
||||
await this.authService.seedDefaultKey('Default System', 'admin@intaleq.xyz', defaultKey);
|
||||
console.log('✅ Default System API Key seeded successfully');
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuthModule = AuthModule;
|
||||
exports.AuthModule = AuthModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([tenant_entity_1.Tenant, api_key_entity_1.ApiKey]),
|
||||
redis_module_1.RedisModule,
|
||||
],
|
||||
providers: [auth_service_1.AuthService],
|
||||
exports: [auth_service_1.AuthService],
|
||||
}),
|
||||
__metadata("design:paramtypes", [auth_service_1.AuthService,
|
||||
config_1.ConfigService])
|
||||
], AuthModule);
|
||||
//# sourceMappingURL=auth.module.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,6CAAgD;AAChD,iDAA6C;AAC7C,4DAAkD;AAClD,8DAAmD;AACnD,yDAAqD;AACrD,2CAA+C;AAWxC,IAAM,UAAU,GAAhB,MAAM,UAAU;IAEF;IACA;IAFnB,YACmB,WAAwB,EACxB,aAA4B;QAD5B,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAMJ,KAAK,CAAC,YAAY;QAChB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,aAAa,CAAC,CAAC;QACjE,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,UAAU,CAAC,CAAC;YACzF,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;CACF,CAAA;AAjBY,gCAAU;qBAAV,UAAU;IATtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,uBAAa,CAAC,UAAU,CAAC,CAAC,sBAAM,EAAE,uBAAM,CAAC,CAAC;YAC1C,0BAAW;SACZ;QACD,SAAS,EAAE,CAAC,0BAAW,CAAC;QACxB,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;qCAGgC,0BAAW;QACT,sBAAa;GAHpC,UAAU,CAiBtB"}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { Repository } from 'typeorm';
|
||||
import { ApiKey } from './entities/api-key.entity';
|
||||
import { Tenant } from './entities/tenant.entity';
|
||||
import { RedisService } from '../common/redis.service';
|
||||
export declare class AuthService {
|
||||
private readonly apiKeyRepository;
|
||||
private readonly tenantRepository;
|
||||
private readonly redisService;
|
||||
private readonly logger;
|
||||
constructor(apiKeyRepository: Repository<ApiKey>, tenantRepository: Repository<Tenant>, redisService: RedisService);
|
||||
validateApiKey(key: string, origin?: string, referer?: string): Promise<{
|
||||
tenant: Tenant;
|
||||
apiKey: ApiKey;
|
||||
rateLimit: number;
|
||||
}>;
|
||||
private validateRestrictions;
|
||||
private isDomainAllowed;
|
||||
hashSecret(secret: string): string;
|
||||
seedDefaultKey(name: string, email: string, keyString: string): Promise<void>;
|
||||
}
|
||||
Vendored
+115
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var AuthService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const crypto_1 = require("crypto");
|
||||
const api_key_entity_1 = require("./entities/api-key.entity");
|
||||
const tenant_entity_1 = require("./entities/tenant.entity");
|
||||
const redis_service_1 = require("../common/redis.service");
|
||||
let AuthService = AuthService_1 = class AuthService {
|
||||
apiKeyRepository;
|
||||
tenantRepository;
|
||||
redisService;
|
||||
logger = new common_1.Logger(AuthService_1.name);
|
||||
constructor(apiKeyRepository, tenantRepository, redisService) {
|
||||
this.apiKeyRepository = apiKeyRepository;
|
||||
this.tenantRepository = tenantRepository;
|
||||
this.redisService = redisService;
|
||||
}
|
||||
async validateApiKey(key, origin, referer) {
|
||||
const cacheKey = `auth:apikey:${key}`;
|
||||
const cachedData = await this.redisService.get(cacheKey);
|
||||
if (cachedData) {
|
||||
this.validateRestrictions(cachedData.apiKey, origin, referer);
|
||||
return cachedData;
|
||||
}
|
||||
const apiKey = await this.apiKeyRepository.findOne({
|
||||
where: { key, isActive: true },
|
||||
relations: ['tenant'],
|
||||
});
|
||||
if (!apiKey || !apiKey.tenant || !apiKey.tenant.isActive) {
|
||||
throw new common_1.UnauthorizedException('Invalid or inactive API Key');
|
||||
}
|
||||
this.validateRestrictions(apiKey, origin, referer);
|
||||
const result = {
|
||||
tenant: apiKey.tenant,
|
||||
apiKey: apiKey,
|
||||
rateLimit: apiKey.rateLimit || 100,
|
||||
};
|
||||
await this.redisService.set(cacheKey, result, 3600);
|
||||
this.apiKeyRepository.update(apiKey.id, { lastUsedAt: new Date() }).catch(err => this.logger.error(`Failed to update lastUsedAt for API key ${apiKey.id}: ${err.message}`));
|
||||
return result;
|
||||
}
|
||||
validateRestrictions(apiKey, origin, referer) {
|
||||
if (apiKey.allowedOrigins && apiKey.allowedOrigins.length > 0) {
|
||||
if (!origin || !this.isDomainAllowed(origin, apiKey.allowedOrigins)) {
|
||||
this.logger.warn(`Origin mismatch for API key ${apiKey.id}. Received: ${origin}`);
|
||||
throw new common_1.UnauthorizedException('Request Origin not allowed for this API Key');
|
||||
}
|
||||
}
|
||||
if (apiKey.allowedReferrers && apiKey.allowedReferrers.length > 0) {
|
||||
if (!referer || !this.isDomainAllowed(referer, apiKey.allowedReferrers)) {
|
||||
this.logger.warn(`Referer mismatch for API key ${apiKey.id}. Received: ${referer}`);
|
||||
throw new common_1.UnauthorizedException('Request Referer not allowed for this API Key');
|
||||
}
|
||||
}
|
||||
}
|
||||
isDomainAllowed(domain, allowedList) {
|
||||
const cleanDomain = domain.replace(/^https?:\/\//, '').split('/')[0];
|
||||
return allowedList.some(allowed => {
|
||||
if (allowed === '*')
|
||||
return true;
|
||||
const regex = new RegExp('^' + allowed.replace(/\*/g, '.*') + '$');
|
||||
return regex.test(cleanDomain);
|
||||
});
|
||||
}
|
||||
hashSecret(secret) {
|
||||
return (0, crypto_1.createHash)('sha256').update(secret).digest('hex');
|
||||
}
|
||||
async seedDefaultKey(name, email, keyString) {
|
||||
let tenant = await this.tenantRepository.findOne({ where: { email } });
|
||||
if (!tenant) {
|
||||
tenant = await this.tenantRepository.save({
|
||||
name,
|
||||
email,
|
||||
isActive: true
|
||||
});
|
||||
}
|
||||
const existingKey = await this.apiKeyRepository.findOne({ where: { key: keyString } });
|
||||
if (!existingKey) {
|
||||
await this.apiKeyRepository.save({
|
||||
key: keyString,
|
||||
secretHash: this.hashSecret(keyString),
|
||||
name: 'Default Production Key',
|
||||
isActive: true,
|
||||
tenantId: tenant.id,
|
||||
rateLimit: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuthService = AuthService;
|
||||
exports.AuthService = AuthService = AuthService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(api_key_entity_1.ApiKey)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(tenant_entity_1.Tenant)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
redis_service_1.RedisService])
|
||||
], AuthService);
|
||||
//# sourceMappingURL=auth.service.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,6CAAmD;AACnD,qCAAqC;AACrC,mCAAoC;AACpC,8DAAmD;AACnD,4DAAkD;AAClD,2DAAuD;AAGhD,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAKH;IAEA;IACA;IAPF,MAAM,GAAG,IAAI,eAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;IAEvD,YAEmB,gBAAoC,EAEpC,gBAAoC,EACpC,YAA0B;QAH1B,qBAAgB,GAAhB,gBAAgB,CAAoB;QAEpC,qBAAgB,GAAhB,gBAAgB,CAAoB;QACpC,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAMJ,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,MAAe,EAAE,OAAgB;QAEjE,MAAM,QAAQ,GAAG,eAAe,GAAG,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAwD,QAAQ,CAAC,CAAC;QAEhH,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAC9D,OAAO,UAAU,CAAC;QACpB,CAAC;QAGD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YACjD,KAAK,EAAE,EAAE,GAAG,E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CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACxC,IAAI;gBACJ,KAAK;gBACL,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACvF,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBAC/B,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;gBACtC,IAAI,EAAE,wBAAwB;gBAC9B,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAA;AArHY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,0BAAgB,EAAC,uBAAM,CAAC,CAAA;IAExB,WAAA,IAAA,0BAAgB,EAAC,sBAAM,CAAC,CAAA;qCADU,oBAAU;QAEV,oBAAU;QACd,4BAAY;GARlC,WAAW,CAqHvB"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { Tenant } from './tenant.entity';
|
||||
export declare class ApiKey {
|
||||
id: string;
|
||||
key: string;
|
||||
secretHash: string;
|
||||
name: string;
|
||||
isActive: boolean;
|
||||
rateLimit: number;
|
||||
allowedOrigins: string[];
|
||||
allowedReferrers: string[];
|
||||
tenant: Tenant;
|
||||
tenantId: string;
|
||||
lastUsedAt: Date;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApiKey = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const tenant_entity_1 = require("./tenant.entity");
|
||||
let ApiKey = class ApiKey {
|
||||
id;
|
||||
key;
|
||||
secretHash;
|
||||
name;
|
||||
isActive;
|
||||
rateLimit;
|
||||
allowedOrigins;
|
||||
allowedReferrers;
|
||||
tenant;
|
||||
tenantId;
|
||||
lastUsedAt;
|
||||
createdAt;
|
||||
updatedAt;
|
||||
};
|
||||
exports.ApiKey = ApiKey;
|
||||
__decorate([
|
||||
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
||||
__metadata("design:type", String)
|
||||
], ApiKey.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true }),
|
||||
(0, typeorm_1.Index)(),
|
||||
__metadata("design:type", String)
|
||||
], ApiKey.prototype, "key", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)(),
|
||||
__metadata("design:type", String)
|
||||
], ApiKey.prototype, "secretHash", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)(),
|
||||
__metadata("design:type", String)
|
||||
], ApiKey.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ApiKey.prototype, "isActive", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ApiKey.prototype, "rateLimit", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)('simple-array', { nullable: true }),
|
||||
__metadata("design:type", Array)
|
||||
], ApiKey.prototype, "allowedOrigins", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)('simple-array', { nullable: true }),
|
||||
__metadata("design:type", Array)
|
||||
], ApiKey.prototype, "allowedReferrers", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.ManyToOne)(() => tenant_entity_1.Tenant, (tenant) => tenant.apiKeys),
|
||||
__metadata("design:type", tenant_entity_1.Tenant)
|
||||
], ApiKey.prototype, "tenant", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)(),
|
||||
__metadata("design:type", String)
|
||||
], ApiKey.prototype, "tenantId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ nullable: true }),
|
||||
__metadata("design:type", Date)
|
||||
], ApiKey.prototype, "lastUsedAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.CreateDateColumn)(),
|
||||
__metadata("design:type", Date)
|
||||
], ApiKey.prototype, "createdAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.UpdateDateColumn)(),
|
||||
__metadata("design:type", Date)
|
||||
], ApiKey.prototype, "updatedAt", void 0);
|
||||
exports.ApiKey = ApiKey = __decorate([
|
||||
(0, typeorm_1.Entity)('api_keys')
|
||||
], ApiKey);
|
||||
//# sourceMappingURL=api-key.entity.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"api-key.entity.js","sourceRoot":"","sources":["../../../src/auth/entities/api-key.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuH;AACvH,mDAAyC;AAGlC,IAAM,M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CL,MAAM;IADlB,IAAA,gBAAM,EAAC,UAAU,CAAC;GACN,MAAM,CAwClB"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { ApiKey } from './api-key.entity';
|
||||
export declare enum TenantPlan {
|
||||
FREE = "FREE",
|
||||
PREMIUM = "PREMIUM",
|
||||
ENTERPRISE = "ENTERPRISE"
|
||||
}
|
||||
export declare class Tenant {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
plan: TenantPlan;
|
||||
isActive: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
apiKeys: ApiKey[];
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Tenant = exports.TenantPlan = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const api_key_entity_1 = require("./api-key.entity");
|
||||
var TenantPlan;
|
||||
(function (TenantPlan) {
|
||||
TenantPlan["FREE"] = "FREE";
|
||||
TenantPlan["PREMIUM"] = "PREMIUM";
|
||||
TenantPlan["ENTERPRISE"] = "ENTERPRISE";
|
||||
})(TenantPlan || (exports.TenantPlan = TenantPlan = {}));
|
||||
let Tenant = class Tenant {
|
||||
id;
|
||||
name;
|
||||
email;
|
||||
plan;
|
||||
isActive;
|
||||
createdAt;
|
||||
updatedAt;
|
||||
apiKeys;
|
||||
};
|
||||
exports.Tenant = Tenant;
|
||||
__decorate([
|
||||
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
||||
__metadata("design:type", String)
|
||||
], Tenant.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)(),
|
||||
__metadata("design:type", String)
|
||||
], Tenant.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true }),
|
||||
__metadata("design:type", String)
|
||||
], Tenant.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
type: 'enum',
|
||||
enum: TenantPlan,
|
||||
default: TenantPlan.FREE,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], Tenant.prototype, "plan", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], Tenant.prototype, "isActive", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.CreateDateColumn)(),
|
||||
__metadata("design:type", Date)
|
||||
], Tenant.prototype, "createdAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.UpdateDateColumn)(),
|
||||
__metadata("design:type", Date)
|
||||
], Tenant.prototype, "updatedAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.OneToMany)(() => api_key_entity_1.ApiKey, (apiKey) => apiKey.tenant),
|
||||
__metadata("design:type", Array)
|
||||
], Tenant.prototype, "apiKeys", void 0);
|
||||
exports.Tenant = Tenant = __decorate([
|
||||
(0, typeorm_1.Entity)('tenants')
|
||||
], Tenant);
|
||||
//# sourceMappingURL=tenant.entity.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"tenant.entity.js","sourceRoot":"","sources":["../../../src/auth/entities/tenant.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgH;AAChH,qDAA0C;AAE1C,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,iCAAmB,CAAA;IACnB,uCAAyB,CAAA;AAC3B,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAGM,IAAM,MAAM,GAAZ,MAAM,MAAM;IAEjB,EAAE,CAAS;IAGX,IAAI,CAAS;IAGb,KAAK,CAAS;IAOd,IAAI,CAAa;IAGjB,QAAQ,CAAU;IAGlB,SAAS,CAAO;IAGhB,SAAS,CAAO;IAGhB,OAAO,CAAW;CACnB,CAAA;AA5BY,wBAAM;AAEjB;IADC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;kCACpB;AAGX;IADC,IAAA,gBAAM,GAAE;;oCACI;AAGb;IADC,IAAA,gBAAM,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;qCACX;AAOd;IALC,IAAA,gBAAM,EAAC;QACN,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,UAAU,CAAC,IAAI;KACzB,CAAC;;oCACe;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;wCACR;AAGlB;IADC,IAAA,0BAAgB,GAAE;8BACR,IAAI;yCAAC;AAGhB;IADC,IAAA,0BAAgB,GAAE;8BACR,IAAI;yCAAC;AAGhB;IADC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,uBAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;;uCACjC;iBA3BP,MAAM;IADlB,IAAA,gBAAM,EAAC,SAAS,CAAC;GACL,MAAM,CA4BlB"}
|
||||
Reference in New Issue
Block a user