@ac-kit/net-socketmap 0.1.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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @ac-kit/net-socketmap
2
+
3
+ A client for socketmap, the protocol Postfix uses to ask an external service
4
+ whether an address exists, where to route it, or what it maps to.
5
+
6
+ It is how you put your own database behind a Postfix lookup table without
7
+ writing a Postfix plugin: Postfix sends a netstring-framed key, your service
8
+ answers `OK`, `NOTFOUND` or `TEMP`.
9
+
10
+ ```ts
11
+ import { SocketmapClient } from "@ac-kit/net-socketmap";
12
+ import { DuplexTransport } from "@ac-kit/net-transport-node";
13
+
14
+ const client = new SocketmapClient(new DuplexTransport(socket.stream));
15
+
16
+ const result = await client.lookup("aliases", "postmaster@example.com");
17
+ ```
18
+
19
+ Built on `@ac-kit/net-core`'s `Transport`, so the same client runs over TCP, a
20
+ Unix socket, or an in-memory double in a test. It imports no socket API itself.
21
+
22
+ See the
23
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/net-socketmap/)
24
+ for the full reference.
@@ -0,0 +1,2 @@
1
+ export * from "./socketmap/socketmap-client.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./socketmap/socketmap-client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { ExchangeOptions, Transport } from "@ac-kit/net-core";
2
+ import { type BaseSessionEvents, Session } from "@ac-kit/net-core";
3
+ /** A parsed socketmap lookup result. */
4
+ export type SocketmapResult = {
5
+ /** The status token returned by the server, such as `OK`, `NOTFOUND`, `TEMP`. */
6
+ status: string;
7
+ /** The value accompanying the status, or an empty string if absent. */
8
+ value: string;
9
+ };
10
+ /** Events emitted by {@link SocketmapClient}. */
11
+ export type SocketmapClientEvents = BaseSessionEvents;
12
+ /** Construction options for {@link SocketmapClient}. */
13
+ export interface SocketmapClientOptions {
14
+ /** Ceiling on undecoded received bytes. Defaults to 1 MiB. */
15
+ maxBufferSize?: number;
16
+ /**
17
+ * Maximum declared netstring payload length. Defaults to 100 KiB, well above
18
+ * any realistic lookup result and low enough that a bogus length declaration
19
+ * is rejected immediately.
20
+ */
21
+ maxPayloadLength?: number;
22
+ /** Applied to every lookup that does not specify its own timeout. */
23
+ defaultTimeoutMs?: number;
24
+ }
25
+ /**
26
+ * Postfix socketmap client.
27
+ *
28
+ * Implements the socketmap lookup protocol over netstring framing. The protocol
29
+ * is purely request-response with no unsolicited frames, so every inbound
30
+ * netstring answers the preceding {@link lookup}.
31
+ *
32
+ * Spec: http://www.postfix.org/socketmap_table.5.html
33
+ */
34
+ export declare class SocketmapClient extends Session<Uint8Array, Uint8Array | string, SocketmapClientEvents> {
35
+ private readonly defaultTimeoutMs;
36
+ /**
37
+ * @param source Any {@link Transport}. Postfix socketmaps are usually reached
38
+ * over a Unix socket — for a Node.js `Duplex`/`net.Socket`, wrap it first:
39
+ * `new DuplexTransport(socket)` from `@ac-kit/net-transport-node`.
40
+ * @param options Buffer, payload-length and timeout tuning.
41
+ */
42
+ constructor(source: Transport, options?: SocketmapClientOptions);
43
+ protected routeFrame(frame: Uint8Array): void;
44
+ /**
45
+ * Look a key up in a table.
46
+ *
47
+ * @param table The socketmap table name, for example `forward`.
48
+ * @param key The key to look up.
49
+ * @param options Abort, timeout and abort-policy overrides.
50
+ * @returns The status token and its accompanying value.
51
+ */
52
+ lookup(table: string, key: string, options?: ExchangeOptions<Uint8Array>): Promise<SocketmapResult>;
53
+ private static buildOptions;
54
+ /** Applies the client-wide timeout when the call site did not set one. */
55
+ private withDefaults;
56
+ private static parseResponse;
57
+ }
58
+ //# sourceMappingURL=socketmap-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socketmap-client.d.ts","sourceRoot":"","sources":["../../src/socketmap/socketmap-client.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} from "@ac-kit/format-netstring";
3
+ import { Session, } from "@ac-kit/net-core";
4
+ /**
5
+ * Postfix socketmap client.
6
+ *
7
+ * Implements the socketmap lookup protocol over netstring framing. The protocol
8
+ * is purely request-response with no unsolicited frames, so every inbound
9
+ * netstring answers the preceding {@link lookup}.
10
+ *
11
+ * Spec: http://www.postfix.org/socketmap_table.5.html
12
+ */
13
+ export class SocketmapClient extends Session {
14
+ defaultTimeoutMs;
15
+ /**
16
+ * @param source Any {@link Transport}. Postfix socketmaps are usually reached
17
+ * over a Unix socket — for a Node.js `Duplex`/`net.Socket`, wrap it first:
18
+ * `new DuplexTransport(socket)` from `@ac-kit/net-transport-node`.
19
+ * @param options Buffer, payload-length and timeout tuning.
20
+ */
21
+ constructor(source, options) {
22
+ super(SocketmapClient.buildOptions(source, options));
23
+ this.defaultTimeoutMs = options?.defaultTimeoutMs;
24
+ }
25
+ routeFrame(frame) {
26
+ this.offer(frame);
27
+ }
28
+ /**
29
+ * Look a key up in a table.
30
+ *
31
+ * @param table The socketmap table name, for example `forward`.
32
+ * @param key The key to look up.
33
+ * @param options Abort, timeout and abort-policy overrides.
34
+ * @returns The status token and its accompanying value.
35
+ */
36
+ async lookup(table, key, options) {
37
+ const request = encodeTextUtf8(`${table} ${key}`);
38
+ const frames = await this.request(request, () => "complete", this.withDefaults(options));
39
+ return SocketmapClient.parseResponse(decodeText(frames[0], "utf-8"));
40
+ }
41
+ static buildOptions(source, options) {
42
+ return {
43
+ transport: source,
44
+ codec: createNetstringCodec({
45
+ maxPayloadLength: options?.maxPayloadLength ?? 100 * 1024,
46
+ }),
47
+ maxBufferSize: options?.maxBufferSize ?? 1024 * 1024,
48
+ };
49
+ }
50
+ /** Applies the client-wide timeout when the call site did not set one. */
51
+ withDefaults(options) {
52
+ if (this.defaultTimeoutMs === undefined ||
53
+ options?.timeoutMs !== undefined) {
54
+ return options;
55
+ }
56
+ return { ...options, timeoutMs: this.defaultTimeoutMs };
57
+ }
58
+ static parseResponse(response) {
59
+ const space = response.indexOf(" ");
60
+ const status = space === -1 ? response : response.slice(0, space);
61
+ const value = space === -1 ? "" : response.slice(space + 1);
62
+ return { status, value };
63
+ }
64
+ }
65
+ //# sourceMappingURL=socketmap-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socketmap-client.js","sourceRoot":"","sources":["../../src/socketmap/socketmap-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAEN,OAAO,GAEP,MAAM,kBAAkB,CAAC;AA6B1B;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAIpC;IACiB,gBAAgB,CAAqB;IAEtD;;;;;OAKG;IACH,YAAY,MAAiB,EAAE,OAAgC;QAC9D,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,gBAAgB,GAAG,OAAO,EAAE,gBAAgB,CAAC;IACnD,CAAC;IAEkB,UAAU,CAAC,KAAiB;QAC9C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACX,KAAa,EACb,GAAW,EACX,OAAqC;QAErC,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAChC,OAAO,EACP,GAAG,EAAE,CAAC,UAAU,EAChB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAC1B,CAAC;QACF,OAAO,eAAe,CAAC,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IACvE,CAAC;IAEO,MAAM,CAAC,YAAY,CAC1B,MAAiB,EACjB,OAAgC;QAEhC,OAAO;YACN,SAAS,EAAE,MAAM;YACjB,KAAK,EAAE,oBAAoB,CAAC;gBAC3B,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,IAAI,GAAG,GAAG,IAAI;aACzD,CAAC;YACF,aAAa,EAAE,OAAO,EAAE,aAAa,IAAI,IAAI,GAAG,IAAI;SACpD,CAAC;IACH,CAAC;IAED,0EAA0E;IAClE,YAAY,CACnB,OAAqC;QAErC,IACC,IAAI,CAAC,gBAAgB,KAAK,SAAS;YACnC,OAAO,EAAE,SAAS,KAAK,SAAS,EAC/B,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACzD,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,QAAgB;QAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC5D,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;CACD"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@ac-kit/net-socketmap",
3
+ "version": "0.1.0",
4
+ "description": "A client for the socketmap protocol, Postfix's external table lookup protocol.",
5
+ "keywords": [
6
+ "client",
7
+ "postfix",
8
+ "protocol",
9
+ "socketmap"
10
+ ],
11
+ "homepage": "https://anthochamp.github.io/node-essentials/api/net-socketmap/",
12
+ "bugs": {
13
+ "url": "https://github.com/anthochamp/node-essentials/issues"
14
+ },
15
+ "license": "BSD-3-Clause",
16
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
20
+ "directory": "packages/net-socketmap"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "publishConfig": {
32
+ "main": "./dist/index.js",
33
+ "exports": {
34
+ ".": "./dist/index.js"
35
+ },
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
40
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
41
+ "clean": "rimraf dist",
42
+ "build": "yarn clean && yarn compile",
43
+ "test": "yarn run -T vitest run",
44
+ "prepack": "yarn build"
45
+ },
46
+ "dependencies": {
47
+ "@ac-kit/core": "^0.1.0",
48
+ "@ac-kit/format-netstring": "^0.1.0",
49
+ "@ac-kit/net-core": "^0.1.0"
50
+ },
51
+ "devDependencies": {
52
+ "@ac-kit/net-transport-node": "0.1.0",
53
+ "@ac-kit/tsconfig": "0.1.0",
54
+ "@ac-kit/typedoc-config": "0.1.0",
55
+ "@ac-kit/vitest-config": "0.1.0",
56
+ "@types/node": "^26.5.1",
57
+ "@typescript/native": "typescript@7.0.2",
58
+ "rimraf": "6.1.3",
59
+ "typedoc": "0.28.20",
60
+ "typescript": "@typescript/typescript6@6.0.2"
61
+ },
62
+ "engines": {
63
+ "node": ">=24"
64
+ }
65
+ }