@tsdmarc/opensearch 0.0.0-reserved.0 → 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/CHANGELOG.md +12 -0
- package/LICENSE +201 -0
- package/NOTICE +61 -0
- package/README.md +176 -1
- package/dist/index.d.ts +233 -0
- package/dist/index.js +1931 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @tsdmarc/opensearch
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a1c5fad: First release: a 1:1 TypeScript port of parsedmarc 11.2.1 and of the parts of mailsuite 2.3.4 it uses, for Node.js 24+, Bun and Deno.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [a1c5fad]
|
|
12
|
+
- tsdmarc@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
tsdmarc
|
|
2
|
+
Copyright 2026 tsdmarc contributors
|
|
3
|
+
|
|
4
|
+
This product is a TypeScript port of parsedmarc
|
|
5
|
+
(https://github.com/domainaware/parsedmarc), Copyright Sean Whalen and
|
|
6
|
+
parsedmarc contributors, licensed under the Apache License, Version 2.0.
|
|
7
|
+
Ported from parsedmarc 11.2.1, commit 7bbc405c01a1c4c37811b2a3746e8881c00cda39.
|
|
8
|
+
|
|
9
|
+
The mailbox connection and SMTP code is a port of mailsuite
|
|
10
|
+
(https://github.com/seanthegeek/mailsuite), Copyright Sean Whalen,
|
|
11
|
+
licensed under the Apache License, Version 2.0.
|
|
12
|
+
Ported from mailsuite 2.3.4, commit 3bd62831d137c9aa7884be33b83323ca3a1bd1de.
|
|
13
|
+
|
|
14
|
+
All source files were translated from Python to TypeScript; this is a
|
|
15
|
+
modification of the original works within the meaning of section 4(b) of
|
|
16
|
+
the Apache License.
|
|
17
|
+
|
|
18
|
+
Third-party data files in resources/:
|
|
19
|
+
- ipinfo_lite.mmdb: IPinfo Lite, (c) IPinfo (https://ipinfo.io/lite),
|
|
20
|
+
licensed under CC BY-SA 4.0.
|
|
21
|
+
- base_reverse_dns_map.csv: from parsedmarc, derived in part from IPinfo
|
|
22
|
+
Lite data, licensed under CC BY-SA 4.0.
|
|
23
|
+
|
|
24
|
+
Ported third-party code in packages/tsdmarc/src (behavior reimplemented in
|
|
25
|
+
TypeScript to reproduce parsedmarc's output exactly):
|
|
26
|
+
- xml/expat.ts, xml/expat-names.ts: port of parts of Expat 2.9.0
|
|
27
|
+
(https://libexpat.github.io/), Copyright (c) 1997-2000 Thai Open Source
|
|
28
|
+
Software Center Ltd and Copyright (c) 2000-2026 Expat development team,
|
|
29
|
+
licensed under the MIT License.
|
|
30
|
+
- xml/xmltodict.ts: port of xmltodict (https://github.com/martinblech/xmltodict),
|
|
31
|
+
Copyright (c) 2012 Martin Blech, licensed under the MIT License.
|
|
32
|
+
- xml/recover.ts: emulates the observable recovery behavior of libxml2
|
|
33
|
+
(https://gitlab.gnome.org/GNOME/libxml2), MIT License.
|
|
34
|
+
- utils/py-email/, utils/py-codecs*.ts, utils/py-binascii.ts, utils/py-str.ts,
|
|
35
|
+
csv.ts, utils/csv-reader.ts, utils/url-split.ts: ports of parts of the
|
|
36
|
+
CPython standard library (https://github.com/python/cpython), Copyright (c)
|
|
37
|
+
2001 Python Software Foundation, licensed under the PSF License Agreement.
|
|
38
|
+
- utils/mailparser/: port of mail-parser 4.8.0
|
|
39
|
+
(https://github.com/SpamScope/mail-parser), Copyright Fedele Mantuano,
|
|
40
|
+
licensed under the Apache License, Version 2.0.
|
|
41
|
+
- utils/dns*.ts: port of parts of dnspython (https://www.dnspython.org/),
|
|
42
|
+
Copyright (c) Dnspython Contributors, licensed under the ISC License.
|
|
43
|
+
- utils/timestamps.ts: date parsing compatible with python-dateutil
|
|
44
|
+
(https://github.com/dateutil/dateutil), Apache License 2.0 / BSD 3-Clause.
|
|
45
|
+
- internal/zipfile.ts and the decompressor wrappers in internal/bz2.ts,
|
|
46
|
+
internal/lzma.ts, internal/zstd.ts and internal/zlib.ts: ports of parts of
|
|
47
|
+
the CPython standard library (zipfile, bz2, lzma, compression.zstd, zlib
|
|
48
|
+
modules), Copyright (c) 2001 Python Software Foundation, licensed under the
|
|
49
|
+
PSF License Agreement.
|
|
50
|
+
- internal/zlib.ts: port of the inflate code of zlib 1.3 (https://zlib.net/),
|
|
51
|
+
Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler, licensed under the
|
|
52
|
+
zlib License.
|
|
53
|
+
- internal/bz2.ts: port of the libbzip2 1.0.8 decompressor
|
|
54
|
+
(https://sourceware.org/bzip2/), Copyright (C) 1996-2019 Julian R Seward,
|
|
55
|
+
licensed under the bzip2 license (BSD-style).
|
|
56
|
+
- internal/lzma.ts: port of the LZMA1 decoder of liblzma 5.8
|
|
57
|
+
(https://tukaani.org/xz/), by Igor Pavlov and Lasse Collin, licensed under
|
|
58
|
+
the BSD Zero Clause License (0BSD).
|
|
59
|
+
- internal/zstd.ts: port of the libzstd 1.5.7 decoder
|
|
60
|
+
(https://github.com/facebook/zstd), Copyright (c) Meta Platforms, Inc. and
|
|
61
|
+
affiliates, licensed under the BSD 3-Clause License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,178 @@
|
|
|
1
1
|
# @tsdmarc/opensearch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Save tsdmarc reports to OpenSearch (self-managed or Amazon OpenSearch Service). Port of parsedmarc's `opensearch.py`, on [`@opensearch-project/opensearch`](https://www.npmjs.com/package/@opensearch-project/opensearch): same index names, documents, duplicate checks and migrations, so parsedmarc's OpenSearch Dashboards and Grafana dashboards ([`dashboards/`](https://github.com/helixnebulatech/tsdmarc/tree/main/dashboards)) work unchanged.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install tsdmarc @tsdmarc/opensearch
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`tsdmarc` is a peer dependency. Node.js 24 or later, Bun or Deno.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
AlreadySaved,
|
|
18
|
+
getDefaultConnection,
|
|
19
|
+
migrateIndexes,
|
|
20
|
+
saveAggregateReportToOpenSearch,
|
|
21
|
+
saveFailureReportToOpenSearch,
|
|
22
|
+
saveSmtpTlsReportToOpenSearch,
|
|
23
|
+
setDefaultConnection,
|
|
24
|
+
setHosts,
|
|
25
|
+
} from '@tsdmarc/opensearch';
|
|
26
|
+
import { parseReportFile } from 'tsdmarc';
|
|
27
|
+
|
|
28
|
+
await setHosts('search.example.com:9200', {
|
|
29
|
+
useSsl: true,
|
|
30
|
+
username: process.env.OPENSEARCH_USER,
|
|
31
|
+
password: process.env.OPENSEARCH_PASSWORD,
|
|
32
|
+
});
|
|
33
|
+
await migrateIndexes({
|
|
34
|
+
aggregateIndexes: ['dmarc_aggregate'],
|
|
35
|
+
smtpTlsIndexes: ['smtp_tls'],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const parsed = await parseReportFile('report.xml.gz');
|
|
40
|
+
if (parsed.reportType === 'aggregate') {
|
|
41
|
+
await saveAggregateReportToOpenSearch(parsed.report);
|
|
42
|
+
} else if (parsed.reportType === 'failure') {
|
|
43
|
+
await saveFailureReportToOpenSearch(parsed.report);
|
|
44
|
+
} else {
|
|
45
|
+
await saveSmtpTlsReportToOpenSearch(parsed.report);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (!(error instanceof AlreadySaved)) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
await getDefaultConnection()?.close();
|
|
53
|
+
setDefaultConnection(null);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`setHosts()` registers a module-wide default client that the other functions use, like parsedmarc's DSL connection. The save functions create the index if needed and throw `AlreadySaved` when the report is already stored.
|
|
58
|
+
|
|
59
|
+
### Several clusters
|
|
60
|
+
|
|
61
|
+
The default connection is module state, shared by everything in the process: a later `setHosts()` or `setDefaultConnection()` redirects the requests of saves still in progress. One connection at a time is supported that way. An application that writes to several clusters at once (one per tenant, say) creates a client per cluster with `createClient()`, which takes the same options as `setHosts()` but registers nothing, and passes it as `client`:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import {
|
|
65
|
+
createClient,
|
|
66
|
+
saveAggregateReportToOpenSearch,
|
|
67
|
+
} from '@tsdmarc/opensearch';
|
|
68
|
+
|
|
69
|
+
const tenantClient = await createClient('https://tenant-a.example.com:9200', {
|
|
70
|
+
username: 'tsdmarc',
|
|
71
|
+
password: process.env.TENANT_A_PASSWORD,
|
|
72
|
+
});
|
|
73
|
+
await saveAggregateReportToOpenSearch(report, { client: tenantClient });
|
|
74
|
+
await tenantClient.close();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`client` is accepted by the save functions, `createIndexes()` (fourth argument, `{ client }`) and `migrateIndexes()`. A client from anywhere else works too, with its own settings.
|
|
78
|
+
|
|
79
|
+
Documents go to `[indexPrefix]<base>[_indexSuffix]-YYYY-MM-DD` (or `-YYYY-MM` with `monthlyIndexes`), with `<base>` one of `dmarc_aggregate`, `dmarc_failure` and `smtp_tls`. Field names are snake_case, as in parsedmarc. Every document carries an `@timestamp`: the record's begin date for aggregate reports, the arrival date for failure reports and the begin date for SMTP TLS reports.
|
|
80
|
+
|
|
81
|
+
### Data streams
|
|
82
|
+
|
|
83
|
+
With `useDataStreams: true`, each report type goes to one data stream named like the index without the date (`[indexPrefix]<base>[_indexSuffix]`), and `monthlyIndexes` is ignored. The save functions put an index template named after the stream, whose `index_patterns` is the exact name, and create the stream; an ISM policy attaches itself to the backing indices through its `ism_template`. tsdmarc puts its template again in every process, so edit the policy, not the template. Retention is up to you. Dated indexes saved before the switch stay where they are, and the duplicate search covers both. If an index or alias already holds a stream's name (such as an undated index from parsedmarc before 5.0.0), saving fails with `OpenSearchError`.
|
|
84
|
+
|
|
85
|
+
## Amazon OpenSearch Service
|
|
86
|
+
|
|
87
|
+
`authType: 'awssigv4'` signs requests with AWS Signature Version 4. Credentials come from the AWS SDK's default provider chain (environment, shared config files, SSO, instance or container roles), and are checked when `setHosts()` runs. The AWS SDK is loaded only in this mode.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
await setHosts('search-domain.eu-west-1.es.amazonaws.com:443', {
|
|
91
|
+
useSsl: true,
|
|
92
|
+
authType: 'awssigv4',
|
|
93
|
+
awsRegion: 'eu-west-1',
|
|
94
|
+
awsService: 'es', // 'aoss' for OpenSearch Serverless
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API
|
|
99
|
+
|
|
100
|
+
| Function | Description |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `setHosts(hosts, options?)` | Create the client for one host or an array of hosts and register it as the default connection. Returns the client. |
|
|
103
|
+
| `createClient(hosts, options?)` | Create a client like `setHosts()` without registering it, to pass as `client` (see [Several clusters](#several-clusters)). |
|
|
104
|
+
| `saveAggregateReportToOpenSearch(report, options?)` | Save an aggregate report, one document per record. |
|
|
105
|
+
| `saveFailureReportToOpenSearch(report, options?)` | Save a failure report. `saveForensicReportToOpenSearch` is a backward-compatible alias. |
|
|
106
|
+
| `saveSmtpTlsReportToOpenSearch(report, options?)` | Save an SMTP TLS report. |
|
|
107
|
+
| `migrateIndexes(options?)` | Run parsedmarc's index migrations and backfills. Logs warnings instead of throwing. |
|
|
108
|
+
| `createIndexes(names, settings?, mappings?, { client }?)` | Create indexes that don't exist yet (default settings: 1 shard, 0 replicas). |
|
|
109
|
+
| `createDataStreams(names, settings?, mappings?, { client }?)` | Put the index template of each data stream and create the streams that don't exist yet (see [Data streams](#data-streams)). |
|
|
110
|
+
| `getDefaultConnection()` / `setDefaultConnection(client)` | Read or replace the registered client (`null` removes it). |
|
|
111
|
+
| `AlreadySaved`, `OpenSearchError`, `BulkIndexError`, `ScanError` | Errors. |
|
|
112
|
+
| `DOCUMENT_MAPPINGS`, `BACKFILL` | The mappings parsedmarc's document classes declare, and the backfill queries/scripts `migrateIndexes()` submits. |
|
|
113
|
+
|
|
114
|
+
### `setHosts()` options
|
|
115
|
+
|
|
116
|
+
Hosts without a scheme default to port 9200; `https://` hosts default to port 443.
|
|
117
|
+
|
|
118
|
+
| Option | Type | Default | Description |
|
|
119
|
+
| --- | --- | --- | --- |
|
|
120
|
+
| `useSsl` | `boolean \| null` | `false` | Use HTTPS for every host. |
|
|
121
|
+
| `sslCertPath` | `string \| null` | `null` | Path to the CA certificate chain (with `useSsl`). |
|
|
122
|
+
| `skipCertificateVerification` | `boolean` | `false` | Skip certificate verification (with `useSsl`). |
|
|
123
|
+
| `username` | `string \| null` | `null` | Basic auth user name (used only with `password`). |
|
|
124
|
+
| `password` | `string \| null` | `null` | Basic auth password. |
|
|
125
|
+
| `apiKey` | `string \| null` | `null` | Accepted but not sent, like parsedmarc (opensearch-py ignores a client-level `api_key`). |
|
|
126
|
+
| `timeout` | `number \| null` | `60` | Request timeout in seconds. `null` disables it; `0` or less throws `ValueError`. |
|
|
127
|
+
| `authType` | `string` | `'basic'` | `'basic'` or `'awssigv4'`. |
|
|
128
|
+
| `awsRegion` | `string \| null` | `null` | AWS region; required with `awssigv4`. |
|
|
129
|
+
| `awsService` | `string` | `'es'` | Service name to sign for; `'aoss'` for OpenSearch Serverless. |
|
|
130
|
+
|
|
131
|
+
### Save options
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | Description |
|
|
134
|
+
| --- | --- | --- | --- |
|
|
135
|
+
| `indexSuffix` | `string \| null` | — | Appended to the index name as `_<suffix>`. |
|
|
136
|
+
| `indexPrefix` | `string \| null` | — | Prepended to the index name as is. |
|
|
137
|
+
| `monthlyIndexes` | `boolean \| null` | `false` | Monthly indexes instead of daily ones (ignored with `useDataStreams`). |
|
|
138
|
+
| `useDataStreams` | `boolean` | `false` | Save to a data stream instead of dated indexes (see [Data streams](#data-streams)). |
|
|
139
|
+
| `numberOfShards` | `number` | `1` | Shards for a new index. |
|
|
140
|
+
| `numberOfReplicas` | `number` | `0` | Replicas for a new index. |
|
|
141
|
+
| `maxIndexesPerReport` | `number` | `31` | Most indexes one aggregate report may spread over; later records go to its first index. `0` removes the limit. tsdmarc only. |
|
|
142
|
+
| `client` | `Client \| null` | default connection | The OpenSearch client to use (see [Several clusters](#several-clusters)). |
|
|
143
|
+
|
|
144
|
+
### `migrateIndexes()` options
|
|
145
|
+
|
|
146
|
+
| Option | Type | Default | Description |
|
|
147
|
+
| --- | --- | --- | --- |
|
|
148
|
+
| `aggregateIndexes` | `string[] \| null` | — | Aggregate index names, backfilled as `name*`. |
|
|
149
|
+
| `failureIndexes` | `string[] \| null` | — | Accepted for API compatibility; unused. |
|
|
150
|
+
| `smtpTlsIndexes` | `string[] \| null` | — | SMTP TLS index names, backfilled as `name*`. |
|
|
151
|
+
| `legacyFoIndexes` | `string[] \| null` | — | Exact index names to check for the pre-5.0.0 `published_policy.fo` `long` mapping. |
|
|
152
|
+
| `client` | `Client \| null` | default connection | The client to use. |
|
|
153
|
+
|
|
154
|
+
## CLI
|
|
155
|
+
|
|
156
|
+
With [`@tsdmarc/cli`](https://github.com/helixnebulatech/tsdmarc/tree/main/packages/cli#readme), use the `[opensearch]` section of the configuration file (the same as parsedmarc's): `hosts`, `user`, `password`, `api_key`, `ssl`, `cert_path`, `skip_certificate_verification`, `timeout`, `index_suffix`, `index_prefix`, `monthly_indexes`, `number_of_shards`, `number_of_replicas`, `auth_type` (or `authentication_type`), `aws_region` and `aws_service`.
|
|
157
|
+
|
|
158
|
+
## Notes
|
|
159
|
+
|
|
160
|
+
Differences from parsedmarc (full list in [architecture/README.md](https://github.com/helixnebulatech/tsdmarc/blob/main/architecture/README.md#differences-from-parsedmarc)):
|
|
161
|
+
|
|
162
|
+
- Functions are `async` and take an options object.
|
|
163
|
+
- Retries follow opensearch-py: 3 retries on connection errors and HTTP 502/503/504, none on a timeout (opensearch-js alone would also resend timed-out requests).
|
|
164
|
+
- The JavaScript client sends `/{index}/_mapping` as POST where the Python client uses PUT; servers accept both.
|
|
165
|
+
- `setHosts()` replaces the default connection without closing the previous client, like the Python DSL registry. On shutdown, call `await getDefaultConnection()?.close()` and `setDefaultConnection(null)`.
|
|
166
|
+
- Logged host URLs show the password as `***` (`user:***@`), as in parsedmarc 11.2; tsdmarc also masks everything up to the last `@` of a malformed URL.
|
|
167
|
+
- Error messages that include an SDK error carry the JavaScript client's message.
|
|
168
|
+
- Like parsedmarc, `createIndexes()` does not install `DOCUMENT_MAPPINGS`. The save functions, however, create new indexes with `date_detection: false` and mappings for the date fields only (`@timestamp`, `date_range`, `date_begin`, `date_end`, `arrival_date`, `sample.date`), so a text value that looks like a date can't map its field as `date`. parsedmarc creates bare indexes. Existing indexes are not changed.
|
|
169
|
+
- Data stream templates carry the same date mappings and `sample.headers` mapping as the indexes the save functions create (parsedmarc's map only `@timestamp`), and their description names tsdmarc. A data stream created by another writer between the checks, or an alias holding the name, is told apart from a name collision.
|
|
170
|
+
- One aggregate report spreads over at most `maxIndexesPerReport` (31) indexes: its sender picks the `date_range`, and in parsedmarc a few KB can create more than 1,000 daily indexes and use up `cluster.max_shards_per_node`. Records past the limit go to the report's first index with their dates intact.
|
|
171
|
+
- Dots in failure sample header names become `_`, so a `Subject.x` header can't turn `sample.headers.subject` into an object.
|
|
172
|
+
- New failure indexes map only a fixed list of `sample.headers` fields (those the shipped dashboards use, plus a few such as `cc` and `received-spf`) and set `dynamic: false` on the rest: every header stays in `_source` and shows in Discover, but the others cannot be searched. parsedmarc maps every header name a sender invents, which can use up `index.mapping.total_fields.limit` and get the samples of the rest of that day (or month) rejected. Indexes that already exist keep their mapping.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
Part of [tsdmarc](https://github.com/helixnebulatech/tsdmarc#readme), a TypeScript port of [parsedmarc](https://github.com/domainaware/parsedmarc). Licensed under Apache-2.0.
|
|
177
|
+
|
|
178
|
+
Created by [HelixNebula](https://helixnebula.tech).
|