@communecter/cocolight-api-client 1.0.119 → 1.0.120

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.119",
3
+ "version": "1.0.120",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
package/src/ApiClient.ts CHANGED
@@ -207,7 +207,6 @@ export default class ApiClient extends EventEmitter {
207
207
  baseURL,
208
208
  timeout
209
209
  });
210
-
211
210
  // axios-retry : pour retenter en cas de soucis réseau ou code 5xx
212
211
  if (maxRetries > 0) {
213
212
  axiosRetry(this._client, {
@@ -741,7 +740,7 @@ export default class ApiClient extends EventEmitter {
741
740
  throw new ApiClientError(`Path param manquant ou non résolu : {${key}}`, 400);
742
741
  });
743
742
  }
744
-
743
+
745
744
  // === 2. Validation données (request schema) ===
746
745
  if (requestSchema) {
747
746
  // Si auth est "none" et que userId n'est pas défini, on nettoie le schéma
@@ -44,10 +44,13 @@ import type {
44
44
  CoformAnswersSearchData,
45
45
  ProfilBannerData,
46
46
  SearchMemberAutocompleteData,
47
- GetEventsData
47
+ GetEventsData,
48
+ CostumFilterCoformData,
49
+ SearchZonesData
48
50
  } from "./EndpointApi.types.js";
49
51
  import type { GetElementsKeyResponse } from "../types/api-responses.js";
50
52
  import type { TransformsMap } from "../types/entities.js";
53
+ import type { ZoneItemNormalized } from "./serverDataType/Zone.js";
51
54
  const { fromBuffer } = pkg;
52
55
 
53
56
  /**
@@ -4640,6 +4643,64 @@ export class BaseEntity<TServerData = any> {
4640
4643
  return paginator.next() as Promise<PaginatorPage<any>>;
4641
4644
  }
4642
4645
 
4646
+
4647
+ /**
4648
+ * Récupère les filtres disponibles basés sur les réponses CoForm de l'entité courante.
4649
+ * Utilise le contexte Communecter (costumSlug, contextId, contextType) de l'entité.
4650
+ *
4651
+ * La réponse est un objet indexé par nom de filtre, chaque entrée contenant :
4652
+ * - `count` : nombre de résultats par catégorie
4653
+ * - `results` : valeurs disponibles pour ce filtre (libellé, image, etc.)
4654
+ *
4655
+ * @param data - Paramètres optionnels de recherche
4656
+ * @param data.searchedData - Filtres actifs : clé → `{ label, forms, path, finderPath }`
4657
+ * @returns Objet `Record<filterName, { count, results }>` des filtres disponibles
4658
+ *
4659
+ * @example
4660
+ * const filters = await project.coformFiltersSearch({
4661
+ * searchedData: {
4662
+ * "activités": {
4663
+ * label: "Activités",
4664
+ * forms: "6486d24e9cad105cbf29a777",
4665
+ * path: "lesCommunsDesTierslieux...",
4666
+ * finderPath: "answers.lesCommunsDesTierslieux..."
4667
+ * }
4668
+ * }
4669
+ * });
4670
+ * filters["activités"].count; // { "Atelier": 12, "Coworking": 8 }
4671
+ */
4672
+ async coformFiltersSearch(
4673
+ data: Partial<CostumFilterCoformData> = {},
4674
+ ): Promise<any> {
4675
+ const wrappedFinalizer = this._withCostumContext(
4676
+ (finalData: CostumFilterCoformData) => this.endpointApi.costumFilterCoform(finalData)
4677
+ );
4678
+ return wrappedFinalizer(data);
4679
+ }
4680
+
4681
+
4682
+ /**
4683
+ * Recherche des zones géographiques selon un pays et un niveau administratif.
4684
+ * Utilise le contexte Communecter de l'entité courante.
4685
+ *
4686
+ * @param data - Paramètres de recherche
4687
+ * @param data.countryCode - Code(s) pays ISO (ex: `["FR"]`)
4688
+ * @param data.level - Niveau(x) administratif(s) (ex: `["1"]`)
4689
+ * @returns Liste des zones correspondantes
4690
+ * @throws {ApiError} Si `countryCode` ou `level` sont absents
4691
+ */
4692
+ async searchZone(
4693
+ data: SearchZonesData,
4694
+ ): Promise<ZoneItemNormalized[]> {
4695
+ if(!data.countryCode?.length || !data.level?.length){
4696
+ throw new ApiError("countryCode et level sont requis.", 400);
4697
+ }
4698
+ const wrappedFinalizer = this._withCostumContext(
4699
+ (finalData: SearchZonesData) => this.endpointApi.searchZones(finalData)
4700
+ );
4701
+ return wrappedFinalizer(data) as Promise<ZoneItemNormalized[]>;
4702
+ }
4703
+
4643
4704
  /**
4644
4705
  * ───────────────────────────────
4645
4706
  * Pagination restoration methods
@@ -246,7 +246,7 @@ export class Comment extends BaseEntity<CommentItemNormalized> {
246
246
  }
247
247
  };
248
248
 
249
- return await this.callIsConnected(() => this.endpointApi.addReportAbuse(payload));;
249
+ return await this.callIsConnected(() => this.endpointApi.addReportAbuse(payload));
250
250
  }
251
251
 
252
252
  }
@@ -2,7 +2,7 @@
2
2
  import { ApiAuthenticationError } from "../error.js";
3
3
 
4
4
  import type ApiClient from "../ApiClient.js";
5
- import type { PersonRegisterData, AuthenticateUrlData, RefreshTokenUrlData, PasswordRecoveryData, ServerExchangeTokenData, ChangePasswordData, DeleteAccountData, UpdateSettingsData, UpdateBlockDescriptionData, UpdateBlockInfoData, UpdateBlockSocialData, UpdateBlockLocalityData, UpdateBlockSlugData, CheckData, ProfilImageData, ProfilBannerData, GetElementsAboutData, MulticonnectData, GetNewsData, GetNewsByIdData, AddNewsData, AddImageNewsData, AddFileNewsData, DeleteNewsData, UpdateNewsData, ShareNewsData, GetCommentsData, AddCommentsData, DeleteCommentsData, UpdateCommentsData, SearchTagsData, ShowVoteData, GlobalAutocompleteData, CityAutocompleteData, CityAutocompleteByCountryData, SuggestionInputData, GetProjectsNoAdminData, GetProjectsAdminData, GetPoisNoAdminData, GetPoisAdminData, GetOrganizationsNoAdminData, GetOrganizationsAdminData, GetMembersNoAdminData, GetMembersAdminData, GetFriendsAdminData, GetSubscriptionsData, GetSubscriptionsAdminData, GetSubscribersData, GetSubscribersAdminData, GetContributorsNoAdminData, GetContributorsAdminData, GetBadgesData, GetBadgesFiltersData, ConnectData, DisconnectData, GetElementsKeyData, GetFavorisData, DeleteFavorisData, AddFavorisData, AddOrganizationData, AddProjectData, AddPoiData, AddEventData, DeletePoiData, DeleteEventData, DeleteElementData, AddImageElementData, LinkValidateData, SearchMemberAutocompleteData, GetNotificationsData, GetNotificationsCountData, NotificationUpdateData, MarkNotificationAsReadData, ActivitypubSearchData, ActivitypubLinkData, ActivitypubGetCommunityData, GetBadgeData, AddBadgesData, AssignBadgesData, GetEventsData, ShareEventsData, InviteEventData, FollowData, GetCostumJsonData, GlobalAutocompleteCostumData, CostumEventRequestActorsData, CostumEventRequestSubeventsData, CostumEventRequestElementEventData, CostumEventRequestCategoriesData, CostumEventRequestDatesData, CostumEventRequestEventData, CostumEventRequestLinkTlToEventData, CostumEventRequestLoadContextTagData, GetGalleryData, GetAttendeesNoAdminData, GetAttendeesAdminData, CoformAnswersSearchData, CoformAnswersByIdData, AddVoteData, AddReportAbuseData, UpdatePathValueData, DeleteDocumentByContextData, DemoteAdminData } from "./EndpointApi.types.js";
5
+ import type { PersonRegisterData, AuthenticateUrlData, RefreshTokenUrlData, PasswordRecoveryData, ServerExchangeTokenData, ChangePasswordData, DeleteAccountData, UpdateSettingsData, UpdateBlockDescriptionData, UpdateBlockInfoData, UpdateBlockSocialData, UpdateBlockLocalityData, UpdateBlockSlugData, CheckData, ProfilImageData, ProfilBannerData, GetElementsAboutData, MulticonnectData, GetNewsData, GetNewsByIdData, AddNewsData, AddImageNewsData, AddFileNewsData, DeleteNewsData, UpdateNewsData, ShareNewsData, GetCommentsData, AddCommentsData, DeleteCommentsData, UpdateCommentsData, SearchTagsData, ShowVoteData, GlobalAutocompleteData, CityAutocompleteData, CityAutocompleteByCountryData, SuggestionInputData, GetProjectsNoAdminData, GetProjectsAdminData, GetPoisNoAdminData, GetPoisAdminData, GetOrganizationsNoAdminData, GetOrganizationsAdminData, GetMembersNoAdminData, GetMembersAdminData, GetFriendsAdminData, GetSubscriptionsData, GetSubscriptionsAdminData, GetSubscribersData, GetSubscribersAdminData, GetContributorsNoAdminData, GetContributorsAdminData, GetBadgesData, GetBadgesFiltersData, ConnectData, DisconnectData, GetElementsKeyData, GetFavorisData, DeleteFavorisData, AddFavorisData, AddOrganizationData, AddProjectData, AddPoiData, AddEventData, DeletePoiData, DeleteEventData, DeleteElementData, AddImageElementData, LinkValidateData, SearchMemberAutocompleteData, GetNotificationsData, GetNotificationsCountData, NotificationUpdateData, MarkNotificationAsReadData, ActivitypubSearchData, ActivitypubLinkData, ActivitypubGetCommunityData, GetBadgeData, AddBadgesData, AssignBadgesData, GetEventsData, ShareEventsData, InviteEventData, FollowData, GetCostumJsonData, GlobalAutocompleteCostumData, CostumEventRequestActorsData, CostumEventRequestSubeventsData, CostumEventRequestElementEventData, CostumEventRequestCategoriesData, CostumEventRequestDatesData, CostumEventRequestEventData, CostumEventRequestLinkTlToEventData, CostumEventRequestLoadContextTagData, GetGalleryData, GetAttendeesNoAdminData, GetAttendeesAdminData, CoformAnswersSearchData, CoformAnswersByIdData, AddVoteData, AddReportAbuseData, UpdatePathValueData, DeleteDocumentByContextData, DemoteAdminData, CostumFilterCoformData, SearchZonesData } from "./EndpointApi.types.js";
6
6
 
7
7
  /**
8
8
  * Classe EndpointApi générée automatiquement depuis endpoints-copie.json
@@ -1720,6 +1720,36 @@ export class EndpointApi {
1720
1720
  return this.callIsConnected("DEMOTE_ADMIN", data);
1721
1721
  }
1722
1722
 
1723
+ /**
1724
+ * Filtre par reponses CoForm : Recuperer tous les filtres possibles via l'answers
1725
+ * Constant : COSTUM_FILTER_COFORM
1726
+ * @param data - Données envoyées à l'API
1727
+ * @returns Les données de réponse.
1728
+ * @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
1729
+ * @throws {Error} - En cas d'erreur inattendue.
1730
+ */
1731
+ async costumFilterCoform(data: CostumFilterCoformData): Promise<any> {
1732
+ if (!data || typeof data !== "object") {
1733
+ throw new TypeError("Le paramètre data doit être un objet.");
1734
+ }
1735
+ return this.call("COSTUM_FILTER_COFORM", data);
1736
+ }
1737
+
1738
+ /**
1739
+ * Rechercher des zones géographiques : Rechercher des zones géographiques
1740
+ * Constant : SEARCH_ZONES
1741
+ * @param data - Données envoyées à l'API
1742
+ * @returns Les données de réponse.
1743
+ * @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
1744
+ * @throws {Error} - En cas d'erreur inattendue.
1745
+ */
1746
+ async searchZones(data: SearchZonesData): Promise<any> {
1747
+ if (!data || typeof data !== "object") {
1748
+ throw new TypeError("Le paramètre data doit être un objet.");
1749
+ }
1750
+ return this.call("SEARCH_ZONES", data);
1751
+ }
1752
+
1723
1753
  }
1724
1754
 
1725
1755
  export default EndpointApi;
@@ -3967,7 +3967,7 @@ export interface GlobalAutocompleteCostumData {
3967
3967
  /**
3968
3968
  * Type de la localité : 'cities' pour une ville ou 'level1' pour une région
3969
3969
  */
3970
- type: "cities" | "level1";
3970
+ type: "cities" | "level1" | "level2" | "level3" | "level4" | "level5";
3971
3971
  };
3972
3972
  };
3973
3973
  /**
@@ -4948,3 +4948,59 @@ export interface DemoteAdminData {
4948
4948
  isAdmin: false;
4949
4949
  [k: string]: unknown;
4950
4950
  }
4951
+
4952
+
4953
+ export interface CostumFilterCoformData {
4954
+ /**
4955
+ * Données de recherche pour le filtre
4956
+ */
4957
+ searchedData?: {
4958
+ [k: string]: unknown;
4959
+ };
4960
+ /**
4961
+ * Slug du costume
4962
+ */
4963
+ costumSlug?: string;
4964
+ /**
4965
+ * ID du costume
4966
+ */
4967
+ costumId?: string;
4968
+ /**
4969
+ * Type du costume
4970
+ */
4971
+ costumType?: string;
4972
+ [k: string]: unknown;
4973
+ }
4974
+
4975
+
4976
+ export interface SearchZonesData {
4977
+ /**
4978
+ * Code du pays pour la recherche
4979
+ */
4980
+ countryCode: unknown[];
4981
+ /**
4982
+ * Niveau de la zone géographique pour la recherche
4983
+ */
4984
+ level: unknown[];
4985
+ /**
4986
+ * Critère de tri des résultats
4987
+ */
4988
+ sortBy?: string;
4989
+ /**
4990
+ * ID du niveau supérieur pour la recherche
4991
+ */
4992
+ upperLevelId?: string;
4993
+ /**
4994
+ * Slug du costume
4995
+ */
4996
+ costumSlug?: string;
4997
+ /**
4998
+ * ID du costume
4999
+ */
5000
+ costumId?: string;
5001
+ /**
5002
+ * Type du costume
5003
+ */
5004
+ costumType?: string;
5005
+ [k: string]: unknown;
5006
+ }
@@ -83,7 +83,7 @@ export class UserApi {
83
83
  throw new ApiError("User not connected", 401);
84
84
  }
85
85
 
86
- this.client._logger.info("UserApi", "meIsconnected", this.client.userId);
86
+ this.client._logger.debug("UserApi", "meIsconnected", this.client.userId);
87
87
 
88
88
  this.loggedUser = new User(
89
89
  this.client,
@@ -0,0 +1,33 @@
1
+ import { GeoCoordinates, GeoPosition, IdObject } from "./common.js";
2
+
3
+ import type EJSONType from "../../EJSONType.js";
4
+
5
+ type ObjectIDCtor = typeof EJSONType["ObjectID"];
6
+ type ObjectID = InstanceType<ObjectIDCtor>;
7
+
8
+ export interface ZoneItemNormalized {
9
+ _id: IdObject;
10
+ countryCode: string;
11
+ geo: GeoCoordinates;
12
+ geoPosition: GeoPosition;
13
+ level: string[];
14
+ name: string;
15
+ osmID?: string;
16
+ wikidataID?: string;
17
+ translateId: string;
18
+ [key: string]: unknown;
19
+ }
20
+
21
+ export interface ZoneItemJson {
22
+ id: string;
23
+ _id: ObjectID;
24
+ countryCode: string;
25
+ geo: GeoCoordinates;
26
+ geoPosition: GeoPosition;
27
+ level: string[];
28
+ name: string;
29
+ osmID?: string;
30
+ wikidataID?: string;
31
+ translateId: string;
32
+ [key: string]: unknown;
33
+ }