@communecter/cocolight-api-client 1.0.32 → 1.0.34

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.32",
3
+ "version": "1.0.34",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Api.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // Api.js
2
2
  import { Badge } from "./api/Badge.js";
3
3
  import EndpointApi from "./api/EndpointApi.js";
4
+ import { registerEntity } from "./api/EntityRegistry.js";
4
5
  import { Event } from "./api/Event.js";
5
6
  import { News } from "./api/News.js";
6
7
  import { Organization } from "./api/Organization.js";
@@ -10,6 +11,16 @@ import { User } from "./api/User.js";
10
11
  import { UserApi } from "./api/UserApi.js";
11
12
  import { ApiAuthenticationError, ApiClientError, ApiError } from "./error.js";
12
13
 
14
+ registerEntity("User", User);
15
+ registerEntity("Organization", Organization);
16
+ registerEntity("Project", Project);
17
+ registerEntity("Event", Event);
18
+ registerEntity("Poi", Poi);
19
+ registerEntity("Badge", Badge);
20
+ registerEntity("EndpointApi", EndpointApi);
21
+ registerEntity("UserApi", UserApi);
22
+ registerEntity("News", News);
23
+
13
24
  export default class Api {
14
25
  /**
15
26
  * Authentifie l'utilisateur et retourne une instance d'Api.
@@ -1,6 +1,7 @@
1
1
  // BaseEntity.js
2
2
  import ObjectID from "bson-objectid";
3
3
  // import { fileTypeFromBuffer } from "file-type";
4
+ import EJSON from "ejson";
4
5
  import pkg from "file-type";
5
6
 
6
7
  import { ApiAuthenticationError, ApiError, ApiResponseError, ApiValidationError } from "../error.js";
@@ -266,6 +267,114 @@ export class BaseEntity {
266
267
  */
267
268
  transforms = {};
268
269
 
270
+ /**
271
+ * ───────────────────────────────
272
+ * JSON
273
+ * ───────────────────────────────
274
+ */
275
+
276
+ /**
277
+ * Convertit l'instance en JSON pour l'envoi au serveur.
278
+ *
279
+ * @returns {Object} Représentation JSON de l'instance.
280
+ */
281
+ toJSON() {
282
+ const parentMeta = {};
283
+ if (this.parent?.id) parentMeta.id = this.parent.id;
284
+ if (typeof this.parent?.getEntityType === "function") parentMeta.type = this.parent.getEntityType();
285
+ if (this.parent?.__entityTag) parentMeta.__entityTag = this.parent.__entityTag;
286
+ if (this.parent?.slug) parentMeta.slug = this.parent.slug;
287
+
288
+ return {
289
+ __entityTag: this.__entityTag,
290
+ __isSerializedEntity: true,
291
+ serverData: this._serialize(this._serverData),
292
+ parent: Object.keys(parentMeta).length > 0 ? parentMeta : null
293
+ };
294
+ }
295
+
296
+
297
+ _serialize(obj) {
298
+ try {
299
+ return JSON.parse(EJSON.stringify(this._removeUnserializables(obj)));
300
+ } catch (e) {
301
+ this.apiClient?._logger?.error?.("Erreur de sérialisation EJSON", e);
302
+ return null;
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Supprime les propriétés non sérialisables d'un objet.
308
+ *
309
+ * @param {Object} obj - L'objet à nettoyer.
310
+ * @param {WeakSet} [seen] - Ensemble pour éviter les références circulaires.
311
+ * @returns {Object} L'objet nettoyé.
312
+ * @private
313
+ */
314
+ _removeUnserializables(obj, seen = new WeakSet()) {
315
+ if (obj === null || typeof obj !== "object") return obj;
316
+
317
+ if (seen.has(obj)) return null;
318
+ seen.add(obj);
319
+
320
+ // Ignore les proxys réactifs
321
+ if (obj.__isReactive && typeof obj.__raw === "object") {
322
+ return this._removeUnserializables(obj.__raw, seen);
323
+ }
324
+
325
+ if (Array.isArray(obj)) {
326
+ return obj.map((el) => this._removeUnserializables(el, seen));
327
+ }
328
+
329
+ const clean = {};
330
+ for (const key of Object.keys(obj)) {
331
+ const val = obj[key];
332
+
333
+ if (
334
+ typeof val === "function" ||
335
+ typeof val === "symbol" ||
336
+ typeof val === "undefined"
337
+ ) {
338
+ continue;
339
+ }
340
+
341
+ try {
342
+ clean[key] = this._removeUnserializables(val, seen);
343
+ // eslint-disable-next-line no-unused-vars
344
+ } catch (e) {
345
+ clean[key] = null;
346
+ }
347
+ }
348
+
349
+ return clean;
350
+ }
351
+
352
+ /**
353
+ * Restaure les données sérialisées en un objet d'origine.
354
+ *
355
+ * @param {Object} obj - L'objet à restaurer.
356
+ * @returns {Object} L'objet restauré.
357
+ */
358
+ static _revive(obj) {
359
+ return EJSON.fromJSONValue(obj);
360
+ }
361
+
362
+ /**
363
+ * Crée une instance d'entité à partir de données JSON.
364
+ *
365
+ * @param {Object} json - Données JSON à utiliser.
366
+ * @param {Object} parent - Instance parente.
367
+ * @param {Object} deps - Dépendances injectées.
368
+ * @returns {object} Nouvelle instance d'entité.
369
+ */
370
+ static fromJSON(json, parent, deps) {
371
+
372
+ const { serverData } = json;
373
+
374
+ const instance = this.fromServerData(this._revive(serverData), parent, deps);
375
+
376
+ return instance;
377
+ }
269
378
 
270
379
  /**
271
380
  * ───────────────────────────────
@@ -1685,30 +1794,6 @@ export class BaseEntity {
1685
1794
  async getOrganizations(data = {}) {
1686
1795
  data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType");
1687
1796
  // data.searchBy = "ALL";
1688
- // return this._paginateWith(data, isNext, async (finalData) => {
1689
- // if(this.isMe){
1690
- // finalData.pathParams = { type: this.getEntityType(), id: this.id };
1691
- // // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1692
- // // finalData.filters = {
1693
- // // [`links.members.${this.id}`]: { "$exists": true },
1694
- // // [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1695
- // // [`links.members.${this.id}.isInviting`]: { "$exists": false }
1696
- // // };
1697
- // } else {
1698
- // delete finalData?.pathParams;
1699
- // finalData.filters = {
1700
- // [`links.members.${this.id}`]: { "$exists": true },
1701
- // [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
1702
- // [`links.members.${this.id}.isInviting`]: { "$exists": false }
1703
- // };
1704
- // }
1705
-
1706
- // const fetchFn = this.isMe
1707
- // ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(finalData))
1708
- // : () => this.endpointApi.getOrganizationsNoAdmin(finalData);
1709
-
1710
- // return fetchFn();
1711
- // });
1712
1797
 
1713
1798
  const paginator = this._createPaginatorEngine({
1714
1799
  initialData: data,
@@ -1751,34 +1836,7 @@ export class BaseEntity {
1751
1836
  async getProjects(data = {}) {
1752
1837
  data.searchType = this._getDefaultFromEndpoint("GET_PROJECTS_ADMIN", "searchType");
1753
1838
  // data.searchBy = "ALL";
1754
- // return this._paginateWith(data, isNext, async (finalData) => {
1755
- // if(this.isMe){
1756
- // finalData.pathParams = { type: this.getEntityType(), id: this.id };
1757
- // // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1758
- // // finalData.filters = {
1759
- // // "$or": {
1760
- // // [`links.contributors.${this.id}`]: { "$exists": true },
1761
- // // [`parent.${this.id}`]: { "$exists": true }
1762
- // // },
1763
- // // [`links.contributors.${this.id}`]: { "$exists": true }
1764
- // // };
1765
- // } else {
1766
- // delete finalData?.pathParams;
1767
- // finalData.filters = {
1768
- // "$or": {
1769
- // [`links.contributors.${this.id}`]: { "$exists": true },
1770
- // [`parent.${this.id}`]: { "$exists": true }
1771
- // },
1772
- // [`links.contributors.${this.id}`]: { "$exists": true }
1773
- // };
1774
- // }
1775
-
1776
- // const fetchFn = this.isMe
1777
- // ? () => this.callIsMe(() => this.endpointApi.getProjectsAdmin(finalData))
1778
- // : () => this.endpointApi.getProjectsNoAdmin(finalData);
1779
1839
 
1780
- // return fetchFn();
1781
- // });
1782
1840
  const paginator = this._createPaginatorEngine({
1783
1841
  initialData: data,
1784
1842
  finalizer: async (finalData) => {
@@ -1824,26 +1882,6 @@ export class BaseEntity {
1824
1882
  async getPois(data = {}) {
1825
1883
  data.searchType = this._getDefaultFromEndpoint("GET_POIS_ADMIN", "searchType");
1826
1884
  // data.searchBy = "ALL";
1827
- // return this._paginateWith(data, isNext, async (finalData) => {
1828
- // if(this.isMe){
1829
- // finalData.pathParams = { type: this.getEntityType(), id: this.id };
1830
- // // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
1831
- // // finalData.filters = {
1832
- // // [`parent.${this.id}`]: { "$exists": true },
1833
- // // };
1834
- // } else {
1835
- // delete finalData?.pathParams;
1836
- // finalData.filters = {
1837
- // [`parent.${this.id}`]: { "$exists": true },
1838
- // };
1839
- // }
1840
-
1841
- // const fetchFn = this.isMe
1842
- // ? () => this.callIsMe(() => this.endpointApi.getPoisAdmin(finalData))
1843
- // : () => this.endpointApi.getPoisNoAdmin(finalData);
1844
-
1845
- // return fetchFn();
1846
- // });
1847
1885
 
1848
1886
  const paginator = this._createPaginatorEngine({
1849
1887
  initialData: data,
@@ -1882,17 +1920,7 @@ export class BaseEntity {
1882
1920
  async getSubscribers(data = {}) {
1883
1921
  data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIBERS", "searchType");
1884
1922
  // data.searchBy = "ALL";
1885
- // return this._paginateWith(data, isNext, async (finalData) => {
1886
- // delete finalData?.pathParams;
1887
-
1888
- // finalData.filters = {
1889
- // [`links.follows.${this.id}`]: { "$exists": true },
1890
- // [`links.follows.${this.id}.toBeValidated`]: { "$exists": false },
1891
- // [`links.follows.${this.id}.isInviting`]: { "$exists": false }
1892
- // };
1893
1923
 
1894
- // return this.endpointApi.getSubscribers(finalData);
1895
- // });
1896
1924
  const paginator = this._createPaginatorEngine({
1897
1925
  initialData: data,
1898
1926
  finalizer: async (finalData) => {
@@ -1921,15 +1949,7 @@ export class BaseEntity {
1921
1949
  async getBadgesIssuer(data = {}) {
1922
1950
  data.searchType = this._getDefaultFromEndpoint("GET_BADGES", "searchType");
1923
1951
  // data.searchBy = "ALL";
1924
- // return this._paginateWith(data, isNext, async (finalData) => {
1925
- // delete finalData?.pathParams;
1926
-
1927
- // finalData.filters = finalData.filters || {};
1928
- // finalData.filters["$or"] = {};
1929
- // finalData.filters["$or"][`issuer.${this.id}`] = { "$exists": true };
1930
1952
 
1931
- // return this.endpointApi.getBadges(finalData);
1932
- // });
1933
1953
  const paginator = this._createPaginatorEngine({
1934
1954
  initialData: data,
1935
1955
  finalizer: async (finalData) => {
@@ -2306,122 +2326,6 @@ export class BaseEntity {
2306
2326
 
2307
2327
  return count;
2308
2328
  }
2309
-
2310
- /**
2311
- * Méthode générique de pagination contextuelle avec support next / prev.
2312
- *
2313
- * @param {Object} data - Données d'entrée
2314
- * @param {boolean} isNext - true si appel de page suivante
2315
- * @param {Function} finalizer - fonction qui transforme et envoie les données (exécute la requête)
2316
- * @returns {Promise<Object>} { count, results, next, prev }
2317
- * @throws {ApiError} - Si le slug ou l'id de l'entité n'est pas défini.
2318
- * @throws {ApiResponseError} - Si les résultats ne sont pas un tableau.
2319
- * @private
2320
- */
2321
- // async _paginateWith(data = {}, isNext = false, finalizer) {
2322
- // if (!this.serverData.slug) throw new ApiError("slug de l'entité non défini");
2323
- // if (!this.serverData.id) throw new ApiError("id de l'entité non défini");
2324
-
2325
- // const hasStep = (d) => d?.indexStep && d.indexStep > 0;
2326
-
2327
- // if (!this._paginationCursor || (!isNext && this._paginationHistory.length === 0)) {
2328
- // this._paginationCount = 0;
2329
- // this._paginationPageIndex = 0;
2330
- // this._paginationHistory = [];
2331
- // this._paginationPageSizes = [];
2332
- // data.countType = data.searchType;
2333
-
2334
- // if (!data?.searchBy && hasStep(data)) {
2335
- // data.ranges = this._generateRanges(data.searchType, data.indexStep);
2336
- // data.indexMin = data.indexMin ?? 0;
2337
- // data.indexMax = data.indexMax ?? data.indexStep;
2338
- // } else if (data?.searchBy === "ALL" && hasStep(data)) {
2339
- // data.indexMin = data.indexMin ?? 0;
2340
- // data.indexMax = data.indexMax ?? data.indexStep;
2341
- // }
2342
-
2343
- // this._paginationCursor = { ...data };
2344
- // }
2345
-
2346
- // const cursor = this._paginationCursor;
2347
-
2348
- // if (isNext) {
2349
- // this._paginationHistory.push({ ...cursor });
2350
-
2351
- // if (!cursor.searchBy && hasStep(cursor)) {
2352
- // cursor.ranges = this._generateRanges(cursor.searchType, cursor.indexStep, cursor.ranges);
2353
- // cursor.indexMin = cursor.indexMax ?? 0;
2354
- // cursor.indexMax = (cursor.indexMax ?? 0) + cursor.indexStep;
2355
- // } else if (cursor.searchBy === "ALL" && hasStep(cursor)) {
2356
- // cursor.indexMin = cursor.indexMax ?? 0;
2357
- // cursor.indexMax = (cursor.indexMax ?? 0) + cursor.indexStep;
2358
- // }
2359
-
2360
- // this._paginationCursor = { ...cursor };
2361
- // }
2362
-
2363
- // data = { ...this._paginationCursor };
2364
-
2365
- // if (!isNext && (!data?.searchType || !Array.isArray(data.searchType) || data.searchType.length === 0)) {
2366
- // throw new ApiError("searchType non défini");
2367
- // }
2368
-
2369
- // const result = await finalizer(data);
2370
- // if (!Array.isArray(result.results)) {
2371
- // throw new ApiResponseError("Erreur lors de la récupération des résultats", 500, result.results);
2372
- // }
2373
-
2374
- // this._paginationCount += result.results.length;
2375
- // this._paginationPageSizes.push(result.results.length);
2376
-
2377
- // if (isNext) {
2378
- // this._paginationPageIndex++;
2379
- // }
2380
-
2381
- // const count = this._normalizeCount(result.count);
2382
- // const rawList = this._linkEntities(result.results);
2383
- // const hasNext = hasStep(data) && this._paginationCount < count.total;
2384
- // const hasPrev = this._paginationHistory?.length > 0;
2385
-
2386
- // const response = {
2387
- // count,
2388
- // results: rawList,
2389
- // pageIndex: this._paginationPageIndex,
2390
- // pageNumber: this._paginationPageIndex + 1,
2391
- // hasNext,
2392
- // hasPrev
2393
- // };
2394
-
2395
- // if (hasNext) {
2396
- // response.next = async () => this._paginateWith({}, true, finalizer);
2397
- // }
2398
-
2399
- // if (this._paginationHistory?.length > 0) {
2400
- // response.prev = async () => {
2401
- // const previous = this._paginationHistory.pop();
2402
- // const lastPageSize = this._paginationPageSizes.pop() ?? 0;
2403
- // this._paginationCount -= lastPageSize;
2404
- // this._paginationPageIndex = Math.max(0, this._paginationPageIndex - 1);
2405
- // this._paginationCursor = { ...previous };
2406
- // return this._paginateWith({}, false, finalizer);
2407
- // };
2408
- // }
2409
-
2410
- // return response;
2411
- // }
2412
-
2413
-
2414
- /**
2415
- * Réinitialise l'état de pagination.
2416
- */
2417
- // resetPagination() {
2418
- // this._paginationCursor = undefined;
2419
- // this._paginationCount = 0;
2420
- // this._paginationPageIndex = 0;
2421
- // this._paginationHistory = [];
2422
- // this._paginationPageSizes = [];
2423
- // }
2424
-
2425
2329
 
2426
2330
  /**
2427
2331
  * Récupère une valeur par défaut depuis un endpoint donné.
@@ -2436,32 +2340,6 @@ export class BaseEntity {
2436
2340
  return endpoint.request.properties[path].default;
2437
2341
  }
2438
2342
 
2439
- /**
2440
- * recherche lié à l'entité.
2441
- *
2442
- * @param {Object} data - Les données de recherche.
2443
- * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
2444
- * @returns {Promise<Object>} - Résultat de la recherche.
2445
- * @throws {ApiError} - Si le slug ou l'id de entité n'est pas défini.
2446
- */
2447
- // async searchCostum(data = {}, isNext = false) {
2448
- // return this._paginateWith(data, isNext, async (finalData) => {
2449
- // finalData = {
2450
- // ...finalData,
2451
- // costumSlug: this.serverData.slug,
2452
- // contextId: this.serverData.id,
2453
- // contextType: this.getEntityType()
2454
- // };
2455
-
2456
- // if (finalData.sourceKey?.length) {
2457
- // finalData.sourceKey = [...finalData.sourceKey, this.serverData.slug];
2458
- // } else {
2459
- // finalData.sourceKey = [this.serverData.slug];
2460
- // }
2461
-
2462
- // return this.endpointApi.globalAutocompleteCostum(finalData);
2463
- // });
2464
- // }
2465
2343
 
2466
2344
  /**
2467
2345
  * Recherche liée à l'entité, version stateless.
@@ -0,0 +1,66 @@
1
+ export const EntityRegistry = new Map();
2
+
3
+ /**
4
+ * Enregistre une entité dans la registry.
5
+ * @param {string} tag - ex: "User", "Organization"
6
+ * @param {Function} EntityClass - la classe constructeur
7
+ */
8
+ export function registerEntity(tag, EntityClass) {
9
+ EntityRegistry.set(tag, EntityClass);
10
+ }
11
+
12
+ /**
13
+ * Récupère une instance depuis un JSON générique.
14
+ * @param {Object} json - doit contenir __entityTag
15
+ * @param {Object} parent - ApiClient ou entité parent
16
+ * @param {Object} deps - dépendances (comme dans le constructeur)
17
+ * @returns {BaseEntity|null}
18
+ */
19
+ export function fromEntityJSON(json, parent = null) {
20
+ if (!json?.__entityTag) return null;
21
+ if (!json.serverData?.collection) return json;
22
+ const meta = _getEntityMeta(json.serverData.collection, json.__entityTag);
23
+ if (!meta) return json;
24
+ if (!meta?.entityClass?.fromJSON) throw new Error(`Classe inconnue ou fromJSON manquant pour ${json.__entityTag}`);
25
+ return meta.entityClass.fromJSON(json, parent, meta.deps);
26
+ }
27
+
28
+ /**
29
+ * Récupère la classe d'entité et ses dépendances à partir du type d'entité.
30
+ *
31
+ * @param {string} entityType - Le type d'entité.
32
+ * @param {string} __entityTag - Le tag de l'entité.
33
+ * @returns {Object|null} - Un objet contenant la classe d'entité et ses dépendances, ou null si le type d'entité n'est pas trouvé.
34
+ */
35
+ function _getEntityMeta(entityType, __entityTag) {
36
+ const selfClass = EntityRegistry.get(__entityTag);
37
+ const selfTag = __entityTag;
38
+
39
+ const commonDeps = {
40
+ EndpointApi: EntityRegistry.get("EndpointApi"),
41
+ User: selfTag === "User" ? selfClass : EntityRegistry.get("User"),
42
+ Organization: selfTag === "Organization" ? selfClass : EntityRegistry.get("Organization"),
43
+ Project: selfTag === "Project" ? selfClass : EntityRegistry.get("Project"),
44
+ Event: selfTag === "Event" ? selfClass : EntityRegistry.get("Event"),
45
+ Poi: selfTag === "Poi" ? selfClass : EntityRegistry.get("Poi"),
46
+ Badge: selfTag === "Badge" ? selfClass : EntityRegistry.get("Badge"),
47
+ News: selfTag === "News" ? selfClass : EntityRegistry.get("News")
48
+ };
49
+
50
+ const map = {
51
+ citoyens: { entityClass: commonDeps.User, deps: commonDeps },
52
+ organizations:{ entityClass: commonDeps.Organization, deps: commonDeps },
53
+ projects: { entityClass: commonDeps.Project, deps: commonDeps },
54
+ events: { entityClass: commonDeps.Event, deps: { ...commonDeps, Badge: undefined } },
55
+ poi: { entityClass: commonDeps.Poi, deps: { ...commonDeps, Badge: undefined, News: undefined } },
56
+ news: { entityClass: commonDeps.News, deps: { ...commonDeps } },
57
+ badges: { entityClass: commonDeps.Badge, deps: {
58
+ EndpointApi: commonDeps.EndpointApi,
59
+ User: commonDeps.User,
60
+ Organization: commonDeps.Organization,
61
+ Project: commonDeps.Project
62
+ } }
63
+ };
64
+
65
+ return map[entityType] || null;
66
+ }
@@ -183,29 +183,7 @@ export class Organization extends BaseEntity {
183
183
  async getMembers(data = {}, options = {}) {
184
184
  data.searchType = this._getDefaultFromEndpoint("GET_MEMBERS_ADMIN", "searchType");
185
185
  // data.searchBy = "ALL";
186
- // return this._paginateWith(data, isNext, async (finalData) => {
187
-
188
- // const { toBeValidated, isAdmin, isAdminPending, isInviting, roles = [] } = options;
189
-
190
- // if(this.isMe){
191
- // finalData.pathParams = { type: this.getEntityType(), id: this.id };
192
- // // finalData.filters = {
193
- // // [`links.memberOf.${this.id}`]: { "$exists": true },
194
- // // [`links.memberOf.${this.id}.toBeValidated`]: { "$exists": false },
195
- // // [`links.memberOf.${this.id}.isInviting`]: { "$exists": false }
196
- // // };
197
- // finalData.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
198
- // } else {
199
- // delete finalData?.pathParams;
200
- // finalData.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated: false, isAdmin, isInviting, roles });
201
- // }
202
-
203
- // const fetchFn = this.isMe
204
- // ? () => this.callIsMe(() => this.endpointApi.getMembersAdmin(finalData))
205
- // : () => this.endpointApi.getMembersNoAdmin(finalData);
206
186
 
207
- // return fetchFn();
208
- // });
209
187
  const paginator = this._createPaginatorEngine({
210
188
  initialData: data,
211
189
  finalizer: async (finalData) => {
@@ -193,30 +193,7 @@ export class Project extends BaseEntity {
193
193
  async getContributors(data = {}, options = {}) {
194
194
  data.searchType = this._getDefaultFromEndpoint("GET_CONTRIBUTORS_ADMIN", "searchType");
195
195
  // data.searchBy = "ALL";
196
- // return this._paginateWith(data, isNext, async (finalData) => {
197
-
198
- // const { toBeValidated, isAdmin, isInviting, isAdminPending, roles = [] } = options;
199
-
200
- // if(this.isMe){
201
- // finalData.pathParams = { type: this.getEntityType(), id: this.id };
202
- // // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
203
- // // finalData.filters = {
204
- // // [`links.projects.${this.id}`]: { "$exists": true },
205
- // // [`links.projects.${this.id}.toBeValidated`]: { "$exists": false },
206
- // // [`links.projects.${this.id}.isInviting`]: { "$exists": false }
207
- // // };
208
- // finalData.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
209
- // } else {
210
- // delete finalData?.pathParams;
211
- // finalData.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated: false, isAdmin, isInviting, roles });
212
- // }
213
-
214
- // const fetchFn = this.isMe
215
- // ? () => this.callIsMe(() => this.endpointApi.getContributorsAdmin(finalData))
216
- // : () => this.endpointApi.getContributorsNoAdmin(finalData);
217
196
 
218
- // return fetchFn();
219
- // });
220
197
  const paginator = this._createPaginatorEngine({
221
198
  initialData: data,
222
199
  finalizer: async (finalData) => {
package/src/api/User.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiError, ApiResponseError } from "../error.js";
1
+ import { ApiError } from "../error.js";
2
2
  import BaseEntity from "./BaseEntity.js";
3
3
  import { UserMixin } from "../mixin/UserMixin.js";
4
4
 
@@ -287,23 +287,7 @@ export class User extends BaseEntity {
287
287
  async getOrganizations(data = {}) {
288
288
  data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType");
289
289
  // data.searchBy = "ALL";
290
- // return this._paginateWith(data, isNext, async (finalData) => {
291
- // delete finalData?.pathParams;
292
290
 
293
- // const fetchFn = this.isMe
294
- // ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(finalData))
295
- // : () => this.endpointApi.getOrganizationsNoAdmin(finalData);
296
-
297
- // if (!this.isMe && !finalData.filters) {
298
- // finalData.filters = {
299
- // [`links.members.${this.id}`]: { "$exists": true },
300
- // [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
301
- // [`links.members.${this.id}.isInviting`]: { "$exists": false }
302
- // };
303
- // }
304
-
305
- // return fetchFn();
306
- // });
307
291
  const paginator = this._createPaginatorEngine({
308
292
  initialData: data,
309
293
  finalizer: async (finalData) => {
@@ -359,25 +343,25 @@ export class User extends BaseEntity {
359
343
  * actuellement, c'est tous les utilisateurs connectés
360
344
  */
361
345
  async getFriends(data = {}) {
362
- delete data?.pathParams;
363
-
364
- if (!this.isMe){
365
- // is not me add id
366
- data.pathParams = { id: this.id };
367
- }
346
+ data.searchType = this._getDefaultFromEndpoint("GET_FRIENDS_ADMIN", "searchType");
347
+ // data.searchBy = "ALL";
368
348
 
369
- const arrayObjet = await this.endpointApi.getFriendsAdmin(data);
370
- if (!Array.isArray(arrayObjet.results)){
371
- throw new ApiResponseError("Erreur lors de la récupération des amis administrables.", 500, arrayObjet);
349
+ const paginator = this._createPaginatorEngine({
350
+ initialData: data,
351
+ finalizer: async (finalData) => {
372
352
 
373
- }
353
+ delete finalData?.pathParams;
354
+
355
+ if (!this.isMe){
356
+ // is not me add id
357
+ finalData.pathParams = { id: this.id };
358
+ }
374
359
 
375
- const rawList = this._linkEntities(arrayObjet.results);
360
+ return this.endpointApi.getFriendsAdmin(finalData);;
361
+ }
362
+ });
376
363
 
377
- return {
378
- count: arrayObjet?.count?.citoyens ?? 0,
379
- results: rawList
380
- };
364
+ return paginator.next();
381
365
  }
382
366
 
383
367
  /**
@@ -387,22 +371,7 @@ export class User extends BaseEntity {
387
371
  async getSubscriptions(data = {}) {
388
372
  data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIPTIONS", "searchType");
389
373
  // data.searchBy = "ALL";
390
- // return this._paginateWith(data, isNext, async (finalData) => {
391
374
 
392
- // delete finalData?.pathParams;
393
-
394
- // const fetchFn = this.isMe
395
- // ? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(finalData))
396
- // : () => this.endpointApi.getSubscriptions(finalData);
397
-
398
- // if (!this.isMe && !finalData.filters) {
399
- // finalData.filters = {
400
- // [`links.followers.${this.id}`]: { "$exists": true },
401
- // };
402
- // }
403
-
404
- // return fetchFn();
405
- // });
406
375
  const paginator = this._createPaginatorEngine({
407
376
  initialData: data,
408
377
  finalizer: async (finalData) => {
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { fromEntityJSON } from "./api/EntityRegistry.js";
1
2
  import Api from "./Api.js";
2
3
  import ApiClient from "./ApiClient.js";
3
4
  import * as error from "./error.js";
@@ -25,6 +26,9 @@ export default {
25
26
  createDefaultMultiServerTokenStorageStrategy,
26
27
  MultiServerTokenStorageStrategy
27
28
  },
29
+ helper: {
30
+ fromEntityJSON
31
+ },
28
32
 
29
33
  OfflineClientManager
30
34
  };