@communecter/cocolight-api-client 1.0.114 → 1.0.116

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@communecter/cocolight-api-client",
3
- "version": "1.0.114",
3
+ "version": "1.0.116",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3585,6 +3585,73 @@ export class BaseEntity<TServerData = any> {
3585
3585
  return this._submitLinkRequestAdmin();
3586
3586
  }
3587
3587
 
3588
+ /**
3589
+ * Envoie une demande de promotion en tant qu'administrateur pour l'utilisateur connecté.
3590
+ *
3591
+ * L'utilisateur doit déjà être membre de l'entité (organisation, projet, événement).
3592
+ * Cette méthode envoie une demande pour obtenir les droits d'administration.
3593
+ *
3594
+ * @returns - Résultat de l'API.
3595
+ * @throws {ApiError} 401 - Si l'utilisateur n'est pas connecté.
3596
+ * @throws {ApiError} 404 - Si l'entité n'est pas enregistrée.
3597
+ * @throws {ApiError} 400 - Si l'utilisateur n'est pas membre de l'entité.
3598
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà en cours d'invitation admin.
3599
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà administrateur.
3600
+ * @throws {ApiError} 400 - Si le type d'entité ne supporte pas cette opération.
3601
+ */
3602
+ async requestPromoteToAdmin(): Promise<unknown> {
3603
+ if (!this.isMe) {
3604
+ throw new ApiError("Vous devez être connecté pour envoyer une demande de participation.", 401);
3605
+ }
3606
+
3607
+ this._checkLinkableEntity();
3608
+
3609
+ if (!this.id) {
3610
+ throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
3611
+ }
3612
+
3613
+ if (!this.userId) {
3614
+ throw new ApiError("L'utilisateur connecté n'est pas défini.", 400);
3615
+ }
3616
+
3617
+ const userLink = this._getLinkFromConnectedUser();
3618
+
3619
+ if (!userLink) {
3620
+ throw new ApiError("vous n'êtes pas membre de cette entité.", 400);
3621
+ }
3622
+
3623
+ if (userLink?.isAdmin && (userLink?.isInviting || userLink?.isAdminInviting)) {
3624
+ throw new ApiError("Cet utilisateur est déjà en cours d'invitation en tant qu'admin.", 400);
3625
+ }
3626
+
3627
+ if (userLink?.isAdmin && !userLink?.isInviting && !userLink?.isAdminInviting) {
3628
+ throw new ApiError("Cet utilisateur est déjà admin.", 400);
3629
+ }
3630
+
3631
+ const t = this.getEntityType();
3632
+
3633
+ const expectedTypes = ["organizations", "projects"];
3634
+
3635
+ if (!expectedTypes.includes(t)) {
3636
+ throw new ApiError(`L'entité doit être de type : ${expectedTypes.join(", ")}, reçu : ${t}`, 400);
3637
+ }
3638
+
3639
+ // 2) Narrow de type pour TypeScript
3640
+ const parentType = t as ConnectData["parentType"];
3641
+
3642
+ const data: ConnectData = {
3643
+ childId: this.userId,
3644
+ childType: "citoyens",
3645
+ parentType,
3646
+ parentId: this.id,
3647
+ connectType: "admin"
3648
+ };
3649
+
3650
+ const retour = await this.callIsMe(() => this.endpointApi.connect(data));
3651
+ await this.userContext?.refresh();
3652
+ return retour;
3653
+ }
3654
+
3588
3655
  /**
3589
3656
  * Accepte une invitation à rejoindre l'entité courante.
3590
3657
  * Ne fonctionne que si un lien avec `isInviting` est détecté.
package/src/api/User.ts CHANGED
@@ -1222,15 +1222,25 @@ export class User extends BaseEntity<UserItemNormalized> {
1222
1222
  } catch{
1223
1223
  return false;
1224
1224
  }
1225
- if(this.getEntityType() === "citoyens"){
1226
- const userLink = this._getLinkFromConnectedUser();
1227
- if (!userLink) return false;
1228
- return userLink?.isInviting === true;
1229
- } else {
1230
- const parentLink = this._getParentLinkForUser();
1231
- if (!parentLink) return false;
1232
- return parentLink?.isInviting === true;
1225
+ const parentLink = this._getParentLinkForUser();
1226
+ if (!parentLink) return false;
1227
+ return parentLink?.isInviting === true;
1228
+ }
1229
+
1230
+ /**
1231
+ * Vérifie si l'utilisateur connecté a envoyé une invitation d'ami à cet utilisateur.
1232
+ *
1233
+ * @returns - `true` si une invitation d'ami est en attente, `false` sinon.
1234
+ */
1235
+ isInvitingFriend(): boolean {
1236
+ try {
1237
+ this._validateBasePreconditions("isInviting", ["citoyens", "organizations", "projects", "events"]);
1238
+ } catch{
1239
+ return false;
1233
1240
  }
1241
+ const userLink = this._getLinkFromConnectedUser();
1242
+ if (!userLink) return false;
1243
+ return userLink?.isInviting === true;
1234
1244
  }
1235
1245
 
1236
1246
  /**
@@ -1315,15 +1325,25 @@ export class User extends BaseEntity<UserItemNormalized> {
1315
1325
  } catch{
1316
1326
  return false;
1317
1327
  }
1318
- if(this.getEntityType() === "citoyens"){
1319
- const userLink = this._getLinkFromConnectedUser();
1320
- if (!userLink) return false;
1321
- return userLink?.toBeValidated === true;
1322
- } else {
1323
- const parentLink = this._getParentLinkForUser();
1324
- if (!parentLink) return false;
1325
- return parentLink?.toBeValidated === true;
1328
+ const parentLink = this._getParentLinkForUser();
1329
+ if (!parentLink) return false;
1330
+ return parentLink?.toBeValidated === true;
1331
+ }
1332
+
1333
+ /**
1334
+ * Vérifie si cet utilisateur a envoyé une demande d'ami en attente de validation.
1335
+ *
1336
+ * @returns - `true` si une demande d'ami est en attente de validation, `false` sinon.
1337
+ */
1338
+ isToBeValidatedFriend(): boolean {
1339
+ try {
1340
+ this._validateBasePreconditions("isToBeValidated", ["citoyens", "organizations", "projects", "events"]);
1341
+ } catch{
1342
+ return false;
1326
1343
  }
1344
+ const userLink = this._getLinkFromConnectedUser();
1345
+ if (!userLink) return false;
1346
+ return userLink?.toBeValidated === true;
1327
1347
  }
1328
1348
 
1329
1349
  /**
@@ -1205,6 +1205,21 @@ export declare class BaseEntity<TServerData = any> {
1205
1205
  * @throws {ApiError} - Si l'entité ne supporte pas l'action ou si une demande est déjà en cours.
1206
1206
  */
1207
1207
  requestToJoinAdmin(): Promise<unknown>;
1208
+ /**
1209
+ * Envoie une demande de promotion en tant qu'administrateur pour l'utilisateur connecté.
1210
+ *
1211
+ * L'utilisateur doit déjà être membre de l'entité (organisation, projet, événement).
1212
+ * Cette méthode envoie une demande pour obtenir les droits d'administration.
1213
+ *
1214
+ * @returns - Résultat de l'API.
1215
+ * @throws {ApiError} 401 - Si l'utilisateur n'est pas connecté.
1216
+ * @throws {ApiError} 404 - Si l'entité n'est pas enregistrée.
1217
+ * @throws {ApiError} 400 - Si l'utilisateur n'est pas membre de l'entité.
1218
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà en cours d'invitation admin.
1219
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà administrateur.
1220
+ * @throws {ApiError} 400 - Si le type d'entité ne supporte pas cette opération.
1221
+ */
1222
+ requestPromoteToAdmin(): Promise<unknown>;
1208
1223
  /**
1209
1224
  * Accepte une invitation à rejoindre l'entité courante.
1210
1225
  * Ne fonctionne que si un lien avec `isInviting` est détecté.
@@ -528,6 +528,12 @@ export declare class User extends BaseEntity<UserItemNormalized> {
528
528
  * ```
529
529
  */
530
530
  isInviting(): boolean;
531
+ /**
532
+ * Vérifie si l'utilisateur connecté a envoyé une invitation d'ami à cet utilisateur.
533
+ *
534
+ * @returns - `true` si une invitation d'ami est en attente, `false` sinon.
535
+ */
536
+ isInvitingFriend(): boolean;
531
537
  /**
532
538
  * Vérifie si l'utilisateur a une invitation en attente avec des droits d'admin.
533
539
  *
@@ -586,6 +592,12 @@ export declare class User extends BaseEntity<UserItemNormalized> {
586
592
  * ```
587
593
  */
588
594
  isToBeValidated(): boolean;
595
+ /**
596
+ * Vérifie si cet utilisateur a envoyé une demande d'ami en attente de validation.
597
+ *
598
+ * @returns - `true` si une demande d'ami est en attente de validation, `false` sinon.
599
+ */
600
+ isToBeValidatedFriend(): boolean;
589
601
  /**
590
602
  * Envoie une demande pour rejoindre l'entité parente.
591
603
  *