@abtnode/ux 1.8.26 → 1.8.27

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 (62) hide show
  1. package/lib/actions.js +137 -0
  2. package/lib/blocklet/actions.js +501 -0
  3. package/lib/blocklet/audit-logs.js +226 -0
  4. package/lib/blocklet/avatar.js +123 -0
  5. package/lib/blocklet/blocklet-source.js +69 -0
  6. package/lib/blocklet/component/configuration.js +150 -0
  7. package/lib/blocklet/component/delete.js +138 -0
  8. package/lib/blocklet/component/environment.js +334 -0
  9. package/lib/blocklet/component/index.js +837 -0
  10. package/lib/blocklet/component/setting.js +174 -0
  11. package/lib/blocklet/configuration.js +531 -0
  12. package/lib/blocklet/disk-info.js +115 -0
  13. package/lib/blocklet/icons.js +36 -0
  14. package/lib/blocklet/log.js +70 -0
  15. package/lib/blocklet/mode.js +47 -0
  16. package/lib/blocklet/overview.js +218 -0
  17. package/lib/blocklet/runtime-info.js +111 -0
  18. package/lib/blocklet/status.js +125 -0
  19. package/lib/blocklet/util.js +141 -0
  20. package/lib/blocklet/version.js +216 -0
  21. package/lib/click-to-copy.js +51 -0
  22. package/lib/confirm.js +175 -0
  23. package/lib/contexts/audit-log.js +155 -0
  24. package/lib/contexts/deleting-blocklets.js +91 -0
  25. package/lib/contexts/node.js +34 -0
  26. package/lib/contexts/session.js +22 -0
  27. package/lib/contexts/team.js +22 -0
  28. package/lib/did-address.js +95 -0
  29. package/lib/dot.js +25 -0
  30. package/lib/hooks/mobile-width.js +24 -0
  31. package/lib/icons/long-arrow.svg +5 -0
  32. package/lib/locales/en.js +1046 -38
  33. package/lib/locales/zh.js +1049 -36
  34. package/lib/logs/clock.js +25 -0
  35. package/lib/logs/log-terminal.js +198 -0
  36. package/lib/passport-tag.js +58 -0
  37. package/lib/permission.js +84 -0
  38. package/lib/relative-time.js +74 -0
  39. package/lib/table-icons.js +59 -0
  40. package/lib/table.js +19 -0
  41. package/lib/tag.js +48 -0
  42. package/lib/team/members/actions.js +115 -0
  43. package/lib/team/members/index.js +544 -0
  44. package/lib/team/members/invitations.js +229 -0
  45. package/lib/team/members/invite-member.js +241 -0
  46. package/lib/team/members/issue-passport.js +178 -0
  47. package/lib/team/members/member.js +336 -0
  48. package/lib/team/members/passport-issuances.js +181 -0
  49. package/lib/team/members/passports.js +377 -0
  50. package/lib/team/members/toggle-user-approval.js +154 -0
  51. package/lib/team/members/transfer-node.js +295 -0
  52. package/lib/team/members/util.js +27 -0
  53. package/lib/team/passports/detail.js +304 -0
  54. package/lib/team/passports/index.js +256 -0
  55. package/lib/team/passports/mutate-role.js +230 -0
  56. package/lib/team/passports/trusted-issuer.js +339 -0
  57. package/lib/team/passports/trusted-issuers.js +284 -0
  58. package/lib/team/search-input.js +51 -0
  59. package/lib/team/styles/dialog.js +19 -0
  60. package/lib/team/styles/list-header.js +19 -0
  61. package/lib/util/index.js +642 -6
  62. package/package.json +32 -9
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _styled = _interopRequireDefault(require("@emotion/styled"));
9
+
10
+ var _templateObject;
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
15
+
16
+ const DialogStyle = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 632px;\n height: 90vh;\n overflow: auto;\n @media (max-width: ", "px) {\n width: 100%;\n height: 100%;\n }\n display: flex;\n flex-direction: column;\n\n .dialog-header {\n flex-shrink: 0;\n position: sticky;\n top: 0;\n background: #fff;\n z-index: 30;\n flex: 0;\n box-sizing: border-box;\n width: 100%;\n padding: 0 12px;\n min-height: 72px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-bottom: 1px solid #f8f8f8;\n .title {\n color: #222;\n font-size: 16px;\n }\n .left,\n .right {\n flex-shrink: 0;\n flex-basis: auto;\n width: 120px;\n }\n .right {\n text-align: right;\n svg {\n fill: #bfbfbf;\n }\n }\n }\n .dialog-content {\n flex-grow: 1;\n padding: 16px 24px;\n }\n .dialog-actions {\n flex-shrink: 0;\n border-top: 1px solid #f8f8f8;\n padding 24px;\n position: sticky;\n bottom: 0;\n z-index: 20;\n background: #fff;\n display: flex;\n justify-content: flex-end;\n .MuiButton-root {\n padding-left: 3em;\n padding-right: 3em;\n }\n }\n .dialog-h1 {\n font-style: normal;\n font-weight: 400;\n font-size: 24px;\n line-height: 28px;\n color: #222222;\n }\n"])), props => props.theme.breakpoints.values.md - 1);
17
+
18
+ var _default = DialogStyle;
19
+ exports.default = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _styled = _interopRequireDefault(require("@emotion/styled"));
9
+
10
+ var _templateObject;
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
15
+
16
+ const ListHeader = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: space-between;\n align-items: center;\n font-size: 14px;\n .left,\n .right {\n }\n .right {\n display: flex;\n align-items: center;\n }\n .tabs {\n .MuiButton-root {\n border: none;\n color: #999;\n &.active {\n color: #222;\n }\n }\n }\n\n @media (max-width: 600px) {\n display: block;\n .right {\n margin-top: 12px;\n }\n }\n"])));
17
+
18
+ var _default = ListHeader;
19
+ exports.default = _default;
package/lib/util/index.js CHANGED
@@ -3,17 +3,74 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.checkIsWildcardDomain = exports.checkInputByType = exports.appendParams = exports.BlockletAdminRoles = exports.APP_PREFIX = void 0;
7
+ exports.deepDecodeURIComponent = deepDecodeURIComponent;
8
+ exports.extractStatusUrlFromNextWorkflow = extractStatusUrlFromNextWorkflow;
6
9
  exports.formatDateTime = formatDateTime;
10
+ exports.formatError = exports.formatDiskSize = void 0;
11
+ exports.formatFactoryPrice = formatFactoryPrice;
12
+ exports.formatRegistryScreenshotPath = exports.formatRegistryLogoPath = exports.formatPerson = exports.formatLocale = void 0;
13
+ exports.formatTime = formatTime;
14
+ exports.formatTimeFromNow = formatTimeFromNow;
15
+ exports.formatTimestamp = formatTimestamp;
16
+ exports.formatToDate = formatToDate;
17
+ exports.formatToDatetime = formatToDatetime;
18
+ exports.formatUrl = void 0;
7
19
  exports.getAccessUrl = getAccessUrl;
20
+ exports.getAccessibleUrl = void 0;
21
+ exports.getAsset = getAsset;
22
+ exports.getAssetExpiration = getAssetExpiration;
23
+ exports.getBlockletLogoUrl = void 0;
24
+ exports.getBlockletMetaUrl = getBlockletMetaUrl;
25
+ exports.getEndPoint = exports.getBlockletUrlParams = exports.getBlockletServices = void 0;
8
26
  exports.getExplorerLink = getExplorerLink;
27
+ exports.getPathPrefix = exports.getIssuePassportLink = exports.getInviteLink = void 0;
28
+ exports.getRelativeTime = getRelativeTime;
29
+ exports.getWebWalletUrl = getWebWalletUrl;
30
+ exports.isNewRegistryUrl = exports.isInstalling = exports.isInProgress = exports.isDownloading = exports.isChrome = exports.isCertificateMatch = exports.isBlockletDev = void 0;
31
+ exports.isProtectedRole = isProtectedRole;
32
+ exports.isUrlAccessible = exports.isSafari = void 0;
33
+ exports.isValidClusterSize = isValidClusterSize;
34
+ exports.parseQuery = void 0;
9
35
  exports.patchJsxToLocale = patchJsxToLocale;
36
+ exports.shouldCheckDomainStatus = void 0;
10
37
  exports.sleep = sleep;
11
- exports.validateDomain = void 0;
38
+ exports.validateDomain = exports.stringSortHandlerAsc = void 0;
12
39
 
13
40
  var _constant = require("@abtnode/constant");
14
41
 
15
42
  var _dayjs = _interopRequireDefault(require("dayjs"));
16
43
 
44
+ require("moment/locale/zh-cn");
45
+
46
+ var _querystring = _interopRequireDefault(require("querystring"));
47
+
48
+ var _isUrl = _interopRequireDefault(require("is-url"));
49
+
50
+ var _moment = _interopRequireDefault(require("moment"));
51
+
52
+ var _humanizeUrl = _interopRequireDefault(require("humanize-url"));
53
+
54
+ var _filesize = _interopRequireDefault(require("filesize"));
55
+
56
+ var _urlJoin = _interopRequireDefault(require("url-join"));
57
+
58
+ var _get = _interopRequireDefault(require("lodash/get"));
59
+
60
+ var _last = _interopRequireDefault(require("lodash/last"));
61
+
62
+ var _trimEnd = _interopRequireDefault(require("lodash/trimEnd"));
63
+
64
+ var _constant2 = require("@blocklet/constant");
65
+
66
+ var _urlEvaluation = require("@abtnode/util/lib/url-evaluation");
67
+
68
+ var _checkAccessibleBrowser = _interopRequireDefault(require("@abtnode/util/lib/url-evaluation/check-accessible-browser"));
69
+
70
+ var _axios = _interopRequireDefault(require("@abtnode/util/lib/axios"));
71
+
72
+ var _window$env;
73
+
17
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
75
 
19
76
  function sleep(t) {
@@ -91,10 +148,6 @@ function getAccessUrl(hostname) {
91
148
  return "".concat(url, "?").concat(searchParams.toString());
92
149
  }
93
150
 
94
- function formatDateTime(date) {
95
- return (0, _dayjs.default)(date).format('YYYY-MM-DD HH:mm');
96
- }
97
-
98
151
  function getExplorerLink(chainHost, did, type) {
99
152
  if (!chainHost) return undefined;
100
153
 
@@ -145,4 +198,587 @@ function patchJsxToLocale(rawStr) {
145
198
 
146
199
  return item;
147
200
  }).filter(Boolean);
148
- }
201
+ }
202
+
203
+ function formatTimestamp(ts) {
204
+ if (!ts) {
205
+ return '-';
206
+ }
207
+
208
+ let date;
209
+
210
+ if (Number(ts).toString() === ts) {
211
+ date = new Date();
212
+ date.setTime(ts);
213
+ } else {
214
+ date = new Date(ts);
215
+ }
216
+
217
+ return date.toLocaleString();
218
+ }
219
+
220
+ function formatToDate(date) {
221
+ if (!date) {
222
+ return '-';
223
+ }
224
+
225
+ return (0, _moment.default)(date).format('ll');
226
+ }
227
+
228
+ function formatToDatetime(date) {
229
+ if (!date) {
230
+ return '-';
231
+ }
232
+
233
+ return (0, _moment.default)(date).format('lll');
234
+ }
235
+
236
+ function formatTimeFromNow(date) {
237
+ if (!date) {
238
+ return '-';
239
+ }
240
+
241
+ const startDate = (0, _moment.default)(date);
242
+ const endDate = (0, _moment.default)();
243
+ const diffDay = endDate.diff(startDate, 'day');
244
+ return diffDay > 3 ? formatToDate(date) : startDate.fromNow();
245
+ }
246
+
247
+ function formatTime(date) {
248
+ let format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'lll';
249
+
250
+ if (!date) {
251
+ return '-';
252
+ }
253
+
254
+ return (0, _moment.default)(date).format(format);
255
+ }
256
+
257
+ function formatDateTime(date) {
258
+ return (0, _dayjs.default)(date).format('YYYY-MM-DD HH:mm');
259
+ }
260
+
261
+ const formatError = error => {
262
+ if (Array.isArray(error.errors)) {
263
+ return error.errors.map(x => x.message).join('\n');
264
+ }
265
+
266
+ return error.message;
267
+ };
268
+
269
+ exports.formatError = formatError;
270
+
271
+ const formatLocale = function formatLocale() {
272
+ let locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'en';
273
+
274
+ if (locale === 'zh') {
275
+ return 'zh_CN';
276
+ }
277
+
278
+ return locale;
279
+ };
280
+
281
+ exports.formatLocale = formatLocale;
282
+
283
+ const parseQuery = str => str.replace(/^\?/, '').split('&').map(x => x.split('=')).filter(_ref => {
284
+ let [key] = _ref;
285
+ return !!key;
286
+ }).reduce((memo, x) => {
287
+ const key = x[0];
288
+ const value = decodeURIComponent(x[1]) || true;
289
+ memo[key] = value;
290
+ return memo;
291
+ }, {}); // Append any query string url to api requests
292
+
293
+
294
+ exports.parseQuery = parseQuery;
295
+
296
+ const appendParams = function appendParams(url) {
297
+ let extraParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
298
+ const [pathname, query = ''] = url.split('?');
299
+ const oldParams = parseQuery(query);
300
+ const params = Object.assign({}, oldParams, extraParams);
301
+ return "".concat(pathname, "?").concat(_querystring.default.stringify(params));
302
+ };
303
+
304
+ exports.appendParams = appendParams;
305
+
306
+ const isInProgress = status => ['waiting', 'downloading', 'starting', 'installing', 'stopping', 'upgrading', 'restarting', 'deleting'].includes(status);
307
+
308
+ exports.isInProgress = isInProgress;
309
+
310
+ const isInstalling = status => ['waiting', 'downloading', 'installing', 'upgrading'].includes(status);
311
+
312
+ exports.isInstalling = isInstalling;
313
+
314
+ const isDownloading = status => ['waiting', 'downloading'].includes(status);
315
+
316
+ exports.isDownloading = isDownloading;
317
+
318
+ const formatDiskSize = function formatDiskSize(size) {
319
+ let serverPlatform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
320
+ const base = serverPlatform === 'linux' ? 2 : 10;
321
+ return (0, _filesize.default)(size, {
322
+ base,
323
+ round: 2
324
+ });
325
+ };
326
+
327
+ exports.formatDiskSize = formatDiskSize;
328
+
329
+ const checkInputByType = (type, value) => {
330
+ const typesMap = {
331
+ url: _isUrl.default
332
+ };
333
+
334
+ if (!type) {
335
+ return true;
336
+ }
337
+
338
+ if (typesMap[type]) {
339
+ return typesMap[type](value);
340
+ }
341
+
342
+ return false;
343
+ };
344
+
345
+ exports.checkInputByType = checkInputByType;
346
+
347
+ const formatUrl = url => (0, _humanizeUrl.default)(url.split('?').shift());
348
+
349
+ exports.formatUrl = formatUrl;
350
+
351
+ const formatPerson = person => {
352
+ if (!person) {
353
+ return '-';
354
+ }
355
+
356
+ if (typeof person === 'string') {
357
+ return person;
358
+ }
359
+
360
+ const name = person.name || '';
361
+ const u = person.url || person.web;
362
+ const url = u ? " (".concat(u, ")") : '';
363
+ const e = person.email || person.mail;
364
+ const email = e ? " <".concat(e, ">") : '';
365
+ return name + email + url;
366
+ };
367
+
368
+ exports.formatPerson = formatPerson;
369
+
370
+ const getBlockletServices = blocklet => {
371
+ const services = [];
372
+ const interfaces = (blocklet.meta.interfaces || []).filter(x => x.type === _constant2.BLOCKLET_INTERFACE_TYPE_SERVICE);
373
+ interfaces.forEach(x => {
374
+ services.push({
375
+ name: x.name,
376
+ protocol: x.protocol,
377
+ port: Number(x.port.external),
378
+ upstreamPort: Number(blocklet.ports[x.port.internal])
379
+ });
380
+ });
381
+ return services;
382
+ };
383
+
384
+ exports.getBlockletServices = getBlockletServices;
385
+
386
+ const shouldCheckDomainStatus = domain => domain && // eslint-disable-line
387
+ ![_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
+ exports.shouldCheckDomainStatus = shouldCheckDomainStatus;
390
+
391
+ const checkIsWildcardDomain = url => {
392
+ try {
393
+ if (!url) {
394
+ return false;
395
+ }
396
+
397
+ const tempUrl = url.startsWith('http') ? url : "http://".concat(url);
398
+ const urlObj = new window.URL(tempUrl);
399
+ return decodeURIComponent(urlObj.host).split('.').some(x => x === '*');
400
+ } catch (error) {
401
+ console.error(url, error);
402
+ return false;
403
+ }
404
+ };
405
+
406
+ exports.checkIsWildcardDomain = checkIsWildcardDomain;
407
+
408
+ const stringSortHandlerAsc = function stringSortHandlerAsc() {
409
+ let strA = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
410
+ let strB = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
411
+
412
+ if (strA > strB) {
413
+ return 1;
414
+ }
415
+
416
+ if (strB > strA) {
417
+ return -1;
418
+ }
419
+
420
+ return 0;
421
+ };
422
+
423
+ exports.stringSortHandlerAsc = stringSortHandlerAsc;
424
+
425
+ const getEndPoint = nodeInfo => {
426
+ const {
427
+ routing
428
+ } = nodeInfo;
429
+ const {
430
+ protocol,
431
+ hostname,
432
+ origin,
433
+ port
434
+ } = window.location;
435
+ let endpoint = "".concat(origin).concat(routing.adminPath);
436
+
437
+ if (process.env.NODE_ENV === 'development') {
438
+ endpoint = "".concat(protocol, "//").concat(hostname, ":").concat(port);
439
+ }
440
+
441
+ return endpoint;
442
+ };
443
+
444
+ exports.getEndPoint = getEndPoint;
445
+
446
+ const getInviteLink = _ref2 => {
447
+ let {
448
+ inviteId,
449
+ endpoint
450
+ } = _ref2;
451
+
452
+ if (!endpoint) {
453
+ return '';
454
+ }
455
+
456
+ const u = new URL(endpoint);
457
+ u.pathname = (0, _urlJoin.default)(u.pathname, _constant.WELLKNOWN_SERVICE_PATH_PREFIX, 'invite');
458
+ u.searchParams.set('inviteId', inviteId);
459
+ return u.href;
460
+ };
461
+
462
+ exports.getInviteLink = getInviteLink;
463
+
464
+ const getIssuePassportLink = _ref3 => {
465
+ let {
466
+ id,
467
+ endpoint
468
+ } = _ref3;
469
+
470
+ if (!endpoint) {
471
+ return '';
472
+ }
473
+
474
+ const u = new URL(endpoint);
475
+ u.pathname = (0, _urlJoin.default)(u.pathname, _constant.WELLKNOWN_SERVICE_PATH_PREFIX, 'issue-passport');
476
+ u.searchParams.set('id', id);
477
+ return u.href;
478
+ };
479
+
480
+ exports.getIssuePassportLink = getIssuePassportLink;
481
+
482
+ const formatRegistryScreenshotPath = (did, asset) => {
483
+ if (asset.startsWith('/assets')) {
484
+ return asset;
485
+ }
486
+
487
+ return "/assets/".concat(did, "/screenshots/").concat(asset);
488
+ };
489
+
490
+ exports.formatRegistryScreenshotPath = formatRegistryScreenshotPath;
491
+
492
+ const formatRegistryLogoPath = (did, asset) => {
493
+ if (asset.startsWith('/assets')) {
494
+ return asset;
495
+ }
496
+
497
+ return "/assets/".concat(did, "/").concat(asset);
498
+ };
499
+
500
+ exports.formatRegistryLogoPath = formatRegistryLogoPath;
501
+
502
+ function getWebWalletUrl(info) {
503
+ try {
504
+ const url = window.localStorage.getItem('wallet_url');
505
+
506
+ if (url) {
507
+ return url;
508
+ }
509
+ } catch (err) {// Do nothing
510
+ }
511
+
512
+ return info && info.webWalletUrl ? info.webWalletUrl : '';
513
+ }
514
+
515
+ function isValidClusterSize(data) {
516
+ const {
517
+ value,
518
+ cpuCores
519
+ } = data;
520
+
521
+ if (!value) {
522
+ return '';
523
+ }
524
+
525
+ const v = Number(value);
526
+
527
+ if (Number.isNaN(v)) {
528
+ return 'Cluster size should be a number';
529
+ }
530
+
531
+ if (!Number.isInteger(v)) {
532
+ return 'Cluster size should be integer';
533
+ }
534
+
535
+ if (v <= 0 || v > cpuCores) {
536
+ return "Cluster size should between 1 to ".concat(cpuCores);
537
+ }
538
+
539
+ return '';
540
+ }
541
+
542
+ function isProtectedRole(role) {
543
+ return Object.values(_constant.ROLES).includes(role);
544
+ }
545
+
546
+ function formatFactoryPrice(blocklet) {
547
+ var _blocklet$payment;
548
+
549
+ if (!(blocklet !== null && blocklet !== void 0 && blocklet.payment)) {
550
+ return [];
551
+ }
552
+
553
+ const list = (((_blocklet$payment = blocklet.payment) === null || _blocklet$payment === void 0 ? void 0 : _blocklet$payment.price) || []).map(item => ({
554
+ name: item.symbol,
555
+ value: item.value
556
+ }));
557
+ return list;
558
+ }
559
+
560
+ const getBlockletLogoUrl = _ref4 => {
561
+ let {
562
+ did,
563
+ baseUrl,
564
+ logoPath
565
+ } = _ref4;
566
+
567
+ if (baseUrl.startsWith('http') && logoPath) {
568
+ return (0, _urlJoin.default)(baseUrl, formatRegistryLogoPath(did, logoPath));
569
+ }
570
+
571
+ const prefix = window.env.apiPrefix || '/';
572
+ let apiPrefix = prefix.replace(/^\/+/, '').replace(/\/+$/, '');
573
+
574
+ if (apiPrefix) {
575
+ apiPrefix = "/".concat(apiPrefix);
576
+ }
577
+
578
+ return (0, _urlJoin.default)(apiPrefix, "/blocklet/logo/".concat(did));
579
+ };
580
+
581
+ exports.getBlockletLogoUrl = getBlockletLogoUrl;
582
+
583
+ const getPathPrefix = () => window.env && window.env.apiPrefix ? window.env.apiPrefix : '/';
584
+
585
+ exports.getPathPrefix = getPathPrefix;
586
+
587
+ const isUrlAccessible = async url => (0, _checkAccessibleBrowser.default)((0, _urlJoin.default)(new URL(url).origin, _constant.WELLKNOWN_PING_PREFIX));
588
+
589
+ exports.isUrlAccessible = isUrlAccessible;
590
+
591
+ const getAccessibleUrl = async urls => {
592
+ try {
593
+ const res = await (0, _urlEvaluation.evaluateURLs)(urls);
594
+ return res[0].url;
595
+ } catch (error) {
596
+ console.warn('get accessible url failed');
597
+ return '';
598
+ }
599
+ };
600
+ /**
601
+ * 检查证书是否与 blocklet 匹配
602
+ * @param {string[]} blockletUrls - 通过 blocklet#interfaces#url 获取到的一组 url
603
+ * @param {object[]} matchedSites - 通过 certificate#matchedSites 获取到的一组 site
604
+ * @returns {boolean} - 匹配则返回 true
605
+ */
606
+
607
+
608
+ exports.getAccessibleUrl = getAccessibleUrl;
609
+
610
+ const isCertificateMatch = function isCertificateMatch() {
611
+ let blockletUrls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
612
+ let matchedSites = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
613
+
614
+ try {
615
+ return matchedSites.map(item => item.domain).some(domain => {
616
+ return blockletUrls.some(blockletUrl => {
617
+ const url = new window.URL(blockletUrl);
618
+ return url.hostname === domain;
619
+ });
620
+ });
621
+ } catch (e) {
622
+ console.warn('domain match failed');
623
+ return false;
624
+ }
625
+ };
626
+
627
+ exports.isCertificateMatch = isCertificateMatch;
628
+
629
+ const getBlockletUrlParams = (blocklet, locale) => (blocklet || {}).status === 'running' ? {
630
+ locale
631
+ } : {
632
+ locale,
633
+ __start__: 1
634
+ };
635
+ /**
636
+ * 判断是否在safari浏览器中
637
+ * 不传的ua情况下,使用当前页面的ua
638
+ * chrome浏览器的ua也会带有 Safari 字样,所以要排除 Chrome 字符串
639
+ * iPhone 设备下,所有浏览器都是 safari 的 webkit
640
+ * @param {String} ua userAgent 字符串
641
+ * @returns bool
642
+ */
643
+
644
+
645
+ exports.getBlockletUrlParams = getBlockletUrlParams;
646
+
647
+ const isSafari = function isSafari() {
648
+ let ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
649
+ return ua.includes('iPhone') || ua.includes('Safari') && !ua.includes('Chrome');
650
+ };
651
+
652
+ exports.isSafari = isSafari;
653
+
654
+ const isChrome = function isChrome() {
655
+ let ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
656
+ return ua.includes('Chrome');
657
+ };
658
+ /**
659
+ *
660
+ * @export
661
+ * @param {string} url
662
+ * @return {string}
663
+ */
664
+
665
+
666
+ exports.isChrome = isChrome;
667
+
668
+ function deepDecodeURIComponent(url) {
669
+ let lastDecodeUrl = decodeURIComponent(url);
670
+
671
+ while (lastDecodeUrl !== decodeURIComponent(lastDecodeUrl)) {
672
+ lastDecodeUrl = decodeURIComponent(lastDecodeUrl);
673
+ }
674
+
675
+ return lastDecodeUrl;
676
+ }
677
+ /**
678
+ *
679
+ * @description 已知nextWorkflow的地址,提取它的statusUrl和token
680
+ * @export
681
+ * @param {string} nextWorkflow
682
+ * @returns {{
683
+ * statusUrl: string;
684
+ * token: string;
685
+ * }}
686
+ */
687
+
688
+
689
+ function extractStatusUrlFromNextWorkflow(nextWorkflow) {
690
+ const nextWorkflowURL = new URL(deepDecodeURIComponent(nextWorkflow)).searchParams.get('url');
691
+ return {
692
+ statusUrl: nextWorkflowURL.replace('/auth?', '/status?'),
693
+ token: new URL(nextWorkflowURL).searchParams.get('_t_')
694
+ };
695
+ }
696
+
697
+ function getBlockletMetaUrl(registry, did) {
698
+ return (0, _urlJoin.default)(registry, "/api/blocklets/".concat(did, "/blocklet.json?source=webapp"));
699
+ }
700
+
701
+ async function getAsset(chainHost, address) {
702
+ const result = await _axios.default.post((0, _urlJoin.default)(chainHost, '/api/gql/'), JSON.stringify({
703
+ 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 }")
704
+ }), {
705
+ headers: {
706
+ 'Content-Type': 'application/json',
707
+ Accept: 'application/json'
708
+ },
709
+ timeout: 60 * 1000
710
+ });
711
+ const state = (0, _get.default)(result.data, 'data.getAssetState.state');
712
+
713
+ if (state && state.data.typeUrl === 'json') {
714
+ state.data.value = JSON.parse(state.data.value);
715
+ }
716
+
717
+ return state;
718
+ }
719
+
720
+ async function getAssetExpiration(chainHost, address) {
721
+ const asset = await getAsset(chainHost, address);
722
+ return (0, _last.default)((0, _get.default)(asset, 'data.value.expirationDate', []));
723
+ }
724
+
725
+ function getRelativeTime(datetime) {
726
+ let locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
727
+ return (0, _moment.default)(datetime).locale(formatLocale(locale)).fromNow().toString();
728
+ }
729
+ /**
730
+ * 检查url是否 未添加到 store registryList 中
731
+ * @param {string} url - 需要检查的url
732
+ * @param {object[]} blockletRegistryList - 后端的store registryList, 一般是 info.blockletRegistryList
733
+ * @returns {Object.freeze({
734
+ * isNew: boolean;
735
+ * decoded: string;
736
+ * })} - 返回判断是否是新的url和解码后的url
737
+ */
738
+
739
+
740
+ const isNewRegistryUrl = (url, blockletRegistryList) => {
741
+ if (typeof url === 'string') {
742
+ let decoded = decodeURIComponent(url === null || url === void 0 ? void 0 : url.trim());
743
+ const regex = /^https?:\/\//;
744
+
745
+ if (!regex.test(decoded)) {
746
+ decoded = "https://".concat(decoded);
747
+ }
748
+
749
+ decoded = (0, _trimEnd.default)(decoded, '/'); // validate
750
+
751
+ try {
752
+ new URL(decoded); // eslint-disable-line no-new
753
+ } catch (_unused2) {
754
+ throw new Error('Invalid Blocklet Store URL');
755
+ }
756
+
757
+ if (blockletRegistryList !== null && blockletRegistryList !== void 0 && blockletRegistryList.some(item => [url, decoded].includes(item.url))) {
758
+ return {
759
+ isNew: false,
760
+ decoded
761
+ };
762
+ }
763
+
764
+ return {
765
+ isNew: true,
766
+ decoded
767
+ };
768
+ }
769
+
770
+ return {
771
+ isNew: false,
772
+ decoded: ''
773
+ };
774
+ };
775
+
776
+ exports.isNewRegistryUrl = isNewRegistryUrl;
777
+
778
+ const isBlockletDev = blocklet => blocklet.mode === _constant2.BLOCKLET_MODES.DEVELOPMENT;
779
+
780
+ exports.isBlockletDev = isBlockletDev;
781
+ const APP_PREFIX = ((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.groupPathPrefix) || '/';
782
+ exports.APP_PREFIX = APP_PREFIX;
783
+ const BlockletAdminRoles = [_constant.ROLES.ADMIN, _constant.ROLES.OWNER];
784
+ exports.BlockletAdminRoles = BlockletAdminRoles;