strapi-sdk-js 2.2.0 → 2.3.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/dist/index.cjs +212 -30
- package/dist/index.d.ts +19 -3
- package/dist/index.mjs +202 -13
- package/package.json +33 -25
- package/CHANGELOG.md +0 -100
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
const axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
11
|
-
const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
|
|
12
|
-
const qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
13
|
-
const Cookies__default = /*#__PURE__*/_interopDefaultLegacy(Cookies);
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
var defu = require('defu');
|
|
5
|
+
var qs = require('qs');
|
|
6
|
+
var Cookies = require('js-cookie');
|
|
7
|
+
var ufo = require('ufo');
|
|
14
8
|
|
|
15
9
|
function isBrowser() {
|
|
16
10
|
return typeof window !== "undefined";
|
|
17
11
|
}
|
|
18
12
|
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __publicField = (obj, key, value) => {
|
|
16
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
19
|
const defaults = {
|
|
20
20
|
url: "http://localhost:1337",
|
|
21
21
|
prefix: "/api",
|
|
@@ -27,12 +27,28 @@ const defaults = {
|
|
|
27
27
|
axiosOptions: {}
|
|
28
28
|
};
|
|
29
29
|
class Strapi {
|
|
30
|
+
/**
|
|
31
|
+
* Strapi SDK Constructor
|
|
32
|
+
*
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param {StrapiOptions} options? - Options in order to configure API URL, list your Content Types & extend the axios configuration
|
|
35
|
+
* @param {string} options.url? - Your Strapi API URL, Default: http://localhost::1337
|
|
36
|
+
* @param {StoreConfig} options.store? - Config the way you want to store JWT (Cookie or LocalStorage)
|
|
37
|
+
* @param {AxiosRequestConfig} options.axiosOptions? - The list of your Content type on your Strapi API
|
|
38
|
+
*/
|
|
30
39
|
constructor(options) {
|
|
31
|
-
this
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
__publicField(this, "axios");
|
|
41
|
+
__publicField(this, "options");
|
|
42
|
+
__publicField(this, "user", null);
|
|
43
|
+
const _options = defu(options || {}, defaults);
|
|
44
|
+
this.options = {
|
|
45
|
+
..._options,
|
|
46
|
+
url: ufo.cleanDoubleSlashes(_options == null ? void 0 : _options.url),
|
|
47
|
+
prefix: ufo.cleanDoubleSlashes(_options == null ? void 0 : _options.prefix)
|
|
48
|
+
};
|
|
49
|
+
this.axios = axios.create({
|
|
50
|
+
baseURL: ufo.joinURL(this.options.url, this.options.prefix),
|
|
51
|
+
paramsSerializer: qs.stringify,
|
|
36
52
|
...this.options.axiosOptions
|
|
37
53
|
});
|
|
38
54
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -46,6 +62,14 @@ class Strapi {
|
|
|
46
62
|
return config;
|
|
47
63
|
});
|
|
48
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Basic axios request
|
|
67
|
+
*
|
|
68
|
+
* @param {Method} method - HTTP method
|
|
69
|
+
* @param {string} url - Custom or Strapi API URL
|
|
70
|
+
* @param {AxiosRequestConfig} axiosConfig? - Custom Axios config
|
|
71
|
+
* @returns Promise<T>
|
|
72
|
+
*/
|
|
49
73
|
async request(method, url, axiosConfig) {
|
|
50
74
|
try {
|
|
51
75
|
const response = await this.axios.request({
|
|
@@ -71,6 +95,14 @@ class Strapi {
|
|
|
71
95
|
}
|
|
72
96
|
}
|
|
73
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Authenticate user & retrieve his JWT
|
|
100
|
+
*
|
|
101
|
+
* @param {StrapiAuthenticationData} data - User authentication form data: `identifier`, `password`
|
|
102
|
+
* @param {string} data.identifier - The email or username of the user
|
|
103
|
+
* @param {string} data.password - The password of the user
|
|
104
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
105
|
+
*/
|
|
74
106
|
async login(data) {
|
|
75
107
|
this.removeToken();
|
|
76
108
|
const { user, jwt } = await this.request("post", "/auth/local", {
|
|
@@ -80,83 +112,217 @@ class Strapi {
|
|
|
80
112
|
this.user = user;
|
|
81
113
|
return { user, jwt };
|
|
82
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Register a new user & retrieve JWT
|
|
117
|
+
*
|
|
118
|
+
* @param {StrapiRegistrationData} data - New user registration data: `username`, `email`, `password`
|
|
119
|
+
* @param {string} data.username - Username of the new user
|
|
120
|
+
* @param {string} data.email - Email of the new user
|
|
121
|
+
* @param {string} data.password - Password of the new user
|
|
122
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
123
|
+
*/
|
|
83
124
|
async register(data) {
|
|
84
125
|
this.removeToken();
|
|
85
|
-
const { user, jwt } = await this.request(
|
|
86
|
-
|
|
87
|
-
|
|
126
|
+
const { user, jwt } = await this.request(
|
|
127
|
+
"post",
|
|
128
|
+
"/auth/local/register",
|
|
129
|
+
{
|
|
130
|
+
data
|
|
131
|
+
}
|
|
132
|
+
);
|
|
88
133
|
this.setToken(jwt);
|
|
89
134
|
this.user = user;
|
|
90
135
|
return { user, jwt };
|
|
91
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Send an email to a user in order to reset his password
|
|
139
|
+
*
|
|
140
|
+
* @param {StrapiForgotPasswordData} data - Forgot password data: `email`
|
|
141
|
+
* @param {string} data.email - Email of the user who forgot his password
|
|
142
|
+
* @returns Promise<void>
|
|
143
|
+
*/
|
|
92
144
|
async forgotPassword(data) {
|
|
93
145
|
this.removeToken();
|
|
94
146
|
return this.request("post", "/auth/forgot-password", { data });
|
|
95
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Change the password of the logged in user.
|
|
150
|
+
* @author AnnikenYT
|
|
151
|
+
*
|
|
152
|
+
* @param {StrapiChangePasswordData} data - Change password data: `currentPassword`, `password`, `passwordConfirmation`
|
|
153
|
+
* @param {string} data.currentPassword - The current password of the user
|
|
154
|
+
* @param {string} data.password - The new password of the user
|
|
155
|
+
* @param {string} data.passwordConfirmation - Confirmation of the new password of the user
|
|
156
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
157
|
+
*/
|
|
158
|
+
async changePassword(data) {
|
|
159
|
+
const { user, jwt } = await this.request(
|
|
160
|
+
"post",
|
|
161
|
+
"/auth/change-password",
|
|
162
|
+
{
|
|
163
|
+
data
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
this.setToken(jwt);
|
|
167
|
+
this.user = user;
|
|
168
|
+
return { jwt, user };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reset the user password
|
|
172
|
+
*
|
|
173
|
+
* @param {StrapiResetPasswordData} data - Reset password data object: `code`, `password`, `passwordConfirmation`
|
|
174
|
+
* @param {string} data.code - Code received by email after calling the `forgotPassword` method
|
|
175
|
+
* @param {string} data.password - New password of the user
|
|
176
|
+
* @param {string} data.passwordConfirmation - Confirmation of the new password of the user
|
|
177
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
178
|
+
*/
|
|
96
179
|
async resetPassword(data) {
|
|
97
180
|
this.removeToken();
|
|
98
|
-
const { user, jwt } = await this.request(
|
|
99
|
-
|
|
100
|
-
|
|
181
|
+
const { user, jwt } = await this.request(
|
|
182
|
+
"post",
|
|
183
|
+
"/auth/reset-password",
|
|
184
|
+
{
|
|
185
|
+
data
|
|
186
|
+
}
|
|
187
|
+
);
|
|
101
188
|
this.setToken(jwt);
|
|
102
189
|
this.user = user;
|
|
103
190
|
return { user, jwt };
|
|
104
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Send programmatically an email to a user in order to confirm his account
|
|
194
|
+
*
|
|
195
|
+
* @param {StrapiEmailConfirmationData} data - Email confirmation data: `email`
|
|
196
|
+
* @param {string} data.email - Email of the user who want to be confirmed
|
|
197
|
+
* @returns Promise<void>
|
|
198
|
+
*/
|
|
105
199
|
async sendEmailConfirmation(data) {
|
|
106
200
|
return this.request("post", "/auth/send-email-confirmation", {
|
|
107
201
|
data
|
|
108
202
|
});
|
|
109
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the correct URL to authenticate with provider
|
|
206
|
+
*
|
|
207
|
+
* @param {StrapiAuthProvider} provider - Provider name
|
|
208
|
+
* @returns string
|
|
209
|
+
*/
|
|
110
210
|
getProviderAuthenticationUrl(provider) {
|
|
111
|
-
return
|
|
211
|
+
return ufo.joinURL(
|
|
212
|
+
this.options.url,
|
|
213
|
+
this.options.prefix,
|
|
214
|
+
"connect",
|
|
215
|
+
provider
|
|
216
|
+
);
|
|
112
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Authenticate user with the token present on the URL or in `params`
|
|
220
|
+
*
|
|
221
|
+
* @param {StrapiAuthProvider} provider - Provider name
|
|
222
|
+
* @param {string} access_token? - Access Token return from Strapi
|
|
223
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
224
|
+
*/
|
|
113
225
|
async authenticateProvider(provider, access_token) {
|
|
114
226
|
this.removeToken();
|
|
115
227
|
if (isBrowser()) {
|
|
116
|
-
const params =
|
|
228
|
+
const params = qs.parse(window.location.search, {
|
|
117
229
|
ignoreQueryPrefix: true
|
|
118
230
|
});
|
|
119
231
|
if (params.access_token)
|
|
120
232
|
access_token = params.access_token;
|
|
121
233
|
}
|
|
122
|
-
const { user, jwt } = await this.request(
|
|
123
|
-
|
|
124
|
-
|
|
234
|
+
const { user, jwt } = await this.request(
|
|
235
|
+
"get",
|
|
236
|
+
`/auth/${provider}/callback`,
|
|
237
|
+
{
|
|
238
|
+
params: { access_token }
|
|
239
|
+
}
|
|
240
|
+
);
|
|
125
241
|
this.setToken(jwt);
|
|
126
242
|
this.user = user;
|
|
127
243
|
return { user, jwt };
|
|
128
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Logout by removing authentication token
|
|
247
|
+
*
|
|
248
|
+
* @returns void
|
|
249
|
+
*/
|
|
129
250
|
logout() {
|
|
130
251
|
this.user = null;
|
|
131
252
|
this.removeToken();
|
|
132
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Get a list of {content-type} entries
|
|
256
|
+
*
|
|
257
|
+
* @param {string} contentType - Content type's name pluralized
|
|
258
|
+
* @param {StrapiRequestParams} params? - Query parameters
|
|
259
|
+
* @returns Promise<StrapiResponse<T>>
|
|
260
|
+
*/
|
|
133
261
|
find(contentType, params) {
|
|
134
262
|
return this.request("get", `/${contentType}`, {
|
|
135
263
|
params
|
|
136
264
|
});
|
|
137
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Get a specific {content-type} entry
|
|
268
|
+
*
|
|
269
|
+
* @param {string} contentType - Content type's name pluralized
|
|
270
|
+
* @param {string|number} id - ID of entry
|
|
271
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
272
|
+
* @returns Promise<StrapiResponse<T>>
|
|
273
|
+
*/
|
|
138
274
|
findOne(contentType, id, params) {
|
|
139
275
|
return this.request("get", `/${contentType}/${id}`, {
|
|
140
276
|
params
|
|
141
277
|
});
|
|
142
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Create a {content-type} entry
|
|
281
|
+
*
|
|
282
|
+
* @param {string} contentType - Content type's name pluralized
|
|
283
|
+
* @param {AxiosRequestConfig["data"]} data - New entry
|
|
284
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
285
|
+
* @returns Promise<StrapiResponse<T>>
|
|
286
|
+
*/
|
|
143
287
|
create(contentType, data, params) {
|
|
144
288
|
return this.request("post", `/${contentType}`, {
|
|
145
289
|
data: { data },
|
|
146
290
|
params
|
|
147
291
|
});
|
|
148
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Update a specific entry
|
|
295
|
+
*
|
|
296
|
+
* @param {string} contentType - Content type's name pluralized
|
|
297
|
+
* @param {string|number} id - ID of entry to be updated
|
|
298
|
+
* @param {AxiosRequestConfig["data"]} data - New entry data
|
|
299
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
300
|
+
* @returns Promise<StrapiResponse<T>>
|
|
301
|
+
*/
|
|
149
302
|
update(contentType, id, data, params) {
|
|
150
303
|
return this.request("put", `/${contentType}/${id}`, {
|
|
151
304
|
data: { data },
|
|
152
305
|
params
|
|
153
306
|
});
|
|
154
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Delete en entry
|
|
310
|
+
*
|
|
311
|
+
* @param {string} contentType - Content type's name pluralized
|
|
312
|
+
* @param {string|number} id - ID of entry to be deleted
|
|
313
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
314
|
+
* @returns Promise<StrapiResponse<T>>
|
|
315
|
+
*/
|
|
155
316
|
delete(contentType, id, params) {
|
|
156
317
|
return this.request("delete", `/${contentType}/${id}`, {
|
|
157
318
|
params
|
|
158
319
|
});
|
|
159
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Refresh local data of the logged-in user
|
|
323
|
+
*
|
|
324
|
+
* @returns Promise<StrapiUser>
|
|
325
|
+
*/
|
|
160
326
|
async fetchUser() {
|
|
161
327
|
try {
|
|
162
328
|
const user = await this.request("get", "/users/me");
|
|
@@ -166,26 +332,42 @@ class Strapi {
|
|
|
166
332
|
}
|
|
167
333
|
return this.user;
|
|
168
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Retrieve token from chosen storage
|
|
337
|
+
*
|
|
338
|
+
* @returns string | null
|
|
339
|
+
*/
|
|
169
340
|
getToken() {
|
|
170
341
|
const { useLocalStorage, key } = this.options.store;
|
|
171
342
|
if (isBrowser()) {
|
|
172
|
-
const token = useLocalStorage ? window.localStorage.getItem(key) :
|
|
343
|
+
const token = useLocalStorage ? window.localStorage.getItem(key) : Cookies.get(key);
|
|
173
344
|
if (typeof token === "undefined")
|
|
174
345
|
return null;
|
|
175
346
|
return token;
|
|
176
347
|
}
|
|
177
348
|
return null;
|
|
178
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Set token in chosen storage
|
|
352
|
+
*
|
|
353
|
+
* @param {string} token - Token retrieve from login or register method
|
|
354
|
+
* @returns void
|
|
355
|
+
*/
|
|
179
356
|
setToken(token) {
|
|
180
357
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
181
358
|
if (isBrowser()) {
|
|
182
|
-
useLocalStorage ? window.localStorage.setItem(key, token) :
|
|
359
|
+
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
183
360
|
}
|
|
184
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Remove token from chosen storage (Cookies or Local)
|
|
364
|
+
*
|
|
365
|
+
* @returns void
|
|
366
|
+
*/
|
|
185
367
|
removeToken() {
|
|
186
368
|
const { useLocalStorage, key } = this.options.store;
|
|
187
369
|
if (isBrowser()) {
|
|
188
|
-
useLocalStorage ? window.localStorage.removeItem(key) :
|
|
370
|
+
useLocalStorage ? window.localStorage.removeItem(key) : Cookies.remove(key);
|
|
189
371
|
}
|
|
190
372
|
}
|
|
191
373
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosInstance, Method } from 'axios';
|
|
2
2
|
import { CookieAttributes } from 'js-cookie';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type StrapiAuthProvider = "github" | "facebook" | "google" | "cognito" | "twitter" | "discord" | "twitch" | "instagram" | "vk" | "linkedin" | "reddit" | "auth0";
|
|
5
|
+
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";
|
|
6
6
|
interface StoreConfig {
|
|
7
7
|
key: string;
|
|
8
8
|
useLocalStorage?: boolean;
|
|
@@ -20,7 +20,7 @@ interface StrapiDefaultOptions {
|
|
|
20
20
|
store: StoreConfig;
|
|
21
21
|
axiosOptions: AxiosRequestConfig;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
type StrapiUser = Record<string, unknown> | null;
|
|
24
24
|
interface PaginationByPage {
|
|
25
25
|
page: number;
|
|
26
26
|
pageSize: number;
|
|
@@ -71,6 +71,11 @@ interface StrapiRegistrationData {
|
|
|
71
71
|
interface StrapiForgotPasswordData {
|
|
72
72
|
email: string;
|
|
73
73
|
}
|
|
74
|
+
interface StrapiChangePasswordData {
|
|
75
|
+
currentPassword: string;
|
|
76
|
+
password: string;
|
|
77
|
+
passwordConfirmation: string;
|
|
78
|
+
}
|
|
74
79
|
interface StrapiResetPasswordData {
|
|
75
80
|
code: string;
|
|
76
81
|
password: string;
|
|
@@ -130,6 +135,17 @@ declare class Strapi {
|
|
|
130
135
|
* @returns Promise<void>
|
|
131
136
|
*/
|
|
132
137
|
forgotPassword(data: StrapiForgotPasswordData): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Change the password of the logged in user.
|
|
140
|
+
* @author AnnikenYT
|
|
141
|
+
*
|
|
142
|
+
* @param {StrapiChangePasswordData} data - Change password data: `currentPassword`, `password`, `passwordConfirmation`
|
|
143
|
+
* @param {string} data.currentPassword - The current password of the user
|
|
144
|
+
* @param {string} data.password - The new password of the user
|
|
145
|
+
* @param {string} data.passwordConfirmation - Confirmation of the new password of the user
|
|
146
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
147
|
+
*/
|
|
148
|
+
changePassword(data: StrapiChangePasswordData): Promise<StrapiAuthenticationResponse>;
|
|
133
149
|
/**
|
|
134
150
|
* Reset the user password
|
|
135
151
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,18 @@ import axios from 'axios';
|
|
|
2
2
|
import defu from 'defu';
|
|
3
3
|
import qs from 'qs';
|
|
4
4
|
import Cookies from 'js-cookie';
|
|
5
|
+
import ufo from 'ufo';
|
|
5
6
|
|
|
6
7
|
function isBrowser() {
|
|
7
8
|
return typeof window !== "undefined";
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __publicField = (obj, key, value) => {
|
|
14
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
10
17
|
const defaults = {
|
|
11
18
|
url: "http://localhost:1337",
|
|
12
19
|
prefix: "/api",
|
|
@@ -18,11 +25,27 @@ const defaults = {
|
|
|
18
25
|
axiosOptions: {}
|
|
19
26
|
};
|
|
20
27
|
class Strapi {
|
|
28
|
+
/**
|
|
29
|
+
* Strapi SDK Constructor
|
|
30
|
+
*
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {StrapiOptions} options? - Options in order to configure API URL, list your Content Types & extend the axios configuration
|
|
33
|
+
* @param {string} options.url? - Your Strapi API URL, Default: http://localhost::1337
|
|
34
|
+
* @param {StoreConfig} options.store? - Config the way you want to store JWT (Cookie or LocalStorage)
|
|
35
|
+
* @param {AxiosRequestConfig} options.axiosOptions? - The list of your Content type on your Strapi API
|
|
36
|
+
*/
|
|
21
37
|
constructor(options) {
|
|
22
|
-
this
|
|
23
|
-
this
|
|
38
|
+
__publicField(this, "axios");
|
|
39
|
+
__publicField(this, "options");
|
|
40
|
+
__publicField(this, "user", null);
|
|
41
|
+
const _options = defu(options || {}, defaults);
|
|
42
|
+
this.options = {
|
|
43
|
+
..._options,
|
|
44
|
+
url: ufo.cleanDoubleSlashes(_options == null ? void 0 : _options.url),
|
|
45
|
+
prefix: ufo.cleanDoubleSlashes(_options == null ? void 0 : _options.prefix)
|
|
46
|
+
};
|
|
24
47
|
this.axios = axios.create({
|
|
25
|
-
baseURL:
|
|
48
|
+
baseURL: ufo.joinURL(this.options.url, this.options.prefix),
|
|
26
49
|
paramsSerializer: qs.stringify,
|
|
27
50
|
...this.options.axiosOptions
|
|
28
51
|
});
|
|
@@ -37,6 +60,14 @@ class Strapi {
|
|
|
37
60
|
return config;
|
|
38
61
|
});
|
|
39
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Basic axios request
|
|
65
|
+
*
|
|
66
|
+
* @param {Method} method - HTTP method
|
|
67
|
+
* @param {string} url - Custom or Strapi API URL
|
|
68
|
+
* @param {AxiosRequestConfig} axiosConfig? - Custom Axios config
|
|
69
|
+
* @returns Promise<T>
|
|
70
|
+
*/
|
|
40
71
|
async request(method, url, axiosConfig) {
|
|
41
72
|
try {
|
|
42
73
|
const response = await this.axios.request({
|
|
@@ -62,6 +93,14 @@ class Strapi {
|
|
|
62
93
|
}
|
|
63
94
|
}
|
|
64
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Authenticate user & retrieve his JWT
|
|
98
|
+
*
|
|
99
|
+
* @param {StrapiAuthenticationData} data - User authentication form data: `identifier`, `password`
|
|
100
|
+
* @param {string} data.identifier - The email or username of the user
|
|
101
|
+
* @param {string} data.password - The password of the user
|
|
102
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
103
|
+
*/
|
|
65
104
|
async login(data) {
|
|
66
105
|
this.removeToken();
|
|
67
106
|
const { user, jwt } = await this.request("post", "/auth/local", {
|
|
@@ -71,36 +110,116 @@ class Strapi {
|
|
|
71
110
|
this.user = user;
|
|
72
111
|
return { user, jwt };
|
|
73
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Register a new user & retrieve JWT
|
|
115
|
+
*
|
|
116
|
+
* @param {StrapiRegistrationData} data - New user registration data: `username`, `email`, `password`
|
|
117
|
+
* @param {string} data.username - Username of the new user
|
|
118
|
+
* @param {string} data.email - Email of the new user
|
|
119
|
+
* @param {string} data.password - Password of the new user
|
|
120
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
121
|
+
*/
|
|
74
122
|
async register(data) {
|
|
75
123
|
this.removeToken();
|
|
76
|
-
const { user, jwt } = await this.request(
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
const { user, jwt } = await this.request(
|
|
125
|
+
"post",
|
|
126
|
+
"/auth/local/register",
|
|
127
|
+
{
|
|
128
|
+
data
|
|
129
|
+
}
|
|
130
|
+
);
|
|
79
131
|
this.setToken(jwt);
|
|
80
132
|
this.user = user;
|
|
81
133
|
return { user, jwt };
|
|
82
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Send an email to a user in order to reset his password
|
|
137
|
+
*
|
|
138
|
+
* @param {StrapiForgotPasswordData} data - Forgot password data: `email`
|
|
139
|
+
* @param {string} data.email - Email of the user who forgot his password
|
|
140
|
+
* @returns Promise<void>
|
|
141
|
+
*/
|
|
83
142
|
async forgotPassword(data) {
|
|
84
143
|
this.removeToken();
|
|
85
144
|
return this.request("post", "/auth/forgot-password", { data });
|
|
86
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Change the password of the logged in user.
|
|
148
|
+
* @author AnnikenYT
|
|
149
|
+
*
|
|
150
|
+
* @param {StrapiChangePasswordData} data - Change password data: `currentPassword`, `password`, `passwordConfirmation`
|
|
151
|
+
* @param {string} data.currentPassword - The current password of the user
|
|
152
|
+
* @param {string} data.password - The new password of the user
|
|
153
|
+
* @param {string} data.passwordConfirmation - Confirmation of the new password of the user
|
|
154
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
155
|
+
*/
|
|
156
|
+
async changePassword(data) {
|
|
157
|
+
const { user, jwt } = await this.request(
|
|
158
|
+
"post",
|
|
159
|
+
"/auth/change-password",
|
|
160
|
+
{
|
|
161
|
+
data
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
this.setToken(jwt);
|
|
165
|
+
this.user = user;
|
|
166
|
+
return { jwt, user };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Reset the user password
|
|
170
|
+
*
|
|
171
|
+
* @param {StrapiResetPasswordData} data - Reset password data object: `code`, `password`, `passwordConfirmation`
|
|
172
|
+
* @param {string} data.code - Code received by email after calling the `forgotPassword` method
|
|
173
|
+
* @param {string} data.password - New password of the user
|
|
174
|
+
* @param {string} data.passwordConfirmation - Confirmation of the new password of the user
|
|
175
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
176
|
+
*/
|
|
87
177
|
async resetPassword(data) {
|
|
88
178
|
this.removeToken();
|
|
89
|
-
const { user, jwt } = await this.request(
|
|
90
|
-
|
|
91
|
-
|
|
179
|
+
const { user, jwt } = await this.request(
|
|
180
|
+
"post",
|
|
181
|
+
"/auth/reset-password",
|
|
182
|
+
{
|
|
183
|
+
data
|
|
184
|
+
}
|
|
185
|
+
);
|
|
92
186
|
this.setToken(jwt);
|
|
93
187
|
this.user = user;
|
|
94
188
|
return { user, jwt };
|
|
95
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Send programmatically an email to a user in order to confirm his account
|
|
192
|
+
*
|
|
193
|
+
* @param {StrapiEmailConfirmationData} data - Email confirmation data: `email`
|
|
194
|
+
* @param {string} data.email - Email of the user who want to be confirmed
|
|
195
|
+
* @returns Promise<void>
|
|
196
|
+
*/
|
|
96
197
|
async sendEmailConfirmation(data) {
|
|
97
198
|
return this.request("post", "/auth/send-email-confirmation", {
|
|
98
199
|
data
|
|
99
200
|
});
|
|
100
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Get the correct URL to authenticate with provider
|
|
204
|
+
*
|
|
205
|
+
* @param {StrapiAuthProvider} provider - Provider name
|
|
206
|
+
* @returns string
|
|
207
|
+
*/
|
|
101
208
|
getProviderAuthenticationUrl(provider) {
|
|
102
|
-
return
|
|
209
|
+
return ufo.joinURL(
|
|
210
|
+
this.options.url,
|
|
211
|
+
this.options.prefix,
|
|
212
|
+
"connect",
|
|
213
|
+
provider
|
|
214
|
+
);
|
|
103
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Authenticate user with the token present on the URL or in `params`
|
|
218
|
+
*
|
|
219
|
+
* @param {StrapiAuthProvider} provider - Provider name
|
|
220
|
+
* @param {string} access_token? - Access Token return from Strapi
|
|
221
|
+
* @returns Promise<StrapiAuthenticationResponse>
|
|
222
|
+
*/
|
|
104
223
|
async authenticateProvider(provider, access_token) {
|
|
105
224
|
this.removeToken();
|
|
106
225
|
if (isBrowser()) {
|
|
@@ -110,44 +229,98 @@ class Strapi {
|
|
|
110
229
|
if (params.access_token)
|
|
111
230
|
access_token = params.access_token;
|
|
112
231
|
}
|
|
113
|
-
const { user, jwt } = await this.request(
|
|
114
|
-
|
|
115
|
-
|
|
232
|
+
const { user, jwt } = await this.request(
|
|
233
|
+
"get",
|
|
234
|
+
`/auth/${provider}/callback`,
|
|
235
|
+
{
|
|
236
|
+
params: { access_token }
|
|
237
|
+
}
|
|
238
|
+
);
|
|
116
239
|
this.setToken(jwt);
|
|
117
240
|
this.user = user;
|
|
118
241
|
return { user, jwt };
|
|
119
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Logout by removing authentication token
|
|
245
|
+
*
|
|
246
|
+
* @returns void
|
|
247
|
+
*/
|
|
120
248
|
logout() {
|
|
121
249
|
this.user = null;
|
|
122
250
|
this.removeToken();
|
|
123
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Get a list of {content-type} entries
|
|
254
|
+
*
|
|
255
|
+
* @param {string} contentType - Content type's name pluralized
|
|
256
|
+
* @param {StrapiRequestParams} params? - Query parameters
|
|
257
|
+
* @returns Promise<StrapiResponse<T>>
|
|
258
|
+
*/
|
|
124
259
|
find(contentType, params) {
|
|
125
260
|
return this.request("get", `/${contentType}`, {
|
|
126
261
|
params
|
|
127
262
|
});
|
|
128
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Get a specific {content-type} entry
|
|
266
|
+
*
|
|
267
|
+
* @param {string} contentType - Content type's name pluralized
|
|
268
|
+
* @param {string|number} id - ID of entry
|
|
269
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
270
|
+
* @returns Promise<StrapiResponse<T>>
|
|
271
|
+
*/
|
|
129
272
|
findOne(contentType, id, params) {
|
|
130
273
|
return this.request("get", `/${contentType}/${id}`, {
|
|
131
274
|
params
|
|
132
275
|
});
|
|
133
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Create a {content-type} entry
|
|
279
|
+
*
|
|
280
|
+
* @param {string} contentType - Content type's name pluralized
|
|
281
|
+
* @param {AxiosRequestConfig["data"]} data - New entry
|
|
282
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
283
|
+
* @returns Promise<StrapiResponse<T>>
|
|
284
|
+
*/
|
|
134
285
|
create(contentType, data, params) {
|
|
135
286
|
return this.request("post", `/${contentType}`, {
|
|
136
287
|
data: { data },
|
|
137
288
|
params
|
|
138
289
|
});
|
|
139
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Update a specific entry
|
|
293
|
+
*
|
|
294
|
+
* @param {string} contentType - Content type's name pluralized
|
|
295
|
+
* @param {string|number} id - ID of entry to be updated
|
|
296
|
+
* @param {AxiosRequestConfig["data"]} data - New entry data
|
|
297
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
298
|
+
* @returns Promise<StrapiResponse<T>>
|
|
299
|
+
*/
|
|
140
300
|
update(contentType, id, data, params) {
|
|
141
301
|
return this.request("put", `/${contentType}/${id}`, {
|
|
142
302
|
data: { data },
|
|
143
303
|
params
|
|
144
304
|
});
|
|
145
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Delete en entry
|
|
308
|
+
*
|
|
309
|
+
* @param {string} contentType - Content type's name pluralized
|
|
310
|
+
* @param {string|number} id - ID of entry to be deleted
|
|
311
|
+
* @param {StrapiBaseRequestParams} params? - Fields selection & Relations population
|
|
312
|
+
* @returns Promise<StrapiResponse<T>>
|
|
313
|
+
*/
|
|
146
314
|
delete(contentType, id, params) {
|
|
147
315
|
return this.request("delete", `/${contentType}/${id}`, {
|
|
148
316
|
params
|
|
149
317
|
});
|
|
150
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Refresh local data of the logged-in user
|
|
321
|
+
*
|
|
322
|
+
* @returns Promise<StrapiUser>
|
|
323
|
+
*/
|
|
151
324
|
async fetchUser() {
|
|
152
325
|
try {
|
|
153
326
|
const user = await this.request("get", "/users/me");
|
|
@@ -157,6 +330,11 @@ class Strapi {
|
|
|
157
330
|
}
|
|
158
331
|
return this.user;
|
|
159
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Retrieve token from chosen storage
|
|
335
|
+
*
|
|
336
|
+
* @returns string | null
|
|
337
|
+
*/
|
|
160
338
|
getToken() {
|
|
161
339
|
const { useLocalStorage, key } = this.options.store;
|
|
162
340
|
if (isBrowser()) {
|
|
@@ -167,12 +345,23 @@ class Strapi {
|
|
|
167
345
|
}
|
|
168
346
|
return null;
|
|
169
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Set token in chosen storage
|
|
350
|
+
*
|
|
351
|
+
* @param {string} token - Token retrieve from login or register method
|
|
352
|
+
* @returns void
|
|
353
|
+
*/
|
|
170
354
|
setToken(token) {
|
|
171
355
|
const { useLocalStorage, key, cookieOptions } = this.options.store;
|
|
172
356
|
if (isBrowser()) {
|
|
173
357
|
useLocalStorage ? window.localStorage.setItem(key, token) : Cookies.set(key, token, cookieOptions);
|
|
174
358
|
}
|
|
175
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Remove token from chosen storage (Cookies or Local)
|
|
362
|
+
*
|
|
363
|
+
* @returns void
|
|
364
|
+
*/
|
|
176
365
|
removeToken() {
|
|
177
366
|
const { useLocalStorage, key } = this.options.store;
|
|
178
367
|
if (isBrowser()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "📦 Javascript SDK for your Strapi API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|
|
40
40
|
"require": "./dist/index.cjs",
|
|
41
|
-
"import": "./dist/index.mjs"
|
|
41
|
+
"import": "./dist/index.mjs",
|
|
42
|
+
"types": "./dist/index.d.ts"
|
|
42
43
|
},
|
|
43
44
|
"./package.json": "./package.json"
|
|
44
45
|
},
|
|
@@ -49,8 +50,8 @@
|
|
|
49
50
|
"dist/"
|
|
50
51
|
],
|
|
51
52
|
"scripts": {
|
|
52
|
-
"start": "
|
|
53
|
-
"build": "
|
|
53
|
+
"start": "rollup -c --watch",
|
|
54
|
+
"build": "rollup -c",
|
|
54
55
|
"clean": "rm -rf bin dist coverage",
|
|
55
56
|
"lint": "eslint . --ext .ts,.js",
|
|
56
57
|
"lint:fix": "eslint . --ext .ts,.js --fix",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"test:unit": "jest",
|
|
59
60
|
"commit": "git-cz",
|
|
60
61
|
"release": "dotenv release-it --",
|
|
61
|
-
"prepare": "
|
|
62
|
+
"prepare": "rollup -c"
|
|
62
63
|
},
|
|
63
64
|
"lint-staged": {
|
|
64
65
|
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
|
|
@@ -71,31 +72,38 @@
|
|
|
71
72
|
"dependencies": {
|
|
72
73
|
"@types/js-cookie": "^3.0.0",
|
|
73
74
|
"@types/qs": "^6.9.6",
|
|
74
|
-
"axios": "^0.
|
|
75
|
+
"axios": "^0.27.0",
|
|
75
76
|
"defu": "^5.0.0",
|
|
76
77
|
"js-cookie": "^3.0.0",
|
|
77
|
-
"qs": "^6.10.1"
|
|
78
|
+
"qs": "^6.10.1",
|
|
79
|
+
"ufo": "^1.2.0"
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
|
-
"@commitlint/cli": "
|
|
81
|
-
"@commitlint/config-conventional": "
|
|
82
|
-
"@release-it/conventional-changelog": "4.
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"@
|
|
86
|
-
"@
|
|
87
|
-
"
|
|
82
|
+
"@commitlint/cli": "17.6.7",
|
|
83
|
+
"@commitlint/config-conventional": "17.6.7",
|
|
84
|
+
"@release-it/conventional-changelog": "4.3.0",
|
|
85
|
+
"@rollup/plugin-commonjs": "^25.0.3",
|
|
86
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
87
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
88
|
+
"@types/jest": "27.5.2",
|
|
89
|
+
"@types/sinon": "10.0.16",
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
91
|
+
"@typescript-eslint/parser": "5.62.0",
|
|
92
|
+
"commitizen": "4.3.0",
|
|
88
93
|
"cz-conventional-changelog": "3.3.0",
|
|
89
|
-
"dotenv-cli": "
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
+
"dotenv-cli": "7.2.1",
|
|
95
|
+
"esbuild": "^0.18.19",
|
|
96
|
+
"eslint": "8.46.0",
|
|
97
|
+
"husky": "8.0.3",
|
|
98
|
+
"jest": "27.5.1",
|
|
99
|
+
"lint-staged": "13.2.3",
|
|
94
100
|
"npm-run-all": "4.1.5",
|
|
95
|
-
"release-it": "14.
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
101
|
+
"release-it": "14.14.3",
|
|
102
|
+
"rollup": "^3.27.2",
|
|
103
|
+
"rollup-plugin-dts": "^5.3.1",
|
|
104
|
+
"rollup-plugin-esbuild": "^5.0.0",
|
|
105
|
+
"sinon": "15.2.0",
|
|
106
|
+
"ts-jest": "27.1.5",
|
|
107
|
+
"typescript": "5.1.6"
|
|
100
108
|
}
|
|
101
109
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# [2.2.0](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.5...v2.2.0) (2022-02-17)
|
|
2
|
-
|
|
3
|
-
## [2.1.5](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.4...v2.1.5) (2022-01-17)
|
|
4
|
-
|
|
5
|
-
## [2.1.4](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.3...v2.1.4) (2022-01-14)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* **options:** remove process usage in default to be compatible with more framework ([aaa162d](https://github.com/Stun3R/strapi-sdk-js/commit/aaa162d53bc656a149da8d2aacc9560a42a11d55))
|
|
11
|
-
|
|
12
|
-
## [2.1.3](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.2...v2.1.3) (2022-01-05)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Bug Fixes
|
|
16
|
-
|
|
17
|
-
* **deps:** pin dependencies ([2e6e5a9](https://github.com/Stun3R/strapi-sdk-js/commit/2e6e5a984e3c3bce226bdb0a55218d6707cc0488))
|
|
18
|
-
* **deps:** update dependency @nuxt/content-theme-docs to v0.11.1 ([1541e39](https://github.com/Stun3R/strapi-sdk-js/commit/1541e392bb9e70ee7cdc65fa1362358518c0d084))
|
|
19
|
-
* **deps:** update dependency axios to ^0.24.0 ([4e2a41d](https://github.com/Stun3R/strapi-sdk-js/commit/4e2a41d5a3ffca07cf502d488ce9caea809f4bbc))
|
|
20
|
-
|
|
21
|
-
## [2.1.2](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.1...v2.1.2) (2021-12-30)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Bug Fixes
|
|
25
|
-
|
|
26
|
-
* **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)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Features
|
|
30
|
-
|
|
31
|
-
* add integrations ([439b292](https://github.com/Stun3R/strapi-sdk-js/commit/439b2926e474c06a0e581f9af7c1ad08c5eb7282))
|
|
32
|
-
|
|
33
|
-
## [2.1.1](https://github.com/Stun3R/strapi-sdk-js/compare/v2.1.0...v2.1.1) (2021-11-29)
|
|
34
|
-
|
|
35
|
-
# [2.0.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.1.0...v2.0.0) (2021-11-08)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Features
|
|
39
|
-
|
|
40
|
-
* **Strapi v4 support**
|
|
41
|
-
* add params to create, update, delete methods in order to selecting field in response ([a693dac](https://github.com/Stun3R/strapi-sdk-js/commit/a693dac21101260125db8672229644387b2ee3e4))
|
|
42
|
-
* add StrapiLocale type for better autocompletion ([583c5b8](https://github.com/Stun3R/strapi-sdk-js/commit/583c5b8d561426c581f31ed6d335fc322411be71))
|
|
43
|
-
* replace axios request config params by custom type based on strapi rest api parameters ([2047433](https://github.com/Stun3R/strapi-sdk-js/commit/2047433f93aaae9b4eaeb0c7f4b49cccfb46f770))
|
|
44
|
-
* v4 error handling ([4d0eb3f](https://github.com/Stun3R/strapi-sdk-js/commit/4d0eb3f50ed9796e7dd3837cd45a2d926e9679d5))
|
|
45
|
-
|
|
46
|
-
# [1.1.0](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.2...v1.1.0) (2021-10-19)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Bug Fixes
|
|
50
|
-
|
|
51
|
-
* add axioserror type on error ([1140bbb](https://github.com/Stun3R/strapi-sdk-js/commit/1140bbb990c37e492aa8d457a1e65ff5a0ac24ed))
|
|
52
|
-
* **deps:** update dependency @types/js-cookie to v3 ([88483aa](https://github.com/Stun3R/strapi-sdk-js/commit/88483aa0ff841c440716bbe1014ff8a6ef58c27f))
|
|
53
|
-
* **deps:** update dependency axios to ^0.23.0 ([854e84e](https://github.com/Stun3R/strapi-sdk-js/commit/854e84e02cdb818a69dddfecb8c1530f791609c4))
|
|
54
|
-
* missing comma after dependencies ([6efe03b](https://github.com/Stun3R/strapi-sdk-js/commit/6efe03b1713c5df97a077d3c5db43022d3fcc3f6))
|
|
55
|
-
* **tests:** switch response type to follow latest change ([362b5d9](https://github.com/Stun3R/strapi-sdk-js/commit/362b5d911ffb9fbeb37de7678dd60b97c7dbf2f6))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Code Refactoring
|
|
59
|
-
|
|
60
|
-
* drop of graphql methods support ([eebd7a3](https://github.com/Stun3R/strapi-sdk-js/commit/eebd7a34ddbce216ba0e8b3f5a3f95c0a0a5add5))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### BREAKING CHANGES
|
|
64
|
-
|
|
65
|
-
* SDK supports Strapi v4. Every CRUD methods response changed. Please refer to [documentation](https://strapi-sdk-js.netlify.app)
|
|
66
|
-
* GraphQL is no longer supported in v1.1.0
|
|
67
|
-
|
|
68
|
-
## [1.0.2](https://github.com/Stun3R/strapi-sdk-js/compare/v1.0.1...v1.0.2) (2021-08-30)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### Bug Fixes
|
|
72
|
-
|
|
73
|
-
* **deps:** update dependency js-cookie to v3 ([54be993](https://github.com/Stun3R/strapi-sdk-js/commit/54be993f1c02949fb320786bca409681eb6c9ed0))
|
|
74
|
-
* **deps:** update dependency nuxt to v2.15.7 ([062c012](https://github.com/Stun3R/strapi-sdk-js/commit/062c0121f63746c728f895fcf4b608e3e820826d))
|
|
75
|
-
* **deps:** update dependency nuxt to v2.15.8 ([598dacd](https://github.com/Stun3R/strapi-sdk-js/commit/598dacdeab43252d92405fc67882de2c00609b48))
|
|
76
|
-
|
|
77
|
-
## 1.0.1 (2021-06-17)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
### Bug Fixes
|
|
81
|
-
|
|
82
|
-
* **npm:** dist folder is missing when installing package ([8629d3d](https://github.com/Stun3R/strapi-sdk-js/commit/8629d3d85f399925f1697a5ab39881f47e1fe5fa)) @lhillebrandt
|
|
83
|
-
* **dist:** change path in order to take dist inside npm package ([b494a35](https://github.com/Stun3R/strapi-sdk-js/commit/b494a352cb5559a8e9a2e2e931ee30a67836ef82))
|
|
84
|
-
* **package.json:** remove trailing slash from dist folder in files ([7d3000c](https://github.com/Stun3R/strapi-sdk-js/commit/7d3000c15f63443d03971bc510cecf86ae530983))
|
|
85
|
-
|
|
86
|
-
# 1.0.0 (2021-06-11)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
### Bug Fixes
|
|
90
|
-
|
|
91
|
-
* **deps:** pin dependency docus to v0.1.5 ([9870d86](https://github.com/Stun3R/strapi-sdk-js/commit/9870d8669457bd31bfb184dcafc2e90b6fd0ecba))
|
|
92
|
-
* **deps:** update dependency nuxt to v2.15.6 ([f37aefd](https://github.com/Stun3R/strapi-sdk-js/commit/f37aefdebbcc9fb6bea8628c5b10c8c706dbc287))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### Features
|
|
96
|
-
|
|
97
|
-
* **user:** add user object, getter, setter & fetch methods ([e18089a](https://github.com/Stun3R/strapi-sdk-js/commit/e18089ae31446eeaff49c6e8a01250bc5cbe14ac))
|
|
98
|
-
* **auth:** add auth & token methods ([a554ee9](https://github.com/Stun3R/strapi-sdk-js/commit/a554ee9930f3dc87e792afaba571e84143707528))
|
|
99
|
-
* **core:** add crud methods, typescript support & graphql method ([cbe3b47](https://github.com/Stun3R/strapi-sdk-js/commit/cbe3b475dcdf49e3d6a37d594de2c69db8e185f3))
|
|
100
|
-
|