@nocobase/sdk 1.0.0-alpha.9 → 1.0.1-alpha.1
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/lib/APIClient.d.ts +4 -2
- package/lib/APIClient.js +24 -21
- package/package.json +2 -2
package/lib/APIClient.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ export type IResource = {
|
|
|
23
23
|
};
|
|
24
24
|
export declare class Auth {
|
|
25
25
|
protected api: APIClient;
|
|
26
|
-
|
|
26
|
+
get storagePrefix(): string;
|
|
27
|
+
get KEYS(): {
|
|
27
28
|
locale: string;
|
|
28
29
|
role: string;
|
|
29
30
|
token: string;
|
|
@@ -37,7 +38,6 @@ export declare class Auth {
|
|
|
37
38
|
token: any;
|
|
38
39
|
};
|
|
39
40
|
constructor(api: APIClient);
|
|
40
|
-
initKeys(): void;
|
|
41
41
|
get locale(): string;
|
|
42
42
|
set locale(value: string);
|
|
43
43
|
get role(): string;
|
|
@@ -115,12 +115,14 @@ export declare class MemoryStorage extends Storage {
|
|
|
115
115
|
interface ExtendedOptions {
|
|
116
116
|
authClass?: any;
|
|
117
117
|
storageClass?: any;
|
|
118
|
+
storagePrefix?: string;
|
|
118
119
|
}
|
|
119
120
|
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
|
|
120
121
|
export declare class APIClient {
|
|
121
122
|
axios: AxiosInstance;
|
|
122
123
|
auth: Auth;
|
|
123
124
|
storage: Storage;
|
|
125
|
+
storagePrefix: string;
|
|
124
126
|
getHeaders(): {};
|
|
125
127
|
constructor(instance?: APIClientOptions);
|
|
126
128
|
private initStorage;
|
package/lib/APIClient.js
CHANGED
|
@@ -45,16 +45,29 @@ __export(APIClient_exports, {
|
|
|
45
45
|
module.exports = __toCommonJS(APIClient_exports);
|
|
46
46
|
var import_axios = __toESM(require("axios"));
|
|
47
47
|
var import_qs = __toESM(require("qs"));
|
|
48
|
-
var import_getSubAppName = __toESM(require("./getSubAppName"));
|
|
49
48
|
const _Auth = class _Auth {
|
|
50
49
|
api;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
get storagePrefix() {
|
|
51
|
+
return this.api.storagePrefix;
|
|
52
|
+
}
|
|
53
|
+
get KEYS() {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const defaults = {
|
|
56
|
+
locale: this.storagePrefix + "LOCALE",
|
|
57
|
+
role: this.storagePrefix + "ROLE",
|
|
58
|
+
token: this.storagePrefix + "TOKEN",
|
|
59
|
+
authenticator: this.storagePrefix + "AUTH",
|
|
60
|
+
theme: this.storagePrefix + "THEME"
|
|
61
|
+
};
|
|
62
|
+
if (this.api["app"]) {
|
|
63
|
+
const appName = (_b = (_a = this.api["app"]) == null ? void 0 : _a.getName) == null ? void 0 : _b.call(_a);
|
|
64
|
+
if (appName) {
|
|
65
|
+
defaults["role"] = `${appName.toUpperCase()}_` + defaults["role"];
|
|
66
|
+
defaults["locale"] = `${appName.toUpperCase()}_` + defaults["locale"];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return defaults;
|
|
70
|
+
}
|
|
58
71
|
options = {
|
|
59
72
|
locale: null,
|
|
60
73
|
role: null,
|
|
@@ -63,20 +76,8 @@ const _Auth = class _Auth {
|
|
|
63
76
|
};
|
|
64
77
|
constructor(api) {
|
|
65
78
|
this.api = api;
|
|
66
|
-
this.initKeys();
|
|
67
79
|
this.api.axios.interceptors.request.use(this.middleware.bind(this));
|
|
68
80
|
}
|
|
69
|
-
initKeys() {
|
|
70
|
-
if (typeof window === "undefined") {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const appName = (0, import_getSubAppName.default)(this.api["app"] ? this.api["app"].getPublicPath() : "/");
|
|
74
|
-
if (!appName) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.KEYS["role"] = `${appName.toUpperCase()}_` + this.KEYS["role"];
|
|
78
|
-
this.KEYS["locale"] = `${appName.toUpperCase()}_` + this.KEYS["locale"];
|
|
79
|
-
}
|
|
80
81
|
get locale() {
|
|
81
82
|
return this.getLocale();
|
|
82
83
|
}
|
|
@@ -254,6 +255,7 @@ const _APIClient = class _APIClient {
|
|
|
254
255
|
axios;
|
|
255
256
|
auth;
|
|
256
257
|
storage;
|
|
258
|
+
storagePrefix = "NOCOBASE_";
|
|
257
259
|
getHeaders() {
|
|
258
260
|
const headers = {};
|
|
259
261
|
if (this.auth.locale) {
|
|
@@ -274,7 +276,8 @@ const _APIClient = class _APIClient {
|
|
|
274
276
|
if (typeof instance === "function") {
|
|
275
277
|
this.axios = instance;
|
|
276
278
|
} else {
|
|
277
|
-
const { authClass, storageClass, ...others } = instance || {};
|
|
279
|
+
const { authClass, storageClass, storagePrefix = "NOCOBASE_", ...others } = instance || {};
|
|
280
|
+
this.storagePrefix = storagePrefix;
|
|
278
281
|
this.axios = import_axios.default.create(others);
|
|
279
282
|
this.initStorage(storageClass);
|
|
280
283
|
if (authClass) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.1",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"axios-mock-adapter": "^1.20.0"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "d24aa16987a4068f857ae073fcce18f3cb490660"
|
|
15
15
|
}
|