@strapi2front/client 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eleven Estudio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Strapi from 'strapi-sdk-js';
|
|
2
|
+
|
|
3
|
+
interface StrapiClientConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
axiosOptions?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Strapi response types
|
|
10
|
+
*/
|
|
11
|
+
interface StrapiMeta {
|
|
12
|
+
pagination?: {
|
|
13
|
+
page: number;
|
|
14
|
+
pageSize: number;
|
|
15
|
+
pageCount: number;
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface StrapiResponse<T> {
|
|
20
|
+
data: T;
|
|
21
|
+
meta: StrapiMeta;
|
|
22
|
+
}
|
|
23
|
+
interface StrapiListResponse<T> {
|
|
24
|
+
data: T[];
|
|
25
|
+
meta: StrapiMeta & {
|
|
26
|
+
pagination: {
|
|
27
|
+
page: number;
|
|
28
|
+
pageSize: number;
|
|
29
|
+
pageCount: number;
|
|
30
|
+
total: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Strapi Client
|
|
36
|
+
* A typed wrapper around strapi-sdk-js
|
|
37
|
+
*/
|
|
38
|
+
declare class StrapiClient {
|
|
39
|
+
private sdk;
|
|
40
|
+
constructor(config: StrapiClientConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Find multiple entries for a content type
|
|
43
|
+
*/
|
|
44
|
+
find<T>(contentType: string, params?: Record<string, unknown>): Promise<StrapiListResponse<T>>;
|
|
45
|
+
/**
|
|
46
|
+
* Find one entry by documentId
|
|
47
|
+
*/
|
|
48
|
+
findOne<T>(contentType: string, documentId: string, params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new entry
|
|
51
|
+
*/
|
|
52
|
+
create<T>(contentType: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
|
|
53
|
+
/**
|
|
54
|
+
* Update an entry
|
|
55
|
+
*/
|
|
56
|
+
update<T>(contentType: string, documentId: string, data: Partial<T>, params?: Record<string, unknown>): Promise<StrapiResponse<T>>;
|
|
57
|
+
/**
|
|
58
|
+
* Delete an entry
|
|
59
|
+
*/
|
|
60
|
+
delete(contentType: string, documentId: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Get the underlying SDK instance for advanced usage
|
|
63
|
+
*/
|
|
64
|
+
getSdk(): Strapi;
|
|
65
|
+
/**
|
|
66
|
+
* Set or update the authentication token
|
|
67
|
+
*/
|
|
68
|
+
setToken(token: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Remove the authentication token
|
|
71
|
+
*/
|
|
72
|
+
removeToken(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current token
|
|
75
|
+
*/
|
|
76
|
+
getToken(): string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a new Strapi client instance
|
|
80
|
+
*/
|
|
81
|
+
declare function createStrapiClient(config: StrapiClientConfig): StrapiClient;
|
|
82
|
+
|
|
83
|
+
export { StrapiClient, type StrapiClientConfig, type StrapiListResponse, type StrapiMeta, type StrapiResponse, createStrapiClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import Strapi from 'strapi-sdk-js';
|
|
2
|
+
|
|
3
|
+
// src/client.ts
|
|
4
|
+
var StrapiClient = class {
|
|
5
|
+
sdk;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.sdk = new Strapi({
|
|
8
|
+
url: config.url,
|
|
9
|
+
axiosOptions: config.axiosOptions
|
|
10
|
+
});
|
|
11
|
+
if (config.token) {
|
|
12
|
+
this.sdk.setToken(config.token);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Find multiple entries for a content type
|
|
17
|
+
*/
|
|
18
|
+
async find(contentType, params) {
|
|
19
|
+
const response = await this.sdk.find(contentType, params);
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find one entry by documentId
|
|
24
|
+
*/
|
|
25
|
+
async findOne(contentType, documentId, params) {
|
|
26
|
+
const response = await this.sdk.findOne(contentType, documentId, params);
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a new entry
|
|
31
|
+
*/
|
|
32
|
+
async create(contentType, data, params) {
|
|
33
|
+
const response = await this.sdk.create(contentType, data, params);
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Update an entry
|
|
38
|
+
*/
|
|
39
|
+
async update(contentType, documentId, data, params) {
|
|
40
|
+
const response = await this.sdk.update(contentType, documentId, data, params);
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Delete an entry
|
|
45
|
+
*/
|
|
46
|
+
async delete(contentType, documentId) {
|
|
47
|
+
await this.sdk.delete(contentType, documentId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the underlying SDK instance for advanced usage
|
|
51
|
+
*/
|
|
52
|
+
getSdk() {
|
|
53
|
+
return this.sdk;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set or update the authentication token
|
|
57
|
+
*/
|
|
58
|
+
setToken(token) {
|
|
59
|
+
this.sdk.setToken(token);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Remove the authentication token
|
|
63
|
+
*/
|
|
64
|
+
removeToken() {
|
|
65
|
+
this.sdk.removeToken();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the current token
|
|
69
|
+
*/
|
|
70
|
+
getToken() {
|
|
71
|
+
return this.sdk.getToken();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function createStrapiClient(config) {
|
|
75
|
+
return new StrapiClient(config);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { StrapiClient, createStrapiClient };
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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AAA;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);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@strapi2front/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed Strapi SDK client for strapi2front",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"strapi-sdk-js": "^3.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"tsup": "^8.0.0",
|
|
22
|
+
"typescript": "^5.3.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"typescript": ">=5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/eleven-estudio/strapi2front.git",
|
|
34
|
+
"directory": "packages/client"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|