@blocklet/meta 1.8.34 → 1.8.35

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.
Files changed (58) hide show
  1. package/lib/channel.d.ts +27 -0
  2. package/lib/channel.js +32 -32
  3. package/lib/constants.d.ts +2 -0
  4. package/lib/constants.js +6 -3
  5. package/lib/did.d.ts +10 -0
  6. package/lib/did.js +18 -24
  7. package/lib/engine.d.ts +7 -0
  8. package/lib/engine.js +21 -25
  9. package/lib/entry.d.ts +3 -0
  10. package/lib/entry.js +51 -64
  11. package/lib/extension.d.ts +10 -0
  12. package/lib/extension.js +78 -77
  13. package/lib/file.d.ts +21 -0
  14. package/lib/file.js +44 -39
  15. package/lib/fix.d.ts +33 -0
  16. package/lib/fix.js +218 -208
  17. package/lib/get-component-process-id.d.ts +5 -0
  18. package/lib/get-component-process-id.js +13 -14
  19. package/lib/has-reserved-key.d.ts +3 -0
  20. package/lib/has-reserved-key.js +10 -9
  21. package/lib/index.d.ts +82 -0
  22. package/lib/index.js +51 -34
  23. package/lib/info.d.ts +13 -0
  24. package/lib/info.js +58 -60
  25. package/lib/name.d.ts +5 -0
  26. package/lib/name.js +14 -7
  27. package/lib/nft-templates.d.ts +86 -0
  28. package/lib/nft-templates.js +47 -42
  29. package/lib/parse-navigation.d.ts +3 -0
  30. package/lib/parse-navigation.js +167 -228
  31. package/lib/parse.d.ts +22 -0
  32. package/lib/parse.js +71 -82
  33. package/lib/payment/index.d.ts +254 -0
  34. package/lib/payment/index.js +13 -6
  35. package/lib/payment/v1.d.ts +185 -0
  36. package/lib/payment/v1.js +80 -81
  37. package/lib/payment/v2.d.ts +242 -0
  38. package/lib/payment/v2.js +453 -531
  39. package/lib/schema.d.ts +50 -0
  40. package/lib/schema.js +405 -402
  41. package/lib/service-configs/auth.json +61 -61
  42. package/lib/service.d.ts +26 -0
  43. package/lib/service.js +69 -85
  44. package/lib/types/index.d.ts +1 -0
  45. package/lib/types/index.js +18 -0
  46. package/lib/types/schema.d.ts +241 -0
  47. package/lib/types/schema.js +3 -0
  48. package/lib/util-meta.d.ts +42 -0
  49. package/lib/util-meta.js +138 -158
  50. package/lib/util.d.ts +185 -0
  51. package/lib/util.js +359 -414
  52. package/lib/validate.d.ts +10 -0
  53. package/lib/validate.js +28 -34
  54. package/lib/verify-multi-sig.d.ts +3 -0
  55. package/lib/verify-multi-sig.js +94 -101
  56. package/lib/wallet.d.ts +9 -0
  57. package/lib/wallet.js +17 -27
  58. package/package.json +40 -18
package/lib/util.js CHANGED
@@ -1,31 +1,32 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
1
16
  /* eslint-disable no-await-in-loop */
2
- const get = require('lodash/get');
3
- const slugify = require('slugify');
4
- const joinUrl = require('url-join');
5
-
6
- const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS } = require('@abtnode/constant');
7
-
8
- const {
9
- BlockletGroup,
10
- fromBlockletStatus,
11
- fromBlockletSource,
12
- BLOCKLET_INTERFACE_TYPE_WEB,
13
- BLOCKLET_CONFIGURABLE_KEY,
14
- CHAIN_INFO_CONFIG,
15
- } = require('./constants');
16
-
17
- const getComponentId = (component, ancestors = []) =>
18
- `${ancestors.map((x) => (x && x.meta ? x.meta.did : '')).join('/')}${ancestors.length ? '/' : ''}${
19
- component && component.meta ? component.meta.did : ''
20
- }`;
21
-
22
- const getComponentName = (component, ancestors = []) =>
23
- `${ancestors.map((x) => (x && x.meta ? x.meta.name : '')).join('/')}${ancestors.length ? '/' : ''}${
24
- component && component.meta ? component.meta.name : ''
25
- }`;
26
-
17
+ const get_1 = __importDefault(require("lodash/get"));
18
+ const slugify_1 = __importDefault(require("slugify"));
19
+ const url_join_1 = __importDefault(require("url-join"));
20
+ const constant_1 = __importDefault(require("@abtnode/constant"));
21
+ const constants_1 = __importDefault(require("./constants"));
22
+ const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS } = constant_1.default;
23
+ const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_CONFIGURABLE_KEY, CHAIN_INFO_CONFIG, } = constants_1.default;
24
+ const getComponentId = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.did : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.did : ''}`;
25
+ exports.getComponentId = getComponentId;
26
+ const getComponentName = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.name : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.name : ''}`;
27
+ exports.getComponentName = getComponentName;
27
28
  const getComponentBundleId = (component) => `${component.meta.bundleName}@${component.meta.version}`;
28
-
29
+ exports.getComponentBundleId = getComponentBundleId;
29
30
  /**
30
31
  * a => ''
31
32
  * @a/b => ''
@@ -37,307 +38,265 @@ const getComponentBundleId = (component) => `${component.meta.bundleName}@${comp
37
38
  * @a/b/@c/d/@e/f => @a/b/@c/d
38
39
  */
39
40
  const getParentComponentName = (name) => {
40
- if (!name) {
41
- return '';
42
- }
43
-
44
- const arr = name.split('/');
45
- arr.pop();
46
-
47
- if (!arr.length) {
48
- return '';
49
- }
50
-
51
- if (arr[arr.length - 1].startsWith('@')) {
41
+ if (!name) {
42
+ return '';
43
+ }
44
+ const arr = name.split('/');
52
45
  arr.pop();
53
- }
54
-
55
- if (!arr.length) {
56
- return '';
57
- }
58
-
59
- return arr.join('/');
60
- };
61
-
62
- const forEachBlocklet = (
63
- blocklet,
64
- cb,
65
- { parallel = false, sync, params: inputParams, _parent, _root, _level = 0, _tasks: inputTasks, _ancestors = [] } = {}
66
- ) => {
67
- const root = _root || _parent || blocklet;
68
-
69
- // id maybe meaningless if no meta in blocklet or _ancestors
70
- const id = getComponentId(blocklet, _ancestors);
71
-
72
- const newAncestors = _ancestors.concat(blocklet);
73
-
74
- // sync
75
- if (sync) {
76
- const params = cb(blocklet, {
77
- parent: _parent,
78
- root,
79
- level: _level,
80
- params: inputParams,
81
- ancestors: _ancestors,
82
- id,
83
- });
84
- if (blocklet.children) {
85
- for (const child of blocklet.children) {
86
- forEachBlocklet(child, cb, {
87
- sync,
88
- params,
89
- _parent: blocklet,
90
- _root: root,
91
- _level: _level + 1,
92
- _ancestors: newAncestors,
93
- });
94
- }
46
+ if (!arr.length) {
47
+ return '';
95
48
  }
96
- return null;
97
- }
98
-
99
- // serial
100
- if (!parallel) {
101
- // eslint-disable-next-line no-async-promise-executor
102
- return new Promise(async (resolve, reject) => {
103
- try {
104
- const params = await cb(blocklet, {
105
- parent: _parent,
106
- root,
107
- level: _level,
108
- ancestors: _ancestors,
109
- params: inputParams,
110
- id,
49
+ if (arr[arr.length - 1].startsWith('@')) {
50
+ arr.pop();
51
+ }
52
+ if (!arr.length) {
53
+ return '';
54
+ }
55
+ return arr.join('/');
56
+ };
57
+ exports.getParentComponentName = getParentComponentName;
58
+ const forEachBlocklet = (blocklet, cb, { parallel = false, sync, params: inputParams, _parent, _root, _level = 0, _tasks: inputTasks, _ancestors = [], } = {}) => {
59
+ const root = _root || _parent || blocklet;
60
+ // id maybe meaningless if no meta in blocklet or _ancestors
61
+ const id = getComponentId(blocklet, _ancestors);
62
+ const newAncestors = _ancestors.concat(blocklet);
63
+ // sync
64
+ if (sync) {
65
+ const params = cb(blocklet, {
66
+ parent: _parent,
67
+ root,
68
+ level: _level,
69
+ params: inputParams,
70
+ ancestors: _ancestors,
71
+ id,
111
72
  });
112
73
  if (blocklet.children) {
113
- for (const child of blocklet.children) {
114
- await forEachBlocklet(child, cb, {
115
- params,
116
- _parent: blocklet,
117
- _root: root,
118
- _level: _level + 1,
119
- _ancestors: newAncestors,
74
+ for (const child of blocklet.children) {
75
+ forEachBlocklet(child, cb, {
76
+ sync,
77
+ params,
78
+ _parent: blocklet,
79
+ _root: root,
80
+ _level: _level + 1,
81
+ _ancestors: newAncestors,
82
+ });
83
+ }
84
+ }
85
+ return null;
86
+ }
87
+ // serial
88
+ if (!parallel) {
89
+ // eslint-disable-next-line no-async-promise-executor
90
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
91
+ try {
92
+ const params = yield cb(blocklet, {
93
+ parent: _parent,
94
+ root,
95
+ level: _level,
96
+ ancestors: _ancestors,
97
+ params: inputParams,
98
+ id,
99
+ });
100
+ if (blocklet.children) {
101
+ for (const child of blocklet.children) {
102
+ yield forEachBlocklet(child, cb, {
103
+ params,
104
+ _parent: blocklet,
105
+ _root: root,
106
+ _level: _level + 1,
107
+ _ancestors: newAncestors,
108
+ });
109
+ }
110
+ }
111
+ resolve(null);
112
+ }
113
+ catch (err) {
114
+ reject(err);
115
+ }
116
+ }));
117
+ }
118
+ // parallel
119
+ const tasks = inputTasks || [];
120
+ tasks.push(cb(blocklet, { parent: _parent, root, level: _level, ancestors: _ancestors, id }));
121
+ if (blocklet.children) {
122
+ for (const child of blocklet.children) {
123
+ forEachBlocklet(child, cb, {
124
+ parallel,
125
+ _parent: blocklet,
126
+ _root: root,
127
+ _level: _level + 1,
128
+ _tasks: tasks,
129
+ _ancestors: newAncestors,
120
130
  });
121
- }
122
131
  }
123
-
124
- resolve(null);
125
- } catch (err) {
126
- reject(err);
127
- }
128
- });
129
- }
130
-
131
- // parallel
132
- const tasks = inputTasks || [];
133
- tasks.push(cb(blocklet, { parent: _parent, root, level: _level, ancestors: _ancestors, id }));
134
- if (blocklet.children) {
135
- for (const child of blocklet.children) {
136
- forEachBlocklet(child, cb, {
137
- parallel,
138
- _parent: blocklet,
139
- _root: root,
140
- _level: _level + 1,
141
- _tasks: tasks,
142
- _ancestors: newAncestors,
143
- });
144
132
  }
145
- }
146
- if (inputTasks) {
147
- return null;
148
- }
149
- return Promise.all(tasks);
133
+ if (inputTasks) {
134
+ return null;
135
+ }
136
+ return Promise.all(tasks);
150
137
  };
151
-
138
+ exports.forEachBlocklet = forEachBlocklet;
152
139
  const forEachBlockletSync = (blocklet, cb) => forEachBlocklet(blocklet, cb, { sync: true });
153
-
140
+ exports.forEachBlockletSync = forEachBlockletSync;
154
141
  const forEachChild = (blocklet, cb, params) => {
155
- return forEachBlocklet(
156
- blocklet,
157
- (b, opt) => {
158
- if (opt.level === 0) {
159
- return {};
160
- }
161
- return cb(b, opt);
162
- },
163
- params
164
- );
142
+ return forEachBlocklet(blocklet, (b, opt) => {
143
+ if (opt.level === 0) {
144
+ return {};
145
+ }
146
+ return cb(b, opt);
147
+ }, params);
165
148
  };
166
-
149
+ exports.forEachChild = forEachChild;
150
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
167
151
  const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
168
-
169
- const findComponentById = (blocklet, componentId, { _ancestors = [], returnAncestors = false } = {}) => {
170
- const id = getComponentId(blocklet, _ancestors);
171
- if (componentId === id) {
172
- if (returnAncestors) {
173
- return {
174
- component: blocklet,
175
- ancestors: _ancestors,
176
- };
152
+ exports.forEachChildSync = forEachChildSync;
153
+ const findComponentById = (blocklet, componentId, { _ancestors = [], returnAncestors = false, } = {}) => {
154
+ const id = getComponentId(blocklet, _ancestors);
155
+ if (componentId === id) {
156
+ if (returnAncestors) {
157
+ return {
158
+ component: blocklet,
159
+ ancestors: _ancestors,
160
+ };
161
+ }
162
+ return blocklet;
177
163
  }
178
-
179
- return blocklet;
180
- }
181
-
182
- for (const child of blocklet.children || []) {
183
- const ancestors = _ancestors.concat(blocklet);
184
- const component = findComponentById(child, componentId, { _ancestors: ancestors, returnAncestors });
185
- if (component) {
186
- return component;
164
+ for (const child of blocklet.children || []) {
165
+ const ancestors = _ancestors.concat(blocklet);
166
+ const component = findComponentById(child, componentId, { _ancestors: ancestors, returnAncestors });
167
+ if (component) {
168
+ return component;
169
+ }
187
170
  }
188
- }
189
-
190
- return null;
171
+ return null;
191
172
  };
192
-
173
+ exports.findComponentById = findComponentById;
193
174
  const isEnvShareable = (env) => {
194
- return (
195
- !!env &&
196
- !!(env.key || env.name) &&
197
- !env.secure &&
198
- env.shared !== false &&
199
- !BLOCKLET_CONFIGURABLE_KEY[env.key || env.name]
200
- );
175
+ return (!!env &&
176
+ !!(env.key || env.name) &&
177
+ !env.secure &&
178
+ env.shared !== false &&
179
+ !BLOCKLET_CONFIGURABLE_KEY[env.key || env.name]);
201
180
  };
202
-
181
+ exports.isEnvShareable = isEnvShareable;
203
182
  const getSharedConfigObj = (component, ancestors) => {
204
- const res = {};
205
- if (!ancestors) {
206
- return res;
207
- }
208
-
209
- for (let i = ancestors.length - 1; i >= 0; i--) {
210
- const ancestor = ancestors[i];
211
- if (Array.isArray(ancestor.configs)) {
212
- ancestor.configs.forEach(({ key, value, secure, shared }) => {
213
- if (res[key]) {
214
- return;
215
- }
216
-
217
- if (!value || secure !== false || shared === false || BLOCKLET_CONFIGURABLE_KEY[key]) {
218
- return;
219
- }
220
-
221
- const config = (component.configs || []).find((x) => x.key === key);
222
- if (config && config.value) {
223
- return;
183
+ const res = {};
184
+ if (!ancestors) {
185
+ return res;
186
+ }
187
+ for (let i = ancestors.length - 1; i >= 0; i--) {
188
+ const ancestor = ancestors[i];
189
+ if (Array.isArray(ancestor.configs)) {
190
+ ancestor.configs.forEach(({ key, value, secure, shared }) => {
191
+ if (res[key]) {
192
+ return;
193
+ }
194
+ if (!value || secure !== false || shared === false || BLOCKLET_CONFIGURABLE_KEY[key]) {
195
+ return;
196
+ }
197
+ const config = (component.configs || []).find((x) => x.key === key);
198
+ if (config && config.value) {
199
+ return;
200
+ }
201
+ res[key] = value;
202
+ });
224
203
  }
225
-
226
- res[key] = value;
227
- });
228
204
  }
229
- }
230
-
231
- return res;
205
+ return res;
232
206
  };
233
-
207
+ exports.getSharedConfigObj = getSharedConfigObj;
234
208
  const getAppMissingConfigs = (blocklet = {}) => {
235
- const missingConfigs = [];
236
-
237
- forEachBlockletSync(blocklet, (b, { ancestors }) => {
238
- const configs = b.configs || [];
239
- const sharedConfigObj = getSharedConfigObj(b, ancestors);
240
- configs.forEach((item) => {
241
- if (item.required && !item.value && !sharedConfigObj[item.key]) {
242
- missingConfigs.push({ did: b.meta.did, key: item.key, description: item.description });
243
- }
209
+ const missingConfigs = [];
210
+ forEachBlockletSync(blocklet, (b, { ancestors }) => {
211
+ const configs = b.configs || [];
212
+ const sharedConfigObj = getSharedConfigObj(b, ancestors);
213
+ configs.forEach((item) => {
214
+ if (item.required && !item.value && !sharedConfigObj[item.key]) {
215
+ missingConfigs.push({ did: b.meta.did, key: item.key, description: item.description });
216
+ }
217
+ });
244
218
  });
245
- });
246
-
247
- return missingConfigs;
219
+ return missingConfigs;
248
220
  };
249
-
221
+ exports.getAppMissingConfigs = getAppMissingConfigs;
250
222
  const getComponentMissingConfigs = (component = {}, ancestors = []) => {
251
- const missingConfigs = [];
252
-
253
- const configs = component.configs || [];
254
- const sharedConfigObj = getSharedConfigObj(component, ancestors);
255
- configs.forEach((item) => {
256
- if (item.required && !item.value && !sharedConfigObj[item.key]) {
257
- missingConfigs.push({ did: component.meta.did, key: item.key, description: item.description });
258
- }
259
- });
260
-
261
- return missingConfigs;
223
+ const missingConfigs = [];
224
+ const configs = component.configs || [];
225
+ const sharedConfigObj = getSharedConfigObj(component, ancestors);
226
+ configs.forEach((item) => {
227
+ if (item.required && !item.value && !sharedConfigObj[item.key]) {
228
+ missingConfigs.push({ did: component.meta.did, key: item.key, description: item.description });
229
+ }
230
+ });
231
+ return missingConfigs;
262
232
  };
263
-
233
+ exports.getComponentMissingConfigs = getComponentMissingConfigs;
264
234
  const isFreeBlocklet = (meta) => {
265
- if (!meta.payment) {
266
- return true;
267
- }
268
-
269
- const priceList = (meta.payment.price || []).map((x) => x.value || 0);
270
- return priceList.every((x) => x === 0);
235
+ if (!meta.payment) {
236
+ return true;
237
+ }
238
+ const priceList = (meta.payment.price || []).map((x) => x.value || 0);
239
+ return priceList.every((x) => x === 0);
271
240
  };
272
-
241
+ exports.isFreeBlocklet = isFreeBlocklet;
273
242
  const isFreeComponent = (meta) => {
274
- if (!meta.payment) {
275
- return true;
276
- }
277
-
278
- if (!meta.payment.componentPrice) {
279
- return true;
280
- }
281
-
282
- return !meta.payment.componentPrice.length;
243
+ if (!meta.payment) {
244
+ return true;
245
+ }
246
+ if (!meta.payment.componentPrice) {
247
+ return true;
248
+ }
249
+ return !meta.payment.componentPrice.length;
283
250
  };
284
-
251
+ exports.isFreeComponent = isFreeComponent;
285
252
  const isComponentBlocklet = (meta) => {
286
- return get(meta, 'capabilities.component') !== false;
253
+ return (0, get_1.default)(meta, 'capabilities.component') !== false;
287
254
  };
288
-
255
+ exports.isComponentBlocklet = isComponentBlocklet;
289
256
  const wipeSensitiveData = (blocklet) => {
290
- if (!blocklet) {
257
+ if (!blocklet) {
258
+ return blocklet;
259
+ }
260
+ forEachBlocklet(blocklet, (d) => {
261
+ (d.configs || []).forEach((x) => {
262
+ if (x.secure) {
263
+ x.value = x.value ? '__encrypted__' : '';
264
+ }
265
+ });
266
+ (d.environments || []).forEach((x) => {
267
+ if (['BLOCKLET_APP_SK'].includes(x.key)) {
268
+ x.value = '__encrypted__';
269
+ }
270
+ });
271
+ // @ts-ignore
272
+ delete blocklet.configObj;
273
+ // @ts-ignore
274
+ delete blocklet.environmentObj;
275
+ }, { sync: true });
291
276
  return blocklet;
292
- }
293
-
294
- forEachBlocklet(
295
- blocklet,
296
- (d) => {
297
- (d.configs || []).forEach((x) => {
298
- if (x.secure) {
299
- x.value = x.value ? '__encrypted__' : '';
300
- }
301
- });
302
- (d.environments || []).forEach((x) => {
303
- if (['BLOCKLET_APP_SK'].includes(x.key)) {
304
- x.value = '__encrypted__';
305
- }
306
- });
307
-
308
- delete blocklet.configObj;
309
- delete blocklet.environmentObj;
310
- },
311
- { sync: true }
312
- );
313
-
314
- return blocklet;
315
277
  };
316
-
278
+ exports.wipeSensitiveData = wipeSensitiveData;
317
279
  const isDeletableBlocklet = (blocklet) => {
318
- if (!blocklet) {
319
- return false;
320
- }
321
-
322
- const config = blocklet.environments.find((x) => x.key === 'BLOCKLET_DELETABLE');
323
- if (!config) {
324
- return true;
325
- }
326
-
327
- return config.value === 'yes';
280
+ if (!blocklet) {
281
+ return false;
282
+ }
283
+ const config = blocklet.environments.find((x) => x.key === 'BLOCKLET_DELETABLE');
284
+ if (!config) {
285
+ return true;
286
+ }
287
+ return config.value === 'yes';
328
288
  };
329
-
289
+ exports.isDeletableBlocklet = isDeletableBlocklet;
330
290
  const hasRunnableComponent = (blocklet) => {
331
- let has = false;
332
- forEachBlockletSync(blocklet, (x) => {
333
- if (x.meta.group !== BlockletGroup.gateway) {
334
- has = true;
335
- }
336
- });
337
-
338
- return has;
291
+ let has = false;
292
+ forEachBlockletSync(blocklet, (x) => {
293
+ if (x.meta.group !== BlockletGroup.gateway) {
294
+ has = true;
295
+ }
296
+ });
297
+ return has;
339
298
  };
340
-
299
+ exports.hasRunnableComponent = hasRunnableComponent;
341
300
  /**
342
301
  * 获取 blocklet 的 name
343
302
  * @param {Object} blocklet 应用数据
@@ -345,152 +304,138 @@ const hasRunnableComponent = (blocklet) => {
345
304
  * @returns blocklet display name
346
305
  */
347
306
  const getDisplayName = (blocklet, onlyUseMeta = false) => {
348
- if (!blocklet) {
349
- return '';
350
- }
351
-
352
- const { meta } = blocklet;
353
- let displayName;
354
-
355
- if (!onlyUseMeta && blocklet.environments) {
356
- const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_NAME');
357
- if (target && target.value) {
358
- displayName = target.value;
307
+ if (!blocklet) {
308
+ return '';
359
309
  }
360
- }
361
- return displayName || meta.title || meta.name;
310
+ const { meta } = blocklet;
311
+ let displayName;
312
+ if (!onlyUseMeta && blocklet.environments) {
313
+ const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_NAME');
314
+ if (target && target.value) {
315
+ displayName = target.value;
316
+ }
317
+ }
318
+ return displayName || meta.title || meta.name;
362
319
  };
363
-
320
+ exports.getDisplayName = getDisplayName;
364
321
  const fixBlockletStatus = (blocklet) => {
365
- if (!blocklet) {
366
- return;
367
- }
368
-
369
- forEachBlockletSync(blocklet, (b) => {
370
- b.status = fromBlockletStatus(b.status);
371
- if (b.source !== undefined) {
372
- b.source = fromBlockletSource(b.source);
322
+ if (!blocklet) {
323
+ return;
373
324
  }
374
- });
375
-
376
- if (blocklet.settings) {
377
- (blocklet.settings.children || []).forEach((child) => {
378
- forEachBlockletSync(child, (b) => {
325
+ forEachBlockletSync(blocklet, (b) => {
379
326
  b.status = fromBlockletStatus(b.status);
380
327
  if (b.source !== undefined) {
381
- b.source = fromBlockletSource(b.source);
328
+ b.source = fromBlockletSource(b.source);
382
329
  }
383
- });
384
330
  });
385
- }
331
+ if (blocklet.settings) {
332
+ (blocklet.settings.children || []).forEach((child) => {
333
+ forEachBlockletSync(child, (b) => {
334
+ b.status = fromBlockletStatus(b.status);
335
+ if (b.source !== undefined) {
336
+ b.source = fromBlockletSource(b.source);
337
+ }
338
+ });
339
+ });
340
+ }
386
341
  };
387
-
342
+ exports.fixBlockletStatus = fixBlockletStatus;
388
343
  const findWebInterface = (blocklet) => {
389
- if (!blocklet) {
390
- return null;
391
- }
392
-
393
- const meta = blocklet.meta || blocklet || {};
394
- const { interfaces = [] } = meta;
395
-
396
- if (!Array.isArray(interfaces)) {
397
- return null;
398
- }
399
-
400
- return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
344
+ if (!blocklet) {
345
+ return null;
346
+ }
347
+ // @ts-ignore
348
+ const meta = blocklet.meta || blocklet || {};
349
+ const { interfaces = [] } = meta;
350
+ if (!Array.isArray(interfaces)) {
351
+ return null;
352
+ }
353
+ return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
401
354
  };
402
-
355
+ exports.findWebInterface = findWebInterface;
403
356
  const findServiceFromMeta = (meta, ServiceName) => {
404
- const names = [ServiceName];
405
-
406
- // backward compatible
407
- if (ServiceName === NODE_SERVICES.AUTH) {
408
- names.push(NODE_SERVICES.AUTH_SERVICE);
409
- }
410
-
411
- const webInterface = findWebInterface(meta);
412
-
413
- if (!webInterface) {
414
- return null;
415
- }
416
-
417
- return (webInterface.services || []).find((x) => names.includes(x.name));
357
+ const names = [ServiceName];
358
+ // backward compatible
359
+ if (ServiceName === NODE_SERVICES.AUTH) {
360
+ names.push(NODE_SERVICES.AUTH_SERVICE);
361
+ }
362
+ const webInterface = findWebInterface(meta);
363
+ if (!webInterface) {
364
+ return null;
365
+ }
366
+ return (webInterface.services || []).find((x) => names.includes(x.name));
418
367
  };
419
-
368
+ exports.findServiceFromMeta = findServiceFromMeta;
420
369
  const getWhoCanAccess = (blocklet) => {
421
- if (!blocklet) {
370
+ if (!blocklet) {
371
+ return WHO_CAN_ACCESS.ALL;
372
+ }
373
+ if ((0, get_1.default)(blocklet, 'settings.whoCanAccess')) {
374
+ return blocklet.settings.whoCanAccess;
375
+ }
376
+ // @ts-ignore
377
+ const service = findServiceFromMeta(blocklet.meta, NODE_SERVICES.AUTH);
378
+ if ((0, get_1.default)(service, 'config.whoCanAccess')) {
379
+ return service.config.whoCanAccess;
380
+ }
422
381
  return WHO_CAN_ACCESS.ALL;
423
- }
424
-
425
- if (get(blocklet, 'settings.whoCanAccess')) {
426
- return blocklet.settings.whoCanAccess;
427
- }
428
-
429
- const service = findServiceFromMeta(blocklet.meta, NODE_SERVICES.AUTH);
430
- if (get(service, 'config.whoCanAccess')) {
431
- return service.config.whoCanAccess;
432
- }
433
-
434
- return WHO_CAN_ACCESS.ALL;
435
382
  };
436
-
383
+ exports.getWhoCanAccess = getWhoCanAccess;
437
384
  const getConnectAppUrl = ({ request, baseUrl }) => {
438
- const blockletDid = request.headers['x-blocklet-did'] || '';
439
- const blockletRealDid = request.headers['x-blocklet-real-did'] || '';
440
- const pathPrefix = request.headers['x-path-prefix'] || '/';
441
- const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
442
-
443
- // Child blocklets should set appInfo.link to exactly the same path as the root blocklet
444
- let appUrl = baseUrl;
445
- if (blockletDid !== blockletRealDid && pathPrefix !== groupPathPrefix) {
446
- appUrl = joinUrl(joinUrl(appUrl, '/').replace(pathPrefix, groupPathPrefix), '');
447
- }
448
-
449
- return appUrl;
385
+ const blockletDid = request.headers['x-blocklet-did'] || '';
386
+ const blockletRealDid = request.headers['x-blocklet-real-did'] || '';
387
+ const pathPrefix = request.headers['x-path-prefix'] || '/';
388
+ const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
389
+ // Child blocklets should set appInfo.link to exactly the same path as the root blocklet
390
+ let appUrl = baseUrl;
391
+ if (blockletDid !== blockletRealDid && pathPrefix !== groupPathPrefix) {
392
+ appUrl = (0, url_join_1.default)((0, url_join_1.default)(appUrl, '/').replace(pathPrefix, groupPathPrefix), '');
393
+ }
394
+ return appUrl;
450
395
  };
451
-
396
+ exports.getConnectAppUrl = getConnectAppUrl;
452
397
  const replaceSlotToIp = (url, ip) => (url || '').replace(SLOT_FOR_IP_DNS_SITE, (ip || '').replace(/\./g, '-'));
453
-
454
- const urlFriendly = (name) => slugify(name.replace(/^[@./-]/, '').replace(/[@./_]/g, '-'));
455
-
398
+ exports.replaceSlotToIp = replaceSlotToIp;
399
+ const urlFriendly = (name) => (0, slugify_1.default)(name.replace(/^[@./-]/, '').replace(/[@./_]/g, '-'));
400
+ exports.urlFriendly = urlFriendly;
456
401
  // transform process.env.CHAIN_x => { x: v }
457
- const getChainInfo = (env) =>
458
- Object.entries(CHAIN_INFO_CONFIG).reduce((info, x) => {
402
+ const getChainInfo = (env) => Object.entries(CHAIN_INFO_CONFIG).reduce((info, x) => {
403
+ // @ts-expect-error TS(2488) FIXME: Type 'unknown' must have a '[Symbol.iterator]()' m... Remove this comment to see the full error message
459
404
  const [envName, [key, value]] = x;
460
- info[key] = get(env, envName) || value;
405
+ info[key] = (0, get_1.default)(env, envName) || value;
461
406
  return info;
462
- }, {});
463
-
464
- const isExternalBlocklet = (blocklet) => !!blocklet?.controller;
465
-
466
- module.exports = {
467
- isFreeBlocklet,
468
- isFreeComponent,
469
- isComponentBlocklet,
470
- forEachBlocklet,
471
- forEachBlockletSync,
472
- forEachChild,
473
- forEachChildSync,
474
- isDeletableBlocklet,
475
- getSharedConfigObj,
476
- getAppMissingConfigs,
477
- getComponentMissingConfigs,
478
- isEnvShareable,
479
- wipeSensitiveData,
480
- hasRunnableComponent,
481
- getDisplayName,
482
- fixBlockletStatus,
483
- findWebInterface,
484
- findServiceFromMeta,
485
- getWhoCanAccess,
486
- replaceSlotToIp,
487
- urlFriendly,
488
- getComponentId,
489
- getComponentName,
490
- getComponentBundleId,
491
- findComponentById,
492
- getParentComponentName,
493
- getConnectAppUrl,
494
- getChainInfo,
495
- isExternalBlocklet,
407
+ }, {});
408
+ exports.getChainInfo = getChainInfo;
409
+ const isExternalBlocklet = (blocklet) => !!(blocklet === null || blocklet === void 0 ? void 0 : blocklet.controller);
410
+ exports.isExternalBlocklet = isExternalBlocklet;
411
+ exports.default = {
412
+ isFreeBlocklet,
413
+ isFreeComponent,
414
+ isComponentBlocklet,
415
+ forEachBlocklet,
416
+ forEachBlockletSync,
417
+ forEachChild,
418
+ forEachChildSync,
419
+ isDeletableBlocklet,
420
+ getSharedConfigObj,
421
+ getAppMissingConfigs,
422
+ getComponentMissingConfigs,
423
+ isEnvShareable,
424
+ wipeSensitiveData,
425
+ hasRunnableComponent,
426
+ getDisplayName,
427
+ fixBlockletStatus,
428
+ findWebInterface,
429
+ findServiceFromMeta,
430
+ getWhoCanAccess,
431
+ replaceSlotToIp,
432
+ urlFriendly,
433
+ getComponentId,
434
+ getComponentName,
435
+ getComponentBundleId,
436
+ findComponentById,
437
+ getParentComponentName,
438
+ getConnectAppUrl,
439
+ getChainInfo,
440
+ isExternalBlocklet,
496
441
  };