@communecter/cocolight-api-client 1.0.123 → 1.0.124

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.123",
3
+ "version": "1.0.124",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Api.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Api.ts
2
2
  import { Answer } from "./api/Answer.js";
3
3
  import { Badge } from "./api/Badge.js";
4
+ import { Classified } from "./api/Classified.js";
4
5
  import { Comment } from "./api/Comment.js";
5
6
  import EndpointApi from "./api/EndpointApi.js";
6
7
  import { createFromCollection, registerEntity } from "./api/EntityRegistry.js";
@@ -31,6 +32,7 @@ registerEntity("News", News);
31
32
  registerEntity("Comment", Comment);
32
33
  registerEntity("Answer", Answer);
33
34
  registerEntity("Form", Form);
35
+ registerEntity("Classified", Classified);
34
36
 
35
37
 
36
38
 
@@ -128,9 +130,9 @@ export default class Api {
128
130
  async user(userData: EntityData): Promise<User> {
129
131
  try {
130
132
  if (!userData.id && !userData.slug) {
131
- return new User(this._client, userData, { EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer });
133
+ return new User(this._client, userData, { EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer, Classified });
132
134
  } else {
133
- const user = new User(this._client, userData, { EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer });
135
+ const user = new User(this._client, userData, { EndpointApi, Organization, Project, Event, Poi, Badge, News, Comment, Answer, Classified });
134
136
  await user.get();
135
137
  return user;
136
138
  }
@@ -146,7 +148,7 @@ export default class Api {
146
148
  */
147
149
  async organization(organizationData: EntityData): Promise<Organization> {
148
150
  try {
149
- const organization = new Organization(this._client, organizationData, { EndpointApi, User, Project, Event, Poi, Badge, News, Comment, Answer });
151
+ const organization = new Organization(this._client, organizationData, { EndpointApi, User, Project, Event, Poi, Badge, News, Comment, Answer, Classified });
150
152
  if (!organizationData.id && !organizationData.slug) {
151
153
  throw new Error("Vous devez fournir un id ou un slug pour créer une instance Organization.");
152
154
  }
@@ -163,7 +165,7 @@ export default class Api {
163
165
  */
164
166
  async project(projectData: EntityData): Promise<Project> {
165
167
  try {
166
- const project = new Project(this._client, projectData, { EndpointApi, User, Organization, Event, Poi, Badge, News, Comment });
168
+ const project = new Project(this._client, projectData, { EndpointApi, User, Organization, Event, Poi, Badge, News, Comment, Classified });
167
169
  if (!projectData.id && !projectData.slug) {
168
170
  throw new Error("Vous devez fournir un id ou un slug pour créer une instance Project.");
169
171
  }
@@ -243,6 +245,20 @@ export default class Api {
243
245
  }
244
246
  }
245
247
 
248
+ async classified(classifiedData: EntityData): Promise<Classified> {
249
+ try {
250
+ const classified = new Classified(this._client, classifiedData, { EndpointApi, User, Organization, Project, Event, Poi, Badge, News, Comment, Answer, Form, Classified });
251
+ if (!classifiedData.id && !classifiedData.slug) {
252
+ throw new Error("Vous devez fournir un id ou un slug pour créer une instance Classified.");
253
+ }
254
+ await classified.get();
255
+ return classified;
256
+ } catch (error) {
257
+ console.error("[Api.classified] Erreur lors de la création d'un objet Classified :", (error as Error).message);
258
+ throw error;
259
+ }
260
+ }
261
+
246
262
  /**
247
263
  * Retourne une entité à partir d'un slug.
248
264
  */
package/src/ApiClient.ts CHANGED
@@ -1616,6 +1616,22 @@ export default class ApiClient extends EventEmitter {
1616
1616
  return value;
1617
1617
  }
1618
1618
 
1619
+ /**
1620
+ * Normalise les valeurs numériques renvoyées en string par le backend
1621
+ * (cas typique : content-type application/x-www-form-urlencoded qui
1622
+ * sérialise tout en string, et le backend stocke tel quel).
1623
+ *
1624
+ * @param value - La valeur à normaliser.
1625
+ * @returns Number si conversion possible, sinon la valeur d'origine.
1626
+ */
1627
+ private _normalizeNumber(value: any) {
1628
+ if (typeof value !== "string") return value;
1629
+ const trimmed = value.trim();
1630
+ if (trimmed === "") return value;
1631
+ const n = Number(trimmed);
1632
+ return Number.isFinite(n) ? n : value;
1633
+ }
1634
+
1619
1635
  /**
1620
1636
  * Liste des champs d'image à normaliser.
1621
1637
  */
@@ -1638,6 +1654,13 @@ export default class ApiClient extends EventEmitter {
1638
1654
  */
1639
1655
  private _dateFields = ["modified", "created", "updated", "birthDate", "lastLoginDate", "startDate", "endDate", "date", "issuedOn"];
1640
1656
 
1657
+ /**
1658
+ * Liste des champs numériques à normaliser (le backend les renvoie en string
1659
+ * via x-www-form-urlencoded ; sans cette coercion, JSON.stringify diff
1660
+ * produit des faux positifs dans `hasChanges()`).
1661
+ */
1662
+ private _numberFields = ["buildingSurfaceArea", "siteSurfaceArea"];
1663
+
1641
1664
  /**
1642
1665
  * Normalise récursivement un objet, un tableau ou une valeur simple.
1643
1666
  * Cette fonction réalise en une seule passe les opérations suivantes :
@@ -1680,6 +1703,11 @@ export default class ApiClient extends EventEmitter {
1680
1703
  value = this._normalizeImage(value);
1681
1704
  }
1682
1705
 
1706
+ // Si la clé correspond à un champ numérique, on coerce la string en number.
1707
+ if (this._numberFields.includes(key)) {
1708
+ value = this._normalizeNumber(value);
1709
+ }
1710
+
1683
1711
  // Cas particulier : si la clé est "content" et qu'elle possède une propriété "image".
1684
1712
  if (key === "content" && value && typeof value === "object" && value.image) {
1685
1713
  value.image = this._normalizeImage(value.image);