@waniwani/relay 0.0.0-stage → 0.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/dist/index.js ADDED
@@ -0,0 +1,1368 @@
1
+ // src/headers.ts
2
+ var HEADER_CAP = [
3
+ "user-agent",
4
+ "referer",
5
+ "accept",
6
+ "accept-language",
7
+ "from",
8
+ "signature-agent",
9
+ "signature-input",
10
+ "signature",
11
+ "dpop",
12
+ "sec-ch-ua",
13
+ "sec-ch-ua-platform",
14
+ "sec-ch-ua-mobile",
15
+ "authorization"
16
+ ];
17
+ var KNOWN_SCHEMES = new Map(
18
+ [
19
+ "Basic",
20
+ "Bearer",
21
+ "Digest",
22
+ "DPoP",
23
+ "HOBA",
24
+ "Mutual",
25
+ "Negotiate",
26
+ "NTLM",
27
+ "OAuth",
28
+ "PrivateToken",
29
+ "SCRAM-SHA-1",
30
+ "SCRAM-SHA-256",
31
+ "vapid",
32
+ "AWS4-HMAC-SHA256"
33
+ ].map((scheme) => [scheme.toLowerCase(), scheme])
34
+ );
35
+ function authorizationScheme(value) {
36
+ const parts = value.trim().split(/\s+/);
37
+ if (parts.length < 2) {
38
+ return null;
39
+ }
40
+ return KNOWN_SCHEMES.get((parts[0] ?? "").toLowerCase()) ?? null;
41
+ }
42
+ function readCappedHeaders(headers) {
43
+ const out = {};
44
+ for (const name of HEADER_CAP) {
45
+ const value = headers.get(name);
46
+ if (value === null) {
47
+ continue;
48
+ }
49
+ if (name === "authorization") {
50
+ const scheme = authorizationScheme(value);
51
+ if (scheme !== null) {
52
+ out[name] = scheme;
53
+ }
54
+ } else {
55
+ out[name] = value;
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+ function clientIp(headers) {
61
+ const forwarded = headers.get("x-forwarded-for");
62
+ const candidate = headers.get("cf-connecting-ip") ?? (forwarded !== null ? forwarded.split(",")[0] : headers.get("x-real-ip"));
63
+ const ip = candidate?.trim().toLowerCase();
64
+ return ip ? ip : null;
65
+ }
66
+
67
+ // src/settings.ts
68
+ var settings = {
69
+ apiUrls: {
70
+ us: "https://app.waniwani.ai",
71
+ eu: "https://eu.app.waniwani.ai"
72
+ },
73
+ requestTimeoutMs: 2e3,
74
+ retryDelayMs: 500
75
+ };
76
+
77
+ // src/http.ts
78
+ async function fetchWithTimeout(url, init) {
79
+ const controller = new AbortController();
80
+ const timer = setTimeout(() => controller.abort(), settings.requestTimeoutMs);
81
+ try {
82
+ const response = await fetch(url, { ...init, signal: controller.signal });
83
+ await response.body?.cancel().catch(() => {
84
+ });
85
+ return { status: response.status };
86
+ } catch {
87
+ return { failure: controller.signal.aborted ? "timeout" : "network" };
88
+ } finally {
89
+ clearTimeout(timer);
90
+ }
91
+ }
92
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
93
+
94
+ // src/ingest.ts
95
+ var isSuccess = (outcome) => "status" in outcome && outcome.status >= 200 && outcome.status < 300;
96
+ var isRetryable = (outcome) => "failure" in outcome || outcome.status === 429 || outcome.status >= 500;
97
+ var describe = (outcome) => "failure" in outcome ? outcome.failure : `status ${outcome.status}`;
98
+ var post = (url, body) => fetchWithTimeout(url, {
99
+ method: "POST",
100
+ headers: { "content-type": "application/json" },
101
+ body
102
+ });
103
+ async function postEvent(url, body) {
104
+ let outcome = await post(url, body);
105
+ if (!isSuccess(outcome) && isRetryable(outcome)) {
106
+ await delay(settings.retryDelayMs);
107
+ outcome = await post(url, body);
108
+ }
109
+ if (isSuccess(outcome)) {
110
+ return true;
111
+ }
112
+ console.warn(
113
+ `[@waniwani/relay] Could not record an agent visit (${describe(outcome)}). The event was dropped.`
114
+ );
115
+ return false;
116
+ }
117
+
118
+ // src/key.ts
119
+ var KEY = /^wwt_([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+={0,2})$/;
120
+ var warnedMalformed = false;
121
+ function readKey(explicit) {
122
+ const raw = explicit ?? readEnv("WANIWANI_AGENT_TRAFFIC_KEY");
123
+ if (raw === void 0 || raw.trim() === "") {
124
+ return null;
125
+ }
126
+ const match = KEY.exec(raw.trim());
127
+ if (!match?.[1] || !match[2]) {
128
+ if (!warnedMalformed) {
129
+ warnedMalformed = true;
130
+ console.warn(
131
+ "[@waniwani/relay] WANIWANI_AGENT_TRAFFIC_KEY is malformed, so no agent visits are recorded. Copy the key again from the WaniWani setup screen."
132
+ );
133
+ }
134
+ return null;
135
+ }
136
+ return { ingestToken: match[1], orgKey: match[2] };
137
+ }
138
+ function readEnv(name) {
139
+ try {
140
+ return typeof process === "undefined" ? void 0 : process.env[name];
141
+ } catch {
142
+ return void 0;
143
+ }
144
+ }
145
+
146
+ // src/logic/decide.ts
147
+ import { BlockList } from "node:net";
148
+
149
+ // src/logic/agents.json
150
+ var agents_default = {
151
+ source: "Hand copied from the WaniWani bot catalog (kinds training, search and fetcher). Each token is matched case-insensitively inside the User-Agent header.",
152
+ tokens: [
153
+ "gptbot",
154
+ "claudebot",
155
+ "anthropic-ai",
156
+ "googleother",
157
+ "googleother-image",
158
+ "googleother-video",
159
+ "meta-externalagent",
160
+ "facebookbot",
161
+ "bytespider",
162
+ "tiktokspider",
163
+ "ccbot",
164
+ "diffbot",
165
+ "ai2bot",
166
+ "ai2bot-dolma",
167
+ "timpibot",
168
+ "cohere-training-data-crawler",
169
+ "mistralai-training",
170
+ "deepseekbot",
171
+ "erniebot",
172
+ "qwenbot",
173
+ "pangubot",
174
+ "kimibot",
175
+ "yandexadditional",
176
+ "yandexadditionalbot",
177
+ "brightbot",
178
+ "reflectionbot",
179
+ "agenttimes",
180
+ "aihitbot",
181
+ "awario",
182
+ "chatglm-spider",
183
+ "cotoyogi",
184
+ "datenbank crawler",
185
+ "echobot bot",
186
+ "echoboxbot",
187
+ "factset_spyderbot",
188
+ "friendlycrawler",
189
+ "icc-crawler",
190
+ "imagesiftbot",
191
+ "imagespider",
192
+ "img2dataset",
193
+ "isscyberriskcrawler",
194
+ "kangaroo bot",
195
+ "kunatocrawler",
196
+ "laion-huggingface-processor",
197
+ "laiondownloader",
198
+ "mycentralaiscraperbot",
199
+ "nagetbot",
200
+ "netestate imprint crawler",
201
+ "omgili",
202
+ "omgilibot",
203
+ "panscient",
204
+ "poseidon research crawler",
205
+ "sbintuitionsbot",
206
+ "sidetrade indexer bot",
207
+ "thinkbot",
208
+ "velenpublicwebcrawler",
209
+ "wardbot",
210
+ "oai-searchbot",
211
+ "oai-adsbot",
212
+ "claude-searchbot",
213
+ "perplexitybot",
214
+ "applebot",
215
+ "amazonbot",
216
+ "amzn-searchbot",
217
+ "amazon-kendra",
218
+ "meta-webindexer",
219
+ "mistralai-index",
220
+ "kimi-searchbot",
221
+ "azureai-searchbot",
222
+ "petalbot",
223
+ "youbot",
224
+ "exabot",
225
+ "exasearchbot",
226
+ "keenablebot",
227
+ "linkupbot",
228
+ "seltzsitemapfetcher",
229
+ "shapbot",
230
+ "tavilybot",
231
+ "bravebot",
232
+ "cloudflare-autorag",
233
+ "jackjillcareersbot",
234
+ "addsearchbot",
235
+ "aiwebindex",
236
+ "andibot",
237
+ "aranet-searchbot",
238
+ "channel3bot",
239
+ "iaskbot",
240
+ "iaskspider",
241
+ "querit-searchbot",
242
+ "queritbot",
243
+ "terracotta",
244
+ "terra cotta",
245
+ "zanistabot",
246
+ "chatgpt-user",
247
+ "chatgpt agent",
248
+ "claude-user",
249
+ "claude-web",
250
+ "claude-code",
251
+ "perplexity-user",
252
+ "mistralai-user",
253
+ "meta-externalfetcher",
254
+ "google-cloudvertexbot",
255
+ "cloudvertexbot",
256
+ "google-firebase",
257
+ "google-notebooklm",
258
+ "notebooklm",
259
+ "gemini-deep-research",
260
+ "google-agent",
261
+ "googleagent-mariner",
262
+ "googleagent-urlcontext",
263
+ "google-gemini-cli",
264
+ "duckassistbot",
265
+ "cohere-ai",
266
+ "amzn-user",
267
+ "amazonbuyforme",
268
+ "amazon-qbusiness",
269
+ "novaact",
270
+ "bedrockbot",
271
+ "diffbot-user",
272
+ "ai2bot-deepresearcheval",
273
+ "kimi-agent",
274
+ "kimi-user",
275
+ "manus-user",
276
+ "kagi-fetcher",
277
+ "phindbot",
278
+ "tongyibot",
279
+ "yiyanbot",
280
+ "doubaobot",
281
+ "shap-user",
282
+ "firecrawlagent",
283
+ "apifybot",
284
+ "apifywebsitecontentcrawler",
285
+ "cloudflarebrowserrenderingcrawler",
286
+ "crawlspace",
287
+ "mozilla-tabstack",
288
+ "klaviyoaibot",
289
+ "atlassian-bot",
290
+ "semrushbot-ocob",
291
+ "semrushbot-swa",
292
+ "quillbot",
293
+ "bigsur.ai",
294
+ "geisthaus-pagefetcher",
295
+ "poggio-citations",
296
+ "qualifiedbot",
297
+ "twinagent",
298
+ "agentdatabot",
299
+ "bixelbot",
300
+ "buddybot",
301
+ "cragcrawler",
302
+ "crawl4ai",
303
+ "henkbot",
304
+ "lightpanda",
305
+ "linerbot",
306
+ "qodercli",
307
+ "wrtnbot"
308
+ ]
309
+ };
310
+
311
+ // src/logic/ip-ranges.generated.json
312
+ var ip_ranges_generated_default = {
313
+ sources: [
314
+ {
315
+ bot: "GPTBot",
316
+ url: "https://openai.com/gptbot.json",
317
+ ipv4: [
318
+ "4.227.36.0/25",
319
+ "20.125.66.80/28",
320
+ "20.171.206.0/24",
321
+ "20.171.207.0/24",
322
+ "52.230.152.0/24",
323
+ "74.7.175.128/25",
324
+ "74.7.227.0/25",
325
+ "74.7.227.128/25",
326
+ "74.7.228.0/25",
327
+ "74.7.230.0/25",
328
+ "74.7.241.0/25",
329
+ "74.7.241.128/25",
330
+ "74.7.242.0/25",
331
+ "74.7.243.128/25",
332
+ "74.7.244.0/25",
333
+ "132.196.86.0/24",
334
+ "172.182.202.0/25",
335
+ "172.182.207.0/25"
336
+ ],
337
+ ipv6: []
338
+ },
339
+ {
340
+ bot: "OAI-SearchBot",
341
+ url: "https://openai.com/searchbot.json",
342
+ ipv4: [
343
+ "4.227.36.0/25",
344
+ "13.66.216.176/28",
345
+ "20.14.99.96/28",
346
+ "20.25.151.224/28",
347
+ "20.42.10.176/28",
348
+ "20.168.18.32/28",
349
+ "20.169.6.224/28",
350
+ "20.169.7.48/28",
351
+ "20.169.77.0/25",
352
+ "20.171.53.224/28",
353
+ "20.171.123.64/28",
354
+ "23.102.145.48/28",
355
+ "40.67.175.0/25",
356
+ "40.90.214.16/28",
357
+ "51.8.102.0/24",
358
+ "74.7.175.128/25",
359
+ "74.7.228.0/25",
360
+ "74.7.228.128/25",
361
+ "74.7.229.0/25",
362
+ "74.7.229.128/25",
363
+ "74.7.230.0/25",
364
+ "74.7.241.128/25",
365
+ "74.7.242.128/25",
366
+ "74.7.243.0/25",
367
+ "74.7.244.0/25",
368
+ "104.210.140.128/28",
369
+ "135.234.64.0/24",
370
+ "172.182.193.80/28",
371
+ "172.182.193.224/28",
372
+ "172.182.194.32/28",
373
+ "172.182.194.144/28",
374
+ "172.182.195.48/28",
375
+ "172.182.209.208/28",
376
+ "172.182.211.192/28",
377
+ "172.182.213.192/28",
378
+ "172.182.224.0/28",
379
+ "172.203.190.80/28",
380
+ "172.203.190.112/28",
381
+ "172.203.190.128/28"
382
+ ],
383
+ ipv6: []
384
+ },
385
+ {
386
+ bot: "ChatGPT-User",
387
+ url: "https://openai.com/chatgpt-user.json",
388
+ ipv4: [
389
+ "4.151.71.176/28",
390
+ "4.151.119.48/28",
391
+ "4.189.118.208/28",
392
+ "4.189.119.48/28",
393
+ "4.197.22.112/28",
394
+ "4.197.64.0/28",
395
+ "4.197.64.16/28",
396
+ "4.197.64.48/28",
397
+ "4.197.64.64/28",
398
+ "4.197.115.112/28",
399
+ "4.201.232.64/28",
400
+ "4.205.128.176/28",
401
+ "4.218.24.64/28",
402
+ "4.226.200.16/28",
403
+ "4.226.226.32/28",
404
+ "9.129.0.0/16",
405
+ "9.160.34.144/28",
406
+ "9.160.36.16/28",
407
+ "9.160.96.16/28",
408
+ "9.160.128.16/28",
409
+ "9.160.128.64/28",
410
+ "9.160.163.128/28",
411
+ "9.163.101.48/28",
412
+ "9.205.8.48/28",
413
+ "9.205.8.64/28",
414
+ "9.205.25.128/28",
415
+ "9.205.30.128/28",
416
+ "9.205.30.144/28",
417
+ "9.205.30.176/28",
418
+ "9.205.128.32/28",
419
+ "9.205.128.48/28",
420
+ "9.223.181.208/28",
421
+ "9.234.96.192/28",
422
+ "9.234.97.96/28",
423
+ "13.65.138.112/28",
424
+ "13.67.72.16/28",
425
+ "13.71.2.208/28",
426
+ "13.76.32.208/28",
427
+ "13.76.116.80/28",
428
+ "13.83.167.128/28",
429
+ "13.83.237.176/28",
430
+ "20.45.178.144/28",
431
+ "20.55.229.144/28",
432
+ "20.57.199.192/28",
433
+ "20.63.180.96/28",
434
+ "20.63.221.64/28",
435
+ "20.78.130.48/28",
436
+ "20.83.243.176/28",
437
+ "20.98.18.80/28",
438
+ "20.102.212.144/28",
439
+ "20.113.211.112/28",
440
+ "20.113.225.112/28",
441
+ "20.125.112.224/28",
442
+ "20.125.144.144/28",
443
+ "20.161.75.208/28",
444
+ "20.168.7.192/28",
445
+ "20.169.73.32/28",
446
+ "20.169.73.64/28",
447
+ "20.169.78.48/28",
448
+ "20.169.78.64/28",
449
+ "20.169.78.128/28",
450
+ "20.169.78.160/28",
451
+ "20.169.78.192/28",
452
+ "20.169.86.224/28",
453
+ "20.169.86.240/28",
454
+ "20.170.184.16/28",
455
+ "20.170.184.32/28",
456
+ "20.170.184.48/28",
457
+ "20.170.184.64/28",
458
+ "20.170.184.80/28",
459
+ "20.172.29.32/28",
460
+ "20.199.211.160/28",
461
+ "20.199.242.0/28",
462
+ "20.200.212.240/28",
463
+ "20.206.101.192/28",
464
+ "20.210.211.192/28",
465
+ "20.212.62.208/28",
466
+ "20.215.187.208/28",
467
+ "20.215.219.128/28",
468
+ "20.215.219.160/28",
469
+ "20.215.219.208/28",
470
+ "20.218.30.240/28",
471
+ "20.219.71.192/28",
472
+ "20.219.161.192/28",
473
+ "20.219.184.96/28",
474
+ "20.222.36.192/28",
475
+ "20.227.140.32/28",
476
+ "20.228.106.176/28",
477
+ "20.235.87.224/28",
478
+ "20.249.63.208/28",
479
+ "20.250.6.128/28",
480
+ "20.250.136.64/28",
481
+ "20.254.201.208/28",
482
+ "23.98.142.176/28",
483
+ "23.98.186.64/28",
484
+ "23.98.186.96/28",
485
+ "23.98.186.176/28",
486
+ "23.98.186.192/28",
487
+ "23.101.217.176/28",
488
+ "23.102.140.144/28",
489
+ "23.102.141.32/28",
490
+ "40.74.200.208/28",
491
+ "40.81.67.96/28",
492
+ "40.81.234.144/28",
493
+ "40.84.221.208/28",
494
+ "40.84.221.224/28",
495
+ "40.116.73.208/28",
496
+ "40.119.36.240/28",
497
+ "40.124.161.0/28",
498
+ "48.221.40.176/28",
499
+ "48.221.184.80/28",
500
+ "48.221.184.96/28",
501
+ "51.8.155.48/28",
502
+ "51.8.155.112/28",
503
+ "51.57.0.96/28",
504
+ "51.59.24.64/28",
505
+ "51.59.24.80/28",
506
+ "51.59.48.80/28",
507
+ "51.116.2.80/28",
508
+ "51.116.221.96/28",
509
+ "52.148.129.32/28",
510
+ "52.156.77.144/28",
511
+ "52.159.227.32/28",
512
+ "52.159.249.96/28",
513
+ "52.161.49.96/28",
514
+ "52.165.212.48/28",
515
+ "52.172.129.160/28",
516
+ "52.173.219.96/28",
517
+ "52.173.219.112/28",
518
+ "52.173.221.16/28",
519
+ "52.173.221.176/28",
520
+ "52.173.221.208/28",
521
+ "52.173.234.16/28",
522
+ "52.173.234.80/28",
523
+ "52.183.217.240/28",
524
+ "52.190.137.16/28",
525
+ "52.190.137.144/28",
526
+ "52.190.139.48/28",
527
+ "52.190.142.64/28",
528
+ "52.190.190.16/28",
529
+ "52.190.251.112/28",
530
+ "52.225.75.208/28",
531
+ "52.231.30.48/28",
532
+ "52.231.34.176/28",
533
+ "52.231.39.144/28",
534
+ "52.231.50.64/28",
535
+ "52.236.94.144/28",
536
+ "52.241.146.208/28",
537
+ "52.242.132.224/28",
538
+ "52.242.132.240/28",
539
+ "52.255.109.80/28",
540
+ "52.255.109.96/28",
541
+ "52.255.109.144/28",
542
+ "52.255.111.0/28",
543
+ "52.255.111.80/28",
544
+ "57.154.174.112/28",
545
+ "57.154.175.0/28",
546
+ "57.154.187.32/28",
547
+ "68.154.28.96/28",
548
+ "68.220.57.64/28",
549
+ "70.153.32.16/28",
550
+ "70.153.32.32/28",
551
+ "70.153.87.224/28",
552
+ "70.153.189.192/28",
553
+ "70.156.152.96/28",
554
+ "74.7.35.48/28",
555
+ "74.7.35.112/28",
556
+ "74.7.36.64/28",
557
+ "74.7.36.80/28",
558
+ "74.7.36.96/28",
559
+ "74.161.200.96/28",
560
+ "74.224.217.64/28",
561
+ "74.226.253.160/28",
562
+ "74.248.37.160/28",
563
+ "85.211.128.16/28",
564
+ "85.211.128.32/28",
565
+ "104.208.184.192/28",
566
+ "104.210.139.192/28",
567
+ "104.210.139.224/28",
568
+ "128.85.198.32/28",
569
+ "132.196.82.48/28",
570
+ "134.33.102.192/28",
571
+ "134.138.52.16/28",
572
+ "134.138.52.64/28",
573
+ "134.138.52.96/28",
574
+ "134.138.52.128/28",
575
+ "134.138.57.64/28",
576
+ "134.138.57.80/28",
577
+ "134.138.57.176/28",
578
+ "134.138.58.32/28",
579
+ "134.149.233.80/28",
580
+ "135.13.64.240/28",
581
+ "135.116.136.160/28",
582
+ "135.220.73.208/28",
583
+ "135.220.73.240/28",
584
+ "135.222.99.32/28",
585
+ "135.237.131.208/28",
586
+ "135.237.133.48/28",
587
+ "137.135.191.176/28",
588
+ "138.91.46.96/28",
589
+ "145.132.136.96/28",
590
+ "158.158.5.32/28",
591
+ "168.63.252.240/28",
592
+ "172.162.248.64/28",
593
+ "172.170.1.80/28",
594
+ "172.170.225.0/28",
595
+ "172.170.241.80/28",
596
+ "172.172.206.48/28",
597
+ "172.175.152.224/28",
598
+ "172.178.140.144/28",
599
+ "172.178.141.112/28",
600
+ "172.178.141.128/28",
601
+ "172.183.143.224/28",
602
+ "172.183.222.128/28",
603
+ "172.192.112.208/28",
604
+ "172.197.160.192/28",
605
+ "172.197.203.16/28",
606
+ "172.198.58.176/28",
607
+ "172.198.78.192/28",
608
+ "172.198.79.112/28",
609
+ "172.198.161.128/28",
610
+ "172.199.137.80/28",
611
+ "172.204.28.224/28",
612
+ "172.204.96.80/28",
613
+ "172.205.189.192/28",
614
+ "172.206.38.240/28",
615
+ "172.207.1.32/28",
616
+ "172.212.172.160/28",
617
+ "172.215.215.32/28",
618
+ "191.232.238.96/28",
619
+ "191.233.197.0/28",
620
+ "191.233.199.160/28",
621
+ "191.234.167.144/28",
622
+ "191.235.99.160/28",
623
+ "191.237.249.64/28"
624
+ ],
625
+ ipv6: []
626
+ },
627
+ {
628
+ bot: "PerplexityBot",
629
+ url: "https://www.perplexity.com/perplexitybot.json",
630
+ ipv4: [
631
+ "3.222.232.239/32",
632
+ "3.224.62.45/32",
633
+ "18.97.1.228/32",
634
+ "18.97.9.96/32",
635
+ "18.97.9.97/32",
636
+ "18.97.9.98/32",
637
+ "18.97.9.99/32",
638
+ "18.97.9.100/32",
639
+ "18.97.9.101/32",
640
+ "18.97.9.102/32",
641
+ "18.97.9.103/32",
642
+ "18.210.92.235/32",
643
+ "107.20.236.150/32"
644
+ ],
645
+ ipv6: []
646
+ },
647
+ {
648
+ bot: "Perplexity-User",
649
+ url: "https://www.perplexity.com/perplexity-user.json",
650
+ ipv4: [
651
+ "18.97.43.80/32",
652
+ "18.97.43.81/32",
653
+ "18.97.43.82/32",
654
+ "18.97.43.83/32",
655
+ "18.97.43.84/32",
656
+ "18.97.43.85/32",
657
+ "18.97.43.86/32",
658
+ "18.97.43.87/32",
659
+ "34.193.163.52/32",
660
+ "44.208.221.197/32"
661
+ ],
662
+ ipv6: []
663
+ },
664
+ {
665
+ bot: "MistralAI-User",
666
+ url: "https://mistral.ai/mistralai-user-ips.json",
667
+ ipv4: [
668
+ "20.240.160.1/32",
669
+ "20.240.160.161/32",
670
+ "20.240.194.83/32",
671
+ "51.12.243.114/32"
672
+ ],
673
+ ipv6: []
674
+ },
675
+ {
676
+ bot: "CCBot",
677
+ url: "https://index.commoncrawl.org/ccbot.json",
678
+ ipv4: [
679
+ "3.41.188.32/29",
680
+ "18.97.9.168/29",
681
+ "18.97.14.80/29",
682
+ "18.97.14.88/30"
683
+ ],
684
+ ipv6: [
685
+ "2600:1f28:365:8000::/56"
686
+ ]
687
+ },
688
+ {
689
+ bot: "DuckAssistBot",
690
+ url: "https://duckduckgo.com/duckassistbot.json",
691
+ ipv4: [
692
+ "4.144.148.23/32",
693
+ "4.144.182.50/32",
694
+ "4.144.227.142/32",
695
+ "4.144.251.39/32",
696
+ "4.149.142.7/32",
697
+ "4.149.159.71/32",
698
+ "4.149.159.102/32",
699
+ "4.149.216.220/32",
700
+ "4.150.142.218/32",
701
+ "4.154.193.167/32",
702
+ "4.156.30.123/32",
703
+ "4.156.136.79/32",
704
+ "4.156.154.107/32",
705
+ "4.157.77.76/32",
706
+ "4.172.49.103/32",
707
+ "4.177.16.196/32",
708
+ "4.182.10.198/32",
709
+ "4.182.131.108/32",
710
+ "4.195.133.120/32",
711
+ "4.201.125.59/32",
712
+ "4.201.141.71/32",
713
+ "4.201.197.203/32",
714
+ "4.201.206.133/32",
715
+ "4.201.220.8/32",
716
+ "4.207.220.92/32",
717
+ "4.209.224.56/32",
718
+ "4.213.46.14/32",
719
+ "4.226.40.135/32",
720
+ "4.228.76.163/32",
721
+ "4.237.155.54/32",
722
+ "4.237.244.80/32",
723
+ "4.242.119.13/32",
724
+ "4.246.10.252/32",
725
+ "4.248.234.26/32",
726
+ "4.249.216.104/32",
727
+ "4.249.223.51/32",
728
+ "4.249.238.11/32",
729
+ "4.254.123.56/32",
730
+ "4.255.35.121/32",
731
+ "4.255.39.80/32",
732
+ "13.86.35.212/32",
733
+ "13.89.106.77/32",
734
+ "13.90.178.139/32",
735
+ "20.3.1.178/32",
736
+ "20.3.60.212/32",
737
+ "20.8.252.26/32",
738
+ "20.9.114.242/32",
739
+ "20.12.141.99/32",
740
+ "20.12.249.123/32",
741
+ "20.12.252.21/32",
742
+ "20.13.44.19/32",
743
+ "20.15.142.178/32",
744
+ "20.23.88.231/32",
745
+ "20.29.149.44/32",
746
+ "20.29.154.56/32",
747
+ "20.40.133.240/32",
748
+ "20.40.147.172/32",
749
+ "20.43.150.85/32",
750
+ "20.43.150.93/32",
751
+ "20.43.152.28/32",
752
+ "20.43.172.120/32",
753
+ "20.44.222.1/32",
754
+ "20.49.129.236/32",
755
+ "20.49.136.28/32",
756
+ "20.50.48.159/32",
757
+ "20.50.48.192/32",
758
+ "20.50.49.0/32",
759
+ "20.50.49.25/32",
760
+ "20.50.49.40/32",
761
+ "20.50.49.55/32",
762
+ "20.50.49.237/32",
763
+ "20.50.50.46/32",
764
+ "20.50.50.118/32",
765
+ "20.50.50.121/32",
766
+ "20.50.50.123/32",
767
+ "20.50.50.130/32",
768
+ "20.50.50.134/32",
769
+ "20.50.50.145/32",
770
+ "20.50.50.146/32",
771
+ "20.50.50.163/32",
772
+ "20.50.168.91/32",
773
+ "20.53.78.106/32",
774
+ "20.53.78.123/32",
775
+ "20.53.78.138/32",
776
+ "20.53.78.144/32",
777
+ "20.53.78.236/32",
778
+ "20.53.91.2/32",
779
+ "20.53.92.211/32",
780
+ "20.53.134.160/32",
781
+ "20.54.224.39/32",
782
+ "20.56.197.58/32",
783
+ "20.56.197.63/32",
784
+ "20.59.0.65/32",
785
+ "20.61.34.40/32",
786
+ "20.61.142.192/32",
787
+ "20.62.224.44/32",
788
+ "20.64.185.45/32",
789
+ "20.69.74.250/32",
790
+ "20.69.129.205/32",
791
+ "20.69.131.45/32",
792
+ "20.69.138.149/32",
793
+ "20.69.138.189/32",
794
+ "20.69.144.137/32",
795
+ "20.69.146.171/32",
796
+ "20.69.147.21/32",
797
+ "20.69.171.204/32",
798
+ "20.71.12.143/32",
799
+ "20.71.69.210/32",
800
+ "20.72.197.110/32",
801
+ "20.72.203.250/32",
802
+ "20.72.218.29/32",
803
+ "20.72.221.33/32",
804
+ "20.72.221.45/32",
805
+ "20.72.225.13/32",
806
+ "20.72.242.93/32",
807
+ "20.72.242.209/32",
808
+ "20.73.132.240/32",
809
+ "20.73.202.147/32",
810
+ "20.75.144.152/32",
811
+ "20.75.254.61/32",
812
+ "20.77.146.108/32",
813
+ "20.79.226.26/32",
814
+ "20.79.238.198/32",
815
+ "20.79.239.66/32",
816
+ "20.80.114.203/32",
817
+ "20.80.120.41/32",
818
+ "20.80.129.80/32",
819
+ "20.80.135.7/32",
820
+ "20.80.156.88/32",
821
+ "20.81.115.13/32",
822
+ "20.82.24.207/32",
823
+ "20.84.138.61/32",
824
+ "20.84.219.45/32",
825
+ "20.84.251.223/32",
826
+ "20.85.138.75/32",
827
+ "20.85.167.56/32",
828
+ "20.85.187.146/32",
829
+ "20.88.168.65/32",
830
+ "20.93.28.24/32",
831
+ "20.93.49.96/32",
832
+ "20.99.154.113/32",
833
+ "20.99.255.235/32",
834
+ "20.100.136.36/32",
835
+ "20.100.140.155/32",
836
+ "20.101.17.173/32",
837
+ "20.102.34.205/32",
838
+ "20.109.129.162/32",
839
+ "20.109.130.190/32",
840
+ "20.109.241.18/32",
841
+ "20.112.58.44/32",
842
+ "20.113.3.121/32",
843
+ "20.113.14.159/32",
844
+ "20.115.181.187/32",
845
+ "20.118.11.251/32",
846
+ "20.119.127.146/32",
847
+ "20.121.75.32/32",
848
+ "20.166.171.150/32",
849
+ "20.170.75.54/32",
850
+ "20.175.232.228/32",
851
+ "20.185.79.15/32",
852
+ "20.185.79.47/32",
853
+ "20.190.21.172/32",
854
+ "20.191.44.16/32",
855
+ "20.191.44.22/32",
856
+ "20.191.44.119/32",
857
+ "20.191.44.234/32",
858
+ "20.191.45.212/32",
859
+ "20.193.12.126/32",
860
+ "20.193.24.10/32",
861
+ "20.193.24.251/32",
862
+ "20.193.25.197/32",
863
+ "20.193.27.215/32",
864
+ "20.193.45.113/32",
865
+ "20.195.58.189/32",
866
+ "20.195.108.47/32",
867
+ "20.197.209.11/32",
868
+ "20.197.209.27/32",
869
+ "20.198.132.126/32",
870
+ "20.198.152.208/32",
871
+ "20.201.15.208/32",
872
+ "20.204.228.200/32",
873
+ "20.204.240.172/32",
874
+ "20.204.241.148/32",
875
+ "20.204.242.19/32",
876
+ "20.204.242.101/32",
877
+ "20.204.243.55/32",
878
+ "20.204.246.81/32",
879
+ "20.204.246.254/32",
880
+ "20.207.72.11/32",
881
+ "20.207.72.21/32",
882
+ "20.207.72.110/32",
883
+ "20.207.72.113/32",
884
+ "20.207.97.190/32",
885
+ "20.207.99.197/32",
886
+ "20.207.107.181/32",
887
+ "20.207.117.66/32",
888
+ "20.212.90.107/32",
889
+ "20.212.139.34/32",
890
+ "20.216.200.223/32",
891
+ "20.219.43.246/32",
892
+ "20.219.45.67/32",
893
+ "20.219.45.190/32",
894
+ "20.221.10.115/32",
895
+ "20.221.84.185/32",
896
+ "20.226.133.105/32",
897
+ "20.231.254.179/32",
898
+ "20.232.51.46/32",
899
+ "20.232.249.95/32",
900
+ "20.236.40.93/32",
901
+ "20.236.195.196/32",
902
+ "20.236.198.192/32",
903
+ "20.236.227.113/32",
904
+ "20.236.233.23/32",
905
+ "20.236.247.180/32",
906
+ "20.237.1.51/32",
907
+ "20.241.135.19/32",
908
+ "20.241.147.151/32",
909
+ "20.241.153.203/32",
910
+ "20.241.164.5/32",
911
+ "20.241.241.100/32",
912
+ "20.242.133.53/32",
913
+ "20.242.135.165/32",
914
+ "20.242.211.139/32",
915
+ "20.242.215.53/32",
916
+ "20.242.237.240/32",
917
+ "20.246.132.168/32",
918
+ "20.246.225.34/32",
919
+ "20.247.235.11/32",
920
+ "20.250.51.113/32",
921
+ "20.252.9.6/32",
922
+ "20.252.16.193/32",
923
+ "20.252.41.18/32",
924
+ "20.252.63.162/32",
925
+ "20.252.88.10/32",
926
+ "20.253.59.76/32",
927
+ "20.253.96.199/32",
928
+ "20.253.114.51/32",
929
+ "40.64.67.220/32",
930
+ "40.64.78.45/32",
931
+ "40.64.88.145/32",
932
+ "40.64.105.247/32",
933
+ "40.64.106.11/32",
934
+ "40.64.106.152/32",
935
+ "40.65.78.86/32",
936
+ "40.76.162.17/32",
937
+ "40.76.162.191/32",
938
+ "40.76.162.208/32",
939
+ "40.76.162.247/32",
940
+ "40.76.163.7/32",
941
+ "40.76.163.23/32",
942
+ "40.76.173.151/32",
943
+ "40.81.250.205/32",
944
+ "40.82.218.203/32",
945
+ "40.88.21.235/32",
946
+ "40.88.195.62/32",
947
+ "40.89.243.175/32",
948
+ "40.114.182.45/32",
949
+ "40.114.182.153/32",
950
+ "40.114.182.172/32",
951
+ "40.114.183.88/32",
952
+ "40.114.183.196/32",
953
+ "40.114.183.251/32",
954
+ "40.119.232.50/32",
955
+ "40.119.232.146/32",
956
+ "40.119.232.215/32",
957
+ "40.119.232.218/32",
958
+ "40.119.232.251/32",
959
+ "40.121.121.54/32",
960
+ "40.127.154.196/32",
961
+ "48.192.16.86/32",
962
+ "48.192.74.178/32",
963
+ "48.200.33.227/32",
964
+ "48.202.155.200/32",
965
+ "48.202.171.124/32",
966
+ "48.204.32.87/32",
967
+ "48.206.18.152/32",
968
+ "48.217.23.236/32",
969
+ "48.217.129.210/32",
970
+ "48.217.212.89/32",
971
+ "48.223.209.110/32",
972
+ "51.8.31.28/32",
973
+ "51.8.71.117/32",
974
+ "51.8.253.152/32",
975
+ "51.104.144.31/32",
976
+ "51.104.146.225/32",
977
+ "51.104.146.235/32",
978
+ "51.104.160.167/32",
979
+ "51.104.160.177/32",
980
+ "51.104.161.32/32",
981
+ "51.104.162.149/32",
982
+ "51.104.163.250/32",
983
+ "51.104.164.109/32",
984
+ "51.104.164.147/32",
985
+ "51.104.164.189/32",
986
+ "51.104.164.215/32",
987
+ "51.104.166.111/32",
988
+ "51.104.167.19/32",
989
+ "51.104.167.52/32",
990
+ "51.104.167.54/32",
991
+ "51.104.167.61/32",
992
+ "51.104.167.71/32",
993
+ "51.104.167.87/32",
994
+ "51.104.167.88/32",
995
+ "51.104.167.95/32",
996
+ "51.104.167.96/32",
997
+ "51.104.167.104/32",
998
+ "51.104.167.110/32",
999
+ "51.104.180.26/32",
1000
+ "51.104.180.47/32",
1001
+ "51.104.180.53/32",
1002
+ "51.107.40.209/32",
1003
+ "51.116.131.221/32",
1004
+ "51.120.48.122/32",
1005
+ "51.138.90.161/32",
1006
+ "51.138.90.206/32",
1007
+ "51.138.90.233/32",
1008
+ "51.143.114.45/32",
1009
+ "51.145.185.16/32",
1010
+ "52.142.24.149/32",
1011
+ "52.142.26.175/32",
1012
+ "52.143.95.162/32",
1013
+ "52.143.95.204/32",
1014
+ "52.143.241.111/32",
1015
+ "52.143.242.6/32",
1016
+ "52.143.243.117/32",
1017
+ "52.143.244.81/32",
1018
+ "52.143.247.235/32",
1019
+ "52.146.57.51/32",
1020
+ "52.146.58.236/32",
1021
+ "52.146.59.12/32",
1022
+ "52.146.59.154/32",
1023
+ "52.146.59.156/32",
1024
+ "52.146.63.80/32",
1025
+ "52.148.161.87/32",
1026
+ "52.148.165.38/32",
1027
+ "52.149.25.43/32",
1028
+ "52.149.28.18/32",
1029
+ "52.149.28.83/32",
1030
+ "52.149.30.45/32",
1031
+ "52.149.56.151/32",
1032
+ "52.149.58.27/32",
1033
+ "52.149.58.69/32",
1034
+ "52.149.58.139/32",
1035
+ "52.149.58.173/32",
1036
+ "52.149.60.38/32",
1037
+ "52.149.61.51/32",
1038
+ "52.154.60.82/32",
1039
+ "52.154.169.50/32",
1040
+ "52.154.169.200/32",
1041
+ "52.154.170.26/32",
1042
+ "52.154.170.28/32",
1043
+ "52.154.170.88/32",
1044
+ "52.154.170.96/32",
1045
+ "52.154.170.113/32",
1046
+ "52.154.170.117/32",
1047
+ "52.154.170.122/32",
1048
+ "52.154.170.209/32",
1049
+ "52.154.170.229/32",
1050
+ "52.154.170.243/32",
1051
+ "52.154.171.0/32",
1052
+ "52.154.171.44/32",
1053
+ "52.154.171.70/32",
1054
+ "52.154.171.87/32",
1055
+ "52.154.171.150/32",
1056
+ "52.154.171.196/32",
1057
+ "52.154.171.205/32",
1058
+ "52.154.171.235/32",
1059
+ "52.154.171.250/32",
1060
+ "52.154.172.2/32",
1061
+ "52.154.204.93/32",
1062
+ "52.185.93.208/32",
1063
+ "52.186.37.211/32",
1064
+ "52.188.89.106/32",
1065
+ "52.189.70.103/32",
1066
+ "52.190.37.160/32",
1067
+ "52.191.82.242/32",
1068
+ "52.191.222.158/32",
1069
+ "52.224.16.221/32",
1070
+ "52.224.16.229/32",
1071
+ "52.224.19.152/32",
1072
+ "52.224.20.174/32",
1073
+ "52.224.20.181/32",
1074
+ "52.224.20.186/32",
1075
+ "52.224.20.190/32",
1076
+ "52.224.20.193/32",
1077
+ "52.224.20.203/32",
1078
+ "52.224.20.204/32",
1079
+ "52.224.20.223/32",
1080
+ "52.224.20.227/32",
1081
+ "52.224.20.249/32",
1082
+ "52.224.21.4/32",
1083
+ "52.224.21.19/32",
1084
+ "52.224.21.20/32",
1085
+ "52.224.21.23/32",
1086
+ "52.224.21.27/32",
1087
+ "52.224.21.49/32",
1088
+ "52.224.21.51/32",
1089
+ "52.224.21.53/32",
1090
+ "52.224.21.55/32",
1091
+ "52.224.21.61/32",
1092
+ "52.224.147.21/32",
1093
+ "52.224.191.245/32",
1094
+ "52.242.224.168/32",
1095
+ "52.250.46.221/32",
1096
+ "57.151.44.140/32",
1097
+ "57.152.17.237/32",
1098
+ "57.152.62.107/32",
1099
+ "57.152.72.128/32",
1100
+ "57.155.18.44/32",
1101
+ "57.165.205.172/32",
1102
+ "57.167.88.38/32",
1103
+ "64.236.15.33/32",
1104
+ "64.236.93.100/32",
1105
+ "64.236.118.43/32",
1106
+ "68.219.152.220/32",
1107
+ "72.144.95.185/32",
1108
+ "74.163.169.106/32",
1109
+ "74.163.208.206/32",
1110
+ "74.179.200.126/32",
1111
+ "74.179.232.116/32",
1112
+ "74.242.194.48/32",
1113
+ "98.70.219.37/32",
1114
+ "104.43.54.127/32",
1115
+ "104.43.55.116/32",
1116
+ "104.43.55.117/32",
1117
+ "104.43.55.166/32",
1118
+ "104.43.55.167/32",
1119
+ "108.141.83.74/32",
1120
+ "128.203.82.154/32",
1121
+ "128.203.132.152/32",
1122
+ "128.203.181.79/32",
1123
+ "128.203.214.241/32",
1124
+ "128.203.236.110/32",
1125
+ "130.107.228.224/32",
1126
+ "131.145.39.118/32",
1127
+ "131.189.183.241/32",
1128
+ "132.164.209.198/32",
1129
+ "132.196.106.146/32",
1130
+ "132.220.1.71/32",
1131
+ "134.33.207.189/32",
1132
+ "135.171.251.169/32",
1133
+ "135.233.63.237/32",
1134
+ "135.234.221.112/32",
1135
+ "135.235.183.95/32",
1136
+ "172.168.12.93/32",
1137
+ "172.168.43.43/32",
1138
+ "172.168.51.216/32",
1139
+ "172.168.53.53/32",
1140
+ "172.168.81.217/32",
1141
+ "172.168.94.160/32",
1142
+ "172.168.115.250/32",
1143
+ "172.168.133.76/32",
1144
+ "172.168.137.102/32",
1145
+ "172.168.152.88/32",
1146
+ "172.168.173.230/32",
1147
+ "172.168.190.186/32",
1148
+ "172.168.227.120/32",
1149
+ "172.168.254.119/32",
1150
+ "172.169.7.33/32",
1151
+ "172.169.17.165/32",
1152
+ "172.169.28.184/32",
1153
+ "172.169.36.43/32",
1154
+ "172.169.53.208/32",
1155
+ "172.169.60.134/32",
1156
+ "172.169.93.148/32",
1157
+ "172.169.164.109/32",
1158
+ "172.169.177.131/32",
1159
+ "172.169.181.237/32",
1160
+ "172.171.37.221/32",
1161
+ "172.179.105.87/32",
1162
+ "172.179.128.118/32",
1163
+ "172.188.250.220/32",
1164
+ "172.189.40.18/32",
1165
+ "172.193.184.42/32",
1166
+ "172.193.197.146/32",
1167
+ "172.193.245.229/32",
1168
+ "172.194.141.49/32",
1169
+ "172.199.55.212/32",
1170
+ "172.210.111.68/32",
1171
+ "191.233.3.197/32",
1172
+ "191.233.3.202/32",
1173
+ "191.234.216.4/32",
1174
+ "191.234.216.178/32",
1175
+ "191.235.201.214/32",
1176
+ "191.235.202.38/32",
1177
+ "191.235.202.48/32"
1178
+ ],
1179
+ ipv6: []
1180
+ }
1181
+ ]
1182
+ };
1183
+
1184
+ // src/logic/decide.ts
1185
+ var MAX_SCANNED_USER_AGENT = 1024;
1186
+ var PREFIX = 3;
1187
+ var tokensByPrefix = /* @__PURE__ */ new Map();
1188
+ for (const token of agents_default.tokens) {
1189
+ const key = token.slice(0, PREFIX);
1190
+ const list = tokensByPrefix.get(key);
1191
+ if (list) {
1192
+ list.push(token);
1193
+ } else {
1194
+ tokensByPrefix.set(key, [token]);
1195
+ }
1196
+ }
1197
+ var agentRanges = new BlockList();
1198
+ var addRanges = (cidrs, type) => {
1199
+ for (const cidr of cidrs) {
1200
+ const [address = "", prefix] = cidr.split("/");
1201
+ agentRanges.addSubnet(address, Number(prefix), type);
1202
+ }
1203
+ };
1204
+ for (const source of ip_ranges_generated_default.sources) {
1205
+ addRanges(source.ipv4, "ipv4");
1206
+ addRanges(source.ipv6, "ipv6");
1207
+ }
1208
+ var isAgentIp = (ip) => agentRanges.check(ip, ip.includes(":") ? "ipv6" : "ipv4");
1209
+ function hasAgentToken(userAgent) {
1210
+ const text = userAgent.slice(0, MAX_SCANNED_USER_AGENT).toLowerCase();
1211
+ for (let i = 0; i + PREFIX <= text.length; i++) {
1212
+ const candidates = tokensByPrefix.get(text.slice(i, i + PREFIX));
1213
+ if (candidates) {
1214
+ for (const token of candidates) {
1215
+ if (text.startsWith(token, i)) {
1216
+ return true;
1217
+ }
1218
+ }
1219
+ }
1220
+ }
1221
+ return false;
1222
+ }
1223
+ function decide({ headers, ip }) {
1224
+ const userAgent = headers["user-agent"];
1225
+ return userAgent !== void 0 && hasAgentToken(userAgent) || headers["signature-agent"] !== void 0 || headers.dpop !== void 0 || headers.authorization?.toLowerCase() === "dpop" || ip !== null && isAgentIp(ip);
1226
+ }
1227
+
1228
+ // src/match-key.ts
1229
+ var encoder = new TextEncoder();
1230
+ var keys = /* @__PURE__ */ new Map();
1231
+ function importOrgKey(orgKey) {
1232
+ let key = keys.get(orgKey);
1233
+ if (!key) {
1234
+ key = crypto.subtle.importKey(
1235
+ "raw",
1236
+ encoder.encode(orgKey),
1237
+ { name: "HMAC", hash: "SHA-256" },
1238
+ false,
1239
+ ["sign"]
1240
+ );
1241
+ key.catch(() => keys.delete(orgKey));
1242
+ keys.set(orgKey, key);
1243
+ }
1244
+ return key;
1245
+ }
1246
+ var toHex = (bytes) => Array.from(
1247
+ new Uint8Array(bytes),
1248
+ (byte) => byte.toString(16).padStart(2, "0")
1249
+ ).join("");
1250
+ async function deriveMatchKey(orgKey, ip) {
1251
+ const signature = await crypto.subtle.sign(
1252
+ "HMAC",
1253
+ await importOrgKey(orgKey),
1254
+ encoder.encode(ip)
1255
+ );
1256
+ return toHex(signature);
1257
+ }
1258
+
1259
+ // src/version.ts
1260
+ var RELAY_VERSION = true ? "0.1.1" : "0.0.0-dev";
1261
+
1262
+ // src/wait-until.ts
1263
+ var REQUEST_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
1264
+ function vercelWaitUntil() {
1265
+ const store = Reflect.get(
1266
+ globalThis,
1267
+ REQUEST_CONTEXT
1268
+ );
1269
+ const context = store?.get?.();
1270
+ return context?.waitUntil ? (promise) => context.waitUntil?.(promise) : void 0;
1271
+ }
1272
+
1273
+ // src/index.ts
1274
+ function isAgent(request) {
1275
+ try {
1276
+ const headers = readCappedHeaders(request.headers);
1277
+ return decide({ headers, ip: clientIp(request.headers) });
1278
+ } catch {
1279
+ return false;
1280
+ }
1281
+ }
1282
+ function recordAgentVisit(request, options = {}) {
1283
+ try {
1284
+ const key = readKey(options.key);
1285
+ if (!key) {
1286
+ return;
1287
+ }
1288
+ const apiUrl = resolveApiUrl(options);
1289
+ if (!apiUrl) {
1290
+ return;
1291
+ }
1292
+ const omitted = omitSet(options.omit);
1293
+ const ip = clientIp(request.headers);
1294
+ const capped = readCappedHeaders(request.headers);
1295
+ const headers = {};
1296
+ for (const [name, value] of Object.entries(capped)) {
1297
+ if (!omitted.has(name)) {
1298
+ headers[name] = value;
1299
+ }
1300
+ }
1301
+ const url = new URL(request.url);
1302
+ const record = {
1303
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
1304
+ method: request.method,
1305
+ host: url.hostname,
1306
+ path: url.pathname + url.search,
1307
+ headers,
1308
+ sourceEventId: crypto.randomUUID(),
1309
+ relayVersion: RELAY_VERSION
1310
+ };
1311
+ if (capped["user-agent"] !== void 0 && !omitted.has("user-agent")) {
1312
+ record.userAgent = capped["user-agent"];
1313
+ }
1314
+ if (capped.referer !== void 0 && !omitted.has("referer")) {
1315
+ record.referer = capped.referer;
1316
+ }
1317
+ const ingestUrl = `${apiUrl}/api/v2/agent-traffic/ingest/middleware/${key.ingestToken}`;
1318
+ const withMatchKey = async () => {
1319
+ if (ip !== null && !omitted.has("matchkey")) {
1320
+ record.matchKey = await deriveMatchKey(key.orgKey, ip).catch(
1321
+ () => void 0
1322
+ );
1323
+ }
1324
+ await postEvent(ingestUrl, JSON.stringify({ requests: [record] }));
1325
+ };
1326
+ schedule(withMatchKey(), options.waitUntil);
1327
+ } catch {
1328
+ }
1329
+ }
1330
+ var warnedRegion = false;
1331
+ function resolveApiUrl(options) {
1332
+ if (options.apiUrl !== void 0) {
1333
+ return options.apiUrl.replace(/\/+$/, "");
1334
+ }
1335
+ const region = options.region ?? "us";
1336
+ if (Object.hasOwn(settings.apiUrls, region)) {
1337
+ return settings.apiUrls[region];
1338
+ }
1339
+ if (!warnedRegion) {
1340
+ warnedRegion = true;
1341
+ console.warn(
1342
+ `[@waniwani/relay] Unknown region ${JSON.stringify(region)}, so no agent visits are recorded. Use "us" or "eu".`
1343
+ );
1344
+ }
1345
+ return null;
1346
+ }
1347
+ function omitSet(omit) {
1348
+ const names = new Set((omit ?? []).map((name) => name.toLowerCase()));
1349
+ if (names.has("useragent")) {
1350
+ names.add("user-agent");
1351
+ }
1352
+ return names;
1353
+ }
1354
+ function schedule(work, waitUntil) {
1355
+ const settled = work.then(
1356
+ () => void 0,
1357
+ () => void 0
1358
+ );
1359
+ try {
1360
+ (waitUntil ?? vercelWaitUntil())?.(settled);
1361
+ } catch {
1362
+ }
1363
+ }
1364
+ export {
1365
+ isAgent,
1366
+ recordAgentVisit
1367
+ };
1368
+ //# sourceMappingURL=index.js.map