@communecter/cocolight-api-client 1.0.121 → 1.0.122
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/203.cocolight-api-client.cjs +1 -0
- package/dist/278.cocolight-api-client.browser.js +1 -0
- package/dist/278.cocolight-api-client.cjs +1 -0
- package/dist/278.cocolight-api-client.mjs.js +1 -0
- package/dist/401.cocolight-api-client.mjs.js +1 -1
- package/dist/407.cocolight-api-client.browser.js +1 -0
- package/dist/407.cocolight-api-client.mjs.js +1 -0
- package/dist/499.cocolight-api-client.browser.js +1 -0
- package/dist/499.cocolight-api-client.cjs +1 -0
- package/dist/499.cocolight-api-client.mjs.js +1 -0
- package/dist/556.cocolight-api-client.browser.js +1 -0
- package/dist/556.cocolight-api-client.cjs +1 -0
- package/dist/556.cocolight-api-client.mjs.js +1 -0
- package/dist/588.cocolight-api-client.mjs.js +1 -1
- package/dist/593.cocolight-api-client.mjs.js +1 -1
- package/dist/839.cocolight-api-client.mjs.js +1 -1
- package/dist/85.cocolight-api-client.browser.js +1 -0
- package/dist/85.cocolight-api-client.cjs +1 -0
- package/dist/85.cocolight-api-client.mjs.js +1 -0
- package/dist/906.cocolight-api-client.browser.js +1 -0
- package/dist/906.cocolight-api-client.cjs +1 -0
- package/dist/906.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 +1 -1
- package/src/Api.ts +21 -2
- package/src/api/BaseEntity.ts +145 -4
- package/src/api/EndpointApi.ts +125 -1
- package/src/api/EndpointApi.types.ts +180 -1
- package/src/api/EntityRegistry.ts +11 -3
- package/src/api/Form.ts +60 -0
- package/src/api/User.ts +2 -0
- package/src/api/UserApi.ts +3 -2
- package/src/api/serverDataType/Form.ts +56 -0
- package/src/endpoints.module.ts +1 -1
- package/src/index.ts +3 -1
- package/src/types/entities.ts +3 -2
- package/types/Api.d.ts +7 -0
- package/types/api/BaseEntity.d.ts +99 -3
- package/types/api/EndpointApi.d.ts +77 -1
- package/types/api/EndpointApi.types.d.ts +164 -1
- package/types/api/EntityRegistry.d.ts +1 -1
- package/types/api/Form.d.ts +23 -0
- package/types/api/Organization.d.ts +1 -1
- package/types/api/User.d.ts +1 -0
- package/types/api/serverDataType/Form.d.ts +51 -0
- package/types/endpoints.module.d.ts +2661 -166
- package/types/index.d.ts +3 -1
- package/types/types/entities.d.ts +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TypeScript native types
|
|
2
2
|
import type { CollectionType } from "../types/entities.js";
|
|
3
3
|
|
|
4
|
-
export type EntityTag = "User" | "Organization" | "Project" | "Event" | "Poi" | "Badge" | "News" | "Comment" | "Answer";
|
|
4
|
+
export type EntityTag = "User" | "Organization" | "Project" | "Event" | "Poi" | "Badge" | "News" | "Comment" | "Answer" | "Form";
|
|
5
5
|
export type CollectionKey = CollectionType; // Alias pour compatibilité
|
|
6
6
|
type BaseEntity = import("./BaseEntity.js").BaseEntity<any>;
|
|
7
7
|
type ApiClient = import("../ApiClient.js").default;
|
|
@@ -111,7 +111,8 @@ function _getCollectionFromTag(tag: EntityTag): CollectionKey | null {
|
|
|
111
111
|
"News": "news",
|
|
112
112
|
"Badge": "badges",
|
|
113
113
|
"Comment": "comments",
|
|
114
|
-
"Answer": "answers"
|
|
114
|
+
"Answer": "answers",
|
|
115
|
+
"Form": "forms"
|
|
115
116
|
};
|
|
116
117
|
return map[tag] || null;
|
|
117
118
|
}
|
|
@@ -134,6 +135,7 @@ function _getEntityMeta(entityType: CollectionKey, __entityTag: EntityTag): Enti
|
|
|
134
135
|
News: selfTag === "News" ? selfClass : EntityRegistry.get("News"),
|
|
135
136
|
Comment: selfTag === "Comment" ? selfClass : EntityRegistry.get("Comment"),
|
|
136
137
|
Answer: selfTag === "Answer" ? selfClass : EntityRegistry.get("Answer"),
|
|
138
|
+
Form: selfTag === "Form" ? selfClass : EntityRegistry.get("Form"),
|
|
137
139
|
};
|
|
138
140
|
|
|
139
141
|
const map: Record<CollectionKey, EntityMeta> = {
|
|
@@ -151,6 +153,7 @@ function _getEntityMeta(entityType: CollectionKey, __entityTag: EntityTag): Enti
|
|
|
151
153
|
} },
|
|
152
154
|
comments: { entityClass: commonDeps.Comment as EntityClass, deps: { ...commonDeps } },
|
|
153
155
|
answers: { entityClass: commonDeps.Answer as EntityClass, deps: { ...commonDeps } },
|
|
156
|
+
forms: { entityClass: commonDeps.Form as EntityClass, deps: { ...commonDeps } },
|
|
154
157
|
};
|
|
155
158
|
|
|
156
159
|
return map[entityType] || null;
|
|
@@ -201,6 +204,10 @@ export function createFromCollection(collection: CollectionKey, parent: ApiClien
|
|
|
201
204
|
answers: {
|
|
202
205
|
entityTag: "Answer",
|
|
203
206
|
meta: tag => _buildMeta(tag, { remove: [] })
|
|
207
|
+
},
|
|
208
|
+
forms: {
|
|
209
|
+
entityTag: "Form",
|
|
210
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
204
211
|
}
|
|
205
212
|
};
|
|
206
213
|
const entry = _collectionMap[collection];
|
|
@@ -232,7 +239,8 @@ function _buildMeta(tag: EntityTag, options: { remove: string[] }): EntityMeta {
|
|
|
232
239
|
Badge: EntityRegistry.get("Badge"),
|
|
233
240
|
News: EntityRegistry.get("News"),
|
|
234
241
|
Comment: EntityRegistry.get("Comment"),
|
|
235
|
-
Answer: EntityRegistry.get("Answer")
|
|
242
|
+
Answer: EntityRegistry.get("Answer"),
|
|
243
|
+
Form: EntityRegistry.get("Form")
|
|
236
244
|
};
|
|
237
245
|
// inject self
|
|
238
246
|
(allDeps as any)[tag] = EntityClass;
|
package/src/api/Form.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseEntity } from "./BaseEntity.js";
|
|
2
|
+
import { ApiError } from "../error.js";
|
|
3
|
+
|
|
4
|
+
import type { FormItemNormalized } from "./serverDataType/Form.js";
|
|
5
|
+
|
|
6
|
+
export class Form extends BaseEntity<FormItemNormalized> {
|
|
7
|
+
static override entityType = "forms";
|
|
8
|
+
|
|
9
|
+
static override entityTag = "Form";
|
|
10
|
+
static override SCHEMA_CONSTANTS: string[] = [];
|
|
11
|
+
|
|
12
|
+
static ADD_BLOCKS: Map<string, string> = new Map([]);
|
|
13
|
+
static UPDATE_BLOCKS: Map<string, string> = new Map([]);
|
|
14
|
+
|
|
15
|
+
override defaultFields: Record<string, any> = {};
|
|
16
|
+
override removeFields: string[] = [];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Transforme les champs imbriqués en instances d'entités si nécessaire.
|
|
20
|
+
* @param data - Les données brutes du serveur.
|
|
21
|
+
* @returns Les données transformées.
|
|
22
|
+
* @protected
|
|
23
|
+
*/
|
|
24
|
+
protected override _transformServerData(data: FormItemNormalized): FormItemNormalized {
|
|
25
|
+
// Pour l'instant, on ne transforme pas les relations parent
|
|
26
|
+
// car elles peuvent être des Organizations ou Projects
|
|
27
|
+
// On pourrait ajouter cette transformation plus tard si nécessaire
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Rafraîchit les données du formulaire depuis l'API.
|
|
34
|
+
* Constant : GET_COFORM_BY_ID
|
|
35
|
+
*/
|
|
36
|
+
override async get(): Promise<Record<string, any>> {
|
|
37
|
+
if (!this.id) throw new ApiError("Impossible de rafraîchir sans ID.", 400);
|
|
38
|
+
const parentFormId = this.id; // Type narrowing
|
|
39
|
+
|
|
40
|
+
const form = await this.endpointApi.getCoformById({
|
|
41
|
+
parentFormId
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (form?.data?.id || form?.data?._id) {
|
|
45
|
+
// Normaliser les valeurs nulles en objets/tableaux vides pour cohérence
|
|
46
|
+
const normalizedData = {
|
|
47
|
+
...form.data,
|
|
48
|
+
inputs: form.data.inputs ?? {},
|
|
49
|
+
params: form.data.params ?? {},
|
|
50
|
+
subForms: form.data.subForms ?? [],
|
|
51
|
+
parent: form.data.parent ?? undefined,
|
|
52
|
+
config: form.data.config ?? undefined,
|
|
53
|
+
} as FormItemNormalized;
|
|
54
|
+
|
|
55
|
+
this._setData(normalizedData, { forceInitialDraftReset: true });
|
|
56
|
+
return this.serverData;
|
|
57
|
+
}
|
|
58
|
+
throw new ApiError(`Aucun formulaire trouvé pour l'ID ${this.id}`, 404);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/api/User.ts
CHANGED
|
@@ -111,6 +111,7 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
111
111
|
Badge: typeof import("./Badge.js").Badge;
|
|
112
112
|
News: typeof import("./News.js").News;
|
|
113
113
|
Comment: typeof import("./Comment.js").Comment;
|
|
114
|
+
Answer: typeof import("./Answer.js").Answer;
|
|
114
115
|
}
|
|
115
116
|
) {
|
|
116
117
|
if(!deps.EndpointApi){
|
|
@@ -126,6 +127,7 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
126
127
|
if (!deps.Poi) throw new ApiError("Poi class must be injected.", 500);
|
|
127
128
|
if (!deps.Badge) throw new ApiError("Badge class must be injected.", 500);
|
|
128
129
|
if (!deps.News) throw new ApiError("News class must be injected.", 500);
|
|
130
|
+
if (!deps.Answer) throw new ApiError("Answer class must be injected.", 500);
|
|
129
131
|
|
|
130
132
|
super(parent, data, deps);
|
|
131
133
|
}
|
package/src/api/UserApi.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ApiClient from "../ApiClient.js";
|
|
2
2
|
import { ApiError, ApiResponseError } from "../error.js";
|
|
3
|
+
import { Answer } from "./Answer.js";
|
|
3
4
|
import { Badge } from "./Badge.js";
|
|
4
5
|
import { Comment } from "./Comment.js";
|
|
5
6
|
import EndpointApi from "./EndpointApi.js";
|
|
@@ -66,7 +67,7 @@ export class UserApi {
|
|
|
66
67
|
this.loggedUser = new User(
|
|
67
68
|
this.client,
|
|
68
69
|
response.data.user,
|
|
69
|
-
{ EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment }
|
|
70
|
+
{ EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer }
|
|
70
71
|
);
|
|
71
72
|
return this.loggedUser;
|
|
72
73
|
});
|
|
@@ -88,7 +89,7 @@ export class UserApi {
|
|
|
88
89
|
this.loggedUser = new User(
|
|
89
90
|
this.client,
|
|
90
91
|
{ id: this.client.userId },
|
|
91
|
-
{ EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment }
|
|
92
|
+
{ EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer }
|
|
92
93
|
);
|
|
93
94
|
|
|
94
95
|
return this.loggedUser;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DateValue, IdObject, ParentsMap } 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 FormSubFormInputField {
|
|
9
|
+
label?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
info?: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
positions?: Record<string, string>;
|
|
14
|
+
markdown?: boolean;
|
|
15
|
+
uploader?: Record<string, any>;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FormSubFormInputs {
|
|
20
|
+
name: string;
|
|
21
|
+
info?: string;
|
|
22
|
+
id: string;
|
|
23
|
+
formParent: string;
|
|
24
|
+
hasMultiEval?: boolean;
|
|
25
|
+
inputs: Record<string, FormSubFormInputField>;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FormItemJson {
|
|
30
|
+
_id: IdObject;
|
|
31
|
+
config?: string | null;
|
|
32
|
+
parent?: ParentsMap | null;
|
|
33
|
+
subForms?: string[] | null;
|
|
34
|
+
type: string;
|
|
35
|
+
created?: DateValue;
|
|
36
|
+
creator?: string;
|
|
37
|
+
params?: Record<string, unknown> | null;
|
|
38
|
+
updated?: DateValue;
|
|
39
|
+
inputs?: Record<string, FormSubFormInputs> | null;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FormItemNormalized {
|
|
44
|
+
id: string;
|
|
45
|
+
_id: ObjectID;
|
|
46
|
+
config?: string | null;
|
|
47
|
+
parent?: ParentsMap | null;
|
|
48
|
+
subForms?: string[] | null;
|
|
49
|
+
type: string;
|
|
50
|
+
created?: Date;
|
|
51
|
+
creator?: string;
|
|
52
|
+
params?: Record<string, unknown> | null;
|
|
53
|
+
updated?: Date;
|
|
54
|
+
inputs?: Record<string, FormSubFormInputs> | null;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|