@communecter/cocolight-api-client 1.0.119 → 1.0.121

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.121",
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,15 @@ import type {
44
44
  CoformAnswersSearchData,
45
45
  ProfilBannerData,
46
46
  SearchMemberAutocompleteData,
47
- GetEventsData
47
+ GetEventsData,
48
+ CostumFilterCoformData,
49
+ GetCountriesData,
50
+ SearchZonesData
48
51
  } from "./EndpointApi.types.js";
49
52
  import type { GetElementsKeyResponse } from "../types/api-responses.js";
50
53
  import type { TransformsMap } from "../types/entities.js";
54
+ import type { CountryItem } from "./serverDataType/Country.js";
55
+ import type { ZoneItemNormalized } from "./serverDataType/Zone.js";
51
56
  const { fromBuffer } = pkg;
52
57
 
53
58
  /**
@@ -3220,14 +3225,13 @@ export class BaseEntity<TServerData = any> {
3220
3225
  finalizer: async (finalData) => {
3221
3226
  if(this.isMe){
3222
3227
  finalData.pathParams = { type: this.getEntityType(), id: this.id };
3223
- // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
3224
- // finalData.filters = {
3225
- // "$or": {
3226
- // [`links.contributors.${this.id}`]: { "$exists": true },
3227
- // [`parent.${this.id}`]: { "$exists": true }
3228
- // },
3229
- // [`links.contributors.${this.id}`]: { "$exists": true }
3230
- // };
3228
+ finalData.filters = {
3229
+ "$or": {
3230
+ [`links.contributors.${this.id}`]: { "$exists": true },
3231
+ [`parent.${this.id}`]: { "$exists": true }
3232
+ },
3233
+ [`links.contributors.${this.id}`]: { "$exists": true }
3234
+ };
3231
3235
  } else {
3232
3236
  delete finalData?.pathParams;
3233
3237
  finalData.filters = {
@@ -4640,6 +4644,81 @@ export class BaseEntity<TServerData = any> {
4640
4644
  return paginator.next() as Promise<PaginatorPage<any>>;
4641
4645
  }
4642
4646
 
4647
+
4648
+ /**
4649
+ * Récupère les filtres disponibles basés sur les réponses CoForm de l'entité courante.
4650
+ * Utilise le contexte Communecter (costumSlug, contextId, contextType) de l'entité.
4651
+ *
4652
+ * La réponse est un objet indexé par nom de filtre, chaque entrée contenant :
4653
+ * - `count` : nombre de résultats par catégorie
4654
+ * - `results` : valeurs disponibles pour ce filtre (libellé, image, etc.)
4655
+ *
4656
+ * @param data - Paramètres optionnels de recherche
4657
+ * @param data.searchedData - Filtres actifs : clé → `{ label, forms, path, finderPath }`
4658
+ * @returns Objet `Record<filterName, { count, results }>` des filtres disponibles
4659
+ *
4660
+ * @example
4661
+ * const filters = await project.coformFiltersSearch({
4662
+ * searchedData: {
4663
+ * "activités": {
4664
+ * label: "Activités",
4665
+ * forms: "6486d24e9cad105cbf29a777",
4666
+ * path: "lesCommunsDesTierslieux...",
4667
+ * finderPath: "answers.lesCommunsDesTierslieux..."
4668
+ * }
4669
+ * }
4670
+ * });
4671
+ * filters["activités"].count; // { "Atelier": 12, "Coworking": 8 }
4672
+ */
4673
+ async coformFiltersSearch(
4674
+ data: Partial<CostumFilterCoformData> = {},
4675
+ ): Promise<any> {
4676
+ const wrappedFinalizer = this._withCostumContext(
4677
+ (finalData: CostumFilterCoformData) => this.endpointApi.costumFilterCoform(finalData)
4678
+ );
4679
+ return wrappedFinalizer(data);
4680
+ }
4681
+
4682
+
4683
+ /**
4684
+ * Recherche des zones géographiques selon un pays et un niveau administratif.
4685
+ * Utilise le contexte Communecter de l'entité courante.
4686
+ *
4687
+ * @param data - Paramètres de recherche
4688
+ * @param data.countryCode - Code(s) pays ISO (ex: `["FR"]`)
4689
+ * @param data.level - Niveau(x) administratif(s) (ex: `["1"]`)
4690
+ * @returns Liste des zones correspondantes
4691
+ * @throws {ApiError} Si `countryCode` ou `level` sont absents
4692
+ */
4693
+ async searchZone(
4694
+ data: SearchZonesData,
4695
+ ): Promise<ZoneItemNormalized[]> {
4696
+ if(!data.countryCode?.length || !data.level?.length){
4697
+ throw new ApiError("countryCode et level sont requis.", 400);
4698
+ }
4699
+ const wrappedFinalizer = this._withCostumContext(
4700
+ (finalData: SearchZonesData) => this.endpointApi.searchZones(finalData)
4701
+ );
4702
+ return wrappedFinalizer(data) as Promise<ZoneItemNormalized[]>;
4703
+ }
4704
+
4705
+ /**
4706
+ * Récupère la liste de tous les pays (endpoint public, sans authentification).
4707
+ *
4708
+ * @param data - Paramètres optionnels (costumSlug, costumId, costumType)
4709
+ * @returns Liste des pays `{ name, countryCode, level, geo, ... }`
4710
+ *
4711
+ * @example
4712
+ * const countries = await organization.getCountries();
4713
+ * countries[0].name; // "France"
4714
+ * countries[0].countryCode; // "FR"
4715
+ */
4716
+ async getCountries(
4717
+ data: Partial<GetCountriesData> = {},
4718
+ ): Promise<CountryItem[]> {
4719
+ return this.endpointApi.getCountries(data as GetCountriesData) as Promise<CountryItem[]>;
4720
+ }
4721
+
4643
4722
  /**
4644
4723
  * ───────────────────────────────
4645
4724
  * 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, GetCountriesData, 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,51 @@ 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
+ * Récupérer la liste des pays : Récupérer la liste de tous les pays
1740
+ * Constant : GET_COUNTRIES
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 getCountries(data: GetCountriesData): 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("GET_COUNTRIES", data);
1751
+ }
1752
+
1753
+ /**
1754
+ * Rechercher des zones géographiques : Rechercher des zones géographiques
1755
+ * Constant : SEARCH_ZONES
1756
+ * @param data - Données envoyées à l'API
1757
+ * @returns Les données de réponse.
1758
+ * @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
1759
+ * @throws {Error} - En cas d'erreur inattendue.
1760
+ */
1761
+ async searchZones(data: SearchZonesData): Promise<any> {
1762
+ if (!data || typeof data !== "object") {
1763
+ throw new TypeError("Le paramètre data doit être un objet.");
1764
+ }
1765
+ return this.call("SEARCH_ZONES", data);
1766
+ }
1767
+
1723
1768
  }
1724
1769
 
1725
1770
  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,80 @@ 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 GetCountriesData {
4977
+ /**
4978
+ * Slug personnalisé
4979
+ */
4980
+ costumSlug?: string;
4981
+ /**
4982
+ * Mode édition personnalisé (boolean, string ou number)
4983
+ */
4984
+ costumEditMode?: ("true" | "false") | (0 | 1) | boolean;
4985
+ /**
4986
+ * ID personnalisé (format ObjectID MongoDB)
4987
+ */
4988
+ costumId?: string;
4989
+ /**
4990
+ * Type de collection
4991
+ */
4992
+ costumType?: "organizations" | "projects" | "events" | "citoyens" | "poi";
4993
+ [k: string]: unknown;
4994
+ }
4995
+
4996
+
4997
+ export interface SearchZonesData {
4998
+ /**
4999
+ * Code du pays pour la recherche
5000
+ */
5001
+ countryCode: unknown[];
5002
+ /**
5003
+ * Niveau de la zone géographique pour la recherche
5004
+ */
5005
+ level: unknown[];
5006
+ /**
5007
+ * Critère de tri des résultats
5008
+ */
5009
+ sortBy?: string;
5010
+ /**
5011
+ * ID du niveau supérieur pour la recherche
5012
+ */
5013
+ upperLevelId?: string;
5014
+ /**
5015
+ * Slug du costume
5016
+ */
5017
+ costumSlug?: string;
5018
+ /**
5019
+ * ID du costume
5020
+ */
5021
+ costumId?: string;
5022
+ /**
5023
+ * Type du costume
5024
+ */
5025
+ costumType?: string;
5026
+ [k: string]: unknown;
5027
+ }
@@ -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 @@
1
+ export type { ZoneItemNormalized as CountryItem } from "./Zone.js";
@@ -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
+ }