@etsoo/appscript 1.5.99 → 1.6.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/__tests__/app/CoreApp.ts +2 -2
- package/__tests__/app/TestApp.ts +2 -11
- package/lib/cjs/app/CoreApp.js +16 -5
- package/lib/cjs/app/ExternalSettings.d.ts +7 -3
- package/lib/cjs/app/ExternalSettings.js +14 -9
- package/lib/mjs/app/CoreApp.js +16 -5
- package/lib/mjs/app/ExternalSettings.d.ts +7 -3
- package/lib/mjs/app/ExternalSettings.js +14 -9
- package/package.json +1 -1
- package/src/app/CoreApp.ts +25 -8
- package/src/app/ExternalSettings.ts +26 -19
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -22,10 +22,10 @@ const app = new appClass();
|
|
|
22
22
|
await app.changeCulture(app.settings.cultures[0]);
|
|
23
23
|
|
|
24
24
|
test("Test for domain substitution", () => {
|
|
25
|
-
expect(app.settings.endpoint).toBe("http://
|
|
25
|
+
expect(app.settings.endpoint).toBe("http://admin.etsoo.com:9000/api/");
|
|
26
26
|
|
|
27
27
|
expect(app.settings.endpoints?.core.endpoint).toBe(
|
|
28
|
-
"https://
|
|
28
|
+
"https://core.etsoo.com:9001/api/"
|
|
29
29
|
);
|
|
30
30
|
});
|
|
31
31
|
|
package/__tests__/app/TestApp.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
CoreApp,
|
|
12
12
|
createClient,
|
|
13
13
|
Culture,
|
|
14
|
-
ExternalSettings,
|
|
15
14
|
IAppSettings,
|
|
16
15
|
InitCallResultData,
|
|
17
16
|
IUser
|
|
@@ -87,6 +86,8 @@ export class TestApp extends CoreApp<
|
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
88
|
|
|
89
|
+
hostname: "admin.etsoo.com",
|
|
90
|
+
|
|
90
91
|
/**
|
|
91
92
|
* App root url
|
|
92
93
|
*/
|
|
@@ -126,16 +127,6 @@ export class TestApp extends CoreApp<
|
|
|
126
127
|
);
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
// Example of local format settings
|
|
130
|
-
protected override formatSettings(settings: IAppSettings): IAppSettings {
|
|
131
|
-
const { endpoint, endpoints, ...rest } = settings;
|
|
132
|
-
return {
|
|
133
|
-
...rest,
|
|
134
|
-
endpoint: ExternalSettings.formatHost(endpoint, "localhost"),
|
|
135
|
-
endpoints: ExternalSettings.formatHost(endpoints, "localhost")
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
130
|
freshCountdownUI(callback?: () => PromiseLike<unknown>): void {
|
|
140
131
|
throw new Error("Method not implemented.");
|
|
141
132
|
}
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -11,6 +11,7 @@ const EntityStatus_1 = require("../business/EntityStatus");
|
|
|
11
11
|
const ActionResultError_1 = require("../result/ActionResultError");
|
|
12
12
|
const IApp_1 = require("./IApp");
|
|
13
13
|
const UserRole_1 = require("./UserRole");
|
|
14
|
+
const ExternalSettings_1 = require("./ExternalSettings");
|
|
14
15
|
const AuthApi_1 = require("../api/AuthApi");
|
|
15
16
|
let CJ;
|
|
16
17
|
const loadCrypto = () => import("crypto-js");
|
|
@@ -188,17 +189,19 @@ class CoreApp {
|
|
|
188
189
|
}
|
|
189
190
|
return undefined;
|
|
190
191
|
};
|
|
192
|
+
// Destruct the settings
|
|
193
|
+
const { currentCulture, currentRegion, endpoint, webUrl } = this.settings;
|
|
191
194
|
if (api) {
|
|
192
195
|
// Base URL of the API
|
|
193
|
-
api.baseUrl =
|
|
196
|
+
api.baseUrl = endpoint;
|
|
194
197
|
api.name = systemApi;
|
|
195
198
|
this.setApi(api, refresh);
|
|
196
199
|
this.api = api;
|
|
197
200
|
}
|
|
198
201
|
else {
|
|
199
202
|
this.api = this.createApi(systemApi, {
|
|
200
|
-
endpoint
|
|
201
|
-
webUrl
|
|
203
|
+
endpoint,
|
|
204
|
+
webUrl
|
|
202
205
|
}, refresh);
|
|
203
206
|
}
|
|
204
207
|
this.notifier = notifier;
|
|
@@ -219,7 +222,6 @@ class CoreApp {
|
|
|
219
222
|
// Embedded
|
|
220
223
|
this._embedded =
|
|
221
224
|
this.storage.getData(this.fields.embedded) ?? false;
|
|
222
|
-
const { currentCulture, currentRegion } = settings;
|
|
223
225
|
// Load resources
|
|
224
226
|
Promise.all([loadCrypto(), this.changeCulture(currentCulture)]).then(([cj, _resources]) => {
|
|
225
227
|
CJ = cj.default;
|
|
@@ -237,7 +239,16 @@ class CoreApp {
|
|
|
237
239
|
* @returns Result
|
|
238
240
|
*/
|
|
239
241
|
formatSettings(settings) {
|
|
240
|
-
|
|
242
|
+
const { endpoint, webUrl, endpoints, hostname = globalThis.location.hostname, ...rest } = settings;
|
|
243
|
+
return {
|
|
244
|
+
...rest,
|
|
245
|
+
hostname,
|
|
246
|
+
endpoint: ExternalSettings_1.ExternalSettings.formatHost(endpoint, hostname),
|
|
247
|
+
webUrl: ExternalSettings_1.ExternalSettings.formatHost(webUrl, hostname),
|
|
248
|
+
endpoints: endpoints == null
|
|
249
|
+
? undefined
|
|
250
|
+
: ExternalSettings_1.ExternalSettings.formatHost(endpoints, hostname)
|
|
251
|
+
};
|
|
241
252
|
}
|
|
242
253
|
getDeviceId() {
|
|
243
254
|
return this.deviceId.substring(0, 15);
|
|
@@ -28,6 +28,11 @@ export interface IExternalSettings extends ExternalEndpoint {
|
|
|
28
28
|
* 程序编号
|
|
29
29
|
*/
|
|
30
30
|
readonly appId: number;
|
|
31
|
+
/**
|
|
32
|
+
* Default hostname for substitution
|
|
33
|
+
* 用于替换的默认主机名
|
|
34
|
+
*/
|
|
35
|
+
hostname?: string;
|
|
31
36
|
/**
|
|
32
37
|
* Endpoints to other services
|
|
33
38
|
*/
|
|
@@ -46,7 +51,7 @@ export declare namespace ExternalSettings {
|
|
|
46
51
|
* @param settings Settings
|
|
47
52
|
* @returns Result
|
|
48
53
|
*/
|
|
49
|
-
function create<T extends IExternalSettings = IExternalSettings>(settings
|
|
54
|
+
function create<T extends IExternalSettings = IExternalSettings>(settings?: unknown, hostname?: string): T;
|
|
50
55
|
/**
|
|
51
56
|
* Format the app
|
|
52
57
|
* @param hostname Hostname
|
|
@@ -61,7 +66,6 @@ export declare namespace ExternalSettings {
|
|
|
61
66
|
* @param hostname Hostname
|
|
62
67
|
* @returns Result
|
|
63
68
|
*/
|
|
64
|
-
function formatHost(setting: string, hostname
|
|
69
|
+
function formatHost(setting: string, hostname: string): string;
|
|
65
70
|
function formatHost(setting: Record<string, ExternalEndpoint>, hostname?: string | null): Record<string, ExternalEndpoint>;
|
|
66
|
-
function formatHost(setting: undefined, hostname?: string | null): undefined;
|
|
67
71
|
}
|
|
@@ -15,14 +15,22 @@ var ExternalSettings;
|
|
|
15
15
|
* @param settings Settings
|
|
16
16
|
* @returns Result
|
|
17
17
|
*/
|
|
18
|
-
function create(settings) {
|
|
18
|
+
function create(settings, hostname) {
|
|
19
19
|
// Default settings reading from globalThis
|
|
20
20
|
settings ?? (settings = Reflect.get(globalThis, "settings"));
|
|
21
|
-
if (settings
|
|
22
|
-
typeof settings === "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (settings) {
|
|
22
|
+
if (typeof settings === "string") {
|
|
23
|
+
settings = JSON.parse(settings);
|
|
24
|
+
}
|
|
25
|
+
if (settings != null &&
|
|
26
|
+
typeof settings === "object" &&
|
|
27
|
+
"appId" in settings &&
|
|
28
|
+
"endpoint" in settings) {
|
|
29
|
+
const s = settings;
|
|
30
|
+
if (hostname)
|
|
31
|
+
s.hostname = hostname;
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
throw new Error("No external settings found");
|
|
28
36
|
}
|
|
@@ -39,9 +47,6 @@ var ExternalSettings;
|
|
|
39
47
|
}
|
|
40
48
|
ExternalSettings.formatApp = formatApp;
|
|
41
49
|
function formatHost(setting, hostname) {
|
|
42
|
-
// No setting
|
|
43
|
-
if (setting == null)
|
|
44
|
-
return undefined;
|
|
45
50
|
// Default hostname
|
|
46
51
|
hostname ?? (hostname = globalThis.location.hostname);
|
|
47
52
|
if (typeof setting === "string") {
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -8,6 +8,7 @@ import { EntityStatus } from "../business/EntityStatus";
|
|
|
8
8
|
import { ActionResultError } from "../result/ActionResultError";
|
|
9
9
|
import { appFields } from "./IApp";
|
|
10
10
|
import { UserRole } from "./UserRole";
|
|
11
|
+
import { ExternalSettings } from "./ExternalSettings";
|
|
11
12
|
import { AuthApi } from "../api/AuthApi";
|
|
12
13
|
let CJ;
|
|
13
14
|
const loadCrypto = () => import("crypto-js");
|
|
@@ -185,17 +186,19 @@ export class CoreApp {
|
|
|
185
186
|
}
|
|
186
187
|
return undefined;
|
|
187
188
|
};
|
|
189
|
+
// Destruct the settings
|
|
190
|
+
const { currentCulture, currentRegion, endpoint, webUrl } = this.settings;
|
|
188
191
|
if (api) {
|
|
189
192
|
// Base URL of the API
|
|
190
|
-
api.baseUrl =
|
|
193
|
+
api.baseUrl = endpoint;
|
|
191
194
|
api.name = systemApi;
|
|
192
195
|
this.setApi(api, refresh);
|
|
193
196
|
this.api = api;
|
|
194
197
|
}
|
|
195
198
|
else {
|
|
196
199
|
this.api = this.createApi(systemApi, {
|
|
197
|
-
endpoint
|
|
198
|
-
webUrl
|
|
200
|
+
endpoint,
|
|
201
|
+
webUrl
|
|
199
202
|
}, refresh);
|
|
200
203
|
}
|
|
201
204
|
this.notifier = notifier;
|
|
@@ -216,7 +219,6 @@ export class CoreApp {
|
|
|
216
219
|
// Embedded
|
|
217
220
|
this._embedded =
|
|
218
221
|
this.storage.getData(this.fields.embedded) ?? false;
|
|
219
|
-
const { currentCulture, currentRegion } = settings;
|
|
220
222
|
// Load resources
|
|
221
223
|
Promise.all([loadCrypto(), this.changeCulture(currentCulture)]).then(([cj, _resources]) => {
|
|
222
224
|
CJ = cj.default;
|
|
@@ -234,7 +236,16 @@ export class CoreApp {
|
|
|
234
236
|
* @returns Result
|
|
235
237
|
*/
|
|
236
238
|
formatSettings(settings) {
|
|
237
|
-
|
|
239
|
+
const { endpoint, webUrl, endpoints, hostname = globalThis.location.hostname, ...rest } = settings;
|
|
240
|
+
return {
|
|
241
|
+
...rest,
|
|
242
|
+
hostname,
|
|
243
|
+
endpoint: ExternalSettings.formatHost(endpoint, hostname),
|
|
244
|
+
webUrl: ExternalSettings.formatHost(webUrl, hostname),
|
|
245
|
+
endpoints: endpoints == null
|
|
246
|
+
? undefined
|
|
247
|
+
: ExternalSettings.formatHost(endpoints, hostname)
|
|
248
|
+
};
|
|
238
249
|
}
|
|
239
250
|
getDeviceId() {
|
|
240
251
|
return this.deviceId.substring(0, 15);
|
|
@@ -28,6 +28,11 @@ export interface IExternalSettings extends ExternalEndpoint {
|
|
|
28
28
|
* 程序编号
|
|
29
29
|
*/
|
|
30
30
|
readonly appId: number;
|
|
31
|
+
/**
|
|
32
|
+
* Default hostname for substitution
|
|
33
|
+
* 用于替换的默认主机名
|
|
34
|
+
*/
|
|
35
|
+
hostname?: string;
|
|
31
36
|
/**
|
|
32
37
|
* Endpoints to other services
|
|
33
38
|
*/
|
|
@@ -46,7 +51,7 @@ export declare namespace ExternalSettings {
|
|
|
46
51
|
* @param settings Settings
|
|
47
52
|
* @returns Result
|
|
48
53
|
*/
|
|
49
|
-
function create<T extends IExternalSettings = IExternalSettings>(settings
|
|
54
|
+
function create<T extends IExternalSettings = IExternalSettings>(settings?: unknown, hostname?: string): T;
|
|
50
55
|
/**
|
|
51
56
|
* Format the app
|
|
52
57
|
* @param hostname Hostname
|
|
@@ -61,7 +66,6 @@ export declare namespace ExternalSettings {
|
|
|
61
66
|
* @param hostname Hostname
|
|
62
67
|
* @returns Result
|
|
63
68
|
*/
|
|
64
|
-
function formatHost(setting: string, hostname
|
|
69
|
+
function formatHost(setting: string, hostname: string): string;
|
|
65
70
|
function formatHost(setting: Record<string, ExternalEndpoint>, hostname?: string | null): Record<string, ExternalEndpoint>;
|
|
66
|
-
function formatHost(setting: undefined, hostname?: string | null): undefined;
|
|
67
71
|
}
|
|
@@ -12,14 +12,22 @@ export var ExternalSettings;
|
|
|
12
12
|
* @param settings Settings
|
|
13
13
|
* @returns Result
|
|
14
14
|
*/
|
|
15
|
-
function create(settings) {
|
|
15
|
+
function create(settings, hostname) {
|
|
16
16
|
// Default settings reading from globalThis
|
|
17
17
|
settings ?? (settings = Reflect.get(globalThis, "settings"));
|
|
18
|
-
if (settings
|
|
19
|
-
typeof settings === "
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (settings) {
|
|
19
|
+
if (typeof settings === "string") {
|
|
20
|
+
settings = JSON.parse(settings);
|
|
21
|
+
}
|
|
22
|
+
if (settings != null &&
|
|
23
|
+
typeof settings === "object" &&
|
|
24
|
+
"appId" in settings &&
|
|
25
|
+
"endpoint" in settings) {
|
|
26
|
+
const s = settings;
|
|
27
|
+
if (hostname)
|
|
28
|
+
s.hostname = hostname;
|
|
29
|
+
return s;
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
throw new Error("No external settings found");
|
|
25
33
|
}
|
|
@@ -36,9 +44,6 @@ export var ExternalSettings;
|
|
|
36
44
|
}
|
|
37
45
|
ExternalSettings.formatApp = formatApp;
|
|
38
46
|
function formatHost(setting, hostname) {
|
|
39
|
-
// No setting
|
|
40
|
-
if (setting == null)
|
|
41
|
-
return undefined;
|
|
42
47
|
// Default hostname
|
|
43
48
|
hostname ?? (hostname = globalThis.location.hostname);
|
|
44
49
|
if (typeof setting === "string") {
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
import { UserRole } from "./UserRole";
|
|
46
46
|
import type CryptoJS from "crypto-js";
|
|
47
47
|
import { Currency } from "../business/Currency";
|
|
48
|
-
import { ExternalEndpoint } from "./ExternalSettings";
|
|
48
|
+
import { ExternalEndpoint, ExternalSettings } from "./ExternalSettings";
|
|
49
49
|
import { ApiRefreshTokenDto } from "../api/dto/ApiRefreshTokenDto";
|
|
50
50
|
import { ApiRefreshTokenRQ } from "../api/rq/ApiRefreshTokenRQ";
|
|
51
51
|
import { AuthApi } from "../api/AuthApi";
|
|
@@ -365,9 +365,12 @@ export abstract class CoreApp<
|
|
|
365
365
|
return undefined;
|
|
366
366
|
};
|
|
367
367
|
|
|
368
|
+
// Destruct the settings
|
|
369
|
+
const { currentCulture, currentRegion, endpoint, webUrl } = this.settings;
|
|
370
|
+
|
|
368
371
|
if (api) {
|
|
369
372
|
// Base URL of the API
|
|
370
|
-
api.baseUrl =
|
|
373
|
+
api.baseUrl = endpoint;
|
|
371
374
|
api.name = systemApi;
|
|
372
375
|
this.setApi(api, refresh);
|
|
373
376
|
this.api = api;
|
|
@@ -375,8 +378,8 @@ export abstract class CoreApp<
|
|
|
375
378
|
this.api = this.createApi(
|
|
376
379
|
systemApi,
|
|
377
380
|
{
|
|
378
|
-
endpoint
|
|
379
|
-
webUrl
|
|
381
|
+
endpoint,
|
|
382
|
+
webUrl
|
|
380
383
|
},
|
|
381
384
|
refresh
|
|
382
385
|
);
|
|
@@ -408,8 +411,6 @@ export abstract class CoreApp<
|
|
|
408
411
|
this._embedded =
|
|
409
412
|
this.storage.getData<boolean>(this.fields.embedded) ?? false;
|
|
410
413
|
|
|
411
|
-
const { currentCulture, currentRegion } = settings;
|
|
412
|
-
|
|
413
414
|
// Load resources
|
|
414
415
|
Promise.all([loadCrypto(), this.changeCulture(currentCulture)]).then(
|
|
415
416
|
([cj, _resources]) => {
|
|
@@ -438,8 +439,24 @@ export abstract class CoreApp<
|
|
|
438
439
|
* @param settings Original settings
|
|
439
440
|
* @returns Result
|
|
440
441
|
*/
|
|
441
|
-
protected formatSettings(settings: S) {
|
|
442
|
-
|
|
442
|
+
protected formatSettings(settings: S): S {
|
|
443
|
+
const {
|
|
444
|
+
endpoint,
|
|
445
|
+
webUrl,
|
|
446
|
+
endpoints,
|
|
447
|
+
hostname = globalThis.location.hostname,
|
|
448
|
+
...rest
|
|
449
|
+
} = settings;
|
|
450
|
+
return {
|
|
451
|
+
...rest,
|
|
452
|
+
hostname,
|
|
453
|
+
endpoint: ExternalSettings.formatHost(endpoint, hostname),
|
|
454
|
+
webUrl: ExternalSettings.formatHost(webUrl, hostname),
|
|
455
|
+
endpoints:
|
|
456
|
+
endpoints == null
|
|
457
|
+
? undefined
|
|
458
|
+
: ExternalSettings.formatHost(endpoints, hostname)
|
|
459
|
+
} as S;
|
|
443
460
|
}
|
|
444
461
|
|
|
445
462
|
private getDeviceId() {
|
|
@@ -33,6 +33,12 @@ export interface IExternalSettings extends ExternalEndpoint {
|
|
|
33
33
|
*/
|
|
34
34
|
readonly appId: number;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Default hostname for substitution
|
|
38
|
+
* 用于替换的默认主机名
|
|
39
|
+
*/
|
|
40
|
+
hostname?: string;
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* Endpoints to other services
|
|
38
44
|
*/
|
|
@@ -57,18 +63,27 @@ export namespace ExternalSettings {
|
|
|
57
63
|
* @returns Result
|
|
58
64
|
*/
|
|
59
65
|
export function create<T extends IExternalSettings = IExternalSettings>(
|
|
60
|
-
settings
|
|
66
|
+
settings?: unknown,
|
|
67
|
+
hostname?: string
|
|
61
68
|
): T {
|
|
62
69
|
// Default settings reading from globalThis
|
|
63
70
|
settings ??= Reflect.get(globalThis, "settings");
|
|
64
71
|
|
|
65
|
-
if (
|
|
66
|
-
settings
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
if (settings) {
|
|
73
|
+
if (typeof settings === "string") {
|
|
74
|
+
settings = JSON.parse(settings);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
settings != null &&
|
|
79
|
+
typeof settings === "object" &&
|
|
80
|
+
"appId" in settings &&
|
|
81
|
+
"endpoint" in settings
|
|
82
|
+
) {
|
|
83
|
+
const s = settings as T;
|
|
84
|
+
if (hostname) s.hostname = hostname;
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
throw new Error("No external settings found");
|
|
@@ -91,7 +106,7 @@ export namespace ExternalSettings {
|
|
|
91
106
|
* @param hostname Hostname
|
|
92
107
|
* @returns Result
|
|
93
108
|
*/
|
|
94
|
-
export function formatHost(setting: string, hostname
|
|
109
|
+
export function formatHost(setting: string, hostname: string): string;
|
|
95
110
|
|
|
96
111
|
export function formatHost(
|
|
97
112
|
setting: Record<string, ExternalEndpoint>,
|
|
@@ -99,17 +114,9 @@ export namespace ExternalSettings {
|
|
|
99
114
|
): Record<string, ExternalEndpoint>;
|
|
100
115
|
|
|
101
116
|
export function formatHost(
|
|
102
|
-
setting:
|
|
117
|
+
setting: string | Record<string, ExternalEndpoint>,
|
|
103
118
|
hostname?: string | null
|
|
104
|
-
):
|
|
105
|
-
|
|
106
|
-
export function formatHost(
|
|
107
|
-
setting?: string | Record<string, ExternalEndpoint>,
|
|
108
|
-
hostname?: string | null
|
|
109
|
-
): string | Record<string, ExternalEndpoint> | undefined {
|
|
110
|
-
// No setting
|
|
111
|
-
if (setting == null) return undefined;
|
|
112
|
-
|
|
119
|
+
): string | Record<string, ExternalEndpoint> {
|
|
113
120
|
// Default hostname
|
|
114
121
|
hostname ??= globalThis.location.hostname;
|
|
115
122
|
|