@blocklet/sdk 1.8.67-beta-65933c91 → 1.8.67-beta-794a8082
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 +15 -16
- package/lib/embed/index.d.ts +0 -9
- package/lib/embed/index.js +0 -13
- package/lib/embed/message.d.ts +0 -26
- package/lib/embed/message.js +0 -134
- package/lib/embed/utils.d.ts +0 -7
- package/lib/embed/utils.js +0 -95
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.67-beta-
|
|
6
|
+
"version": "1.8.67-beta-794a8082",
|
|
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,27 +26,25 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/client": "1.8.
|
|
30
|
-
"@abtnode/constant": "1.8.
|
|
31
|
-
"@abtnode/util": "
|
|
32
|
-
"@arcblock/did-auth": "1.18.
|
|
33
|
-
"@arcblock/jwt": "1.18.
|
|
34
|
-
"@arcblock/ws": "1.18.
|
|
35
|
-
"@blocklet/constant": "1.8.
|
|
36
|
-
"@blocklet/meta": "1.8.
|
|
37
|
-
"@did-connect/authenticator": "^2.1.
|
|
38
|
-
"@did-connect/handler": "^2.1.
|
|
29
|
+
"@abtnode/client": "1.8.67-beta-794a8082",
|
|
30
|
+
"@abtnode/constant": "1.8.67-beta-794a8082",
|
|
31
|
+
"@abtnode/util": "1.8.67-beta-794a8082",
|
|
32
|
+
"@arcblock/did-auth": "1.18.54",
|
|
33
|
+
"@arcblock/jwt": "1.18.54",
|
|
34
|
+
"@arcblock/ws": "1.18.54",
|
|
35
|
+
"@blocklet/constant": "1.8.67-beta-794a8082",
|
|
36
|
+
"@blocklet/meta": "1.8.67-beta-794a8082",
|
|
37
|
+
"@did-connect/authenticator": "^2.1.39",
|
|
38
|
+
"@did-connect/handler": "^2.1.39",
|
|
39
39
|
"@nedb/core": "^2.1.5",
|
|
40
|
-
"@ocap/mcrypto": "1.18.
|
|
41
|
-
"@ocap/wallet": "1.18.
|
|
40
|
+
"@ocap/mcrypto": "1.18.54",
|
|
41
|
+
"@ocap/wallet": "1.18.54",
|
|
42
42
|
"axios": "^0.27.2",
|
|
43
43
|
"fs-extra": "^10.1.0",
|
|
44
44
|
"joi": "17.7.0",
|
|
45
|
-
"jsdom": "^21.1.0",
|
|
46
45
|
"json-stable-stringify": "^1.0.1",
|
|
47
46
|
"lodash": "^4.17.21",
|
|
48
47
|
"lru-cache": "^6.0.0",
|
|
49
|
-
"ufo": "^1.1.1",
|
|
50
48
|
"url-join": "^4.0.1"
|
|
51
49
|
},
|
|
52
50
|
"resolutions": {
|
|
@@ -70,5 +68,6 @@
|
|
|
70
68
|
"ts-jest": "^29.0.3",
|
|
71
69
|
"ts-node": "^10.9.1",
|
|
72
70
|
"typescript": "^4.8.4"
|
|
73
|
-
}
|
|
71
|
+
},
|
|
72
|
+
"gitHead": "f4ad32bea4d80b12971fb6bef941bdbe2af6a834"
|
|
74
73
|
}
|
package/lib/embed/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from 'express';
|
|
2
|
-
import { generateBlockletEmbed } from './utils';
|
|
3
|
-
declare const expressEmbed: (req: Request, res: Response) => Promise<void>;
|
|
4
|
-
declare const _default: {
|
|
5
|
-
expressEmbed: (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Promise<void>;
|
|
6
|
-
generateBlockletEmbed: typeof generateBlockletEmbed;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
export { expressEmbed, generateBlockletEmbed };
|
package/lib/embed/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateBlockletEmbed = exports.expressEmbed = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
Object.defineProperty(exports, "generateBlockletEmbed", { enumerable: true, get: function () { return utils_1.generateBlockletEmbed; } });
|
|
6
|
-
const expressEmbed = async (req, res) => {
|
|
7
|
-
const { query = {} } = req;
|
|
8
|
-
const { url = '' } = query;
|
|
9
|
-
const data = await (0, utils_1.getBlockletEmbedFromUrl)(url);
|
|
10
|
-
res.json(data);
|
|
11
|
-
};
|
|
12
|
-
exports.expressEmbed = expressEmbed;
|
|
13
|
-
exports.default = { expressEmbed, generateBlockletEmbed: utils_1.generateBlockletEmbed };
|
package/lib/embed/message.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
type InstanceType = 'client' | 'server';
|
|
2
|
-
type MessageType = string;
|
|
3
|
-
interface Callback {
|
|
4
|
-
(...args: any[]): void;
|
|
5
|
-
}
|
|
6
|
-
declare class Message {
|
|
7
|
-
id: string;
|
|
8
|
-
type: InstanceType;
|
|
9
|
-
private bc;
|
|
10
|
-
private eventMap;
|
|
11
|
-
init: (cb: Callback) => void;
|
|
12
|
-
onInit: (getData: () => any) => void;
|
|
13
|
-
close: () => void;
|
|
14
|
-
constructor(id: string, type?: InstanceType);
|
|
15
|
-
on(type: MessageType, cb: Callback): void;
|
|
16
|
-
off(type: MessageType, cb: Callback): void;
|
|
17
|
-
once(type: MessageType, cb: Callback): void;
|
|
18
|
-
send(type: MessageType, payload: any): void;
|
|
19
|
-
}
|
|
20
|
-
declare function useMessage(id?: string, type?: InstanceType): any;
|
|
21
|
-
declare const _default: {
|
|
22
|
-
useMessage: typeof useMessage;
|
|
23
|
-
Message: typeof Message;
|
|
24
|
-
};
|
|
25
|
-
export default _default;
|
|
26
|
-
export { useMessage, Message };
|
package/lib/embed/message.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Message = exports.useMessage = void 0;
|
|
4
|
-
const INIT = '__init';
|
|
5
|
-
const ON_INIT = '__on-init';
|
|
6
|
-
function checkKey(typeKey) {
|
|
7
|
-
return !typeKey.startsWith(INIT);
|
|
8
|
-
}
|
|
9
|
-
function ensureType(type) {
|
|
10
|
-
if (!checkKey(type)) {
|
|
11
|
-
throw new Error(`Type can't starts with ${INIT}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function notExist() {
|
|
15
|
-
console.error('function not exist');
|
|
16
|
-
}
|
|
17
|
-
class Message {
|
|
18
|
-
constructor(id, type = 'client') {
|
|
19
|
-
this.id = id;
|
|
20
|
-
this.type = type;
|
|
21
|
-
const bc = new BroadcastChannel(this.id);
|
|
22
|
-
this.bc = bc;
|
|
23
|
-
this.eventMap = new Map();
|
|
24
|
-
const onMessage = (event) => {
|
|
25
|
-
const { data } = event;
|
|
26
|
-
const { type: messageType, payload, id: dataId } = data;
|
|
27
|
-
if (dataId === this.id) {
|
|
28
|
-
const cbList = this.eventMap.get(messageType) || [];
|
|
29
|
-
cbList.forEach((cbItem) => {
|
|
30
|
-
cbItem(payload);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
window.addEventListener('message', onMessage, false);
|
|
35
|
-
this.close = () => {
|
|
36
|
-
window.removeEventListener('message', onMessage, false);
|
|
37
|
-
// v1 message
|
|
38
|
-
this.bc.close();
|
|
39
|
-
};
|
|
40
|
-
// v1 message
|
|
41
|
-
bc.onmessage = ({ data }) => {
|
|
42
|
-
const { type: messageType, payload } = data;
|
|
43
|
-
const cbList = this.eventMap.get(messageType) || [];
|
|
44
|
-
cbList.forEach((cbItem) => {
|
|
45
|
-
cbItem(payload);
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
this.init = notExist;
|
|
49
|
-
this.onInit = notExist;
|
|
50
|
-
if (type === 'server') {
|
|
51
|
-
this.onInit = (getData = () => null) => {
|
|
52
|
-
this.eventMap.set(INIT, [
|
|
53
|
-
(listenKey) => {
|
|
54
|
-
const initData = getData();
|
|
55
|
-
this.send(listenKey, initData);
|
|
56
|
-
},
|
|
57
|
-
]);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (type === 'client') {
|
|
61
|
-
this.init = (cb) => {
|
|
62
|
-
const uniqueId = String(+new Date());
|
|
63
|
-
const listenKey = `${ON_INIT}_${uniqueId}`;
|
|
64
|
-
this.once(listenKey, cb);
|
|
65
|
-
this.send(INIT, listenKey);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
on(type, cb) {
|
|
70
|
-
ensureType(type);
|
|
71
|
-
const cbList = this.eventMap.get(type) || [];
|
|
72
|
-
cbList.push(cb);
|
|
73
|
-
this.eventMap.set(type, cbList);
|
|
74
|
-
}
|
|
75
|
-
off(type, cb) {
|
|
76
|
-
ensureType(type);
|
|
77
|
-
const cbList = this.eventMap.get(type) || [];
|
|
78
|
-
if (cb) {
|
|
79
|
-
const index = cbList.indexOf(cb);
|
|
80
|
-
if (index !== -1) {
|
|
81
|
-
cbList.splice(index, 1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
cbList.length = 0;
|
|
86
|
-
}
|
|
87
|
-
this.eventMap.set(type, cbList);
|
|
88
|
-
}
|
|
89
|
-
once(type, cb) {
|
|
90
|
-
ensureType(type);
|
|
91
|
-
const callback = (...args) => {
|
|
92
|
-
cb(...args);
|
|
93
|
-
this.off(type, callback);
|
|
94
|
-
};
|
|
95
|
-
this.on(type, callback);
|
|
96
|
-
}
|
|
97
|
-
send(type, payload) {
|
|
98
|
-
const data = {
|
|
99
|
-
id: this.id,
|
|
100
|
-
type,
|
|
101
|
-
payload,
|
|
102
|
-
};
|
|
103
|
-
if (this.type === 'server') {
|
|
104
|
-
const iframeList = [...document.querySelectorAll(`iframe[data-id="${this.id}"]`)];
|
|
105
|
-
iframeList.forEach((iframeItem) => {
|
|
106
|
-
iframeItem.contentWindow.postMessage(data, '*');
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
window.parent.postMessage(data, '*');
|
|
111
|
-
}
|
|
112
|
-
// v1 message
|
|
113
|
-
this.bc.postMessage(data);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.Message = Message;
|
|
117
|
-
const messageCache = new Map();
|
|
118
|
-
function useMessage(id, type = 'client') {
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
120
|
-
const _id = id || window.frameElement?.dataset.id || window.name;
|
|
121
|
-
if (messageCache.has(_id)) {
|
|
122
|
-
return messageCache.get(_id);
|
|
123
|
-
}
|
|
124
|
-
const isInIframe = window !== window.parent;
|
|
125
|
-
const message = (type === 'server' || isInIframe) && _id ? new Message(_id, type) : null;
|
|
126
|
-
const data = { message };
|
|
127
|
-
messageCache.set(_id, data);
|
|
128
|
-
return data;
|
|
129
|
-
}
|
|
130
|
-
exports.useMessage = useMessage;
|
|
131
|
-
exports.default = {
|
|
132
|
-
useMessage,
|
|
133
|
-
Message,
|
|
134
|
-
};
|
package/lib/embed/utils.d.ts
DELETED
package/lib/embed/utils.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateBlockletEmbed = exports.getBlockletEmbedFromUrl = void 0;
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const jsdom_1 = __importDefault(require("jsdom"));
|
|
9
|
-
const lodash_1 = require("lodash");
|
|
10
|
-
const ufo_1 = require("ufo");
|
|
11
|
-
const axios_1 = __importDefault(require("axios"));
|
|
12
|
-
const { JSDOM } = jsdom_1.default;
|
|
13
|
-
const api = axios_1.default.create();
|
|
14
|
-
/**
|
|
15
|
-
* 判断 document 是否为开发环境
|
|
16
|
-
* @param document html document 对象(jsdom)
|
|
17
|
-
* @returns boolean
|
|
18
|
-
*/
|
|
19
|
-
function checkDev(document) {
|
|
20
|
-
const scirptList = document.querySelectorAll('script[type="module"]');
|
|
21
|
-
return !![...scirptList].find((scriptItem) => scriptItem.textContent?.includes('window.__vite_plugin_react_preamble_installed__ = true'));
|
|
22
|
-
}
|
|
23
|
-
async function getEmbedUrlFromUrl(url) {
|
|
24
|
-
try {
|
|
25
|
-
const { data: htmlContent } = await api.get(url, {
|
|
26
|
-
headers: {
|
|
27
|
-
accept: 'text/html,application/xhtml+xml,application/xml',
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
const { document } = new JSDOM(htmlContent).window;
|
|
31
|
-
let prefix = '/';
|
|
32
|
-
let metaUrl = url;
|
|
33
|
-
const link = document.querySelector('link[rel="blocklet-open-embed"]');
|
|
34
|
-
const blockletScript = document.querySelector('script[src="__blocklet__.js"]');
|
|
35
|
-
if (link) {
|
|
36
|
-
metaUrl = link.getAttribute('href') || url;
|
|
37
|
-
}
|
|
38
|
-
const isDev = checkDev(document);
|
|
39
|
-
if (blockletScript) {
|
|
40
|
-
const scriptUrl = new URL('__blocklet__.js?type=json', (0, ufo_1.withTrailingSlash)(url));
|
|
41
|
-
const { data: blockletMeta } = await api.get(scriptUrl.href);
|
|
42
|
-
prefix = blockletMeta.prefix;
|
|
43
|
-
}
|
|
44
|
-
return isDev ? (0, ufo_1.joinURL)(prefix, metaUrl.replace(prefix, '')) : (0, ufo_1.joinURL)(prefix, metaUrl);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return url;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function getBlockletEmbedFromUrl(url) {
|
|
51
|
-
const metaUrl = await getEmbedUrlFromUrl(url);
|
|
52
|
-
if (metaUrl) {
|
|
53
|
-
let finalUrl = '';
|
|
54
|
-
if (metaUrl.startsWith('http://') || metaUrl.startsWith('https://')) {
|
|
55
|
-
finalUrl = metaUrl;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
finalUrl = `${new URL(url).origin}${(0, path_1.join)('/', metaUrl)}`;
|
|
59
|
-
}
|
|
60
|
-
const { data: metaData } = await api.get(finalUrl);
|
|
61
|
-
if ((0, lodash_1.isObject)(metaData)) {
|
|
62
|
-
return metaData;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
exports.getBlockletEmbedFromUrl = getBlockletEmbedFromUrl;
|
|
68
|
-
function safeJsonParse(input, defaultValue) {
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(input);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return defaultValue;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function generateBlockletEmbed() {
|
|
77
|
-
const BLOCKLET_MOUNT_POINTS = safeJsonParse(process.env.BLOCKLET_MOUNT_POINTS, []);
|
|
78
|
-
const { BLOCKLET_APP_NAME, BLOCKLET_APP_URL, BLOCKLET_REAL_NAME } = process.env;
|
|
79
|
-
let name = BLOCKLET_APP_NAME;
|
|
80
|
-
const blockletNames = BLOCKLET_REAL_NAME.split('/');
|
|
81
|
-
let url = '/';
|
|
82
|
-
const componentBlocklet = BLOCKLET_MOUNT_POINTS.find((blockletItem) => blockletItem.name === blockletNames[blockletNames.length - 1]);
|
|
83
|
-
if (componentBlocklet) {
|
|
84
|
-
// 先假设只有一层 component blocklet
|
|
85
|
-
url = componentBlocklet.mountPoint;
|
|
86
|
-
name = componentBlocklet.title;
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
name,
|
|
90
|
-
url,
|
|
91
|
-
origin: BLOCKLET_APP_URL,
|
|
92
|
-
embed: [],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
exports.generateBlockletEmbed = generateBlockletEmbed;
|