@url-sanitize/core 0.1.4 → 1.0.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/README.md +19 -0
- package/dist/index.d.ts +619 -1
- package/dist/index.js +200 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,25 @@ type SanitizeResult =
|
|
|
42
42
|
- Factory pattern (`compileSanitizer(catalog)`) — no module-level cache, no singletons.
|
|
43
43
|
- Discriminated union return type — exhaustive `switch (result.kind)`.
|
|
44
44
|
|
|
45
|
+
## Custom catalogs
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { defineCatalog, mergeCatalogs, sanitizerCatalogJsonSchema } from '@url-sanitize/core';
|
|
49
|
+
|
|
50
|
+
const custom = defineCatalog({
|
|
51
|
+
version: 'custom-1',
|
|
52
|
+
generatedAt: new Date().toISOString(),
|
|
53
|
+
sources: [{ name: 'custom' }],
|
|
54
|
+
rules: [{ kind: 'strip-param', source: 'custom', provider: 'local', paramPattern: 'utm_.+' }]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const merged = mergeCatalogs(custom);
|
|
58
|
+
console.log(sanitizerCatalogJsonSchema.$id);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`mergeCatalogs()` preserves input order and concatenates sources/rules. It does
|
|
62
|
+
not dedupe, reorder, or apply source precedence.
|
|
63
|
+
|
|
45
64
|
## License
|
|
46
65
|
|
|
47
66
|
MIT.
|
package/dist/index.d.ts
CHANGED
|
@@ -73,7 +73,625 @@ interface SanitizerOptions {
|
|
|
73
73
|
domainBlocking?: boolean;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
declare function defineCatalog(catalog: SanitizerCatalog): SanitizerCatalog;
|
|
77
|
+
declare function mergeCatalogs(first: SanitizerCatalog, ...rest: SanitizerCatalog[]): SanitizerCatalog;
|
|
78
|
+
|
|
76
79
|
type Sanitizer = (input: string) => SanitizeResult;
|
|
77
80
|
declare function compileSanitizer(catalog: SanitizerCatalog, options?: SanitizerOptions): Sanitizer;
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
declare const sanitizerOptionsJsonSchema: {
|
|
83
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
84
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/options.json";
|
|
85
|
+
readonly title: "url-sanitize options";
|
|
86
|
+
readonly type: "object";
|
|
87
|
+
readonly additionalProperties: false;
|
|
88
|
+
readonly properties: {
|
|
89
|
+
readonly stripReferralMarketing: {
|
|
90
|
+
readonly type: "boolean";
|
|
91
|
+
};
|
|
92
|
+
readonly unwrapRedirects: {
|
|
93
|
+
readonly type: "boolean";
|
|
94
|
+
};
|
|
95
|
+
readonly domainBlocking: {
|
|
96
|
+
readonly type: "boolean";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
declare const sanitizerCatalogJsonSchema: {
|
|
101
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
102
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/catalog.json";
|
|
103
|
+
readonly title: "url-sanitize catalog";
|
|
104
|
+
readonly type: "object";
|
|
105
|
+
readonly required: readonly ["version", "generatedAt", "sources", "rules"];
|
|
106
|
+
readonly additionalProperties: false;
|
|
107
|
+
readonly properties: {
|
|
108
|
+
readonly version: {
|
|
109
|
+
readonly type: "string";
|
|
110
|
+
};
|
|
111
|
+
readonly generatedAt: {
|
|
112
|
+
readonly type: "string";
|
|
113
|
+
};
|
|
114
|
+
readonly sources: {
|
|
115
|
+
readonly type: "array";
|
|
116
|
+
readonly items: {
|
|
117
|
+
readonly type: "object";
|
|
118
|
+
readonly required: readonly ["name"];
|
|
119
|
+
readonly additionalProperties: false;
|
|
120
|
+
readonly properties: {
|
|
121
|
+
readonly name: {
|
|
122
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
123
|
+
};
|
|
124
|
+
readonly version: {
|
|
125
|
+
readonly type: "string";
|
|
126
|
+
};
|
|
127
|
+
readonly hash: {
|
|
128
|
+
readonly type: "string";
|
|
129
|
+
};
|
|
130
|
+
readonly license: {
|
|
131
|
+
readonly type: "string";
|
|
132
|
+
};
|
|
133
|
+
readonly upstream: {
|
|
134
|
+
readonly type: "string";
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
readonly rules: {
|
|
140
|
+
readonly type: "array";
|
|
141
|
+
readonly items: {
|
|
142
|
+
readonly oneOf: readonly [{
|
|
143
|
+
readonly type: "object";
|
|
144
|
+
readonly required: readonly ["kind", "source", "provider", "paramPattern"];
|
|
145
|
+
readonly additionalProperties: false;
|
|
146
|
+
readonly properties: {
|
|
147
|
+
readonly kind: {
|
|
148
|
+
readonly const: "strip-param";
|
|
149
|
+
};
|
|
150
|
+
readonly paramPattern: {
|
|
151
|
+
readonly type: "string";
|
|
152
|
+
};
|
|
153
|
+
readonly isReferralMarketing: {
|
|
154
|
+
readonly type: "boolean";
|
|
155
|
+
};
|
|
156
|
+
readonly source: {
|
|
157
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
158
|
+
};
|
|
159
|
+
readonly provider: {
|
|
160
|
+
readonly type: "string";
|
|
161
|
+
};
|
|
162
|
+
readonly urlPattern: {
|
|
163
|
+
readonly type: "string";
|
|
164
|
+
};
|
|
165
|
+
readonly exceptions: {
|
|
166
|
+
readonly type: "array";
|
|
167
|
+
readonly items: {
|
|
168
|
+
readonly type: "string";
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}, {
|
|
173
|
+
readonly type: "object";
|
|
174
|
+
readonly required: readonly ["kind", "source", "provider", "pattern", "replacement"];
|
|
175
|
+
readonly additionalProperties: false;
|
|
176
|
+
readonly properties: {
|
|
177
|
+
readonly kind: {
|
|
178
|
+
readonly const: "raw-replace";
|
|
179
|
+
};
|
|
180
|
+
readonly pattern: {
|
|
181
|
+
readonly type: "string";
|
|
182
|
+
};
|
|
183
|
+
readonly replacement: {
|
|
184
|
+
readonly type: "string";
|
|
185
|
+
};
|
|
186
|
+
readonly source: {
|
|
187
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
188
|
+
};
|
|
189
|
+
readonly provider: {
|
|
190
|
+
readonly type: "string";
|
|
191
|
+
};
|
|
192
|
+
readonly urlPattern: {
|
|
193
|
+
readonly type: "string";
|
|
194
|
+
};
|
|
195
|
+
readonly exceptions: {
|
|
196
|
+
readonly type: "array";
|
|
197
|
+
readonly items: {
|
|
198
|
+
readonly type: "string";
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
}, {
|
|
203
|
+
readonly type: "object";
|
|
204
|
+
readonly required: readonly ["kind", "source", "provider", "pattern", "captureGroup"];
|
|
205
|
+
readonly additionalProperties: false;
|
|
206
|
+
readonly properties: {
|
|
207
|
+
readonly kind: {
|
|
208
|
+
readonly const: "unwrap-redirect";
|
|
209
|
+
};
|
|
210
|
+
readonly pattern: {
|
|
211
|
+
readonly type: "string";
|
|
212
|
+
};
|
|
213
|
+
readonly captureGroup: {
|
|
214
|
+
readonly type: "integer";
|
|
215
|
+
readonly minimum: 0;
|
|
216
|
+
};
|
|
217
|
+
readonly source: {
|
|
218
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
219
|
+
};
|
|
220
|
+
readonly provider: {
|
|
221
|
+
readonly type: "string";
|
|
222
|
+
};
|
|
223
|
+
readonly urlPattern: {
|
|
224
|
+
readonly type: "string";
|
|
225
|
+
};
|
|
226
|
+
readonly exceptions: {
|
|
227
|
+
readonly type: "array";
|
|
228
|
+
readonly items: {
|
|
229
|
+
readonly type: "string";
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
}, {
|
|
234
|
+
readonly type: "object";
|
|
235
|
+
readonly required: readonly ["kind", "source", "provider", "urlPattern"];
|
|
236
|
+
readonly additionalProperties: false;
|
|
237
|
+
readonly properties: {
|
|
238
|
+
readonly kind: {
|
|
239
|
+
readonly const: "block-domain";
|
|
240
|
+
};
|
|
241
|
+
readonly source: {
|
|
242
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
243
|
+
};
|
|
244
|
+
readonly provider: {
|
|
245
|
+
readonly type: "string";
|
|
246
|
+
};
|
|
247
|
+
readonly urlPattern: {
|
|
248
|
+
readonly type: "string";
|
|
249
|
+
};
|
|
250
|
+
readonly exceptions: {
|
|
251
|
+
readonly type: "array";
|
|
252
|
+
readonly items: {
|
|
253
|
+
readonly type: "string";
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
}];
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
declare const sanitizeResultJsonSchema: {
|
|
263
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
264
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/result.json";
|
|
265
|
+
readonly title: "url-sanitize result";
|
|
266
|
+
readonly oneOf: readonly [{
|
|
267
|
+
readonly type: "object";
|
|
268
|
+
readonly required: readonly ["kind", "url"];
|
|
269
|
+
readonly additionalProperties: false;
|
|
270
|
+
readonly properties: {
|
|
271
|
+
readonly kind: {
|
|
272
|
+
readonly const: "unchanged";
|
|
273
|
+
};
|
|
274
|
+
readonly url: {
|
|
275
|
+
readonly type: "string";
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}, {
|
|
279
|
+
readonly type: "object";
|
|
280
|
+
readonly required: readonly ["kind", "original", "url", "strippedParams", "matchedRules"];
|
|
281
|
+
readonly additionalProperties: false;
|
|
282
|
+
readonly properties: {
|
|
283
|
+
readonly kind: {
|
|
284
|
+
readonly const: "cleaned";
|
|
285
|
+
};
|
|
286
|
+
readonly original: {
|
|
287
|
+
readonly type: "string";
|
|
288
|
+
};
|
|
289
|
+
readonly url: {
|
|
290
|
+
readonly type: "string";
|
|
291
|
+
};
|
|
292
|
+
readonly strippedParams: {
|
|
293
|
+
readonly type: "array";
|
|
294
|
+
readonly items: {
|
|
295
|
+
readonly type: "string";
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
readonly matchedRules: {
|
|
299
|
+
readonly type: "array";
|
|
300
|
+
readonly items: {
|
|
301
|
+
readonly type: "object";
|
|
302
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
303
|
+
readonly additionalProperties: false;
|
|
304
|
+
readonly properties: {
|
|
305
|
+
readonly source: {
|
|
306
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
307
|
+
};
|
|
308
|
+
readonly provider: {
|
|
309
|
+
readonly type: "string";
|
|
310
|
+
};
|
|
311
|
+
readonly kind: {
|
|
312
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
313
|
+
};
|
|
314
|
+
readonly detail: {
|
|
315
|
+
readonly type: "string";
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
}, {
|
|
322
|
+
readonly type: "object";
|
|
323
|
+
readonly required: readonly ["kind", "original", "url", "via"];
|
|
324
|
+
readonly additionalProperties: false;
|
|
325
|
+
readonly properties: {
|
|
326
|
+
readonly kind: {
|
|
327
|
+
readonly const: "redirected";
|
|
328
|
+
};
|
|
329
|
+
readonly original: {
|
|
330
|
+
readonly type: "string";
|
|
331
|
+
};
|
|
332
|
+
readonly url: {
|
|
333
|
+
readonly type: "string";
|
|
334
|
+
};
|
|
335
|
+
readonly via: {
|
|
336
|
+
readonly type: "object";
|
|
337
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
338
|
+
readonly additionalProperties: false;
|
|
339
|
+
readonly properties: {
|
|
340
|
+
readonly source: {
|
|
341
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
342
|
+
};
|
|
343
|
+
readonly provider: {
|
|
344
|
+
readonly type: "string";
|
|
345
|
+
};
|
|
346
|
+
readonly kind: {
|
|
347
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
348
|
+
};
|
|
349
|
+
readonly detail: {
|
|
350
|
+
readonly type: "string";
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
}, {
|
|
356
|
+
readonly type: "object";
|
|
357
|
+
readonly required: readonly ["kind", "original", "via"];
|
|
358
|
+
readonly additionalProperties: false;
|
|
359
|
+
readonly properties: {
|
|
360
|
+
readonly kind: {
|
|
361
|
+
readonly const: "blocked";
|
|
362
|
+
};
|
|
363
|
+
readonly original: {
|
|
364
|
+
readonly type: "string";
|
|
365
|
+
};
|
|
366
|
+
readonly via: {
|
|
367
|
+
readonly type: "object";
|
|
368
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
369
|
+
readonly additionalProperties: false;
|
|
370
|
+
readonly properties: {
|
|
371
|
+
readonly source: {
|
|
372
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
373
|
+
};
|
|
374
|
+
readonly provider: {
|
|
375
|
+
readonly type: "string";
|
|
376
|
+
};
|
|
377
|
+
readonly kind: {
|
|
378
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
379
|
+
};
|
|
380
|
+
readonly detail: {
|
|
381
|
+
readonly type: "string";
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
}];
|
|
387
|
+
};
|
|
388
|
+
declare const urlSanitizeJsonSchemas: {
|
|
389
|
+
readonly catalog: {
|
|
390
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
391
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/catalog.json";
|
|
392
|
+
readonly title: "url-sanitize catalog";
|
|
393
|
+
readonly type: "object";
|
|
394
|
+
readonly required: readonly ["version", "generatedAt", "sources", "rules"];
|
|
395
|
+
readonly additionalProperties: false;
|
|
396
|
+
readonly properties: {
|
|
397
|
+
readonly version: {
|
|
398
|
+
readonly type: "string";
|
|
399
|
+
};
|
|
400
|
+
readonly generatedAt: {
|
|
401
|
+
readonly type: "string";
|
|
402
|
+
};
|
|
403
|
+
readonly sources: {
|
|
404
|
+
readonly type: "array";
|
|
405
|
+
readonly items: {
|
|
406
|
+
readonly type: "object";
|
|
407
|
+
readonly required: readonly ["name"];
|
|
408
|
+
readonly additionalProperties: false;
|
|
409
|
+
readonly properties: {
|
|
410
|
+
readonly name: {
|
|
411
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
412
|
+
};
|
|
413
|
+
readonly version: {
|
|
414
|
+
readonly type: "string";
|
|
415
|
+
};
|
|
416
|
+
readonly hash: {
|
|
417
|
+
readonly type: "string";
|
|
418
|
+
};
|
|
419
|
+
readonly license: {
|
|
420
|
+
readonly type: "string";
|
|
421
|
+
};
|
|
422
|
+
readonly upstream: {
|
|
423
|
+
readonly type: "string";
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
readonly rules: {
|
|
429
|
+
readonly type: "array";
|
|
430
|
+
readonly items: {
|
|
431
|
+
readonly oneOf: readonly [{
|
|
432
|
+
readonly type: "object";
|
|
433
|
+
readonly required: readonly ["kind", "source", "provider", "paramPattern"];
|
|
434
|
+
readonly additionalProperties: false;
|
|
435
|
+
readonly properties: {
|
|
436
|
+
readonly kind: {
|
|
437
|
+
readonly const: "strip-param";
|
|
438
|
+
};
|
|
439
|
+
readonly paramPattern: {
|
|
440
|
+
readonly type: "string";
|
|
441
|
+
};
|
|
442
|
+
readonly isReferralMarketing: {
|
|
443
|
+
readonly type: "boolean";
|
|
444
|
+
};
|
|
445
|
+
readonly source: {
|
|
446
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
447
|
+
};
|
|
448
|
+
readonly provider: {
|
|
449
|
+
readonly type: "string";
|
|
450
|
+
};
|
|
451
|
+
readonly urlPattern: {
|
|
452
|
+
readonly type: "string";
|
|
453
|
+
};
|
|
454
|
+
readonly exceptions: {
|
|
455
|
+
readonly type: "array";
|
|
456
|
+
readonly items: {
|
|
457
|
+
readonly type: "string";
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
}, {
|
|
462
|
+
readonly type: "object";
|
|
463
|
+
readonly required: readonly ["kind", "source", "provider", "pattern", "replacement"];
|
|
464
|
+
readonly additionalProperties: false;
|
|
465
|
+
readonly properties: {
|
|
466
|
+
readonly kind: {
|
|
467
|
+
readonly const: "raw-replace";
|
|
468
|
+
};
|
|
469
|
+
readonly pattern: {
|
|
470
|
+
readonly type: "string";
|
|
471
|
+
};
|
|
472
|
+
readonly replacement: {
|
|
473
|
+
readonly type: "string";
|
|
474
|
+
};
|
|
475
|
+
readonly source: {
|
|
476
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
477
|
+
};
|
|
478
|
+
readonly provider: {
|
|
479
|
+
readonly type: "string";
|
|
480
|
+
};
|
|
481
|
+
readonly urlPattern: {
|
|
482
|
+
readonly type: "string";
|
|
483
|
+
};
|
|
484
|
+
readonly exceptions: {
|
|
485
|
+
readonly type: "array";
|
|
486
|
+
readonly items: {
|
|
487
|
+
readonly type: "string";
|
|
488
|
+
};
|
|
489
|
+
};
|
|
490
|
+
};
|
|
491
|
+
}, {
|
|
492
|
+
readonly type: "object";
|
|
493
|
+
readonly required: readonly ["kind", "source", "provider", "pattern", "captureGroup"];
|
|
494
|
+
readonly additionalProperties: false;
|
|
495
|
+
readonly properties: {
|
|
496
|
+
readonly kind: {
|
|
497
|
+
readonly const: "unwrap-redirect";
|
|
498
|
+
};
|
|
499
|
+
readonly pattern: {
|
|
500
|
+
readonly type: "string";
|
|
501
|
+
};
|
|
502
|
+
readonly captureGroup: {
|
|
503
|
+
readonly type: "integer";
|
|
504
|
+
readonly minimum: 0;
|
|
505
|
+
};
|
|
506
|
+
readonly source: {
|
|
507
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
508
|
+
};
|
|
509
|
+
readonly provider: {
|
|
510
|
+
readonly type: "string";
|
|
511
|
+
};
|
|
512
|
+
readonly urlPattern: {
|
|
513
|
+
readonly type: "string";
|
|
514
|
+
};
|
|
515
|
+
readonly exceptions: {
|
|
516
|
+
readonly type: "array";
|
|
517
|
+
readonly items: {
|
|
518
|
+
readonly type: "string";
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
}, {
|
|
523
|
+
readonly type: "object";
|
|
524
|
+
readonly required: readonly ["kind", "source", "provider", "urlPattern"];
|
|
525
|
+
readonly additionalProperties: false;
|
|
526
|
+
readonly properties: {
|
|
527
|
+
readonly kind: {
|
|
528
|
+
readonly const: "block-domain";
|
|
529
|
+
};
|
|
530
|
+
readonly source: {
|
|
531
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
532
|
+
};
|
|
533
|
+
readonly provider: {
|
|
534
|
+
readonly type: "string";
|
|
535
|
+
};
|
|
536
|
+
readonly urlPattern: {
|
|
537
|
+
readonly type: "string";
|
|
538
|
+
};
|
|
539
|
+
readonly exceptions: {
|
|
540
|
+
readonly type: "array";
|
|
541
|
+
readonly items: {
|
|
542
|
+
readonly type: "string";
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
}];
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
readonly options: {
|
|
552
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
553
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/options.json";
|
|
554
|
+
readonly title: "url-sanitize options";
|
|
555
|
+
readonly type: "object";
|
|
556
|
+
readonly additionalProperties: false;
|
|
557
|
+
readonly properties: {
|
|
558
|
+
readonly stripReferralMarketing: {
|
|
559
|
+
readonly type: "boolean";
|
|
560
|
+
};
|
|
561
|
+
readonly unwrapRedirects: {
|
|
562
|
+
readonly type: "boolean";
|
|
563
|
+
};
|
|
564
|
+
readonly domainBlocking: {
|
|
565
|
+
readonly type: "boolean";
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
readonly result: {
|
|
570
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
571
|
+
readonly $id: "https://url-sanitize.dev/schema/v1/result.json";
|
|
572
|
+
readonly title: "url-sanitize result";
|
|
573
|
+
readonly oneOf: readonly [{
|
|
574
|
+
readonly type: "object";
|
|
575
|
+
readonly required: readonly ["kind", "url"];
|
|
576
|
+
readonly additionalProperties: false;
|
|
577
|
+
readonly properties: {
|
|
578
|
+
readonly kind: {
|
|
579
|
+
readonly const: "unchanged";
|
|
580
|
+
};
|
|
581
|
+
readonly url: {
|
|
582
|
+
readonly type: "string";
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
}, {
|
|
586
|
+
readonly type: "object";
|
|
587
|
+
readonly required: readonly ["kind", "original", "url", "strippedParams", "matchedRules"];
|
|
588
|
+
readonly additionalProperties: false;
|
|
589
|
+
readonly properties: {
|
|
590
|
+
readonly kind: {
|
|
591
|
+
readonly const: "cleaned";
|
|
592
|
+
};
|
|
593
|
+
readonly original: {
|
|
594
|
+
readonly type: "string";
|
|
595
|
+
};
|
|
596
|
+
readonly url: {
|
|
597
|
+
readonly type: "string";
|
|
598
|
+
};
|
|
599
|
+
readonly strippedParams: {
|
|
600
|
+
readonly type: "array";
|
|
601
|
+
readonly items: {
|
|
602
|
+
readonly type: "string";
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
readonly matchedRules: {
|
|
606
|
+
readonly type: "array";
|
|
607
|
+
readonly items: {
|
|
608
|
+
readonly type: "object";
|
|
609
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
610
|
+
readonly additionalProperties: false;
|
|
611
|
+
readonly properties: {
|
|
612
|
+
readonly source: {
|
|
613
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
614
|
+
};
|
|
615
|
+
readonly provider: {
|
|
616
|
+
readonly type: "string";
|
|
617
|
+
};
|
|
618
|
+
readonly kind: {
|
|
619
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
620
|
+
};
|
|
621
|
+
readonly detail: {
|
|
622
|
+
readonly type: "string";
|
|
623
|
+
};
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
};
|
|
628
|
+
}, {
|
|
629
|
+
readonly type: "object";
|
|
630
|
+
readonly required: readonly ["kind", "original", "url", "via"];
|
|
631
|
+
readonly additionalProperties: false;
|
|
632
|
+
readonly properties: {
|
|
633
|
+
readonly kind: {
|
|
634
|
+
readonly const: "redirected";
|
|
635
|
+
};
|
|
636
|
+
readonly original: {
|
|
637
|
+
readonly type: "string";
|
|
638
|
+
};
|
|
639
|
+
readonly url: {
|
|
640
|
+
readonly type: "string";
|
|
641
|
+
};
|
|
642
|
+
readonly via: {
|
|
643
|
+
readonly type: "object";
|
|
644
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
645
|
+
readonly additionalProperties: false;
|
|
646
|
+
readonly properties: {
|
|
647
|
+
readonly source: {
|
|
648
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
649
|
+
};
|
|
650
|
+
readonly provider: {
|
|
651
|
+
readonly type: "string";
|
|
652
|
+
};
|
|
653
|
+
readonly kind: {
|
|
654
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
655
|
+
};
|
|
656
|
+
readonly detail: {
|
|
657
|
+
readonly type: "string";
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
}, {
|
|
663
|
+
readonly type: "object";
|
|
664
|
+
readonly required: readonly ["kind", "original", "via"];
|
|
665
|
+
readonly additionalProperties: false;
|
|
666
|
+
readonly properties: {
|
|
667
|
+
readonly kind: {
|
|
668
|
+
readonly const: "blocked";
|
|
669
|
+
};
|
|
670
|
+
readonly original: {
|
|
671
|
+
readonly type: "string";
|
|
672
|
+
};
|
|
673
|
+
readonly via: {
|
|
674
|
+
readonly type: "object";
|
|
675
|
+
readonly required: readonly ["source", "provider", "kind"];
|
|
676
|
+
readonly additionalProperties: false;
|
|
677
|
+
readonly properties: {
|
|
678
|
+
readonly source: {
|
|
679
|
+
readonly enum: readonly ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
680
|
+
};
|
|
681
|
+
readonly provider: {
|
|
682
|
+
readonly type: "string";
|
|
683
|
+
};
|
|
684
|
+
readonly kind: {
|
|
685
|
+
readonly enum: readonly ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
686
|
+
};
|
|
687
|
+
readonly detail: {
|
|
688
|
+
readonly type: "string";
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
}];
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
export { type MatchedRule, type RuleSource, type SanitizeResult, type Sanitizer, type SanitizerCatalog, type SanitizerOptions, type SanitizerRule, compileSanitizer, defineCatalog, mergeCatalogs, sanitizeResultJsonSchema, sanitizerCatalogJsonSchema, sanitizerOptionsJsonSchema, urlSanitizeJsonSchemas };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
// src/catalog.ts
|
|
2
|
+
function defineCatalog(catalog) {
|
|
3
|
+
return catalog;
|
|
4
|
+
}
|
|
5
|
+
function mergeCatalogs(first, ...rest) {
|
|
6
|
+
const catalogs = [first, ...rest];
|
|
7
|
+
return {
|
|
8
|
+
version: catalogs.length === 1 ? first.version : `merged(${catalogs.map((catalog) => catalog.version).join(",")})`,
|
|
9
|
+
generatedAt: latestGeneratedAt(catalogs),
|
|
10
|
+
sources: catalogs.flatMap((catalog) => catalog.sources.map((source) => ({ ...source }))),
|
|
11
|
+
rules: catalogs.flatMap((catalog) => catalog.rules.map(cloneRule))
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function latestGeneratedAt(catalogs) {
|
|
15
|
+
return catalogs.map((catalog) => catalog.generatedAt).reduce((latest, generatedAt) => generatedAt > latest ? generatedAt : latest);
|
|
16
|
+
}
|
|
17
|
+
function cloneRule(rule) {
|
|
18
|
+
return rule.exceptions ? { ...rule, exceptions: [...rule.exceptions] } : { ...rule };
|
|
19
|
+
}
|
|
20
|
+
|
|
1
21
|
// src/sanitize.ts
|
|
2
22
|
function safeRegex(pattern, flags = "") {
|
|
3
23
|
try {
|
|
@@ -214,6 +234,185 @@ function stripFromQueryString(searchOrHash, paramPattern) {
|
|
|
214
234
|
if (kept.length === 0) return { result: "", removed };
|
|
215
235
|
return { result: prefix + kept.join("&"), removed };
|
|
216
236
|
}
|
|
237
|
+
|
|
238
|
+
// src/schemas.ts
|
|
239
|
+
var ruleSourceValues = ["clearurls", "adguard", "brave", "firefox", "custom"];
|
|
240
|
+
var ruleKindValues = ["strip-param", "raw-replace", "unwrap-redirect", "block-domain"];
|
|
241
|
+
var catalogSourceSchema = {
|
|
242
|
+
type: "object",
|
|
243
|
+
required: ["name"],
|
|
244
|
+
additionalProperties: false,
|
|
245
|
+
properties: {
|
|
246
|
+
name: { enum: ruleSourceValues },
|
|
247
|
+
version: { type: "string" },
|
|
248
|
+
hash: { type: "string" },
|
|
249
|
+
license: { type: "string" },
|
|
250
|
+
upstream: { type: "string" }
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var ruleBaseProperties = {
|
|
254
|
+
source: { enum: ruleSourceValues },
|
|
255
|
+
provider: { type: "string" },
|
|
256
|
+
urlPattern: { type: "string" },
|
|
257
|
+
exceptions: {
|
|
258
|
+
type: "array",
|
|
259
|
+
items: { type: "string" }
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var matchedRuleSchema = {
|
|
263
|
+
type: "object",
|
|
264
|
+
required: ["source", "provider", "kind"],
|
|
265
|
+
additionalProperties: false,
|
|
266
|
+
properties: {
|
|
267
|
+
source: { enum: ruleSourceValues },
|
|
268
|
+
provider: { type: "string" },
|
|
269
|
+
kind: { enum: ruleKindValues },
|
|
270
|
+
detail: { type: "string" }
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var sanitizerOptionsJsonSchema = {
|
|
274
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
275
|
+
$id: "https://url-sanitize.dev/schema/v1/options.json",
|
|
276
|
+
title: "url-sanitize options",
|
|
277
|
+
type: "object",
|
|
278
|
+
additionalProperties: false,
|
|
279
|
+
properties: {
|
|
280
|
+
stripReferralMarketing: { type: "boolean" },
|
|
281
|
+
unwrapRedirects: { type: "boolean" },
|
|
282
|
+
domainBlocking: { type: "boolean" }
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var sanitizerCatalogJsonSchema = {
|
|
286
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
287
|
+
$id: "https://url-sanitize.dev/schema/v1/catalog.json",
|
|
288
|
+
title: "url-sanitize catalog",
|
|
289
|
+
type: "object",
|
|
290
|
+
required: ["version", "generatedAt", "sources", "rules"],
|
|
291
|
+
additionalProperties: false,
|
|
292
|
+
properties: {
|
|
293
|
+
version: { type: "string" },
|
|
294
|
+
generatedAt: { type: "string" },
|
|
295
|
+
sources: {
|
|
296
|
+
type: "array",
|
|
297
|
+
items: catalogSourceSchema
|
|
298
|
+
},
|
|
299
|
+
rules: {
|
|
300
|
+
type: "array",
|
|
301
|
+
items: {
|
|
302
|
+
oneOf: [
|
|
303
|
+
{
|
|
304
|
+
type: "object",
|
|
305
|
+
required: ["kind", "source", "provider", "paramPattern"],
|
|
306
|
+
additionalProperties: false,
|
|
307
|
+
properties: {
|
|
308
|
+
...ruleBaseProperties,
|
|
309
|
+
kind: { const: "strip-param" },
|
|
310
|
+
paramPattern: { type: "string" },
|
|
311
|
+
isReferralMarketing: { type: "boolean" }
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
type: "object",
|
|
316
|
+
required: ["kind", "source", "provider", "pattern", "replacement"],
|
|
317
|
+
additionalProperties: false,
|
|
318
|
+
properties: {
|
|
319
|
+
...ruleBaseProperties,
|
|
320
|
+
kind: { const: "raw-replace" },
|
|
321
|
+
pattern: { type: "string" },
|
|
322
|
+
replacement: { type: "string" }
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
type: "object",
|
|
327
|
+
required: ["kind", "source", "provider", "pattern", "captureGroup"],
|
|
328
|
+
additionalProperties: false,
|
|
329
|
+
properties: {
|
|
330
|
+
...ruleBaseProperties,
|
|
331
|
+
kind: { const: "unwrap-redirect" },
|
|
332
|
+
pattern: { type: "string" },
|
|
333
|
+
captureGroup: { type: "integer", minimum: 0 }
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
type: "object",
|
|
338
|
+
required: ["kind", "source", "provider", "urlPattern"],
|
|
339
|
+
additionalProperties: false,
|
|
340
|
+
properties: {
|
|
341
|
+
...ruleBaseProperties,
|
|
342
|
+
kind: { const: "block-domain" }
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var sanitizeResultJsonSchema = {
|
|
351
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
352
|
+
$id: "https://url-sanitize.dev/schema/v1/result.json",
|
|
353
|
+
title: "url-sanitize result",
|
|
354
|
+
oneOf: [
|
|
355
|
+
{
|
|
356
|
+
type: "object",
|
|
357
|
+
required: ["kind", "url"],
|
|
358
|
+
additionalProperties: false,
|
|
359
|
+
properties: {
|
|
360
|
+
kind: { const: "unchanged" },
|
|
361
|
+
url: { type: "string" }
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
type: "object",
|
|
366
|
+
required: ["kind", "original", "url", "strippedParams", "matchedRules"],
|
|
367
|
+
additionalProperties: false,
|
|
368
|
+
properties: {
|
|
369
|
+
kind: { const: "cleaned" },
|
|
370
|
+
original: { type: "string" },
|
|
371
|
+
url: { type: "string" },
|
|
372
|
+
strippedParams: {
|
|
373
|
+
type: "array",
|
|
374
|
+
items: { type: "string" }
|
|
375
|
+
},
|
|
376
|
+
matchedRules: {
|
|
377
|
+
type: "array",
|
|
378
|
+
items: matchedRuleSchema
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
type: "object",
|
|
384
|
+
required: ["kind", "original", "url", "via"],
|
|
385
|
+
additionalProperties: false,
|
|
386
|
+
properties: {
|
|
387
|
+
kind: { const: "redirected" },
|
|
388
|
+
original: { type: "string" },
|
|
389
|
+
url: { type: "string" },
|
|
390
|
+
via: matchedRuleSchema
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: "object",
|
|
395
|
+
required: ["kind", "original", "via"],
|
|
396
|
+
additionalProperties: false,
|
|
397
|
+
properties: {
|
|
398
|
+
kind: { const: "blocked" },
|
|
399
|
+
original: { type: "string" },
|
|
400
|
+
via: matchedRuleSchema
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
]
|
|
404
|
+
};
|
|
405
|
+
var urlSanitizeJsonSchemas = {
|
|
406
|
+
catalog: sanitizerCatalogJsonSchema,
|
|
407
|
+
options: sanitizerOptionsJsonSchema,
|
|
408
|
+
result: sanitizeResultJsonSchema
|
|
409
|
+
};
|
|
217
410
|
export {
|
|
218
|
-
compileSanitizer
|
|
411
|
+
compileSanitizer,
|
|
412
|
+
defineCatalog,
|
|
413
|
+
mergeCatalogs,
|
|
414
|
+
sanitizeResultJsonSchema,
|
|
415
|
+
sanitizerCatalogJsonSchema,
|
|
416
|
+
sanitizerOptionsJsonSchema,
|
|
417
|
+
urlSanitizeJsonSchemas
|
|
219
418
|
};
|