@malevich-studio/strapi-sdk-typescript 1.2.2 → 1.2.4

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 CHANGED
@@ -20079,6 +20079,9 @@ class Strapi {
20079
20079
  this.token = token;
20080
20080
  }
20081
20081
  async fetch(endpoint, data = {}, params = {}) {
20082
+ return await this.fetchData(endpoint, data, params);
20083
+ }
20084
+ async fetchData(endpoint, data = {}, params = {}) {
20082
20085
  const queryString = params.method === 'GET' ? qs.stringify(data) : '';
20083
20086
  return await this.baseFetch(queryString ? `${endpoint}?${queryString}` : endpoint, _.merge({
20084
20087
  headers: {
@@ -20091,6 +20094,69 @@ class Strapi {
20091
20094
  } : {}),
20092
20095
  }, params));
20093
20096
  }
20097
+ setToken(token) {
20098
+ this.token = token;
20099
+ }
20100
+ getToken() {
20101
+ return this.token;
20102
+ }
20103
+ async baseLogin(identifier, password) {
20104
+ const response = await this.fetchData('/auth/local', {
20105
+ identifier,
20106
+ password
20107
+ }, {
20108
+ method: 'POST',
20109
+ });
20110
+ if (!response.error) {
20111
+ this.setToken(response.jwt);
20112
+ }
20113
+ return response;
20114
+ }
20115
+ async baseRegister(data) {
20116
+ const response = await this.fetchData('/auth/local/register', data, {
20117
+ method: 'POST',
20118
+ });
20119
+ if (!response.error) {
20120
+ this.setToken(response.jwt);
20121
+ }
20122
+ return response;
20123
+ }
20124
+ async forgotPassword(email) {
20125
+ return await this.fetchData('/auth/forgot-password', { email }, {
20126
+ method: 'POST',
20127
+ });
20128
+ }
20129
+ async sendEmailConfirmation(email) {
20130
+ return await this.fetchData('/auth/send-email-confirmation', { email }, {
20131
+ method: 'POST',
20132
+ });
20133
+ }
20134
+ async baseResetPassword(password, code) {
20135
+ const response = await this.fetchData('/auth/reset-password', {
20136
+ password,
20137
+ passwordConfirmation: password,
20138
+ code,
20139
+ }, {
20140
+ method: 'POST',
20141
+ });
20142
+ if (!response.error) {
20143
+ this.setToken(response.jwt);
20144
+ }
20145
+ return response;
20146
+ }
20147
+ async baseChangePassword(password, currentPassword) {
20148
+ const response = await this.fetchData('/auth/change-password', {
20149
+ password,
20150
+ passwordConfirmation: password,
20151
+ currentPassword,
20152
+ }, {
20153
+ method: 'POST',
20154
+ });
20155
+ if (!response.error) {
20156
+ this.setToken(response.jwt);
20157
+ }
20158
+ return response;
20159
+ }
20094
20160
  async getLocales(params) {
20095
20161
  return await this.baseFetch('i18n/locales', _.merge({
20096
20162
  headers: {