@blocklet/sdk 1.16.16 → 1.16.17-beta-8cacb9b3
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/component/index.d.ts +9 -0
- package/lib/component/index.js +16 -1
- package/lib/config.js +6 -6
- package/lib/middlewares/fallback.js +2 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +13 -13
package/lib/component/index.d.ts
CHANGED
|
@@ -20,10 +20,15 @@ type CallComponent = {
|
|
|
20
20
|
declare const call: CallComponent;
|
|
21
21
|
declare const getComponentMountPoint: (keyword: string) => string;
|
|
22
22
|
declare const getUrl: (...parts: string[]) => string;
|
|
23
|
+
declare const getResourceExportDir: ({ projectId, releaseId }?: {
|
|
24
|
+
projectId: string;
|
|
25
|
+
releaseId?: string;
|
|
26
|
+
}) => string;
|
|
23
27
|
export { call };
|
|
24
28
|
export { getUrl };
|
|
25
29
|
export { getComponentMountPoint };
|
|
26
30
|
export { getComponentWebEndpoint };
|
|
31
|
+
export { getResourceExportDir };
|
|
27
32
|
export { getChildWebEndpoint };
|
|
28
33
|
export { getParentWebEndpoint };
|
|
29
34
|
declare const _default: {
|
|
@@ -31,6 +36,10 @@ declare const _default: {
|
|
|
31
36
|
getUrl: (...parts: string[]) => string;
|
|
32
37
|
getComponentMountPoint: (keyword: string) => string;
|
|
33
38
|
getComponentWebEndpoint: (keyword: string) => string;
|
|
39
|
+
getResourceExportDir: ({ projectId, releaseId }?: {
|
|
40
|
+
projectId: string;
|
|
41
|
+
releaseId?: string;
|
|
42
|
+
}) => string;
|
|
34
43
|
getChildWebEndpoint: (name: string) => string;
|
|
35
44
|
getParentWebEndpoint: () => string;
|
|
36
45
|
};
|
package/lib/component/index.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
|
|
6
|
+
exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getResourceExportDir = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
|
|
7
|
+
const path_1 = require("path");
|
|
7
8
|
const util_1 = require("@blocklet/meta/lib/util");
|
|
8
9
|
const axios_1 = __importDefault(require("axios"));
|
|
9
10
|
const get_1 = __importDefault(require("lodash/get"));
|
|
@@ -99,11 +100,25 @@ const getUrl = (...parts) => {
|
|
|
99
100
|
return (0, url_join_1.default)(BLOCKLET_APP_URL, mountPoint === '/' ? '' : mountPoint, ...parts);
|
|
100
101
|
};
|
|
101
102
|
exports.getUrl = getUrl;
|
|
103
|
+
const getResourceExportDir = ({ projectId, releaseId } = { projectId: '' }) => {
|
|
104
|
+
if (!projectId) {
|
|
105
|
+
throw new Error('projectId is required');
|
|
106
|
+
}
|
|
107
|
+
const dirArr = [process.env.BLOCKLET_APP_DATA_DIR, constant_1.PROJECT.DIR, projectId || '/'];
|
|
108
|
+
if (releaseId) {
|
|
109
|
+
dirArr.push(constant_1.PROJECT.RELEASE_DIR, releaseId || '/');
|
|
110
|
+
}
|
|
111
|
+
dirArr.push(constant_1.PROJECT.RESOURCE_DIR);
|
|
112
|
+
const dir = (0, path_1.join)(...dirArr);
|
|
113
|
+
return dir;
|
|
114
|
+
};
|
|
115
|
+
exports.getResourceExportDir = getResourceExportDir;
|
|
102
116
|
exports.default = {
|
|
103
117
|
call,
|
|
104
118
|
getUrl,
|
|
105
119
|
getComponentMountPoint,
|
|
106
120
|
getComponentWebEndpoint,
|
|
121
|
+
getResourceExportDir,
|
|
107
122
|
getChildWebEndpoint,
|
|
108
123
|
getParentWebEndpoint, // deprecated
|
|
109
124
|
};
|
package/lib/config.js
CHANGED
|
@@ -66,7 +66,7 @@ if (appDataDir) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
69
|
-
|
|
69
|
+
logger.error(error);
|
|
70
70
|
}
|
|
71
71
|
try {
|
|
72
72
|
const envFile = path_1.default.join(appDataDir, constant_1.APP_CONFIG_DIR, process.env.BLOCKLET_COMPONENT_DID, constant_1.COMPONENT_ENV_FILE_NAME);
|
|
@@ -84,7 +84,7 @@ if (appDataDir) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
catch (error) {
|
|
87
|
-
|
|
87
|
+
logger.error(error);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
const env = {
|
|
@@ -234,7 +234,7 @@ const fetchBlockletJs = async () => {
|
|
|
234
234
|
const componentDid = process.env.BLOCKLET_COMPONENT_DID;
|
|
235
235
|
try {
|
|
236
236
|
const { mountPoint } = componentStore.find((x) => x.did === componentDid);
|
|
237
|
-
const res = await axios_1.default.get((0, url_join_1.default)(env.appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?t=${Date.now()}`), {
|
|
237
|
+
const res = await axios_1.default.get((0, url_join_1.default)(env.appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?force=1&t=${Date.now()}`), {
|
|
238
238
|
timeout: 8000,
|
|
239
239
|
headers: {
|
|
240
240
|
'User-Agent': `BlockletSDK/${version_1.version}`,
|
|
@@ -252,19 +252,19 @@ const fetchBlockletJs = async () => {
|
|
|
252
252
|
// Page group is dynamic, so we need to create it on the fly
|
|
253
253
|
const normalize = (prefix) => `/${prefix}/`.replace(/\/+/g, '/');
|
|
254
254
|
const getBlockletJs = (pageGroup = '', pathPrefix = '', source = blockletJs) => {
|
|
255
|
-
let copy = source;
|
|
255
|
+
let copy = source.slice(0);
|
|
256
256
|
if (pageGroup) {
|
|
257
257
|
copy = copy.replace('pageGroup: "",', `pageGroup: "${pageGroup}",`);
|
|
258
258
|
}
|
|
259
259
|
if (pathPrefix) {
|
|
260
260
|
const componentDid = process.env.BLOCKLET_COMPONENT_DID;
|
|
261
261
|
const { mountPoint } = componentStore.find((x) => x.did === componentDid);
|
|
262
|
-
copy = copy.replace(`prefix: "${normalize(mountPoint)}",`, `prefix: "${normalize(pathPrefix)}",`);
|
|
262
|
+
copy = copy.replace(`prefix: "${normalize(mountPoint)}",`, `prefix: "${normalize(pathPrefix)}",`).replace('prefix: "/",', `prefix: "${normalize(pathPrefix)}",`);
|
|
263
263
|
}
|
|
264
264
|
return copy;
|
|
265
265
|
};
|
|
266
266
|
exports.getBlockletJs = getBlockletJs;
|
|
267
|
-
const refreshBlockletJs = (0, throttle_1.default)(fetchBlockletJs,
|
|
267
|
+
const refreshBlockletJs = (0, throttle_1.default)(fetchBlockletJs, 3000, { trailing: true });
|
|
268
268
|
const runInServer = (fn, type) =>
|
|
269
269
|
// eslint-disable-next-line consistent-return
|
|
270
270
|
(...args) => {
|
|
@@ -18,6 +18,7 @@ const fallback = (file, options = {}) => {
|
|
|
18
18
|
if ((req.method === 'GET' || req.method === 'HEAD') && req.accepts('html') && !resourcePattern.test(req.path)) {
|
|
19
19
|
res.type('html');
|
|
20
20
|
const pageGroup = req.headers['x-page-group'] || '';
|
|
21
|
+
const pathPrefix = req.headers['x-path-prefix'] || '';
|
|
21
22
|
const pageData = typeof options.getPageData === 'function' ? await options.getPageData(req) : {};
|
|
22
23
|
pageData.title = (0, escape_1.default)(pageData.title || config_1.env.appName);
|
|
23
24
|
pageData.description = (0, escape_1.default)(pageData.description || config_1.env.appDescription);
|
|
@@ -49,7 +50,7 @@ const fallback = (file, options = {}) => {
|
|
|
49
50
|
source = source.replace('</head>', `${og}</head>`);
|
|
50
51
|
}
|
|
51
52
|
// inline blocklet.js
|
|
52
|
-
const blockletJs = (0, config_1.getBlockletJs)(pageGroup);
|
|
53
|
+
const blockletJs = (0, config_1.getBlockletJs)(pageGroup, pathPrefix);
|
|
53
54
|
if (blockletJs) {
|
|
54
55
|
source = source
|
|
55
56
|
.replace('<script src="__blocklet__.js"></script>', `<script>${blockletJs}</script>`)
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.17-beta-8cacb9b3",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/client": "1.16.
|
|
30
|
-
"@abtnode/constant": "1.16.
|
|
31
|
-
"@arcblock/did": "1.18.
|
|
32
|
-
"@arcblock/did-auth": "1.18.
|
|
33
|
-
"@arcblock/jwt": "1.18.
|
|
34
|
-
"@arcblock/ws": "1.18.
|
|
35
|
-
"@blocklet/constant": "1.16.
|
|
36
|
-
"@blocklet/env": "1.16.
|
|
37
|
-
"@blocklet/meta": "1.16.
|
|
29
|
+
"@abtnode/client": "1.16.17-beta-8cacb9b3",
|
|
30
|
+
"@abtnode/constant": "1.16.17-beta-8cacb9b3",
|
|
31
|
+
"@arcblock/did": "1.18.91",
|
|
32
|
+
"@arcblock/did-auth": "1.18.91",
|
|
33
|
+
"@arcblock/jwt": "1.18.91",
|
|
34
|
+
"@arcblock/ws": "1.18.91",
|
|
35
|
+
"@blocklet/constant": "1.16.17-beta-8cacb9b3",
|
|
36
|
+
"@blocklet/env": "1.16.17-beta-8cacb9b3",
|
|
37
|
+
"@blocklet/meta": "1.16.17-beta-8cacb9b3",
|
|
38
38
|
"@did-connect/authenticator": "^2.2.0",
|
|
39
39
|
"@did-connect/handler": "^2.2.0",
|
|
40
40
|
"@nedb/core": "^2.1.5",
|
|
41
|
-
"@ocap/mcrypto": "1.18.
|
|
42
|
-
"@ocap/wallet": "1.18.
|
|
41
|
+
"@ocap/mcrypto": "1.18.91",
|
|
42
|
+
"@ocap/wallet": "1.18.91",
|
|
43
43
|
"axios": "^0.27.2",
|
|
44
44
|
"cheerio": "^1.0.0-rc.12",
|
|
45
45
|
"fs-extra": "^10.1.0",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"ts-node": "^10.9.1",
|
|
75
75
|
"typescript": "^5.0.4"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "0e3266f543b6d419a004ca94ee9efb572e3d9809"
|
|
78
78
|
}
|