@communecter/cocolight-api-client 1.0.118 → 1.0.119

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.118",
3
+ "version": "1.0.119",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3959,12 +3959,15 @@ export class BaseEntity<TServerData = any> {
3959
3959
  * @throws {ApiError} - Si `silent` est `false` et que les préconditions ne sont pas remplies.
3960
3960
  */
3961
3961
  isFollower(options?: { silent?: boolean }): boolean {
3962
- const userLink = this._getValidatedUserLink(
3963
- "vérifier si il vous suit",
3964
- ["citoyens", "organizations", "projects", "events", "poi"],
3965
- { silent: options?.silent }
3966
- );
3967
- if (!userLink) return false;
3962
+ const silent = options?.silent ?? true;
3963
+ const expectedTypes = ["citoyens", "organizations", "projects", "events", "poi"];
3964
+ try {
3965
+ this._checkAccess("vérifier si il vous suit");
3966
+ this._assertEntityType(...expectedTypes);
3967
+ } catch (e) {
3968
+ if (silent) return false;
3969
+ throw e;
3970
+ }
3968
3971
  return this._isLinked("followers");
3969
3972
  }
3970
3973
 
@@ -3977,12 +3980,15 @@ export class BaseEntity<TServerData = any> {
3977
3980
  * @throws {ApiError} - Si `silent` est `false` et que les préconditions ne sont pas remplies.
3978
3981
  */
3979
3982
  isFollowing(options?: { silent?: boolean }): boolean {
3980
- const userLink = this._getValidatedUserLink(
3981
- "vérifier si vous le suivez",
3982
- ["citoyens", "organizations", "projects", "events", "poi"],
3983
- { silent: options?.silent }
3984
- );
3985
- if (!userLink) return false;
3983
+ const silent = options?.silent ?? true;
3984
+ const expectedTypes = ["citoyens", "organizations", "projects", "events", "poi"];
3985
+ try {
3986
+ this._checkAccess("vérifier si vous le suivez");
3987
+ this._assertEntityType(...expectedTypes);
3988
+ } catch (e) {
3989
+ if (silent) return false;
3990
+ throw e;
3991
+ }
3986
3992
  return this._isLinked("follows");
3987
3993
  }
3988
3994
 
package/src/api/User.ts CHANGED
@@ -858,31 +858,46 @@ export class User extends BaseEntity<UserItemNormalized> {
858
858
 
859
859
  /**
860
860
  * Vérifie si l'utilisateur connecté est ami avec cet utilisateur.
861
- *
861
+ * @param options - Options de vérification.
862
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
862
863
  * @returns - True si l'utilisateur connecté est ami, sinon false.
863
864
  * @throws {ApiError} - Si l'utilisateur n'est pas connecté.
864
865
  */
865
- isFriend(): boolean {
866
- if (!this.isActingUser) {
867
- throw new ApiError("Vous devez être connecté pour vérifier si vous êtes ami.", 401);
866
+ isFriend(options?: { silent?: boolean }): boolean {
867
+ const silent = options?.silent ?? true;
868
+ try {
869
+ if (!this.isActingUser) {
870
+ throw new ApiError("Vous devez être connecté pour vérifier si vous êtes ami.", 401);
871
+ }
872
+ } catch (e) {
873
+ if (silent) return false;
874
+ throw e;
868
875
  }
869
876
  this._assertEntityType("citoyens");
870
877
  const userLink = this._getLinkFromConnectedUser();
878
+ if(!userLink) return false;
871
879
  return this._validateUserLink(userLink);
872
880
  }
873
881
 
874
882
  /**
875
883
  * Vérifie si l'utilisateur suit l'entité.
876
- *
884
+ * @param options - Options de vérification.
885
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
877
886
  * @returns - `true` si l'utilisateur suit l'entité, `false` sinon.
878
887
  * @throws {ApiError}
879
888
  */
880
- override isFollower(): boolean {
881
- if (!this.isActingUser) {
882
- throw new ApiError("Vous devez être connecté pour vérifier si il vous suit.", 401);
883
- }
884
- if (!this.id) {
885
- throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
889
+ override isFollower(options?: { silent?: boolean }): boolean {
890
+ const silent = options?.silent ?? true;
891
+ try {
892
+ if (!this.isActingUser) {
893
+ throw new ApiError("Vous devez être connecté pour vérifier si il vous suit.", 401);
894
+ }
895
+ if (!this.id) {
896
+ throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
897
+ }
898
+ } catch (e) {
899
+ if (silent) return false;
900
+ throw e;
886
901
  }
887
902
  this._assertEntityType("citoyens");
888
903
  return this._isLinked("followers");
@@ -890,16 +905,23 @@ export class User extends BaseEntity<UserItemNormalized> {
890
905
 
891
906
  /**
892
907
  * Vérifie si l'utilisateur est abonné à l'entité.
893
- *
908
+ * @param options - Options de vérification.
909
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
894
910
  * @returns - `true` si l'utilisateur est abonné, `false` sinon.
895
911
  * @throws {ApiError}
896
912
  */
897
- override isFollowing(): boolean {
898
- if (!this.isActingUser) {
899
- throw new ApiError("Vous devez être connecté pour vérifier si vous le suivez.", 401);
900
- }
901
- if (!this.id) {
902
- throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
913
+ override isFollowing(options?: { silent?: boolean }): boolean {
914
+ const silent = options?.silent ?? true;
915
+ try {
916
+ if (!this.isActingUser) {
917
+ throw new ApiError("Vous devez être connecté pour vérifier si vous le suivez.", 401);
918
+ }
919
+ if (!this.id) {
920
+ throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
921
+ }
922
+ } catch (e) {
923
+ if (silent) return false;
924
+ throw e;
903
925
  }
904
926
  this._assertEntityType("citoyens");
905
927
  return this._isLinked("follows");
@@ -318,25 +318,34 @@ export declare class User extends BaseEntity<UserItemNormalized> {
318
318
  unfollow(): Promise<unknown>;
319
319
  /**
320
320
  * Vérifie si l'utilisateur connecté est ami avec cet utilisateur.
321
- *
321
+ * @param options - Options de vérification.
322
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
322
323
  * @returns - True si l'utilisateur connecté est ami, sinon false.
323
324
  * @throws {ApiError} - Si l'utilisateur n'est pas connecté.
324
325
  */
325
- isFriend(): boolean;
326
+ isFriend(options?: {
327
+ silent?: boolean;
328
+ }): boolean;
326
329
  /**
327
330
  * Vérifie si l'utilisateur suit l'entité.
328
- *
331
+ * @param options - Options de vérification.
332
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
329
333
  * @returns - `true` si l'utilisateur suit l'entité, `false` sinon.
330
334
  * @throws {ApiError}
331
335
  */
332
- isFollower(): boolean;
336
+ isFollower(options?: {
337
+ silent?: boolean;
338
+ }): boolean;
333
339
  /**
334
340
  * Vérifie si l'utilisateur est abonné à l'entité.
335
- *
341
+ * @param options - Options de vérification.
342
+ * @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
336
343
  * @returns - `true` si l'utilisateur est abonné, `false` sinon.
337
344
  * @throws {ApiError}
338
345
  */
339
- isFollowing(): boolean;
346
+ isFollowing(options?: {
347
+ silent?: boolean;
348
+ }): boolean;
340
349
  /**
341
350
  * Retourne une entité à partir d'un slug.
342
351
  * @param slug - Le slug de l'entité à récupérer.