@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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { AggregateReport, FailureReport, SMTPTLSReport } from "tsdmarc";
|
|
2
|
+
import { Client } from "@opensearch-project/opensearch";
|
|
3
|
+
interface IndexMapping {
|
|
4
|
+
readonly date_detection: boolean;
|
|
5
|
+
readonly properties: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/** A query clause, as the DSL's `Q()` renders it. */
|
|
8
|
+
type Query = Record<string, unknown>;
|
|
9
|
+
interface DocumentMappings {
|
|
10
|
+
readonly aggregate: {
|
|
11
|
+
properties: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
readonly failure: {
|
|
14
|
+
properties: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
readonly smtpTls: {
|
|
17
|
+
properties: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The mappings parsedmarc's document classes declare. `createIndexes()`
|
|
22
|
+
* does not install them (neither does parsedmarc): the shipped dashboards
|
|
23
|
+
* rely on dynamic mapping. They are exported for reference and for users
|
|
24
|
+
* who manage index templates themselves.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DOCUMENT_MAPPINGS: DocumentMappings;
|
|
27
|
+
/** Raised when an OpenSearch error occurs. */
|
|
28
|
+
export declare class OpenSearchError extends Error {
|
|
29
|
+
override name: string;
|
|
30
|
+
}
|
|
31
|
+
/** Raised when a report to be saved matches an existing report. */
|
|
32
|
+
export declare class AlreadySaved extends Error {
|
|
33
|
+
override name: string;
|
|
34
|
+
}
|
|
35
|
+
/** The backfill queries and scripts migrateIndexes() submits. */
|
|
36
|
+
export declare const BACKFILL: {
|
|
37
|
+
readonly aggregateQuery: Query;
|
|
38
|
+
readonly aggregateScript: string;
|
|
39
|
+
readonly smtpTlsQuery: Query;
|
|
40
|
+
readonly smtpTlsScript: string;
|
|
41
|
+
};
|
|
42
|
+
interface SetHostsOptions {
|
|
43
|
+
/** Use an HTTPS connection to the server. */
|
|
44
|
+
useSsl?: boolean | null;
|
|
45
|
+
/** Path to the CA certificate chain (used when `useSsl` is set). */
|
|
46
|
+
sslCertPath?: string | null;
|
|
47
|
+
/** Skip certificate verification (used when `useSsl` is set). */
|
|
48
|
+
skipCertificateVerification?: boolean;
|
|
49
|
+
username?: string | null;
|
|
50
|
+
password?: string | null;
|
|
51
|
+
/**
|
|
52
|
+
* The Base64-encoded API key. Accepted as parsedmarc accepts it, but
|
|
53
|
+
* opensearch-py ignores a client-level `api_key`, so parsedmarc never
|
|
54
|
+
* sends it; neither does tsdmarc.
|
|
55
|
+
*/
|
|
56
|
+
apiKey?: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Request timeout in seconds (default 60). `null` means no timeout; 0 or
|
|
59
|
+
* less raises `ValueError`, like opensearch-py.
|
|
60
|
+
*/
|
|
61
|
+
timeout?: number | null;
|
|
62
|
+
/** `basic` (default) or `awssigv4`. */
|
|
63
|
+
authType?: string;
|
|
64
|
+
/** AWS region for SigV4 auth (required for `awssigv4`). */
|
|
65
|
+
awsRegion?: string | null;
|
|
66
|
+
/** AWS service for SigV4 signing (default `es`; `aoss` for Serverless). */
|
|
67
|
+
awsService?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates an OpenSearch client the way {@link setHosts} does, without
|
|
71
|
+
* registering it as the default connection. Pass it as `client` to the save
|
|
72
|
+
* functions, createIndexes() and migrateIndexes() to write to several
|
|
73
|
+
* clusters from one process. Close it with `client.close()`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createClient(hosts: string | string[], options?: SetHostsOptions): Promise<Client>;
|
|
76
|
+
/**
|
|
77
|
+
* Sets the OpenSearch hosts to use, and registers the client as the
|
|
78
|
+
* default connection the other functions use.
|
|
79
|
+
*
|
|
80
|
+
* A client registered by an earlier call is replaced but not closed, as in
|
|
81
|
+
* parsedmarc (the DSL's connection registry only drops it): its owner may
|
|
82
|
+
* still be using it or put it back (the CLI's configuration reload). Close
|
|
83
|
+
* clients you no longer need with `client.close()`; on shutdown,
|
|
84
|
+
* `await getDefaultConnection()?.close()` then `setDefaultConnection(null)`.
|
|
85
|
+
*
|
|
86
|
+
* @returns The registered client. Callers that need to close this exact
|
|
87
|
+
* client later should hold on to it.
|
|
88
|
+
*/
|
|
89
|
+
export declare function setHosts(hosts: string | string[], options?: SetHostsOptions): Promise<Client>;
|
|
90
|
+
/**
|
|
91
|
+
* The client registered as the `default` connection, or `null`. With
|
|
92
|
+
* {@link setDefaultConnection}, lets a caller snapshot and restore the
|
|
93
|
+
* module state setHosts() writes (the CLI's configuration reload).
|
|
94
|
+
*/
|
|
95
|
+
export declare function getDefaultConnection(): Client | null;
|
|
96
|
+
/** Register `client` as the `default` connection (`null` removes it). */
|
|
97
|
+
export declare function setDefaultConnection(client: Client | null): void;
|
|
98
|
+
/** Selects the cluster a function writes to. */
|
|
99
|
+
interface ConnectionOptions {
|
|
100
|
+
/**
|
|
101
|
+
* The client to use instead of the default connection setHosts()
|
|
102
|
+
* registers, such as one from {@link createClient}. The default connection
|
|
103
|
+
* is module state, shared by every caller in the process: an application
|
|
104
|
+
* that writes to several clusters at once passes the client of each.
|
|
105
|
+
*/
|
|
106
|
+
client?: Client | null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create OpenSearch indexes that don't exist yet.
|
|
110
|
+
*
|
|
111
|
+
* @param settings Index settings (default: 1 shard, 0 replicas).
|
|
112
|
+
* @param mappings Mappings for new indexes (default: none, as in parsedmarc).
|
|
113
|
+
* @param options The cluster to use (default: the default connection).
|
|
114
|
+
*/
|
|
115
|
+
export declare function createIndexes(names: string[], settings?: Record<string, unknown> | null, mappings?: IndexMapping | null, options?: ConnectionOptions): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Create OpenSearch data streams and their index templates.
|
|
118
|
+
*
|
|
119
|
+
* For each name, puts an index template named after the stream whose
|
|
120
|
+
* `index_patterns` is exactly that name (no wildcard, so it never applies to
|
|
121
|
+
* the date-suffixed indexes written without data streams), and then creates
|
|
122
|
+
* the data stream if it does not exist yet. The template is put again by
|
|
123
|
+
* every process that writes to the stream, so edits made to it directly do
|
|
124
|
+
* not last; an ISM policy attaches itself to the stream's backing indices
|
|
125
|
+
* through its own `ism_template` instead. Each name is set up once per
|
|
126
|
+
* client and template.
|
|
127
|
+
*
|
|
128
|
+
* @param settings Index settings for the stream's backing indices (default:
|
|
129
|
+
* 1 shard, 0 replicas, as in {@link createIndexes}).
|
|
130
|
+
* @param mappings Mappings for the backing indices, plus `@timestamp` as a
|
|
131
|
+
* date (default: only `@timestamp`, as in parsedmarc). The save functions
|
|
132
|
+
* pass the mappings they create dated indexes with.
|
|
133
|
+
* @param options The cluster to use (default: the default connection).
|
|
134
|
+
* @throws {OpenSearchError} when a concrete index or alias already holds one
|
|
135
|
+
* of the names, or the cluster returns an error. A name that fails is not
|
|
136
|
+
* remembered, so the next save retries it.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createDataStreams(names: string[], settings?: Record<string, unknown> | null, mappings?: IndexMapping | null, options?: ConnectionOptions): Promise<void>;
|
|
139
|
+
interface MigrateIndexesOptions extends ConnectionOptions {
|
|
140
|
+
/** Aggregate index names (backfilled as the `name*` pattern). */
|
|
141
|
+
aggregateIndexes?: string[] | null;
|
|
142
|
+
/** Failure index names (accepted for API compatibility; unused). */
|
|
143
|
+
failureIndexes?: string[] | null;
|
|
144
|
+
/** SMTP TLS index names (backfilled as the `name*` pattern). */
|
|
145
|
+
smtpTlsIndexes?: string[] | null;
|
|
146
|
+
/**
|
|
147
|
+
* Exact index names to check for the pre-5.0.0 `published_policy.fo`
|
|
148
|
+
* `long` mapping, as the caller's prefix/suffix configuration names them.
|
|
149
|
+
*/
|
|
150
|
+
legacyFoIndexes?: string[] | null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Runs index migrations and backfills.
|
|
154
|
+
*
|
|
155
|
+
* First, the legacy `published_policy.fo` migration for each name in
|
|
156
|
+
* `legacyFoIndexes`: an index that maps the field as `long` (parsedmarc
|
|
157
|
+
* before 5.0.0) is rebuilt as a `-v2` index with the text/keyword shape, its
|
|
158
|
+
* documents are reindexed into it, and the original is deleted.
|
|
159
|
+
*
|
|
160
|
+
* Second, it backfills `dkim_results_combined`/`spf_results_combined` on
|
|
161
|
+
* aggregate documents and `policies_combined`/`failure_details_combined` on
|
|
162
|
+
* SMTP TLS documents saved before those fields existed, as non-blocking
|
|
163
|
+
* `update_by_query` tasks against each `name*` pattern, guarded by a cheap
|
|
164
|
+
* `count`. Errors are logged as warnings, never thrown: the work is retried
|
|
165
|
+
* at the next startup.
|
|
166
|
+
*/
|
|
167
|
+
export declare function migrateIndexes(options?: MigrateIndexesOptions): Promise<void>;
|
|
168
|
+
interface SaveOptions extends ConnectionOptions {
|
|
169
|
+
/** The suffix of the name of the index to save to. */
|
|
170
|
+
indexSuffix?: string | null;
|
|
171
|
+
/** The prefix of the name of the index to save to. */
|
|
172
|
+
indexPrefix?: string | null;
|
|
173
|
+
/**
|
|
174
|
+
* Use monthly indexes instead of daily indexes (ignored when
|
|
175
|
+
* `useDataStreams` is set).
|
|
176
|
+
*/
|
|
177
|
+
monthlyIndexes?: boolean | null;
|
|
178
|
+
/** The number of shards to use in the index (default 1). */
|
|
179
|
+
numberOfShards?: number;
|
|
180
|
+
/** The number of replicas to use in the index (default 0). */
|
|
181
|
+
numberOfReplicas?: number;
|
|
182
|
+
/**
|
|
183
|
+
* Most indexes one aggregate report may spread over (default 31, 0 = no
|
|
184
|
+
* limit). The sender picks the dates, and each new index takes a shard from
|
|
185
|
+
* the cluster's limit; the records past this go to the report's first
|
|
186
|
+
* index, with their dates intact.
|
|
187
|
+
*/
|
|
188
|
+
maxIndexesPerReport?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Save to a data stream named like the index, without the date suffix,
|
|
191
|
+
* instead of to a dated index (see {@link createDataStreams}).
|
|
192
|
+
*/
|
|
193
|
+
useDataStreams?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Saves a parsed DMARC aggregate report to OpenSearch, one document per
|
|
197
|
+
* record.
|
|
198
|
+
*
|
|
199
|
+
* @throws {AlreadySaved} when the report is already in OpenSearch.
|
|
200
|
+
* @throws {OpenSearchError} when OpenSearch fails or rejects the document.
|
|
201
|
+
*/
|
|
202
|
+
export declare function saveAggregateReportToOpenSearch(aggregateReport: AggregateReport, options?: SaveOptions): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Saves a parsed DMARC failure report to OpenSearch.
|
|
205
|
+
*
|
|
206
|
+
* @throws {AlreadySaved} when the failure sample is already in OpenSearch.
|
|
207
|
+
* @throws {OpenSearchError} when OpenSearch fails or rejects the document.
|
|
208
|
+
* @throws {InvalidFailureReport} when the report lacks a required field.
|
|
209
|
+
*/
|
|
210
|
+
export declare function saveFailureReportToOpenSearch(failureReport: FailureReport, options?: SaveOptions): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Saves a parsed SMTP TLS report to OpenSearch.
|
|
213
|
+
*
|
|
214
|
+
* @throws {AlreadySaved} when the report is already in OpenSearch.
|
|
215
|
+
* @throws {OpenSearchError} when OpenSearch fails or rejects the document.
|
|
216
|
+
*/
|
|
217
|
+
export declare function saveSmtpTlsReportToOpenSearch(report: SMTPTLSReport, options?: SaveOptions): Promise<void>;
|
|
218
|
+
/** Backward-compatible alias of {@link saveFailureReportToOpenSearch}. */
|
|
219
|
+
export declare const saveForensicReportToOpenSearch: typeof saveFailureReportToOpenSearch;
|
|
220
|
+
/** Raised when a scroll request fails on some shards (helpers.ScanError). */
|
|
221
|
+
export declare class ScanError extends Error {
|
|
222
|
+
override name: string;
|
|
223
|
+
readonly scrollId: string;
|
|
224
|
+
constructor(scrollId: string, message: string);
|
|
225
|
+
}
|
|
226
|
+
/** Raised when some documents fail to index (helpers.BulkIndexError). */
|
|
227
|
+
export declare class BulkIndexError extends Error {
|
|
228
|
+
override name: string;
|
|
229
|
+
readonly errors: unknown[];
|
|
230
|
+
constructor(message: string, errors: unknown[]);
|
|
231
|
+
}
|
|
232
|
+
export type { ConnectionOptions, DocumentMappings, MigrateIndexesOptions, SaveOptions, SetHostsOptions };
|
|
233
|
+
//# sourceMappingURL=index.d.ts.map
|