@w0s/report-same-referrer 4.0.0 → 4.0.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/README.md +102 -102
- package/package.json +44 -44
package/README.md
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
# Send referrer error information to endpoints
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@w0s/report-same-referrer)
|
|
4
|
-
[;
|
|
45
|
-
</script>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Default function
|
|
49
|
-
|
|
50
|
-
```TypeScript
|
|
51
|
-
async (endpoint: string, options: Readonly<Option>): Promise<void>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Parameters
|
|
55
|
-
|
|
56
|
-
<dl>
|
|
57
|
-
<dt><code>endpoint</code> [required]</dt>
|
|
58
|
-
<dd>URL of the endpoint</dd>
|
|
59
|
-
<dt><code>options</code> [required]</dt>
|
|
60
|
-
<dd>Information such as transmission conditions</dd>
|
|
61
|
-
</dl>
|
|
62
|
-
|
|
63
|
-
### Option
|
|
64
|
-
|
|
65
|
-
```TypeScript
|
|
66
|
-
interface Option {
|
|
67
|
-
fetchParam: {
|
|
68
|
-
documentURL: string;
|
|
69
|
-
referrer: string;
|
|
70
|
-
};
|
|
71
|
-
fetchContentType?: 'application/x-www-form-urlencoded' | 'application/json';
|
|
72
|
-
fetchHeaders?: HeadersInit;
|
|
73
|
-
condition?: 'origin' | 'host' | 'hostname';
|
|
74
|
-
same?: string[];
|
|
75
|
-
denyUAs?: RegExp[];
|
|
76
|
-
allowUAs?: RegExp[];
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
<dl>
|
|
81
|
-
<dt><code>fetchParam.documentURL</code></dt>
|
|
82
|
-
<dd>Field name when sending the URL of the document to an endpoint.</dd>
|
|
83
|
-
<dt><code>fetchParam.referrer</code></dt>
|
|
84
|
-
<dd>Field name when sending `document.referrer` to an endpoint.</dd>
|
|
85
|
-
<dt><code>fetchContentType</code></dt>
|
|
86
|
-
<dd><code>Content-Type</code> header to be set in <code>fetch()</code> request.</dd>
|
|
87
|
-
<dt><code>fetchHeaders</code></dt>
|
|
88
|
-
<dd>Header to add to the <code>fetch()</code> request. Specify the <a href="https://fetch.spec.whatwg.org/#typedefdef-headersinit">HeadersInit</a> type.</dd>
|
|
89
|
-
<dt><code>condition</code></dt>
|
|
90
|
-
<dd>Which parts of the referrer to check. Has the same meaning as the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL#instance_properties">URL interface properties</a>. The default value when omitted is <code>origin</code>.</dd>
|
|
91
|
-
<dt><code>same</code></dt>
|
|
92
|
-
<dd>Domain information treated as the same site. Specify the format according to the value of <code>condition</code>.
|
|
93
|
-
<ul>
|
|
94
|
-
<li><code>condition: origin</code> → 'https://www1.example.com'</li>
|
|
95
|
-
<li><code>condition: host</code> → 'www1.example.com:999'</li>
|
|
96
|
-
<li><code>condition: hostname</code> → 'www1.example.com'</li>
|
|
97
|
-
</ul></dd>
|
|
98
|
-
<dt><code>denyUAs</code></dt>
|
|
99
|
-
<dd>If a user agent matches this regular expression, do not send report.</dd>
|
|
100
|
-
<dt><code>allowUAs</code></dt>
|
|
101
|
-
<dd>If a user agent matches this regular expression, send report. If neither <code>denyUAs</code> nor <code>allowUAs</code> is specified, any file name will be accepted.</dd>
|
|
102
|
-
</dl>
|
|
1
|
+
# Send referrer error information to endpoints
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@w0s/report-same-referrer)
|
|
4
|
+
[](https://github.com/SaekiTominaga/js-library-browser/actions/workflows/report-same-referrer.yml)
|
|
5
|
+
|
|
6
|
+
If there are referrers from same site, that information will be sent to the endpoint as an error.
|
|
7
|
+
|
|
8
|
+
As a practical use case, this script put this script in error pages like 403, 404, 410 error pages to detect **the existence of broken links in the same site**.
|
|
9
|
+
|
|
10
|
+
## Demo
|
|
11
|
+
|
|
12
|
+
- [Demo page](https://saekitominaga.github.io/js-library-browser/packages/report-same-referrer/demo/)
|
|
13
|
+
|
|
14
|
+
## Examples
|
|
15
|
+
|
|
16
|
+
```HTML
|
|
17
|
+
<script type="importmap">
|
|
18
|
+
{
|
|
19
|
+
"imports": {
|
|
20
|
+
"@w0s/report-same-referrer": "..."
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
<script type="module">
|
|
25
|
+
import reportSameReferrer from '@w0s/report-same-referrer';
|
|
26
|
+
|
|
27
|
+
await reportSameReferrer('https://report.example.com/referrer', {
|
|
28
|
+
fetchParam: {
|
|
29
|
+
documentURL: 'documentURL',
|
|
30
|
+
referrer: 'referrer',
|
|
31
|
+
},
|
|
32
|
+
fetchContentType: 'application/json',
|
|
33
|
+
fetchHeaders: {
|
|
34
|
+
'X-Requested-With': 'hoge',
|
|
35
|
+
},
|
|
36
|
+
condition: 'origin',
|
|
37
|
+
same: [
|
|
38
|
+
'https://www1.example.com',
|
|
39
|
+
'https://www2.example.com',
|
|
40
|
+
],
|
|
41
|
+
denyUAs: [
|
|
42
|
+
/Googlebot\/2.1;/,
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Default function
|
|
49
|
+
|
|
50
|
+
```TypeScript
|
|
51
|
+
async (endpoint: string, options: Readonly<Option>): Promise<void>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Parameters
|
|
55
|
+
|
|
56
|
+
<dl>
|
|
57
|
+
<dt><code>endpoint</code> [required]</dt>
|
|
58
|
+
<dd>URL of the endpoint</dd>
|
|
59
|
+
<dt><code>options</code> [required]</dt>
|
|
60
|
+
<dd>Information such as transmission conditions</dd>
|
|
61
|
+
</dl>
|
|
62
|
+
|
|
63
|
+
### Option
|
|
64
|
+
|
|
65
|
+
```TypeScript
|
|
66
|
+
interface Option {
|
|
67
|
+
fetchParam: {
|
|
68
|
+
documentURL: string;
|
|
69
|
+
referrer: string;
|
|
70
|
+
};
|
|
71
|
+
fetchContentType?: 'application/x-www-form-urlencoded' | 'application/json';
|
|
72
|
+
fetchHeaders?: HeadersInit;
|
|
73
|
+
condition?: 'origin' | 'host' | 'hostname';
|
|
74
|
+
same?: string[];
|
|
75
|
+
denyUAs?: RegExp[];
|
|
76
|
+
allowUAs?: RegExp[];
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
<dl>
|
|
81
|
+
<dt><code>fetchParam.documentURL</code></dt>
|
|
82
|
+
<dd>Field name when sending the URL of the document to an endpoint.</dd>
|
|
83
|
+
<dt><code>fetchParam.referrer</code></dt>
|
|
84
|
+
<dd>Field name when sending `document.referrer` to an endpoint.</dd>
|
|
85
|
+
<dt><code>fetchContentType</code></dt>
|
|
86
|
+
<dd><code>Content-Type</code> header to be set in <code>fetch()</code> request.</dd>
|
|
87
|
+
<dt><code>fetchHeaders</code></dt>
|
|
88
|
+
<dd>Header to add to the <code>fetch()</code> request. Specify the <a href="https://fetch.spec.whatwg.org/#typedefdef-headersinit">HeadersInit</a> type.</dd>
|
|
89
|
+
<dt><code>condition</code></dt>
|
|
90
|
+
<dd>Which parts of the referrer to check. Has the same meaning as the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL#instance_properties">URL interface properties</a>. The default value when omitted is <code>origin</code>.</dd>
|
|
91
|
+
<dt><code>same</code></dt>
|
|
92
|
+
<dd>Domain information treated as the same site. Specify the format according to the value of <code>condition</code>.
|
|
93
|
+
<ul>
|
|
94
|
+
<li><code>condition: origin</code> → 'https://www1.example.com'</li>
|
|
95
|
+
<li><code>condition: host</code> → 'www1.example.com:999'</li>
|
|
96
|
+
<li><code>condition: hostname</code> → 'www1.example.com'</li>
|
|
97
|
+
</ul></dd>
|
|
98
|
+
<dt><code>denyUAs</code></dt>
|
|
99
|
+
<dd>If a user agent matches this regular expression, do not send report.</dd>
|
|
100
|
+
<dt><code>allowUAs</code></dt>
|
|
101
|
+
<dd>If a user agent matches this regular expression, send report. If neither <code>denyUAs</code> nor <code>allowUAs</code> is specified, any file name will be accepted.</dd>
|
|
102
|
+
</dl>
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@w0s/report-same-referrer",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "Send referrer error information to endpoints",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"Report"
|
|
7
|
-
],
|
|
8
|
-
"homepage": "https://github.com/SaekiTominaga/
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/SaekiTominaga/
|
|
11
|
-
},
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"author": "Saeki Tominaga",
|
|
14
|
-
"files": [
|
|
15
|
-
"dist/**/*.d.ts",
|
|
16
|
-
"!dist/**/*.test.d.ts",
|
|
17
|
-
"dist/**/*.d.ts.map",
|
|
18
|
-
"!dist/**/*.test.d.ts.map",
|
|
19
|
-
"dist/**/*.js",
|
|
20
|
-
"!dist/**/*.test.js",
|
|
21
|
-
"dist/**/*.js.map",
|
|
22
|
-
"!dist/**/*.test.js.map"
|
|
23
|
-
],
|
|
24
|
-
"type": "module",
|
|
25
|
-
"main": "dist/index.js",
|
|
26
|
-
"module": "dist/index.js",
|
|
27
|
-
"types": "dist/index.d.ts",
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/SaekiTominaga/
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"server": "http-server -o demo -c-1",
|
|
34
|
-
"prebuild": "rimraf dist/* -g",
|
|
35
|
-
"build": "tsc",
|
|
36
|
-
"watch": "tsc -w",
|
|
37
|
-
"lint": "eslint src/**/*.ts __tests__/**/*.js",
|
|
38
|
-
"pretest": "npm run build",
|
|
39
|
-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest dist/.+\\.test\\.js -c ../../jest.config.mjs --roots packages/report-same-referrer"
|
|
40
|
-
},
|
|
41
|
-
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@w0s/report-same-referrer",
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Send referrer error information to endpoints",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Report"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/SaekiTominaga/js-library-browser#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/SaekiTominaga/js-library-browser/issues"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Saeki Tominaga",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**/*.d.ts",
|
|
16
|
+
"!dist/**/*.test.d.ts",
|
|
17
|
+
"dist/**/*.d.ts.map",
|
|
18
|
+
"!dist/**/*.test.d.ts.map",
|
|
19
|
+
"dist/**/*.js",
|
|
20
|
+
"!dist/**/*.test.js",
|
|
21
|
+
"dist/**/*.js.map",
|
|
22
|
+
"!dist/**/*.test.js.map"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/SaekiTominaga/js-library-browser.git"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"server": "http-server -o demo -c-1",
|
|
34
|
+
"prebuild": "rimraf dist/* -g",
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"watch": "tsc -w",
|
|
37
|
+
"lint": "eslint src/**/*.ts __tests__/**/*.js",
|
|
38
|
+
"pretest": "npm run build",
|
|
39
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest dist/.+\\.test\\.js -c ../../jest.config.mjs --roots packages/report-same-referrer"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|