@nocobase/sdk 2.0.0-alpha.6 → 2.0.0-alpha.60
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 +7 -95
- package/lib/APIClient.js +42 -257
- package/lib/Auth.d.ts +84 -0
- package/lib/Auth.js +234 -0
- package/lib/Storage.d.ts +38 -0
- package/lib/Storage.js +105 -0
- package/lib/getSubAppName.js +6 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -1
- package/package.json +2 -2
package/lib/APIClient.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios';
|
|
10
|
+
import { Auth } from './Auth';
|
|
11
|
+
import { BaseStorage, LocalStorage, MemoryStorage } from './Storage';
|
|
10
12
|
export interface ActionParams {
|
|
11
13
|
filterByTk?: any;
|
|
12
14
|
[key: string]: any;
|
|
@@ -21,115 +23,25 @@ type ResourceAction = (params?: ActionParams, opts?: any) => Promise<any>;
|
|
|
21
23
|
export type IResource = {
|
|
22
24
|
[key: string]: ResourceAction;
|
|
23
25
|
};
|
|
24
|
-
export declare class Auth {
|
|
25
|
-
protected api: APIClient;
|
|
26
|
-
get storagePrefix(): string;
|
|
27
|
-
get KEYS(): {
|
|
28
|
-
locale: string;
|
|
29
|
-
role: string;
|
|
30
|
-
token: string;
|
|
31
|
-
authenticator: string;
|
|
32
|
-
theme: string;
|
|
33
|
-
};
|
|
34
|
-
protected options: {
|
|
35
|
-
locale: any;
|
|
36
|
-
role: any;
|
|
37
|
-
authenticator: any;
|
|
38
|
-
token: any;
|
|
39
|
-
};
|
|
40
|
-
constructor(api: APIClient);
|
|
41
|
-
get locale(): string;
|
|
42
|
-
set locale(value: string);
|
|
43
|
-
get role(): string;
|
|
44
|
-
set role(value: string);
|
|
45
|
-
get token(): string;
|
|
46
|
-
set token(value: string);
|
|
47
|
-
get authenticator(): string;
|
|
48
|
-
set authenticator(value: string);
|
|
49
|
-
/**
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
getOption(key: string): string;
|
|
53
|
-
/**
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
setOption(key: string, value?: string): void;
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
* use {@link Auth#locale} instead
|
|
60
|
-
*/
|
|
61
|
-
getLocale(): string;
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
* use {@link Auth#locale} instead
|
|
65
|
-
*/
|
|
66
|
-
setLocale(locale: string): void;
|
|
67
|
-
/**
|
|
68
|
-
* @internal
|
|
69
|
-
* use {@link Auth#role} instead
|
|
70
|
-
*/
|
|
71
|
-
getRole(): string;
|
|
72
|
-
/**
|
|
73
|
-
* @internal
|
|
74
|
-
* use {@link Auth#role} instead
|
|
75
|
-
*/
|
|
76
|
-
setRole(role: string): void;
|
|
77
|
-
/**
|
|
78
|
-
* @internal
|
|
79
|
-
* use {@link Auth#token} instead
|
|
80
|
-
*/
|
|
81
|
-
getToken(): string;
|
|
82
|
-
/**
|
|
83
|
-
* @internal
|
|
84
|
-
* use {@link Auth#token} instead
|
|
85
|
-
*/
|
|
86
|
-
setToken(token: string): void;
|
|
87
|
-
/**
|
|
88
|
-
* @internal
|
|
89
|
-
* use {@link Auth#authenticator} instead
|
|
90
|
-
*/
|
|
91
|
-
getAuthenticator(): string;
|
|
92
|
-
/**
|
|
93
|
-
* @internal
|
|
94
|
-
* use {@link Auth#authenticator} instead
|
|
95
|
-
*/
|
|
96
|
-
setAuthenticator(authenticator: string): void;
|
|
97
|
-
middleware(config: AxiosRequestConfig): AxiosRequestConfig<any>;
|
|
98
|
-
signIn(values: any, authenticator?: string): Promise<AxiosResponse<any>>;
|
|
99
|
-
signUp(values: any, authenticator?: string): Promise<AxiosResponse<any>>;
|
|
100
|
-
signOut(): Promise<AxiosResponse<any, any>>;
|
|
101
|
-
lostPassword(values: any): Promise<AxiosResponse<any>>;
|
|
102
|
-
resetPassword(values: any): Promise<AxiosResponse<any>>;
|
|
103
|
-
checkResetToken(values: any): Promise<AxiosResponse<any>>;
|
|
104
|
-
}
|
|
105
|
-
export declare abstract class Storage {
|
|
106
|
-
abstract clear(): void;
|
|
107
|
-
abstract getItem(key: string): string | null;
|
|
108
|
-
abstract removeItem(key: string): void;
|
|
109
|
-
abstract setItem(key: string, value: string): void;
|
|
110
|
-
}
|
|
111
|
-
export declare class MemoryStorage extends Storage {
|
|
112
|
-
items: Map<any, any>;
|
|
113
|
-
clear(): void;
|
|
114
|
-
getItem(key: string): any;
|
|
115
|
-
setItem(key: string, value: string): Map<any, any>;
|
|
116
|
-
removeItem(key: string): boolean;
|
|
117
|
-
}
|
|
118
26
|
interface ExtendedOptions {
|
|
119
27
|
authClass?: any;
|
|
120
28
|
storageType?: 'localStorage' | 'sessionStorage' | 'memory';
|
|
121
29
|
storageClass?: any;
|
|
122
30
|
storagePrefix?: string;
|
|
31
|
+
appName?: string;
|
|
123
32
|
}
|
|
124
33
|
export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
|
|
125
34
|
export declare class APIClient {
|
|
126
35
|
options?: APIClientOptions;
|
|
127
36
|
axios: AxiosInstance;
|
|
128
37
|
auth: Auth;
|
|
129
|
-
storage:
|
|
38
|
+
storage: BaseStorage;
|
|
130
39
|
storagePrefix: string;
|
|
40
|
+
baseStoragePrefix: string;
|
|
41
|
+
toErrMessages(error: any): any;
|
|
131
42
|
getHeaders(): {};
|
|
132
43
|
constructor(options?: APIClientOptions);
|
|
44
|
+
createStorage(storageType: 'localStorage' | 'sessionStorage' | 'memory'): MemoryStorage | LocalStorage;
|
|
133
45
|
private initStorage;
|
|
134
46
|
interceptors(): void;
|
|
135
47
|
request<T = any, R = AxiosResponse<T>, D = any>(config: (AxiosRequestConfig<D> | ResourceActionOptions) & {
|
package/lib/APIClient.js
CHANGED
|
@@ -37,263 +37,41 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var APIClient_exports = {};
|
|
39
39
|
__export(APIClient_exports, {
|
|
40
|
-
APIClient: () => APIClient
|
|
41
|
-
Auth: () => Auth,
|
|
42
|
-
MemoryStorage: () => MemoryStorage,
|
|
43
|
-
Storage: () => Storage
|
|
40
|
+
APIClient: () => APIClient
|
|
44
41
|
});
|
|
45
42
|
module.exports = __toCommonJS(APIClient_exports);
|
|
46
43
|
var import_axios = __toESM(require("axios"));
|
|
47
44
|
var import_qs = __toESM(require("qs"));
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
}
|
|
71
|
-
options = {
|
|
72
|
-
locale: null,
|
|
73
|
-
role: null,
|
|
74
|
-
authenticator: null,
|
|
75
|
-
token: null
|
|
76
|
-
};
|
|
77
|
-
constructor(api) {
|
|
78
|
-
this.api = api;
|
|
79
|
-
this.api.axios.interceptors.request.use(this.middleware.bind(this));
|
|
80
|
-
}
|
|
81
|
-
get locale() {
|
|
82
|
-
return this.getLocale();
|
|
83
|
-
}
|
|
84
|
-
set locale(value) {
|
|
85
|
-
this.setLocale(value);
|
|
86
|
-
}
|
|
87
|
-
get role() {
|
|
88
|
-
return this.getRole();
|
|
89
|
-
}
|
|
90
|
-
set role(value) {
|
|
91
|
-
this.setRole(value);
|
|
92
|
-
}
|
|
93
|
-
get token() {
|
|
94
|
-
return this.getToken();
|
|
95
|
-
}
|
|
96
|
-
set token(value) {
|
|
97
|
-
this.setToken(value);
|
|
98
|
-
}
|
|
99
|
-
get authenticator() {
|
|
100
|
-
return this.getAuthenticator();
|
|
101
|
-
}
|
|
102
|
-
set authenticator(value) {
|
|
103
|
-
this.setAuthenticator(value);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
getOption(key) {
|
|
109
|
-
if (!this.KEYS[key]) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
return this.api.storage.getItem(this.KEYS[key]);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @internal
|
|
116
|
-
*/
|
|
117
|
-
setOption(key, value) {
|
|
118
|
-
if (!this.KEYS[key]) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
this.options[key] = value;
|
|
122
|
-
return this.api.storage.setItem(this.KEYS[key], value || "");
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* @internal
|
|
126
|
-
* use {@link Auth#locale} instead
|
|
127
|
-
*/
|
|
128
|
-
getLocale() {
|
|
129
|
-
return this.getOption("locale");
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* @internal
|
|
133
|
-
* use {@link Auth#locale} instead
|
|
134
|
-
*/
|
|
135
|
-
setLocale(locale) {
|
|
136
|
-
this.setOption("locale", locale);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @internal
|
|
140
|
-
* use {@link Auth#role} instead
|
|
141
|
-
*/
|
|
142
|
-
getRole() {
|
|
143
|
-
return this.getOption("role");
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* @internal
|
|
147
|
-
* use {@link Auth#role} instead
|
|
148
|
-
*/
|
|
149
|
-
setRole(role) {
|
|
150
|
-
this.setOption("role", role);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* @internal
|
|
154
|
-
* use {@link Auth#token} instead
|
|
155
|
-
*/
|
|
156
|
-
getToken() {
|
|
157
|
-
return this.getOption("token");
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @internal
|
|
161
|
-
* use {@link Auth#token} instead
|
|
162
|
-
*/
|
|
163
|
-
setToken(token) {
|
|
164
|
-
this.setOption("token", token);
|
|
165
|
-
if (this.api["app"]) {
|
|
166
|
-
this.api["app"].eventBus.dispatchEvent(
|
|
167
|
-
new CustomEvent("auth:tokenChanged", { detail: { token, authenticator: this.authenticator } })
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* @internal
|
|
173
|
-
* use {@link Auth#authenticator} instead
|
|
174
|
-
*/
|
|
175
|
-
getAuthenticator() {
|
|
176
|
-
return this.getOption("authenticator");
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* @internal
|
|
180
|
-
* use {@link Auth#authenticator} instead
|
|
181
|
-
*/
|
|
182
|
-
setAuthenticator(authenticator) {
|
|
183
|
-
this.setOption("authenticator", authenticator);
|
|
184
|
-
}
|
|
185
|
-
middleware(config) {
|
|
186
|
-
if (this.locale) {
|
|
187
|
-
config.headers["X-Locale"] = this.locale;
|
|
188
|
-
}
|
|
189
|
-
if (this.role) {
|
|
190
|
-
config.headers["X-Role"] = this.role;
|
|
191
|
-
}
|
|
192
|
-
if (this.authenticator && !config.headers["X-Authenticator"]) {
|
|
193
|
-
config.headers["X-Authenticator"] = this.authenticator;
|
|
194
|
-
}
|
|
195
|
-
if (this.token) {
|
|
196
|
-
config.headers["Authorization"] = `Bearer ${this.token}`;
|
|
197
|
-
}
|
|
198
|
-
return config;
|
|
199
|
-
}
|
|
200
|
-
async signIn(values, authenticator) {
|
|
201
|
-
var _a;
|
|
202
|
-
const response = await this.api.request({
|
|
203
|
-
method: "post",
|
|
204
|
-
url: "auth:signIn",
|
|
205
|
-
data: values,
|
|
206
|
-
headers: {
|
|
207
|
-
"X-Authenticator": authenticator
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
const data = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data;
|
|
211
|
-
this.setAuthenticator(authenticator);
|
|
212
|
-
this.setToken(data == null ? void 0 : data.token);
|
|
213
|
-
return response;
|
|
214
|
-
}
|
|
215
|
-
async signUp(values, authenticator) {
|
|
216
|
-
return await this.api.request({
|
|
217
|
-
method: "post",
|
|
218
|
-
url: "auth:signUp",
|
|
219
|
-
data: values,
|
|
220
|
-
headers: {
|
|
221
|
-
"X-Authenticator": authenticator
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
async signOut() {
|
|
226
|
-
const response = await this.api.request({
|
|
227
|
-
method: "post",
|
|
228
|
-
url: "auth:signOut"
|
|
229
|
-
});
|
|
230
|
-
this.setToken(null);
|
|
231
|
-
this.setRole(null);
|
|
232
|
-
this.setAuthenticator(null);
|
|
233
|
-
return response;
|
|
234
|
-
}
|
|
235
|
-
async lostPassword(values) {
|
|
236
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
237
|
-
const paramsObject = Object.fromEntries(searchParams.entries());
|
|
238
|
-
const response = await this.api.request({
|
|
239
|
-
method: "post",
|
|
240
|
-
url: "auth:lostPassword",
|
|
241
|
-
data: {
|
|
242
|
-
...values,
|
|
243
|
-
baseURL: window.location.href.split("/forgot-password")[0]
|
|
244
|
-
},
|
|
245
|
-
headers: {
|
|
246
|
-
"X-Authenticator": paramsObject.name
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
return response;
|
|
250
|
-
}
|
|
251
|
-
async resetPassword(values) {
|
|
252
|
-
const response = await this.api.request({
|
|
253
|
-
method: "post",
|
|
254
|
-
url: "auth:resetPassword",
|
|
255
|
-
data: values
|
|
256
|
-
});
|
|
257
|
-
return response;
|
|
258
|
-
}
|
|
259
|
-
async checkResetToken(values) {
|
|
260
|
-
const response = await this.api.request({
|
|
261
|
-
method: "post",
|
|
262
|
-
url: "auth:checkResetToken",
|
|
263
|
-
data: values
|
|
264
|
-
});
|
|
265
|
-
return response;
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
__name(_Auth, "Auth");
|
|
269
|
-
let Auth = _Auth;
|
|
270
|
-
const _Storage = class _Storage {
|
|
271
|
-
};
|
|
272
|
-
__name(_Storage, "Storage");
|
|
273
|
-
let Storage = _Storage;
|
|
274
|
-
const _MemoryStorage = class _MemoryStorage extends Storage {
|
|
275
|
-
items = /* @__PURE__ */ new Map();
|
|
276
|
-
clear() {
|
|
277
|
-
this.items.clear();
|
|
278
|
-
}
|
|
279
|
-
getItem(key) {
|
|
280
|
-
return this.items.get(key);
|
|
281
|
-
}
|
|
282
|
-
setItem(key, value) {
|
|
283
|
-
return this.items.set(key, value);
|
|
284
|
-
}
|
|
285
|
-
removeItem(key) {
|
|
286
|
-
return this.items.delete(key);
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
__name(_MemoryStorage, "MemoryStorage");
|
|
290
|
-
let MemoryStorage = _MemoryStorage;
|
|
45
|
+
var import_Auth = require("./Auth");
|
|
46
|
+
var import_Storage = require("./Storage");
|
|
291
47
|
const _APIClient = class _APIClient {
|
|
292
48
|
options;
|
|
293
49
|
axios;
|
|
294
50
|
auth;
|
|
295
51
|
storage;
|
|
296
52
|
storagePrefix = "NOCOBASE_";
|
|
53
|
+
baseStoragePrefix = "NOCOBASE_";
|
|
54
|
+
toErrMessages(error) {
|
|
55
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
56
|
+
if (typeof document !== "undefined" && typeof ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) === "string") {
|
|
57
|
+
const tempElement = document.createElement("div");
|
|
58
|
+
tempElement.innerHTML = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
59
|
+
let message = tempElement.textContent || tempElement.innerText;
|
|
60
|
+
if (message.includes("Error occurred while trying")) {
|
|
61
|
+
message = "The application may be starting up. Please try again later.";
|
|
62
|
+
return [{ code: "APP_WARNING", message }];
|
|
63
|
+
}
|
|
64
|
+
if (message.includes("502 Bad Gateway")) {
|
|
65
|
+
message = "The application may be starting up. Please try again later.";
|
|
66
|
+
return [{ code: "APP_WARNING", message }];
|
|
67
|
+
}
|
|
68
|
+
return [{ message }];
|
|
69
|
+
}
|
|
70
|
+
if ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.error) {
|
|
71
|
+
return [(_f = (_e = error == null ? void 0 : error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.error];
|
|
72
|
+
}
|
|
73
|
+
return ((_h = (_g = error == null ? void 0 : error.response) == null ? void 0 : _g.data) == null ? void 0 : _h.errors) || ((_j = (_i = error == null ? void 0 : error.response) == null ? void 0 : _i.data) == null ? void 0 : _j.messages) || ((_k = error == null ? void 0 : error.response) == null ? void 0 : _k.error) || [{ message: error.message || "Server error" }];
|
|
74
|
+
}
|
|
297
75
|
getHeaders() {
|
|
298
76
|
const headers = {};
|
|
299
77
|
if (this.auth.locale) {
|
|
@@ -315,8 +93,9 @@ const _APIClient = class _APIClient {
|
|
|
315
93
|
if (typeof options === "function") {
|
|
316
94
|
this.axios = options;
|
|
317
95
|
} else {
|
|
318
|
-
const { authClass, storageType, storageClass, storagePrefix = "NOCOBASE_", ...others } = options || {};
|
|
319
|
-
this.
|
|
96
|
+
const { appName, authClass, storageType, storageClass, storagePrefix = "NOCOBASE_", ...others } = options || {};
|
|
97
|
+
this.baseStoragePrefix = storagePrefix;
|
|
98
|
+
this.storagePrefix = appName ? `${storagePrefix}${appName.toUpperCase()}_` : storagePrefix;
|
|
320
99
|
this.axios = import_axios.default.create(others);
|
|
321
100
|
this.initStorage(storageClass, storageType);
|
|
322
101
|
if (authClass) {
|
|
@@ -327,24 +106,33 @@ const _APIClient = class _APIClient {
|
|
|
327
106
|
this.initStorage();
|
|
328
107
|
}
|
|
329
108
|
if (!this.auth) {
|
|
330
|
-
this.auth = new Auth(this);
|
|
109
|
+
this.auth = new import_Auth.Auth(this);
|
|
331
110
|
}
|
|
332
111
|
this.interceptors();
|
|
333
112
|
}
|
|
113
|
+
createStorage(storageType) {
|
|
114
|
+
if (storageType === "localStorage" && typeof localStorage !== "undefined") {
|
|
115
|
+
return new import_Storage.LocalStorage(this.storagePrefix, this.baseStoragePrefix);
|
|
116
|
+
}
|
|
117
|
+
if (storageType === "sessionStorage" && typeof sessionStorage !== "undefined") {
|
|
118
|
+
return new import_Storage.SessionStorage(this.storagePrefix, this.baseStoragePrefix);
|
|
119
|
+
}
|
|
120
|
+
return new import_Storage.MemoryStorage();
|
|
121
|
+
}
|
|
334
122
|
initStorage(storage, storageType = "localStorage") {
|
|
335
123
|
if (storage) {
|
|
336
124
|
this.storage = new storage(this);
|
|
337
125
|
return;
|
|
338
126
|
}
|
|
339
127
|
if (storageType === "localStorage" && typeof localStorage !== "undefined") {
|
|
340
|
-
this.storage =
|
|
128
|
+
this.storage = new import_Storage.LocalStorage(this.storagePrefix, this.baseStoragePrefix);
|
|
341
129
|
return;
|
|
342
130
|
}
|
|
343
131
|
if (storageType === "sessionStorage" && typeof sessionStorage !== "undefined") {
|
|
344
|
-
this.storage =
|
|
132
|
+
this.storage = new import_Storage.SessionStorage(this.storagePrefix, this.baseStoragePrefix);
|
|
345
133
|
return;
|
|
346
134
|
}
|
|
347
|
-
this.storage = new MemoryStorage();
|
|
135
|
+
this.storage = new import_Storage.MemoryStorage();
|
|
348
136
|
}
|
|
349
137
|
interceptors() {
|
|
350
138
|
this.axios.interceptors.request.use((config) => {
|
|
@@ -410,8 +198,5 @@ __name(_APIClient, "APIClient");
|
|
|
410
198
|
let APIClient = _APIClient;
|
|
411
199
|
// Annotate the CommonJS export names for ESM import in node:
|
|
412
200
|
0 && (module.exports = {
|
|
413
|
-
APIClient
|
|
414
|
-
Auth,
|
|
415
|
-
MemoryStorage,
|
|
416
|
-
Storage
|
|
201
|
+
APIClient
|
|
417
202
|
});
|
package/lib/Auth.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
10
|
+
import { APIClient } from './APIClient';
|
|
11
|
+
export declare class Auth {
|
|
12
|
+
protected api: APIClient;
|
|
13
|
+
get storagePrefix(): string;
|
|
14
|
+
protected options: {
|
|
15
|
+
locale: any;
|
|
16
|
+
role: any;
|
|
17
|
+
authenticator: any;
|
|
18
|
+
token: any;
|
|
19
|
+
};
|
|
20
|
+
constructor(api: APIClient);
|
|
21
|
+
get locale(): string;
|
|
22
|
+
set locale(value: string);
|
|
23
|
+
get role(): string;
|
|
24
|
+
set role(value: string);
|
|
25
|
+
get token(): string;
|
|
26
|
+
set token(value: string);
|
|
27
|
+
get authenticator(): string;
|
|
28
|
+
set authenticator(value: string);
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
getOption(key: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
setOption(key: string, value?: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
* use {@link Auth#locale} instead
|
|
40
|
+
*/
|
|
41
|
+
getLocale(): string;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
* use {@link Auth#locale} instead
|
|
45
|
+
*/
|
|
46
|
+
setLocale(locale: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
* use {@link Auth#role} instead
|
|
50
|
+
*/
|
|
51
|
+
getRole(): string;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
* use {@link Auth#role} instead
|
|
55
|
+
*/
|
|
56
|
+
setRole(role: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
* use {@link Auth#token} instead
|
|
60
|
+
*/
|
|
61
|
+
getToken(): string;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
* use {@link Auth#token} instead
|
|
65
|
+
*/
|
|
66
|
+
setToken(token: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* @internal
|
|
69
|
+
* use {@link Auth#authenticator} instead
|
|
70
|
+
*/
|
|
71
|
+
getAuthenticator(): string;
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
* use {@link Auth#authenticator} instead
|
|
75
|
+
*/
|
|
76
|
+
setAuthenticator(authenticator: string): void;
|
|
77
|
+
middleware(config: AxiosRequestConfig): AxiosRequestConfig<any>;
|
|
78
|
+
signIn(values: any, authenticator?: string): Promise<AxiosResponse<any>>;
|
|
79
|
+
signUp(values: any, authenticator?: string): Promise<AxiosResponse<any>>;
|
|
80
|
+
signOut(): Promise<AxiosResponse<any, any>>;
|
|
81
|
+
lostPassword(values: any): Promise<AxiosResponse<any>>;
|
|
82
|
+
resetPassword(values: any): Promise<AxiosResponse<any>>;
|
|
83
|
+
checkResetToken(values: any): Promise<AxiosResponse<any>>;
|
|
84
|
+
}
|
package/lib/Auth.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Auth_exports = {};
|
|
29
|
+
__export(Auth_exports, {
|
|
30
|
+
Auth: () => Auth
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Auth_exports);
|
|
33
|
+
const _Auth = class _Auth {
|
|
34
|
+
api;
|
|
35
|
+
get storagePrefix() {
|
|
36
|
+
return this.api.storagePrefix;
|
|
37
|
+
}
|
|
38
|
+
options = {
|
|
39
|
+
locale: null,
|
|
40
|
+
role: null,
|
|
41
|
+
authenticator: null,
|
|
42
|
+
token: null
|
|
43
|
+
};
|
|
44
|
+
constructor(api) {
|
|
45
|
+
this.api = api;
|
|
46
|
+
this.api.axios.interceptors.request.use(this.middleware.bind(this));
|
|
47
|
+
}
|
|
48
|
+
get locale() {
|
|
49
|
+
return this.getLocale();
|
|
50
|
+
}
|
|
51
|
+
set locale(value) {
|
|
52
|
+
this.setLocale(value);
|
|
53
|
+
}
|
|
54
|
+
get role() {
|
|
55
|
+
return this.getRole();
|
|
56
|
+
}
|
|
57
|
+
set role(value) {
|
|
58
|
+
this.setRole(value);
|
|
59
|
+
}
|
|
60
|
+
get token() {
|
|
61
|
+
return this.getToken();
|
|
62
|
+
}
|
|
63
|
+
set token(value) {
|
|
64
|
+
this.setToken(value);
|
|
65
|
+
}
|
|
66
|
+
get authenticator() {
|
|
67
|
+
return this.getAuthenticator();
|
|
68
|
+
}
|
|
69
|
+
set authenticator(value) {
|
|
70
|
+
this.setAuthenticator(value);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
getOption(key) {
|
|
76
|
+
return this.api.storage.getItem(key);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
setOption(key, value) {
|
|
82
|
+
this.options[key] = value;
|
|
83
|
+
return this.api.storage.setItem(key, value || "");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
* use {@link Auth#locale} instead
|
|
88
|
+
*/
|
|
89
|
+
getLocale() {
|
|
90
|
+
return this.getOption("locale");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
* use {@link Auth#locale} instead
|
|
95
|
+
*/
|
|
96
|
+
setLocale(locale) {
|
|
97
|
+
this.setOption("locale", locale);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
* use {@link Auth#role} instead
|
|
102
|
+
*/
|
|
103
|
+
getRole() {
|
|
104
|
+
return this.getOption("role");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
* use {@link Auth#role} instead
|
|
109
|
+
*/
|
|
110
|
+
setRole(role) {
|
|
111
|
+
this.setOption("role", role);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @internal
|
|
115
|
+
* use {@link Auth#token} instead
|
|
116
|
+
*/
|
|
117
|
+
getToken() {
|
|
118
|
+
return this.getOption("token");
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @internal
|
|
122
|
+
* use {@link Auth#token} instead
|
|
123
|
+
*/
|
|
124
|
+
setToken(token) {
|
|
125
|
+
this.setOption("token", token);
|
|
126
|
+
if (this.api["app"]) {
|
|
127
|
+
this.api["app"].eventBus.dispatchEvent(
|
|
128
|
+
new CustomEvent("auth:tokenChanged", { detail: { token, authenticator: this.authenticator } })
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
* use {@link Auth#authenticator} instead
|
|
135
|
+
*/
|
|
136
|
+
getAuthenticator() {
|
|
137
|
+
return this.getOption("auth");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
* use {@link Auth#authenticator} instead
|
|
142
|
+
*/
|
|
143
|
+
setAuthenticator(authenticator) {
|
|
144
|
+
this.setOption("auth", authenticator);
|
|
145
|
+
}
|
|
146
|
+
middleware(config) {
|
|
147
|
+
if (this.locale) {
|
|
148
|
+
config.headers["X-Locale"] = this.locale;
|
|
149
|
+
}
|
|
150
|
+
if (this.role) {
|
|
151
|
+
config.headers["X-Role"] = this.role;
|
|
152
|
+
}
|
|
153
|
+
if (this.authenticator && !config.headers["X-Authenticator"]) {
|
|
154
|
+
config.headers["X-Authenticator"] = this.authenticator;
|
|
155
|
+
}
|
|
156
|
+
if (this.token) {
|
|
157
|
+
config.headers["Authorization"] = `Bearer ${this.token}`;
|
|
158
|
+
}
|
|
159
|
+
return config;
|
|
160
|
+
}
|
|
161
|
+
async signIn(values, authenticator) {
|
|
162
|
+
var _a;
|
|
163
|
+
const response = await this.api.request({
|
|
164
|
+
method: "post",
|
|
165
|
+
url: "auth:signIn",
|
|
166
|
+
data: values,
|
|
167
|
+
headers: {
|
|
168
|
+
"X-Authenticator": authenticator
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const data = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data;
|
|
172
|
+
this.setAuthenticator(authenticator);
|
|
173
|
+
this.setToken(data == null ? void 0 : data.token);
|
|
174
|
+
return response;
|
|
175
|
+
}
|
|
176
|
+
async signUp(values, authenticator) {
|
|
177
|
+
return await this.api.request({
|
|
178
|
+
method: "post",
|
|
179
|
+
url: "auth:signUp",
|
|
180
|
+
data: values,
|
|
181
|
+
headers: {
|
|
182
|
+
"X-Authenticator": authenticator
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async signOut() {
|
|
187
|
+
const response = await this.api.request({
|
|
188
|
+
method: "post",
|
|
189
|
+
url: "auth:signOut"
|
|
190
|
+
});
|
|
191
|
+
this.setToken(null);
|
|
192
|
+
this.setRole(null);
|
|
193
|
+
this.setAuthenticator(null);
|
|
194
|
+
return response;
|
|
195
|
+
}
|
|
196
|
+
async lostPassword(values) {
|
|
197
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
198
|
+
const paramsObject = Object.fromEntries(searchParams.entries());
|
|
199
|
+
const response = await this.api.request({
|
|
200
|
+
method: "post",
|
|
201
|
+
url: "auth:lostPassword",
|
|
202
|
+
data: {
|
|
203
|
+
...values,
|
|
204
|
+
baseURL: window.location.href.split("/forgot-password")[0]
|
|
205
|
+
},
|
|
206
|
+
headers: {
|
|
207
|
+
"X-Authenticator": paramsObject.name
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return response;
|
|
211
|
+
}
|
|
212
|
+
async resetPassword(values) {
|
|
213
|
+
const response = await this.api.request({
|
|
214
|
+
method: "post",
|
|
215
|
+
url: "auth:resetPassword",
|
|
216
|
+
data: values
|
|
217
|
+
});
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
220
|
+
async checkResetToken(values) {
|
|
221
|
+
const response = await this.api.request({
|
|
222
|
+
method: "post",
|
|
223
|
+
url: "auth:checkResetToken",
|
|
224
|
+
data: values
|
|
225
|
+
});
|
|
226
|
+
return response;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
__name(_Auth, "Auth");
|
|
230
|
+
let Auth = _Auth;
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
Auth
|
|
234
|
+
});
|
package/lib/Storage.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class BaseStorage {
|
|
10
|
+
storagePrefix: string;
|
|
11
|
+
abstract clear(): void;
|
|
12
|
+
abstract getItem(key: string): string | null;
|
|
13
|
+
abstract removeItem(key: string): void;
|
|
14
|
+
abstract setItem(key: string, value: string): void;
|
|
15
|
+
toUpperCase(prefix?: string, ...arr: string[]): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class MemoryStorage extends BaseStorage {
|
|
18
|
+
items: Map<any, any>;
|
|
19
|
+
clear(): void;
|
|
20
|
+
getItem(key: string): any;
|
|
21
|
+
setItem(key: string, value: string): Map<any, any>;
|
|
22
|
+
removeItem(key: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class LocalStorage extends BaseStorage {
|
|
25
|
+
storagePrefix: string;
|
|
26
|
+
baseStoragePrefix: string;
|
|
27
|
+
items: Storage;
|
|
28
|
+
constructor(storagePrefix: string, baseStoragePrefix?: string);
|
|
29
|
+
clear(): void;
|
|
30
|
+
getItem(key: string): string;
|
|
31
|
+
setItem(key: string, value: string): void;
|
|
32
|
+
removeItem(key: string): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class SessionStorage extends LocalStorage {
|
|
35
|
+
storagePrefix: string;
|
|
36
|
+
baseStoragePrefix: string;
|
|
37
|
+
constructor(storagePrefix: string, baseStoragePrefix?: string);
|
|
38
|
+
}
|
package/lib/Storage.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Storage_exports = {};
|
|
29
|
+
__export(Storage_exports, {
|
|
30
|
+
BaseStorage: () => BaseStorage,
|
|
31
|
+
LocalStorage: () => LocalStorage,
|
|
32
|
+
MemoryStorage: () => MemoryStorage,
|
|
33
|
+
SessionStorage: () => SessionStorage
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(Storage_exports);
|
|
36
|
+
const _BaseStorage = class _BaseStorage {
|
|
37
|
+
storagePrefix;
|
|
38
|
+
toUpperCase(prefix = "", ...arr) {
|
|
39
|
+
return prefix.toUpperCase() + arr.map((str) => str.toUpperCase()).join("_");
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
__name(_BaseStorage, "BaseStorage");
|
|
43
|
+
let BaseStorage = _BaseStorage;
|
|
44
|
+
const _MemoryStorage = class _MemoryStorage extends BaseStorage {
|
|
45
|
+
items = /* @__PURE__ */ new Map();
|
|
46
|
+
clear() {
|
|
47
|
+
this.items.clear();
|
|
48
|
+
}
|
|
49
|
+
getItem(key) {
|
|
50
|
+
return this.items.get(key);
|
|
51
|
+
}
|
|
52
|
+
setItem(key, value) {
|
|
53
|
+
return this.items.set(key, value);
|
|
54
|
+
}
|
|
55
|
+
removeItem(key) {
|
|
56
|
+
return this.items.delete(key);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_MemoryStorage, "MemoryStorage");
|
|
60
|
+
let MemoryStorage = _MemoryStorage;
|
|
61
|
+
const _LocalStorage = class _LocalStorage extends BaseStorage {
|
|
62
|
+
constructor(storagePrefix, baseStoragePrefix = "") {
|
|
63
|
+
super();
|
|
64
|
+
this.storagePrefix = storagePrefix;
|
|
65
|
+
this.baseStoragePrefix = baseStoragePrefix;
|
|
66
|
+
this.items = window.localStorage;
|
|
67
|
+
}
|
|
68
|
+
items;
|
|
69
|
+
clear() {
|
|
70
|
+
return this.items.clear();
|
|
71
|
+
}
|
|
72
|
+
getItem(key) {
|
|
73
|
+
const value = this.items.getItem(this.toUpperCase(this.storagePrefix, key));
|
|
74
|
+
if (key === "token" && this.baseStoragePrefix) {
|
|
75
|
+
return value || this.items.getItem(this.toUpperCase(this.baseStoragePrefix, key));
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
setItem(key, value) {
|
|
80
|
+
console.log("setItem", this.toUpperCase(this.storagePrefix, key), value);
|
|
81
|
+
return this.items.setItem(this.toUpperCase(this.storagePrefix, key), value);
|
|
82
|
+
}
|
|
83
|
+
removeItem(key) {
|
|
84
|
+
return this.items.removeItem(this.toUpperCase(this.storagePrefix, key));
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__name(_LocalStorage, "LocalStorage");
|
|
88
|
+
let LocalStorage = _LocalStorage;
|
|
89
|
+
const _SessionStorage = class _SessionStorage extends LocalStorage {
|
|
90
|
+
constructor(storagePrefix, baseStoragePrefix = "") {
|
|
91
|
+
super(storagePrefix, baseStoragePrefix);
|
|
92
|
+
this.storagePrefix = storagePrefix;
|
|
93
|
+
this.baseStoragePrefix = baseStoragePrefix;
|
|
94
|
+
this.items = window.sessionStorage;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
__name(_SessionStorage, "SessionStorage");
|
|
98
|
+
let SessionStorage = _SessionStorage;
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
BaseStorage,
|
|
102
|
+
LocalStorage,
|
|
103
|
+
MemoryStorage,
|
|
104
|
+
SessionStorage
|
|
105
|
+
});
|
package/lib/getSubAppName.js
CHANGED
|
@@ -31,6 +31,12 @@ __export(getSubAppName_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(getSubAppName_exports);
|
|
33
33
|
const getSubAppName = /* @__PURE__ */ __name((publicPath = "/") => {
|
|
34
|
+
if (typeof window === "undefined") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!window.location.pathname) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
34
40
|
const prefix = `${publicPath}apps/`;
|
|
35
41
|
if (!window.location.pathname.startsWith(prefix)) {
|
|
36
42
|
return;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -41,9 +41,13 @@ __export(src_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(src_exports);
|
|
43
43
|
__reExport(src_exports, require("./APIClient"), module.exports);
|
|
44
|
+
__reExport(src_exports, require("./Auth"), module.exports);
|
|
45
|
+
__reExport(src_exports, require("./Storage"), module.exports);
|
|
44
46
|
var import_getSubAppName = __toESM(require("./getSubAppName"));
|
|
45
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
48
|
0 && (module.exports = {
|
|
47
49
|
getSubAppName,
|
|
48
|
-
...require("./APIClient")
|
|
50
|
+
...require("./APIClient"),
|
|
51
|
+
...require("./Auth"),
|
|
52
|
+
...require("./Storage")
|
|
49
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.60",
|
|
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": "9113d61ce85b60b7ba3d0e5ca64182d92a15ece4"
|
|
15
15
|
}
|