strapi-sdk-js 1.1.0 → 2.1.2
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/CHANGELOG.md +26 -0
- package/dist/index.d.ts +53 -20
- package/dist/index.es.js +32 -33
- package/dist/index.js +32 -33
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## [2.1.2](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.1...v2.1.2) (2021-12-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **params:** change type to accept object for populate ([bfa835c](https://github.com/Stun3R/strapi-sdk-js/commit/bfa835c6d01425049f7d675f96316516d59bca5d)), closes [#108](https://github.com/Stun3R/strapi-sdk-js/issues/108)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add integrations ([439b292](https://github.com/Stun3R/strapi-sdk-js/commit/439b2926e474c06a0e581f9af7c1ad08c5eb7282))
|
|
12
|
+
|
|
13
|
+
## [2.1.1](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.0...v2.1.1) (2021-11-29)
|
|
14
|
+
|
|
15
|
+
# [2.0.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.1.0...v2.0.0) (2021-11-08)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **Strapi v4 support**
|
|
21
|
+
* add params to create, update, delete methods in order to selecting field in response ([a693dac](https://github.com/Stun3R/strapi-sdk-js/commit/a693dac21101260125db8672229644387b2ee3e4))
|
|
22
|
+
* add StrapiLocale type for better autocompletion ([583c5b8](https://github.com/Stun3R/strapi-sdk-js/commit/583c5b8d561426c581f31ed6d335fc322411be71))
|
|
23
|
+
* replace axios request config params by custom type based on strapi rest api parameters ([2047433](https://github.com/Stun3R/strapi-sdk-js/commit/2047433f93aaae9b4eaeb0c7f4b49cccfb46f770))
|
|
24
|
+
* v4 error handling ([4d0eb3f](https://github.com/Stun3R/strapi-sdk-js/commit/4d0eb3f50ed9796e7dd3837cd45a2d926e9679d5))
|
|
25
|
+
|
|
1
26
|
# [1.1.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.2...v1.1.0) (2021-10-19)
|
|
2
27
|
|
|
3
28
|
|
|
@@ -17,6 +42,7 @@
|
|
|
17
42
|
|
|
18
43
|
### BREAKING CHANGES
|
|
19
44
|
|
|
45
|
+
* SDK supports Strapi v4. Every CRUD methods response changed. Please refer to [documentation](https://strapi-sdk-js.netlify.app)
|
|
20
46
|
* GraphQL is no longer supported in v1.1.0
|
|
21
47
|
|
|
22
48
|
## [1.0.2](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.1...v1.0.2) (2021-08-30)
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AxiosRequestConfig, AxiosInstance, Method } from 'axios';
|
|
|
2
2
|
import { CookieAttributes } from 'js-cookie';
|
|
3
3
|
|
|
4
4
|
declare type StrapiAuthProvider = "github" | "facebook" | "google" | "cognito" | "twitter" | "discord" | "twitch" | "instagram" | "vk" | "linkedin" | "reddit" | "auth0";
|
|
5
|
+
declare type StrapiLocale = "af" | "af-NA" | "af-ZA" | "agq" | "agq-CM" | "ak" | "ak-GH" | "sq" | "sq-AL" | "am" | "am-ET" | "ar" | "ar-DZ" | "ar-BH" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-AE" | "ar-001" | "ar-YE" | "hy" | "hy-AM" | "as" | "as-IN" | "asa" | "asa-TZ" | "az" | "az-Cyrl" | "az-Cyrl-AZ" | "az-Latn" | "az-Latn-AZ" | "ksf" | "ksf-CM" | "bm" | "bm-ML" | "bas" | "bas-CM" | "eu" | "eu-ES" | "be" | "be-BY" | "bem" | "bem-ZM" | "bez" | "bez-TZ" | "bn" | "bn-BD" | "bn-IN" | "brx" | "brx-IN" | "bs" | "bs-BA" | "br" | "br-FR" | "bg" | "bg-BG" | "my" | "my-MM" | "ca" | "ca-ES" | "ckb" | "tzm" | "tzm-Latn" | "tzm-Latn-MA" | "chr" | "chr-US" | "cgg" | "cgg-UG" | "zh" | "zh-Hans" | "zh-CN" | "zh-Hans-CN" | "zh-Hans-HK" | "zh-Hans-MO" | "zh-Hans-SG" | "zh-Hant" | "zh-Hant-HK" | "zh-Hant-MO" | "zh-Hant-TW" | "swc" | "swc-CD" | "kw" | "kw-GB" | "hr" | "hr-HR" | "cs" | "cs-CZ" | "da" | "da-DK" | "dua" | "dua-CM" | "nl" | "nl-AW" | "nl-BE" | "nl-CW" | "nl-NL" | "nl-SX" | "ebu" | "ebu-KE" | "en" | "en-AS" | "en-AU" | "en-BB" | "en-BE" | "en-BZ" | "en-BM" | "en-BW" | "en-CA" | "en-EG" | "en-EU" | "en-GU" | "en-GY" | "en-HK" | "en-IN" | "en-IE" | "en-JM" | "en-MT" | "en-MH" | "en-MU" | "en-NA" | "en-NZ" | "en-MP" | "en-PK" | "en-PH" | "en-SA" | "en-SG" | "en-ZA" | "en-TT" | "en-AE" | "en-UM" | "en-VI" | "en-US-POSIX" | "en-GB" | "en-US" | "en-ZW" | "eo" | "et" | "et-EE" | "ee" | "ee-GH" | "ee-TG" | "ewo" | "ewo-CM" | "fo" | "fo-FO" | "fil" | "fil-PH" | "fi" | "fi-FI" | "fr" | "fr-BE" | "fr-BJ" | "fr-BF" | "fr-BI" | "fr-CM" | "fr-CA" | "fr-CF" | "fr-TD" | "fr-KM" | "fr-CG" | "fr-CD" | "fr-CI" | "fr-DJ" | "fr-GQ" | "fr-FR" | "fr-GF" | "fr-GA" | "fr-GP" | "fr-GN" | "fr-LU" | "fr-MG" | "fr-ML" | "fr-MQ" | "fr-YT" | "fr-MC" | "fr-NE" | "fr-RW" | "fr-RE" | "fr-BL" | "fr-MF" | "fr-SN" | "fr-CH" | "fr-TG" | "ff" | "ff-SN" | "gl" | "gl-ES" | "lg" | "lg-UG" | "ka" | "ka-GE" | "de" | "de-AT" | "de-BE" | "de-DE" | "de-LI" | "de-LU" | "de-CH" | "el" | "el-CY" | "el-GR" | "gu" | "gu-IN" | "guz" | "guz-KE" | "ha" | "ha-Latn" | "ha-Latn-GH" | "ha-Latn-NE" | "ha-Latn-NG" | "haw" | "haw-US" | "he" | "he-IL" | "hi" | "hi-IN" | "hu" | "hu-HU" | "is" | "is-IS" | "ig" | "ig-NG" | "id" | "id-ID" | "ga" | "ga-IE" | "it" | "it-IT" | "it-CH" | "ja" | "ja-JP" | "dyo" | "dyo-SN" | "kea" | "kea-CV" | "kab" | "kab-DZ" | "kl" | "kl-GL" | "kln" | "kln-KE" | "kam" | "kam-KE" | "kn" | "kn-IN" | "kk" | "kk-Cyrl" | "kk-Cyrl-KZ" | "km" | "km-KH" | "ki" | "ki-KE" | "rw" | "rw-RW" | "kok" | "kok-IN" | "ko" | "ko-KR" | "khq" | "khq-ML" | "ses" | "ses-ML" | "nmg" | "nmg-CM" | "lag" | "lag-TZ" | "lv" | "lv-LV" | "ln" | "ln-CG" | "ln-CD" | "lt" | "lt-LT" | "lu" | "lu-CD" | "luo" | "luo-KE" | "luy" | "luy-KE" | "mk" | "mk-MK" | "jmc" | "jmc-TZ" | "mgh" | "mgh-MZ" | "kde" | "kde-TZ" | "mg" | "mg-MG" | "ms" | "ms-BN" | "ms-MY" | "ml" | "ml-IN" | "mt" | "mt-MT" | "gv" | "gv-GB" | "mr" | "mr-IN" | "mas" | "mas-KE" | "mas-TZ" | "mer" | "mer-KE" | "mfe" | "mfe-MU" | "mua" | "mua-CM" | "naq" | "naq-NA" | "ne" | "ne-IN" | "ne-NP" | "nd" | "nd-ZW" | "nb" | "nb-NO" | "nn" | "nn-NO" | "nus" | "nus-SD" | "nyn" | "nyn-UG" | "or" | "or-IN" | "om" | "om-ET" | "om-KE" | "ps" | "ps-AF" | "fa" | "fa-AF" | "fa-IR" | "pl" | "pl-PL" | "pt" | "pt-AO" | "pt-BR" | "pt-GW" | "pt-MZ" | "pt-PT" | "pt-ST" | "pa" | "pa-Arab" | "pa-Arab-PK" | "pa-Guru" | "pa-Guru-IN" | "ro" | "ro-MD" | "ro-RO" | "rm" | "rm-CH" | "rof" | "rof-TZ" | "rn" | "rn-BI" | "ru" | "ru-MD" | "ru-RU" | "ru-UA" | "rwk" | "rwk-TZ" | "saq" | "saq-KE" | "sg" | "sg-CF" | "sbp" | "sbp-TZ" | "seh" | "seh-MZ" | "sr" | "sr-Cyrl" | "sr-Cyrl-BA" | "sr-Cyrl-ME" | "sr-Cyrl-RS" | "sr-Latn" | "sr-Latn-BA" | "sr-Latn-ME" | "sr-Latn-RS" | "ksb" | "ksb-TZ" | "sn" | "sn-ZW" | "ii" | "ii-CN" | "si" | "si-LK" | "sk" | "sk-SK" | "sl" | "sl-SI" | "xog" | "xog-UG" | "so" | "so-DJ" | "so-ET" | "so-KE" | "so-SO" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-SV" | "es-GQ" | "es-GT" | "es-HN" | "es-419" | "es-MX" | "es-NI" | "es-PA" | "es-PY" | "es-PE" | "es-PR" | "es-ES" | "es-US" | "es-UY" | "es-VE" | "sw" | "sw-KE" | "sw-TZ" | "sv" | "sv-FI" | "sv-SE" | "gsw" | "gsw-CH" | "shi" | "shi-Latn" | "shi-Latn-MA" | "shi-Tfng" | "shi-Tfng-MA" | "dav" | "dav-KE" | "ta" | "ta-IN" | "ta-LK" | "twq" | "twq-NE" | "te" | "te-IN" | "teo" | "teo-KE" | "teo-UG" | "th" | "th-TH" | "bo" | "bo-CN" | "bo-IN" | "ti" | "ti-ER" | "ti-ET" | "to" | "to-TO" | "tr" | "tr-TR" | "uk" | "uk-UA" | "ur" | "ur-IN" | "ur-PK" | "uz" | "uz-Arab" | "uz-Arab-AF" | "uz-Cyrl" | "uz-Cyrl-UZ" | "uz-Latn" | "uz-Latn-UZ" | "vai" | "vai-Latn" | "vai-Latn-LR" | "vai-Vaii" | "vai-Vaii-LR" | "vi" | "vi-VN" | "vun" | "vun-TZ" | "cy" | "cy-GB" | "yav" | "yav-CM" | "yo" | "yo-NG" | "dje" | "dje-NE" | "zu" | "zu-ZA";
|
|
5
6
|
interface StoreConfig {
|
|
6
7
|
key: string;
|
|
7
8
|
useLocalStorage?: boolean;
|
|
@@ -9,15 +10,51 @@ interface StoreConfig {
|
|
|
9
10
|
}
|
|
10
11
|
interface StrapiOptions {
|
|
11
12
|
url?: string;
|
|
13
|
+
prefix?: string;
|
|
12
14
|
store?: StoreConfig;
|
|
13
15
|
axiosOptions?: AxiosRequestConfig;
|
|
14
16
|
}
|
|
15
17
|
interface StrapiDefaultOptions {
|
|
16
18
|
url: string;
|
|
19
|
+
prefix: string;
|
|
17
20
|
store: StoreConfig;
|
|
18
21
|
axiosOptions: AxiosRequestConfig;
|
|
19
22
|
}
|
|
20
23
|
declare type StrapiUser = Record<string, unknown> | null;
|
|
24
|
+
interface PaginationByPage {
|
|
25
|
+
page: number;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
withCount?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface PaginationByOffset {
|
|
30
|
+
start: number;
|
|
31
|
+
limit: number;
|
|
32
|
+
withCount?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface StrapiBaseRequestParams {
|
|
35
|
+
fields?: Array<string>;
|
|
36
|
+
populate?: string | Array<string> | Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
interface StrapiRequestParams extends StrapiBaseRequestParams {
|
|
39
|
+
sort?: string | Array<string>;
|
|
40
|
+
pagination?: PaginationByOffset | PaginationByPage;
|
|
41
|
+
filters?: Record<string, unknown>;
|
|
42
|
+
publicationState?: "live" | "preview";
|
|
43
|
+
locale?: StrapiLocale;
|
|
44
|
+
}
|
|
45
|
+
interface StrapiError {
|
|
46
|
+
data: null;
|
|
47
|
+
error: {
|
|
48
|
+
status: number;
|
|
49
|
+
name: string;
|
|
50
|
+
message: string;
|
|
51
|
+
details: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface StrapiResponse<T> {
|
|
55
|
+
data: T;
|
|
56
|
+
meta: Record<string, unknown>;
|
|
57
|
+
}
|
|
21
58
|
interface StrapiAuthenticationResponse {
|
|
22
59
|
user: Record<string, unknown>;
|
|
23
60
|
jwt: string;
|
|
@@ -138,51 +175,47 @@ declare class Strapi {
|
|
|
138
175
|
* Get a list of {content-type} entries
|
|
139
176
|
*
|
|
140
177
|
* @param {string} contentType - Content type's name pluralized
|
|
141
|
-
* @param {
|
|
142
|
-
* @returns Promise<T
|
|
178
|
+
* @param {StrapiRequestParams} params? - Query parameters
|
|
179
|
+
* @returns Promise<StrapiResponse<T>>
|
|
143
180
|
*/
|
|
144
|
-
find<T>(contentType: string, params?:
|
|
181
|
+
find<T>(contentType: string, params?: StrapiRequestParams): Promise<StrapiResponse<T>>;
|
|
145
182
|
/**
|
|
146
183
|
* Get a specific {content-type} entry
|
|
147
184
|
*
|
|
148
185
|
* @param {string} contentType - Content type's name pluralized
|
|
149
186
|
* @param {string|number} id - ID of entry
|
|
150
|
-
* @
|
|
187
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
188
|
+
* @returns Promise<StrapiResponse<T>>
|
|
151
189
|
*/
|
|
152
|
-
findOne<T>(contentType: string, id: string | number): Promise<T
|
|
153
|
-
/**
|
|
154
|
-
* Count {content-type} entries
|
|
155
|
-
*
|
|
156
|
-
* @param {string} contentType - Content type's name pluralized
|
|
157
|
-
* @param {AxiosRequestConfig["params"]} params? - Filter and order queries
|
|
158
|
-
* @returns Promise<T>
|
|
159
|
-
*/
|
|
160
|
-
count<T>(contentType: string, params?: AxiosRequestConfig["params"]): Promise<T>;
|
|
190
|
+
findOne<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
|
|
161
191
|
/**
|
|
162
192
|
* Create a {content-type} entry
|
|
163
193
|
*
|
|
164
194
|
* @param {string} contentType - Content type's name pluralized
|
|
165
195
|
* @param {AxiosRequestConfig["data"]} data - New entry
|
|
166
|
-
* @
|
|
196
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
197
|
+
* @returns Promise<StrapiResponse<T>>
|
|
167
198
|
*/
|
|
168
|
-
create<T>(contentType: string, data: AxiosRequestConfig["data"]): Promise<T
|
|
199
|
+
create<T>(contentType: string, data: AxiosRequestConfig["data"], params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
|
|
169
200
|
/**
|
|
170
201
|
* Update a specific entry
|
|
171
202
|
*
|
|
172
203
|
* @param {string} contentType - Content type's name pluralized
|
|
173
204
|
* @param {string|number} id - ID of entry to be updated
|
|
174
205
|
* @param {AxiosRequestConfig["data"]} data - New entry data
|
|
175
|
-
* @
|
|
206
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
207
|
+
* @returns Promise<StrapiResponse<T>>
|
|
176
208
|
*/
|
|
177
|
-
update<T>(contentType: string, id: string | number, data: AxiosRequestConfig["data"]): Promise<T
|
|
209
|
+
update<T>(contentType: string, id: string | number, data: AxiosRequestConfig["data"], params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
|
|
178
210
|
/**
|
|
179
211
|
* Delete en entry
|
|
180
212
|
*
|
|
181
213
|
* @param {string} contentType - Content type's name pluralized
|
|
182
214
|
* @param {string|number} id - ID of entry to be deleted
|
|
183
|
-
* @
|
|
215
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
216
|
+
* @returns Promise<StrapiResponse<T>>
|
|
184
217
|
*/
|
|
185
|
-
delete<T>(contentType: string, id: string | number): Promise<T
|
|
218
|
+
delete<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
|
|
186
219
|
/**
|
|
187
220
|
* Define local data of the logged-in user
|
|
188
221
|
*
|
|
@@ -217,4 +250,4 @@ declare class Strapi {
|
|
|
217
250
|
removeToken(): void;
|
|
218
251
|
}
|
|
219
252
|
|
|
220
|
-
export { StoreConfig, StrapiAuthProvider, StrapiAuthenticationData, StrapiAuthenticationResponse, StrapiDefaultOptions, StrapiEmailConfirmationData, StrapiForgotPasswordData, StrapiOptions, StrapiRegistrationData, StrapiResetPasswordData, Strapi as default };
|
|
253
|
+
export { PaginationByOffset, PaginationByPage, StoreConfig, StrapiAuthProvider, StrapiAuthenticationData, StrapiAuthenticationResponse, StrapiBaseRequestParams, StrapiDefaultOptions, StrapiEmailConfirmationData, StrapiError, StrapiForgotPasswordData, StrapiLocale, StrapiOptions, StrapiRegistrationData, StrapiRequestParams, StrapiResetPasswordData, StrapiResponse, StrapiUser, Strapi as default };
|
package/dist/index.es.js
CHANGED
|
@@ -9,6 +9,7 @@ function isBrowser() {
|
|
|
9
9
|
|
|
10
10
|
const defaults = {
|
|
11
11
|
url: process.env.STRAPI_URL || "http://localhost:1337",
|
|
12
|
+
prefix: "/api",
|
|
12
13
|
store: {
|
|
13
14
|
key: "strapi_jwt",
|
|
14
15
|
useLocalStorage: false,
|
|
@@ -21,7 +22,7 @@ class Strapi {
|
|
|
21
22
|
this._user = null;
|
|
22
23
|
this.options = defu(options || {}, defaults);
|
|
23
24
|
this.axios = axios.create({
|
|
24
|
-
baseURL: this.options.url,
|
|
25
|
+
baseURL: new URL(this.options.prefix, this.options.url).href,
|
|
25
26
|
paramsSerializer: qs.stringify,
|
|
26
27
|
...this.options.axiosOptions
|
|
27
28
|
});
|
|
@@ -45,27 +46,16 @@ class Strapi {
|
|
|
45
46
|
const e = error;
|
|
46
47
|
if (!e.response) {
|
|
47
48
|
throw {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let message;
|
|
55
|
-
if (Array.isArray(data.message)) {
|
|
56
|
-
if (data.message[0].hasOwnProperty("messages")) {
|
|
57
|
-
message = data.message[0].messages[0];
|
|
58
|
-
} else {
|
|
59
|
-
message = data.message[0];
|
|
49
|
+
data: null,
|
|
50
|
+
error: {
|
|
51
|
+
status: 500,
|
|
52
|
+
name: "UnknownError",
|
|
53
|
+
message: e.message,
|
|
54
|
+
details: e
|
|
60
55
|
}
|
|
61
|
-
} else {
|
|
62
|
-
message = data.message;
|
|
63
|
-
}
|
|
64
|
-
throw {
|
|
65
|
-
status,
|
|
66
|
-
message,
|
|
67
|
-
original: data
|
|
68
56
|
};
|
|
57
|
+
} else {
|
|
58
|
+
throw e.response.data;
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
61
|
}
|
|
@@ -129,29 +119,38 @@ class Strapi {
|
|
|
129
119
|
this.removeToken();
|
|
130
120
|
}
|
|
131
121
|
find(contentType, params) {
|
|
132
|
-
return this.request("get", `/${contentType}`, {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return this.request("get", `/${contentType}/${id}`);
|
|
122
|
+
return this.request("get", `/${contentType}`, {
|
|
123
|
+
params
|
|
124
|
+
});
|
|
136
125
|
}
|
|
137
|
-
|
|
138
|
-
return this.request("get", `/${contentType}
|
|
126
|
+
findOne(contentType, id, params) {
|
|
127
|
+
return this.request("get", `/${contentType}/${id}`, {
|
|
128
|
+
params
|
|
129
|
+
});
|
|
139
130
|
}
|
|
140
|
-
create(contentType, data) {
|
|
141
|
-
return this.request("post", `/${contentType}`, {
|
|
131
|
+
create(contentType, data, params) {
|
|
132
|
+
return this.request("post", `/${contentType}`, {
|
|
133
|
+
data: { data },
|
|
134
|
+
params
|
|
135
|
+
});
|
|
142
136
|
}
|
|
143
|
-
update(contentType, id, data) {
|
|
144
|
-
return this.request("put", `/${contentType}/${id}`, {
|
|
137
|
+
update(contentType, id, data, params) {
|
|
138
|
+
return this.request("put", `/${contentType}/${id}`, {
|
|
139
|
+
data: { data },
|
|
140
|
+
params
|
|
141
|
+
});
|
|
145
142
|
}
|
|
146
|
-
delete(contentType, id) {
|
|
147
|
-
return this.request("delete", `/${contentType}/${id}
|
|
143
|
+
delete(contentType, id, params) {
|
|
144
|
+
return this.request("delete", `/${contentType}/${id}`, {
|
|
145
|
+
params
|
|
146
|
+
});
|
|
148
147
|
}
|
|
149
148
|
setUser(user) {
|
|
150
149
|
this._user = user;
|
|
151
150
|
}
|
|
152
151
|
async fetchUser() {
|
|
153
152
|
try {
|
|
154
|
-
const user = await this.
|
|
153
|
+
const user = await this.request("get", "/users/me");
|
|
155
154
|
this.setUser(user);
|
|
156
155
|
} catch (e) {
|
|
157
156
|
this.logout();
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ function isBrowser() {
|
|
|
18
18
|
|
|
19
19
|
const defaults = {
|
|
20
20
|
url: process.env.STRAPI_URL || "http://localhost:1337",
|
|
21
|
+
prefix: "/api",
|
|
21
22
|
store: {
|
|
22
23
|
key: "strapi_jwt",
|
|
23
24
|
useLocalStorage: false,
|
|
@@ -30,7 +31,7 @@ class Strapi {
|
|
|
30
31
|
this._user = null;
|
|
31
32
|
this.options = defu__default["default"](options || {}, defaults);
|
|
32
33
|
this.axios = axios__default["default"].create({
|
|
33
|
-
baseURL: this.options.url,
|
|
34
|
+
baseURL: new URL(this.options.prefix, this.options.url).href,
|
|
34
35
|
paramsSerializer: qs__default["default"].stringify,
|
|
35
36
|
...this.options.axiosOptions
|
|
36
37
|
});
|
|
@@ -54,27 +55,16 @@ class Strapi {
|
|
|
54
55
|
const e = error;
|
|
55
56
|
if (!e.response) {
|
|
56
57
|
throw {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let message;
|
|
64
|
-
if (Array.isArray(data.message)) {
|
|
65
|
-
if (data.message[0].hasOwnProperty("messages")) {
|
|
66
|
-
message = data.message[0].messages[0];
|
|
67
|
-
} else {
|
|
68
|
-
message = data.message[0];
|
|
58
|
+
data: null,
|
|
59
|
+
error: {
|
|
60
|
+
status: 500,
|
|
61
|
+
name: "UnknownError",
|
|
62
|
+
message: e.message,
|
|
63
|
+
details: e
|
|
69
64
|
}
|
|
70
|
-
} else {
|
|
71
|
-
message = data.message;
|
|
72
|
-
}
|
|
73
|
-
throw {
|
|
74
|
-
status,
|
|
75
|
-
message,
|
|
76
|
-
original: data
|
|
77
65
|
};
|
|
66
|
+
} else {
|
|
67
|
+
throw e.response.data;
|
|
78
68
|
}
|
|
79
69
|
}
|
|
80
70
|
}
|
|
@@ -138,29 +128,38 @@ class Strapi {
|
|
|
138
128
|
this.removeToken();
|
|
139
129
|
}
|
|
140
130
|
find(contentType, params) {
|
|
141
|
-
return this.request("get", `/${contentType}`, {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return this.request("get", `/${contentType}/${id}`);
|
|
131
|
+
return this.request("get", `/${contentType}`, {
|
|
132
|
+
params
|
|
133
|
+
});
|
|
145
134
|
}
|
|
146
|
-
|
|
147
|
-
return this.request("get", `/${contentType}
|
|
135
|
+
findOne(contentType, id, params) {
|
|
136
|
+
return this.request("get", `/${contentType}/${id}`, {
|
|
137
|
+
params
|
|
138
|
+
});
|
|
148
139
|
}
|
|
149
|
-
create(contentType, data) {
|
|
150
|
-
return this.request("post", `/${contentType}`, {
|
|
140
|
+
create(contentType, data, params) {
|
|
141
|
+
return this.request("post", `/${contentType}`, {
|
|
142
|
+
data: { data },
|
|
143
|
+
params
|
|
144
|
+
});
|
|
151
145
|
}
|
|
152
|
-
update(contentType, id, data) {
|
|
153
|
-
return this.request("put", `/${contentType}/${id}`, {
|
|
146
|
+
update(contentType, id, data, params) {
|
|
147
|
+
return this.request("put", `/${contentType}/${id}`, {
|
|
148
|
+
data: { data },
|
|
149
|
+
params
|
|
150
|
+
});
|
|
154
151
|
}
|
|
155
|
-
delete(contentType, id) {
|
|
156
|
-
return this.request("delete", `/${contentType}/${id}
|
|
152
|
+
delete(contentType, id, params) {
|
|
153
|
+
return this.request("delete", `/${contentType}/${id}`, {
|
|
154
|
+
params
|
|
155
|
+
});
|
|
157
156
|
}
|
|
158
157
|
setUser(user) {
|
|
159
158
|
this._user = user;
|
|
160
159
|
}
|
|
161
160
|
async fetchUser() {
|
|
162
161
|
try {
|
|
163
|
-
const user = await this.
|
|
162
|
+
const user = await this.request("get", "/users/me");
|
|
164
163
|
this.setUser(user);
|
|
165
164
|
} catch (e) {
|
|
166
165
|
this.logout();
|