@abtnode/ux 1.15.17 → 1.16.0-beta-b16cb035

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