@paywalls-net/filter 1.2.3 → 1.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +23 -14
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Client SDK for integrating paywalls.net bot filtering and authorization services into your server or CDN.",
4
4
  "author": "paywalls.net",
5
5
  "license": "MIT",
6
- "version": "1.2.3",
6
+ "version": "1.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
package/src/index.js CHANGED
@@ -34,10 +34,7 @@ let runtime = detectRuntime();
34
34
  let fetchVersion = detectFetchVersion();
35
35
  const sdkUserAgent = `pw-filter-sdk/${sdk_version} (${runtime}; fetch/${fetchVersion})`;
36
36
 
37
- async function logAccess(cfg, request, access) {
38
- // Separate html from the status in the access object.
39
- const { response, ...status } = access;
40
-
37
+ function getAllHeaders(request) {
41
38
  // Get all headers as a plain object (name-value pairs)
42
39
  let headers = {};
43
40
  if (typeof request.headers.entries === "function") {
@@ -51,6 +48,15 @@ async function logAccess(cfg, request, access) {
51
48
  headers[key] = request.headers[key][0]?.value || "";
52
49
  }
53
50
  }
51
+ return headers;
52
+ }
53
+
54
+ async function logAccess(cfg, request, access) {
55
+ // Separate html from the status in the access object.
56
+ const { response, ...status } = access;
57
+
58
+ // Get all headers as a plain object (name-value pairs)
59
+ let headers = getAllHeaders(request);
54
60
 
55
61
  const url = new URL(request.url);
56
62
  let body = {
@@ -107,14 +113,15 @@ async function checkAgentStatus(cfg, request) {
107
113
  response: { code: 401, html: "Unauthorized access." }
108
114
  };
109
115
  }
110
-
116
+ let headers = getAllHeaders(request);
111
117
  const agentInfo = await classifyUserAgent(cfg, userAgent);
112
118
 
113
119
  const body = JSON.stringify({
114
120
  account_id: cfg.paywallsPublisherId,
115
121
  operator: agentInfo.operator,
116
122
  agent: agentInfo.agent,
117
- token: token
123
+ token: token,
124
+ headers: headers
118
125
  });
119
126
 
120
127
  const response = await fetch(`${cfg.paywallsAPIHost}/api/filter/agents/auth`, {
@@ -275,15 +282,17 @@ async function cloudflare(config = null) {
275
282
  }
276
283
 
277
284
 
278
- async function fastly(config) {
279
- const paywallsConfig = {
280
- paywallsAPIHost: config.get('PAYWALLS_CLOUD_API_HOST') || PAYWALLS_CLOUD_API_HOST,
281
- paywallsAPIKey: config.get('PAYWALLS_API_KEY'),
282
- paywallsPublisherId: config.get('PAYWALLS_PUBLISHER_ID')
283
- };
284
- await loadAgentPatterns(paywallsConfig);
285
+ async function fastly() {
286
+
287
+ return async function handle(request, config, ctx) {
288
+ const paywallsConfig = {
289
+ paywallsAPIHost: config.get('PAYWALLS_CLOUD_API_HOST') || PAYWALLS_CLOUD_API_HOST,
290
+ paywallsAPIKey: config.get('PAYWALLS_API_KEY'),
291
+ paywallsPublisherId: config.get('PAYWALLS_PUBLISHER_ID')
292
+ };
293
+
294
+ await loadAgentPatterns(paywallsConfig);
285
295
 
286
- return async function handle(request) {
287
296
  if (await isRecognizedBot(paywallsConfig, request)) {
288
297
  const authz = await checkAgentStatus(paywallsConfig, request);
289
298