@tgwf/co2 0.9.0 → 0.10.0
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/.esbuild.browser.js +11 -0
- package/.esbuild.esm.js +25 -0
- package/.esbuild.node.js +16 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +13 -2
- package/README.md +6 -8
- package/dist/cjs/1byte.js +52 -0
- package/dist/cjs/1byte.js.map +7 -0
- package/dist/cjs/1byte.test.js +27 -0
- package/dist/cjs/1byte.test.js.map +7 -0
- package/dist/cjs/co2.js +116 -0
- package/dist/cjs/co2.js.map +7 -0
- package/dist/cjs/co2.test.js +244 -0
- package/dist/cjs/co2.test.js.map +7 -0
- package/dist/cjs/constants/file-size.js +27 -0
- package/dist/cjs/constants/file-size.js.map +7 -0
- package/dist/cjs/constants/index.js +27 -0
- package/dist/cjs/constants/index.js.map +7 -0
- package/dist/cjs/helpers/index.js +24 -0
- package/dist/cjs/helpers/index.js.map +7 -0
- package/dist/cjs/hosting-api.js +64 -0
- package/dist/cjs/hosting-api.js.map +7 -0
- package/dist/cjs/hosting-api.test.js +47 -0
- package/dist/cjs/hosting-api.test.js.map +7 -0
- package/dist/cjs/hosting-database.node.test.js +36 -0
- package/dist/cjs/hosting-database.node.test.js.map +7 -0
- package/dist/cjs/hosting-json.node.js +73 -0
- package/dist/cjs/hosting-json.node.js.map +7 -0
- package/dist/cjs/hosting-json.node.test.js +43 -0
- package/dist/cjs/hosting-json.node.test.js.map +7 -0
- package/dist/cjs/hosting-node.js +78 -0
- package/dist/cjs/hosting-node.js.map +7 -0
- package/dist/cjs/hosting.js +36 -0
- package/dist/cjs/hosting.js.map +7 -0
- package/dist/cjs/hosting.test.js +74 -0
- package/dist/cjs/hosting.test.js.map +7 -0
- package/dist/cjs/index-node.js +29 -0
- package/dist/cjs/index-node.js.map +7 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sustainable-web-design.js +151 -0
- package/dist/cjs/sustainable-web-design.js.map +7 -0
- package/dist/cjs/sustainable-web-design.test.js +85 -0
- package/dist/cjs/sustainable-web-design.test.js.map +7 -0
- package/dist/esm/1byte.js +32 -0
- package/dist/esm/1byte.test.js +11 -0
- package/dist/esm/co2.js +93 -0
- package/{src → dist/esm}/co2.test.js +27 -88
- package/dist/esm/constants/file-size.js +7 -0
- package/dist/esm/constants/index.js +4 -0
- package/dist/esm/helpers/index.js +4 -0
- package/dist/esm/hosting-api.js +41 -0
- package/dist/esm/hosting-api.test.js +31 -0
- package/{src/hosting-database.test.js → dist/esm/hosting-database.node.test.js} +7 -18
- package/{src/hosting-json.test.js → dist/esm/hosting-json.node.test.js} +4 -21
- package/dist/esm/hosting.js +13 -0
- package/{src → dist/esm}/hosting.test.js +10 -30
- package/dist/esm/index.js +8 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/sustainable-web-design.js +128 -0
- package/{src → dist/esm}/sustainable-web-design.test.js +25 -37
- package/fixup +19 -0
- package/package.json +37 -17
- package/public/index.html +57 -0
- package/public/index.js +2 -0
- package/public/index.js.map +7 -0
- package/src/1byte.js +2 -3
- package/src/co2.js +9 -17
- package/src/constants/file-size.js +1 -1
- package/src/constants/index.js +2 -2
- package/src/helpers/index.js +1 -3
- package/src/hosting-api.js +23 -43
- package/src/{hosting-json.js → hosting-json.node.js} +9 -11
- package/src/hosting-node.js +94 -0
- package/src/hosting.js +6 -28
- package/src/index-node.js +4 -0
- package/src/index.js +4 -6
- package/src/sustainable-web-design.js +79 -11
- package/.eslintrc.json +0 -21
- package/.github/workflows/unittests.yml +0 -26
- package/data/Lean-ICT-Materials-1byte-Model-2018.xlsx +0 -0
- package/data/Lean-ICT-Materials-Forecast-Model-2018.xlsx +0 -0
- package/data/fixtures/tgwf.har +0 -6107
- package/data/fixtures/url2green.test.db +0 -0
- package/data/fixtures/url2green.test.json +0 -1
- package/data/fixtures/url2green.test.json.gz +0 -0
- package/images/swd-energy-usage.png +0 -0
- package/src/1byte.test.js +0 -17
- package/src/green-byte.js +0 -26
- package/src/hosting-api.test.js +0 -37
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var file_size_exports = {};
|
|
19
|
+
__export(file_size_exports, {
|
|
20
|
+
default: () => file_size_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(file_size_exports);
|
|
23
|
+
const GIGABYTE = 1024 * 1024 * 1024;
|
|
24
|
+
var file_size_default = {
|
|
25
|
+
GIGABYTE
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=file-size.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/constants/file-size.js"],
|
|
4
|
+
"sourcesContent": ["const GIGABYTE = 1024 * 1024 * 1024;\n\nexport default {\n GIGABYTE,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,WAAW,OAAO,OAAO;AAE/B,IAAO,oBAAQ;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var constants_exports = {};
|
|
22
|
+
__export(constants_exports, {
|
|
23
|
+
fileSize: () => import_file_size.default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constants_exports);
|
|
26
|
+
var import_file_size = __toESM(require("./file-size.js"));
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var helpers_exports = {};
|
|
19
|
+
__export(helpers_exports, {
|
|
20
|
+
formatNumber: () => formatNumber
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
23
|
+
const formatNumber = (num) => parseFloat(num.toFixed(2));
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/index.js"],
|
|
4
|
+
"sourcesContent": ["const formatNumber = (num) => parseFloat(num.toFixed(2));\n\nexport { formatNumber };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,eAAe,CAAC,QAAQ,WAAW,IAAI,QAAQ,CAAC,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var hosting_api_exports = {};
|
|
23
|
+
__export(hosting_api_exports, {
|
|
24
|
+
default: () => hosting_api_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hosting_api_exports);
|
|
27
|
+
var import_debug = __toESM(require("debug"));
|
|
28
|
+
const log = (0, import_debug.default)("tgwf:hostingAPI");
|
|
29
|
+
function check(domain) {
|
|
30
|
+
if (typeof domain === "string") {
|
|
31
|
+
return checkAgainstAPI(domain);
|
|
32
|
+
} else {
|
|
33
|
+
return checkDomainsAgainstAPI(domain);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function checkAgainstAPI(domain) {
|
|
37
|
+
const req = await fetch(`https://api.thegreenwebfoundation.org/greencheck/${domain}`);
|
|
38
|
+
const res = await req.json();
|
|
39
|
+
return res.green;
|
|
40
|
+
}
|
|
41
|
+
async function checkDomainsAgainstAPI(domains) {
|
|
42
|
+
try {
|
|
43
|
+
const apiPath = "https://api.thegreenwebfoundation.org/v2/greencheckmulti";
|
|
44
|
+
const domainsString = JSON.stringify(domains);
|
|
45
|
+
const req = await fetch(`${apiPath}/${domainsString}`);
|
|
46
|
+
log(`${apiPath}/${domainsString}`);
|
|
47
|
+
log({ req });
|
|
48
|
+
const textResult = await req.text();
|
|
49
|
+
log({ textResult });
|
|
50
|
+
const allGreenCheckResults = await req.json();
|
|
51
|
+
return greenDomainsFromResults(allGreenCheckResults);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function greenDomainsFromResults(greenResults) {
|
|
57
|
+
const entries = Object.entries(greenResults);
|
|
58
|
+
const greenEntries = entries.filter(([key, val]) => val.green);
|
|
59
|
+
return greenEntries.map(([key, val]) => val.url);
|
|
60
|
+
}
|
|
61
|
+
var hosting_api_default = {
|
|
62
|
+
check
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=hosting-api.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-api.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hostingAPI\");\n\nfunction check(domain) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain);\n } else {\n return checkDomainsAgainstAPI(domain);\n }\n}\n\nasync function checkAgainstAPI(domain) {\n const req = await fetch(\n `https://api.thegreenwebfoundation.org/greencheck/${domain}`\n );\n const res = await req.json();\n return res.green;\n}\n\nasync function checkDomainsAgainstAPI(domains) {\n try {\n const apiPath = \"https://api.thegreenwebfoundation.org/v2/greencheckmulti\";\n const domainsString = JSON.stringify(domains);\n\n const req = await fetch(`${apiPath}/${domainsString}`);\n\n // sanity check API result. Is this the library or\n // the actual API request that's the problem?\n // Is nock mocking node-native fetch API calls properly?\n log(`${apiPath}/${domainsString}`);\n log({ req });\n const textResult = await req.text();\n log({ textResult });\n\n const allGreenCheckResults = await req.json();\n\n return greenDomainsFromResults(allGreenCheckResults);\n } catch (e) {\n return [];\n }\n}\n\nfunction greenDomainsFromResults(greenResults) {\n const entries = Object.entries(greenResults);\n const greenEntries = entries.filter(([key, val]) => val.green);\n return greenEntries.map(([key, val]) => val.url);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAyB;AACzB,MAAM,MAAM,0BAAa,iBAAiB;AAE1C,eAAe,QAAQ;AAErB,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,gBAAgB,MAAM;AAAA,EAC/B,OAAO;AACL,WAAO,uBAAuB,MAAM;AAAA,EACtC;AACF;AAEA,+BAA+B,QAAQ;AACrC,QAAM,MAAM,MAAM,MAChB,oDAAoD,QACtD;AACA,QAAM,MAAM,MAAM,IAAI,KAAK;AAC3B,SAAO,IAAI;AACb;AAEA,sCAAsC,SAAS;AAC7C,MAAI;AACF,UAAM,UAAU;AAChB,UAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,UAAM,MAAM,MAAM,MAAM,GAAG,WAAW,eAAe;AAKrD,QAAI,GAAG,WAAW,eAAe;AACjC,QAAI,EAAE,IAAI,CAAC;AACX,UAAM,aAAa,MAAM,IAAI,KAAK;AAClC,QAAI,EAAE,WAAW,CAAC;AAElB,UAAM,uBAAuB,MAAM,IAAI,KAAK;AAE5C,WAAO,wBAAwB,oBAAoB;AAAA,EACrD,SAAS,GAAP;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAEA,iCAAiC,cAAc;AAC7C,QAAM,UAAU,OAAO,QAAQ,YAAY;AAC3C,QAAM,eAAe,QAAQ,OAAO,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK;AAC7D,SAAO,aAAa,IAAI,CAAC,CAAC,KAAK,SAAS,IAAI,GAAG;AACjD;AAEA,IAAO,sBAAQ;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
|
+
var import_hosting_node = __toESM(require("./hosting-node.js"));
|
|
18
|
+
var import_nock = __toESM(require("nock"));
|
|
19
|
+
describe("hostingAPI", () => {
|
|
20
|
+
describe("checking a single domain with #check", () => {
|
|
21
|
+
it.skip("using the API", async () => {
|
|
22
|
+
const scope = (0, import_nock.default)("https://api.thegreenwebfoundation.org/").get("/greencheck/google.com").reply(200, {
|
|
23
|
+
url: "google.com",
|
|
24
|
+
green: true
|
|
25
|
+
});
|
|
26
|
+
const res = await import_hosting_node.default.check("google.com");
|
|
27
|
+
expect(res).toEqual(true);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("implicitly checking multiple domains with #check", () => {
|
|
31
|
+
it.skip("using the API", async () => {
|
|
32
|
+
const scope = (0, import_nock.default)("https://api.thegreenwebfoundation.org/").get("/v2/greencheckmulti/[%22google.com%22,%22kochindustries.com%22]").reply(200, {
|
|
33
|
+
"google.com": {
|
|
34
|
+
url: "google.com",
|
|
35
|
+
green: true
|
|
36
|
+
},
|
|
37
|
+
"kochindustries.com": {
|
|
38
|
+
url: "kochindustries.com",
|
|
39
|
+
green: null
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const res = await import_hosting_node.default.check(["google.com", "kochindustries.com"]);
|
|
43
|
+
expect(res).toContain("google.com");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=hosting-api.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-api.test.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport hosting from \"./hosting-node.js\";\nimport nock from \"nock\";\n/* eslint-disable jest/no-disabled-tests */\ndescribe(\"hostingAPI\", () => {\n describe(\"checking a single domain with #check\", () => {\n it.skip(\"using the API\", async () => {\n const scope = nock(\"https://api.thegreenwebfoundation.org/\")\n .get(\"/greencheck/google.com\")\n .reply(200, {\n url: \"google.com\",\n green: true,\n });\n const res = await hosting.check(\"google.com\");\n expect(res).toEqual(true);\n });\n });\n describe(\"implicitly checking multiple domains with #check\", () => {\n it.skip(\"using the API\", async () => {\n const scope = nock(\"https://api.thegreenwebfoundation.org/\")\n .get(\"/v2/greencheckmulti/[%22google.com%22,%22kochindustries.com%22]\")\n .reply(200, {\n \"google.com\": {\n url: \"google.com\",\n green: true,\n },\n \"kochindustries.com\": {\n url: \"kochindustries.com\",\n green: null,\n },\n });\n const res = await hosting.check([\"google.com\", \"kochindustries.com\"]);\n expect(res).toContain(\"google.com\");\n });\n });\n});\n/* eslint-enable jest/no-disabled-tests */\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,0BAAoB;AACpB,kBAAiB;AAEjB,SAAS,cAAc,MAAM;AAC3B,WAAS,wCAAwC,MAAM;AACrD,OAAG,KAAK,iBAAiB,YAAY;AACnC,YAAM,QAAQ,yBAAK,wCAAwC,EACxD,IAAI,wBAAwB,EAC5B,MAAM,KAAK;AAAA,QACV,KAAK;AAAA,QACL,OAAO;AAAA,MACT,CAAC;AACH,YAAM,MAAM,MAAM,4BAAQ,MAAM,YAAY;AAC5C,aAAO,GAAG,EAAE,QAAQ,IAAI;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC;AACD,WAAS,oDAAoD,MAAM;AACjE,OAAG,KAAK,iBAAiB,YAAY;AACnC,YAAM,QAAQ,yBAAK,wCAAwC,EACxD,IAAI,iEAAiE,EACrE,MAAM,KAAK;AAAA,QACV,cAAc;AAAA,UACZ,KAAK;AAAA,UACL,OAAO;AAAA,QACT;AAAA,QACA,sBAAsB;AAAA,UACpB,KAAK;AAAA,UACL,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AACH,YAAM,MAAM,MAAM,4BAAQ,MAAM,CAAC,cAAc,oBAAoB,CAAC;AACpE,aAAO,GAAG,EAAE,UAAU,YAAY;AAAA,IACpC,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
|
+
var import_path = __toESM(require("path"));
|
|
18
|
+
var import_debug = __toESM(require("debug"));
|
|
19
|
+
var import_url2green = require("@tgwf/url2green");
|
|
20
|
+
const log = (0, import_debug.default)("tgwf:url2green:test");
|
|
21
|
+
const dbPath = import_path.default.resolve(__dirname, "..", "data", "fixtures", "url2green.test.db");
|
|
22
|
+
describe("hostingDatabase", () => {
|
|
23
|
+
describe("checking a single domain with #check", () => {
|
|
24
|
+
test("tries to use a local database if available", async () => {
|
|
25
|
+
const res = await import_url2green.hosting.check("google.com", dbPath);
|
|
26
|
+
expect(res).toEqual(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("implicitly checking multiple domains with #check", () => {
|
|
30
|
+
test("tries to use a local database if available", async () => {
|
|
31
|
+
const res = await import_url2green.hosting.check(["google.com", "kochindustries.com"], dbPath);
|
|
32
|
+
expect(res).toContain("google.com");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=hosting-database.node.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-database.node.test.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport path from \"path\";\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:url2green:test\");\n\nimport { hosting } from \"@tgwf/url2green\";\n\nconst dbPath = path.resolve(\n __dirname,\n \"..\",\n \"data\",\n \"fixtures\",\n \"url2green.test.db\"\n);\n\ndescribe(\"hostingDatabase\", () => {\n describe(\"checking a single domain with #check\", () => {\n test(\"tries to use a local database if available\", async () => {\n const res = await hosting.check(\"google.com\", dbPath);\n expect(res).toEqual(true);\n });\n });\n describe(\"implicitly checking multiple domains with #check\", () => {\n test(\"tries to use a local database if available\", async () => {\n const res = await hosting.check(\n [\"google.com\", \"kochindustries.com\"],\n dbPath\n );\n expect(res).toContain(\"google.com\");\n });\n });\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,kBAAiB;AAEjB,mBAAyB;AAGzB,uBAAwB;AAFxB,MAAM,MAAM,0BAAa,qBAAqB;AAI9C,MAAM,SAAS,oBAAK,QAClB,WACA,MACA,QACA,YACA,mBACF;AAEA,SAAS,mBAAmB,MAAM;AAChC,WAAS,wCAAwC,MAAM;AACrD,SAAK,8CAA8C,YAAY;AAC7D,YAAM,MAAM,MAAM,yBAAQ,MAAM,cAAc,MAAM;AACpD,aAAO,GAAG,EAAE,QAAQ,IAAI;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC;AACD,WAAS,oDAAoD,MAAM;AACjE,SAAK,8CAA8C,YAAY;AAC7D,YAAM,MAAM,MAAM,yBAAQ,MACxB,CAAC,cAAc,oBAAoB,GACnC,MACF;AACA,aAAO,GAAG,EAAE,UAAU,YAAY;AAAA,IACpC,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
|
+
var import_fs = __toESM(require("fs"));
|
|
18
|
+
var import_zlib = __toESM(require("zlib"));
|
|
19
|
+
var import_util = require("util");
|
|
20
|
+
var import_debug = __toESM(require("debug"));
|
|
21
|
+
const readFile = (0, import_util.promisify)(import_fs.default.readFile);
|
|
22
|
+
const gunzip = (0, import_util.promisify)(import_zlib.default.gunzip);
|
|
23
|
+
const log = (0, import_debug.default)("tgwf:hostingCache");
|
|
24
|
+
async function streamToString(stream) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
stream.on("error", reject);
|
|
28
|
+
stream.on("data", (chunk) => chunks.push(chunk));
|
|
29
|
+
stream.on("end", () => resolve(Buffer.concat(chunks)));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function getGzippedFileAsJson(jsonPath) {
|
|
33
|
+
const readStream = import_fs.default.createReadStream(jsonPath);
|
|
34
|
+
const text = await streamToString(readStream);
|
|
35
|
+
const unzipped = await gunzip(text);
|
|
36
|
+
return unzipped.toString();
|
|
37
|
+
}
|
|
38
|
+
async function loadJSON(jsonPath) {
|
|
39
|
+
const jsonBuffer = jsonPath.endsWith(".gz") ? await getGzippedFileAsJson(jsonPath) : await readFile(jsonPath);
|
|
40
|
+
return JSON.parse(jsonBuffer);
|
|
41
|
+
}
|
|
42
|
+
async function check(domain, db) {
|
|
43
|
+
if (typeof domain === "string") {
|
|
44
|
+
return checkInJSON(domain, db);
|
|
45
|
+
} else {
|
|
46
|
+
return checkDomainsInJSON(domain, db);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function checkInJSON(domain, db) {
|
|
50
|
+
if (db.indexOf(domain) > -1) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function greenDomainsFromResults(greenResults) {
|
|
56
|
+
const entries = Object.entries(greenResults);
|
|
57
|
+
const greenEntries = entries.filter(([key, val]) => val.green);
|
|
58
|
+
return greenEntries.map(([key, val]) => val.url);
|
|
59
|
+
}
|
|
60
|
+
function checkDomainsInJSON(domains, db) {
|
|
61
|
+
let greenDomains = [];
|
|
62
|
+
for (let domain of domains) {
|
|
63
|
+
if (db.indexOf(domain) > -1) {
|
|
64
|
+
greenDomains.push(domain);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return greenDomains;
|
|
68
|
+
}
|
|
69
|
+
module.exports = {
|
|
70
|
+
check,
|
|
71
|
+
loadJSON
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=hosting-json.node.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-json.node.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport fs from \"fs\";\nimport zlib from \"zlib\";\nimport { promisify } from \"util\";\n\nconst readFile = promisify(fs.readFile);\nconst gunzip = promisify(zlib.gunzip);\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hostingCache\");\n\nasync function streamToString(stream) {\n return new Promise((resolve, reject) => {\n const chunks = [];\n stream.on(\"error\", reject);\n stream.on(\"data\", (chunk) => chunks.push(chunk));\n stream.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n\nasync function getGzippedFileAsJson(jsonPath) {\n const readStream = fs.createReadStream(jsonPath);\n const text = await streamToString(readStream);\n const unzipped = await gunzip(text);\n return unzipped.toString();\n}\n\nasync function loadJSON(jsonPath) {\n const jsonBuffer = jsonPath.endsWith(\".gz\")\n ? await getGzippedFileAsJson(jsonPath)\n : await readFile(jsonPath);\n return JSON.parse(jsonBuffer);\n}\n\nasync function check(domain, db) {\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkInJSON(domain, db);\n } else {\n return checkDomainsInJSON(domain, db);\n }\n}\n\nfunction checkInJSON(domain, db) {\n if (db.indexOf(domain) > -1) {\n return true;\n }\n return false;\n}\n\nfunction greenDomainsFromResults(greenResults) {\n const entries = Object.entries(greenResults);\n const greenEntries = entries.filter(([key, val]) => val.green);\n\n return greenEntries.map(([key, val]) => val.url);\n}\n\nfunction checkDomainsInJSON(domains, db) {\n let greenDomains = [];\n\n for (let domain of domains) {\n if (db.indexOf(domain) > -1) {\n greenDomains.push(domain);\n }\n }\n return greenDomains;\n}\n\nmodule.exports = {\n check,\n loadJSON,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,gBAAe;AACf,kBAAiB;AACjB,kBAA0B;AAK1B,mBAAyB;AAHzB,MAAM,WAAW,2BAAU,kBAAG,QAAQ;AACtC,MAAM,SAAS,2BAAU,oBAAK,MAAM;AAGpC,MAAM,MAAM,0BAAa,mBAAmB;AAE5C,8BAA8B,QAAQ;AACpC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,CAAC;AAChB,WAAO,GAAG,SAAS,MAAM;AACzB,WAAO,GAAG,QAAQ,CAAC,UAAU,OAAO,KAAK,KAAK,CAAC;AAC/C,WAAO,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC,CAAC;AAAA,EACvD,CAAC;AACH;AAEA,oCAAoC,UAAU;AAC5C,QAAM,aAAa,kBAAG,iBAAiB,QAAQ;AAC/C,QAAM,OAAO,MAAM,eAAe,UAAU;AAC5C,QAAM,WAAW,MAAM,OAAO,IAAI;AAClC,SAAO,SAAS,SAAS;AAC3B;AAEA,wBAAwB,UAAU;AAChC,QAAM,aAAa,SAAS,SAAS,KAAK,IACtC,MAAM,qBAAqB,QAAQ,IACnC,MAAM,SAAS,QAAQ;AAC3B,SAAO,KAAK,MAAM,UAAU;AAC9B;AAEA,qBAAqB,QAAQ,IAAI;AAE/B,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,YAAY,QAAQ,EAAE;AAAA,EAC/B,OAAO;AACL,WAAO,mBAAmB,QAAQ,EAAE;AAAA,EACtC;AACF;AAEA,qBAAqB,QAAQ,IAAI;AAC/B,MAAI,GAAG,QAAQ,MAAM,IAAI,IAAI;AAC3B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,iCAAiC,cAAc;AAC7C,QAAM,UAAU,OAAO,QAAQ,YAAY;AAC3C,QAAM,eAAe,QAAQ,OAAO,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK;AAE7D,SAAO,aAAa,IAAI,CAAC,CAAC,KAAK,SAAS,IAAI,GAAG;AACjD;AAEA,4BAA4B,SAAS,IAAI;AACvC,MAAI,eAAe,CAAC;AAEpB,WAAS,UAAU,SAAS;AAC1B,QAAI,GAAG,QAAQ,MAAM,IAAI,IAAI;AAC3B,mBAAa,KAAK,MAAM;AAAA,IAC1B;AAAA,EACF;AACA,SAAO;AACT;AAEA,OAAO,UAAU;AAAA,EACf;AAAA,EACA;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
|
+
var import_hosting_json_node = __toESM(require("./hosting-json.node.js"));
|
|
18
|
+
var import_path = __toESM(require("path"));
|
|
19
|
+
describe("hostingJSON", () => {
|
|
20
|
+
const jsonPath = import_path.default.resolve(__dirname, "..", "data", "fixtures", "url2green.test.json");
|
|
21
|
+
const jsonPathGz = import_path.default.resolve(__dirname, "..", "data", "fixtures", "url2green.test.json.gz");
|
|
22
|
+
describe("checking a single domain with #check", () => {
|
|
23
|
+
test("against the list of domains as JSON", async () => {
|
|
24
|
+
const db = await import_hosting_json_node.default.loadJSON(jsonPath);
|
|
25
|
+
const res = await import_hosting_json_node.default.check("google.com", db);
|
|
26
|
+
expect(res).toEqual(true);
|
|
27
|
+
});
|
|
28
|
+
test("against the list of domains as JSON loaded from a gzipped JSON", async () => {
|
|
29
|
+
const db = await import_hosting_json_node.default.loadJSON(jsonPathGz);
|
|
30
|
+
const res = await import_hosting_json_node.default.check("google.com", db);
|
|
31
|
+
expect(res).toEqual(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("implicitly checking multiple domains with #check", () => {
|
|
35
|
+
test("against the list of domains as JSON", async () => {
|
|
36
|
+
const db = await import_hosting_json_node.default.loadJSON(jsonPath);
|
|
37
|
+
const domains = ["google.com", "kochindustries.com"];
|
|
38
|
+
const res = await import_hosting_json_node.default.check(domains, db);
|
|
39
|
+
expect(res).toContain("google.com");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=hosting-json.node.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-json.node.test.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport hosting from \"./hosting-json.node.js\";\nimport path from \"path\";\n\ndescribe(\"hostingJSON\", () => {\n const jsonPath = path.resolve(\n __dirname,\n \"..\",\n \"data\",\n \"fixtures\",\n \"url2green.test.json\"\n );\n const jsonPathGz = path.resolve(\n __dirname,\n \"..\",\n \"data\",\n \"fixtures\",\n \"url2green.test.json.gz\"\n );\n describe(\"checking a single domain with #check\", () => {\n test(\"against the list of domains as JSON\", async () => {\n const db = await hosting.loadJSON(jsonPath);\n const res = await hosting.check(\"google.com\", db);\n expect(res).toEqual(true);\n });\n test(\"against the list of domains as JSON loaded from a gzipped JSON\", async () => {\n const db = await hosting.loadJSON(jsonPathGz);\n const res = await hosting.check(\"google.com\", db);\n expect(res).toEqual(true);\n });\n });\n describe(\"implicitly checking multiple domains with #check\", () => {\n test(\"against the list of domains as JSON\", async () => {\n const db = await hosting.loadJSON(jsonPath);\n const domains = [\"google.com\", \"kochindustries.com\"];\n\n const res = await hosting.check(domains, db);\n expect(res).toContain(\"google.com\");\n });\n });\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,+BAAoB;AACpB,kBAAiB;AAEjB,SAAS,eAAe,MAAM;AAC5B,QAAM,WAAW,oBAAK,QACpB,WACA,MACA,QACA,YACA,qBACF;AACA,QAAM,aAAa,oBAAK,QACtB,WACA,MACA,QACA,YACA,wBACF;AACA,WAAS,wCAAwC,MAAM;AACrD,SAAK,uCAAuC,YAAY;AACtD,YAAM,KAAK,MAAM,iCAAQ,SAAS,QAAQ;AAC1C,YAAM,MAAM,MAAM,iCAAQ,MAAM,cAAc,EAAE;AAChD,aAAO,GAAG,EAAE,QAAQ,IAAI;AAAA,IAC1B,CAAC;AACD,SAAK,kEAAkE,YAAY;AACjF,YAAM,KAAK,MAAM,iCAAQ,SAAS,UAAU;AAC5C,YAAM,MAAM,MAAM,iCAAQ,MAAM,cAAc,EAAE;AAChD,aAAO,GAAG,EAAE,QAAQ,IAAI;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC;AACD,WAAS,oDAAoD,MAAM;AACjE,SAAK,uCAAuC,YAAY;AACtD,YAAM,KAAK,MAAM,iCAAQ,SAAS,QAAQ;AAC1C,YAAM,UAAU,CAAC,cAAc,oBAAoB;AAEnD,YAAM,MAAM,MAAM,iCAAQ,MAAM,SAAS,EAAE;AAC3C,aAAO,GAAG,EAAE,UAAU,YAAY;AAAA,IACpC,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var hosting_node_exports = {};
|
|
22
|
+
__export(hosting_node_exports, {
|
|
23
|
+
default: () => hosting_node_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(hosting_node_exports);
|
|
26
|
+
var import_https = __toESM(require("https"));
|
|
27
|
+
var import_debug = __toESM(require("debug"));
|
|
28
|
+
var import_hosting_json_node = __toESM(require("./hosting-json.node.js"));
|
|
29
|
+
const log = (0, import_debug.default)("tgwf:hosting-node");
|
|
30
|
+
async function getBody(url) {
|
|
31
|
+
return new Promise(function(resolve, reject) {
|
|
32
|
+
const req = import_https.default.get(url, function(res) {
|
|
33
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
34
|
+
log("Could not get info from the Green Web Foundation API, %s for %s", res.statusCode, url);
|
|
35
|
+
return reject(new Error(`Status Code: ${res.statusCode}`));
|
|
36
|
+
}
|
|
37
|
+
const data = [];
|
|
38
|
+
res.on("data", (chunk) => {
|
|
39
|
+
data.push(chunk);
|
|
40
|
+
});
|
|
41
|
+
res.on("end", () => resolve(Buffer.concat(data).toString()));
|
|
42
|
+
});
|
|
43
|
+
req.end();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function check(domain, db) {
|
|
47
|
+
if (db) {
|
|
48
|
+
return import_hosting_json_node.default.check(domain, db);
|
|
49
|
+
}
|
|
50
|
+
if (typeof domain === "string") {
|
|
51
|
+
return checkAgainstAPI(domain);
|
|
52
|
+
} else {
|
|
53
|
+
return checkDomainsAgainstAPI(domain);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function checkAgainstAPI(domain) {
|
|
57
|
+
const res = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`));
|
|
58
|
+
return res.green;
|
|
59
|
+
}
|
|
60
|
+
async function checkDomainsAgainstAPI(domains) {
|
|
61
|
+
try {
|
|
62
|
+
const allGreenCheckResults = JSON.parse(await getBody(`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(domains)}`));
|
|
63
|
+
return import_hosting_json_node.default.greenDomainsFromResults(allGreenCheckResults);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function checkPage(pageXray, db) {
|
|
69
|
+
const domains = Object.keys(pageXray.domains);
|
|
70
|
+
return check(domains, db);
|
|
71
|
+
}
|
|
72
|
+
var hosting_node_default = {
|
|
73
|
+
check,
|
|
74
|
+
checkPage,
|
|
75
|
+
greendomains: import_hosting_json_node.default.greenDomainsFromResults,
|
|
76
|
+
loadJSON: import_hosting_json_node.default.loadJSON
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=hosting-node.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting-node.js"],
|
|
4
|
+
"sourcesContent": ["/*\n\nWe have a separate node-specific hosting.js file for node.\nThis uses the node-specific APIs for making http requests,\nand doing lookups against local JSON and sqlite databases.\nThis is used in the CommonJS build of co2.js\n\nThis lets us keep the total library small, and dependencies minimal.\n*/\n\nimport https from \"https\";\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hosting-node\");\n\nimport hostingJSON from \"./hosting-json.node.js\";\n\n/**\n * Accept a url and perform an http request, returning the body\n * for parsing as JSON.\n *\n * @param {string} url\n * @return {string}\n */\nasync function getBody(url) {\n return new Promise(function (resolve, reject) {\n // Do async job\n const req = https.get(url, function (res) {\n if (res.statusCode < 200 || res.statusCode >= 300) {\n log(\n \"Could not get info from the Green Web Foundation API, %s for %s\",\n res.statusCode,\n url\n );\n return reject(new Error(`Status Code: ${res.statusCode}`));\n }\n const data = [];\n\n res.on(\"data\", (chunk) => {\n data.push(chunk);\n });\n\n res.on(\"end\", () => resolve(Buffer.concat(data).toString()));\n });\n req.end();\n });\n}\n\nfunction check(domain, db) {\n if (db) {\n return hostingJSON.check(domain, db);\n }\n\n // is it a single domain or an array of them?\n if (typeof domain === \"string\") {\n return checkAgainstAPI(domain);\n } else {\n return checkDomainsAgainstAPI(domain);\n }\n}\n\nasync function checkAgainstAPI(domain) {\n const res = JSON.parse(\n await getBody(`https://api.thegreenwebfoundation.org/greencheck/${domain}`)\n );\n return res.green;\n}\n\nasync function checkDomainsAgainstAPI(domains) {\n try {\n const allGreenCheckResults = JSON.parse(\n await getBody(\n `https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(\n domains\n )}`\n )\n );\n return hostingJSON.greenDomainsFromResults(allGreenCheckResults);\n } catch (e) {\n return [];\n }\n}\n\nasync function checkPage(pageXray, db) {\n const domains = Object.keys(pageXray.domains);\n return check(domains, db);\n}\n\nexport default {\n check,\n checkPage,\n greendomains: hostingJSON.greenDomainsFromResults,\n loadJSON: hostingJSON.loadJSON,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,mBAAkB;AAElB,mBAAyB;AAGzB,+BAAwB;AAFxB,MAAM,MAAM,0BAAa,mBAAmB;AAW5C,uBAAuB,KAAK;AAC1B,SAAO,IAAI,QAAQ,SAAU,SAAS,QAAQ;AAE5C,UAAM,MAAM,qBAAM,IAAI,KAAK,SAAU,KAAK;AACxC,UAAI,IAAI,aAAa,OAAO,IAAI,cAAc,KAAK;AACjD,YACE,mEACA,IAAI,YACJ,GACF;AACA,eAAO,OAAO,IAAI,MAAM,gBAAgB,IAAI,YAAY,CAAC;AAAA,MAC3D;AACA,YAAM,OAAO,CAAC;AAEd,UAAI,GAAG,QAAQ,CAAC,UAAU;AACxB,aAAK,KAAK,KAAK;AAAA,MACjB,CAAC;AAED,UAAI,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,IAAI,EAAE,SAAS,CAAC,CAAC;AAAA,IAC7D,CAAC;AACD,QAAI,IAAI;AAAA,EACV,CAAC;AACH;AAEA,eAAe,QAAQ,IAAI;AACzB,MAAI,IAAI;AACN,WAAO,iCAAY,MAAM,QAAQ,EAAE;AAAA,EACrC;AAGA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,gBAAgB,MAAM;AAAA,EAC/B,OAAO;AACL,WAAO,uBAAuB,MAAM;AAAA,EACtC;AACF;AAEA,+BAA+B,QAAQ;AACrC,QAAM,MAAM,KAAK,MACf,MAAM,QAAQ,oDAAoD,QAAQ,CAC5E;AACA,SAAO,IAAI;AACb;AAEA,sCAAsC,SAAS;AAC7C,MAAI;AACF,UAAM,uBAAuB,KAAK,MAChC,MAAM,QACJ,4DAA4D,KAAK,UAC/D,OACF,GACF,CACF;AACA,WAAO,iCAAY,wBAAwB,oBAAoB;AAAA,EACjE,SAAS,GAAP;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAEA,yBAAyB,UAAU,IAAI;AACrC,QAAM,UAAU,OAAO,KAAK,SAAS,OAAO;AAC5C,SAAO,MAAM,SAAS,EAAE;AAC1B;AAEA,IAAO,uBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA,cAAc,iCAAY;AAAA,EAC1B,UAAU,iCAAY;AACxB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var hosting_exports = {};
|
|
23
|
+
__export(hosting_exports, {
|
|
24
|
+
default: () => hosting_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hosting_exports);
|
|
27
|
+
var import_debug = __toESM(require("debug"));
|
|
28
|
+
var import_hosting_api = __toESM(require("./hosting-api.js"));
|
|
29
|
+
const log = (0, import_debug.default)("tgwf:hosting");
|
|
30
|
+
function check(domain, db) {
|
|
31
|
+
return import_hosting_api.default.check(domain);
|
|
32
|
+
}
|
|
33
|
+
var hosting_default = {
|
|
34
|
+
check
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=hosting.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hosting.js"],
|
|
4
|
+
"sourcesContent": ["\"use strict\";\n\nimport debugFactory from \"debug\";\nconst log = debugFactory(\"tgwf:hosting\");\n\nimport hostingAPI from \"./hosting-api.js\";\n\nfunction check(domain, db) {\n return hostingAPI.check(domain);\n}\n\nexport default {\n check,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAyB;AAGzB,yBAAuB;AAFvB,MAAM,MAAM,0BAAa,cAAc;AAIvC,eAAe,QAAQ,IAAI;AACzB,SAAO,2BAAW,MAAM,MAAM;AAChC;AAEA,IAAO,kBAAQ;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|