@nocobase/sdk 1.2.13-alpha → 1.3.0-alpha.20240710084543

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/sdk",
3
- "version": "1.2.13-alpha",
3
+ "version": "1.3.0-alpha.20240710084543",
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": "b6a1c2ee330b47c2581ea2ce15ee46210e6220f2"
14
+ "gitHead": "07a8b596fc64a9779a194cb9b0dc2ca7570ed9d4"
15
15
  }
@@ -1,133 +0,0 @@
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 { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
10
- export interface ActionParams {
11
- filterByTk?: any;
12
- [key: string]: any;
13
- }
14
- type ResourceActionOptions<P = any> = {
15
- resource?: string;
16
- resourceOf?: any;
17
- action?: string;
18
- params?: P;
19
- };
20
- type ResourceAction = (params?: ActionParams) => Promise<any>;
21
- export type IResource = {
22
- [key: string]: ResourceAction;
23
- };
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
- }
102
- export declare abstract class Storage {
103
- abstract clear(): void;
104
- abstract getItem(key: string): string | null;
105
- abstract removeItem(key: string): void;
106
- abstract setItem(key: string, value: string): void;
107
- }
108
- export declare class MemoryStorage extends Storage {
109
- items: Map<any, any>;
110
- clear(): void;
111
- getItem(key: string): any;
112
- setItem(key: string, value: string): Map<any, any>;
113
- removeItem(key: string): boolean;
114
- }
115
- interface ExtendedOptions {
116
- authClass?: any;
117
- storageClass?: any;
118
- storagePrefix?: string;
119
- }
120
- export type APIClientOptions = AxiosInstance | (AxiosRequestConfig & ExtendedOptions);
121
- export declare class APIClient {
122
- axios: AxiosInstance;
123
- auth: Auth;
124
- storage: Storage;
125
- storagePrefix: string;
126
- getHeaders(): {};
127
- constructor(instance?: APIClientOptions);
128
- private initStorage;
129
- interceptors(): void;
130
- request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R>;
131
- resource(name: string, of?: any, headers?: AxiosRequestHeaders): IResource;
132
- }
133
- export {};
package/lib/APIClient.js DELETED
@@ -1,369 +0,0 @@
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 __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var APIClient_exports = {};
39
- __export(APIClient_exports, {
40
- APIClient: () => APIClient,
41
- Auth: () => Auth,
42
- MemoryStorage: () => MemoryStorage,
43
- Storage: () => Storage
44
- });
45
- module.exports = __toCommonJS(APIClient_exports);
46
- var import_axios = __toESM(require("axios"));
47
- var import_qs = __toESM(require("qs"));
48
- const _Auth = class _Auth {
49
- api;
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
- }
166
- /**
167
- * @internal
168
- * use {@link Auth#authenticator} instead
169
- */
170
- getAuthenticator() {
171
- return this.getOption("authenticator");
172
- }
173
- /**
174
- * @internal
175
- * use {@link Auth#authenticator} instead
176
- */
177
- setAuthenticator(authenticator) {
178
- this.setOption("authenticator", authenticator);
179
- }
180
- middleware(config) {
181
- if (this.locale) {
182
- config.headers["X-Locale"] = this.locale;
183
- }
184
- if (this.role) {
185
- config.headers["X-Role"] = this.role;
186
- }
187
- if (this.authenticator && !config.headers["X-Authenticator"]) {
188
- config.headers["X-Authenticator"] = this.authenticator;
189
- }
190
- if (this.token) {
191
- config.headers["Authorization"] = `Bearer ${this.token}`;
192
- }
193
- return config;
194
- }
195
- async signIn(values, authenticator) {
196
- var _a;
197
- const response = await this.api.request({
198
- method: "post",
199
- url: "auth:signIn",
200
- data: values,
201
- headers: {
202
- "X-Authenticator": authenticator
203
- }
204
- });
205
- const data = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data;
206
- this.setToken(data == null ? void 0 : data.token);
207
- this.setAuthenticator(authenticator);
208
- return response;
209
- }
210
- async signUp(values, authenticator) {
211
- return await this.api.request({
212
- method: "post",
213
- url: "auth:signUp",
214
- data: values,
215
- headers: {
216
- "X-Authenticator": authenticator
217
- }
218
- });
219
- }
220
- async signOut() {
221
- const response = await this.api.request({
222
- method: "post",
223
- url: "auth:signOut"
224
- });
225
- this.setToken(null);
226
- this.setRole(null);
227
- this.setAuthenticator(null);
228
- return response;
229
- }
230
- };
231
- __name(_Auth, "Auth");
232
- let Auth = _Auth;
233
- const _Storage = class _Storage {
234
- };
235
- __name(_Storage, "Storage");
236
- let Storage = _Storage;
237
- const _MemoryStorage = class _MemoryStorage extends Storage {
238
- items = /* @__PURE__ */ new Map();
239
- clear() {
240
- this.items.clear();
241
- }
242
- getItem(key) {
243
- return this.items.get(key);
244
- }
245
- setItem(key, value) {
246
- return this.items.set(key, value);
247
- }
248
- removeItem(key) {
249
- return this.items.delete(key);
250
- }
251
- };
252
- __name(_MemoryStorage, "MemoryStorage");
253
- let MemoryStorage = _MemoryStorage;
254
- const _APIClient = class _APIClient {
255
- axios;
256
- auth;
257
- storage;
258
- storagePrefix = "NOCOBASE_";
259
- getHeaders() {
260
- const headers = {};
261
- if (this.auth.locale) {
262
- headers["X-Locale"] = this.auth.locale;
263
- }
264
- if (this.auth.role) {
265
- headers["X-Role"] = this.auth.role;
266
- }
267
- if (this.auth.authenticator) {
268
- headers["X-Authenticator"] = this.auth.authenticator;
269
- }
270
- if (this.auth.token) {
271
- headers["Authorization"] = `Bearer ${this.auth.token}`;
272
- }
273
- return headers;
274
- }
275
- constructor(instance) {
276
- if (typeof instance === "function") {
277
- this.axios = instance;
278
- } else {
279
- const { authClass, storageClass, storagePrefix = "NOCOBASE_", ...others } = instance || {};
280
- this.storagePrefix = storagePrefix;
281
- this.axios = import_axios.default.create(others);
282
- this.initStorage(storageClass);
283
- if (authClass) {
284
- this.auth = new authClass(this);
285
- }
286
- }
287
- if (!this.storage) {
288
- this.initStorage();
289
- }
290
- if (!this.auth) {
291
- this.auth = new Auth(this);
292
- }
293
- this.interceptors();
294
- }
295
- initStorage(storage) {
296
- if (storage) {
297
- this.storage = new storage(this);
298
- } else if (typeof localStorage !== "undefined") {
299
- this.storage = localStorage;
300
- } else {
301
- this.storage = new MemoryStorage();
302
- }
303
- }
304
- interceptors() {
305
- this.axios.interceptors.request.use((config) => {
306
- config.paramsSerializer = (params) => {
307
- return import_qs.default.stringify(params, {
308
- strictNullHandling: true,
309
- arrayFormat: "brackets"
310
- });
311
- };
312
- return config;
313
- });
314
- }
315
- request(config) {
316
- const { resource, resourceOf, action, params, headers } = config;
317
- if (resource) {
318
- return this.resource(resource, resourceOf, headers)[action](params);
319
- }
320
- return this.axios.request(config);
321
- }
322
- resource(name, of, headers) {
323
- const target = {};
324
- const handler = {
325
- get: (_, actionName) => {
326
- let url = name.split(".").join(`/${encodeURIComponent(of) || "_"}/`);
327
- url += `:${actionName}`;
328
- const config = { url };
329
- if (["get", "list"].includes(actionName)) {
330
- config["method"] = "get";
331
- } else {
332
- config["method"] = "post";
333
- }
334
- return async (params, opts) => {
335
- const { values, filter, ...others } = params || {};
336
- config["params"] = others;
337
- if (filter) {
338
- if (typeof filter === "string") {
339
- config["params"]["filter"] = filter;
340
- } else {
341
- if (filter["*"]) {
342
- delete filter["*"];
343
- }
344
- config["params"]["filter"] = JSON.stringify(filter);
345
- }
346
- }
347
- if (config.method !== "get") {
348
- config["data"] = values || {};
349
- }
350
- return await this.request({
351
- ...config,
352
- ...opts,
353
- headers
354
- });
355
- };
356
- }
357
- };
358
- return new Proxy(target, handler);
359
- }
360
- };
361
- __name(_APIClient, "APIClient");
362
- let APIClient = _APIClient;
363
- // Annotate the CommonJS export names for ESM import in node:
364
- 0 && (module.exports = {
365
- APIClient,
366
- Auth,
367
- MemoryStorage,
368
- Storage
369
- });
@@ -1,10 +0,0 @@
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
- declare const getSubAppName: (publicPath?: string) => string;
10
- export default getSubAppName;
@@ -1,42 +0,0 @@
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 getSubAppName_exports = {};
29
- __export(getSubAppName_exports, {
30
- default: () => getSubAppName_default
31
- });
32
- module.exports = __toCommonJS(getSubAppName_exports);
33
- const getSubAppName = /* @__PURE__ */ __name((publicPath = "/") => {
34
- const prefix = `${publicPath}apps/`;
35
- if (!window.location.pathname.startsWith(prefix)) {
36
- return;
37
- }
38
- const pathname = window.location.pathname.substring(prefix.length);
39
- const args = pathname.split("/", 1);
40
- return args[0] || "";
41
- }, "getSubAppName");
42
- var getSubAppName_default = getSubAppName;
package/lib/index.d.ts DELETED
@@ -1,10 +0,0 @@
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 * from './APIClient';
10
- export { default as getSubAppName } from './getSubAppName';
package/lib/index.js DELETED
@@ -1,49 +0,0 @@
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 __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var src_exports = {};
39
- __export(src_exports, {
40
- getSubAppName: () => import_getSubAppName.default
41
- });
42
- module.exports = __toCommonJS(src_exports);
43
- __reExport(src_exports, require("./APIClient"), module.exports);
44
- var import_getSubAppName = __toESM(require("./getSubAppName"));
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- getSubAppName,
48
- ...require("./APIClient")
49
- });