@communecter/cocolight-api-client 1.0.29 → 1.0.30

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.29",
3
+ "version": "1.0.30",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Api.js CHANGED
@@ -163,7 +163,7 @@ export default class Api {
163
163
  */
164
164
  async project(projectData) {
165
165
  try {
166
- const project = new Project(this._client, projectData, { EndpointApi, User, Event, Poi, Badge, News });
166
+ const project = new Project(this._client, projectData, { EndpointApi, User, Organization, Event, Poi, Badge, News });
167
167
  if (!projectData.id && !projectData.slug) {
168
168
  throw new Error("Vous devez fournir un id ou un slug pour créer une instance Project.");
169
169
  }
@@ -1002,7 +1002,14 @@ export class BaseEntity {
1002
1002
  * @private
1003
1003
  */
1004
1004
  _linkEntities(results) {
1005
- return results.map(d => this._linkEntity?.(d.collection, d) ?? d);
1005
+ return results.flatMap(d => {
1006
+ if (!d?.collection) {
1007
+ this.apiClient._logger?.warn?.(`Objet ignoré car sans 'collection' : ${d?.id}`);
1008
+ return []; // exclu de la liste
1009
+ }
1010
+
1011
+ return [this._linkEntity?.(d.collection, d) ?? d];
1012
+ });
1006
1013
  }
1007
1014
 
1008
1015
  /**
@@ -1670,193 +1677,152 @@ export class BaseEntity {
1670
1677
  * Récupérer les organisations d'une entitée : la liste des organisations dont l'entité est membre ou admin valide.
1671
1678
  * Constant : GET_ORGANIZATIONS_ADMIN | GET_ORGANIZATIONS_NO_ADMIN
1672
1679
  * @param {Object} data - Les données à envoyer.
1680
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
1673
1681
  * @returns {Promise<Object>} - Les données de réponse.
1674
1682
  */
1675
- async getOrganizations(data = {}) {
1676
-
1677
- if(this.isMe){
1678
- data.pathParams = { type: this.getEntityType(), id: this.id };
1679
- // NOTE : dans le schema je crois que si pas de data.filters alors le default ce fait avec data.pathParams
1680
- // data.filters = {
1681
- // [`links.members.${this.id}`]: { "$exists": true },
1682
- // [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1683
- // [`links.members.${this.id}.isInviting`]: { "$exists": false }
1684
- // };
1685
- } else {
1686
- delete data?.pathParams;
1687
- data.filters = {
1688
- [`links.members.${this.id}`]: { "$exists": true },
1689
- [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1690
- [`links.members.${this.id}.isInviting`]: { "$exists": false }
1691
- };
1692
- }
1693
-
1694
- const fetchFn = this.isMe
1695
- ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(data))
1696
- : () => this.endpointApi.getOrganizationsNoAdmin(data);
1697
-
1698
- const arrayObjet = await fetchFn();
1699
-
1700
- if (!Array.isArray(arrayObjet.results)) {
1701
- throw new ApiResponseError("Erreur lors de la récupération des organisations.", 500, arrayObjet.results);
1702
- }
1703
-
1704
- // nettoyage du count
1705
- delete arrayObjet?.count?.spam;
1706
-
1707
- // calcul du total
1708
- const totalCount = Object.values(arrayObjet.count || {}).reduce((acc, val) => acc + val, 0);
1709
- arrayObjet.count.total = totalCount;
1710
-
1711
- const rawList = this._linkEntities(arrayObjet.results);
1683
+ async getOrganizations(data = {}, isNext = false) {
1684
+ data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType");
1685
+ // data.searchBy = "ALL";
1686
+ return this._paginateWith(data, isNext, async (finalData) => {
1687
+ if(this.isMe){
1688
+ finalData.pathParams = { type: this.getEntityType(), id: this.id };
1689
+ // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1690
+ // finalData.filters = {
1691
+ // [`links.members.${this.id}`]: { "$exists": true },
1692
+ // [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1693
+ // [`links.members.${this.id}.isInviting`]: { "$exists": false }
1694
+ // };
1695
+ } else {
1696
+ delete finalData?.pathParams;
1697
+ finalData.filters = {
1698
+ [`links.members.${this.id}`]: { "$exists": true },
1699
+ [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1700
+ [`links.members.${this.id}.isInviting`]: { "$exists": false }
1701
+ };
1702
+ }
1712
1703
 
1713
- return {
1714
- count: arrayObjet.count,
1715
- results: rawList
1716
- };
1704
+ const fetchFn = this.isMe
1705
+ ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(finalData))
1706
+ : () => this.endpointApi.getOrganizationsNoAdmin(finalData);
1707
+
1708
+ return fetchFn();
1709
+ });
1717
1710
  }
1718
1711
 
1719
1712
  /**
1720
- * Récupérer les projets d'une entitée : liste des projets de l'entité ou elle est "parent" ou "contributeur".
1721
- * Constant : GET_PROJECTS_ADMIN | GET_PROJECTS_NO_ADMIN
1722
- * @param {Object} data - Les données à envoyer.
1723
- * @returns {Promise<Object>} - Les données de réponse.
1724
- */
1725
- async getProjects(data = {}) {
1726
-
1727
- if(this.isMe){
1728
- data.pathParams = { type: this.getEntityType(), id: this.id };
1729
- // NOTE : dans le schema je crois que si pas de data.filters alors le default ce fait avec data.pathParams
1730
- // data.filters = {
1713
+ * Récupérer les projets d'une entitée : liste des projets de l'entité ou elle est "parent" ou "contributeur".
1714
+ * Constant : GET_PROJECTS_ADMIN | GET_PROJECTS_NO_ADMIN
1715
+ * @param {Object} data - Les données à envoyer.
1716
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
1717
+ * @returns {Promise<Object>} - Les données de réponse.
1718
+ */
1719
+ async getProjects(data = {}, isNext = false) {
1720
+ data.searchType = this._getDefaultFromEndpoint("GET_PROJECTS_ADMIN", "searchType");
1721
+ // data.searchBy = "ALL";
1722
+ return this._paginateWith(data, isNext, async (finalData) => {
1723
+ if(this.isMe){
1724
+ finalData.pathParams = { type: this.getEntityType(), id: this.id };
1725
+ // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1726
+ // finalData.filters = {
1731
1727
  // "$or": {
1732
1728
  // [`links.contributors.${this.id}`]: { "$exists": true },
1733
1729
  // [`parent.${this.id}`]: { "$exists": true }
1734
1730
  // },
1735
1731
  // [`links.contributors.${this.id}`]: { "$exists": true }
1736
1732
  // };
1737
- } else {
1738
- delete data?.pathParams;
1739
- data.filters = {
1740
- "$or": {
1741
- [`links.contributors.${this.id}`]: { "$exists": true },
1742
- [`parent.${this.id}`]: { "$exists": true }
1743
- },
1744
- [`links.contributors.${this.id}`]: { "$exists": true }
1745
- };
1746
- }
1747
-
1748
- const fetchFn = this.isMe
1749
- ? () => this.callIsMe(() => this.endpointApi.getProjectsAdmin(data))
1750
- : () => this.endpointApi.getProjectsNoAdmin(data);
1751
-
1752
-
1753
- const arrayObjet = await fetchFn();
1733
+ } else {
1734
+ delete finalData?.pathParams;
1735
+ finalData.filters = {
1736
+ "$or": {
1737
+ [`links.contributors.${this.id}`]: { "$exists": true },
1738
+ [`parent.${this.id}`]: { "$exists": true }
1739
+ },
1740
+ [`links.contributors.${this.id}`]: { "$exists": true }
1741
+ };
1742
+ }
1754
1743
 
1755
- if (!Array.isArray(arrayObjet.results)) {
1756
- throw new ApiResponseError("Erreur lors de la récupération des projets.", 500, arrayObjet.results);
1757
- }
1744
+ const fetchFn = this.isMe
1745
+ ? () => this.callIsMe(() => this.endpointApi.getProjectsAdmin(finalData))
1746
+ : () => this.endpointApi.getProjectsNoAdmin(finalData);
1758
1747
 
1759
- const rawList = this._linkEntities(arrayObjet.results);
1760
-
1761
- return {
1762
- count: arrayObjet?.count?.projects ?? 0,
1763
- results: rawList
1764
- };
1748
+ return fetchFn();
1749
+ });
1765
1750
  }
1766
1751
 
1767
1752
  /**
1768
1753
  * Récupérer les POIs d'une entité : liste des POIs de l'entité ou elle est "parent".
1769
1754
  * Constant : GET_POIS_NO_ADMIN / GET_POIS_ADMIN
1770
1755
  * @param {Object} data - Les données à envoyer.
1756
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
1771
1757
  * @returns {Promise<Object>} - Les données de réponse.
1772
1758
  */
1773
- async getPois(data = {}) {
1774
-
1775
- if(this.isMe){
1776
- data.pathParams = { type: this.getEntityType(), id: this.id };
1777
- // NOTE : dans le schema je crois que si pas de data.filters alors le default ce fait avec data.pathParams
1778
- // data.filters = {
1759
+ async getPois(data = {}, isNext = false) {
1760
+ data.searchType = this._getDefaultFromEndpoint("GET_POIS_ADMIN", "searchType");
1761
+ // data.searchBy = "ALL";
1762
+ return this._paginateWith(data, isNext, async (finalData) => {
1763
+ if(this.isMe){
1764
+ finalData.pathParams = { type: this.getEntityType(), id: this.id };
1765
+ // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1766
+ // finalData.filters = {
1779
1767
  // [`parent.${this.id}`]: { "$exists": true },
1780
1768
  // };
1781
- } else {
1782
- delete data?.pathParams;
1783
- data.filters = {
1784
- [`parent.${this.id}`]: { "$exists": true },
1785
- };
1786
- }
1787
-
1788
- const fetchFn = this.isMe
1789
- ? () => this.callIsMe(() => this.endpointApi.getPoisAdmin(data))
1790
- : () => this.endpointApi.getPoisNoAdmin(data);
1769
+ } else {
1770
+ delete finalData?.pathParams;
1771
+ finalData.filters = {
1772
+ [`parent.${this.id}`]: { "$exists": true },
1773
+ };
1774
+ }
1791
1775
 
1792
- const arrayObjet = await fetchFn();
1793
- if (!Array.isArray(arrayObjet.results)) {
1794
- throw new ApiResponseError("Erreur lors de la récupération des POIs.", 500, arrayObjet.results);
1795
- }
1776
+ const fetchFn = this.isMe
1777
+ ? () => this.callIsMe(() => this.endpointApi.getPoisAdmin(finalData))
1778
+ : () => this.endpointApi.getPoisNoAdmin(finalData);
1796
1779
 
1797
- // lier les entités au objets
1798
- const rawList = this._linkEntities(arrayObjet.results);
1799
-
1800
- return {
1801
- count: arrayObjet.count?.poi ?? 0,
1802
- results: rawList
1803
- };
1780
+ return fetchFn();
1781
+ });
1804
1782
  }
1805
1783
 
1806
1784
  /**
1807
1785
  * Récupérer les abonnés d'une entité
1808
1786
  * Constant : GET_SUBSCRIBERS
1809
1787
  * @param {Object} data - Les données à envoyer.
1788
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
1810
1789
  * @returns {Promise<Object>} - Les données de réponse.
1811
1790
  */
1812
- async getSubscribers(data = {}) {
1813
- delete data?.pathParams;
1814
-
1815
- data.filters = {
1816
- [`links.follows.${this.id}`]: { "$exists": true },
1817
- [`links.follows.${this.id}.toBeValidated`]: { "$exists": false },
1818
- [`links.follows.${this.id}.isInviting`]: { "$exists": false }
1819
- };
1820
-
1821
- const arrayObjet = await this.endpointApi.getSubscribers(data);
1822
- if (!Array.isArray(arrayObjet.results)) {
1823
- throw new ApiResponseError("Erreur lors de la récupération des abonnés.", 500, arrayObjet.results);
1824
- }
1791
+ async getSubscribers(data = {}, isNext = false) {
1792
+ data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIBERS", "searchType");
1793
+ // data.searchBy = "ALL";
1794
+ return this._paginateWith(data, isNext, async (finalData) => {
1795
+ delete finalData?.pathParams;
1825
1796
 
1826
- // lier les entités au objets
1827
- const rawList = this._linkEntities(arrayObjet.results);
1797
+ finalData.filters = {
1798
+ [`links.follows.${this.id}`]: { "$exists": true },
1799
+ [`links.follows.${this.id}.toBeValidated`]: { "$exists": false },
1800
+ [`links.follows.${this.id}.isInviting`]: { "$exists": false }
1801
+ };
1828
1802
 
1829
- return {
1830
- count: arrayObjet.count,
1831
- results: rawList
1832
- };
1803
+ return this.endpointApi.getSubscribers(finalData);
1804
+ });
1833
1805
  }
1834
1806
 
1835
1807
  /**
1836
1808
  * Liste des badges créés par l'entité
1837
1809
  * Constant : GET_BADGES
1838
1810
  * @param {Object} data - Les données à envoyer.
1811
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
1839
1812
  * @returns {Promise<Object>} - Les données de réponse.
1840
1813
  */
1841
- async getBadgesIssuer(data = {}) {
1842
- delete data?.pathParams;
1814
+ async getBadgesIssuer(data = {}, isNext = false) {
1815
+ data.searchType = this._getDefaultFromEndpoint("GET_BADGES", "searchType");
1816
+ // data.searchBy = "ALL";
1817
+ return this._paginateWith(data, isNext, async (finalData) => {
1818
+ delete finalData?.pathParams;
1843
1819
 
1844
- data.filters = data.filters || {};
1845
- data.filters["$or"] = {};
1846
- data.filters["$or"][`issuer.${this.id}`] = { "$exists": true };
1847
-
1848
- const arrayObjet = await this.endpointApi.getBadges(data);
1849
- if (!Array.isArray(arrayObjet.results)) {
1850
- throw new ApiResponseError("Erreur lors de la récupération des badges.", 500, arrayObjet.results);
1851
- }
1820
+ finalData.filters = finalData.filters || {};
1821
+ finalData.filters["$or"] = {};
1822
+ finalData.filters["$or"][`issuer.${this.id}`] = { "$exists": true };
1852
1823
 
1853
- // lier les entités au objets
1854
- const rawList = this._linkEntities(arrayObjet.results);
1855
-
1856
- return {
1857
- count: arrayObjet.count?.badges ?? 0,
1858
- results: rawList
1859
- };
1824
+ return this.endpointApi.getBadges(finalData);
1825
+ });
1860
1826
  }
1861
1827
 
1862
1828
  /**
@@ -2164,6 +2130,217 @@ export class BaseEntity {
2164
2130
  return this._isLinked("follows");
2165
2131
  }
2166
2132
 
2133
+ /**
2134
+ * Récupère le JSON personnalisé de l'entité
2135
+ *
2136
+ * @returns {Promise<Object>} - Le JSON personnalisé de l'entité.
2137
+ * @throws {ApiError} - Si le slug de l'entité n'est pas défini.
2138
+ */
2139
+ async getCostumJson() {
2140
+ if (!this.serverData.slug) {
2141
+ throw new ApiError("slug de l'entité non défini");
2142
+ }
2143
+ const data = {
2144
+ pathParams: {
2145
+ slug: this.serverData.slug
2146
+ }
2147
+ };
2148
+ return this.endpointApi.getCostumJson(data);
2149
+ }
2150
+
2151
+ /**
2152
+ * Génère des plages d'index pour la pagination.
2153
+ *
2154
+ * @param {Array<string>} searchType - Types de recherche.
2155
+ * @param {number} indexStep - Pas d'index.
2156
+ * @param {Object} previousRanges - Plages précédentes.
2157
+ * @returns {Object} - Plages d'index générées.
2158
+ * @private
2159
+ */
2160
+ _generateRanges(searchType, indexStep, previousRanges = {}) {
2161
+ const ranges = {};
2162
+ for (const type of searchType) {
2163
+ const previous = previousRanges[type] || { indexMax: 0 };
2164
+ ranges[type] = {
2165
+ indexMin: previous.indexMax || 0,
2166
+ indexMax: previous.indexMax + indexStep
2167
+ };
2168
+ }
2169
+ return ranges;
2170
+ }
2171
+
2172
+ /**
2173
+ * Normalise le compte des résultats.
2174
+ *
2175
+ * @param {Object} count - Compte des résultats.
2176
+ * @returns {Object} - Compte normalisé.
2177
+ * @private
2178
+ */
2179
+ _normalizeCount(count = {}) {
2180
+ // suppression des indésirables
2181
+ delete count.spam;
2182
+
2183
+ // calcul du total (somme des valeurs numériques)
2184
+ count.total = Object.values(count).reduce((acc, val) => acc + (typeof val === "number" ? val : 0), 0);
2185
+
2186
+ return count;
2187
+ }
2188
+
2189
+ /**
2190
+ * Méthode générique de pagination contextuelle avec support next / prev.
2191
+ *
2192
+ * @param {Object} data - Données d'entrée
2193
+ * @param {boolean} isNext - true si appel de page suivante
2194
+ * @param {Function} finalizer - fonction qui transforme et envoie les données (exécute la requête)
2195
+ * @returns {Promise<Object>} { count, results, next, prev }
2196
+ * @throws {ApiError} - Si le slug ou l'id de l'entité n'est pas défini.
2197
+ * @throws {ApiResponseError} - Si les résultats ne sont pas un tableau.
2198
+ * @private
2199
+ */
2200
+ async _paginateWith(data = {}, isNext = false, finalizer) {
2201
+ if (!this.serverData.slug) throw new ApiError("slug de l'entité non défini");
2202
+ if (!this.serverData.id) throw new ApiError("id de l'entité non défini");
2203
+
2204
+ const hasStep = (d) => d?.indexStep && d.indexStep > 0;
2205
+
2206
+ if (!this._paginationCursor || (!isNext && this._paginationHistory.length === 0)) {
2207
+ this._paginationCount = 0;
2208
+ this._paginationPageIndex = 0;
2209
+ this._paginationHistory = [];
2210
+ this._paginationPageSizes = [];
2211
+ data.countType = data.searchType;
2212
+
2213
+ if (!data?.searchBy && hasStep(data)) {
2214
+ data.ranges = this._generateRanges(data.searchType, data.indexStep);
2215
+ data.indexMin = data.indexMin ?? 0;
2216
+ data.indexMax = data.indexMax ?? data.indexStep;
2217
+ } else if (data?.searchBy === "ALL" && hasStep(data)) {
2218
+ data.indexMin = data.indexMin ?? 0;
2219
+ data.indexMax = data.indexMax ?? data.indexStep;
2220
+ }
2221
+
2222
+ this._paginationCursor = { ...data };
2223
+ }
2224
+
2225
+ const cursor = this._paginationCursor;
2226
+
2227
+ if (isNext) {
2228
+ this._paginationHistory.push({ ...cursor });
2229
+
2230
+ if (!cursor.searchBy && hasStep(cursor)) {
2231
+ cursor.ranges = this._generateRanges(cursor.searchType, cursor.indexStep, cursor.ranges);
2232
+ cursor.indexMin = cursor.indexMax ?? 0;
2233
+ cursor.indexMax = (cursor.indexMax ?? 0) + cursor.indexStep;
2234
+ } else if (cursor.searchBy === "ALL" && hasStep(cursor)) {
2235
+ cursor.indexMin = cursor.indexMax ?? 0;
2236
+ cursor.indexMax = (cursor.indexMax ?? 0) + cursor.indexStep;
2237
+ }
2238
+
2239
+ this._paginationCursor = { ...cursor };
2240
+ }
2241
+
2242
+ data = { ...this._paginationCursor };
2243
+
2244
+ if (!isNext && (!data?.searchType || !Array.isArray(data.searchType) || data.searchType.length === 0)) {
2245
+ throw new ApiError("searchType non défini");
2246
+ }
2247
+
2248
+ const result = await finalizer(data);
2249
+ if (!Array.isArray(result.results)) {
2250
+ throw new ApiResponseError("Erreur lors de la récupération des résultats", 500, result.results);
2251
+ }
2252
+
2253
+ this._paginationCount += result.results.length;
2254
+ this._paginationPageSizes.push(result.results.length);
2255
+
2256
+ if (isNext) {
2257
+ this._paginationPageIndex++;
2258
+ }
2259
+
2260
+ const count = this._normalizeCount(result.count);
2261
+ const rawList = this._linkEntities(result.results);
2262
+ const hasNext = hasStep(data) && this._paginationCount < count.total;
2263
+ const hasPrev = this._paginationHistory?.length > 0;
2264
+
2265
+ const response = {
2266
+ count,
2267
+ results: rawList,
2268
+ pageIndex: this._paginationPageIndex,
2269
+ pageNumber: this._paginationPageIndex + 1,
2270
+ hasNext,
2271
+ hasPrev
2272
+ };
2273
+
2274
+ if (hasNext) {
2275
+ response.next = async () => this._paginateWith({}, true, finalizer);
2276
+ }
2277
+
2278
+ if (this._paginationHistory?.length > 0) {
2279
+ response.prev = async () => {
2280
+ const previous = this._paginationHistory.pop();
2281
+ const lastPageSize = this._paginationPageSizes.pop() ?? 0;
2282
+ this._paginationCount -= lastPageSize;
2283
+ this._paginationPageIndex = Math.max(0, this._paginationPageIndex - 1);
2284
+ this._paginationCursor = { ...previous };
2285
+ return this._paginateWith({}, false, finalizer);
2286
+ };
2287
+ }
2288
+
2289
+ return response;
2290
+ }
2291
+
2292
+
2293
+ /**
2294
+ * Réinitialise l'état de pagination.
2295
+ */
2296
+ resetPagination() {
2297
+ this._paginationCursor = undefined;
2298
+ this._paginationCount = 0;
2299
+ this._paginationPageIndex = 0;
2300
+ this._paginationHistory = [];
2301
+ this._paginationPageSizes = [];
2302
+ }
2303
+
2304
+
2305
+ /**
2306
+ * Récupère une valeur par défaut depuis un endpoint donné.
2307
+ *
2308
+ * @param {string} constant - Le nom unique de l’endpoint (ex: "GET_ORGANIZATIONS_NO_ADMIN")
2309
+ * @param {string} path - Le chemin vers la propriété (ex: "searchType")
2310
+ * @returns {*} La valeur par défaut, ou undefined si non trouvée
2311
+ */
2312
+ _getDefaultFromEndpoint(constant, path) {
2313
+ const endpoint = this.apiClient._endpoints.find((ep) => ep.constant === constant);
2314
+ if (!endpoint?.request?.properties?.[path]) return undefined;
2315
+ return endpoint.request.properties[path].default;
2316
+ }
2317
+
2318
+ /**
2319
+ * recherche lié à l'entité.
2320
+ *
2321
+ * @param {Object} data - Les données de recherche.
2322
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
2323
+ * @returns {Promise<Object>} - Résultat de la recherche.
2324
+ * @throws {ApiError} - Si le slug ou l'id de entité n'est pas défini.
2325
+ */
2326
+ async searchCostum(data = {}, isNext = false) {
2327
+ return this._paginateWith(data, isNext, async (finalData) => {
2328
+ finalData = {
2329
+ ...finalData,
2330
+ costumSlug: this.serverData.slug,
2331
+ contextId: this.serverData.id,
2332
+ contextType: this.getEntityType()
2333
+ };
2334
+
2335
+ if (finalData.sourceKey?.length) {
2336
+ finalData.sourceKey = [...finalData.sourceKey, this.serverData.slug];
2337
+ } else {
2338
+ finalData.sourceKey = [this.serverData.slug];
2339
+ }
2340
+
2341
+ return this.endpointApi.globalAutocompleteCostum(finalData);
2342
+ });
2343
+ }
2167
2344
 
2168
2345
 
2169
2346
  }
@@ -1363,6 +1363,21 @@ class EndpointApi {
1363
1363
  return this.call("GET_COSTUM_JSON", data);
1364
1364
  }
1365
1365
 
1366
+ /**
1367
+ * Recherche globale lier à un costum : Effectue une recherche globale lier à un costum
1368
+ * Constant : GLOBAL_AUTOCOMPLETE_COSTUM
1369
+ * @param {import("./EndpointApi.types").GlobalAutocompleteCostumData} data - Données envoyées à l'API
1370
+ * @returns {Promise<Object>} - Les données de réponse.
1371
+ * @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
1372
+ * @throws {Error} - En cas d'erreur inattendue.
1373
+ */
1374
+ async globalAutocompleteCostum(data) {
1375
+ if (!data || typeof data !== "object") {
1376
+ throw new TypeError("Le paramètre data doit être un objet.");
1377
+ }
1378
+ return this.call("GLOBAL_AUTOCOMPLETE_COSTUM", data);
1379
+ }
1380
+
1366
1381
  }
1367
1382
 
1368
1383
  export default EndpointApi;