@likewatt/models 1.124.3 → 1.126.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.
package/README.md CHANGED
@@ -1,122 +1,122 @@
1
- # @likewatt/models
2
-
3
- Package privé contenant les modèles TypeScript partagés pour les applications Likewatt.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @likewatt/models
9
- ```
10
-
11
- ## Description
12
-
13
- Ce package exporte les modèles de données TypeScript utilisés dans l'écosystème Likewatt, incluant :
14
-
15
- - **Entités principales** : `Site`, `Scenario`, `User`, `License`, `CollectiveSite`, `Invitation`, `ScenarioDefaultValue`
16
- - **Entités TypeORM** : `Analysis`, `Optimization`, `WebhookOutput`, historiques (Co2, Enedis, FCR, Okwind, Pvgis, Spot, Tempo)
17
- - **Modèles internes** : Paramètres énergétiques (batteries, PV, éolien, hydrogène, stockage thermique, etc.)
18
- - **Types frontend** : Types TypeScript pour l'interface utilisateur
19
- - **Énumérations** : Types énumérés partagés
20
-
21
- ## Structure
22
-
23
- - `src/core/` : Entités principales et modèles internes
24
- - `src/frontend/` : Types TypeScript pour le frontend
25
- - `dist/` : Build compilé (CommonJS)
26
-
27
- ## Technologies
28
-
29
- - TypeScript 5.x
30
- - TypeORM 0.3.x
31
- - Mongoose 8.x
32
- - NestJS decorators (Swagger, Mongoose)
33
- - Class Validator
34
-
35
- ## Scripts disponibles
36
-
37
- ```bash
38
- npm run build # Compile le projet TypeScript
39
- npm run format # Formate le code avec Prettier
40
- npm run lint # Lint et fixe le code avec ESLint
41
- npm run lint:quick # Lint sans auto-fix
42
- npm run release # Crée une release automatique (conventional commits)
43
- npm run release:minor # Crée une release minor
44
- npm run release:major # Crée une release major
45
- ```
46
-
47
- ## Convention de commit
48
-
49
- Le projet utilise **Husky** et **Commitlint** pour enforcer les conventions de commit.
50
-
51
- ### Format requis
52
-
53
- ```
54
- <type>(<scope>): <subject>
55
-
56
- <body>
57
-
58
- <footer>
59
- ```
60
-
61
- ### Types autorisés
62
-
63
- - `feat`: Nouvelle fonctionnalité
64
- - `fix`: Correction de bug
65
- - `docs`: Documentation
66
- - `style`: Formatage, point-virgules manquants, etc.
67
- - `refactor`: Refactoring du code
68
- - `perf`: Amélioration des performances
69
- - `test`: Ajout de tests
70
- - `build`: Changements du système de build
71
- - `ci`: Changements CI/CD
72
- - `chore`: Tâches de maintenance
73
- - `revert`: Revert d'un commit précédent
74
-
75
- ### Exemples
76
-
77
- ```bash
78
- feat(user): add authentication endpoint
79
- fix(scenario): correct energy calculation
80
- docs(readme): update installation instructions
81
- refactor(battery): simplify params validation
82
- ci(pipeline): add automatic versioning
83
- ```
84
-
85
- ### Impact sur le versioning
86
-
87
- - `feat`: incrémente la version **minor** (1.0.0 → 1.1.0)
88
- - `fix`: incrémente la version **patch** (1.0.0 → 1.0.1)
89
- - `BREAKING CHANGE` dans le footer : incrémente la version **major** (1.0.0 → 2.0.0)
90
-
91
- ## Release et versioning
92
-
93
- Le package utilise `standard-version` pour le versioning sémantique basé sur les commits conventionnels.
94
-
95
- ### Release automatique
96
-
97
- Chaque push sur la branche `main` déclenche automatiquement :
98
- 1. Installation des dépendances
99
- 2. Build du projet
100
- 3. Analyse des commits pour déterminer le type de version (patch/minor/major)
101
- 4. Génération du CHANGELOG
102
- 5. Publication sur le registry NPM privé
103
-
104
- ### Release manuelle
105
-
106
- Via Bitbucket Pipelines, possibilité de forcer un type de release :
107
- - `patch` : Correctifs (1.0.0 → 1.0.1)
108
- - `minor` : Nouvelles fonctionnalités (1.0.0 → 1.1.0)
109
- - `major` : Breaking changes (1.0.0 → 2.0.0)
110
- - `prepatch`, `preminor`, `premajor`, `prerelease` : Versions de pré-release
111
-
112
- ## Configuration
113
-
114
- - **Compilation** : ES2019, CommonJS, avec decorators experimentaux
115
- - **Output** : `dist/index.js` (main), `dist/index.d.ts` (types)
116
- - **Registry** : NPM privé Likewatt
117
-
118
- ## Confidentialité
119
-
120
- Ce package est privé et ne doit pas être partagé en dehors de Likewatt.
121
-
122
-
1
+ # @likewatt/models
2
+
3
+ Package privé contenant les modèles TypeScript partagés pour les applications Likewatt.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @likewatt/models
9
+ ```
10
+
11
+ ## Description
12
+
13
+ Ce package exporte les modèles de données TypeScript utilisés dans l'écosystème Likewatt, incluant :
14
+
15
+ - **Entités principales** : `Site`, `Scenario`, `User`, `License`, `CollectiveSite`, `Invitation`, `ScenarioDefaultValue`
16
+ - **Entités TypeORM** : `Analysis`, `Optimization`, `WebhookOutput`, historiques (Co2, Enedis, FCR, Okwind, Pvgis, Spot, Tempo)
17
+ - **Modèles internes** : Paramètres énergétiques (batteries, PV, éolien, hydrogène, stockage thermique, etc.)
18
+ - **Types frontend** : Types TypeScript pour l'interface utilisateur
19
+ - **Énumérations** : Types énumérés partagés
20
+
21
+ ## Structure
22
+
23
+ - `src/core/` : Entités principales et modèles internes
24
+ - `src/frontend/` : Types TypeScript pour le frontend
25
+ - `dist/` : Build compilé (CommonJS)
26
+
27
+ ## Technologies
28
+
29
+ - TypeScript 5.x
30
+ - TypeORM 0.3.x
31
+ - Mongoose 8.x
32
+ - NestJS decorators (Swagger, Mongoose)
33
+ - Class Validator
34
+
35
+ ## Scripts disponibles
36
+
37
+ ```bash
38
+ npm run build # Compile le projet TypeScript
39
+ npm run format # Formate le code avec Prettier
40
+ npm run lint # Lint et fixe le code avec ESLint
41
+ npm run lint:quick # Lint sans auto-fix
42
+ npm run release # Crée une release automatique (conventional commits)
43
+ npm run release:minor # Crée une release minor
44
+ npm run release:major # Crée une release major
45
+ ```
46
+
47
+ ## Convention de commit
48
+
49
+ Le projet utilise **Husky** et **Commitlint** pour enforcer les conventions de commit.
50
+
51
+ ### Format requis
52
+
53
+ ```
54
+ <type>(<scope>): <subject>
55
+
56
+ <body>
57
+
58
+ <footer>
59
+ ```
60
+
61
+ ### Types autorisés
62
+
63
+ - `feat`: Nouvelle fonctionnalité
64
+ - `fix`: Correction de bug
65
+ - `docs`: Documentation
66
+ - `style`: Formatage, point-virgules manquants, etc.
67
+ - `refactor`: Refactoring du code
68
+ - `perf`: Amélioration des performances
69
+ - `test`: Ajout de tests
70
+ - `build`: Changements du système de build
71
+ - `ci`: Changements CI/CD
72
+ - `chore`: Tâches de maintenance
73
+ - `revert`: Revert d'un commit précédent
74
+
75
+ ### Exemples
76
+
77
+ ```bash
78
+ feat(user): add authentication endpoint
79
+ fix(scenario): correct energy calculation
80
+ docs(readme): update installation instructions
81
+ refactor(battery): simplify params validation
82
+ ci(pipeline): add automatic versioning
83
+ ```
84
+
85
+ ### Impact sur le versioning
86
+
87
+ - `feat`: incrémente la version **minor** (1.0.0 → 1.1.0)
88
+ - `fix`: incrémente la version **patch** (1.0.0 → 1.0.1)
89
+ - `BREAKING CHANGE` dans le footer : incrémente la version **major** (1.0.0 → 2.0.0)
90
+
91
+ ## Release et versioning
92
+
93
+ Le package utilise `standard-version` pour le versioning sémantique basé sur les commits conventionnels.
94
+
95
+ ### Release automatique
96
+
97
+ Chaque push sur la branche `main` déclenche automatiquement :
98
+ 1. Installation des dépendances
99
+ 2. Build du projet
100
+ 3. Analyse des commits pour déterminer le type de version (patch/minor/major)
101
+ 4. Génération du CHANGELOG
102
+ 5. Publication sur le registry NPM privé
103
+
104
+ ### Release manuelle
105
+
106
+ Via Bitbucket Pipelines, possibilité de forcer un type de release :
107
+ - `patch` : Correctifs (1.0.0 → 1.0.1)
108
+ - `minor` : Nouvelles fonctionnalités (1.0.0 → 1.1.0)
109
+ - `major` : Breaking changes (1.0.0 → 2.0.0)
110
+ - `prepatch`, `preminor`, `premajor`, `prerelease` : Versions de pré-release
111
+
112
+ ## Configuration
113
+
114
+ - **Compilation** : ES2019, CommonJS, avec decorators experimentaux
115
+ - **Output** : `dist/index.js` (main), `dist/index.d.ts` (types)
116
+ - **Registry** : NPM privé Likewatt
117
+
118
+ ## Confidentialité
119
+
120
+ Ce package est privé et ne doit pas être partagé en dehors de Likewatt.
121
+
122
+
@@ -1,4 +1,27 @@
1
1
  import { Document } from 'mongoose';
2
+ /**
3
+ * Signal anti-fraude posé sur un consentement (voir `ConsentAntiFraudService`,
4
+ * gateway). Un consentement peut en cumuler plusieurs. Seuls les contrôles
5
+ * NON bloquants produisent un flag (N1-b désactivé, N2 doublon) : les blocages
6
+ * durs (N0 jetable, N1-a adresse identique, N1-b activé) empêchent la création,
7
+ * donc n'écrivent rien.
8
+ */
9
+ export declare class ConsentFraudFlag {
10
+ level: 'N1' | 'N2';
11
+ code: string;
12
+ reason?: string;
13
+ detail?: Record<string, unknown>;
14
+ createdAt: Date;
15
+ }
16
+ export declare const ConsentFraudFlagSchema: import("mongoose").Schema<ConsentFraudFlag, import("mongoose").Model<ConsentFraudFlag, any, any, any, Document<unknown, any, ConsentFraudFlag, any, {}> & ConsentFraudFlag & {
17
+ _id: import("mongoose").Types.ObjectId;
18
+ } & {
19
+ __v: number;
20
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ConsentFraudFlag, Document<unknown, {}, import("mongoose").FlatRecord<ConsentFraudFlag>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ConsentFraudFlag> & {
21
+ _id: import("mongoose").Types.ObjectId;
22
+ } & {
23
+ __v: number;
24
+ }>;
2
25
  /**
3
26
  * Représente un utilisateur dans le système.
4
27
  * - @Schema/timestamps : gère createdAt et updatedAt automatiques
@@ -30,6 +53,11 @@ export declare class Consent {
30
53
  dateConsentCheck?: Date;
31
54
  pdlNotCovered?: boolean;
32
55
  flagReason?: string;
56
+ fraudFlags?: ConsentFraudFlag[];
57
+ fraudReviewStatus?: 'pending' | 'legit' | 'fraud';
58
+ fraudReviewNote?: string;
59
+ fraudReviewedBy?: string;
60
+ fraudReviewedAt?: Date;
33
61
  }
34
62
  export type ConsentDocument = Consent & Document;
35
63
  export declare const ConsentSchema: import("mongoose").Schema<Consent, import("mongoose").Model<Consent, any, any, any, Document<unknown, any, Consent, any, {}> & Consent & Required<{
@@ -9,11 +9,62 @@ 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.ConsentSchema = exports.Consent = void 0;
12
+ exports.ConsentSchema = exports.Consent = exports.ConsentFraudFlagSchema = exports.ConsentFraudFlag = void 0;
13
13
  const swagger_1 = require("@nestjs/swagger");
14
14
  const mongoose_1 = require("@nestjs/mongoose");
15
15
  const class_validator_1 = require("class-validator");
16
16
  const uuid_1 = require("uuid");
17
+ /**
18
+ * Signal anti-fraude posé sur un consentement (voir `ConsentAntiFraudService`,
19
+ * gateway). Un consentement peut en cumuler plusieurs. Seuls les contrôles
20
+ * NON bloquants produisent un flag (N1-b désactivé, N2 doublon) : les blocages
21
+ * durs (N0 jetable, N1-a adresse identique, N1-b activé) empêchent la création,
22
+ * donc n'écrivent rien.
23
+ */
24
+ let ConsentFraudFlag = class ConsentFraudFlag {
25
+ };
26
+ exports.ConsentFraudFlag = ConsentFraudFlag;
27
+ __decorate([
28
+ (0, swagger_1.ApiProperty)({ description: 'Niveau anti-fraude', enum: ['N1', 'N2'] }),
29
+ (0, mongoose_1.Prop)({ type: String, enum: ['N1', 'N2'], required: true }),
30
+ (0, class_validator_1.IsIn)(['N1', 'N2']),
31
+ __metadata("design:type", String)
32
+ ], ConsentFraudFlag.prototype, "level", void 0);
33
+ __decorate([
34
+ (0, swagger_1.ApiProperty)({
35
+ description: 'Code machine du signal (filtrable en admin)',
36
+ example: 'N2_DUPLICATE_PDL',
37
+ }),
38
+ (0, mongoose_1.Prop)({ type: String, required: true }),
39
+ (0, class_validator_1.IsString)(),
40
+ __metadata("design:type", String)
41
+ ], ConsentFraudFlag.prototype, "code", void 0);
42
+ __decorate([
43
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Motif lisible (suivi admin)' }),
44
+ (0, mongoose_1.Prop)({ type: String, required: false }),
45
+ (0, class_validator_1.IsOptional)(),
46
+ (0, class_validator_1.IsString)(),
47
+ __metadata("design:type", String)
48
+ ], ConsentFraudFlag.prototype, "reason", void 0);
49
+ __decorate([
50
+ (0, swagger_1.ApiPropertyOptional)({
51
+ description: 'Contexte structuré (ex. consentements en conflit pour N2)',
52
+ }),
53
+ (0, mongoose_1.Prop)({ type: Object, required: false }),
54
+ (0, class_validator_1.IsOptional)(),
55
+ (0, class_validator_1.IsObject)(),
56
+ __metadata("design:type", Object)
57
+ ], ConsentFraudFlag.prototype, "detail", void 0);
58
+ __decorate([
59
+ (0, swagger_1.ApiProperty)({ description: 'Date de pose du signal' }),
60
+ (0, mongoose_1.Prop)({ type: Date, required: true }),
61
+ (0, class_validator_1.IsDate)(),
62
+ __metadata("design:type", Date)
63
+ ], ConsentFraudFlag.prototype, "createdAt", void 0);
64
+ exports.ConsentFraudFlag = ConsentFraudFlag = __decorate([
65
+ (0, mongoose_1.Schema)({ _id: false })
66
+ ], ConsentFraudFlag);
67
+ exports.ConsentFraudFlagSchema = mongoose_1.SchemaFactory.createForClass(ConsentFraudFlag);
17
68
  /**
18
69
  * Représente un utilisateur dans le système.
19
70
  * - @Schema/timestamps : gère createdAt et updatedAt automatiques
@@ -238,6 +289,52 @@ __decorate([
238
289
  (0, class_validator_1.IsString)(),
239
290
  __metadata("design:type", String)
240
291
  ], Consent.prototype, "flagReason", void 0);
292
+ __decorate([
293
+ (0, swagger_1.ApiPropertyOptional)({
294
+ description: 'Signaux anti-fraude non bloquants (N1 désactivé, N2 doublon PDL)',
295
+ type: [ConsentFraudFlag],
296
+ }),
297
+ (0, mongoose_1.Prop)({ type: [exports.ConsentFraudFlagSchema], default: [] }),
298
+ (0, class_validator_1.IsOptional)(),
299
+ (0, class_validator_1.IsArray)(),
300
+ __metadata("design:type", Array)
301
+ ], Consent.prototype, "fraudFlags", void 0);
302
+ __decorate([
303
+ (0, swagger_1.ApiPropertyOptional)({
304
+ description: 'Statut de traitement admin des signaux anti-fraude',
305
+ enum: ['pending', 'legit', 'fraud'],
306
+ }),
307
+ (0, mongoose_1.Prop)({
308
+ type: String,
309
+ enum: ['pending', 'legit', 'fraud'],
310
+ required: false,
311
+ index: true,
312
+ }),
313
+ (0, class_validator_1.IsOptional)(),
314
+ (0, class_validator_1.IsIn)(['pending', 'legit', 'fraud']),
315
+ __metadata("design:type", String)
316
+ ], Consent.prototype, "fraudReviewStatus", void 0);
317
+ __decorate([
318
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Note de traitement admin' }),
319
+ (0, mongoose_1.Prop)({ type: String, required: false }),
320
+ (0, class_validator_1.IsOptional)(),
321
+ (0, class_validator_1.IsString)(),
322
+ __metadata("design:type", String)
323
+ ], Consent.prototype, "fraudReviewNote", void 0);
324
+ __decorate([
325
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Admin ayant statué (userId)' }),
326
+ (0, mongoose_1.Prop)({ type: String, required: false }),
327
+ (0, class_validator_1.IsOptional)(),
328
+ (0, class_validator_1.IsString)(),
329
+ __metadata("design:type", String)
330
+ ], Consent.prototype, "fraudReviewedBy", void 0);
331
+ __decorate([
332
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Date du traitement admin' }),
333
+ (0, mongoose_1.Prop)({ type: Date, required: false }),
334
+ (0, class_validator_1.IsOptional)(),
335
+ (0, class_validator_1.IsDate)(),
336
+ __metadata("design:type", Date)
337
+ ], Consent.prototype, "fraudReviewedAt", void 0);
241
338
  exports.Consent = Consent = __decorate([
242
339
  (0, mongoose_1.Schema)({
243
340
  id: false,
@@ -249,6 +346,8 @@ exports.Consent = Consent = __decorate([
249
346
  exports.ConsentSchema = mongoose_1.SchemaFactory.createForClass(Consent);
250
347
  // Index pour la requête de couverture anti-fraude (workspace + PDL couvert)
251
348
  exports.ConsentSchema.index({ workspaceId: 1, pdls: 1 });
349
+ // Index pour la console admin de suivi anti-fraude (statut + récence)
350
+ exports.ConsentSchema.index({ fraudReviewStatus: 1, createdAt: -1 });
252
351
  // Hook pre-save pour générer automatiquement un UUID si _id n'est pas fourni
253
352
  exports.ConsentSchema.pre('save', function (next) {
254
353
  if (!this._id) {
@@ -113,6 +113,7 @@ export declare class User {
113
113
  demo: boolean;
114
114
  emailVerified: boolean;
115
115
  principal: boolean;
116
+ isWorkspaceAdmin: boolean;
116
117
  publicApi: boolean;
117
118
  principalUser?: string;
118
119
  workspaceId?: string;
package/dist/core/User.js CHANGED
@@ -447,6 +447,16 @@ __decorate([
447
447
  (0, class_validator_1.IsBoolean)(),
448
448
  __metadata("design:type", Boolean)
449
449
  ], User.prototype, "principal", void 0);
450
+ __decorate([
451
+ (0, swagger_1.ApiProperty)({
452
+ description: 'Admin du workspace : gère les membres, leurs droits, les invitations et les clés API. Distinct de `principal` (titulaire de la licence) et de `isAdmin` (super-admin Likewatt).',
453
+ example: false,
454
+ }),
455
+ (0, mongoose_1.Prop)({ type: Boolean, default: false }),
456
+ (0, class_validator_1.IsOptional)(),
457
+ (0, class_validator_1.IsBoolean)(),
458
+ __metadata("design:type", Boolean)
459
+ ], User.prototype, "isWorkspaceAdmin", void 0);
450
460
  __decorate([
451
461
  (0, swagger_1.ApiProperty)({
452
462
  description: 'Accès à l’API Likewatt publique (gestion et usage des clés API)',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likewatt/models",
3
- "version": "1.124.3",
3
+ "version": "1.126.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {