@metamask-previews/network-connection-banner-controller 0.1.0-preview-7507a11
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.
- package/CHANGELOG.md +14 -0
- package/LICENSE +20 -0
- package/README.md +18 -0
- package/dist/NetworkConnectionBannerController-method-action-types.cjs +7 -0
- package/dist/NetworkConnectionBannerController-method-action-types.cjs.map +1 -0
- package/dist/NetworkConnectionBannerController-method-action-types.d.cts +32 -0
- package/dist/NetworkConnectionBannerController-method-action-types.d.cts.map +1 -0
- package/dist/NetworkConnectionBannerController-method-action-types.d.mts +32 -0
- package/dist/NetworkConnectionBannerController-method-action-types.d.mts.map +1 -0
- package/dist/NetworkConnectionBannerController-method-action-types.mjs +6 -0
- package/dist/NetworkConnectionBannerController-method-action-types.mjs.map +1 -0
- package/dist/NetworkConnectionBannerController.cjs +288 -0
- package/dist/NetworkConnectionBannerController.cjs.map +1 -0
- package/dist/NetworkConnectionBannerController.d.cts +146 -0
- package/dist/NetworkConnectionBannerController.d.cts.map +1 -0
- package/dist/NetworkConnectionBannerController.d.mts +146 -0
- package/dist/NetworkConnectionBannerController.d.mts.map +1 -0
- package/dist/NetworkConnectionBannerController.mjs +283 -0
- package/dist/NetworkConnectionBannerController.mjs.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/url-utils.cjs +55 -0
- package/dist/url-utils.cjs.map +1 -0
- package/dist/url-utils.d.cts +24 -0
- package/dist/url-utils.d.cts.map +1 -0
- package/dist/url-utils.d.mts +24 -0
- package/dist/url-utils.d.mts.map +1 -0
- package/dist/url-utils.mjs +54 -0
- package/dist/url-utils.mjs.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a hostname is localhost or an IP address (v4 or v6). Public RPC
|
|
3
|
+
* providers use domain names, not raw IP addresses, so a `true` result means
|
|
4
|
+
* the host should not be reduced to an eTLD+1.
|
|
5
|
+
*
|
|
6
|
+
* @param hostname - The hostname to check.
|
|
7
|
+
* @returns True if the hostname is localhost or an IP address.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLocalhostOrIPAddress(hostname: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Registrable domain (eTLD+1) for a URL, computed via the Public Suffix List
|
|
12
|
+
* so multi-part suffixes like ".co.uk" resolve correctly. Used to group RPC
|
|
13
|
+
* endpoints by provider so a single provider's wide outage (e.g. *.infura.io)
|
|
14
|
+
* is treated as one failure rather than many.
|
|
15
|
+
*
|
|
16
|
+
* Localhost, IP literals, and single-label hosts are returned verbatim rather
|
|
17
|
+
* than reduced to a domain (psl returns null or garbage for those, and callers
|
|
18
|
+
* grouping by domain still need to distinguish them).
|
|
19
|
+
*
|
|
20
|
+
* @param urlString - The URL to extract a domain from.
|
|
21
|
+
* @returns The domain, or null if the URL is invalid.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDomain(urlString: string): string | null;
|
|
24
|
+
//# sourceMappingURL=url-utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-utils.d.mts","sourceRoot":"","sources":["../src/url-utils.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAe1D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import $ipRegex from "ip-regex/index.js";
|
|
8
|
+
const ipRegex = $importDefault($ipRegex);
|
|
9
|
+
import { get as pslGet } from "psl";
|
|
10
|
+
/**
|
|
11
|
+
* Check if a hostname is localhost or an IP address (v4 or v6). Public RPC
|
|
12
|
+
* providers use domain names, not raw IP addresses, so a `true` result means
|
|
13
|
+
* the host should not be reduced to an eTLD+1.
|
|
14
|
+
*
|
|
15
|
+
* @param hostname - The hostname to check.
|
|
16
|
+
* @returns True if the hostname is localhost or an IP address.
|
|
17
|
+
*/
|
|
18
|
+
export function isLocalhostOrIPAddress(hostname) {
|
|
19
|
+
const lowerHostname = hostname.toLowerCase();
|
|
20
|
+
if (lowerHostname === 'localhost') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Remove brackets from IPv6 addresses for testing (e.g., [::1] -> ::1)
|
|
24
|
+
const hostnameWithoutBrackets = lowerHostname.replace(/^\[|\]$/gu, '');
|
|
25
|
+
return ipRegex({ exact: true }).test(hostnameWithoutBrackets);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registrable domain (eTLD+1) for a URL, computed via the Public Suffix List
|
|
29
|
+
* so multi-part suffixes like ".co.uk" resolve correctly. Used to group RPC
|
|
30
|
+
* endpoints by provider so a single provider's wide outage (e.g. *.infura.io)
|
|
31
|
+
* is treated as one failure rather than many.
|
|
32
|
+
*
|
|
33
|
+
* Localhost, IP literals, and single-label hosts are returned verbatim rather
|
|
34
|
+
* than reduced to a domain (psl returns null or garbage for those, and callers
|
|
35
|
+
* grouping by domain still need to distinguish them).
|
|
36
|
+
*
|
|
37
|
+
* @param urlString - The URL to extract a domain from.
|
|
38
|
+
* @returns The domain, or null if the URL is invalid.
|
|
39
|
+
*/
|
|
40
|
+
export function getDomain(urlString) {
|
|
41
|
+
let url;
|
|
42
|
+
try {
|
|
43
|
+
url = new URL(urlString);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const { hostname } = url;
|
|
49
|
+
if (!hostname.includes('.') || isLocalhostOrIPAddress(hostname)) {
|
|
50
|
+
return hostname;
|
|
51
|
+
}
|
|
52
|
+
return pslGet(hostname) ?? hostname;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=url-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-utils.mjs","sourceRoot":"","sources":["../src/url-utils.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,QAAO,0BAAiB;;AAC/B,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,YAAY;AAEpC;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAE7C,IAAI,aAAa,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uEAAuE;IACvE,MAAM,uBAAuB,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEvE,OAAO,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,SAAiB;IACzC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC;IAEzB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;AACtC,CAAC","sourcesContent":["import ipRegex from 'ip-regex';\nimport { get as pslGet } from 'psl';\n\n/**\n * Check if a hostname is localhost or an IP address (v4 or v6). Public RPC\n * providers use domain names, not raw IP addresses, so a `true` result means\n * the host should not be reduced to an eTLD+1.\n *\n * @param hostname - The hostname to check.\n * @returns True if the hostname is localhost or an IP address.\n */\nexport function isLocalhostOrIPAddress(hostname: string): boolean {\n const lowerHostname = hostname.toLowerCase();\n\n if (lowerHostname === 'localhost') {\n return true;\n }\n\n // Remove brackets from IPv6 addresses for testing (e.g., [::1] -> ::1)\n const hostnameWithoutBrackets = lowerHostname.replace(/^\\[|\\]$/gu, '');\n\n return ipRegex({ exact: true }).test(hostnameWithoutBrackets);\n}\n\n/**\n * Registrable domain (eTLD+1) for a URL, computed via the Public Suffix List\n * so multi-part suffixes like \".co.uk\" resolve correctly. Used to group RPC\n * endpoints by provider so a single provider's wide outage (e.g. *.infura.io)\n * is treated as one failure rather than many.\n *\n * Localhost, IP literals, and single-label hosts are returned verbatim rather\n * than reduced to a domain (psl returns null or garbage for those, and callers\n * grouping by domain still need to distinguish them).\n *\n * @param urlString - The URL to extract a domain from.\n * @returns The domain, or null if the URL is invalid.\n */\nexport function getDomain(urlString: string): string | null {\n let url: URL;\n try {\n url = new URL(urlString);\n } catch {\n return null;\n }\n\n const { hostname } = url;\n\n if (!hostname.includes('.') || isLocalhostOrIPAddress(hostname)) {\n return hostname;\n }\n\n return pslGet(hostname) ?? hostname;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/network-connection-banner-controller",
|
|
3
|
+
"version": "0.1.0-preview-7507a11",
|
|
4
|
+
"description": "Decides when and how to surface the network connection banner based on RPC endpoint health",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ethereum",
|
|
7
|
+
"MetaMask"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/network-connection-banner-controller#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
43
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
44
|
+
"build:docs": "typedoc",
|
|
45
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/network-connection-banner-controller",
|
|
46
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/network-connection-banner-controller",
|
|
47
|
+
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
|
|
48
|
+
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
|
|
49
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
50
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
51
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
52
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
53
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@metamask/base-controller": "^9.1.0",
|
|
57
|
+
"@metamask/connectivity-controller": "^0.2.0",
|
|
58
|
+
"@metamask/messenger": "^1.2.0",
|
|
59
|
+
"@metamask/network-controller": "^32.0.0",
|
|
60
|
+
"@metamask/network-enablement-controller": "^5.3.0",
|
|
61
|
+
"@metamask/utils": "^11.9.0",
|
|
62
|
+
"ip-regex": "^4.3.0",
|
|
63
|
+
"psl": "^1.15.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@metamask/auto-changelog": "^6.1.0",
|
|
67
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
68
|
+
"@types/jest": "^29.5.14",
|
|
69
|
+
"deepmerge": "^4.2.2",
|
|
70
|
+
"jest": "^29.7.0",
|
|
71
|
+
"ts-jest": "^29.2.5",
|
|
72
|
+
"tsx": "^4.20.5",
|
|
73
|
+
"typedoc": "^0.25.13",
|
|
74
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
75
|
+
"typescript": "~5.3.3"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": "^18.18 || >=20"
|
|
79
|
+
}
|
|
80
|
+
}
|