@haraka/test-fixtures 0.0.0-stage → 2.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.
@@ -0,0 +1,270 @@
1
+ // A mock SMTP Transaction
2
+
3
+ import util from 'node:util'
4
+
5
+ import Notes from '@haraka/notes'
6
+ import message from 'haraka-email-message'
7
+
8
+ import logger from './logger.js'
9
+
10
+ /** @typedef {import('./logger.js').LogMethod} LogMethod */
11
+
12
+ export class Transaction {
13
+ // installed by logger.add_log_methods(); declared for the types
14
+ /** @type {LogMethod} */ logdata
15
+ /** @type {LogMethod} */ logprotocol
16
+ /** @type {LogMethod} */ logdebug
17
+ /** @type {LogMethod} */ loginfo
18
+ /** @type {LogMethod} */ lognotice
19
+ /** @type {LogMethod} */ logwarn
20
+ /** @type {LogMethod} */ logerror
21
+ /** @type {LogMethod} */ logcrit
22
+ /** @type {LogMethod} */ logalert
23
+ /** @type {LogMethod} */ logemerg
24
+
25
+ /**
26
+ * @param {string} [uuid]
27
+ * @param {any} [cfg]
28
+ */
29
+ constructor(uuid, cfg) {
30
+ this.uuid = uuid || '111111-222222-333-4444444'
31
+ this.cfg = cfg
32
+ this.mail_from = null
33
+ this.rcpt_to = []
34
+ this.header_lines = []
35
+ this.data_lines = []
36
+ this.attachment_start_hooks = []
37
+ this.banner = null
38
+ this.body_filters = []
39
+ this.data_bytes = 0
40
+ this.header_pos = 0
41
+ this.found_hb_sep = false
42
+ this.body = null
43
+ this.parse_body = false
44
+ this.notes = new Notes()
45
+ this.notes.skip_plugins = []
46
+ this.header = new message.Header()
47
+ this.message_stream = new message.stream(this.cfg, this.uuid, this.header.header_list)
48
+ this.discard_data = false
49
+ this.resetting = false
50
+ this.rcpt_count = {
51
+ accept: 0,
52
+ tempfail: 0,
53
+ reject: 0,
54
+ }
55
+ this.msg_status = undefined
56
+ this.data_post_start = null
57
+ this.data_post_delay = 0
58
+ this.encoding = 'utf8'
59
+ this.mime_part_count = 0
60
+ }
61
+
62
+ ensure_body() {
63
+ if (this.body) return
64
+
65
+ this.body = new message.Body(this.header)
66
+ for (const hook of this.attachment_start_hooks) {
67
+ this.body.on('attachment_start', hook)
68
+ }
69
+
70
+ if (this.banner) this.body.set_banner(this.banner)
71
+
72
+ for (const o of this.body_filters) {
73
+ this.body.add_filter((ct, enc, buf) => {
74
+ const re_match = util.types.isRegExp(o.ct_match) && o.ct_match.test(ct.toLowerCase())
75
+ const ct_begins = ct.toLowerCase().indexOf(String(o.ct_match).toLowerCase()) === 0
76
+ if (re_match || ct_begins) return o.filter(ct, enc, buf)
77
+ })
78
+ }
79
+ }
80
+
81
+ // Removes the CR of a CRLF newline at the end of the buffer.
82
+ remove_final_cr(data) {
83
+ if (data.length < 2) return data
84
+ if (!Buffer.isBuffer(data)) data = Buffer.from(data)
85
+
86
+ if (data[data.length - 2] === 0x0d && data[data.length - 1] === 0x0a) {
87
+ data[data.length - 2] = 0x0a
88
+ return data.slice(0, data.length - 1)
89
+ }
90
+ return data
91
+ }
92
+
93
+ // Duplicates any '.' chars at the beginning of a line (dot-stuffing) and
94
+ // ensures all newlines are CRLF.
95
+ add_dot_stuffing_and_ensure_crlf_newlines(data) {
96
+ if (!data.length) return data
97
+ if (!Buffer.isBuffer(data)) data = Buffer.from(data)
98
+
99
+ // Make a new buffer big enough to hold two bytes for every one input
100
+ // byte. At most, we add one extra character per input byte, so this
101
+ // is always big enough. We allocate it "unsafe" (i.e. no memset) for
102
+ // speed because we're about to fill it with data, and the remainder of
103
+ // the space we don't fill will be sliced away before we return this.
104
+ const output = Buffer.allocUnsafe(data.length * 2)
105
+ let output_pos = 0
106
+
107
+ let input_pos = 0
108
+ let next_dot = data.indexOf(0x2e)
109
+ let next_lf = data.indexOf(0x0a)
110
+ while (next_dot !== -1 || next_lf !== -1) {
111
+ const run_end = next_dot !== -1 && (next_lf === -1 || next_dot < next_lf) ? next_dot : next_lf
112
+
113
+ // Copy up till whichever comes first, '.' or '\n' (but don't
114
+ // copy the '.' or '\n' itself).
115
+ data.copy(output, output_pos, input_pos, run_end)
116
+ output_pos += run_end - input_pos
117
+
118
+ if (data[run_end] === 0x2e && (run_end === 0 || data[run_end - 1] === 0x0a)) {
119
+ // Replace /^\./ with '..'
120
+ output[output_pos++] = 0x2e
121
+ } else if (data[run_end] === 0x0a && (run_end === 0 || data[run_end - 1] !== 0x0d)) {
122
+ // Replace /\r?\n/ with '\r\n'
123
+ output[output_pos++] = 0x0d
124
+ }
125
+ output[output_pos++] = data[run_end]
126
+
127
+ input_pos = run_end + 1
128
+
129
+ if (run_end === next_dot) {
130
+ next_dot = data.indexOf(0x2e, input_pos)
131
+ } else {
132
+ next_lf = data.indexOf(0x0a, input_pos)
133
+ }
134
+ }
135
+
136
+ if (input_pos < data.length) {
137
+ data.copy(output, output_pos, input_pos)
138
+ output_pos += data.length - input_pos
139
+ }
140
+
141
+ return output.slice(0, output_pos)
142
+ }
143
+
144
+ add_data(line) {
145
+ if (typeof line === 'string') {
146
+ // This shouldn't ever happen...
147
+ line = Buffer.from(line, this.encoding)
148
+ }
149
+ // is this the end of headers line?
150
+ if (this.header_pos === 0 && (line[0] === 0x0a || (line[0] === 0x0d && line[1] === 0x0a))) {
151
+ this.header.parse(this.header_lines)
152
+ this.header_pos = this.header_lines.length
153
+ this.found_hb_sep = true
154
+ if (this.parse_body) {
155
+ this.ensure_body()
156
+ }
157
+ } else if (this.header_pos === 0) {
158
+ // Build up headers
159
+ if (this.header_lines.length < this.cfg.headers.max_lines) {
160
+ if (line[0] === 0x2e) line = line.slice(1) // Strip leading "."
161
+ this.header_lines.push(line.toString(this.encoding).replace(/\r\n$/, '\n'))
162
+ }
163
+ } else if (this.parse_body) {
164
+ let new_line = line
165
+ if (new_line[0] === 0x2e) new_line = new_line.slice(1) // Strip leading "."
166
+
167
+ line = this.add_dot_stuffing_and_ensure_crlf_newlines(this.body.parse_more(this.remove_final_cr(new_line)))
168
+ if (!line.length) return // buffering for banners
169
+ }
170
+
171
+ if (!this.discard_data) this.message_stream.add_line(line)
172
+ }
173
+
174
+ /** @param {() => void} [cb] */
175
+ end_data(cb) {
176
+ if (!this.found_hb_sep && this.header_lines.length) {
177
+ // Headers not parsed yet - must be a busted email
178
+ // Strategy: Find the first line that doesn't look like a header.
179
+ // Treat anything before that as headers, anything after as body.
180
+ let header_pos = 0
181
+ for (let i = 0; i < this.header_lines.length; i++) {
182
+ // Anything that doesn't match a header or continuation
183
+ if (!/^(?:([^\s:]*):\s*([\s\S]*)$|[ \t])/.test(this.header_lines[i])) {
184
+ break
185
+ }
186
+ header_pos = i
187
+ }
188
+ const body_lines = this.header_lines.splice(header_pos + 1)
189
+ this.header.parse(this.header_lines)
190
+ this.header_pos = header_pos
191
+ if (this.parse_body) {
192
+ this.ensure_body()
193
+ for (const bodyLine of body_lines) {
194
+ this.body.parse_more(bodyLine)
195
+ }
196
+ }
197
+ }
198
+ if (this.header_pos && this.parse_body) {
199
+ const line = this.add_dot_stuffing_and_ensure_crlf_newlines(this.body.parse_end())
200
+ if (line.length) {
201
+ this.body.force_end()
202
+
203
+ if (!this.discard_data) this.message_stream.add_line(line)
204
+ }
205
+ }
206
+
207
+ if (this.discard_data) {
208
+ cb()
209
+ } else {
210
+ this.message_stream.add_line_end(cb)
211
+ }
212
+ }
213
+
214
+ add_header(key, value) {
215
+ this.header.add_end(key, value)
216
+ if (this.header_pos > 0) this.reset_headers()
217
+ }
218
+
219
+ add_leading_header(key, value) {
220
+ this.header.add(key, value)
221
+ if (this.header_pos > 0) this.reset_headers()
222
+ }
223
+
224
+ reset_headers() {
225
+ const header_lines = this.header.lines()
226
+ this.header_pos = header_lines.length
227
+ }
228
+
229
+ remove_header(key) {
230
+ this.header.remove(key)
231
+ if (this.header_pos > 0) this.reset_headers()
232
+ }
233
+
234
+ attachment_hooks(start) {
235
+ this.parse_body = 1
236
+ this.attachment_start_hooks.push(start)
237
+ }
238
+
239
+ /**
240
+ * @param {string} text
241
+ * @param {string} [html]
242
+ */
243
+ set_banner(text, html) {
244
+ // throw "transaction.set_banner is currently non-functional";
245
+ this.parse_body = true
246
+ if (!html) {
247
+ html = text.replace(/\n/g, '<br/>\n')
248
+ }
249
+ this.banner = [text, html]
250
+ }
251
+
252
+ add_body_filter(ct_match, filter) {
253
+ this.parse_body = true
254
+ this.body_filters.push({ ct_match, filter })
255
+ }
256
+
257
+ incr_mime_count() {
258
+ this.mime_part_count++
259
+ }
260
+ }
261
+
262
+ /**
263
+ * @param {string} [uuid]
264
+ * @param {object} [cfg]
265
+ */
266
+ export function createTransaction(uuid, cfg) {
267
+ const t = new Transaction(uuid, cfg)
268
+ logger.add_log_methods(t, 'mock-connection')
269
+ return t
270
+ }
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@haraka/test-fixtures",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.1",
4
+ "description": "Haraka Test Fixtures",
5
+ "author": "Haraka Team <haraka.mail@gmail.com>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/haraka/test-fixtures.git"
10
+ },
11
+ "type": "module",
12
+ "main": "./index.js",
13
+ "types": "./types/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./types/index.d.ts",
17
+ "default": "./index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "CHANGELOG.md",
23
+ "config",
24
+ "index.js",
25
+ "lib",
26
+ "types"
27
+ ],
28
+ "engines": {
29
+ "node": ">=24"
30
+ },
31
+ "dependencies": {
32
+ "@haraka/config": "^2.0.1",
33
+ "@haraka/constants": "^2.0.0",
34
+ "@haraka/email-address": "^3.1.7",
35
+ "@haraka/notes": "^2.0.1",
36
+ "@haraka/results": "^3.0.1",
37
+ "@haraka/utils": "^3.0.1",
38
+ "haraka-email-message": "^1.4.5",
39
+ "ipaddr.js": "^2.5.0"
40
+ },
41
+ "devDependencies": {
42
+ "@haraka/eslint-config": "^3.0.1",
43
+ "@types/node": "^26.6.11",
44
+ "typescript": "^7.0.2"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/haraka/test-fixtures/issues"
48
+ },
49
+ "scripts": {
50
+ "prepare": "git rev-parse --git-dir >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
51
+ "format": "npm run prettier:fix && npm run lint:fix",
52
+ "lint": "eslint *.js lib test",
53
+ "lint:fix": "eslint *.js lib test --fix",
54
+ "prettier": "npx prettier . --check",
55
+ "prettier:fix": "npx prettier . --write --log-level=warn",
56
+ "qlty": "qlty smells --all",
57
+ "test": "npm run test:types && node --test test/*.js",
58
+ "test:coverage": "node --test --experimental-test-coverage test/*.js",
59
+ "test:coverage:lcov": "mkdir -p coverage && node --test --test-concurrency=1 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info test/*.js",
60
+ "versions": "npx npm-dep-mgr check",
61
+ "versions:fix": "npx npm-dep-mgr update",
62
+ "test:types": "npm run types && tsc -p test/types",
63
+ "types": "tsc -p tsconfig.json",
64
+ "prepack": "npm run types"
65
+ },
66
+ "prettier": {
67
+ "printWidth": 120,
68
+ "semi": false,
69
+ "singleQuote": true
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ }
74
+ }
@@ -0,0 +1,19 @@
1
+ export type LoadedPlugin = import('./lib/plugin.js').LoadedPlugin;
2
+ export type Connection = import('./lib/connection.js').Connection;
3
+ export type Transaction = import('./lib/transaction.js').Transaction;
4
+ export type HookResult = import('./lib/hooks.js').HookResult;
5
+ export type Stub = import('./lib/stub.js').Stub;
6
+ export { default as results, default as result_store } from '@haraka/results';
7
+ export * as assertions from './lib/assertions.js';
8
+ export * as connection from './lib/connection.js';
9
+ export * as dns from './lib/dns.js';
10
+ export * as helpers from './lib/helpers.js';
11
+ export * as hooks from './lib/hooks.js';
12
+ export * as line_socket from './lib/line_socket.js';
13
+ export { default as logger } from './lib/logger.js';
14
+ export { default as plugin } from './lib/plugin.js';
15
+ export * as transaction from './lib/transaction.js';
16
+ export { stub } from './lib/stub.js';
17
+ export { callHook, makePlugin, makeConnection, getResult } from './lib/helpers.js';
18
+ export { callConnect, callHelo, callEhlo, callMail, callRcpt, callRcptOk, callData, callDataPost, callQueue, callQueueOk, callDisconnect, } from './lib/hooks.js';
19
+ export { assertCont, assertOk, assertDeny, assertResult } from './lib/assertions.js';
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Assert the hook continued (no return code, or explicit CONT).
3
+ *
4
+ * assertCont(rc)
5
+ * assertCont(result)
6
+ *
7
+ * @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
8
+ */
9
+ export declare const assertCont: (rcOrResult: unknown) => void;
10
+ /**
11
+ * Assert the hook returned OK. Optional msg matcher.
12
+ *
13
+ * assertOk(rc)
14
+ * assertOk(result)
15
+ * assertOk(result, /accepted/)
16
+ *
17
+ * @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
18
+ * @param {string | RegExp} [msgMatcher]
19
+ */
20
+ export declare const assertOk: (rcOrResult: unknown, msgMatcher?: string | RegExp) => void;
21
+ /**
22
+ * Assert the hook denied. By default accepts any DENY* code; pass a
23
+ * specific code (DENY, DENYSOFT, DENYDISCONNECT, DENYSOFTDISCONNECT)
24
+ * to require an exact match.
25
+ *
26
+ * assertDeny(rc)
27
+ * assertDeny(result)
28
+ * assertDeny(result, /no thanks/)
29
+ * assertDeny(result, /no thanks/, DENYSOFT)
30
+ *
31
+ * @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
32
+ * @param {string | RegExp} [msgMatcher]
33
+ * @param {number} [code]
34
+ */
35
+ export declare const assertDeny: (rcOrResult: unknown, msgMatcher?: string | RegExp, code?: number) => void;
36
+ /**
37
+ * Assert that connection.results.get(plugin)[kind] contains an entry
38
+ * matching `matcher` (string substring or RegExp). Without a matcher,
39
+ * just asserts the bucket is non-empty.
40
+ *
41
+ * assertResult(conn, plugin, 'pass')
42
+ * assertResult(conn, plugin, 'pass', /^connect:/)
43
+ * assertResult(conn, 'access', 'fail', 'blacklist')
44
+ *
45
+ * @param {{ results: import('@haraka/results').default }} connection
46
+ * @param {string | { name: string }} pluginOrName
47
+ * @param {string} kind
48
+ * @param {string | RegExp} [matcher]
49
+ */
50
+ export declare const assertResult: (connection: {
51
+ results: import('@haraka/results').default;
52
+ }, pluginOrName: string | {
53
+ name: string;
54
+ }, kind: string, matcher?: string | RegExp) => void;
@@ -0,0 +1,150 @@
1
+ import Notes from '@haraka/notes';
2
+ import ResultStore from '@haraka/results';
3
+ import * as transaction from './transaction.js';
4
+ export type LogMethod = import('./logger.js').LogMethod;
5
+ export declare class Connection {
6
+ client: any;
7
+ server: any;
8
+ cfg: any;
9
+ local: {
10
+ ip: null;
11
+ port: null;
12
+ host: string;
13
+ info: string;
14
+ };
15
+ remote: {
16
+ ip: string;
17
+ port: null;
18
+ host: null;
19
+ info: null;
20
+ closed: boolean;
21
+ is_private: boolean;
22
+ is_local: boolean;
23
+ };
24
+ hello: {
25
+ host: null;
26
+ verb: null;
27
+ };
28
+ tls: {
29
+ enabled: boolean;
30
+ advertised: boolean;
31
+ verified: boolean;
32
+ cipher: {};
33
+ };
34
+ proxy: {
35
+ allowed: boolean;
36
+ ip: null;
37
+ type: null;
38
+ timer: null;
39
+ };
40
+ current_data: any;
41
+ current_line: any;
42
+ state: number;
43
+ encoding: string;
44
+ prev_state: number | null;
45
+ loop_code: any;
46
+ loop_msg: any;
47
+ uuid: string;
48
+ notes: Notes;
49
+ transaction: transaction.Transaction | null;
50
+ tran_count: number;
51
+ capabilities: any;
52
+ ehlo_hello_message: string;
53
+ connection_close_message: string;
54
+ banner_includes_uuid: boolean;
55
+ deny_includes_uuid: boolean;
56
+ early_talker: boolean;
57
+ pipelining: boolean;
58
+ _relaying: boolean;
59
+ esmtp: boolean;
60
+ last_response: any;
61
+ hooks_to_run: any[];
62
+ start_time: number;
63
+ last_reject: string;
64
+ max_bytes: number;
65
+ max_mime_parts: number;
66
+ totalbytes: number;
67
+ rcpt_count: {
68
+ accept: number;
69
+ tempfail: number;
70
+ reject: number;
71
+ };
72
+ msg_count: {
73
+ accept: number;
74
+ tempfail: number;
75
+ reject: number;
76
+ };
77
+ max_line_length: number;
78
+ max_data_line_length: number;
79
+ results: ResultStore;
80
+ errors: number;
81
+ last_rcpt_msg: string | null | undefined;
82
+ hook: any;
83
+ /** @type {LogMethod} */ logdata: LogMethod;
84
+ /** @type {LogMethod} */ logprotocol: LogMethod;
85
+ /** @type {LogMethod} */ logdebug: LogMethod;
86
+ /** @type {LogMethod} */ loginfo: LogMethod;
87
+ /** @type {LogMethod} */ lognotice: LogMethod;
88
+ /** @type {LogMethod} */ logwarn: LogMethod;
89
+ /** @type {LogMethod} */ logerror: LogMethod;
90
+ /** @type {LogMethod} */ logcrit: LogMethod;
91
+ /** @type {LogMethod} */ logalert: LogMethod;
92
+ /** @type {LogMethod} */ logemerg: LogMethod;
93
+ constructor(client: any, server: any, cfg: any);
94
+ static setupClient(self: any): void;
95
+ setTLS(obj: any): void;
96
+ set(prop_str: any, val: any): void;
97
+ get(prop_str: any): any;
98
+ set relaying(val: unknown);
99
+ get relaying(): unknown;
100
+ auth_results(): void;
101
+ /**
102
+ * @param {string} [err]
103
+ * @param {object} [err_data]
104
+ */
105
+ fail(err?: string, err_data?: object): void;
106
+ /**
107
+ * @param {number} code
108
+ * @param {string | string[]} msg
109
+ * @param {() => any} [func]
110
+ */
111
+ respond(code: number, msg: string | string[], func?: () => any): any;
112
+ /** @param {() => void} [done] */
113
+ init_transaction(done?: () => void): void;
114
+ /** @param {() => void} [done] */
115
+ reset_transaction(done?: () => void): void;
116
+ pause(): void;
117
+ resume(): void;
118
+ process_data(data: any): void;
119
+ _process_data(): void;
120
+ process_line(line: any): void;
121
+ disconnect(): void;
122
+ get_capabilities(): string[];
123
+ /**
124
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
125
+ * @param {string} [msg]
126
+ */
127
+ mail_respond(retval?: number | string, msg?: string): void;
128
+ /**
129
+ * @param {any} rcpt
130
+ * @param {string} action
131
+ * @param {string} [msg]
132
+ */
133
+ rcpt_incr(rcpt: any, action: string, msg?: string): void;
134
+ /**
135
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
136
+ * @param {string} [msg]
137
+ */
138
+ rcpt_ok_respond(retval?: number | string, msg?: string): void;
139
+ /**
140
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
141
+ * @param {string} [msg]
142
+ */
143
+ rcpt_respond(retval?: number | string, msg?: string): void;
144
+ /**
145
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
146
+ * @param {string} [msg]
147
+ */
148
+ data_respond(retval?: number | string, msg?: string): void;
149
+ }
150
+ export declare function createConnection(client?: {}, server?: {}, cfg?: {}): Connection;
@@ -0,0 +1,15 @@
1
+ export declare const TYPE: {
2
+ A: number;
3
+ MX: number;
4
+ TXT: number;
5
+ AAAA: number;
6
+ };
7
+ export declare const RCODE: {
8
+ NOERROR: number;
9
+ FORMERR: number;
10
+ SERVFAIL: number;
11
+ NXDOMAIN: number;
12
+ NOTIMP: number;
13
+ REFUSED: number;
14
+ };
15
+ export declare function start(zones?: {}, opts?: {}): Promise<any>;
@@ -0,0 +1,98 @@
1
+ import { Address } from '@haraka/email-address';
2
+ /**
3
+ * Wraps a Haraka hook callback into an awaitable Promise.
4
+ *
5
+ * Haraka hooks follow the convention: plugin.method(next, connection, ...args)
6
+ * where next is called as next(rc, msg). This helper turns that into:
7
+ *
8
+ * const { rc, msg } = await callHook(plugin, 'bare_ip', connection, 'helo')
9
+ *
10
+ * Prefer the typed call helpers (callMail, callRcpt, etc.) when possible —
11
+ * they're more readable and resolve the method name automatically. Use this
12
+ * generic version for hooks without a typed wrapper, or to call a specific
13
+ * method directly.
14
+ *
15
+ * @param {import('./plugin.js').LoadedPlugin} plugin
16
+ * @param {string} method - Hook method name (e.g. 'hook_rcpt', 'bare_ip')
17
+ * @param {object} connection
18
+ * @param {...*} args - Additional hook arguments (params, helo host, etc.)
19
+ * @returns {Promise<{rc: *, msg: *}>}
20
+ */
21
+ export declare const callHook: (plugin: import('./plugin.js').LoadedPlugin, method: string, connection: object, ...args: any[]) => Promise<{
22
+ rc: any;
23
+ msg: any;
24
+ }>;
25
+ /**
26
+ * Creates, optionally registers, and returns a Plugin instance.
27
+ *
28
+ * const plugin = makePlugin('helo.checks')
29
+ * const plugin = makePlugin('access', { configDir: __dirname })
30
+ *
31
+ * @param {string} name
32
+ * @param {object} [opts]
33
+ * @param {boolean} [opts.register=true] - call plugin.register() after creation
34
+ * @param {string} [opts.configDir] - resolve to plugin.config.module_config(path.resolve(configDir))
35
+ * *before* register() runs
36
+ * @returns {import('./plugin.js').LoadedPlugin}
37
+ */
38
+ export declare const makePlugin: (name: string, { register, configDir }?: {
39
+ register?: boolean;
40
+ configDir?: string;
41
+ }) => import('./plugin.js').LoadedPlugin;
42
+ /**
43
+ * Creates a Connection with commonly-needed options pre-applied.
44
+ *
45
+ * const conn = makeConnection({ ip: '1.2.3.4', mailFrom: 'user@host' })
46
+ *
47
+ * If mailFrom, rcptTo, or txNotes is given, a transaction is created
48
+ * automatically (no need to pass withTxn).
49
+ *
50
+ * @param {object} [opts]
51
+ * @param {string} [opts.ip='127.0.0.1'] - remote.ip
52
+ * @param {boolean} [opts.withTxn=false] - call init_transaction()
53
+ * @param {boolean} [opts.relaying=false] - connection._relaying
54
+ * @param {string} [opts.helo] - hello.host (EHLO hostname)
55
+ * @param {string|Address} [opts.mailFrom] - transaction.mail_from (string coerced to Address)
56
+ * @param {Array<string|Address>} [opts.rcptTo] - transaction.rcpt_to (strings coerced to Address)
57
+ * @param {object} [opts.notes] - seed connection.notes
58
+ * @param {object} [opts.txNotes] - seed transaction.notes
59
+ * @param {object} [opts.server] - assigned to connection.server; use for
60
+ * server.notes.* injection (e.g. shared redis handle)
61
+ * @param {string} [opts.host] - remote.host (rDNS hostname)
62
+ * @param {boolean} [opts.silent=false] - replace every log method with a no-op
63
+ * @param {boolean} [opts.stubLogs=false] - replace every log method with a recording stub()
64
+ * @returns {import('./connection.js').Connection}
65
+ */
66
+ export declare const makeConnection: ({ ip, withTxn, relaying, helo, host, mailFrom, rcptTo, notes, txNotes, server, silent, stubLogs, }?: {
67
+ ip?: string;
68
+ withTxn?: boolean;
69
+ relaying?: boolean;
70
+ helo?: string;
71
+ mailFrom?: string | Address;
72
+ rcptTo?: Array<string | Address>;
73
+ notes?: object;
74
+ txNotes?: object;
75
+ server?: object;
76
+ host?: string;
77
+ silent?: boolean;
78
+ stubLogs?: boolean;
79
+ }) => import('./connection.js').Connection;
80
+ /**
81
+ * Returns the result-store entry for a plugin, accepting either the plugin
82
+ * instance or its string name. Falls back to an empty result object so
83
+ * callers can write `getResult(conn, plugin).pass.length` without null checks.
84
+ *
85
+ * const r = getResult(connection, plugin)
86
+ * assert.ok(r.pass.length)
87
+ *
88
+ * @param {object} connection
89
+ * @param {object|string} pluginOrName
90
+ * @returns {{ pass: string[], fail: string[], skip: string[], err: string[], data: object }}
91
+ */
92
+ export declare const getResult: (connection: object, pluginOrName: object | string) => {
93
+ pass: string[];
94
+ fail: string[];
95
+ skip: string[];
96
+ err: string[];
97
+ data: object;
98
+ };