@nocobase/sdk 1.3.39-beta → 1.4.0-alpha

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.
@@ -6,7 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
9
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios';
10
10
  export interface ActionParams {
11
11
  filterByTk?: any;
12
12
  [key: string]: any;
@@ -114,6 +114,7 @@ export declare class MemoryStorage extends Storage {
114
114
  }
115
115
  interface ExtendedOptions {
116
116
  authClass?: any;
117
+ storageType?: 'localStorage' | 'sessionStorage' | 'memory';
117
118
  storageClass?: any;
118
119
  storagePrefix?: string;
119
120
  }
@@ -128,6 +129,6 @@ export declare class APIClient {
128
129
  private initStorage;
129
130
  interceptors(): void;
130
131
  request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R>;
131
- resource(name: string, of?: any, headers?: AxiosRequestHeaders, cancel?: boolean): IResource;
132
+ resource(name: string, of?: any, headers?: RawAxiosRequestHeaders, cancel?: boolean): IResource;
132
133
  }
133
134
  export {};
package/lib/APIClient.js CHANGED
@@ -276,10 +276,10 @@ const _APIClient = class _APIClient {
276
276
  if (typeof instance === "function") {
277
277
  this.axios = instance;
278
278
  } else {
279
- const { authClass, storageClass, storagePrefix = "NOCOBASE_", ...others } = instance || {};
279
+ const { authClass, storageType, storageClass, storagePrefix = "NOCOBASE_", ...others } = instance || {};
280
280
  this.storagePrefix = storagePrefix;
281
281
  this.axios = import_axios.default.create(others);
282
- this.initStorage(storageClass);
282
+ this.initStorage(storageClass, storageType);
283
283
  if (authClass) {
284
284
  this.auth = new authClass(this);
285
285
  }
@@ -292,14 +292,20 @@ const _APIClient = class _APIClient {
292
292
  }
293
293
  this.interceptors();
294
294
  }
295
- initStorage(storage) {
295
+ initStorage(storage, storageType = "localStorage") {
296
296
  if (storage) {
297
297
  this.storage = new storage(this);
298
- } else if (typeof localStorage !== "undefined") {
298
+ return;
299
+ }
300
+ if (storageType === "localStorage" && typeof localStorage !== "undefined") {
299
301
  this.storage = localStorage;
300
- } else {
301
- this.storage = new MemoryStorage();
302
+ return;
303
+ }
304
+ if (storageType === "sessionStorage" && typeof sessionStorage !== "undefined") {
305
+ this.storage = sessionStorage;
306
+ return;
302
307
  }
308
+ this.storage = new MemoryStorage();
303
309
  }
304
310
  interceptors() {
305
311
  this.axios.interceptors.request.use((config) => {
@@ -327,7 +333,7 @@ const _APIClient = class _APIClient {
327
333
  return;
328
334
  }
329
335
  let url = name.split(".").join(`/${encodeURIComponent(of) || "_"}/`);
330
- url += `:${actionName}`;
336
+ url += `:${actionName.toString()}`;
331
337
  const config = { url };
332
338
  if (["get", "list"].includes(actionName)) {
333
339
  config["method"] = "get";
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@nocobase/sdk",
3
- "version": "1.3.39-beta",
3
+ "version": "1.4.0-alpha",
4
4
  "license": "AGPL-3.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "dependencies": {
8
- "axios": "^0.26.1",
8
+ "axios": "^1.7.0",
9
9
  "qs": "^6.10.1"
10
10
  },
11
11
  "devDependencies": {
12
12
  "axios-mock-adapter": "^1.20.0"
13
13
  },
14
- "gitHead": "68daadf8575cddf9eeb09a1a672f9baf7aabe67a"
14
+ "gitHead": "f097a2bddec152522b5645bd5d451f4c866d2060"
15
15
  }