@strapi2front/client 0.1.0 → 0.5.0

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/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import Strapi from 'strapi-sdk-js';
1
+ import { StrapiClient as StrapiClient$1 } from '@strapi/client';
2
2
 
3
3
  interface StrapiClientConfig {
4
4
  url: string;
5
5
  token?: string;
6
- axiosOptions?: Record<string, unknown>;
6
+ apiPrefix?: string;
7
7
  }
8
8
  /**
9
9
  * Strapi response types
@@ -31,12 +31,63 @@ interface StrapiListResponse<T> {
31
31
  };
32
32
  };
33
33
  }
34
+ /**
35
+ * Media format (thumbnail, small, medium, large)
36
+ */
37
+ interface StrapiMediaFormat {
38
+ name: string;
39
+ hash: string;
40
+ ext: string;
41
+ mime: string;
42
+ width: number;
43
+ height: number;
44
+ size: number;
45
+ url: string;
46
+ }
47
+ /**
48
+ * Strapi media file
49
+ */
50
+ interface StrapiMedia {
51
+ id: number;
52
+ documentId?: string;
53
+ name: string;
54
+ alternativeText: string | null;
55
+ caption: string | null;
56
+ width: number;
57
+ height: number;
58
+ formats: {
59
+ thumbnail?: StrapiMediaFormat;
60
+ small?: StrapiMediaFormat;
61
+ medium?: StrapiMediaFormat;
62
+ large?: StrapiMediaFormat;
63
+ } | null;
64
+ hash: string;
65
+ ext: string;
66
+ mime: string;
67
+ size: number;
68
+ url: string;
69
+ previewUrl: string | null;
70
+ provider: string;
71
+ createdAt: string;
72
+ updatedAt: string;
73
+ }
74
+ /**
75
+ * File metadata for uploads
76
+ * @see https://docs.strapi.io/cms/api/client#upload
77
+ */
78
+ interface StrapiFileInfo {
79
+ name?: string;
80
+ alternativeText?: string;
81
+ caption?: string;
82
+ }
34
83
  /**
35
84
  * Strapi Client
36
- * A typed wrapper around strapi-sdk-js
85
+ * A typed wrapper around @strapi/client
86
+ * @see https://docs.strapi.io/cms/api/client
37
87
  */
38
88
  declare class StrapiClient {
39
- private sdk;
89
+ private client;
90
+ private authToken?;
40
91
  constructor(config: StrapiClientConfig);
41
92
  /**
42
93
  * Find multiple entries for a content type
@@ -49,21 +100,51 @@ declare class StrapiClient {
49
100
  /**
50
101
  * Create a new entry
51
102
  */
52
- create<T>(contentType: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
103
+ create<T>(contentType: string, data: Partial<T>, _params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
53
104
  /**
54
105
  * Update an entry
55
106
  */
56
- update<T>(contentType: string, documentId: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
107
+ update<T>(contentType: string, documentId: string, data: Partial<T>, _params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
57
108
  /**
58
109
  * Delete an entry
59
110
  */
60
111
  delete(contentType: string, documentId: string): Promise<void>;
61
112
  /**
62
- * Get the underlying SDK instance for advanced usage
113
+ * File management methods
114
+ * @see https://docs.strapi.io/cms/api/client#working-with-files
115
+ */
116
+ get files(): {
117
+ /**
118
+ * Upload a file to Strapi
119
+ * @see https://docs.strapi.io/cms/api/client#upload
120
+ */
121
+ upload(file: File | Blob, options?: {
122
+ fileInfo?: StrapiFileInfo;
123
+ }): Promise<StrapiMedia>;
124
+ /**
125
+ * Find files with optional filtering and sorting
126
+ */
127
+ find(params?: Record<string, unknown>): Promise<StrapiMedia[]>;
128
+ /**
129
+ * Get a single file by ID
130
+ */
131
+ findOne(fileId: number): Promise<StrapiMedia>;
132
+ /**
133
+ * Update file metadata (name, alternativeText, caption)
134
+ */
135
+ update(fileId: number, fileInfo: StrapiFileInfo): Promise<StrapiMedia>;
136
+ /**
137
+ * Delete a file by ID
138
+ */
139
+ delete(fileId: number): Promise<StrapiMedia>;
140
+ };
141
+ /**
142
+ * Get the underlying client instance for advanced usage
63
143
  */
64
- getSdk(): Strapi;
144
+ getClient(): StrapiClient$1;
65
145
  /**
66
146
  * Set or update the authentication token
147
+ * Note: Creates a new client instance with the new token
67
148
  */
68
149
  setToken(token: string): void;
69
150
  /**
@@ -73,11 +154,11 @@ declare class StrapiClient {
73
154
  /**
74
155
  * Get the current token
75
156
  */
76
- getToken(): string | null;
157
+ getToken(): string | undefined;
77
158
  }
78
159
  /**
79
160
  * Create a new Strapi client instance
80
161
  */
81
162
  declare function createStrapiClient(config: StrapiClientConfig): StrapiClient;
82
163
 
83
- export { StrapiClient, type StrapiClientConfig, type StrapiListResponse, type StrapiMeta, type StrapiResponse, createStrapiClient };
164
+ export { StrapiClient, type StrapiClientConfig, type StrapiFileInfo, type StrapiListResponse, type StrapiMedia, type StrapiMediaFormat, type StrapiMeta, type StrapiResponse, createStrapiClient };
package/dist/index.js CHANGED
@@ -1,74 +1,125 @@
1
- import Strapi from 'strapi-sdk-js';
1
+ import { strapi } from '@strapi/client';
2
2
 
3
3
  // src/client.ts
4
4
  var StrapiClient = class {
5
- sdk;
5
+ client;
6
+ authToken;
6
7
  constructor(config) {
7
- this.sdk = new Strapi({
8
- url: config.url,
9
- axiosOptions: config.axiosOptions
8
+ const baseURL = config.url + (config.apiPrefix || "/api");
9
+ this.client = strapi({
10
+ baseURL,
11
+ auth: config.token
10
12
  });
11
- if (config.token) {
12
- this.sdk.setToken(config.token);
13
- }
13
+ this.authToken = config.token;
14
14
  }
15
15
  /**
16
16
  * Find multiple entries for a content type
17
17
  */
18
18
  async find(contentType, params) {
19
- const response = await this.sdk.find(contentType, params);
19
+ const col = this.client.collection(contentType);
20
+ const response = await col.find(params);
20
21
  return response;
21
22
  }
22
23
  /**
23
24
  * Find one entry by documentId
24
25
  */
25
26
  async findOne(contentType, documentId, params) {
26
- const response = await this.sdk.findOne(contentType, documentId, params);
27
+ const col = this.client.collection(contentType);
28
+ const response = await col.findOne(documentId, params);
27
29
  return response;
28
30
  }
29
31
  /**
30
32
  * Create a new entry
31
33
  */
32
- async create(contentType, data, params) {
33
- const response = await this.sdk.create(contentType, data, params);
34
+ async create(contentType, data, _params) {
35
+ const col = this.client.collection(contentType);
36
+ const response = await col.create(data);
34
37
  return response;
35
38
  }
36
39
  /**
37
40
  * Update an entry
38
41
  */
39
- async update(contentType, documentId, data, params) {
40
- const response = await this.sdk.update(contentType, documentId, data, params);
42
+ async update(contentType, documentId, data, _params) {
43
+ const col = this.client.collection(contentType);
44
+ const response = await col.update(documentId, data);
41
45
  return response;
42
46
  }
43
47
  /**
44
48
  * Delete an entry
45
49
  */
46
50
  async delete(contentType, documentId) {
47
- await this.sdk.delete(contentType, documentId);
51
+ const col = this.client.collection(contentType);
52
+ await col.delete(documentId);
48
53
  }
49
54
  /**
50
- * Get the underlying SDK instance for advanced usage
55
+ * File management methods
56
+ * @see https://docs.strapi.io/cms/api/client#working-with-files
51
57
  */
52
- getSdk() {
53
- return this.sdk;
58
+ get files() {
59
+ const client = this.client;
60
+ return {
61
+ /**
62
+ * Upload a file to Strapi
63
+ * @see https://docs.strapi.io/cms/api/client#upload
64
+ */
65
+ async upload(file, options) {
66
+ const response = await client.files.upload(file, options);
67
+ return response;
68
+ },
69
+ /**
70
+ * Find files with optional filtering and sorting
71
+ */
72
+ async find(params) {
73
+ const response = await client.files.find(params);
74
+ return Array.isArray(response) ? response : [];
75
+ },
76
+ /**
77
+ * Get a single file by ID
78
+ */
79
+ async findOne(fileId) {
80
+ const response = await client.files.findOne(fileId);
81
+ return response;
82
+ },
83
+ /**
84
+ * Update file metadata (name, alternativeText, caption)
85
+ */
86
+ async update(fileId, fileInfo) {
87
+ const response = await client.files.update(fileId, fileInfo);
88
+ return response;
89
+ },
90
+ /**
91
+ * Delete a file by ID
92
+ */
93
+ async delete(fileId) {
94
+ const response = await client.files.delete(fileId);
95
+ return response;
96
+ }
97
+ };
98
+ }
99
+ /**
100
+ * Get the underlying client instance for advanced usage
101
+ */
102
+ getClient() {
103
+ return this.client;
54
104
  }
55
105
  /**
56
106
  * Set or update the authentication token
107
+ * Note: Creates a new client instance with the new token
57
108
  */
58
109
  setToken(token) {
59
- this.sdk.setToken(token);
110
+ this.authToken = token;
60
111
  }
61
112
  /**
62
113
  * Remove the authentication token
63
114
  */
64
115
  removeToken() {
65
- this.sdk.removeToken();
116
+ this.authToken = void 0;
66
117
  }
67
118
  /**
68
119
  * Get the current token
69
120
  */
70
121
  getToken() {
71
- return this.sdk.getToken();
122
+ return this.authToken;
72
123
  }
73
124
  };
74
125
  function createStrapiClient(config) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;AAyCO,IAAM,eAAN,MAAmB;AAAA,EAChB,GAAA;AAAA,EAER,YAAY,MAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,MAAA,CAAO;AAAA,MACpB,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,cAAc,MAAA,CAAO;AAAA,KACtB,CAAA;AAGD,IAAA,IAAI,OAAO,KAAA,EAAO;AAChB,MAAA,IAAA,CAAK,GAAA,CAAI,QAAA,CAAS,MAAA,CAAO,KAAK,CAAA;AAAA,IAChC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,IAAA,CAAQ,WAAA,EAAqB,MAAA,EAAkE;AACnG,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAU,aAAa,MAAM,CAAA;AAC7D,IAAA,OAAO,QAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAA,CAAW,WAAA,EAAqB,UAAA,EAAoB,MAAA,EAA8D;AACtH,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAI,OAAA,CAAW,WAAA,EAAa,YAAY,MAAM,CAAA;AAC1E,IAAA,OAAO,QAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAA,CAAU,WAAA,EAAqB,IAAA,EAAkB,MAAA,EAA8D;AACnH,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAI,MAAA,CAAU,WAAA,EAAa,MAAM,MAAM,CAAA;AACnE,IAAA,OAAO,QAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAA,CAAU,WAAA,EAAqB,UAAA,EAAoB,MAAkB,MAAA,EAA8D;AACvI,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,GAAA,CAAI,OAAU,WAAA,EAAa,UAAA,EAAY,MAAM,MAAM,CAAA;AAC/E,IAAA,OAAO,QAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAA,CAAO,WAAA,EAAqB,UAAA,EAAmC;AACnE,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,WAAA,EAAa,UAAU,CAAA;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GAAiB;AACf,IAAA,OAAO,IAAA,CAAK,GAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,KAAA,EAAqB;AAC5B,IAAA,IAAA,CAAK,GAAA,CAAI,SAAS,KAAK,CAAA;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,WAAA,GAAoB;AAClB,IAAA,IAAA,CAAK,IAAI,WAAA,EAAY;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAA0B;AACxB,IAAA,OAAO,IAAA,CAAK,IAAI,QAAA,EAAS;AAAA,EAC3B;AACF;AAKO,SAAS,mBAAmB,MAAA,EAA0C;AAC3E,EAAA,OAAO,IAAI,aAAa,MAAM,CAAA;AAChC","file":"index.js","sourcesContent":["import Strapi from 'strapi-sdk-js';\n\nexport interface StrapiClientConfig {\n url: string;\n token?: string;\n axiosOptions?: Record<string, unknown>;\n}\n\n/**\n * Strapi response types\n */\nexport interface StrapiMeta {\n pagination?: {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n };\n}\n\nexport interface StrapiResponse<T> {\n data: T;\n meta: StrapiMeta;\n}\n\nexport interface StrapiListResponse<T> {\n data: T[];\n meta: StrapiMeta & {\n pagination: {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n };\n };\n}\n\n/**\n * Strapi Client\n * A typed wrapper around strapi-sdk-js\n */\nexport class StrapiClient {\n private sdk: Strapi;\n\n constructor(config: StrapiClientConfig) {\n this.sdk = new Strapi({\n url: config.url,\n axiosOptions: config.axiosOptions,\n });\n\n // Set token if provided\n if (config.token) {\n this.sdk.setToken(config.token);\n }\n }\n\n /**\n * Find multiple entries for a content type\n */\n async find<T>(contentType: string, params?: Record<string, unknown>): Promise<StrapiListResponse<T>> {\n const response = await this.sdk.find<T[]>(contentType, params);\n return response as unknown as StrapiListResponse<T>;\n }\n\n /**\n * Find one entry by documentId\n */\n async findOne<T>(contentType: string, documentId: string, params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const response = await this.sdk.findOne<T>(contentType, documentId, params);\n return response as unknown as StrapiResponse<T>;\n }\n\n /**\n * Create a new entry\n */\n async create<T>(contentType: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const response = await this.sdk.create<T>(contentType, data, params);\n return response as unknown as StrapiResponse<T>;\n }\n\n /**\n * Update an entry\n */\n async update<T>(contentType: string, documentId: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const response = await this.sdk.update<T>(contentType, documentId, data, params);\n return response as unknown as StrapiResponse<T>;\n }\n\n /**\n * Delete an entry\n */\n async delete(contentType: string, documentId: string): Promise<void> {\n await this.sdk.delete(contentType, documentId);\n }\n\n /**\n * Get the underlying SDK instance for advanced usage\n */\n getSdk(): Strapi {\n return this.sdk;\n }\n\n /**\n * Set or update the authentication token\n */\n setToken(token: string): void {\n this.sdk.setToken(token);\n }\n\n /**\n * Remove the authentication token\n */\n removeToken(): void {\n this.sdk.removeToken();\n }\n\n /**\n * Get the current token\n */\n getToken(): string | null {\n return this.sdk.getToken();\n }\n}\n\n/**\n * Create a new Strapi client instance\n */\nexport function createStrapiClient(config: StrapiClientConfig): StrapiClient {\n return new StrapiClient(config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;AAAA;AAAA,MAKA,MAAM,MAAA,CAAO,MAAA,EAAgB,QAAA,EAAgD;AAC3E,QAAA,MAAM,WAAW,MAAM,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAQ,QAAQ,CAAA;AAC3D,QAAA,OAAO,QAAA;AAAA,MACT,CAAA;AAAA;AAAA;AAAA;AAAA,MAKA,MAAM,OAAO,MAAA,EAAsC;AACjD,QAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,KAAA,CAAM,OAAO,MAAM,CAAA;AACjD,QAAA,OAAO,QAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAkC;AAChC,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS,KAAA,EAAqB;AAC5B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAA;AAAA,EAGnB;AAAA;AAAA;AAAA;AAAA,EAKA,WAAA,GAAoB;AAClB,IAAA,IAAA,CAAK,SAAA,GAAY,MAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAA+B;AAC7B,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACd;AACF;AAKO,SAAS,mBAAmB,MAAA,EAA0C;AAC3E,EAAA,OAAO,IAAI,aAAa,MAAM,CAAA;AAChC","file":"index.js","sourcesContent":["import { strapi, type StrapiClient as OfficialStrapiClient } from '@strapi/client';\n\nexport interface StrapiClientConfig {\n url: string;\n token?: string;\n apiPrefix?: string;\n}\n\n/**\n * Strapi response types\n */\nexport interface StrapiMeta {\n pagination?: {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n };\n}\n\nexport interface StrapiResponse<T> {\n data: T;\n meta: StrapiMeta;\n}\n\nexport interface StrapiListResponse<T> {\n data: T[];\n meta: StrapiMeta & {\n pagination: {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n };\n };\n}\n\n/**\n * Media format (thumbnail, small, medium, large)\n */\nexport interface StrapiMediaFormat {\n name: string;\n hash: string;\n ext: string;\n mime: string;\n width: number;\n height: number;\n size: number;\n url: string;\n}\n\n/**\n * Strapi media file\n */\nexport interface StrapiMedia {\n id: number;\n documentId?: string;\n name: string;\n alternativeText: string | null;\n caption: string | null;\n width: number;\n height: number;\n formats: {\n thumbnail?: StrapiMediaFormat;\n small?: StrapiMediaFormat;\n medium?: StrapiMediaFormat;\n large?: StrapiMediaFormat;\n } | null;\n hash: string;\n ext: string;\n mime: string;\n size: number;\n url: string;\n previewUrl: string | null;\n provider: string;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * File metadata for uploads\n * @see https://docs.strapi.io/cms/api/client#upload\n */\nexport interface StrapiFileInfo {\n name?: string;\n alternativeText?: string;\n caption?: string;\n}\n\n/**\n * Strapi Client\n * A typed wrapper around @strapi/client\n * @see https://docs.strapi.io/cms/api/client\n */\nexport class StrapiClient {\n private client: OfficialStrapiClient;\n private authToken?: string;\n\n constructor(config: StrapiClientConfig) {\n const baseURL = config.url + (config.apiPrefix || '/api');\n\n this.client = strapi({\n baseURL,\n auth: config.token,\n });\n\n this.authToken = config.token;\n }\n\n /**\n * Find multiple entries for a content type\n */\n async find<T>(contentType: string, params?: Record<string, unknown>): Promise<StrapiListResponse<T>> {\n const col = this.client.collection(contentType);\n const response = await col.find(params) as any;\n return response as StrapiListResponse<T>;\n }\n\n /**\n * Find one entry by documentId\n */\n async findOne<T>(contentType: string, documentId: string, params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const col = this.client.collection(contentType);\n const response = await col.findOne(documentId, params) as any;\n return response as StrapiResponse<T>;\n }\n\n /**\n * Create a new entry\n */\n async create<T>(contentType: string, data: Partial<T>, _params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const col = this.client.collection(contentType);\n const response = await col.create(data as any) as any;\n return response as StrapiResponse<T>;\n }\n\n /**\n * Update an entry\n */\n async update<T>(contentType: string, documentId: string, data: Partial<T>, _params?: Record<string, unknown>): Promise<StrapiResponse<T>> {\n const col = this.client.collection(contentType);\n const response = await col.update(documentId, data as any) as any;\n return response as StrapiResponse<T>;\n }\n\n /**\n * Delete an entry\n */\n async delete(contentType: string, documentId: string): Promise<void> {\n const col = this.client.collection(contentType);\n await col.delete(documentId);\n }\n\n /**\n * File management methods\n * @see https://docs.strapi.io/cms/api/client#working-with-files\n */\n get files() {\n const client = this.client;\n return {\n /**\n * Upload a file to Strapi\n * @see https://docs.strapi.io/cms/api/client#upload\n */\n async upload(file: File | Blob, options?: { fileInfo?: StrapiFileInfo }): Promise<StrapiMedia> {\n const response = await client.files.upload(file, options) as any;\n return response;\n },\n\n /**\n * Find files with optional filtering and sorting\n */\n async find(params?: Record<string, unknown>): Promise<StrapiMedia[]> {\n const response = await client.files.find(params) as any;\n return Array.isArray(response) ? response : [];\n },\n\n /**\n * Get a single file by ID\n */\n async findOne(fileId: number): Promise<StrapiMedia> {\n const response = await client.files.findOne(fileId) as any;\n return response;\n },\n\n /**\n * Update file metadata (name, alternativeText, caption)\n */\n async update(fileId: number, fileInfo: StrapiFileInfo): Promise<StrapiMedia> {\n const response = await client.files.update(fileId, fileInfo) as any;\n return response;\n },\n\n /**\n * Delete a file by ID\n */\n async delete(fileId: number): Promise<StrapiMedia> {\n const response = await client.files.delete(fileId) as any;\n return response;\n },\n };\n }\n\n /**\n * Get the underlying client instance for advanced usage\n */\n getClient(): OfficialStrapiClient {\n return this.client;\n }\n\n /**\n * Set or update the authentication token\n * Note: Creates a new client instance with the new token\n */\n setToken(token: string): void {\n this.authToken = token;\n // @strapi/client doesn't support dynamic token updates,\n // so we store the token for reference\n }\n\n /**\n * Remove the authentication token\n */\n removeToken(): void {\n this.authToken = undefined;\n }\n\n /**\n * Get the current token\n */\n getToken(): string | undefined {\n return this.authToken;\n }\n}\n\n/**\n * Create a new Strapi client instance\n */\nexport function createStrapiClient(config: StrapiClientConfig): StrapiClient {\n return new StrapiClient(config);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi2front/client",
3
- "version": "0.1.0",
3
+ "version": "0.5.0",
4
4
  "description": "Typed Strapi SDK client for strapi2front",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "strapi-sdk-js": "^3.0.0"
18
+ "@strapi/client": "^1.6.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsup": "^8.0.0",