@communecter/cocolight-api-client 1.0.46 → 1.0.48
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/dist/cocolight-api-client.browser.js +2 -2
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js.map +1 -1
- package/package.json +1 -1
- package/src/ApiClient.js +4 -2
- package/src/api/BaseEntity.js +69 -0
- package/src/api/EndpointApi.js +15 -0
- package/src/api/EndpointApi.types.d.ts +38 -10
- package/src/api/Event.js +51 -10
- package/src/api/Organization.js +12 -0
- package/src/api/Project.js +12 -0
- package/src/api/User.js +8 -0
- package/src/endpoints.module.js +2 -2
package/package.json
CHANGED
package/src/ApiClient.js
CHANGED
|
@@ -1074,7 +1074,7 @@ export default class ApiClient extends EventEmitter {
|
|
|
1074
1074
|
data.results = Object.keys(data.results).map((key) => {
|
|
1075
1075
|
return this._normalizeJsonData({ id: key, ...data.results[key] });
|
|
1076
1076
|
});
|
|
1077
|
-
} else if (Array.isArray(data.results)) {
|
|
1077
|
+
} else if (Array.isArray(data.results) && data.results.length > 0) {
|
|
1078
1078
|
data.results = data.results.map((item) => this._normalizeJsonData(item));
|
|
1079
1079
|
} else if (data.news && Array.isArray(data.news) && data.news.length === 0) {
|
|
1080
1080
|
data = data.news;
|
|
@@ -1441,7 +1441,9 @@ export default class ApiClient extends EventEmitter {
|
|
|
1441
1441
|
"profilRealBannerUrl",
|
|
1442
1442
|
"imagePath",
|
|
1443
1443
|
"imageThumbPath",
|
|
1444
|
-
"docPath"
|
|
1444
|
+
"docPath",
|
|
1445
|
+
"imageThumb",
|
|
1446
|
+
"imageMediumPath"
|
|
1445
1447
|
];
|
|
1446
1448
|
|
|
1447
1449
|
/**
|
package/src/api/BaseEntity.js
CHANGED
|
@@ -1080,6 +1080,57 @@ export class BaseEntity {
|
|
|
1080
1080
|
return Object.keys(changed).length > 0 ? changed : null;
|
|
1081
1081
|
}
|
|
1082
1082
|
|
|
1083
|
+
/**
|
|
1084
|
+
* Extrait tous les champs valides selon le schéma, et retourne uniquement ceux qui ont changé par rapport au draft initial.
|
|
1085
|
+
* Contrairement à `_extractChangedFieldsFromSchema`, cette méthode retourne l'ensemble des champs valides (`updated`)
|
|
1086
|
+
* uniquement s'il y a au moins un champ modifié (`changed`).
|
|
1087
|
+
*
|
|
1088
|
+
* ⚠️ Les champs sont filtrés en fonction :
|
|
1089
|
+
* - des champs définis comme modifiables dans le schéma (`writeable`)
|
|
1090
|
+
* - des champs non exclus dans `removeFields`
|
|
1091
|
+
* - des champs définis dans `data` (les `undefined` sont ignorés)
|
|
1092
|
+
*
|
|
1093
|
+
* @param {ApiClient} apiClient - L’instance de client API contenant les schémas.
|
|
1094
|
+
* @param {string} constant - Le nom de la constante de schéma (ex: "ADD_EVENT").
|
|
1095
|
+
* @param {Object} data - Les nouvelles données à comparer avec le draft initial.
|
|
1096
|
+
* @param {() => Object} getInitialDraft - Fonction qui retourne le draft initial (souvent `this.initialDraftData`).
|
|
1097
|
+
* @param {string[]} [removeFields=[]] - Champs à ignorer même s’ils sont valides.
|
|
1098
|
+
* @returns {Object|null} - Un objet `updated` avec les champs valides si au moins un champ a changé, sinon `null`.
|
|
1099
|
+
* @private
|
|
1100
|
+
*/
|
|
1101
|
+
_extractAllValidFieldsFromSchema(apiClient, constant, data = {}, getInitialDraft, removeFields = []) {
|
|
1102
|
+
const schema = apiClient.getRequestSchema(constant);
|
|
1103
|
+
let allowed = this._extractWritableFields(schema, data);
|
|
1104
|
+
const changed = {};
|
|
1105
|
+
const updated = {};
|
|
1106
|
+
const initialDraft = getInitialDraft?.() || {};
|
|
1107
|
+
|
|
1108
|
+
// on enlève les champs qui ne sont pas dans le draft
|
|
1109
|
+
// ou qui sont dans removeFields
|
|
1110
|
+
allowed = allowed.filter(k => !removeFields.includes(k));
|
|
1111
|
+
|
|
1112
|
+
for (const key of allowed) {
|
|
1113
|
+
// on verifie que le champ existe dans le draft
|
|
1114
|
+
// sinon on ne le prend pas en compte
|
|
1115
|
+
|
|
1116
|
+
if (data[key] === undefined) continue;
|
|
1117
|
+
|
|
1118
|
+
const current = data[key];
|
|
1119
|
+
const initial = initialDraft[key];
|
|
1120
|
+
|
|
1121
|
+
const changedValue =
|
|
1122
|
+
JSON.stringify(current) !== JSON.stringify(initial);
|
|
1123
|
+
|
|
1124
|
+
if (changedValue) {
|
|
1125
|
+
changed[key] = current;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
updated[key] = current;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
return Object.keys(changed).length > 0 ? updated : null;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1083
1134
|
/**
|
|
1084
1135
|
* ───────────────────────────────
|
|
1085
1136
|
* MutualEntityMixin
|
|
@@ -2120,6 +2171,24 @@ export class BaseEntity {
|
|
|
2120
2171
|
return this._createFilteredProxy(rawList);
|
|
2121
2172
|
}
|
|
2122
2173
|
|
|
2174
|
+
/**
|
|
2175
|
+
* Récupérer la galerie d'une entité.
|
|
2176
|
+
* Constant : GET_GALLERY
|
|
2177
|
+
* @param {Object} data - Les données à envoyer.
|
|
2178
|
+
* @param {string} data.pathParams.docType - Type de document (default: "image")
|
|
2179
|
+
* @param {string} data.contentKey - Clé de contenu pour la galerie (default: "null")
|
|
2180
|
+
* @param {string} data.folderId - ID du dossier pour la galerie (default: "null")
|
|
2181
|
+
* @returns {Promise<Object>} - Les données de réponse.
|
|
2182
|
+
* @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
|
|
2183
|
+
* @throws {Error} - En cas d'erreur inattendue.
|
|
2184
|
+
*/
|
|
2185
|
+
async getGallery(data = {}) {
|
|
2186
|
+
data.pathParams = { type: this.getEntityType(), id: this.id, docType: data.pathParams?.docType || "image" };
|
|
2187
|
+
const arrayObjet = await this.endpointApi.getGallery(data);
|
|
2188
|
+
|
|
2189
|
+
return arrayObjet;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2123
2192
|
/**
|
|
2124
2193
|
* Soumet une demande pour rejoindre l'entité courante (ex. organisation, projet, événement...).
|
|
2125
2194
|
* Si une invitation est en attente, elle est automatiquement acceptée.
|
package/src/api/EndpointApi.js
CHANGED
|
@@ -1513,6 +1513,21 @@ class EndpointApi {
|
|
|
1513
1513
|
return this.call("COSTUM_EVENT_REQUEST_LOAD_CONTEXT_TAG", data);
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
|
+
/**
|
|
1517
|
+
* Récupération de la galerie : Renvoie soit la liste d’albums associés à une entité, soit les images d’un album spécifique.
|
|
1518
|
+
* Constant : GET_GALLERY
|
|
1519
|
+
* @param {import("./EndpointApi.types").GetGalleryData} data - Données envoyées à l'API
|
|
1520
|
+
* @returns {Promise<Object>} - Les données de réponse.
|
|
1521
|
+
* @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
|
|
1522
|
+
* @throws {Error} - En cas d'erreur inattendue.
|
|
1523
|
+
*/
|
|
1524
|
+
async getGallery(data) {
|
|
1525
|
+
if (!data || typeof data !== "object") {
|
|
1526
|
+
throw new TypeError("Le paramètre data doit être un objet.");
|
|
1527
|
+
}
|
|
1528
|
+
return this.call("GET_GALLERY", data);
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1516
1531
|
}
|
|
1517
1532
|
|
|
1518
1533
|
export default EndpointApi;
|
|
@@ -131,9 +131,9 @@ export interface UpdateSettingsData {
|
|
|
131
131
|
type: string;
|
|
132
132
|
value: unknown;
|
|
133
133
|
/**
|
|
134
|
-
* Type d'élément (citoyens, projects, organizations)
|
|
134
|
+
* Type d'élément (citoyens, projects, organizations, events)
|
|
135
135
|
*/
|
|
136
|
-
typeEntity: "citoyens" | "projects" | "organizations";
|
|
136
|
+
typeEntity: "citoyens" | "projects" | "organizations" | "events";
|
|
137
137
|
/**
|
|
138
138
|
* Id de l'élément
|
|
139
139
|
*/
|
|
@@ -148,9 +148,9 @@ export interface UpdateBlockDescriptionData {
|
|
|
148
148
|
*/
|
|
149
149
|
block: "descriptions";
|
|
150
150
|
/**
|
|
151
|
-
* Type d'élément (citoyens, projects, organizations, poi)
|
|
151
|
+
* Type d'élément (citoyens, projects, organizations, poi, events)
|
|
152
152
|
*/
|
|
153
|
-
typeElement: "citoyens" | "projects" | "organizations" | "poi";
|
|
153
|
+
typeElement: "citoyens" | "projects" | "organizations" | "poi" | "events";
|
|
154
154
|
/**
|
|
155
155
|
* ID de l'élément concerné
|
|
156
156
|
*/
|
|
@@ -181,9 +181,9 @@ export interface UpdateBlockInfoData {
|
|
|
181
181
|
*/
|
|
182
182
|
block: "info";
|
|
183
183
|
/**
|
|
184
|
-
* Type d'élément (citoyens, projects, organizations, poi)
|
|
184
|
+
* Type d'élément (citoyens, projects, organizations, poi, events)
|
|
185
185
|
*/
|
|
186
|
-
typeElement: "citoyens" | "projects" | "organizations" | "poi";
|
|
186
|
+
typeElement: "citoyens" | "projects" | "organizations" | "poi" | "events";
|
|
187
187
|
/**
|
|
188
188
|
* ID de l'élément concerné
|
|
189
189
|
*/
|
|
@@ -274,7 +274,7 @@ export interface UpdateBlockLocalityData {
|
|
|
274
274
|
/**
|
|
275
275
|
* Type d'élément
|
|
276
276
|
*/
|
|
277
|
-
typeElement: "citoyens" | "projects" | "organizations" | "poi";
|
|
277
|
+
typeElement: "citoyens" | "projects" | "organizations" | "poi" | "events";
|
|
278
278
|
/**
|
|
279
279
|
* ID de l'élément concerné
|
|
280
280
|
*/
|
|
@@ -349,9 +349,9 @@ export interface UpdateBlockSlugData {
|
|
|
349
349
|
*/
|
|
350
350
|
block: "info";
|
|
351
351
|
/**
|
|
352
|
-
* Type d'élément (citoyens, projects, organizations, poi)
|
|
352
|
+
* Type d'élément (citoyens, projects, organizations, poi, events)
|
|
353
353
|
*/
|
|
354
|
-
typeElement: "citoyens" | "projects" | "organizations" | "poi";
|
|
354
|
+
typeElement: "citoyens" | "projects" | "organizations" | "poi" | "events";
|
|
355
355
|
/**
|
|
356
356
|
* ID de l'élément concerné
|
|
357
357
|
*/
|
|
@@ -377,7 +377,7 @@ export interface CheckData {
|
|
|
377
377
|
/**
|
|
378
378
|
* Type d'élément
|
|
379
379
|
*/
|
|
380
|
-
type: "citoyens" | "projects" | "organizations";
|
|
380
|
+
type: "citoyens" | "projects" | "organizations" | "events";
|
|
381
381
|
/**
|
|
382
382
|
* Slug à vérifier
|
|
383
383
|
*/
|
|
@@ -4412,3 +4412,31 @@ export interface CostumEventRequestLoadContextTagData {
|
|
|
4412
4412
|
};
|
|
4413
4413
|
[k: string]: unknown;
|
|
4414
4414
|
}
|
|
4415
|
+
|
|
4416
|
+
|
|
4417
|
+
export interface GetGalleryData {
|
|
4418
|
+
/**
|
|
4419
|
+
* Clé de contenu pour correspondre à l'album ou aux images
|
|
4420
|
+
*/
|
|
4421
|
+
contentKey?: string;
|
|
4422
|
+
/**
|
|
4423
|
+
* ID du dossier à récupérer (pour les images d'un album)
|
|
4424
|
+
*/
|
|
4425
|
+
folderId?: string;
|
|
4426
|
+
pathParams?: {
|
|
4427
|
+
/**
|
|
4428
|
+
* ID de l'entité
|
|
4429
|
+
*/
|
|
4430
|
+
id: string;
|
|
4431
|
+
/**
|
|
4432
|
+
* Type d'entité
|
|
4433
|
+
*/
|
|
4434
|
+
type: "citoyens" | "organizations" | "projects";
|
|
4435
|
+
/**
|
|
4436
|
+
* Type de document
|
|
4437
|
+
*/
|
|
4438
|
+
docType: "image" | "file" | "bookmarks";
|
|
4439
|
+
[k: string]: unknown;
|
|
4440
|
+
};
|
|
4441
|
+
[k: string]: unknown;
|
|
4442
|
+
}
|
package/src/api/Event.js
CHANGED
|
@@ -12,31 +12,59 @@ export class Event extends BaseEntity {
|
|
|
12
12
|
// "UPDATE_BLOCK_INFO",
|
|
13
13
|
// "UPDATE_BLOCK_SOCIAL",
|
|
14
14
|
// "UPDATE_BLOCK_LOCALITY",
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
"UPDATE_BLOCK_SLUG",
|
|
16
|
+
"PROFIL_IMAGE"
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
static ADD_BLOCKS = new Map([
|
|
20
|
-
["ADD_EVENT", "addEvent"]
|
|
20
|
+
["ADD_EVENT", "addEvent"],
|
|
21
|
+
["PROFIL_IMAGE", "updateImageProfil"]
|
|
21
22
|
]);
|
|
22
23
|
|
|
23
24
|
static UPDATE_BLOCKS = new Map([
|
|
24
25
|
// ["UPDATE_BLOCK_DESCRIPTION", "updateDescription"],
|
|
25
|
-
// ["UPDATE_BLOCK_INFO", "updateInfo"],
|
|
26
26
|
// ["UPDATE_BLOCK_SOCIAL", "updateSocial"],
|
|
27
27
|
// ["UPDATE_BLOCK_LOCALITY", "updateLocality"],
|
|
28
|
-
// ["
|
|
29
|
-
|
|
28
|
+
// ["UPDATE_BLOCK_INFO", "updateInfo"],
|
|
29
|
+
["UPDATE_BLOCK_SLUG", "updateSlug"],
|
|
30
|
+
["PROFIL_IMAGE", "updateImageProfil"]
|
|
30
31
|
]);
|
|
31
32
|
|
|
32
33
|
defaultFields = {
|
|
33
|
-
|
|
34
|
+
typeElement: this.getEntityType()
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
removeFields = [
|
|
37
|
+
removeFields = [
|
|
38
|
+
"typeElement"
|
|
39
|
+
];
|
|
37
40
|
|
|
38
41
|
transforms = {
|
|
39
|
-
|
|
42
|
+
parent: (val) => {
|
|
43
|
+
if (!val || typeof val !== "object") return null;
|
|
44
|
+
|
|
45
|
+
return Object.fromEntries(
|
|
46
|
+
Object.entries(val).map(([key, obj]) => [
|
|
47
|
+
key,
|
|
48
|
+
{
|
|
49
|
+
type: obj?.type ?? null,
|
|
50
|
+
name: obj?.name ?? null
|
|
51
|
+
}
|
|
52
|
+
])
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
organizer: (val) => {
|
|
56
|
+
if (!val || typeof val !== "object") return null;
|
|
57
|
+
|
|
58
|
+
return Object.fromEntries(
|
|
59
|
+
Object.entries(val).map(([key, obj]) => [
|
|
60
|
+
key,
|
|
61
|
+
{
|
|
62
|
+
type: obj?.type ?? null,
|
|
63
|
+
name: obj?.name ?? null
|
|
64
|
+
}
|
|
65
|
+
])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
40
68
|
};
|
|
41
69
|
|
|
42
70
|
async _add(payload) {
|
|
@@ -73,9 +101,22 @@ export class Event extends BaseEntity {
|
|
|
73
101
|
throw new ApiError("utilisation invalide de _update, utilisez save");
|
|
74
102
|
}
|
|
75
103
|
|
|
76
|
-
if (payload.id) delete payload.id;
|
|
77
104
|
let hasChanged = false;
|
|
78
105
|
|
|
106
|
+
const blockData = this._extractAllValidFieldsFromSchema(
|
|
107
|
+
this.apiClient,
|
|
108
|
+
"ADD_EVENT",
|
|
109
|
+
{ ...payload, ...this.defaultFields },
|
|
110
|
+
() => this.initialDraftData,
|
|
111
|
+
this.removeFields
|
|
112
|
+
);
|
|
113
|
+
if (blockData && Object.keys(blockData).length > 0) {
|
|
114
|
+
await this["addEvent"](blockData);
|
|
115
|
+
hasChanged = true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (payload.id) delete payload.id;
|
|
119
|
+
|
|
79
120
|
for (const [constant, methodName] of Event.UPDATE_BLOCKS) {
|
|
80
121
|
const blockData = this._extractChangedFieldsFromSchema(
|
|
81
122
|
this.apiClient,
|
package/src/api/Organization.js
CHANGED
|
@@ -214,6 +214,18 @@ export class Organization extends BaseEntity {
|
|
|
214
214
|
return paginator.next();
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Récupère la galerie de l'organisation.
|
|
219
|
+
*
|
|
220
|
+
* @param {Object} data - Les données de requête.
|
|
221
|
+
* @returns {Promise<Object>} - Un objet contenant les éléments de la galerie.
|
|
222
|
+
* @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
|
|
223
|
+
* @throws {Error} - En cas d'erreur inattendue.
|
|
224
|
+
*/
|
|
225
|
+
async getGallery(data = {}) {
|
|
226
|
+
return super.getGallery(data);
|
|
227
|
+
}
|
|
228
|
+
|
|
217
229
|
/**
|
|
218
230
|
* Crée une instance de projet et récupère son profil si nécessaire.
|
|
219
231
|
*
|
package/src/api/Project.js
CHANGED
|
@@ -225,6 +225,18 @@ export class Project extends BaseEntity {
|
|
|
225
225
|
return paginator.next();
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Récupère la galerie d'un projet.
|
|
230
|
+
*
|
|
231
|
+
* @param {Object} data - Les données de requête pour la galerie.
|
|
232
|
+
* @returns {Promise<Object>} - Un objet contenant les images de la galerie.
|
|
233
|
+
* @throws {ApiResponseError} - Si une erreur se produit lors de la récupération de la galerie.
|
|
234
|
+
* @throws {Error} - En cas d'erreur inattendue.
|
|
235
|
+
*/
|
|
236
|
+
async getGallery(data = {}) {
|
|
237
|
+
return super.getGallery(data);
|
|
238
|
+
}
|
|
239
|
+
|
|
228
240
|
/**
|
|
229
241
|
* Crée une instance de projet et récupère son profil si nécessaire.
|
|
230
242
|
*
|
package/src/api/User.js
CHANGED
|
@@ -441,6 +441,14 @@ export class User extends BaseEntity {
|
|
|
441
441
|
return filteredBadges;
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Récupérer la galerie de l'utilisateur
|
|
446
|
+
* Constant : GET_GALLERY
|
|
447
|
+
*/
|
|
448
|
+
async getGallery(data = {}) {
|
|
449
|
+
return super.getGallery(data);
|
|
450
|
+
}
|
|
451
|
+
|
|
444
452
|
async user(userData) {
|
|
445
453
|
if(!this.isMe){
|
|
446
454
|
throw new ApiError("Vous devez être connecté et être l'utilisateur");
|