@communecter/cocolight-api-client 1.0.57 → 1.0.59

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.57",
3
+ "version": "1.0.59",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Api.ts CHANGED
@@ -16,6 +16,7 @@ import { ApiAuthenticationError, ApiClientError, ApiError, ApiResponseError } fr
16
16
  import type ApiClient from "./ApiClient.js";
17
17
  import type { ApiClientOptions } from "./ApiClient.js";
18
18
  import type { GetElementsKeyResponse } from "./types/api-responses.js";
19
+ import type { EntityData, EntityTypes } from "./types/entities.js";
19
20
 
20
21
  registerEntity("User", User);
21
22
  registerEntity("Organization", Organization);
@@ -29,19 +30,7 @@ registerEntity("News", News);
29
30
  registerEntity("Comment", Comment);
30
31
  registerEntity("Answer", Answer);
31
32
 
32
- /**
33
- * Union type for all possible entity types
34
- */
35
- type EntityTypes = User | Organization | Project | Event | Poi | Badge | News | Comment | Answer;
36
33
 
37
- /**
38
- * Type pour récupérer une entité existante via l'API publique.
39
- * Nécessite soit un id, soit un slug.
40
- * Les propriétés additionnelles sont autorisées mais ignorées lors de la récupération.
41
- */
42
- type EntityData =
43
- | { id: string; slug?: string; [key: string]: any }
44
- | { slug: string; id?: string; [key: string]: any };
45
34
 
46
35
  export default class Api {
47
36
  private _loggedUser: User | null;
package/src/api/User.ts CHANGED
@@ -18,6 +18,7 @@ import type {
18
18
  GetFriendsAdminData
19
19
  } from "./EndpointApi.types.js";
20
20
  import type { Organization } from "./Organization.js";
21
+ import type { EntityTypes } from "@/types/entities.js";
21
22
 
22
23
  type ApiClient = import("../ApiClient.js").default;
23
24
  type UserItemNormalized = import("./serverDataType/User.js").UserItemNormalized;
@@ -861,6 +862,18 @@ export class User extends BaseEntity<UserItemNormalized> {
861
862
  this._assertEntityType("citoyens");
862
863
  return this._isLinked("follows");
863
864
  }
865
+
866
+ /**
867
+ * Retourne une entité à partir d'un slug.
868
+ * @param slug - Le slug de l'entité à récupérer.
869
+ * @returns L'entité correspondante au slug.
870
+ */
871
+ override async entityBySlug(slug: string): Promise<EntityTypes> {
872
+ if(!this.isMe){
873
+ throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer cet entité.", 401);
874
+ }
875
+ return super.entityBySlug(slug);
876
+ }
864
877
  }
865
878
 
866
879
  // Incorporation des mixins dans User
package/src/index.ts CHANGED
@@ -69,11 +69,17 @@ export type { Event } from "./api/Event.js";
69
69
  export type { Poi } from "./api/Poi.js";
70
70
  export type { Badge } from "./api/Badge.js";
71
71
  export type { News } from "./api/News.js";
72
+ export type { Comment } from "./api/Comment.js";
73
+ export type { Answer } from "./api/Answer.js";
72
74
 
73
75
  // Types ServerData (données normalisées reçues du serveur)
74
76
  export type * from "./api/serverDataType/User.js";
75
77
  export type * from "./api/serverDataType/Organization.js";
76
78
  export type * from "./api/serverDataType/Project.js";
79
+ export type * from "./api/serverDataType/Event.js";
80
+ export type * from "./api/serverDataType/News.js";
81
+ export type * from "./api/serverDataType/Comment.js";
82
+ export type * from "./api/serverDataType/Answer.js";
77
83
  export type * from "./api/serverDataType/common.js";
78
84
 
79
85
  // Types utilitaires
@@ -1,5 +1,29 @@
1
1
  // types/entities.ts - Types partagés pour éviter les dépendances circulaires
2
2
 
3
+ import type { Answer } from "../api/Answer.js";
4
+ import type { Badge } from "../api/Badge.js";
5
+ import type { Comment } from "../api/Comment.js";
6
+ import type { Event } from "../api/Event.js";
7
+ import type { News } from "../api/News.js";
8
+ import type { Organization } from "../api/Organization.js";
9
+ import type { Poi } from "../api/Poi.js";
10
+ import type { Project } from "../api/Project.js";
11
+ import type { User } from "../api/User.js";
12
+
13
+ /**
14
+ * Union type for all possible entity types
15
+ */
16
+ export type EntityTypes = User | Organization | Project | Event | Poi | Badge | News | Comment | Answer;
17
+
18
+ /**
19
+ * Type pour récupérer une entité existante via l'API publique.
20
+ * Nécessite soit un id, soit un slug.
21
+ * Les propriétés additionnelles sont autorisées mais ignorées lors de la récupération.
22
+ */
23
+ export type EntityData =
24
+ | { id: string; slug?: string; [key: string]: any }
25
+ | { slug: string; id?: string; [key: string]: any };
26
+
3
27
  /**
4
28
  * Types de collection possibles
5
29
  */
package/types/Api.d.ts CHANGED
@@ -1,34 +1,13 @@
1
1
  import { Answer } from "./api/Answer.js";
2
- import { Badge } from "./api/Badge.js";
3
- import { Comment } from "./api/Comment.js";
4
2
  import EndpointApi from "./api/EndpointApi.js";
5
3
  import { Event } from "./api/Event.js";
6
- import { News } from "./api/News.js";
7
4
  import { Organization } from "./api/Organization.js";
8
- import { Poi } from "./api/Poi.js";
9
5
  import { Project } from "./api/Project.js";
10
6
  import { User } from "./api/User.js";
11
7
  import { UserApi } from "./api/UserApi.js";
12
8
  import type ApiClient from "./ApiClient.js";
13
9
  import type { ApiClientOptions } from "./ApiClient.js";
14
- /**
15
- * Union type for all possible entity types
16
- */
17
- type EntityTypes = User | Organization | Project | Event | Poi | Badge | News | Comment | Answer;
18
- /**
19
- * Type pour récupérer une entité existante via l'API publique.
20
- * Nécessite soit un id, soit un slug.
21
- * Les propriétés additionnelles sont autorisées mais ignorées lors de la récupération.
22
- */
23
- type EntityData = {
24
- id: string;
25
- slug?: string;
26
- [key: string]: any;
27
- } | {
28
- slug: string;
29
- id?: string;
30
- [key: string]: any;
31
- };
10
+ import type { EntityData, EntityTypes } from "./types/entities.js";
32
11
  export default class Api {
33
12
  private _loggedUser;
34
13
  private _client;
@@ -91,4 +70,3 @@ export default class Api {
91
70
  */
92
71
  logout(): void;
93
72
  }
94
- export {};
@@ -7,7 +7,7 @@ export declare class Organization extends BaseEntity<OrganizationItemNormalized>
7
7
  static entityType: string;
8
8
  static entityTag: string;
9
9
  static SCHEMA_CONSTANTS: string[];
10
- static ADD_BLOCKS: Map<"PROFIL_IMAGE" | "ADD_ORGANIZATION", "addOrganization" | "updateImageProfil">;
10
+ static ADD_BLOCKS: Map<"PROFIL_IMAGE" | "ADD_ORGANIZATION", "updateImageProfil" | "addOrganization">;
11
11
  static UPDATE_BLOCKS: Map<"UPDATE_BLOCK_DESCRIPTION" | "UPDATE_BLOCK_INFO" | "UPDATE_BLOCK_SOCIAL" | "UPDATE_BLOCK_LOCALITY" | "UPDATE_BLOCK_SLUG" | "PROFIL_IMAGE", "updateImageProfil" | "updateDescription" | "updateSocial" | "updateLocality" | "updateInfo" | "updateSlug">;
12
12
  defaultFields: Record<string, any>;
13
13
  removeFields: string[];
@@ -9,7 +9,7 @@ export declare class Project extends BaseEntity<ProjectItemNormalized> {
9
9
  static entityType: string;
10
10
  static entityTag: string;
11
11
  static SCHEMA_CONSTANTS: string[];
12
- static ADD_BLOCKS: Map<"PROFIL_IMAGE" | "ADD_PROJECT", "updateImageProfil" | "addProject">;
12
+ static ADD_BLOCKS: Map<"PROFIL_IMAGE" | "ADD_PROJECT", "addProject" | "updateImageProfil">;
13
13
  static UPDATE_BLOCKS: Map<"UPDATE_BLOCK_DESCRIPTION" | "UPDATE_BLOCK_INFO" | "UPDATE_BLOCK_SOCIAL" | "UPDATE_BLOCK_LOCALITY" | "UPDATE_BLOCK_SLUG" | "PROFIL_IMAGE", "updateImageProfil" | "updateDescription" | "updateSocial" | "updateLocality" | "updateInfo" | "updateSlug">;
14
14
  defaultFields: Record<string, any>;
15
15
  removeFields: string[];
@@ -3,6 +3,7 @@ import type { Badge } from "./Badge.js";
3
3
  import type { PaginatorPage } from "./BaseEntity.js";
4
4
  import type { ChangePasswordData, DeleteAccountData, GetSubscriptionsAdminData, GetSubscriptionsData, GetOrganizationsNoAdminData, GetOrganizationsAdminData, GetFriendsAdminData } from "./EndpointApi.types.js";
5
5
  import type { Organization } from "./Organization.js";
6
+ import type { EntityTypes } from "@/types/entities.js";
6
7
  type ApiClient = import("../ApiClient.js").default;
7
8
  type UserItemNormalized = import("./serverDataType/User.js").UserItemNormalized;
8
9
  export declare class User extends BaseEntity<UserItemNormalized> {
@@ -328,5 +329,11 @@ export declare class User extends BaseEntity<UserItemNormalized> {
328
329
  * @throws {ApiError}
329
330
  */
330
331
  isFollowing(): boolean;
332
+ /**
333
+ * Retourne une entité à partir d'un slug.
334
+ * @param slug - Le slug de l'entité à récupérer.
335
+ * @returns L'entité correspondante au slug.
336
+ */
337
+ entityBySlug(slug: string): Promise<EntityTypes>;
331
338
  }
332
339
  export {};
package/types/index.d.ts CHANGED
@@ -50,9 +50,15 @@ export type { Event } from "./api/Event.js";
50
50
  export type { Poi } from "./api/Poi.js";
51
51
  export type { Badge } from "./api/Badge.js";
52
52
  export type { News } from "./api/News.js";
53
+ export type { Comment } from "./api/Comment.js";
54
+ export type { Answer } from "./api/Answer.js";
53
55
  export type * from "./api/serverDataType/User.js";
54
56
  export type * from "./api/serverDataType/Organization.js";
55
57
  export type * from "./api/serverDataType/Project.js";
58
+ export type * from "./api/serverDataType/Event.js";
59
+ export type * from "./api/serverDataType/News.js";
60
+ export type * from "./api/serverDataType/Comment.js";
61
+ export type * from "./api/serverDataType/Answer.js";
56
62
  export type * from "./api/serverDataType/common.js";
57
63
  export type { PaginatorPage } from "./api/BaseEntity.js";
58
64
  export type * from "./types/index.js";
@@ -1,3 +1,30 @@
1
+ import type { Answer } from "../api/Answer.js";
2
+ import type { Badge } from "../api/Badge.js";
3
+ import type { Comment } from "../api/Comment.js";
4
+ import type { Event } from "../api/Event.js";
5
+ import type { News } from "../api/News.js";
6
+ import type { Organization } from "../api/Organization.js";
7
+ import type { Poi } from "../api/Poi.js";
8
+ import type { Project } from "../api/Project.js";
9
+ import type { User } from "../api/User.js";
10
+ /**
11
+ * Union type for all possible entity types
12
+ */
13
+ export type EntityTypes = User | Organization | Project | Event | Poi | Badge | News | Comment | Answer;
14
+ /**
15
+ * Type pour récupérer une entité existante via l'API publique.
16
+ * Nécessite soit un id, soit un slug.
17
+ * Les propriétés additionnelles sont autorisées mais ignorées lors de la récupération.
18
+ */
19
+ export type EntityData = {
20
+ id: string;
21
+ slug?: string;
22
+ [key: string]: any;
23
+ } | {
24
+ slug: string;
25
+ id?: string;
26
+ [key: string]: any;
27
+ };
1
28
  /**
2
29
  * Types de collection possibles
3
30
  */