strapi-sdk-js 1.0.2 → 2.1.1

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 CHANGED
@@ -1,3 +1,38 @@
1
+ ## [2.1.1](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.0...v2.1.1) (2021-11-29)
2
+
3
+ # [2.0.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.1.0...v2.0.0) (2021-11-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * **Strapi v4 support**
9
+ * add params to create, update, delete methods in order to selecting field in response ([a693dac](https://github.com/Stun3R/strapi-sdk-js/commit/a693dac21101260125db8672229644387b2ee3e4))
10
+ * add StrapiLocale type for better autocompletion ([583c5b8](https://github.com/Stun3R/strapi-sdk-js/commit/583c5b8d561426c581f31ed6d335fc322411be71))
11
+ * replace axios request config params by custom type based on strapi rest api parameters ([2047433](https://github.com/Stun3R/strapi-sdk-js/commit/2047433f93aaae9b4eaeb0c7f4b49cccfb46f770))
12
+ * v4 error handling ([4d0eb3f](https://github.com/Stun3R/strapi-sdk-js/commit/4d0eb3f50ed9796e7dd3837cd45a2d926e9679d5))
13
+
14
+ # [1.1.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.2...v1.1.0) (2021-10-19)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * add axioserror type on error ([1140bbb](https://github.com/Stun3R/strapi-sdk-js/commit/1140bbb990c37e492aa8d457a1e65ff5a0ac24ed))
20
+ * **deps:** update dependency @types/js-cookie to v3 ([88483aa](https://github.com/Stun3R/strapi-sdk-js/commit/88483aa0ff841c440716bbe1014ff8a6ef58c27f))
21
+ * **deps:** update dependency axios to ^0.23.0 ([854e84e](https://github.com/Stun3R/strapi-sdk-js/commit/854e84e02cdb818a69dddfecb8c1530f791609c4))
22
+ * missing comma after dependencies ([6efe03b](https://github.com/Stun3R/strapi-sdk-js/commit/6efe03b1713c5df97a077d3c5db43022d3fcc3f6))
23
+ * **tests:** switch response type to follow latest change ([362b5d9](https://github.com/Stun3R/strapi-sdk-js/commit/362b5d911ffb9fbeb37de7678dd60b97c7dbf2f6))
24
+
25
+
26
+ ### Code Refactoring
27
+
28
+ * drop of graphql methods support ([eebd7a3](https://github.com/Stun3R/strapi-sdk-js/commit/eebd7a34ddbce216ba0e8b3f5a3f95c0a0a5add5))
29
+
30
+
31
+ ### BREAKING CHANGES
32
+
33
+ * SDK supports Strapi v4. Every CRUD methods response changed. Please refer to [documentation](https://strapi-sdk-js.netlify.app)
34
+ * GraphQL is no longer supported in v1.1.0
35
+
1
36
  ## [1.0.2](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.1...v1.0.2) (2021-08-30)
2
37
 
3
38
 
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>;
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,58 +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 {AxiosRequestConfig["params"]} params? - Filter and order queries
142
- * @returns Promise<T>
178
+ * @param {StrapiRequestParams} params? - Query parameters
179
+ * @returns Promise<StrapiResponse<T>>
143
180
  */
144
- find<T>(contentType: string, params?: AxiosRequestConfig["params"]): Promise<T>;
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
- * @returns Promise<T>
151
- */
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>
187
+ * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
188
+ * @returns Promise<StrapiResponse<T>>
159
189
  */
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
- * @returns Promise<T>
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
- * @returns Promise<T>
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
- * @returns Promise<T>
184
- */
185
- delete<T>(contentType: string, id: string | number): Promise<T>;
186
- /**
187
- * Fetch Strapi API through graphQL
188
- *
189
- * @param {AxiosRequestConfig["data"]} query - GraphQL Query
190
- * @returns Promise<T>
215
+ * @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
216
+ * @returns Promise<StrapiResponse<T>>
191
217
  */
192
- graphql<T>(query: AxiosRequestConfig["data"]): Promise<T>;
218
+ delete<T>(contentType: string, id: string | number, params?: StrapiBaseRequestParams): Promise<StrapiResponse<T>>;
193
219
  /**
194
220
  * Define local data of the logged-in user
195
221
  *
@@ -224,4 +250,4 @@ declare class Strapi {
224
250
  removeToken(): void;
225
251
  }
226
252
 
227
- 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
  });
@@ -42,29 +43,19 @@ class Strapi {
42
43
  });
43
44
  return response.data;
44
45
  } catch (error) {
45
- if (!error.response) {
46
+ const e = error;
47
+ if (!e.response) {
46
48
  throw {
47
- status: 500,
48
- message: error.message,
49
- original: error
50
- };
51
- } else {
52
- const { status, data } = error.response;
53
- let message;
54
- if (Array.isArray(data.message)) {
55
- if (data.message[0].hasOwnProperty("messages")) {
56
- message = data.message[0].messages[0];
57
- } else {
58
- message = data.message[0];
49
+ data: null,
50
+ error: {
51
+ status: 500,
52
+ name: "UnknownError",
53
+ message: e.message,
54
+ details: e
59
55
  }
60
- } else {
61
- message = data.message;
62
- }
63
- throw {
64
- status,
65
- message,
66
- original: data
67
56
  };
57
+ } else {
58
+ throw e.response.data;
68
59
  }
69
60
  }
70
61
  }
@@ -128,36 +119,38 @@ class Strapi {
128
119
  this.removeToken();
129
120
  }
130
121
  find(contentType, params) {
131
- return this.request("get", `/${contentType}`, { params });
132
- }
133
- findOne(contentType, id) {
134
- return this.request("get", `/${contentType}/${id}`);
135
- }
136
- count(contentType, params) {
137
- return this.request("get", `/${contentType}/count`, { params });
122
+ return this.request("get", `/${contentType}`, {
123
+ params
124
+ });
138
125
  }
139
- create(contentType, data) {
140
- return this.request("post", `/${contentType}`, { data });
126
+ findOne(contentType, id, params) {
127
+ return this.request("get", `/${contentType}/${id}`, {
128
+ params
129
+ });
141
130
  }
142
- update(contentType, id, data) {
143
- return this.request("put", `/${contentType}/${id}`, { data });
131
+ create(contentType, data, params) {
132
+ return this.request("post", `/${contentType}`, {
133
+ data: { data },
134
+ params
135
+ });
144
136
  }
145
- delete(contentType, id) {
146
- return this.request("delete", `/${contentType}/${id}`);
137
+ update(contentType, id, data, params) {
138
+ return this.request("put", `/${contentType}/${id}`, {
139
+ data: { data },
140
+ params
141
+ });
147
142
  }
148
- async graphql(query) {
149
- const response = await this.request("post", "/graphql", {
150
- data: query
143
+ delete(contentType, id, params) {
144
+ return this.request("delete", `/${contentType}/${id}`, {
145
+ params
151
146
  });
152
- response.data = Object.values(response.data)[0];
153
- return response.data;
154
147
  }
155
148
  setUser(user) {
156
149
  this._user = user;
157
150
  }
158
151
  async fetchUser() {
159
152
  try {
160
- const user = await this.findOne("users", "me");
153
+ const user = await this.request("get", "/users/me");
161
154
  this.setUser(user);
162
155
  } catch (e) {
163
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,
@@ -28,10 +29,10 @@ const defaults = {
28
29
  class Strapi {
29
30
  constructor(options) {
30
31
  this._user = null;
31
- this.options = defu__default['default'](options || {}, defaults);
32
- this.axios = axios__default['default'].create({
33
- baseURL: this.options.url,
34
- paramsSerializer: qs__default['default'].stringify,
32
+ this.options = defu__default["default"](options || {}, defaults);
33
+ this.axios = axios__default["default"].create({
34
+ baseURL: new URL(this.options.prefix, this.options.url).href,
35
+ paramsSerializer: qs__default["default"].stringify,
35
36
  ...this.options.axiosOptions
36
37
  });
37
38
  this.syncToken();
@@ -51,29 +52,19 @@ class Strapi {
51
52
  });
52
53
  return response.data;
53
54
  } catch (error) {
54
- if (!error.response) {
55
+ const e = error;
56
+ if (!e.response) {
55
57
  throw {
56
- status: 500,
57
- message: error.message,
58
- original: error
59
- };
60
- } else {
61
- const { status, data } = error.response;
62
- let message;
63
- if (Array.isArray(data.message)) {
64
- if (data.message[0].hasOwnProperty("messages")) {
65
- message = data.message[0].messages[0];
66
- } else {
67
- message = data.message[0];
58
+ data: null,
59
+ error: {
60
+ status: 500,
61
+ name: "UnknownError",
62
+ message: e.message,
63
+ details: e
68
64
  }
69
- } else {
70
- message = data.message;
71
- }
72
- throw {
73
- status,
74
- message,
75
- original: data
76
65
  };
66
+ } else {
67
+ throw e.response.data;
77
68
  }
78
69
  }
79
70
  }
@@ -119,7 +110,7 @@ class Strapi {
119
110
  async authenticateProvider(provider, access_token) {
120
111
  this.removeToken();
121
112
  if (isBrowser()) {
122
- const params = qs__default['default'].parse(window.location.search, {
113
+ const params = qs__default["default"].parse(window.location.search, {
123
114
  ignoreQueryPrefix: true
124
115
  });
125
116
  if (params.access_token)
@@ -137,36 +128,38 @@ class Strapi {
137
128
  this.removeToken();
138
129
  }
139
130
  find(contentType, params) {
140
- return this.request("get", `/${contentType}`, { params });
141
- }
142
- findOne(contentType, id) {
143
- return this.request("get", `/${contentType}/${id}`);
144
- }
145
- count(contentType, params) {
146
- return this.request("get", `/${contentType}/count`, { params });
131
+ return this.request("get", `/${contentType}`, {
132
+ params
133
+ });
147
134
  }
148
- create(contentType, data) {
149
- return this.request("post", `/${contentType}`, { data });
135
+ findOne(contentType, id, params) {
136
+ return this.request("get", `/${contentType}/${id}`, {
137
+ params
138
+ });
150
139
  }
151
- update(contentType, id, data) {
152
- return this.request("put", `/${contentType}/${id}`, { data });
140
+ create(contentType, data, params) {
141
+ return this.request("post", `/${contentType}`, {
142
+ data: { data },
143
+ params
144
+ });
153
145
  }
154
- delete(contentType, id) {
155
- return this.request("delete", `/${contentType}/${id}`);
146
+ update(contentType, id, data, params) {
147
+ return this.request("put", `/${contentType}/${id}`, {
148
+ data: { data },
149
+ params
150
+ });
156
151
  }
157
- async graphql(query) {
158
- const response = await this.request("post", "/graphql", {
159
- data: query
152
+ delete(contentType, id, params) {
153
+ return this.request("delete", `/${contentType}/${id}`, {
154
+ params
160
155
  });
161
- response.data = Object.values(response.data)[0];
162
- return response.data;
163
156
  }
164
157
  setUser(user) {
165
158
  this._user = user;
166
159
  }
167
160
  async fetchUser() {
168
161
  try {
169
- const user = await this.findOne("users", "me");
162
+ const user = await this.request("get", "/users/me");
170
163
  this.setUser(user);
171
164
  } catch (e) {
172
165
  this.logout();
@@ -176,7 +169,7 @@ class Strapi {
176
169
  syncToken() {
177
170
  const { useLocalStorage, key } = this.options.store;
178
171
  if (isBrowser()) {
179
- const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies__default['default'].get(key);
172
+ const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies__default["default"].get(key);
180
173
  if (token) {
181
174
  this.axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
182
175
  }
@@ -186,14 +179,14 @@ class Strapi {
186
179
  const { useLocalStorage, key, cookieOptions } = this.options.store;
187
180
  this.axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
188
181
  if (isBrowser()) {
189
- useLocalStorage ? window.localStorage.setItem(key, token) : Cookies__default['default'].set(key, token, cookieOptions);
182
+ useLocalStorage ? window.localStorage.setItem(key, token) : Cookies__default["default"].set(key, token, cookieOptions);
190
183
  }
191
184
  }
192
185
  removeToken() {
193
186
  const { useLocalStorage, key } = this.options.store;
194
187
  delete this.axios.defaults.headers.common["Authorization"];
195
188
  if (isBrowser()) {
196
- useLocalStorage ? window.localStorage.removeItem(key) : Cookies__default['default'].remove(key);
189
+ useLocalStorage ? window.localStorage.removeItem(key) : Cookies__default["default"].remove(key);
197
190
  }
198
191
  }
199
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-sdk-js",
3
- "version": "1.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "📦 Javascript SDK for your Strapi API",
5
5
  "keywords": [
6
6
  "strapi",
@@ -12,7 +12,6 @@
12
12
  "http",
13
13
  "rest",
14
14
  "restful",
15
- "graphqL",
16
15
  "javascript"
17
16
  ],
18
17
  "homepage": "https://strapi-sdk-js.netlify.app",
@@ -70,33 +69,33 @@
70
69
  }
71
70
  },
72
71
  "dependencies": {
73
- "@types/js-cookie": "^2.2.6",
72
+ "@types/js-cookie": "^3.0.0",
74
73
  "@types/qs": "^6.9.6",
75
- "axios": "^0.21.1",
74
+ "axios": "^0.23.0",
76
75
  "defu": "^5.0.0",
77
76
  "js-cookie": "^3.0.0",
78
77
  "qs": "^6.10.1"
79
78
  },
80
79
  "devDependencies": {
81
- "@commitlint/cli": "13.1.0",
82
- "@commitlint/config-conventional": "13.1.0",
80
+ "@commitlint/cli": "13.2.1",
81
+ "@commitlint/config-conventional": "13.2.0",
83
82
  "@release-it/conventional-changelog": "3.3.0",
84
- "@types/jest": "27.0.1",
85
- "@types/sinon": "10.0.2",
86
- "@typescript-eslint/eslint-plugin": "4.30.0",
87
- "@typescript-eslint/parser": "4.30.0",
83
+ "@types/jest": "27.0.2",
84
+ "@types/sinon": "10.0.4",
85
+ "@typescript-eslint/eslint-plugin": "5.1.0",
86
+ "@typescript-eslint/parser": "5.1.0",
88
87
  "commitizen": "4.2.4",
89
88
  "cz-conventional-changelog": "3.3.0",
90
89
  "dotenv-cli": "4.0.0",
91
- "eslint": "7.32.0",
90
+ "eslint": "8.0.1",
92
91
  "husky": "7.0.2",
93
- "jest": "27.1.0",
94
- "lint-staged": "11.1.2",
92
+ "jest": "27.3.1",
93
+ "lint-staged": "11.2.3",
95
94
  "npm-run-all": "4.1.5",
96
- "release-it": "14.11.5",
95
+ "release-it": "14.11.6",
97
96
  "sinon": "11.1.2",
98
97
  "siroc": "0.16.0",
99
- "ts-jest": "27.0.5",
100
- "typescript": "4.3.5"
98
+ "ts-jest": "27.0.7",
99
+ "typescript": "4.4.4"
101
100
  }
102
101
  }