@communecter/cocolight-api-client 1.0.54 → 1.0.56
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/401.cocolight-api-client.browser.js +1 -0
- package/dist/401.cocolight-api-client.cjs +1 -0
- package/dist/401.cocolight-api-client.mjs.js +1 -0
- package/dist/588.cocolight-api-client.browser.js +1 -0
- package/dist/588.cocolight-api-client.cjs +1 -0
- package/dist/588.cocolight-api-client.mjs.js +1 -0
- package/dist/593.cocolight-api-client.browser.js +1 -0
- package/dist/593.cocolight-api-client.cjs +1 -0
- package/dist/593.cocolight-api-client.mjs.js +1 -0
- package/dist/839.cocolight-api-client.browser.js +1 -0
- package/dist/839.cocolight-api-client.cjs +1 -0
- package/dist/839.cocolight-api-client.mjs.js +1 -0
- package/dist/cocolight-api-client.browser.js +3 -3
- 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 +29 -17
- package/src/{Api.js → Api.ts} +85 -95
- package/src/{ApiClient.js → ApiClient.ts} +436 -247
- package/src/EJSONType.ts +103 -0
- package/src/api/{Badge.js → Badge.ts} +56 -45
- package/src/api/BaseEntity.ts +3890 -0
- package/src/api/Comment.ts +200 -0
- package/src/api/{EndpointApi.js → EndpointApi.ts} +363 -297
- package/src/api/EndpointApi.types.ts +4609 -0
- package/src/api/EntityRegistry.ts +203 -0
- package/src/api/Event.ts +332 -0
- package/src/api/News.ts +331 -0
- package/src/api/{Organization.js → Organization.ts} +155 -119
- package/src/api/{Poi.js → Poi.ts} +68 -60
- package/src/api/{Project.js → Project.ts} +150 -127
- package/src/api/{User.js → User.ts} +321 -256
- package/src/api/UserApi.ts +148 -0
- package/src/api/serverDataType/Comment.ts +88 -0
- package/src/api/serverDataType/Event.ts +80 -0
- package/src/api/serverDataType/News.ts +138 -0
- package/src/api/serverDataType/Organization.ts +80 -0
- package/src/api/serverDataType/Project.ts +71 -0
- package/src/api/serverDataType/User.ts +103 -0
- package/src/api/serverDataType/common.ts +80 -0
- package/src/endpoints.module.ts +2621 -0
- package/src/error.ts +86 -0
- package/src/index.ts +86 -0
- package/src/mixin/UserMixin.ts +4 -0
- package/src/types/api-responses.ts +217 -0
- package/src/types/entities.ts +22 -0
- package/src/types/error-guards.ts +230 -0
- package/src/types/index.ts +39 -0
- package/src/types/payloads.ts +21 -0
- package/src/types/transforms.ts +110 -0
- package/src/utils/{FileOfflineStorageStrategy.node.js → FileOfflineStorageStrategy.node.ts} +15 -12
- package/src/utils/{FileStorageStrategy.node.js → FileStorageStrategy.node.ts} +16 -39
- package/src/utils/MultiServerFileStorageStrategy.node.ts +67 -0
- package/src/utils/MultiServerTokenStorageStrategy.ts +139 -0
- package/src/utils/{OfflineClientManager.js → OfflineClientManager.ts} +82 -86
- package/src/utils/OfflineQueueStorageStrategy.ts +47 -0
- package/src/utils/TokenStorage.ts +77 -0
- package/src/utils/compat.ts +12 -0
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.ts +35 -0
- package/src/utils/{createDefaultOfflineStrategy.js → createDefaultOfflineStrategy.ts} +8 -3
- package/src/utils/createDefaultTokenStorageStrategy.ts +33 -0
- package/src/utils/{reactive.js → reactive.ts} +49 -40
- package/src/utils/stream-utils.node.ts +12 -0
- package/types/Api.d.ts +38 -82
- package/types/Api.d.ts.map +1 -0
- package/types/ApiClient.d.ts +244 -184
- package/types/ApiClient.d.ts.map +1 -0
- package/types/EJSONType.d.ts +48 -22
- package/types/EJSONType.d.ts.map +1 -0
- package/types/api/Badge.d.ts +20 -20
- package/types/api/Badge.d.ts.map +1 -0
- package/types/api/BaseEntity.d.ts +751 -446
- package/types/api/BaseEntity.d.ts.map +1 -0
- package/types/api/Comment.d.ts +36 -0
- package/types/api/EndpointApi.d.ts +347 -295
- package/types/api/EndpointApi.d.ts.map +1 -0
- package/types/api/EndpointApi.types.d.ts +3914 -4133
- package/types/api/EntityRegistry.d.ts +18 -16
- package/types/api/EntityRegistry.d.ts.map +1 -0
- package/types/api/Event.d.ts +119 -35
- package/types/api/Event.d.ts.map +1 -0
- package/types/api/News.d.ts +52 -20
- package/types/api/News.d.ts.map +1 -0
- package/types/api/Organization.d.ts +165 -49
- package/types/api/Organization.d.ts.map +1 -0
- package/types/api/Poi.d.ts +51 -22
- package/types/api/Poi.d.ts.map +1 -0
- package/types/api/Project.d.ts +151 -52
- package/types/api/Project.d.ts.map +1 -0
- package/types/api/User.d.ts +222 -93
- package/types/api/User.d.ts.map +1 -0
- package/types/api/UserApi.d.ts +60 -9
- package/types/api/UserApi.d.ts.map +1 -0
- package/types/api/serverDataType/Comment.d.ts +83 -0
- package/types/api/serverDataType/Event.d.ts +67 -0
- package/types/api/serverDataType/News.d.ts +130 -0
- package/types/api/serverDataType/Organization.d.ts +65 -0
- package/types/api/serverDataType/Organization.d.ts.map +1 -0
- package/types/api/serverDataType/Project.d.ts +58 -0
- package/types/api/serverDataType/Project.d.ts.map +1 -0
- package/types/api/serverDataType/User.d.ts +86 -0
- package/types/api/serverDataType/User.d.ts.map +1 -0
- package/types/api/serverDataType/common.d.ts +71 -0
- package/types/api/serverDataType/common.d.ts.map +1 -0
- package/types/endpoints.module.d.ts +6922 -1215
- package/types/endpoints.module.d.ts.map +1 -0
- package/types/error.d.ts +25 -51
- package/types/error.d.ts.map +1 -0
- package/types/index.d.ts +55 -48
- package/types/index.d.ts.map +1 -0
- package/types/mixin/UserMixin.d.ts +1 -1
- package/types/mixin/UserMixin.d.ts.map +1 -0
- package/types/types/api-responses.d.ts +190 -0
- package/types/types/api-responses.d.ts.map +1 -0
- package/types/types/entities.d.ts +17 -0
- package/types/types/entities.d.ts.map +1 -0
- package/types/types/error-guards.d.ts +99 -0
- package/types/types/error-guards.d.ts.map +1 -0
- package/types/types/index.d.ts +7 -0
- package/types/types/payloads.d.ts +17 -0
- package/types/types/payloads.d.ts.map +1 -0
- package/types/types/transforms.d.ts +79 -0
- package/types/types/transforms.d.ts.map +1 -0
- package/types/utils/FileOfflineStorageStrategy.node.d.ts +10 -9
- package/types/utils/FileOfflineStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/FileStorageStrategy.node.d.ts +9 -20
- package/types/utils/FileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts +13 -18
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerTokenStorageStrategy.d.ts +30 -51
- package/types/utils/MultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/OfflineClientManager.d.ts +52 -88
- package/types/utils/OfflineClientManager.d.ts.map +1 -0
- package/types/utils/OfflineQueueStorageStrategy.d.ts +12 -9
- package/types/utils/OfflineQueueStorageStrategy.d.ts.map +1 -0
- package/types/utils/TokenStorage.d.ts +20 -70
- package/types/utils/TokenStorage.d.ts.map +1 -0
- package/types/utils/compat.d.ts +4 -0
- package/types/utils/compat.d.ts.map +1 -0
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts +2 -11
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultOfflineStrategy.d.ts +2 -3
- package/types/utils/createDefaultOfflineStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultTokenStorageStrategy.d.ts +2 -12
- package/types/utils/createDefaultTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/reactive.d.ts +10 -16
- package/types/utils/reactive.d.ts.map +1 -0
- package/types/utils/stream-utils.node.d.ts +3 -2
- package/types/utils/stream-utils.node.d.ts.map +1 -0
- package/dist/123.cocolight-api-client.browser.js +0 -1
- package/dist/123.cocolight-api-client.cjs +0 -1
- package/dist/22.cocolight-api-client.mjs.js +0 -1
- package/dist/339.cocolight-api-client.mjs.js +0 -1
- package/dist/394.cocolight-api-client.browser.js +0 -1
- package/dist/394.cocolight-api-client.cjs +0 -1
- package/dist/405.cocolight-api-client.browser.js +0 -1
- package/dist/405.cocolight-api-client.cjs +0 -1
- package/dist/774.cocolight-api-client.mjs.js +0 -1
- package/dist/790.cocolight-api-client.mjs.js +0 -1
- package/dist/931.cocolight-api-client.browser.js +0 -1
- package/dist/931.cocolight-api-client.cjs +0 -1
- package/src/EJSONType.js +0 -53
- package/src/api/BaseEntity.js +0 -2828
- package/src/api/EntityRegistry.js +0 -152
- package/src/api/Event.js +0 -226
- package/src/api/News.js +0 -244
- package/src/api/UserApi.js +0 -81
- package/src/endpoints.module.js +0 -5
- package/src/error.js +0 -121
- package/src/index.js +0 -97
- package/src/mixin/UserMixin.js +0 -8
- package/src/utils/MultiServerFileStorageStrategy.node.js +0 -87
- package/src/utils/MultiServerTokenStorageStrategy.js +0 -188
- package/src/utils/OfflineQueueStorageStrategy.js +0 -51
- package/src/utils/TokenStorage.js +0 -153
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.js +0 -51
- package/src/utils/createDefaultTokenStorageStrategy.js +0 -49
- package/src/utils/stream-utils.node.js +0 -10
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ApiError } from "../error.js";
|
|
2
|
+
import { BaseEntity } from "./BaseEntity.js";
|
|
3
|
+
|
|
4
|
+
import type { AddCommentsData, DeleteCommentsData, UpdateCommentsData } from "./EndpointApi.types.js";
|
|
5
|
+
import type { CommentItemNormalized } from "./serverDataType/Comment.js";
|
|
6
|
+
|
|
7
|
+
export class Comment extends BaseEntity<CommentItemNormalized> {
|
|
8
|
+
static override entityType = "comments";
|
|
9
|
+
|
|
10
|
+
static override entityTag = "Comment";
|
|
11
|
+
|
|
12
|
+
static override SCHEMA_CONSTANTS: string[] = [
|
|
13
|
+
"ADD_COMMENTS"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
static ADD_BLOCKS = new Map([
|
|
17
|
+
["ADD_COMMENTS", "addComments"]
|
|
18
|
+
] as const);
|
|
19
|
+
|
|
20
|
+
static UPDATE_BLOCKS = new Map([
|
|
21
|
+
["ADD_COMMENTS", "updateComments"]
|
|
22
|
+
] as const);
|
|
23
|
+
|
|
24
|
+
override defaultFields: Record<string, any> = {};
|
|
25
|
+
|
|
26
|
+
override removeFields: string[] = ["contextId", "contextType", "parentCommentId", "argval"];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Transforme les champs imbriqués (author) en instances d'entités.
|
|
30
|
+
* @param data - Les données brutes du serveur.
|
|
31
|
+
* @returns Les données transformées.
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
protected override _transformServerData(data: CommentItemNormalized): CommentItemNormalized {
|
|
35
|
+
// Transformer author en instance User/Organization
|
|
36
|
+
if (data.author) {
|
|
37
|
+
data.author = this._linkNestedEntity(data.author);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Transformer les replies récursivement si présentes
|
|
41
|
+
if (Array.isArray(data.replies)) {
|
|
42
|
+
data.replies = data.replies.map(reply => {
|
|
43
|
+
if (reply.author) {
|
|
44
|
+
reply.author = this._linkNestedEntity(reply.author);
|
|
45
|
+
}
|
|
46
|
+
return reply;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override async get(): Promise<never> {
|
|
54
|
+
throw new ApiError(`get n'existe pas dans ${this.constructor.name}`, 501);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override async save(): Promise<Record<string, any>> {
|
|
58
|
+
// Pour les commentaires, on ne peut pas refresh après save
|
|
59
|
+
// car il n'y a pas d'endpoint GET_COMMENT
|
|
60
|
+
const originalRefresh = this.refresh;
|
|
61
|
+
this.refresh = async () => this._serverData; // No-op
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
return await super.save();
|
|
65
|
+
} finally {
|
|
66
|
+
this.refresh = originalRefresh;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override _add = async (payload: Record<string, any>): Promise<void> => {
|
|
71
|
+
if (!this._calledFromSave) {
|
|
72
|
+
throw new Error("utilisation invalide de _add, utilisez save");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if(!this.parent?.id){
|
|
76
|
+
throw new Error("Le parent doit être défini pour ajouter un commentaire.");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(payload.text === ""){
|
|
80
|
+
payload.text = " ";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Si le parent est un Comment, on met son ID dans parentCommentId
|
|
84
|
+
if(this.parent.getEntityType() === "comments"){
|
|
85
|
+
payload.parentCommentId = this.parent.id;
|
|
86
|
+
// Le contextId et contextType doivent pointer vers l'entité racine (news, etc.)
|
|
87
|
+
// Il faut remonter jusqu'à trouver le parent qui n'est pas un commentaire
|
|
88
|
+
let rootParent = this.parent.parent;
|
|
89
|
+
while(rootParent && rootParent.getEntityType && rootParent.getEntityType() === "comments"){
|
|
90
|
+
rootParent = rootParent.parent;
|
|
91
|
+
}
|
|
92
|
+
if(rootParent){
|
|
93
|
+
payload.contextId = rootParent.id;
|
|
94
|
+
payload.contextType = rootParent.getEntityType();
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error("Impossible de trouver l'entité racine pour le commentaire.");
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
// bug doit mettre une chaîne vide si pas de parentCommentId car dans getComments il y a un bug sur l'api dans la requete
|
|
100
|
+
payload.parentCommentId = payload.parentCommentId || "";
|
|
101
|
+
payload.contextId = this.parent.id;
|
|
102
|
+
payload.contextType = this.parent.getEntityType();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
for (const [constant, methodName] of Array.from(Comment.ADD_BLOCKS)) {
|
|
107
|
+
const blockData = this._extractChangedFieldsFromSchema(
|
|
108
|
+
this.apiClient,
|
|
109
|
+
constant,
|
|
110
|
+
{ ...payload, ...this.defaultFields },
|
|
111
|
+
() => {},
|
|
112
|
+
[]
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (blockData && Object.keys(blockData).length > 0) {
|
|
116
|
+
const data = await this._invokeBlockMethod(Comment.ADD_BLOCKS, methodName, blockData);
|
|
117
|
+
// L'API retourne l'ID soit dans data.object.id, soit dans data.id
|
|
118
|
+
const responseId = data?.object?.id || data?.id?.$id || data?.id;
|
|
119
|
+
if (!this.id && responseId) {
|
|
120
|
+
this._draftData.id = responseId;
|
|
121
|
+
this._setData(data.newComment as any, { forceInitialDraftReset: true });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
override _update = async (payload: Record<string, any>): Promise<boolean> => {
|
|
128
|
+
if (!this._calledFromSave) {
|
|
129
|
+
throw new Error("utilisation invalide de _update, utilisez save");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if(!this.parent?.id){
|
|
133
|
+
throw new Error("Le parent doit être défini pour ajouter un commentaire.");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// si le texte est vide, on met un espace pour que le champ soit pris en compte car sur le serveur
|
|
137
|
+
// il y a une vérification de la taille du texte je pense
|
|
138
|
+
if(payload?.text === ""){
|
|
139
|
+
payload.text = " ";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
payload.params = {
|
|
143
|
+
text: payload.text
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
delete payload.text;
|
|
147
|
+
|
|
148
|
+
let hasChanged = false;
|
|
149
|
+
const data = await this.callIsConnected(() => this.endpointApi.updateComments(payload as UpdateCommentsData)) as any;
|
|
150
|
+
if(data?.comment){
|
|
151
|
+
this._setData(data.comment as any, { forceInitialDraftReset: true });
|
|
152
|
+
}
|
|
153
|
+
hasChanged = true;
|
|
154
|
+
return hasChanged;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
async addComments(data: Partial<AddCommentsData> = {}): Promise<unknown> {
|
|
158
|
+
return this.callIsConnected(() => this.endpointApi.addComments(data as AddCommentsData));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async updateComments(data: Partial<UpdateCommentsData> = {}): Promise<unknown> {
|
|
162
|
+
return this.callIsConnected(() => this.endpointApi.updateComments(data as UpdateCommentsData));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Supprimer un commentaire : Supprime un commentaire existant.
|
|
167
|
+
* Constant : DELETE_COMMENT
|
|
168
|
+
*/
|
|
169
|
+
async delete(): Promise<void> {
|
|
170
|
+
if(!this.id) {
|
|
171
|
+
throw new ApiError("Vous devez fournir un id pour supprimer un commentaire.", 400);
|
|
172
|
+
}
|
|
173
|
+
const data = {
|
|
174
|
+
pathParams: { id: this.id },
|
|
175
|
+
};
|
|
176
|
+
await this.callIsConnected(() => this.endpointApi.deleteComments(data as DeleteCommentsData));
|
|
177
|
+
|
|
178
|
+
// Vider les objets réactifs sans casser la réactivité
|
|
179
|
+
Object.keys(this._draftData).forEach(key => delete this._draftData[key]);
|
|
180
|
+
Object.keys(this._serverData).forEach(key => delete (this._serverData as any)[key]);
|
|
181
|
+
|
|
182
|
+
// Marquer comme supprimé
|
|
183
|
+
this._isDeleted = true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Créer une réponse à ce commentaire (commentaire sur commentaire).
|
|
188
|
+
* @param commentData - Données du commentaire.
|
|
189
|
+
* @returns Instance de Comment.
|
|
190
|
+
*/
|
|
191
|
+
async comment(commentData: Record<string, any> = {}): Promise<Comment> {
|
|
192
|
+
if(!this.isConnected){
|
|
193
|
+
throw new ApiError("Vous devez être connecté.", 401);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const entity = await this.entity("comments", commentData);
|
|
197
|
+
return entity as Comment;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|