@communecter/cocolight-api-client 1.0.120 → 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.
Files changed (54) hide show
  1. package/dist/203.cocolight-api-client.cjs +1 -0
  2. package/dist/278.cocolight-api-client.browser.js +1 -0
  3. package/dist/278.cocolight-api-client.cjs +1 -0
  4. package/dist/278.cocolight-api-client.mjs.js +1 -0
  5. package/dist/401.cocolight-api-client.mjs.js +1 -1
  6. package/dist/407.cocolight-api-client.browser.js +1 -0
  7. package/dist/407.cocolight-api-client.mjs.js +1 -0
  8. package/dist/499.cocolight-api-client.browser.js +1 -0
  9. package/dist/499.cocolight-api-client.cjs +1 -0
  10. package/dist/499.cocolight-api-client.mjs.js +1 -0
  11. package/dist/556.cocolight-api-client.browser.js +1 -0
  12. package/dist/556.cocolight-api-client.cjs +1 -0
  13. package/dist/556.cocolight-api-client.mjs.js +1 -0
  14. package/dist/588.cocolight-api-client.mjs.js +1 -1
  15. package/dist/593.cocolight-api-client.mjs.js +1 -1
  16. package/dist/839.cocolight-api-client.mjs.js +1 -1
  17. package/dist/85.cocolight-api-client.browser.js +1 -0
  18. package/dist/85.cocolight-api-client.cjs +1 -0
  19. package/dist/85.cocolight-api-client.mjs.js +1 -0
  20. package/dist/906.cocolight-api-client.browser.js +1 -0
  21. package/dist/906.cocolight-api-client.cjs +1 -0
  22. package/dist/906.cocolight-api-client.mjs.js +1 -0
  23. package/dist/cocolight-api-client.browser.js +3 -3
  24. package/dist/cocolight-api-client.cjs +1 -1
  25. package/dist/cocolight-api-client.mjs.js +1 -1
  26. package/dist/cocolight-api-client.vite.mjs.js +1 -1
  27. package/dist/cocolight-api-client.vite.mjs.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/Api.ts +21 -2
  30. package/src/api/BaseEntity.ts +171 -12
  31. package/src/api/EndpointApi.ts +140 -1
  32. package/src/api/EndpointApi.types.ts +201 -1
  33. package/src/api/EntityRegistry.ts +11 -3
  34. package/src/api/Form.ts +60 -0
  35. package/src/api/User.ts +2 -0
  36. package/src/api/UserApi.ts +3 -2
  37. package/src/api/serverDataType/Country.ts +1 -0
  38. package/src/api/serverDataType/Form.ts +56 -0
  39. package/src/endpoints.module.ts +1 -1
  40. package/src/index.ts +4 -1
  41. package/src/types/entities.ts +3 -2
  42. package/types/Api.d.ts +7 -0
  43. package/types/api/BaseEntity.d.ts +112 -3
  44. package/types/api/EndpointApi.d.ts +86 -1
  45. package/types/api/EndpointApi.types.d.ts +183 -1
  46. package/types/api/EntityRegistry.d.ts +1 -1
  47. package/types/api/Form.d.ts +23 -0
  48. package/types/api/Organization.d.ts +1 -1
  49. package/types/api/User.d.ts +1 -0
  50. package/types/api/serverDataType/Country.d.ts +1 -0
  51. package/types/api/serverDataType/Form.d.ts +51 -0
  52. package/types/endpoints.module.d.ts +2834 -141
  53. package/types/index.d.ts +4 -1
  54. package/types/types/entities.d.ts +3 -2
@@ -4829,6 +4829,108 @@ export interface CoformAnswersByIdData {
4829
4829
  * Liste des champs à retourner
4830
4830
  */
4831
4831
  fields?: string[];
4832
+ /**
4833
+ * ID du formulaire parent (utilisé pour calculer les droits d'édition côté serveur)
4834
+ */
4835
+ formId?: string;
4836
+ [k: string]: unknown;
4837
+ }
4838
+
4839
+
4840
+ export interface GetCoformByIdData {
4841
+ /**
4842
+ * ID du formulaire parent à récupérer
4843
+ */
4844
+ parentFormId: string;
4845
+ [k: string]: unknown;
4846
+ }
4847
+
4848
+
4849
+ export interface CoformUploadAnswerFileData {
4850
+ /**
4851
+ * ID du formulaire parent (pour contrôles d'accès).
4852
+ */
4853
+ formId: string;
4854
+ /**
4855
+ * ID de réponse existant. Si absent, un MongoId est généré côté serveur.
4856
+ */
4857
+ answerId?: string;
4858
+ /**
4859
+ * Type de document à uploader.
4860
+ */
4861
+ docType?: "image" | "file";
4862
+ /**
4863
+ * Clé de contenu (ex: slider pour images).
4864
+ */
4865
+ contentKey?: string;
4866
+ /**
4867
+ * Sous-clé optionnelle pour rattachement du document.
4868
+ */
4869
+ subKey?: string;
4870
+ /**
4871
+ * UUID client du fichier (compat fine-uploader).
4872
+ */
4873
+ qquuid: string;
4874
+ /**
4875
+ * Nom original du fichier.
4876
+ */
4877
+ qqfilename: string;
4878
+ /**
4879
+ * Taille du fichier en octets.
4880
+ */
4881
+ qqtotalfilesize: number;
4882
+ /**
4883
+ * Fichier binaire multipart.
4884
+ */
4885
+ qqfile: {
4886
+ [k: string]: unknown;
4887
+ };
4888
+ [k: string]: unknown;
4889
+ }
4890
+
4891
+
4892
+ export interface CoformGetAnswerFilesData {
4893
+ /**
4894
+ * ID de la réponse CoForm
4895
+ */
4896
+ answerId: string;
4897
+ /**
4898
+ * Clé d'identification de l'input (ex: formId.inputId)
4899
+ */
4900
+ subKey: string;
4901
+ /**
4902
+ * Clé de contenu utilisée lors de l'upload
4903
+ */
4904
+ contentKey?: string;
4905
+ /**
4906
+ * Type de document à récupérer
4907
+ */
4908
+ docType?: "image" | "file";
4909
+ [k: string]: unknown;
4910
+ }
4911
+
4912
+
4913
+ export interface SaveCoformAnswerData {
4914
+ /**
4915
+ * ID du formulaire parent
4916
+ */
4917
+ formId: string;
4918
+ /**
4919
+ * Réponses du formulaire sérialisées en JSON, organisées par subFormId > inputId > valeur
4920
+ */
4921
+ answers: string;
4922
+ /**
4923
+ * ID d'une réponse existante (pour mise à jour)
4924
+ */
4925
+ answerId?: string;
4926
+ /**
4927
+ * Options ajoutées dynamiquement sérialisées en JSON (pour multiCheckboxPlus avec addValue)
4928
+ */
4929
+ addedOptions?: string;
4930
+ /**
4931
+ * Links des champs Finder sérialisés en JSON (pour answer.links). Format: { "organizations": { "mongoId": { "name": "...", "type": "organizations" } } }
4932
+ */
4933
+ links?: string;
4832
4934
  [k: string]: unknown;
4833
4935
  }
4834
4936
 
@@ -4891,7 +4993,7 @@ export interface UpdatePathValueData {
4891
4993
  /**
4892
4994
  * Collection de l’entité
4893
4995
  */
4894
- collection: "citoyens" | "organizations" | "projects" | "events" | "poi";
4996
+ collection: "citoyens" | "organizations" | "projects" | "events" | "poi" | "answers" | "forms";
4895
4997
  /**
4896
4998
  * Chemin de la valeur à mettre à jour
4897
4999
  */
@@ -4936,6 +5038,18 @@ export interface DeleteDocumentByContextData {
4936
5038
  }
4937
5039
 
4938
5040
 
5041
+ export interface DeleteDocumentByIdData {
5042
+ pathParams?: {
5043
+ /**
5044
+ * ID MongoDB du document à supprimer
5045
+ */
5046
+ id: string;
5047
+ [k: string]: unknown;
5048
+ };
5049
+ [k: string]: unknown;
5050
+ }
5051
+
5052
+
4939
5053
  export interface DemoteAdminData {
4940
5054
  parentId: string;
4941
5055
  /**
@@ -4973,6 +5087,27 @@ export interface CostumFilterCoformData {
4973
5087
  }
4974
5088
 
4975
5089
 
5090
+ export interface GetCountriesData {
5091
+ /**
5092
+ * Slug personnalisé
5093
+ */
5094
+ costumSlug?: string;
5095
+ /**
5096
+ * Mode édition personnalisé (boolean, string ou number)
5097
+ */
5098
+ costumEditMode?: ("true" | "false") | (0 | 1) | boolean;
5099
+ /**
5100
+ * ID personnalisé (format ObjectID MongoDB)
5101
+ */
5102
+ costumId?: string;
5103
+ /**
5104
+ * Type de collection
5105
+ */
5106
+ costumType?: "organizations" | "projects" | "events" | "citoyens" | "poi";
5107
+ [k: string]: unknown;
5108
+ }
5109
+
5110
+
4976
5111
  export interface SearchZonesData {
4977
5112
  /**
4978
5113
  * Code du pays pour la recherche
@@ -5004,3 +5139,68 @@ export interface SearchZonesData {
5004
5139
  costumType?: string;
5005
5140
  [k: string]: unknown;
5006
5141
  }
5142
+
5143
+
5144
+ export interface CoformAnswersByFormsData {
5145
+ /**
5146
+ * Liste des IDs de formulaires pour lesquels récupérer les réponses et le champ de recherche
5147
+ */
5148
+ forms?: {
5149
+ /**
5150
+ * This interface was referenced by `undefined`'s JSON-Schema definition
5151
+ * via the `patternProperty` "^[a-fA-F0-9]{24}$".
5152
+ */
5153
+ [k: string]: string;
5154
+ };
5155
+ [k: string]: unknown;
5156
+ }
5157
+
5158
+
5159
+ export interface GenerateAnswerFromFormData {
5160
+ action?: string;
5161
+ pathParams?: {
5162
+ /**
5163
+ * ID du formulaire pour lequel générer une nouvelle réponse
5164
+ */
5165
+ formId: string;
5166
+ [k: string]: unknown;
5167
+ };
5168
+ [k: string]: unknown;
5169
+ }
5170
+
5171
+
5172
+ export interface FundingEnvelopeData {
5173
+ /**
5174
+ * ID du contexte de l’entité
5175
+ */
5176
+ contextId: string;
5177
+ /**
5178
+ * Type de contexte de l’entité
5179
+ */
5180
+ contextType: string;
5181
+ /**
5182
+ * ID du formulaire pour lequel générer une nouvelle réponse
5183
+ */
5184
+ formId?: string;
5185
+ action?: string;
5186
+ /**
5187
+ * ID du projet
5188
+ */
5189
+ project?: string;
5190
+ /**
5191
+ * ID de la réponse
5192
+ */
5193
+ answer?: string;
5194
+ /**
5195
+ * ID du financeur
5196
+ */
5197
+ financerId?: string;
5198
+ financerType?: string;
5199
+ /**
5200
+ * Paramètres supplémentaires pour la recherche d’enveloppes
5201
+ */
5202
+ params?: {
5203
+ [k: string]: unknown;
5204
+ };
5205
+ [k: string]: unknown;
5206
+ }
@@ -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;
@@ -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
  }
@@ -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 @@
1
+ export type { ZoneItemNormalized as CountryItem } from "./Zone.js";
@@ -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
+ }