@abtnode/ux 1.8.27 → 1.8.29

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 (85) hide show
  1. package/lib/actions.js +16 -44
  2. package/lib/blocklet/actions.js +14 -78
  3. package/lib/blocklet/audit-logs.js +0 -32
  4. package/lib/blocklet/avatar.js +6 -33
  5. package/lib/blocklet/blocklet-source.js +0 -13
  6. package/lib/blocklet/component/configuration.js +2 -28
  7. package/lib/blocklet/component/delete.js +0 -23
  8. package/lib/blocklet/component/environment.js +2 -59
  9. package/lib/blocklet/component/index.js +10 -105
  10. package/lib/blocklet/component/setting.js +5 -44
  11. package/lib/blocklet/configuration.js +11 -79
  12. package/lib/blocklet/disk-info.js +3 -29
  13. package/lib/blocklet/icons.js +0 -10
  14. package/lib/blocklet/log.js +3 -18
  15. package/lib/blocklet/mode.js +3 -17
  16. package/lib/blocklet/overview.js +3 -37
  17. package/lib/blocklet/runtime-info.js +4 -30
  18. package/lib/blocklet/status.js +5 -27
  19. package/lib/blocklet/util.js +0 -22
  20. package/lib/blocklet/version.js +7 -45
  21. package/lib/card-selector.js +9 -22
  22. package/lib/click-to-copy.js +3 -18
  23. package/lib/confirm.js +2 -28
  24. package/lib/contexts/audit-log.js +2 -16
  25. package/lib/contexts/deleting-blocklets.js +2 -15
  26. package/lib/contexts/node.js +0 -6
  27. package/lib/contexts/session.js +1 -3
  28. package/lib/contexts/team.js +0 -3
  29. package/lib/did-address.js +6 -26
  30. package/lib/dot.js +0 -7
  31. package/lib/form/form-text-input.js +12 -38
  32. package/lib/form/form-wrapper.js +0 -7
  33. package/lib/form/required.js +0 -6
  34. package/lib/hooks/mobile-width.js +0 -5
  35. package/lib/hooks/use-passport-id.js +0 -5
  36. package/lib/index.js +0 -3
  37. package/lib/invitation/invitation-app.js +3 -21
  38. package/lib/invitation/invitation-passport.js +2 -16
  39. package/lib/invitation/invitation-receive.js +2 -19
  40. package/lib/invitation/invitation-user.js +0 -16
  41. package/lib/invitation/invitation.js +0 -23
  42. package/lib/issue-passport.js +2 -31
  43. package/lib/launch-blocklet/content-layout.js +3 -19
  44. package/lib/launch-blocklet/page-header.js +0 -9
  45. package/lib/layout/addon.js +0 -24
  46. package/lib/locales/index.js +0 -3
  47. package/lib/logs/clock.js +0 -6
  48. package/lib/logs/log-terminal.js +17 -43
  49. package/lib/lost-passport.js +6 -51
  50. package/lib/nav-logo.js +12 -33
  51. package/lib/passport-tag.js +4 -21
  52. package/lib/permission.js +0 -16
  53. package/lib/relative-time.js +0 -13
  54. package/lib/schema-form/color-input.js +2 -15
  55. package/lib/schema-form/common-prop-types.js +0 -3
  56. package/lib/schema-form/index.js +8 -45
  57. package/lib/schema-form/passport-input.js +6 -24
  58. package/lib/schema-form/text-input.js +9 -26
  59. package/lib/table-icons.js +0 -17
  60. package/lib/table.js +0 -6
  61. package/lib/tag.js +4 -17
  62. package/lib/team/members/actions.js +2 -18
  63. package/lib/team/members/index.js +1 -69
  64. package/lib/team/members/invitations.js +0 -33
  65. package/lib/team/members/invite-member.js +0 -29
  66. package/lib/team/members/issue-passport.js +0 -23
  67. package/lib/team/members/member.js +1 -43
  68. package/lib/team/members/passport-issuances.js +3 -30
  69. package/lib/team/members/passports.js +0 -48
  70. package/lib/team/members/toggle-user-approval.js +0 -26
  71. package/lib/team/members/transfer-node.js +0 -33
  72. package/lib/team/members/util.js +2 -9
  73. package/lib/team/passports/detail.js +2 -45
  74. package/lib/team/passports/index.js +0 -36
  75. package/lib/team/passports/mutate-role.js +0 -26
  76. package/lib/team/passports/trusted-issuer.js +0 -44
  77. package/lib/team/passports/trusted-issuers.js +0 -46
  78. package/lib/team/search-input.js +3 -18
  79. package/lib/team/styles/dialog.js +0 -6
  80. package/lib/team/styles/list-header.js +0 -6
  81. package/lib/toast.js +4 -19
  82. package/lib/util/index.js +14 -184
  83. package/lib/who-can-access/config.js +0 -6
  84. package/lib/wrap-locale.js +0 -7
  85. package/package.json +27 -27
package/lib/util/index.js CHANGED
@@ -36,155 +36,111 @@ exports.patchJsxToLocale = patchJsxToLocale;
36
36
  exports.shouldCheckDomainStatus = void 0;
37
37
  exports.sleep = sleep;
38
38
  exports.validateDomain = exports.stringSortHandlerAsc = void 0;
39
-
40
39
  var _constant = require("@abtnode/constant");
41
-
42
40
  var _dayjs = _interopRequireDefault(require("dayjs"));
43
-
44
41
  require("moment/locale/zh-cn");
45
-
46
42
  var _querystring = _interopRequireDefault(require("querystring"));
47
-
48
43
  var _isUrl = _interopRequireDefault(require("is-url"));
49
-
50
44
  var _moment = _interopRequireDefault(require("moment"));
51
-
52
45
  var _humanizeUrl = _interopRequireDefault(require("humanize-url"));
53
-
54
46
  var _filesize = _interopRequireDefault(require("filesize"));
55
-
56
47
  var _urlJoin = _interopRequireDefault(require("url-join"));
57
-
58
48
  var _get = _interopRequireDefault(require("lodash/get"));
59
-
60
49
  var _last = _interopRequireDefault(require("lodash/last"));
61
-
62
50
  var _trimEnd = _interopRequireDefault(require("lodash/trimEnd"));
63
-
64
51
  var _constant2 = require("@blocklet/constant");
65
-
66
52
  var _urlEvaluation = require("@abtnode/util/lib/url-evaluation");
67
-
68
53
  var _checkAccessibleBrowser = _interopRequireDefault(require("@abtnode/util/lib/url-evaluation/check-accessible-browser"));
69
-
70
54
  var _axios = _interopRequireDefault(require("@abtnode/util/lib/axios"));
71
-
72
55
  var _window$env;
73
-
74
56
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
75
-
76
57
  function sleep(t) {
77
58
  // eslint-disable-next-line no-promise-executor-return
78
59
  return new Promise(resolve => setTimeout(resolve, t));
79
60
  }
80
-
81
61
  const validateDomain = function validateDomain(domain) {
82
62
  let locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
83
-
84
63
  if (!domain) {
85
64
  return {
86
65
  en: 'Site domain cannot be empty',
87
66
  zh: '站点域名不能为空'
88
67
  }[locale];
89
68
  }
90
-
91
69
  if (domain.endsWith(_constant.DEFAULT_IP_DOMAIN_SUFFIX)) {
92
70
  return {
93
71
  en: "Site domain cannot include ".concat(_constant.DEFAULT_IP_DOMAIN_SUFFIX),
94
72
  zh: "\u7AD9\u70B9\u57DF\u540D\u4E0D\u80FD\u5305\u542B ".concat(_constant.DEFAULT_IP_DOMAIN_SUFFIX)
95
73
  }[locale];
96
74
  }
97
-
98
75
  return null;
99
76
  };
77
+
100
78
  /**
101
79
  * get access url
102
80
  * auto fix http/https, port, query
103
81
  * docker friendly
104
82
  */
105
-
106
-
107
83
  exports.validateDomain = validateDomain;
108
-
109
84
  function getAccessUrl(hostname) {
110
85
  let path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
111
86
  let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
112
-
113
87
  if (!hostname) {
114
88
  return '';
115
89
  }
116
-
117
90
  let protocol = 'http';
118
-
119
91
  if (window.location.protocol === 'https:') {
120
92
  if (hostname.endsWith(_constant.DEFAULT_IP_DOMAIN_SUFFIX)) {
121
93
  protocol = 'https';
122
94
  }
123
-
124
95
  if (hostname.endsWith(_constant.DEFAULT_DID_DOMAIN)) {
125
96
  protocol = 'https';
126
97
  }
127
98
  }
128
-
129
99
  let port = '';
130
100
  const browserPort = Number(window.location.port);
131
-
132
101
  if (process.env.NODE_ENV !== 'development' && browserPort && ![80, 443].includes(browserPort)) {
133
102
  port = ":".concat(browserPort);
134
103
  }
135
-
136
104
  const urlObj = new URL("".concat(protocol, "://").concat(hostname).concat(port));
137
105
  urlObj.pathname = path;
138
106
  const url = urlObj.href.replace(/\/$/, '');
139
-
140
107
  if (!params || !Object.keys(params)) {
141
108
  return url;
142
109
  }
143
-
144
110
  const searchParams = new URLSearchParams();
145
111
  Object.keys(params).forEach(key => {
146
112
  searchParams.append(key, params[key]);
147
113
  });
148
114
  return "".concat(url, "?").concat(searchParams.toString());
149
115
  }
150
-
151
116
  function getExplorerLink(chainHost, did, type) {
152
117
  if (!chainHost) return undefined;
153
-
154
118
  try {
155
119
  const chainUrl = new URL(chainHost);
156
-
157
120
  switch (type) {
158
121
  case 'account':
159
122
  chainUrl.pathname = "/explorer/accounts/".concat(did);
160
123
  break;
161
-
162
124
  case 'tx':
163
125
  chainUrl.pathname = "/explorer/txs/".concat(did);
164
126
  break;
165
-
166
127
  case 'token':
167
128
  chainUrl.pathname = "/explorer/tokens/".concat(did);
168
129
  break;
169
-
170
130
  case 'factory':
171
131
  chainUrl.pathname = "/explorer/factories/".concat(did);
172
132
  break;
173
-
174
133
  case 'bridge':
175
134
  chainUrl.pathname = "/explorer/bridges/".concat(did);
176
135
  break;
177
-
178
136
  default:
179
137
  chainUrl.pathname = '/';
180
138
  }
181
-
182
139
  return chainUrl.href;
183
140
  } catch (_unused) {
184
141
  return undefined;
185
142
  }
186
143
  }
187
-
188
144
  function patchJsxToLocale(rawStr) {
189
145
  let replaceMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
190
146
  return rawStr.split(/{{|}}/).map(item => {
@@ -192,94 +148,70 @@ function patchJsxToLocale(rawStr) {
192
148
  if (replaceMap[item] instanceof Function) {
193
149
  return replaceMap[item]();
194
150
  }
195
-
196
151
  return replaceMap[item];
197
152
  }
198
-
199
153
  return item;
200
154
  }).filter(Boolean);
201
155
  }
202
-
203
156
  function formatTimestamp(ts) {
204
157
  if (!ts) {
205
158
  return '-';
206
159
  }
207
-
208
160
  let date;
209
-
210
161
  if (Number(ts).toString() === ts) {
211
162
  date = new Date();
212
163
  date.setTime(ts);
213
164
  } else {
214
165
  date = new Date(ts);
215
166
  }
216
-
217
167
  return date.toLocaleString();
218
168
  }
219
-
220
169
  function formatToDate(date) {
221
170
  if (!date) {
222
171
  return '-';
223
172
  }
224
-
225
173
  return (0, _moment.default)(date).format('ll');
226
174
  }
227
-
228
175
  function formatToDatetime(date) {
229
176
  if (!date) {
230
177
  return '-';
231
178
  }
232
-
233
179
  return (0, _moment.default)(date).format('lll');
234
180
  }
235
-
236
181
  function formatTimeFromNow(date) {
237
182
  if (!date) {
238
183
  return '-';
239
184
  }
240
-
241
185
  const startDate = (0, _moment.default)(date);
242
186
  const endDate = (0, _moment.default)();
243
187
  const diffDay = endDate.diff(startDate, 'day');
244
188
  return diffDay > 3 ? formatToDate(date) : startDate.fromNow();
245
189
  }
246
-
247
190
  function formatTime(date) {
248
191
  let format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'lll';
249
-
250
192
  if (!date) {
251
193
  return '-';
252
194
  }
253
-
254
195
  return (0, _moment.default)(date).format(format);
255
196
  }
256
-
257
197
  function formatDateTime(date) {
258
198
  return (0, _dayjs.default)(date).format('YYYY-MM-DD HH:mm');
259
199
  }
260
-
261
200
  const formatError = error => {
262
201
  if (Array.isArray(error.errors)) {
263
202
  return error.errors.map(x => x.message).join('\n');
264
203
  }
265
-
266
204
  return error.message;
267
205
  };
268
-
269
206
  exports.formatError = formatError;
270
-
271
207
  const formatLocale = function formatLocale() {
272
208
  let locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'en';
273
-
274
209
  if (locale === 'zh') {
275
210
  return 'zh_CN';
276
211
  }
277
-
278
212
  return locale;
279
213
  };
280
-
281
214
  exports.formatLocale = formatLocale;
282
-
283
215
  const parseQuery = str => str.replace(/^\?/, '').split('&').map(x => x.split('=')).filter(_ref => {
284
216
  let [key] = _ref;
285
217
  return !!key;
@@ -288,11 +220,10 @@ const parseQuery = str => str.replace(/^\?/, '').split('&').map(x => x.split('='
288
220
  const value = decodeURIComponent(x[1]) || true;
289
221
  memo[key] = value;
290
222
  return memo;
291
- }, {}); // Append any query string url to api requests
292
-
223
+ }, {});
293
224
 
225
+ // Append any query string url to api requests
294
226
  exports.parseQuery = parseQuery;
295
-
296
227
  const appendParams = function appendParams(url) {
297
228
  let extraParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
298
229
  const [pathname, query = ''] = url.split('?');
@@ -300,21 +231,13 @@ const appendParams = function appendParams(url) {
300
231
  const params = Object.assign({}, oldParams, extraParams);
301
232
  return "".concat(pathname, "?").concat(_querystring.default.stringify(params));
302
233
  };
303
-
304
234
  exports.appendParams = appendParams;
305
-
306
235
  const isInProgress = status => ['waiting', 'downloading', 'starting', 'installing', 'stopping', 'upgrading', 'restarting', 'deleting'].includes(status);
307
-
308
236
  exports.isInProgress = isInProgress;
309
-
310
237
  const isInstalling = status => ['waiting', 'downloading', 'installing', 'upgrading'].includes(status);
311
-
312
238
  exports.isInstalling = isInstalling;
313
-
314
239
  const isDownloading = status => ['waiting', 'downloading'].includes(status);
315
-
316
240
  exports.isDownloading = isDownloading;
317
-
318
241
  const formatDiskSize = function formatDiskSize(size) {
319
242
  let serverPlatform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
320
243
  const base = serverPlatform === 'linux' ? 2 : 10;
@@ -323,40 +246,29 @@ const formatDiskSize = function formatDiskSize(size) {
323
246
  round: 2
324
247
  });
325
248
  };
326
-
327
249
  exports.formatDiskSize = formatDiskSize;
328
-
329
250
  const checkInputByType = (type, value) => {
330
251
  const typesMap = {
331
252
  url: _isUrl.default
332
253
  };
333
-
334
254
  if (!type) {
335
255
  return true;
336
256
  }
337
-
338
257
  if (typesMap[type]) {
339
258
  return typesMap[type](value);
340
259
  }
341
-
342
260
  return false;
343
261
  };
344
-
345
262
  exports.checkInputByType = checkInputByType;
346
-
347
263
  const formatUrl = url => (0, _humanizeUrl.default)(url.split('?').shift());
348
-
349
264
  exports.formatUrl = formatUrl;
350
-
351
265
  const formatPerson = person => {
352
266
  if (!person) {
353
267
  return '-';
354
268
  }
355
-
356
269
  if (typeof person === 'string') {
357
270
  return person;
358
271
  }
359
-
360
272
  const name = person.name || '';
361
273
  const u = person.url || person.web;
362
274
  const url = u ? " (".concat(u, ")") : '';
@@ -364,9 +276,7 @@ const formatPerson = person => {
364
276
  const email = e ? " <".concat(e, ">") : '';
365
277
  return name + email + url;
366
278
  };
367
-
368
279
  exports.formatPerson = formatPerson;
369
-
370
280
  const getBlockletServices = blocklet => {
371
281
  const services = [];
372
282
  const interfaces = (blocklet.meta.interfaces || []).filter(x => x.type === _constant2.BLOCKLET_INTERFACE_TYPE_SERVICE);
@@ -380,20 +290,16 @@ const getBlockletServices = blocklet => {
380
290
  });
381
291
  return services;
382
292
  };
383
-
384
293
  exports.getBlockletServices = getBlockletServices;
385
-
386
- const shouldCheckDomainStatus = domain => domain && // eslint-disable-line
294
+ const shouldCheckDomainStatus = domain => domain &&
295
+ // eslint-disable-line
387
296
  ![_constant.DOMAIN_FOR_IP_SITE, _constant.DOMAIN_FOR_IP_SITE_REGEXP, _constant.DOMAIN_FOR_DEFAULT_SITE, _constant.DOMAIN_FOR_INTERNAL_SITE].includes(domain);
388
-
389
297
  exports.shouldCheckDomainStatus = shouldCheckDomainStatus;
390
-
391
298
  const checkIsWildcardDomain = url => {
392
299
  try {
393
300
  if (!url) {
394
301
  return false;
395
302
  }
396
-
397
303
  const tempUrl = url.startsWith('http') ? url : "http://".concat(url);
398
304
  const urlObj = new window.URL(tempUrl);
399
305
  return decodeURIComponent(urlObj.host).split('.').some(x => x === '*');
@@ -402,26 +308,19 @@ const checkIsWildcardDomain = url => {
402
308
  return false;
403
309
  }
404
310
  };
405
-
406
311
  exports.checkIsWildcardDomain = checkIsWildcardDomain;
407
-
408
312
  const stringSortHandlerAsc = function stringSortHandlerAsc() {
409
313
  let strA = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
410
314
  let strB = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
411
-
412
315
  if (strA > strB) {
413
316
  return 1;
414
317
  }
415
-
416
318
  if (strB > strA) {
417
319
  return -1;
418
320
  }
419
-
420
321
  return 0;
421
322
  };
422
-
423
323
  exports.stringSortHandlerAsc = stringSortHandlerAsc;
424
-
425
324
  const getEndPoint = nodeInfo => {
426
325
  const {
427
326
  routing
@@ -433,161 +332,120 @@ const getEndPoint = nodeInfo => {
433
332
  port
434
333
  } = window.location;
435
334
  let endpoint = "".concat(origin).concat(routing.adminPath);
436
-
437
335
  if (process.env.NODE_ENV === 'development') {
438
336
  endpoint = "".concat(protocol, "//").concat(hostname, ":").concat(port);
439
337
  }
440
-
441
338
  return endpoint;
442
339
  };
443
-
444
340
  exports.getEndPoint = getEndPoint;
445
-
446
341
  const getInviteLink = _ref2 => {
447
342
  let {
448
343
  inviteId,
449
344
  endpoint
450
345
  } = _ref2;
451
-
452
346
  if (!endpoint) {
453
347
  return '';
454
348
  }
455
-
456
349
  const u = new URL(endpoint);
457
350
  u.pathname = (0, _urlJoin.default)(u.pathname, _constant.WELLKNOWN_SERVICE_PATH_PREFIX, 'invite');
458
351
  u.searchParams.set('inviteId', inviteId);
459
352
  return u.href;
460
353
  };
461
-
462
354
  exports.getInviteLink = getInviteLink;
463
-
464
355
  const getIssuePassportLink = _ref3 => {
465
356
  let {
466
357
  id,
467
358
  endpoint
468
359
  } = _ref3;
469
-
470
360
  if (!endpoint) {
471
361
  return '';
472
362
  }
473
-
474
363
  const u = new URL(endpoint);
475
364
  u.pathname = (0, _urlJoin.default)(u.pathname, _constant.WELLKNOWN_SERVICE_PATH_PREFIX, 'issue-passport');
476
365
  u.searchParams.set('id', id);
477
366
  return u.href;
478
367
  };
479
-
480
368
  exports.getIssuePassportLink = getIssuePassportLink;
481
-
482
369
  const formatRegistryScreenshotPath = (did, asset) => {
483
370
  if (asset.startsWith('/assets')) {
484
371
  return asset;
485
372
  }
486
-
487
373
  return "/assets/".concat(did, "/screenshots/").concat(asset);
488
374
  };
489
-
490
375
  exports.formatRegistryScreenshotPath = formatRegistryScreenshotPath;
491
-
492
376
  const formatRegistryLogoPath = (did, asset) => {
493
377
  if (asset.startsWith('/assets')) {
494
378
  return asset;
495
379
  }
496
-
497
380
  return "/assets/".concat(did, "/").concat(asset);
498
381
  };
499
-
500
382
  exports.formatRegistryLogoPath = formatRegistryLogoPath;
501
-
502
383
  function getWebWalletUrl(info) {
503
384
  try {
504
385
  const url = window.localStorage.getItem('wallet_url');
505
-
506
386
  if (url) {
507
387
  return url;
508
388
  }
509
- } catch (err) {// Do nothing
389
+ } catch (err) {
390
+ // Do nothing
510
391
  }
511
-
512
392
  return info && info.webWalletUrl ? info.webWalletUrl : '';
513
393
  }
514
-
515
394
  function isValidClusterSize(data) {
516
395
  const {
517
396
  value,
518
397
  cpuCores
519
398
  } = data;
520
-
521
399
  if (!value) {
522
400
  return '';
523
401
  }
524
-
525
402
  const v = Number(value);
526
-
527
403
  if (Number.isNaN(v)) {
528
404
  return 'Cluster size should be a number';
529
405
  }
530
-
531
406
  if (!Number.isInteger(v)) {
532
407
  return 'Cluster size should be integer';
533
408
  }
534
-
535
409
  if (v <= 0 || v > cpuCores) {
536
410
  return "Cluster size should between 1 to ".concat(cpuCores);
537
411
  }
538
-
539
412
  return '';
540
413
  }
541
-
542
414
  function isProtectedRole(role) {
543
415
  return Object.values(_constant.ROLES).includes(role);
544
416
  }
545
-
546
417
  function formatFactoryPrice(blocklet) {
547
418
  var _blocklet$payment;
548
-
549
419
  if (!(blocklet !== null && blocklet !== void 0 && blocklet.payment)) {
550
420
  return [];
551
421
  }
552
-
553
422
  const list = (((_blocklet$payment = blocklet.payment) === null || _blocklet$payment === void 0 ? void 0 : _blocklet$payment.price) || []).map(item => ({
554
423
  name: item.symbol,
555
424
  value: item.value
556
425
  }));
557
426
  return list;
558
427
  }
559
-
560
428
  const getBlockletLogoUrl = _ref4 => {
561
429
  let {
562
430
  did,
563
431
  baseUrl,
564
432
  logoPath
565
433
  } = _ref4;
566
-
567
434
  if (baseUrl.startsWith('http') && logoPath) {
568
435
  return (0, _urlJoin.default)(baseUrl, formatRegistryLogoPath(did, logoPath));
569
436
  }
570
-
571
437
  const prefix = window.env.apiPrefix || '/';
572
438
  let apiPrefix = prefix.replace(/^\/+/, '').replace(/\/+$/, '');
573
-
574
439
  if (apiPrefix) {
575
440
  apiPrefix = "/".concat(apiPrefix);
576
441
  }
577
-
578
442
  return (0, _urlJoin.default)(apiPrefix, "/blocklet/logo/".concat(did));
579
443
  };
580
-
581
444
  exports.getBlockletLogoUrl = getBlockletLogoUrl;
582
-
583
445
  const getPathPrefix = () => window.env && window.env.apiPrefix ? window.env.apiPrefix : '/';
584
-
585
446
  exports.getPathPrefix = getPathPrefix;
586
-
587
447
  const isUrlAccessible = async url => (0, _checkAccessibleBrowser.default)((0, _urlJoin.default)(new URL(url).origin, _constant.WELLKNOWN_PING_PREFIX));
588
-
589
448
  exports.isUrlAccessible = isUrlAccessible;
590
-
591
449
  const getAccessibleUrl = async urls => {
592
450
  try {
593
451
  const res = await (0, _urlEvaluation.evaluateURLs)(urls);
@@ -597,20 +455,17 @@ const getAccessibleUrl = async urls => {
597
455
  return '';
598
456
  }
599
457
  };
458
+
600
459
  /**
601
460
  * 检查证书是否与 blocklet 匹配
602
461
  * @param {string[]} blockletUrls - 通过 blocklet#interfaces#url 获取到的一组 url
603
462
  * @param {object[]} matchedSites - 通过 certificate#matchedSites 获取到的一组 site
604
463
  * @returns {boolean} - 匹配则返回 true
605
464
  */
606
-
607
-
608
465
  exports.getAccessibleUrl = getAccessibleUrl;
609
-
610
466
  const isCertificateMatch = function isCertificateMatch() {
611
467
  let blockletUrls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
612
468
  let matchedSites = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
613
-
614
469
  try {
615
470
  return matchedSites.map(item => item.domain).some(domain => {
616
471
  return blockletUrls.some(blockletUrl => {
@@ -623,15 +478,14 @@ const isCertificateMatch = function isCertificateMatch() {
623
478
  return false;
624
479
  }
625
480
  };
626
-
627
481
  exports.isCertificateMatch = isCertificateMatch;
628
-
629
482
  const getBlockletUrlParams = (blocklet, locale) => (blocklet || {}).status === 'running' ? {
630
483
  locale
631
484
  } : {
632
485
  locale,
633
486
  __start__: 1
634
487
  };
488
+
635
489
  /**
636
490
  * 判断是否在safari浏览器中
637
491
  * 不传的ua情况下,使用当前页面的ua
@@ -640,40 +494,32 @@ const getBlockletUrlParams = (blocklet, locale) => (blocklet || {}).status === '
640
494
  * @param {String} ua userAgent 字符串
641
495
  * @returns bool
642
496
  */
643
-
644
-
645
497
  exports.getBlockletUrlParams = getBlockletUrlParams;
646
-
647
498
  const isSafari = function isSafari() {
648
499
  let ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
649
500
  return ua.includes('iPhone') || ua.includes('Safari') && !ua.includes('Chrome');
650
501
  };
651
-
652
502
  exports.isSafari = isSafari;
653
-
654
503
  const isChrome = function isChrome() {
655
504
  let ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
656
505
  return ua.includes('Chrome');
657
506
  };
507
+
658
508
  /**
659
509
  *
660
510
  * @export
661
511
  * @param {string} url
662
512
  * @return {string}
663
513
  */
664
-
665
-
666
514
  exports.isChrome = isChrome;
667
-
668
515
  function deepDecodeURIComponent(url) {
669
516
  let lastDecodeUrl = decodeURIComponent(url);
670
-
671
517
  while (lastDecodeUrl !== decodeURIComponent(lastDecodeUrl)) {
672
518
  lastDecodeUrl = decodeURIComponent(lastDecodeUrl);
673
519
  }
674
-
675
520
  return lastDecodeUrl;
676
521
  }
522
+
677
523
  /**
678
524
  *
679
525
  * @description 已知nextWorkflow的地址,提取它的statusUrl和token
@@ -684,8 +530,6 @@ function deepDecodeURIComponent(url) {
684
530
  * token: string;
685
531
  * }}
686
532
  */
687
-
688
-
689
533
  function extractStatusUrlFromNextWorkflow(nextWorkflow) {
690
534
  const nextWorkflowURL = new URL(deepDecodeURIComponent(nextWorkflow)).searchParams.get('url');
691
535
  return {
@@ -693,11 +537,9 @@ function extractStatusUrlFromNextWorkflow(nextWorkflow) {
693
537
  token: new URL(nextWorkflowURL).searchParams.get('_t_')
694
538
  };
695
539
  }
696
-
697
540
  function getBlockletMetaUrl(registry, did) {
698
541
  return (0, _urlJoin.default)(registry, "/api/blocklets/".concat(did, "/blocklet.json?source=webapp"));
699
542
  }
700
-
701
543
  async function getAsset(chainHost, address) {
702
544
  const result = await _axios.default.post((0, _urlJoin.default)(chainHost, '/api/gql/'), JSON.stringify({
703
545
  query: "{\n getAssetState(address: \"".concat(address, "\") {\n state {\n address\n data {\n typeUrl\n value\n }\n issuer\n owner\n parent\n }\n }\n }")
@@ -709,23 +551,20 @@ async function getAsset(chainHost, address) {
709
551
  timeout: 60 * 1000
710
552
  });
711
553
  const state = (0, _get.default)(result.data, 'data.getAssetState.state');
712
-
713
554
  if (state && state.data.typeUrl === 'json') {
714
555
  state.data.value = JSON.parse(state.data.value);
715
556
  }
716
-
717
557
  return state;
718
558
  }
719
-
720
559
  async function getAssetExpiration(chainHost, address) {
721
560
  const asset = await getAsset(chainHost, address);
722
561
  return (0, _last.default)((0, _get.default)(asset, 'data.value.expirationDate', []));
723
562
  }
724
-
725
563
  function getRelativeTime(datetime) {
726
564
  let locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
727
565
  return (0, _moment.default)(datetime).locale(formatLocale(locale)).fromNow().toString();
728
566
  }
567
+
729
568
  /**
730
569
  * 检查url是否 未添加到 store registryList 中
731
570
  * @param {string} url - 需要检查的url
@@ -735,48 +574,39 @@ function getRelativeTime(datetime) {
735
574
  * decoded: string;
736
575
  * })} - 返回判断是否是新的url和解码后的url
737
576
  */
738
-
739
-
740
577
  const isNewRegistryUrl = (url, blockletRegistryList) => {
741
578
  if (typeof url === 'string') {
742
579
  let decoded = decodeURIComponent(url === null || url === void 0 ? void 0 : url.trim());
743
580
  const regex = /^https?:\/\//;
744
-
745
581
  if (!regex.test(decoded)) {
746
582
  decoded = "https://".concat(decoded);
747
583
  }
584
+ decoded = (0, _trimEnd.default)(decoded, '/');
748
585
 
749
- decoded = (0, _trimEnd.default)(decoded, '/'); // validate
750
-
586
+ // validate
751
587
  try {
752
588
  new URL(decoded); // eslint-disable-line no-new
753
589
  } catch (_unused2) {
754
590
  throw new Error('Invalid Blocklet Store URL');
755
591
  }
756
-
757
592
  if (blockletRegistryList !== null && blockletRegistryList !== void 0 && blockletRegistryList.some(item => [url, decoded].includes(item.url))) {
758
593
  return {
759
594
  isNew: false,
760
595
  decoded
761
596
  };
762
597
  }
763
-
764
598
  return {
765
599
  isNew: true,
766
600
  decoded
767
601
  };
768
602
  }
769
-
770
603
  return {
771
604
  isNew: false,
772
605
  decoded: ''
773
606
  };
774
607
  };
775
-
776
608
  exports.isNewRegistryUrl = isNewRegistryUrl;
777
-
778
609
  const isBlockletDev = blocklet => blocklet.mode === _constant2.BLOCKLET_MODES.DEVELOPMENT;
779
-
780
610
  exports.isBlockletDev = isBlockletDev;
781
611
  const APP_PREFIX = ((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.groupPathPrefix) || '/';
782
612
  exports.APP_PREFIX = APP_PREFIX;