@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/cli.cjs CHANGED
@@ -20104,6 +20104,9 @@ class Strapi {
20104
20104
  this.token = token;
20105
20105
  }
20106
20106
  async fetch(endpoint, data = {}, params = {}) {
20107
+ return await this.fetchData(endpoint, data, params);
20108
+ }
20109
+ async fetchData(endpoint, data = {}, params = {}) {
20107
20110
  const queryString = params.method === 'GET' ? qs.stringify(data) : '';
20108
20111
  return await this.baseFetch(queryString ? `${endpoint}?${queryString}` : endpoint, _.merge({
20109
20112
  headers: {
@@ -20116,6 +20119,69 @@ class Strapi {
20116
20119
  } : {}),
20117
20120
  }, params));
20118
20121
  }
20122
+ setToken(token) {
20123
+ this.token = token;
20124
+ }
20125
+ getToken() {
20126
+ return this.token;
20127
+ }
20128
+ async baseLogin(identifier, password) {
20129
+ const response = await this.fetchData('/auth/local', {
20130
+ identifier,
20131
+ password
20132
+ }, {
20133
+ method: 'POST',
20134
+ });
20135
+ if (!response.error) {
20136
+ this.setToken(response.jwt);
20137
+ }
20138
+ return response;
20139
+ }
20140
+ async baseRegister(data) {
20141
+ const response = await this.fetchData('/auth/local/register', data, {
20142
+ method: 'POST',
20143
+ });
20144
+ if (!response.error) {
20145
+ this.setToken(response.jwt);
20146
+ }
20147
+ return response;
20148
+ }
20149
+ async forgotPassword(email) {
20150
+ return await this.fetchData('/auth/forgot-password', { email }, {
20151
+ method: 'POST',
20152
+ });
20153
+ }
20154
+ async sendEmailConfirmation(email) {
20155
+ return await this.fetchData('/auth/send-email-confirmation', { email }, {
20156
+ method: 'POST',
20157
+ });
20158
+ }
20159
+ async baseResetPassword(password, code) {
20160
+ const response = await this.fetchData('/auth/reset-password', {
20161
+ password,
20162
+ passwordConfirmation: password,
20163
+ code,
20164
+ }, {
20165
+ method: 'POST',
20166
+ });
20167
+ if (!response.error) {
20168
+ this.setToken(response.jwt);
20169
+ }
20170
+ return response;
20171
+ }
20172
+ async baseChangePassword(password, currentPassword) {
20173
+ const response = await this.fetchData('/auth/change-password', {
20174
+ password,
20175
+ passwordConfirmation: password,
20176
+ currentPassword,
20177
+ }, {
20178
+ method: 'POST',
20179
+ });
20180
+ if (!response.error) {
20181
+ this.setToken(response.jwt);
20182
+ }
20183
+ return response;
20184
+ }
20119
20185
  async getLocales(params) {
20120
20186
  return await this.baseFetch('i18n/locales', _.merge({
20121
20187
  headers: {
@@ -20732,6 +20798,22 @@ async function generateStrapiTypes(strapi) {
20732
20798
  'import {BlocksContent} from "@strapi/blocks-react-renderer";',
20733
20799
  '',
20734
20800
  'export default class Strapi extends StrapiBase {',
20801
+ ` public async login(identifier: string, password: string) {`,
20802
+ ` return await this.baseLogin<User>(identifier, password);`,
20803
+ ' }',
20804
+ ' ',
20805
+ ` public async register(data: UserInput) {`,
20806
+ ` return await this.baseRegister<User, UserInput>(data);`,
20807
+ ' }',
20808
+ ' ',
20809
+ ` public async resetPassword(password: string, code: string) {`,
20810
+ ` return await this.baseResetPassword<User>(password, code);`,
20811
+ ' }',
20812
+ ' ',
20813
+ ` public async changePassword(password: string, currentPassword: string) {`,
20814
+ ` return await this.baseChangePassword<User>(password, currentPassword);`,
20815
+ ' }',
20816
+ ' ',
20735
20817
  methods.join('\n\n'),
20736
20818
  '}',
20737
20819
  '',