@dartcom/ui-kit 10.1.2 → 10.1.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.
@@ -1,18 +1,20 @@
1
1
  import { ApiService } from '../../services/api';
2
- import { ResponseData } from './types';
2
+ import { BackendError, ResponseData } from './types';
3
3
  export interface ConfigOptions {
4
4
  apiKey: string;
5
5
  backendUrl: string;
6
6
  onCheck?: (data: ResponseData) => void;
7
+ onError?: (error: BackendError) => void;
7
8
  }
8
9
  export declare class GlobalConfig {
10
+ private configOptions;
9
11
  private _apiService;
10
12
  get apiService(): ApiService;
11
13
  private static _instance;
12
14
  static get instance(): GlobalConfig;
13
15
  static initialize(options: ConfigOptions): void;
14
16
  static deactivate(): void;
15
- constructor({ apiKey, backendUrl, onCheck }: ConfigOptions);
17
+ constructor(configOptions: ConfigOptions);
16
18
  private _apiKey;
17
19
  private _isValidApiKey;
18
20
  get isValidApiKey(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/configs/global/global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAoB,MAAM,gBAAgB,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CACxC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAa;IAChC,IAAW,UAAU,eAEpB;IAED,OAAO,CAAC,MAAM,CAAC,SAAS,CAAgC;IACxD,WAAkB,QAAQ,iBAQzB;WACa,UAAU,CAAC,OAAO,EAAE,aAAa;WAKjC,UAAU;gBAIZ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,aAAa;IAe1D,OAAO,CAAC,OAAO,CAAM;IAErB,OAAO,CAAC,cAAc,CAAS;IAC/B,IAAW,aAAa,YAEvB;IACD,IAAW,aAAa,CAAC,KAAK,SAAA,EAE7B;YAEa,gBAAgB;CA6B/B"}
1
+ {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/configs/global/global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAoB,MAAM,gBAAgB,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CACzC;AAED,qBAAa,YAAY;IAyBX,OAAO,CAAC,aAAa;IAxBjC,OAAO,CAAC,WAAW,CAAa;IAChC,IAAW,UAAU,eAEpB;IAED,OAAO,CAAC,MAAM,CAAC,SAAS,CAAgC;IACxD,WAAkB,QAAQ,iBAQzB;WACa,UAAU,CAAC,OAAO,EAAE,aAAa;WAKjC,UAAU;gBAIJ,aAAa,EAAE,aAAa;IAehD,OAAO,CAAC,OAAO,CAAM;IAErB,OAAO,CAAC,cAAc,CAAS;IAC/B,IAAW,aAAa,YAEvB;IACD,IAAW,aAAa,CAAC,KAAK,SAAA,EAE7B;YAEa,gBAAgB;CAgC/B"}
@@ -1,5 +1,9 @@
1
+ import { AxiosError } from 'axios';
1
2
  export type ResponseData = {
2
3
  valid: boolean;
3
4
  reason: string;
4
5
  };
6
+ export type BackendError = AxiosError<{
7
+ detail?: ResponseData;
8
+ }>;
5
9
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/configs/global/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/configs/global/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;IACpC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC,CAAC"}
package/dist/index.cjs CHANGED
@@ -16817,19 +16817,23 @@ class ApiService {
16817
16817
  return Promise.reject(error);
16818
16818
  });
16819
16819
  }
16820
- async get({ url, config, }) {
16820
+ async get({ url, config }) {
16821
16821
  const response = await this.client.get(url, config);
16822
16822
  return response.data;
16823
16823
  }
16824
- async post({ url, body, config, }) {
16824
+ async post({ url, body, config }) {
16825
16825
  const response = await this.client.post(url, body, config);
16826
16826
  return response.data;
16827
16827
  }
16828
- async put({ url, body, config, }) {
16828
+ async put({ url, body, config }) {
16829
16829
  const response = await this.client.put(url, body, config);
16830
16830
  return response.data;
16831
16831
  }
16832
- async delete({ url, config, }) {
16832
+ async patch({ url, body, config }) {
16833
+ const response = await this.client.patch(url, body, config);
16834
+ return response.data;
16835
+ }
16836
+ async delete({ url, config }) {
16833
16837
  const response = await this.client.delete(url, config);
16834
16838
  return response.data;
16835
16839
  }
@@ -16841,6 +16845,7 @@ const createApiService = (baseURL) => {
16841
16845
  };
16842
16846
 
16843
16847
  class GlobalConfig {
16848
+ configOptions;
16844
16849
  _apiService;
16845
16850
  get apiService() {
16846
16851
  return this._apiService;
@@ -16860,13 +16865,14 @@ class GlobalConfig {
16860
16865
  static deactivate() {
16861
16866
  this._instance = null;
16862
16867
  }
16863
- constructor({ apiKey, backendUrl, onCheck }) {
16864
- this._apiKey = apiKey;
16865
- this._apiService = createApiService(backendUrl);
16868
+ constructor(configOptions) {
16869
+ this.configOptions = configOptions;
16870
+ this._apiKey = configOptions.apiKey;
16871
+ this._apiService = createApiService(configOptions.backendUrl);
16866
16872
  this._getCheckKeyData().then((data) => {
16867
16873
  if (data) {
16868
16874
  const { valid } = data;
16869
- onCheck?.(data);
16875
+ configOptions.onCheck?.(data);
16870
16876
  this.isValidApiKey = valid;
16871
16877
  }
16872
16878
  });
@@ -16890,11 +16896,17 @@ class GlobalConfig {
16890
16896
  },
16891
16897
  })
16892
16898
  .then((data) => data)
16893
- .catch(({ response, }) => {
16899
+ .catch((error) => {
16900
+ const { response, message } = error;
16901
+ this.configOptions.onError?.(error);
16894
16902
  if (response) {
16895
16903
  const { data: { detail }, } = response;
16896
16904
  return detail;
16897
16905
  }
16906
+ return {
16907
+ reason: message,
16908
+ valid: false,
16909
+ };
16898
16910
  });
16899
16911
  return checkKeyData;
16900
16912
  }