@apify/utilities 2.3.2 → 2.3.4
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/index.js +79 -13
- package/index.js.map +1 -1
- package/index.mjs +75 -13
- package/index.mjs.map +1 -1
- package/package.json +2 -2
- package/utilities.client.d.ts +3 -0
package/index.mjs
CHANGED
|
@@ -77,6 +77,7 @@ function betterSetInterval(func, delay) {
|
|
|
77
77
|
}, "callback");
|
|
78
78
|
funcWrapper();
|
|
79
79
|
return {
|
|
80
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
80
81
|
_betterClearInterval() {
|
|
81
82
|
isRunning = false;
|
|
82
83
|
clearTimeout(timeoutId);
|
|
@@ -115,6 +116,7 @@ function weightedAverage(val1, weight1, val2, weight2) {
|
|
|
115
116
|
}
|
|
116
117
|
__name(weightedAverage, "weightedAverage");
|
|
117
118
|
var FORBIDDEN_USERNAMES_REGEXPS = [
|
|
119
|
+
// Meteor app routes
|
|
118
120
|
"page-not-found",
|
|
119
121
|
"docs",
|
|
120
122
|
"terms-of-use",
|
|
@@ -152,6 +154,7 @@ var FORBIDDEN_USERNAMES_REGEXPS = [
|
|
|
152
154
|
"community",
|
|
153
155
|
"crawlers",
|
|
154
156
|
"ext",
|
|
157
|
+
// Various strings
|
|
155
158
|
"admin",
|
|
156
159
|
"administration",
|
|
157
160
|
"crawler",
|
|
@@ -296,6 +299,8 @@ var FORBIDDEN_USERNAMES_REGEXPS = [
|
|
|
296
299
|
"freelancer",
|
|
297
300
|
"partner",
|
|
298
301
|
"preview",
|
|
302
|
+
"templates",
|
|
303
|
+
// Special files
|
|
299
304
|
"index",
|
|
300
305
|
"index\\.html",
|
|
301
306
|
"(favicon\\.[a-z]+)",
|
|
@@ -305,11 +310,17 @@ var FORBIDDEN_USERNAMES_REGEXPS = [
|
|
|
305
310
|
"(sitemap\\.[a-z]+)",
|
|
306
311
|
"(apple-touch-icon.*)",
|
|
307
312
|
"security-whitepaper\\.pdf",
|
|
313
|
+
// All hidden files
|
|
308
314
|
"(\\..*)",
|
|
315
|
+
// File starting with xxx-
|
|
309
316
|
"(xxx-.*)",
|
|
317
|
+
// Strings not starting with letter or number
|
|
310
318
|
"([^0-9a-z].*)",
|
|
319
|
+
// Strings not ending with letter or number
|
|
311
320
|
"(.*[^0-9a-z])",
|
|
321
|
+
// Strings where there's more than one underscore, comma or dash in row
|
|
312
322
|
"(.*[_.\\-]{2}.*)",
|
|
323
|
+
// Reserved usernames from https://github.com/shouldbee/reserved-usernames/blob/master/reserved-usernames.json
|
|
313
324
|
"0",
|
|
314
325
|
"about",
|
|
315
326
|
"access",
|
|
@@ -1060,7 +1071,9 @@ function parseUrl(str) {
|
|
|
1060
1071
|
},
|
|
1061
1072
|
parser: {
|
|
1062
1073
|
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
1074
|
+
// eslint-disable-line max-len,no-useless-escape
|
|
1063
1075
|
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
|
1076
|
+
// eslint-disable-line max-len,no-useless-escape
|
|
1064
1077
|
}
|
|
1065
1078
|
};
|
|
1066
1079
|
const m = o.parser[o.strictMode ? "strict" : "loose"].exec(str);
|
|
@@ -1087,15 +1100,25 @@ function normalizeUrl(url, keepFragment) {
|
|
|
1087
1100
|
if (typeof url !== "string" || !url.length) {
|
|
1088
1101
|
return null;
|
|
1089
1102
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1103
|
+
let urlObj;
|
|
1104
|
+
try {
|
|
1105
|
+
urlObj = new URL(url.trim());
|
|
1106
|
+
} catch {
|
|
1092
1107
|
return null;
|
|
1093
1108
|
}
|
|
1094
|
-
const
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1109
|
+
const { searchParams } = urlObj;
|
|
1110
|
+
for (const key of [...searchParams.keys()]) {
|
|
1111
|
+
if (key.startsWith("utm_")) {
|
|
1112
|
+
searchParams.delete(key);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
searchParams.sort();
|
|
1116
|
+
const protocol = urlObj.protocol.toLowerCase();
|
|
1117
|
+
const host = urlObj.host.toLowerCase();
|
|
1118
|
+
const path = urlObj.pathname.replace(/\/$/, "");
|
|
1119
|
+
const search = searchParams.toString() ? `?${searchParams}` : "";
|
|
1120
|
+
const hash = keepFragment ? urlObj.hash : "";
|
|
1121
|
+
return `${protocol}//${host}${path}${search}${hash}`;
|
|
1099
1122
|
}
|
|
1100
1123
|
__name(normalizeUrl, "normalizeUrl");
|
|
1101
1124
|
function markedSetNofollowLinks(href, title, text) {
|
|
@@ -1385,7 +1408,7 @@ var HealthChecker = class {
|
|
|
1385
1408
|
});
|
|
1386
1409
|
await collection.insertOne({
|
|
1387
1410
|
_id: id,
|
|
1388
|
-
createdAt: new Date()
|
|
1411
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1389
1412
|
});
|
|
1390
1413
|
const retrieved = await collection.findOne({ _id: id });
|
|
1391
1414
|
if (!retrieved)
|
|
@@ -1444,6 +1467,8 @@ var ParseJsonlStream = class extends Transform {
|
|
|
1444
1467
|
}
|
|
1445
1468
|
callback(null, chunk);
|
|
1446
1469
|
}
|
|
1470
|
+
// This function is called right after stream.end() is called by the writer.
|
|
1471
|
+
// It just tries to process the pending chunk and returns an error if that fails.
|
|
1447
1472
|
_flush(callback) {
|
|
1448
1473
|
if (this.pendingChunk) {
|
|
1449
1474
|
try {
|
|
@@ -1509,6 +1534,13 @@ var WebhookPayloadTemplate = class {
|
|
|
1509
1534
|
this.payload = this.template;
|
|
1510
1535
|
this.replacedVariables = [];
|
|
1511
1536
|
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Parse existing webhook payload template string into an object, replacing
|
|
1539
|
+
* template variables using the provided context.
|
|
1540
|
+
*
|
|
1541
|
+
* Parse also validates the template structure, so it can be used
|
|
1542
|
+
* to check validity of the template JSON and usage of allowedVariables.
|
|
1543
|
+
*/
|
|
1512
1544
|
static parse(payloadTemplate, allowedVariables = null, context = {}) {
|
|
1513
1545
|
const type = typeof payloadTemplate;
|
|
1514
1546
|
if (type !== "string")
|
|
@@ -1516,12 +1548,42 @@ var WebhookPayloadTemplate = class {
|
|
|
1516
1548
|
const template = new WebhookPayloadTemplate(payloadTemplate, allowedVariables, context);
|
|
1517
1549
|
return template._parse();
|
|
1518
1550
|
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Stringify an object into a webhook payload template.
|
|
1553
|
+
* Values created using `getTemplateVariable('foo.bar')`
|
|
1554
|
+
* will be stringified to `{{foo.bar}}` template variable.
|
|
1555
|
+
*/
|
|
1519
1556
|
static stringify(objectTemplate, replacer, indent = 2) {
|
|
1520
1557
|
const type = typeof objectTemplate;
|
|
1521
1558
|
if (!objectTemplate || type !== "object")
|
|
1522
1559
|
throw new Error(`Cannot stringify a ${type} payload template.`);
|
|
1523
1560
|
return jsonStringifyExtended(objectTemplate, replacer, indent);
|
|
1524
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Produces an instance of a template variable that can be used
|
|
1564
|
+
* in objects and will be stringified into `{{variableName}}` syntax.
|
|
1565
|
+
*
|
|
1566
|
+
* **Example:**
|
|
1567
|
+
* ```js
|
|
1568
|
+
* const resourceVariable = WebhookPayloadTemplate.getVariable('resource');
|
|
1569
|
+
* const objectTemplate = {
|
|
1570
|
+
* foo: 'foo',
|
|
1571
|
+
* bar: ['bar'],
|
|
1572
|
+
* res: resourceVariable,
|
|
1573
|
+
* }
|
|
1574
|
+
*
|
|
1575
|
+
* const payloadTemplate = WebhookPayloadTemplate.stringify(objectTemplate);
|
|
1576
|
+
* ```
|
|
1577
|
+
*
|
|
1578
|
+
* **Produces:**
|
|
1579
|
+
* ```json
|
|
1580
|
+
* {
|
|
1581
|
+
* "foo": "foo",
|
|
1582
|
+
* "bar": ["bar"],
|
|
1583
|
+
* "res": {{resource}},
|
|
1584
|
+
* }
|
|
1585
|
+
* ```
|
|
1586
|
+
*/
|
|
1525
1587
|
static getVariable(variableName) {
|
|
1526
1588
|
return new JsonVariable(variableName);
|
|
1527
1589
|
}
|
|
@@ -1690,18 +1752,18 @@ export {
|
|
|
1690
1752
|
weightedAverage
|
|
1691
1753
|
};
|
|
1692
1754
|
/*!
|
|
1693
|
-
* This module contains various
|
|
1755
|
+
* This module contains various server utility and helper functions.
|
|
1756
|
+
* Note that it automatically exports functions from utilities.client.js
|
|
1694
1757
|
*
|
|
1695
1758
|
* Author: Jan Curn (jan@apify.com)
|
|
1696
|
-
* Copyright(c)
|
|
1759
|
+
* Copyright(c) 2015 Apify. All rights reserved.
|
|
1697
1760
|
*
|
|
1698
1761
|
*/
|
|
1699
1762
|
/*!
|
|
1700
|
-
* This module contains various
|
|
1701
|
-
* Note that it automatically exports functions from utilities.client.js
|
|
1763
|
+
* This module contains various client-side utility and helper functions.
|
|
1702
1764
|
*
|
|
1703
1765
|
* Author: Jan Curn (jan@apify.com)
|
|
1704
|
-
* Copyright(c)
|
|
1766
|
+
* Copyright(c) 2016 Apify. All rights reserved.
|
|
1705
1767
|
*
|
|
1706
1768
|
*/
|
|
1707
1769
|
//# sourceMappingURL=index.mjs.map
|