@nocobase/sdk 0.10.1-alpha.1 → 0.11.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/es/APIClient.d.ts +4 -2
- package/es/APIClient.js +5 -4
- package/es/getSubAppName.d.ts +2 -0
- package/es/getSubAppName.js +8 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/lib/APIClient.d.ts +4 -2
- package/lib/APIClient.js +5 -4
- package/lib/getSubAppName.d.ts +2 -0
- package/lib/getSubAppName.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +13 -1
- package/package.json +2 -2
- package/src/APIClient.ts +7 -4
- package/src/getSubAppName.ts +9 -0
- package/src/index.ts +2 -0
package/es/APIClient.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface ActionParams {
|
|
|
3
3
|
filterByTk?: any;
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
type ResourceActionOptions<P = any> = {
|
|
7
7
|
resource?: string;
|
|
8
8
|
resourceOf?: any;
|
|
9
9
|
action?: string;
|
|
@@ -24,6 +24,7 @@ export declare class Auth {
|
|
|
24
24
|
role: string;
|
|
25
25
|
token: string;
|
|
26
26
|
authenticator: string;
|
|
27
|
+
theme: string;
|
|
27
28
|
};
|
|
28
29
|
protected options: {
|
|
29
30
|
locale: any;
|
|
@@ -73,11 +74,12 @@ interface ExtendedOptions {
|
|
|
73
74
|
authClass?: any;
|
|
74
75
|
storageClass?: any;
|
|
75
76
|
}
|
|
77
|
+
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
|
|
76
78
|
export declare class APIClient {
|
|
77
79
|
axios: AxiosInstance;
|
|
78
80
|
auth: Auth;
|
|
79
81
|
storage: Storage;
|
|
80
|
-
constructor(instance?:
|
|
82
|
+
constructor(instance?: APIClientOptions);
|
|
81
83
|
private initStorage;
|
|
82
84
|
interceptors(): void;
|
|
83
85
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R>;
|
package/es/APIClient.js
CHANGED
|
@@ -11,6 +11,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
11
11
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
12
|
import axios from 'axios';
|
|
13
13
|
import qs from 'qs';
|
|
14
|
+
import getSubAppName from './getSubAppName';
|
|
14
15
|
export class Auth {
|
|
15
16
|
constructor(api) {
|
|
16
17
|
this.api = void 0;
|
|
@@ -18,7 +19,8 @@ export class Auth {
|
|
|
18
19
|
locale: 'NOCOBASE_LOCALE',
|
|
19
20
|
role: 'NOCOBASE_ROLE',
|
|
20
21
|
token: 'NOCOBASE_TOKEN',
|
|
21
|
-
authenticator: 'NOCOBASE_AUTH'
|
|
22
|
+
authenticator: 'NOCOBASE_AUTH',
|
|
23
|
+
theme: 'NOCOBASE_THEME'
|
|
22
24
|
};
|
|
23
25
|
this.options = {
|
|
24
26
|
locale: null,
|
|
@@ -34,11 +36,10 @@ export class Auth {
|
|
|
34
36
|
if (!window) {
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
+
const appName = getSubAppName();
|
|
40
|
+
if (!appName) {
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
|
-
const appName = match[1];
|
|
42
43
|
this.KEYS['role'] = `${appName.toUpperCase()}_` + this.KEYS['role'];
|
|
43
44
|
this.KEYS['locale'] = `${appName.toUpperCase()}_` + this.KEYS['locale'];
|
|
44
45
|
}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './APIClient';
|
|
1
|
+
export * from './APIClient';
|
|
2
|
+
export { default as getSubAppName } from './getSubAppName';
|
package/lib/APIClient.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface ActionParams {
|
|
|
3
3
|
filterByTk?: any;
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
type ResourceActionOptions<P = any> = {
|
|
7
7
|
resource?: string;
|
|
8
8
|
resourceOf?: any;
|
|
9
9
|
action?: string;
|
|
@@ -24,6 +24,7 @@ export declare class Auth {
|
|
|
24
24
|
role: string;
|
|
25
25
|
token: string;
|
|
26
26
|
authenticator: string;
|
|
27
|
+
theme: string;
|
|
27
28
|
};
|
|
28
29
|
protected options: {
|
|
29
30
|
locale: any;
|
|
@@ -73,11 +74,12 @@ interface ExtendedOptions {
|
|
|
73
74
|
authClass?: any;
|
|
74
75
|
storageClass?: any;
|
|
75
76
|
}
|
|
77
|
+
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
|
|
76
78
|
export declare class APIClient {
|
|
77
79
|
axios: AxiosInstance;
|
|
78
80
|
auth: Auth;
|
|
79
81
|
storage: Storage;
|
|
80
|
-
constructor(instance?:
|
|
82
|
+
constructor(instance?: APIClientOptions);
|
|
81
83
|
private initStorage;
|
|
82
84
|
interceptors(): void;
|
|
83
85
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R>;
|
package/lib/APIClient.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Storage = exports.MemoryStorage = exports.Auth = exports.APIClient = void 0;
|
|
7
7
|
var _axios = _interopRequireDefault(require("axios"));
|
|
8
8
|
var _qs = _interopRequireDefault(require("qs"));
|
|
9
|
+
var _getSubAppName = _interopRequireDefault(require("./getSubAppName"));
|
|
9
10
|
const _excluded = ["authClass", "storageClass"],
|
|
10
11
|
_excluded2 = ["values", "filter"];
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,7 +26,8 @@ class Auth {
|
|
|
25
26
|
locale: 'NOCOBASE_LOCALE',
|
|
26
27
|
role: 'NOCOBASE_ROLE',
|
|
27
28
|
token: 'NOCOBASE_TOKEN',
|
|
28
|
-
authenticator: 'NOCOBASE_AUTH'
|
|
29
|
+
authenticator: 'NOCOBASE_AUTH',
|
|
30
|
+
theme: 'NOCOBASE_THEME'
|
|
29
31
|
};
|
|
30
32
|
this.options = {
|
|
31
33
|
locale: null,
|
|
@@ -41,11 +43,10 @@ class Auth {
|
|
|
41
43
|
if (!window) {
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
46
|
+
const appName = (0, _getSubAppName.default)();
|
|
47
|
+
if (!appName) {
|
|
46
48
|
return;
|
|
47
49
|
}
|
|
48
|
-
const appName = match[1];
|
|
49
50
|
this.KEYS['role'] = `${appName.toUpperCase()}_` + this.KEYS['role'];
|
|
50
51
|
this.KEYS['locale'] = `${appName.toUpperCase()}_` + this.KEYS['locale'];
|
|
51
52
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const getSubAppName = () => {
|
|
8
|
+
const match = window.location.pathname.match(/^\/apps\/([^/]*)\//);
|
|
9
|
+
if (!match) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return match[1].toUpperCase();
|
|
13
|
+
};
|
|
14
|
+
var _default = getSubAppName;
|
|
15
|
+
exports.default = _default;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
getSubAppName: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "getSubAppName", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return _getSubAppName.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
var _APIClient = require("./APIClient");
|
|
7
16
|
Object.keys(_APIClient).forEach(function (key) {
|
|
8
17
|
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
19
|
if (key in exports && exports[key] === _APIClient[key]) return;
|
|
10
20
|
Object.defineProperty(exports, key, {
|
|
11
21
|
enumerable: true,
|
|
@@ -13,4 +23,6 @@ Object.keys(_APIClient).forEach(function (key) {
|
|
|
13
23
|
return _APIClient[key];
|
|
14
24
|
}
|
|
15
25
|
});
|
|
16
|
-
});
|
|
26
|
+
});
|
|
27
|
+
var _getSubAppName = _interopRequireDefault(require("./getSubAppName"));
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1-alpha.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"axios-mock-adapter": "^1.20.0"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
|
|
16
16
|
}
|
package/src/APIClient.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import qs from 'qs';
|
|
3
|
+
import getSubAppName from './getSubAppName';
|
|
3
4
|
|
|
4
5
|
export interface ActionParams {
|
|
5
6
|
filterByTk?: any;
|
|
@@ -30,6 +31,7 @@ export class Auth {
|
|
|
30
31
|
role: 'NOCOBASE_ROLE',
|
|
31
32
|
token: 'NOCOBASE_TOKEN',
|
|
32
33
|
authenticator: 'NOCOBASE_AUTH',
|
|
34
|
+
theme: 'NOCOBASE_THEME',
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
protected options = {
|
|
@@ -49,11 +51,10 @@ export class Auth {
|
|
|
49
51
|
if (!window) {
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
+
const appName = getSubAppName();
|
|
55
|
+
if (!appName) {
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
const appName = match[1];
|
|
57
58
|
this.KEYS['role'] = `${appName.toUpperCase()}_` + this.KEYS['role'];
|
|
58
59
|
this.KEYS['locale'] = `${appName.toUpperCase()}_` + this.KEYS['locale'];
|
|
59
60
|
}
|
|
@@ -223,12 +224,14 @@ interface ExtendedOptions {
|
|
|
223
224
|
storageClass?: any;
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
|
|
228
|
+
|
|
226
229
|
export class APIClient {
|
|
227
230
|
axios: AxiosInstance;
|
|
228
231
|
auth: Auth;
|
|
229
232
|
storage: Storage;
|
|
230
233
|
|
|
231
|
-
constructor(instance?:
|
|
234
|
+
constructor(instance?: APIClientOptions) {
|
|
232
235
|
if (typeof instance === 'function') {
|
|
233
236
|
this.axios = instance;
|
|
234
237
|
} else {
|
package/src/index.ts
CHANGED