@blocklet/sdk 1.17.2-beta-20251113-212234-9e640edd → 1.17.2-beta-20251113-233643-ab2254af
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/config.js +32 -29
- package/package.json +9 -9
package/lib/config.js
CHANGED
|
@@ -14,11 +14,13 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
14
14
|
const debug_1 = __importDefault(require("debug"));
|
|
15
15
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
16
16
|
const throttle_1 = __importDefault(require("lodash/throttle"));
|
|
17
|
+
const constant_1 = require("@abtnode/constant");
|
|
17
18
|
const theme_1 = require("@blocklet/theme");
|
|
18
19
|
const env_1 = require("@blocklet/env");
|
|
19
|
-
const
|
|
20
|
+
const constant_2 = require("@blocklet/constant");
|
|
20
21
|
const util_1 = require("@blocklet/env/lib/util");
|
|
21
22
|
const util_2 = require("@blocklet/meta/lib/util");
|
|
23
|
+
const base32_1 = require("@abtnode/util/lib/base32");
|
|
22
24
|
const security_1 = require("./security");
|
|
23
25
|
const version_1 = require("./version");
|
|
24
26
|
const notification_1 = __importDefault(require("./service/notification"));
|
|
@@ -80,7 +82,7 @@ let componentsFromDisk;
|
|
|
80
82
|
let configFile;
|
|
81
83
|
if (appDataDir) {
|
|
82
84
|
try {
|
|
83
|
-
configFile = path_1.default.join(appDataDir,
|
|
85
|
+
configFile = path_1.default.join(appDataDir, constant_2.APP_CONFIG_FILE_PATH);
|
|
84
86
|
if (fs_1.default.existsSync(configFile)) {
|
|
85
87
|
let configRaw = fs_1.default.readFileSync(configFile).toString();
|
|
86
88
|
if (process.env.DOCKER_HOST_SERVER_DIR && process.env.DOCKER_CONTAINER_SERVER_DIR) {
|
|
@@ -95,7 +97,7 @@ if (appDataDir) {
|
|
|
95
97
|
logger.error(error);
|
|
96
98
|
}
|
|
97
99
|
try {
|
|
98
|
-
const envFile = path_1.default.join(appDataDir,
|
|
100
|
+
const envFile = path_1.default.join(appDataDir, constant_2.APP_CONFIG_DIR, process.env.BLOCKLET_COMPONENT_DID, constant_2.COMPONENT_ENV_FILE_NAME);
|
|
99
101
|
envFromDisk = (0, parse_env_file_1.parseEnvFile)(envFile, {
|
|
100
102
|
apiKey: process.env.BLOCKLET_COMPONENT_API_KEY,
|
|
101
103
|
componentDid: process.env.BLOCKLET_COMPONENT_DID,
|
|
@@ -223,12 +225,12 @@ const _setUpdatedComponents = (components) => {
|
|
|
223
225
|
_fillWebEndpoint(list);
|
|
224
226
|
list.forEach((newItem) => {
|
|
225
227
|
const exist = componentStore.find((x) => x.did === newItem.did);
|
|
226
|
-
newItem.status = exist ? exist.status :
|
|
228
|
+
newItem.status = exist ? exist.status : constant_2.BlockletStatus.stopped;
|
|
227
229
|
if (exist) {
|
|
228
230
|
Object.assign(exist, newItem);
|
|
229
231
|
}
|
|
230
232
|
else {
|
|
231
|
-
componentStore.push({ ...newItem, status:
|
|
233
|
+
componentStore.push({ ...newItem, status: constant_2.BlockletStatus.stopped });
|
|
232
234
|
}
|
|
233
235
|
});
|
|
234
236
|
updateComponentStoreInDocker(componentStore);
|
|
@@ -236,13 +238,13 @@ const _setUpdatedComponents = (components) => {
|
|
|
236
238
|
return list;
|
|
237
239
|
};
|
|
238
240
|
const _handleComponentStarted = (data) => {
|
|
239
|
-
const list = _setComponentStatus(data.components,
|
|
241
|
+
const list = _setComponentStatus(data.components, constant_2.BlockletStatus.running);
|
|
240
242
|
debug('handle component started', data, list);
|
|
241
243
|
events.emit(Events.componentStarted, list);
|
|
242
244
|
};
|
|
243
245
|
exports._handleComponentStarted = _handleComponentStarted;
|
|
244
246
|
const _handleComponentStopped = (data) => {
|
|
245
|
-
const list = _setComponentStatus(data.components,
|
|
247
|
+
const list = _setComponentStatus(data.components, constant_2.BlockletStatus.stopped);
|
|
246
248
|
debug('handle component stopped', data, list);
|
|
247
249
|
events.emit(Events.componentStopped, list);
|
|
248
250
|
};
|
|
@@ -339,9 +341,10 @@ const blockletSettings = {
|
|
|
339
341
|
};
|
|
340
342
|
const fetchBlockletJs = async (type = 'js') => {
|
|
341
343
|
const componentDid = process.env.BLOCKLET_COMPONENT_DID;
|
|
344
|
+
const appUrl = `https://${(0, base32_1.encode)(env.appPid)}.${constant_1.DEFAULT_DID_DOMAIN}`;
|
|
342
345
|
try {
|
|
343
346
|
const { mountPoint } = componentStore.find((x) => x.did === componentDid);
|
|
344
|
-
const url = (0, ufo_1.joinURL)(
|
|
347
|
+
const url = (0, ufo_1.joinURL)(appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?nocache=1&t=${Date.now()}${type === 'json' ? '&type=json' : ''}`);
|
|
345
348
|
const res = await axios_1.default.get(url, {
|
|
346
349
|
timeout: 8000,
|
|
347
350
|
headers: {
|
|
@@ -351,7 +354,7 @@ const fetchBlockletJs = async (type = 'js') => {
|
|
|
351
354
|
if (type === 'js') {
|
|
352
355
|
if (typeof res.data === 'string' && res.data.startsWith('window.blocklet')) {
|
|
353
356
|
blockletJs = res.data;
|
|
354
|
-
logger.info(`Fetch blocklet
|
|
357
|
+
logger.info(`Fetch blocklet.${type} succeed: ${componentDid} from ${appUrl}`);
|
|
355
358
|
return res.data;
|
|
356
359
|
}
|
|
357
360
|
throw new Error('Invalid blocklet.js');
|
|
@@ -371,14 +374,14 @@ const fetchBlockletJs = async (type = 'js') => {
|
|
|
371
374
|
light: (0, theme_1.merge)(DEFAULT_THEME_SETTINGS.light, data.theme?.light || {}),
|
|
372
375
|
dark: (0, theme_1.merge)(DEFAULT_THEME_SETTINGS.dark, data.theme?.dark || {}),
|
|
373
376
|
};
|
|
374
|
-
logger.info(`Fetch blocklet
|
|
377
|
+
logger.info(`Fetch blocklet.${type} succeed: ${componentDid} from ${appUrl}`);
|
|
375
378
|
return data;
|
|
376
379
|
}
|
|
377
380
|
throw new Error('Invalid blocklet.json data');
|
|
378
381
|
}
|
|
379
382
|
}
|
|
380
383
|
catch (err) {
|
|
381
|
-
logger.error(`Fetch blocklet.${type} failed: ${
|
|
384
|
+
logger.error(`Fetch blocklet.${type} failed: ${componentDid} from ${appUrl}`, err.message);
|
|
382
385
|
return type === 'js' ? '' : {};
|
|
383
386
|
}
|
|
384
387
|
};
|
|
@@ -437,25 +440,25 @@ const runInServer = (fn, type) =>
|
|
|
437
440
|
};
|
|
438
441
|
const inRuntimeEnv = !!process.env.BLOCKLET_APP_ASK || !!process.env.BLOCKLET_APP_SK;
|
|
439
442
|
if (inRuntimeEnv && !process.env.BLOCKLET_HOOK_NAME && process.env.BLOCKLET_MODE !== 'test') {
|
|
440
|
-
notification_1.default.on(
|
|
441
|
-
notification_1.default.on(
|
|
442
|
-
notification_1.default.on(
|
|
443
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.appConfigChanged, _handleAppConfigUpdate);
|
|
444
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.appSettingChanged, _handleAppSettingUpdate);
|
|
445
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentConfigChanged, _handleComponentConfigUpdate);
|
|
443
446
|
// Reactive fetch
|
|
444
|
-
notification_1.default.on(
|
|
445
|
-
notification_1.default.on(
|
|
446
|
-
notification_1.default.on(
|
|
447
|
-
notification_1.default.on(
|
|
448
|
-
notification_1.default.on(
|
|
449
|
-
notification_1.default.on(
|
|
450
|
-
notification_1.default.on(
|
|
451
|
-
notification_1.default.on(
|
|
452
|
-
notification_1.default.on(
|
|
453
|
-
notification_1.default.on(
|
|
454
|
-
notification_1.default.on(
|
|
455
|
-
notification_1.default.on(
|
|
456
|
-
notification_1.default.on(
|
|
457
|
-
notification_1.default.on(
|
|
458
|
-
notification_1.default.on(
|
|
447
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.appConfigChanged, refreshBlockletContext);
|
|
448
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.appSettingChanged, refreshBlockletContext);
|
|
449
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentConfigChanged, refreshBlockletContext);
|
|
450
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentInstalled, runInServer(_handleComponentInstalled, 'new'));
|
|
451
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentUpgraded, runInServer(_handleComponentUpdated, 'new'));
|
|
452
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentUpdated, runInServer(_handleComponentUpdated, 'new'));
|
|
453
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentStarted, runInServer(_handleComponentStarted, 'new'));
|
|
454
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentStopped, runInServer(_handleComponentStopped, 'new'));
|
|
455
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentRemoved, runInServer(_handleComponentRemoved, 'new'));
|
|
456
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentInstalled, runInServer(refreshBlockletContext, 'new'));
|
|
457
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentUpgraded, runInServer(refreshBlockletContext, 'new'));
|
|
458
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentUpdated, runInServer(refreshBlockletContext, 'new'));
|
|
459
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentStarted, runInServer(refreshBlockletContext, 'new'));
|
|
460
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentStopped, runInServer(refreshBlockletContext, 'new'));
|
|
461
|
+
notification_1.default.on(constant_2.BlockletInternalEvents.componentRemoved, runInServer(refreshBlockletContext, 'new'));
|
|
459
462
|
// Do an initial fetch
|
|
460
463
|
refreshBlockletContext();
|
|
461
464
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.2-beta-20251113-
|
|
6
|
+
"version": "1.17.2-beta-20251113-233643-ab2254af",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"homepage": "https://www.arcblock.io/docs/blocklet-sdk-nodejs",
|
|
9
9
|
"main": "lib/index.js",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/constant": "1.17.2-beta-20251113-
|
|
30
|
-
"@abtnode/db-cache": "1.17.2-beta-20251113-
|
|
31
|
-
"@abtnode/util": "1.17.2-beta-20251113-
|
|
29
|
+
"@abtnode/constant": "1.17.2-beta-20251113-233643-ab2254af",
|
|
30
|
+
"@abtnode/db-cache": "1.17.2-beta-20251113-233643-ab2254af",
|
|
31
|
+
"@abtnode/util": "1.17.2-beta-20251113-233643-ab2254af",
|
|
32
32
|
"@arcblock/did": "^1.27.4",
|
|
33
33
|
"@arcblock/did-connect-js": "^1.27.4",
|
|
34
34
|
"@arcblock/did-ext": "^1.27.4",
|
|
35
35
|
"@arcblock/jwt": "^1.27.4",
|
|
36
36
|
"@arcblock/ws": "^1.27.4",
|
|
37
|
-
"@blocklet/constant": "1.17.2-beta-20251113-
|
|
38
|
-
"@blocklet/env": "1.17.2-beta-20251113-
|
|
37
|
+
"@blocklet/constant": "1.17.2-beta-20251113-233643-ab2254af",
|
|
38
|
+
"@blocklet/env": "1.17.2-beta-20251113-233643-ab2254af",
|
|
39
39
|
"@blocklet/error": "^0.3.2",
|
|
40
|
-
"@blocklet/meta": "1.17.2-beta-20251113-
|
|
41
|
-
"@blocklet/server-js": "1.17.2-beta-20251113-
|
|
40
|
+
"@blocklet/meta": "1.17.2-beta-20251113-233643-ab2254af",
|
|
41
|
+
"@blocklet/server-js": "1.17.2-beta-20251113-233643-ab2254af",
|
|
42
42
|
"@blocklet/theme": "^3.2.3",
|
|
43
43
|
"@did-connect/authenticator": "^2.2.8",
|
|
44
44
|
"@did-connect/handler": "^2.2.8",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"ts-node": "^10.9.1",
|
|
83
83
|
"typescript": "^5.6.3"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "b0b39ab22bcee6e5c0e280f1799bcb5df5132e6c"
|
|
86
86
|
}
|