@paywalls-net/filter 1.1.0 → 1.1.1
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/package.json +1 -1
- package/src/index.js +5 -5
- package/src/user-agent-classification.js +2 -10
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -69,7 +69,7 @@ async function checkAgentStatus(cfg, request) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
const agentInfo = classifyUserAgent(cfg, userAgent);
|
|
72
|
+
const agentInfo = await classifyUserAgent(cfg, userAgent);
|
|
73
73
|
|
|
74
74
|
const body = JSON.stringify({
|
|
75
75
|
account_id: cfg.paywallsPublisherId,
|
|
@@ -129,14 +129,14 @@ function isTestBot(request) {
|
|
|
129
129
|
const uaParam = url.searchParams.get("user-agent");
|
|
130
130
|
return uaParam && uaParam.includes("bot");
|
|
131
131
|
}
|
|
132
|
-
function isPaywallsKnownBot(cfg,request) {
|
|
132
|
+
async function isPaywallsKnownBot(cfg, request) {
|
|
133
133
|
const userAgent = request.headers.get("User-Agent");
|
|
134
|
-
const uaClassification = classifyUserAgent(userAgent);
|
|
134
|
+
const uaClassification = await classifyUserAgent(cfg, userAgent);
|
|
135
135
|
return uaClassification.operator && uaClassification.agent;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
function isRecognizedBot(cfg,request) {
|
|
139
|
-
return isFastlyKnownBot(request) || isCloudflareKnownBot(request) || isTestBot(request) || isPaywallsKnownBot(cfg,request);
|
|
138
|
+
async function isRecognizedBot(cfg, request) {
|
|
139
|
+
return isFastlyKnownBot(request) || isCloudflareKnownBot(request) || isTestBot(request) || await isPaywallsKnownBot(cfg, request);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
|
|
@@ -39,27 +39,19 @@ export async function loadAgentPatterns(cfg) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function getAgentPatterns() {
|
|
43
|
-
if (cachedUserAgentPatterns) {
|
|
44
|
-
return cachedUserAgentPatterns;
|
|
45
|
-
} else {
|
|
46
|
-
throw new Error('User agent patterns not loaded. Call loadAgentPatterns first.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
42
|
/**
|
|
51
43
|
* Classifies the user agent string based on fetched patterns.
|
|
52
44
|
* @param {Object} cfg - Configuration object containing API host details.
|
|
53
45
|
* @param {string} userAgent - The user agent string to classify.
|
|
54
46
|
* @returns {Promise<Object>} An object containing the browser, OS, operator, usage, and user_initiated status.
|
|
55
47
|
*/
|
|
56
|
-
export function classifyUserAgent(cfg, userAgent) {
|
|
48
|
+
export async function classifyUserAgent(cfg, userAgent) {
|
|
57
49
|
const parsedUA = new UAParser(userAgent).getResult();
|
|
58
50
|
|
|
59
51
|
const browser = parsedUA.browser.name || 'Unknown';
|
|
60
52
|
const os = parsedUA.os.name || 'Unknown';
|
|
61
53
|
|
|
62
|
-
const userAgentPatterns =
|
|
54
|
+
const userAgentPatterns = await loadAgentPatterns(cfg);
|
|
63
55
|
|
|
64
56
|
for (const config of userAgentPatterns) {
|
|
65
57
|
if (!config.patterns) continue;
|