@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.mjs CHANGED
@@ -20084,6 +20084,9 @@ class Strapi {
20084
20084
  this.token = token;
20085
20085
  }
20086
20086
  async fetch(endpoint, data = {}, params = {}) {
20087
+ return await this.fetchData(endpoint, data, params);
20088
+ }
20089
+ async fetchData(endpoint, data = {}, params = {}) {
20087
20090
  const queryString = params.method === 'GET' ? qs.stringify(data) : '';
20088
20091
  return await this.baseFetch(queryString ? `${endpoint}?${queryString}` : endpoint, _.merge({
20089
20092
  headers: {
@@ -20096,6 +20099,69 @@ class Strapi {
20096
20099
  } : {}),
20097
20100
  }, params));
20098
20101
  }
20102
+ setToken(token) {
20103
+ this.token = token;
20104
+ }
20105
+ getToken() {
20106
+ return this.token;
20107
+ }
20108
+ async baseLogin(identifier, password) {
20109
+ const response = await this.fetchData('/auth/local', {
20110
+ identifier,
20111
+ password
20112
+ }, {
20113
+ method: 'POST',
20114
+ });
20115
+ if (!response.error) {
20116
+ this.setToken(response.jwt);
20117
+ }
20118
+ return response;
20119
+ }
20120
+ async baseRegister(data) {
20121
+ const response = await this.fetchData('/auth/local/register', data, {
20122
+ method: 'POST',
20123
+ });
20124
+ if (!response.error) {
20125
+ this.setToken(response.jwt);
20126
+ }
20127
+ return response;
20128
+ }
20129
+ async forgotPassword(email) {
20130
+ return await this.fetchData('/auth/forgot-password', { email }, {
20131
+ method: 'POST',
20132
+ });
20133
+ }
20134
+ async sendEmailConfirmation(email) {
20135
+ return await this.fetchData('/auth/send-email-confirmation', { email }, {
20136
+ method: 'POST',
20137
+ });
20138
+ }
20139
+ async baseResetPassword(password, code) {
20140
+ const response = await this.fetchData('/auth/reset-password', {
20141
+ password,
20142
+ passwordConfirmation: password,
20143
+ code,
20144
+ }, {
20145
+ method: 'POST',
20146
+ });
20147
+ if (!response.error) {
20148
+ this.setToken(response.jwt);
20149
+ }
20150
+ return response;
20151
+ }
20152
+ async baseChangePassword(password, currentPassword) {
20153
+ const response = await this.fetchData('/auth/change-password', {
20154
+ password,
20155
+ passwordConfirmation: password,
20156
+ currentPassword,
20157
+ }, {
20158
+ method: 'POST',
20159
+ });
20160
+ if (!response.error) {
20161
+ this.setToken(response.jwt);
20162
+ }
20163
+ return response;
20164
+ }
20099
20165
  async getLocales(params) {
20100
20166
  return await this.baseFetch('i18n/locales', _.merge({
20101
20167
  headers: {
@@ -20712,6 +20778,22 @@ async function generateStrapiTypes(strapi) {
20712
20778
  'import {BlocksContent} from "@strapi/blocks-react-renderer";',
20713
20779
  '',
20714
20780
  'export default class Strapi extends StrapiBase {',
20781
+ ` public async login(identifier: string, password: string) {`,
20782
+ ` return await this.baseLogin<User>(identifier, password);`,
20783
+ ' }',
20784
+ ' ',
20785
+ ` public async register(data: UserInput) {`,
20786
+ ` return await this.baseRegister<User, UserInput>(data);`,
20787
+ ' }',
20788
+ ' ',
20789
+ ` public async resetPassword(password: string, code: string) {`,
20790
+ ` return await this.baseResetPassword<User>(password, code);`,
20791
+ ' }',
20792
+ ' ',
20793
+ ` public async changePassword(password: string, currentPassword: string) {`,
20794
+ ` return await this.baseChangePassword<User>(password, currentPassword);`,
20795
+ ' }',
20796
+ ' ',
20715
20797
  methods.join('\n\n'),
20716
20798
  '}',
20717
20799
  '',