@malevich-studio/strapi-sdk-typescript 1.2.1 → 1.2.3

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
@@ -27,6 +27,7 @@ type SuccessResponse<T> = {
27
27
  limit: number;
28
28
  });
29
29
  };
30
+ error: undefined;
30
31
  };
31
32
  type ErrorResponse = {
32
33
  data: null;
@@ -140,9 +141,12 @@ type DynamiczonePopulate<T> = {
140
141
  };
141
142
  declare class Strapi {
142
143
  private readonly url;
143
- private readonly token?;
144
+ private token?;
144
145
  constructor(url: string, token?: string | undefined);
145
146
  fetch<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<Response<T>>;
147
+ private fetchData;
148
+ setToken(token: string): void;
149
+ protected baseLogin<T>(identifier: string, password: string): Promise<T>;
146
150
  getLocales(params: RequestInit): Promise<Locale[]>;
147
151
  getDocuments<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T[]>>;
148
152
  getDocument<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T>>;
package/dist/index.mjs CHANGED
@@ -20077,6 +20077,9 @@ class Strapi {
20077
20077
  this.token = token;
20078
20078
  }
20079
20079
  async fetch(endpoint, data = {}, params = {}) {
20080
+ return await this.fetchData(endpoint, data, params);
20081
+ }
20082
+ async fetchData(endpoint, data = {}, params = {}) {
20080
20083
  const queryString = params.method === 'GET' ? qs.stringify(data) : '';
20081
20084
  return await this.baseFetch(queryString ? `${endpoint}?${queryString}` : endpoint, _.merge({
20082
20085
  headers: {
@@ -20089,6 +20092,19 @@ class Strapi {
20089
20092
  } : {}),
20090
20093
  }, params));
20091
20094
  }
20095
+ setToken(token) {
20096
+ this.token = token;
20097
+ }
20098
+ async baseLogin(identifier, password) {
20099
+ const response = await this.fetchData('/auth/local', {
20100
+ identifier,
20101
+ password
20102
+ }, {
20103
+ method: 'POST',
20104
+ });
20105
+ this.setToken(response.jwt);
20106
+ return response.user;
20107
+ }
20092
20108
  async getLocales(params) {
20093
20109
  return await this.baseFetch('i18n/locales', _.merge({
20094
20110
  headers: {