@malevich-studio/strapi-sdk-typescript 1.2.3 → 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.d.ts CHANGED
@@ -41,6 +41,11 @@ type ErrorResponse = {
41
41
  };
42
42
  };
43
43
  type Response<T> = SuccessResponse<T> | ErrorResponse;
44
+ type AuthResponse<T> = {
45
+ jwt: string;
46
+ user: T;
47
+ error: undefined;
48
+ } | ErrorResponse;
44
49
  type File = {
45
50
  id?: number;
46
51
  documentId?: string;
@@ -146,7 +151,20 @@ declare class Strapi {
146
151
  fetch<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<Response<T>>;
147
152
  private fetchData;
148
153
  setToken(token: string): void;
149
- protected baseLogin<T>(identifier: string, password: string): Promise<T>;
154
+ getToken(): string | undefined;
155
+ protected baseLogin<T>(identifier: string, password: string): Promise<AuthResponse<T>>;
156
+ protected baseRegister<T, Q>(data: Q): Promise<AuthResponse<T>>;
157
+ forgotPassword(email: string): Promise<ErrorResponse | {
158
+ ok: boolean;
159
+ error: undefined;
160
+ }>;
161
+ sendEmailConfirmation(email: string): Promise<ErrorResponse | {
162
+ email: string;
163
+ sent: boolean;
164
+ error: undefined;
165
+ }>;
166
+ protected baseResetPassword<T>(password: string, code: string): Promise<AuthResponse<T>>;
167
+ protected baseChangePassword<T>(password: string, currentPassword: string): Promise<AuthResponse<T>>;
150
168
  getLocales(params: RequestInit): Promise<Locale[]>;
151
169
  getDocuments<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T[]>>;
152
170
  getDocument<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T>>;
@@ -157,4 +175,4 @@ declare class Strapi {
157
175
  private baseFetch;
158
176
  }
159
177
 
160
- export { type DynamiczoneComponent, type DynamiczonePopulate, type File, type FilterValue, type Filters, type Folder, type Locale, type Query, type RelationInput, Strapi };
178
+ export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type File, type FilterValue, type Filters, type Folder, type Locale, type Query, type RelationInput, Strapi };
package/dist/index.mjs CHANGED
@@ -20095,6 +20095,9 @@ class Strapi {
20095
20095
  setToken(token) {
20096
20096
  this.token = token;
20097
20097
  }
20098
+ getToken() {
20099
+ return this.token;
20100
+ }
20098
20101
  async baseLogin(identifier, password) {
20099
20102
  const response = await this.fetchData('/auth/local', {
20100
20103
  identifier,
@@ -20102,8 +20105,55 @@ class Strapi {
20102
20105
  }, {
20103
20106
  method: 'POST',
20104
20107
  });
20105
- this.setToken(response.jwt);
20106
- return response.user;
20108
+ if (!response.error) {
20109
+ this.setToken(response.jwt);
20110
+ }
20111
+ return response;
20112
+ }
20113
+ async baseRegister(data) {
20114
+ const response = await this.fetchData('/auth/local/register', data, {
20115
+ method: 'POST',
20116
+ });
20117
+ if (!response.error) {
20118
+ this.setToken(response.jwt);
20119
+ }
20120
+ return response;
20121
+ }
20122
+ async forgotPassword(email) {
20123
+ return await this.fetchData('/auth/forgot-password', { email }, {
20124
+ method: 'POST',
20125
+ });
20126
+ }
20127
+ async sendEmailConfirmation(email) {
20128
+ return await this.fetchData('/auth/send-email-confirmation', { email }, {
20129
+ method: 'POST',
20130
+ });
20131
+ }
20132
+ async baseResetPassword(password, code) {
20133
+ const response = await this.fetchData('/auth/reset-password', {
20134
+ password,
20135
+ passwordConfirmation: password,
20136
+ code,
20137
+ }, {
20138
+ method: 'POST',
20139
+ });
20140
+ if (!response.error) {
20141
+ this.setToken(response.jwt);
20142
+ }
20143
+ return response;
20144
+ }
20145
+ async baseChangePassword(password, currentPassword) {
20146
+ const response = await this.fetchData('/auth/change-password', {
20147
+ password,
20148
+ passwordConfirmation: password,
20149
+ currentPassword,
20150
+ }, {
20151
+ method: 'POST',
20152
+ });
20153
+ if (!response.error) {
20154
+ this.setToken(response.jwt);
20155
+ }
20156
+ return response;
20107
20157
  }
20108
20158
  async getLocales(params) {
20109
20159
  return await this.baseFetch('i18n/locales', _.merge({