@communecter/cocolight-api-client 1.0.69 → 1.0.71

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.69",
3
+ "version": "1.0.71",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2626,7 +2626,7 @@ export interface AddOrganizationData {
2626
2626
  /**
2627
2627
  * Site web
2628
2628
  */
2629
- url?: string;
2629
+ url?: string | "";
2630
2630
  preferences?: {
2631
2631
  /**
2632
2632
  * Open data (true/false)
@@ -2744,7 +2744,7 @@ export interface AddProjectData {
2744
2744
  /**
2745
2745
  * Site web
2746
2746
  */
2747
- url?: string;
2747
+ url?: string | "";
2748
2748
  preferences?: {
2749
2749
  /**
2750
2750
  * Open data (true/false)
@@ -3040,7 +3040,7 @@ export interface AddEventData {
3040
3040
  /**
3041
3041
  * Site web
3042
3042
  */
3043
- url?: string;
3043
+ url?: string | "";
3044
3044
  /**
3045
3045
  * Email de l’organisation
3046
3046
  */
package/src/api/News.ts CHANGED
@@ -435,4 +435,61 @@ export class News extends BaseEntity<NewsItemNormalized> {
435
435
  return await this.callIsConnected(() => this.endpointApi.shareNews(payload));
436
436
  }
437
437
 
438
+ /**
439
+ * Vérifie si l'utilisateur connecté est l'auteur de cette actualité.
440
+ *
441
+ * Cette méthode compare l'ID de l'utilisateur connecté avec l'ID de l'auteur
442
+ * de l'actualité. L'auteur peut être soit un objet simple NewsAuthor, soit
443
+ * une instance d'entité User ou Organization.
444
+ *
445
+ * @returns `true` si l'utilisateur connecté est l'auteur, `false` sinon
446
+ * @throws {ApiError} Si l'utilisateur n'est pas connecté (401)
447
+ * @throws {ApiError} Si l'actualité n'a pas d'ID - non enregistrée (404)
448
+ * @throws {ApiError} Si les données serveur ne sont pas disponibles (404)
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const news = await me.news({ id: "123" });
453
+ * await news.get();
454
+ *
455
+ * if (news.isAuthor()) {
456
+ * console.log("Vous êtes l'auteur de cette actualité");
457
+ * await news.delete(); // Vous pouvez la supprimer
458
+ * }
459
+ * ```
460
+ */
461
+ override isAuthor(): boolean {
462
+ if (!this.isMe) {
463
+ throw new ApiError("Vous devez être connecté pour vérifier l'auteur.", 401);
464
+ }
465
+ if (!this.id) {
466
+ throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
467
+ }
468
+ if (!this.serverData) {
469
+ throw new ApiError("Aucune donnée serveur disponible.", 404);
470
+ }
471
+ if (!this.userId) {
472
+ throw new ApiError("Utilisateur non connecté.", 401);
473
+ }
474
+
475
+ const author = this.serverData.author;
476
+ if (!author) {
477
+ return false;
478
+ }
479
+
480
+ // Extraire l'ID selon le type d'author
481
+ // author peut être NewsAuthor (objet simple avec .id) ou User/Organization (entité avec .serverData.id)
482
+ let authorId: string | undefined;
483
+
484
+ if ("serverData" in author && author.serverData && typeof author.serverData === "object" && "id" in author.serverData) {
485
+ // C'est une instance d'entité (User ou Organization)
486
+ authorId = author.serverData.id as string;
487
+ } else if ("id" in author) {
488
+ // C'est un objet NewsAuthor simple
489
+ authorId = author.id as string;
490
+ }
491
+
492
+ return Boolean(authorId && this.userId === authorId);
493
+ }
494
+
438
495
  }