@communecter/cocolight-api-client 1.0.58 → 1.0.60

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.58",
3
+ "version": "1.0.60",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -746,6 +746,25 @@ export class BaseEntity<TServerData = any> {
746
746
  return obj.map((el) => this._removeUnserializables(el, seen));
747
747
  }
748
748
 
749
+ // Preserve native types that EJSON handles natively
750
+ if (obj instanceof Date) {
751
+ return obj;
752
+ }
753
+
754
+ if (obj instanceof RegExp) {
755
+ return obj;
756
+ }
757
+
758
+ // Preserve ObjectID instances (both bson-objectid and custom ObjectID)
759
+ if (obj && typeof obj === "object" && "_bsontype" in obj && obj._bsontype === "ObjectID") {
760
+ return obj;
761
+ }
762
+
763
+ // Preserve binary types (Uint8Array, Buffer, etc.)
764
+ if (obj instanceof Uint8Array || ArrayBuffer.isView(obj)) {
765
+ return obj;
766
+ }
767
+
749
768
  const clean: Record<string, any> = {};
750
769
  for (const key of Object.keys(obj)) {
751
770
  const val = obj[key];
package/src/api/User.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { ApiError, ApiResponseError } from "../error.js";
1
+ import { ApiError } from "../error.js";
2
2
  import { BaseEntity } from "./BaseEntity.js";
3
- import { createFromCollection } from "./EntityRegistry.js";
4
3
  import { UserMixin } from "../mixin/UserMixin.js";
5
4
 
6
5
  import type { Badge } from "./Badge.js";
@@ -19,7 +18,6 @@ import type {
19
18
  GetFriendsAdminData
20
19
  } from "./EndpointApi.types.js";
21
20
  import type { Organization } from "./Organization.js";
22
- import type { GetElementsKeyResponse } from "@/types/api-responses.js";
23
21
  import type { EntityTypes } from "@/types/entities.js";
24
22
 
25
23
  type ApiClient = import("../ApiClient.js").default;
@@ -867,40 +865,14 @@ export class User extends BaseEntity<UserItemNormalized> {
867
865
 
868
866
  /**
869
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
870
  */
871
- async entitySlug(slug: string): Promise<EntityTypes> {
871
+ override async entityBySlug(slug: string): Promise<EntityTypes> {
872
872
  if(!this.isMe){
873
873
  throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer cet entité.", 401);
874
874
  }
875
- if (!slug) {
876
- throw new ApiError("slug requis", 400);
877
- }
878
- try {
879
- const data = await this.endpointApi.getElementsKey({
880
- pathParams:{
881
- slug: slug
882
- }
883
- }) as GetElementsKeyResponse;
884
-
885
- if(data.contextId && data.contextType) {
886
- const entity = createFromCollection(data.contextType, this, { id: data.contextId });
887
- if (!entity) {
888
- throw new ApiResponseError(`Le type d'entité pour le slug ${slug} n'est pas reconnu`, 200, data as object);
889
- }
890
- await entity.get();
891
- // On sait que c'est l'un des types concrets → on caste
892
- return entity as EntityTypes;
893
- } else {
894
- throw new ApiResponseError(`Le slug ${slug} n'est pas valide`, 200, data as object);
895
- }
896
- } catch (error) {
897
- if(error instanceof ApiResponseError) {
898
- throw new ApiResponseError(`Impossible de récupérer l'identifiant pour le slug ${slug}`, error.status, error.responseData);
899
- } else {
900
- throw error;
901
- }
902
- }
903
-
875
+ return super.entityBySlug(slug);
904
876
  }
905
877
  }
906
878
 
@@ -7,6 +7,7 @@ export type {
7
7
  } from "../api/EntityRegistry.js";
8
8
 
9
9
  export type {
10
+ EntityTypes,
10
11
  TransformsMap,
11
12
  TransformFunction,
12
13
  } from "./entities.js";
@@ -331,7 +331,9 @@ export declare class User extends BaseEntity<UserItemNormalized> {
331
331
  isFollowing(): boolean;
332
332
  /**
333
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.
334
336
  */
335
- entitySlug(slug: string): Promise<EntityTypes>;
337
+ entityBySlug(slug: string): Promise<EntityTypes>;
336
338
  }
337
339
  export {};
@@ -1,5 +1,5 @@
1
1
  export type { CollectionKey, EntityTag } from "../api/EntityRegistry.js";
2
- export type { TransformsMap, TransformFunction, } from "./entities.js";
2
+ export type { EntityTypes, TransformsMap, TransformFunction, } from "./entities.js";
3
3
  export type { SocialNetworkPayload, } from "./payloads.js";
4
4
  export type { UserTransforms, OrganizationTransforms, ProjectTransforms, EventTransforms } from "./transforms.js";
5
5
  export type { BaseApiResponse, ApiDataResponse, ApiErrorResponse, PaginatedApiResponse, GetElementsKeyResponse, ApiResponse } from "./api-responses.js";