@abtnode/util 1.16.5 → 1.16.6-beta-4562aa60
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.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { slugify } = require('transliteration');
|
|
2
|
+
const { MAIN_CHAIN_ENDPOINT } = require('@abtnode/constant');
|
|
3
|
+
const { getChainClient } = require('./get-chain-client');
|
|
4
|
+
const { urlPathFriendly } = require('./url-path-friendly');
|
|
5
|
+
|
|
6
|
+
const ensureAccountOnMainChain = async (wallet, title) => {
|
|
7
|
+
const mainChainClient = getChainClient(MAIN_CHAIN_ENDPOINT);
|
|
8
|
+
const newResultOnMainChain = await mainChainClient.getAccountState({ address: wallet.address });
|
|
9
|
+
if (!newResultOnMainChain.state) {
|
|
10
|
+
const hash = await mainChainClient.declare({
|
|
11
|
+
moniker: (urlPathFriendly(slugify(title || 'application')) || 'application').toLowerCase(),
|
|
12
|
+
wallet,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return hash;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return '';
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
ensureAccountOnMainChain,
|
|
23
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const joinUrl = require('url-join');
|
|
2
|
+
const Client = require('@ocap/client');
|
|
3
|
+
|
|
4
|
+
// cache ocap clients for smaller memory consumption
|
|
5
|
+
const clients = new Map();
|
|
6
|
+
|
|
7
|
+
const getChainClient = (chainHost) => {
|
|
8
|
+
const endpoint = joinUrl(chainHost, '/');
|
|
9
|
+
if (!clients.has(endpoint)) {
|
|
10
|
+
const client = new Client(endpoint);
|
|
11
|
+
clients.set(endpoint, client);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return clients.get(endpoint);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
getChainClient,
|
|
19
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const isValidUrlPath = (name) => {
|
|
2
|
+
// Check if the path contains any uppercase letters
|
|
3
|
+
if (/[A-Z]/.test(name)) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Check if the path contains any non-ASCII characters
|
|
8
|
+
if (/[^\x20-\x7F]/.test(name)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Check if the resulting string matches the pattern of a valid URL path
|
|
13
|
+
const regex = /^[a-z0-9/\-._]*$/i;
|
|
14
|
+
return regex.test(name) && !name.includes('//');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const urlPathFriendly = (name, { keepSlash = true } = {}) => {
|
|
18
|
+
// Replace non-URL path friendly characters with hyphens
|
|
19
|
+
const pathFriendlyStr = name
|
|
20
|
+
.trim()
|
|
21
|
+
.replace(/[^\x20-\x7F]/g, '')
|
|
22
|
+
.replace(/[^a-z0-9_.\-/]/gi, '-')
|
|
23
|
+
.toLowerCase();
|
|
24
|
+
|
|
25
|
+
// Remove consecutive hyphens
|
|
26
|
+
const noConsecutiveHyphens = pathFriendlyStr.replace(/-+/g, '-');
|
|
27
|
+
|
|
28
|
+
// Replace consecutive periods with a single period
|
|
29
|
+
const result = noConsecutiveHyphens.replace(/\.+/g, '.');
|
|
30
|
+
|
|
31
|
+
// Remove consecutive slashes if keepSlash is true
|
|
32
|
+
const noConsecutiveSlashes = result.replace(/\/+/g, '/');
|
|
33
|
+
|
|
34
|
+
// Remove leading/trailing slashes if keepSlash is false
|
|
35
|
+
if (!keepSlash) {
|
|
36
|
+
return noConsecutiveSlashes.replace(/^\/|\/$/g, '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return noConsecutiveSlashes;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
isValidUrlPath,
|
|
44
|
+
urlPathFriendly,
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.6-beta-4562aa60",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.
|
|
22
|
-
"@abtnode/logger": "1.16.
|
|
23
|
-
"@arcblock/jwt": "1.18.
|
|
24
|
-
"@blocklet/constant": "1.16.
|
|
25
|
-
"@ocap/
|
|
26
|
-
"@ocap/
|
|
27
|
-
"@ocap/
|
|
21
|
+
"@abtnode/constant": "1.16.6-beta-4562aa60",
|
|
22
|
+
"@abtnode/logger": "1.16.6-beta-4562aa60",
|
|
23
|
+
"@arcblock/jwt": "1.18.72",
|
|
24
|
+
"@blocklet/constant": "1.16.6-beta-4562aa60",
|
|
25
|
+
"@ocap/client": "1.18.72",
|
|
26
|
+
"@ocap/mcrypto": "1.18.72",
|
|
27
|
+
"@ocap/util": "1.18.72",
|
|
28
|
+
"@ocap/wallet": "1.18.72",
|
|
28
29
|
"archiver": "^5.3.1",
|
|
29
30
|
"axios": "^0.27.2",
|
|
30
31
|
"axios-mock-adapter": "^1.21.2",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"through2-filter": "^3.0.0",
|
|
62
63
|
"through2-map": "^3.0.0",
|
|
63
64
|
"to-semver": "^3.0.0",
|
|
65
|
+
"transliteration": "^2.3.5",
|
|
64
66
|
"url-join": "^4.0.1",
|
|
65
67
|
"which": "^2.0.2"
|
|
66
68
|
},
|
|
@@ -71,5 +73,5 @@
|
|
|
71
73
|
"jest": "^27.5.1",
|
|
72
74
|
"unzipper": "^0.10.11"
|
|
73
75
|
},
|
|
74
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "e49856099ffc3c16eda77480a7ad93b2e9760764"
|
|
75
77
|
}
|