@likewatt/models 1.95.0 → 1.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ import { Document } from 'mongoose';
2
+ export type ApiKeyDocument = ApiKey & Document;
3
+ export declare class ApiKey {
4
+ readonly _id: string;
5
+ userId: string;
6
+ name: string;
7
+ keyHash: string;
8
+ keyPrefix: string;
9
+ lastUsedAt?: Date | null;
10
+ revokedAt?: Date | null;
11
+ createdAt?: Date;
12
+ updatedAt?: Date;
13
+ }
14
+ export declare const ApiKeySchema: import("mongoose").Schema<ApiKey, import("mongoose").Model<ApiKey, any, any, any, Document<unknown, any, ApiKey, any, {}> & ApiKey & Required<{
15
+ _id: string;
16
+ }> & {
17
+ __v: number;
18
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ApiKey, Document<unknown, {}, import("mongoose").FlatRecord<ApiKey>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ApiKey> & Required<{
19
+ _id: string;
20
+ }> & {
21
+ __v: number;
22
+ }>;
@@ -0,0 +1,87 @@
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.ApiKeySchema = exports.ApiKey = void 0;
13
+ const mongoose_1 = require("@nestjs/mongoose");
14
+ const swagger_1 = require("@nestjs/swagger");
15
+ const class_validator_1 = require("class-validator");
16
+ const uuid_1 = require("uuid");
17
+ let ApiKey = class ApiKey {
18
+ };
19
+ exports.ApiKey = ApiKey;
20
+ __decorate([
21
+ (0, swagger_1.ApiProperty)({ type: String, readOnly: true }),
22
+ (0, mongoose_1.Prop)({ type: String }),
23
+ __metadata("design:type", String)
24
+ ], ApiKey.prototype, "_id", void 0);
25
+ __decorate([
26
+ (0, swagger_1.ApiProperty)({ description: 'Compte principal propriétaire de la clé' }),
27
+ (0, mongoose_1.Prop)({ type: String, required: true, index: true }),
28
+ (0, class_validator_1.IsString)(),
29
+ __metadata("design:type", String)
30
+ ], ApiKey.prototype, "userId", void 0);
31
+ __decorate([
32
+ (0, swagger_1.ApiProperty)({ example: 'Prod CRM' }),
33
+ (0, mongoose_1.Prop)({ type: String, required: true }),
34
+ (0, class_validator_1.IsString)(),
35
+ __metadata("design:type", String)
36
+ ], ApiKey.prototype, "name", void 0);
37
+ __decorate([
38
+ (0, swagger_1.ApiProperty)({
39
+ description: 'SHA-256 hex de la clé complète',
40
+ writeOnly: true,
41
+ }),
42
+ (0, mongoose_1.Prop)({ type: String, required: true, unique: true, index: true }),
43
+ (0, class_validator_1.IsString)(),
44
+ __metadata("design:type", String)
45
+ ], ApiKey.prototype, "keyHash", void 0);
46
+ __decorate([
47
+ (0, swagger_1.ApiProperty)({ description: '12 premiers caractères, pour identification UI' }),
48
+ (0, mongoose_1.Prop)({ type: String, required: true }),
49
+ (0, class_validator_1.IsString)(),
50
+ __metadata("design:type", String)
51
+ ], ApiKey.prototype, "keyPrefix", void 0);
52
+ __decorate([
53
+ (0, swagger_1.ApiPropertyOptional)({ type: Date }),
54
+ (0, mongoose_1.Prop)({ type: Date, default: null }),
55
+ (0, class_validator_1.IsOptional)(),
56
+ __metadata("design:type", Object)
57
+ ], ApiKey.prototype, "lastUsedAt", void 0);
58
+ __decorate([
59
+ (0, swagger_1.ApiPropertyOptional)({ type: Date }),
60
+ (0, mongoose_1.Prop)({ type: Date, default: null }),
61
+ (0, class_validator_1.IsOptional)(),
62
+ __metadata("design:type", Object)
63
+ ], ApiKey.prototype, "revokedAt", void 0);
64
+ __decorate([
65
+ (0, swagger_1.ApiPropertyOptional)({ type: Date, readOnly: true }),
66
+ __metadata("design:type", Date)
67
+ ], ApiKey.prototype, "createdAt", void 0);
68
+ __decorate([
69
+ (0, swagger_1.ApiPropertyOptional)({ type: Date, readOnly: true }),
70
+ __metadata("design:type", Date)
71
+ ], ApiKey.prototype, "updatedAt", void 0);
72
+ exports.ApiKey = ApiKey = __decorate([
73
+ (0, mongoose_1.Schema)({
74
+ collection: 'apiKeys',
75
+ id: false,
76
+ timestamps: true,
77
+ toJSON: { virtuals: true, versionKey: false },
78
+ toObject: { virtuals: true, versionKey: false },
79
+ })
80
+ ], ApiKey);
81
+ exports.ApiKeySchema = mongoose_1.SchemaFactory.createForClass(ApiKey);
82
+ exports.ApiKeySchema.pre('save', function (next) {
83
+ if (!this._id) {
84
+ this._id = (0, uuid_1.v4)();
85
+ }
86
+ next();
87
+ });
@@ -60,6 +60,26 @@ export declare const WebhookParamsSchema: import("mongoose").Schema<WebhookParam
60
60
  } & {
61
61
  __v: number;
62
62
  }>;
63
+ /**
64
+ * 2FA TOTP. Les champs sensibles ne quittent jamais le microservice par
65
+ * défaut : le prop `mfa` du User est déclaré `select: false`.
66
+ */
67
+ export declare class Mfa {
68
+ enabled: boolean;
69
+ secret?: string;
70
+ pendingSecret?: string;
71
+ backupCodes?: string[];
72
+ enabledAt?: Date;
73
+ }
74
+ export declare const MfaSchema: import("mongoose").Schema<Mfa, import("mongoose").Model<Mfa, any, any, any, Document<unknown, any, Mfa, any, {}> & Mfa & {
75
+ _id: import("mongoose").Types.ObjectId;
76
+ } & {
77
+ __v: number;
78
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Mfa, Document<unknown, {}, import("mongoose").FlatRecord<Mfa>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Mfa> & {
79
+ _id: import("mongoose").Types.ObjectId;
80
+ } & {
81
+ __v: number;
82
+ }>;
63
83
  /**
64
84
  * Représente un utilisateur dans le système.
65
85
  * - @Schema/timestamps : gère createdAt et updatedAt automatiques
@@ -72,6 +92,7 @@ export declare class User {
72
92
  leadTenantId?: string | null;
73
93
  email: string;
74
94
  password: string;
95
+ mfa?: Mfa;
75
96
  firstname: string;
76
97
  folders: Folder[];
77
98
  managerLicenses?: ManagerLicenses;
package/dist/core/User.js CHANGED
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserSchema = exports.User = exports.WebhookParamsSchema = exports.WebhookParams = exports.tokenDataSchema = exports.tokenData = exports.RightsSchema = exports.Rights = exports.SiteTagSchema = exports.SiteTag = void 0;
12
+ exports.UserSchema = exports.User = exports.MfaSchema = exports.Mfa = exports.WebhookParamsSchema = exports.WebhookParams = exports.tokenDataSchema = exports.tokenData = exports.RightsSchema = exports.Rights = exports.SiteTagSchema = exports.SiteTag = void 0;
13
13
  const swagger_1 = require("@nestjs/swagger");
14
14
  const mongoose_1 = require("@nestjs/mongoose");
15
15
  const uuid_1 = require("uuid");
@@ -143,6 +143,63 @@ exports.WebhookParams = WebhookParams = __decorate([
143
143
  (0, mongoose_1.Schema)({ _id: false })
144
144
  ], WebhookParams);
145
145
  exports.WebhookParamsSchema = mongoose_1.SchemaFactory.createForClass(WebhookParams);
146
+ /**
147
+ * 2FA TOTP. Les champs sensibles ne quittent jamais le microservice par
148
+ * défaut : le prop `mfa` du User est déclaré `select: false`.
149
+ */
150
+ let Mfa = class Mfa {
151
+ };
152
+ exports.Mfa = Mfa;
153
+ __decorate([
154
+ (0, swagger_1.ApiProperty)({ description: '2FA active', example: false }),
155
+ (0, mongoose_1.Prop)({ type: Boolean, required: true, default: false }),
156
+ (0, class_validator_1.IsBoolean)(),
157
+ __metadata("design:type", Boolean)
158
+ ], Mfa.prototype, "enabled", void 0);
159
+ __decorate([
160
+ (0, swagger_1.ApiProperty)({
161
+ description: 'Secret TOTP chiffré AES-256-GCM (format iv:tag:cipher hex)',
162
+ writeOnly: true,
163
+ required: false,
164
+ }),
165
+ (0, mongoose_1.Prop)({ type: String, required: false }),
166
+ (0, class_validator_1.IsOptional)(),
167
+ (0, class_validator_1.IsString)(),
168
+ __metadata("design:type", String)
169
+ ], Mfa.prototype, "secret", void 0);
170
+ __decorate([
171
+ (0, swagger_1.ApiProperty)({
172
+ description: 'Secret en attente de validation (setup non confirmé)',
173
+ writeOnly: true,
174
+ required: false,
175
+ }),
176
+ (0, mongoose_1.Prop)({ type: String, required: false }),
177
+ (0, class_validator_1.IsOptional)(),
178
+ (0, class_validator_1.IsString)(),
179
+ __metadata("design:type", String)
180
+ ], Mfa.prototype, "pendingSecret", void 0);
181
+ __decorate([
182
+ (0, swagger_1.ApiProperty)({
183
+ description: 'Backup codes hashés (sha256 hex)',
184
+ writeOnly: true,
185
+ required: false,
186
+ }),
187
+ (0, mongoose_1.Prop)({ type: [String], required: false, default: [] }),
188
+ (0, class_validator_1.IsOptional)(),
189
+ (0, class_validator_1.IsArray)(),
190
+ __metadata("design:type", Array)
191
+ ], Mfa.prototype, "backupCodes", void 0);
192
+ __decorate([
193
+ (0, swagger_1.ApiProperty)({ description: "Date d'activation", required: false }),
194
+ (0, mongoose_1.Prop)({ type: Date, required: false }),
195
+ (0, class_validator_1.IsOptional)(),
196
+ (0, class_validator_1.IsDate)(),
197
+ __metadata("design:type", Date)
198
+ ], Mfa.prototype, "enabledAt", void 0);
199
+ exports.Mfa = Mfa = __decorate([
200
+ (0, mongoose_1.Schema)({ _id: false })
201
+ ], Mfa);
202
+ exports.MfaSchema = mongoose_1.SchemaFactory.createForClass(Mfa);
146
203
  /**
147
204
  * Représente un utilisateur dans le système.
148
205
  * - @Schema/timestamps : gère createdAt et updatedAt automatiques
@@ -189,10 +246,17 @@ __decorate([
189
246
  writeOnly: true,
190
247
  minLength: 8,
191
248
  }),
192
- (0, mongoose_1.Prop)({ type: String, required: true }),
249
+ (0, mongoose_1.Prop)({ type: String, required: true, select: false }),
193
250
  (0, class_validator_1.IsString)(),
194
251
  __metadata("design:type", String)
195
252
  ], User.prototype, "password", void 0);
253
+ __decorate([
254
+ (0, swagger_1.ApiProperty)({ type: Mfa, required: false }),
255
+ (0, mongoose_1.Prop)({ type: exports.MfaSchema, _id: false, required: false, select: false }),
256
+ (0, class_validator_1.IsOptional)(),
257
+ (0, class_validator_1.IsObject)(),
258
+ __metadata("design:type", Mfa)
259
+ ], User.prototype, "mfa", void 0);
196
260
  __decorate([
197
261
  (0, swagger_1.ApiProperty)({
198
262
  description: 'Prénom de l’utilisateur',
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './core/ApiKey';
1
2
  export * from './core/CollectiveSite';
2
3
  export * from './core/Scenario';
3
4
  export * from './core/Site';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ExtractionSource = exports.ExtractionType = exports.ExtractionSens = exports.EnedisReportOperationType = exports.EnedisReportAcquisitionMethod = void 0;
18
18
  // Main entities
19
+ __exportStar(require("./core/ApiKey"), exports);
19
20
  __exportStar(require("./core/CollectiveSite"), exports);
20
21
  __exportStar(require("./core/Scenario"), exports);
21
22
  __exportStar(require("./core/Site"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likewatt/models",
3
- "version": "1.95.0",
3
+ "version": "1.97.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {