Move src into codec, protocol, messages and session layers #53

Open
lilleman wants to merge 5 commits from move-to-folders into main
79 changed files with 573 additions and 610 deletions
Showing only changes of commit 980e9d4569 - Show all commits
+42 -40
View File
@@ -37,55 +37,58 @@ These are not preferences. Breaking one is a defect.
```
src/
index.ts Public surface. Named exports only, no default export.
client.ts client() -> { err, session }
server.ts server() -> { err, server }, server owns the listener + close()
session.ts Session: the socket's life, dispatch, events, and the collaborators below
sms.ts The live handle emitted as the 'sms' event (sendResp/sendDlr)
concat.ts How a PDU says it is a segment: its UDH, or the sar_* TLVs
dlr.ts Delivery receipts: text and TLV parsing, receipt status codes
dlr-merger.ts DlrMerger: per-segment receipts counted into one MessageDlr
error-from.ts An untyped value as error material: errorFrom() an Error, namedValue() a name
expiring-groups.ts ExpiringGroups: the capped, weighed, expiring store DlrMerger, HeldMessages and Reassembler share
held-messages.ts HeldMessages: a message from its `sms` event to its answer, capped and expiring, one MessageHold each
idle-waiters.ts IdleWaiters: waiting for a count to fall to zero, and what is left of a budget
incoming-requests.ts Every request the peer sends: messages, receipts, links, unknown commands
index.ts Public surface. Named exports only, no default export; assembles `defs`.
link-life.ts LinkLife: whether the link lives, and where a request waits for the next one
link-timers.ts LinkTimers: the enquire_link heartbeat and the idle timeout
log.ts SmppLog, the logger contract, and silentLog — the default
message.ts Encoding detection, splitting, bit counting, SMPP date formatting
message-body.ts Where an inbound body is: short_message, or the message_payload TLV
outgoing-requests.ts OutgoingRequests: the window, the pending map and the retry
pdu.ts pduToObj / objToPdu / pduReturn — synchronous, result-returning
pdu-framer.ts PduFramer: a byte stream cut into complete PDUs
pdu-refusal.ts A PDU the codec would not read, and the answer SMPP names for it
pdu-transport.ts PduTransport: the socket a session reads complete PDUs off
pending-requests.ts PendingRequests: sequence numbers, correlation, timeout, abort
reassembly.ts Reassembler: capped, expiring multipart groups
options.ts SessionOptions, ReconnectOptions, their checks, and `defaults`: every default and internal cap
reconnect-loop.ts ReconnectLoop: backoff, retry timer, stopped-ness
result.ts Result<T> — the shape every fallible call returns
retained-pdu.ts A PDU copied off the wire so holding it pins nothing else, and what holding it costs
send-sms.ts submitSms composition and the submitSmParams builder
send-window.ts SendWindow: the maxOutstanding semaphore
session-options.ts SessionOptions, ReconnectOptions, bind direction and the session defaults
sms-id.ts Message ids: the peer's notation, the <base>-<n> a segment gets, which response carries one
udh.ts User data header: its length, the concatenation fields of a long SMS and their reference
result.ts Result<T>, and an untyped value as error material: errorFrom(), namedValue(), quoted()
session.ts Session: the socket's life, dispatch, events, and the collaborators in session/
sms.ts The live handle emitted as the 'sms' event (sendResp/sendDlr)
unanswered-error.ts UnansweredError: it went out and no answer came back
uuid.ts uuidv7() — the ids the library generates for messages
defs/
codec/ Bytes <-> PduObject
commands.ts The 33 commands, their ids and ordered parameter lists
constants.ts consts + constsById, and the SMPP version constants
encodings.ts GSM 03.38, LATIN1, UCS2, detection, data_coding resolution
errors.ts errors + errorsById (ESME_*)
index.ts defs: every table as one group
field-types.ts Wire types: int8/int16/int32/string/cstring/buffer/arrays
framer.ts PduFramer: a byte stream cut into complete PDUs
pdu.ts pduToObj / objToPdu / pduReturn — synchronous, result-returning
refusal.ts A PDU the codec would not read, and the answer SMPP names for it
retained.ts A PDU copied off the wire so holding it pins nothing else, and what holding it costs
statuses.ts errors + errorsById (ESME_*)
tlvs.ts TLV definitions, tlvsById, the typed read and input shapes, and reading and writing a TLV stream
types.ts Wire types: int8/int16/int32/string/cstring/buffer/arrays
protocol/ What the fields mean
bind.ts Bind directions: which commands bind, what a direction carries, data_sm's stand-in, checkedBind()
concat.ts How a PDU says it is a segment: its UDH, or the sar_* TLVs
message-body.ts Where an inbound body is: short_message, or the message_payload TLV
message-ids.ts Message ids: the peer's notation, the <base>-<n> a segment gets, which response carries one
receipt.ts Delivery receipts: text and TLV parsing, receipt status codes
udh.ts User data header: its length, the concatenation fields of a long SMS and their reference
uuid.ts uuidv7() — the ids the library generates for messages
messages/ Whole messages across segments and time
expiring-groups.ts ExpiringGroups: the capped, weighed, expiring store DlrMerger, HeldMessages and Reassembler share
reassembly.ts Reassembler: capped, expiring multipart groups
receipt-merge.ts DlrMerger: per-segment receipts counted into one MessageDlr
submit.ts submitSms composition and the submitSmParams builder
session/ One socket's collaborators
held-messages.ts HeldMessages: a message from its `sms` event to its answer, capped and expiring, one MessageHold each
keepalive.ts LinkTimers: the enquire_link heartbeat and the idle timeout
outgoing-requests.ts OutgoingRequests: the window, the pending map and the retry
pending-requests.ts PendingRequests: sequence numbers, correlation, timeout, abort
requests-in.ts IncomingRequests: every request the peer sends: messages, receipts, links, unknown commands
send-window.ts SendWindow: the maxOutstanding semaphore
transport.ts PduTransport: the socket a session reads complete PDUs off
waiting.ts IdleWaiters: waiting for a count to fall to zero, and what is left of a budget
client/client.ts client() -> { err, session }
server/server.ts server() -> { err, server }, server owns the listener + close()
```
Imports point one way: `defs` knows nothing above it but `result.ts`, `pdu` uses `defs`, `session`
uses `pdu`, and `client`/`server` use `session`. The ways back up are the `Session` handed to
`createSms()`, `HeldMessages` and `IncomingRequests`, which call back into it, and to `OnRequest`
and `onConnected` in `session-options.ts`, all imported as a type only.
Imports point one way: `codec` ← `protocol` ← `messages` ← `session/` ← `client`/`server`, and
the root files sit beside that order; `codec` reaches outside itself only for `result.ts` and, from
`pdu.ts`, `message.ts`. The ways back up are the `Session` handed to `createSms()`, `HeldMessages`
and `IncomingRequests`, which call back into it, and to `OnRequest` and `onConnected` in
`options.ts`, all imported as a type only.
**Parameter order is wire order.** The key order inside `cmds.*.params` is the order the fields are
written to and read from the buffer. Never sort those alphabetically — the alphabetical-ordering
@@ -314,8 +317,7 @@ this is not a changelog.
`SendWindow` rather than extracted.
- `SmppLog` is a five-method contract this library declares, not a dependency.
- The TLS tests build their own self-signed certificate in DER
- `src/` stays flat until a module has to move for another reason.
- `test/` stays flat too, and a file there is named for the question it answers rather than for the
- `test/` stays flat, and a file there is named for the question it answers rather than for the
module it covers.
- CI tests on Linux only; `src/` keeps off what is known to break on macOS or Windows.
- GitHub mirrors Gitea without pruning, and a ref deleted on Gitea is deleted on GitHub by a run of
+1 -1
View File
@@ -1,4 +1,4 @@
import { server } from '../src/server.ts';
import { server } from '../src/server/server.ts';
/**
* Answers every submit_sm ESME_ROK and does nothing else, so a measurement against it reads this
+1 -1
View File
@@ -1,4 +1,4 @@
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
/**
* Pushes `count` single-segment messages and reports what the wire carried per second. Keeps
+3 -9
View File
@@ -295,7 +295,7 @@ rule and an index of the titles below.
a delivery receipt (0x04).** Appendix B makes a receipt's `stat` the message's final status, so
0x04 over `ENROUTE` emits the two disagreeing spellings of finality the reading side above has to
reconcile, and goal 3 has our own senders write the marker 3.4 defines. `sendDlr()` takes the list
from `transientStates` in `dlr.ts`, the same one the reader uses, so the two cannot drift.
from `transientStates` in `protocol/receipt.ts`, the same one the reader uses, so the two cannot drift.
Rejected: 0x04 for every state, for the sake of a peer that classifies on the marker — the cost
accepted here is that such a peer stops recognising a transient report as a report at all and hands
its application receipt text as an inbound message, where under 0x04 it would have read the state
@@ -590,7 +590,7 @@ rule and an index of the titles below.
deadlocked every multi-segment message against a production gateway
([interop-tests/findings/03-jasmin.md](../interop-tests/findings/03-jasmin.md)). Goal 1 has the answer
a real SMSC gives — one `message_id` per `submit_sm`, immediately — so the group's id base is
generated when it opens and each segment is answered `<base>-<n>`, the notation `sms-id.ts` owns
generated when it opens and each segment is answered `<base>-<n>`, the notation `protocol/message-ids.ts` owns
and `DlrMerger` reads back. The id is therefore fixed by the first segment, which is why an `smsId`
or a refusing `status` passed to `sendResp()` on such a message is an error rather than a silent
no-op. `answeredOnArrival` is on `Sms` because nothing the application can compute says it, and the
@@ -795,13 +795,7 @@ rule and an index of the titles below.
fail on every developer machine, and a committed key leaks in a public repository. Valid while the
dev image has no openssl.
- **`src/` stays flat until a module has to move for another reason.** Architecture review,
2026-09-06: the grouping the [file map](../AGENTS.md#architecture) already implies — `wire/` for `pdu*` and `defs`,
`link/` for `link-*`, `reconnect-*`, `pdu-transport` and `send-window`, `messages/` for `sms*`,
`dlr*`, `message*`, `reassembly` and `udh` — rewrites every import for no change to
`dist/index.js`, the one published entry. Valid while that map is what a reader navigates by.
- **`test/` stays flat too, and a file there is named for the question it answers rather than for the
- **`test/` stays flat, and a file there is named for the question it answers rather than for the
module it covers.** Architecture review, 2026-09-08, at 18 test files: what keeps that count honest
is the naming rule rather than a tree — `operator-receipts.test.ts` holds a corpus defined by where
it came from, cutting across four modules, where filing it by module would enter each new operator
+3 -3
View File
@@ -35,17 +35,17 @@ export default tseslint.config(
},
{
// The spec tables are data: their length tracks the specification, not any complexity.
files: ['src/defs/*.ts'],
files: ['src/codec/{commands,constants,encodings,field-types,statuses,tlvs}.ts'],
rules: { 'max-lines': 'off' },
},
{
// ESLint counts every ?. and ?? in dlrFromPdu as a branch; the 19 is 26 lines of flat field resolution.
files: ['src/dlr.ts'],
files: ['src/protocol/receipt.ts'],
rules: { complexity: ['error', 19] },
},
{
// ESC (0x1B) is the GSM 03.38 escape character, so it belongs in these patterns.
files: ['src/defs/encodings.ts'],
files: ['src/codec/encodings.ts'],
rules: { 'no-control-regex': 'off' },
},
{
+2 -2
View File
@@ -3,8 +3,8 @@ import { readFileSync } from 'node:fs';
import test, { after, describe } from 'node:test';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import type { SmppServer } from '../src/server.ts';
import { server } from '../src/server.ts';
import type { SmppServer } from '../src/server/server.ts';
import { server } from '../src/server/server.ts';
const CLOUDHOPPER_HOST = process.env.CLOUDHOPPER_HOST ?? 'cloudhopper:8080';
const SMPP_PORT = Number(process.env.SMPP_PORT ?? '2775');
+1 -1
View File
@@ -32,7 +32,7 @@ services:
dumbclient-netns:
condition: service_started
# S9's comparison run: window below maxHeldMessages (1000, session-options.ts), where nothing
# S9's comparison run: window below maxHeldMessages (1000, options.ts), where nothing
# should ever be throttled - see findings/07-load.md.
dumbclient-w500:
build: ./interop-tests/peers/dumbclient
+3 -3
View File
@@ -3,7 +3,7 @@ import test, { after, describe } from 'node:test';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import type { LogMethod, SmppLog } from '../src/log.ts';
import { server } from '../src/server.ts';
import { server } from '../src/server/server.ts';
const SMPP_PORT = Number(process.env.SMPP_PORT ?? '2775');
/** Slower than every scenario's submission rate (2000/s for the window runs), so a real backlog
@@ -206,7 +206,7 @@ after(async () => {
// S9 (target 11) and the backpressure-at-server scenario: window 2000 at a high rate against a
// handler slowed enough to build a real backlog. window500 is the same shape with a window below
// maxHeldMessages (1000, session-options.ts defaults.maxHeldMessages), the bound past which a
// maxHeldMessages (1000, options.ts defaults.maxHeldMessages), the bound past which a
// peer's window is answered ESME_RTHROTTLED. smpp-dumb-client counts a throttled message as sent
// and never resends it, so window 2000 accounts for 20,000 as answered plus throttled.
const throttleMessage = 'session - unanswered messages at their bound, asking the peer to retry';
@@ -270,7 +270,7 @@ describe('S6 - idle peer, no enquire_link at all', () => {
assert.ok(bound, 'dumb-idle never submitted its one message');
// idleTimeout is 40s from the last byte the peer sent (its submit_sm), never from our own
// writes (link-timers.ts resets only on inbound data). This test may start running well
// writes (session/keepalive.ts resets only on inbound data). This test may start running well
// past that mark on its own (S9 above can take a minute) - statsFor(...).closed is set from
// a 'close' listener attached at session-creation time, so a close from before this test
// even started is still seen; budget is slack for a session that is still open, not a clock.
+8 -8
View File
@@ -1,18 +1,18 @@
import assert from 'node:assert/strict';
import http from 'node:http';
import test, { after, describe } from 'node:test';
import type { Dlr } from '../src/dlr.ts';
import type { EncodingName } from '../src/defs/encodings.ts';
import type { PduObject } from '../src/pdu.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { EncodingName } from '../src/codec/encodings.ts';
import type { PduObject } from '../src/codec/pdu.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { ConcatReference } from '../src/udh.ts';
import { client } from '../src/client.ts';
import { ConcatReference } from '../src/protocol/udh.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from '../test/teardown.ts';
import { paramText } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import { paramText } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
import { encodeMessage, splitMessage } from '../src/message.ts';
import { submitSmParams } from '../src/send-sms.ts';
import { submitSmParams } from '../src/messages/submit.ts';
const PEER_HOST = process.env.PEER_HOST ?? 'jasmin';
const PEER_PORT = Number(process.env.PEER_PORT ?? '2775');
+1 -1
View File
@@ -5,7 +5,7 @@ import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { PduRefusedError } from '../src/index.ts';
import { bareTlvHeader, pduBytes } from '../test/raw-pdus.ts';
import { server } from '../src/server.ts';
import { server } from '../src/server/server.ts';
const JSMPP_HOST = process.env.JSMPP_HOST ?? 'jsmpp:8080';
const SMPP_PORT = Number(process.env.SMPP_PORT ?? '2775');
+8 -8
View File
@@ -1,17 +1,17 @@
import assert from 'node:assert/strict';
import http from 'node:http';
import test, { after, describe } from 'node:test';
import type { MessageState } from '../src/defs/constants.ts';
import type { Dlr } from '../src/dlr.ts';
import type { MessageState } from '../src/codec/constants.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { ConcatReference } from '../src/udh.ts';
import { consts } from '../src/defs/constants.ts';
import { detect, encodings } from '../src/defs/encodings.ts';
import { paramText } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import { ConcatReference } from '../src/protocol/udh.ts';
import { consts } from '../src/codec/constants.ts';
import { detect, encodings } from '../src/codec/encodings.ts';
import { paramText } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
import { splitMessage } from '../src/message.ts';
import { submitSmParams } from '../src/send-sms.ts';
import { submitSmParams } from '../src/messages/submit.ts';
// smsbox HTTP hosts, one per variant - all point at the same node:2775 SMPP server.
const MAIN_SMSBOX = process.env.MAIN_SMSBOX ?? 'kannel-smsbox:13013';
+1 -1
View File
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
import test, { after, describe } from 'node:test';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { paramText } from '../src/defs/types.ts';
import { paramText } from '../src/codec/field-types.ts';
import { isCommand, server } from '../src/index.ts';
const DRIVER = process.env.PHP_DRIVER ?? 'php:8080';
+2 -2
View File
@@ -2,8 +2,8 @@ import assert from 'node:assert/strict';
import test, { after, describe } from 'node:test';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { encodings } from '../src/defs/encodings.ts';
import { paramText } from '../src/defs/types.ts';
import { encodings } from '../src/codec/encodings.ts';
import { paramText } from '../src/codec/field-types.ts';
import { isCommand, server } from '../src/index.ts';
const DRIVER = process.env.PYTHON_DRIVER ?? 'python:8080';
+2 -2
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import test, { after, describe } from 'node:test';
import type { Session } from '../src/session.ts';
import { server } from '../src/server.ts';
import { server } from '../src/server/server.ts';
const SMPP_PORT = Number(process.env.SMPP_PORT ?? '2775');
@@ -54,7 +54,7 @@ describe('smppload (blocked)', () => {
const refusal = await waitFor(() => sessionErr, 10_000);
assert.ok(refusal);
// maxPduLength (pdu-refusal.ts) is 1MiB; the corrupted command_length (0x2a shifted into the
// maxPduLength (codec/refusal.ts) is 1MiB; the corrupted command_length (0x2a shifted into the
// high bytes) reads as roughly 2.75M, so this is the "unreadable stream" teardown, not the
// "one bad PDU, link stays up" path - see AGENTS.md, "A stream this library cannot frame...".
assert.match(refusal.message, /Refusing a cmd_length of \d+/);
+8 -8
View File
@@ -1,16 +1,16 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { Dlr } from '../src/dlr.ts';
import type { EncodingName } from '../src/defs/encodings.ts';
import type { MessageDlr } from '../src/dlr-merger.ts';
import type { PduObject } from '../src/pdu.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { EncodingName } from '../src/codec/encodings.ts';
import type { MessageDlr } from '../src/messages/receipt-merge.ts';
import type { PduObject } from '../src/codec/pdu.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from '../test/teardown.ts';
import { consts } from '../src/defs/constants.ts';
import { paramText } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import { consts } from '../src/codec/constants.ts';
import { paramText } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
const PEER_HOST = process.env.PEER_HOST ?? 'smppsim';
const PEER_PORT = Number(process.env.PEER_PORT ?? '2775');
+2 -2
View File
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { Dlr } from '../src/dlr.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from '../test/teardown.ts';
const PEER_HOST = process.env.PEER_HOST ?? 'smscsim';
+9 -21
View File
@@ -1,18 +1,18 @@
import type { ConnectionOptions } from 'node:tls';
import type { Result, VoidResult } from './result.ts';
import type { BindType, ReconnectOptions } from './session-options.ts';
import type { SmppLog } from './log.ts';
import type { SmsIdFormat } from './sms-id.ts';
import type { Result, VoidResult } from '../result.ts';
import type { BindType } from '../protocol/bind.ts';
import type { ReconnectOptions } from '../options.ts';
import type { SmppLog } from '../log.ts';
import type { SmsIdFormat } from '../protocol/message-ids.ts';
import type { Socket } from 'node:net';
export type { BindType };
import { ReconnectLoop } from './reconnect-loop.ts';
import { Session } from './session.ts';
import { checkSessionOptions } from './session-options.ts';
import { ReconnectLoop } from '../reconnect-loop.ts';
import { Session } from '../session.ts';
import { checkSessionOptions, defaults } from '../options.ts';
import { connect as netConnect } from 'node:net';
import { connect as tlsConnect } from 'node:tls';
import { defaultInterfaceVersion } from './defs/constants.ts';
import { guardedLog } from './log.ts';
import { guardedLog } from '../log.ts';
/** `fromStart` puts the very first connect and bind through the same backoff loop as a drop. */
type ReconnectTuning = { fromStart?: boolean; maxDelay?: number; minDelay?: number };
@@ -41,18 +41,6 @@ export type ClientOptions = {
username?: string;
};
const defaults = {
bindType: 'transceiver',
connectTimeout: 10_000,
enquireLinkInterval: 20_000,
host: 'localhost',
/** The idle timeout is what notices a dead link, so it has to outlast one silent probe. */
idleTimeoutFactor: 2,
interfaceVersion: defaultInterfaceVersion,
password: 'pass',
port: 2775,
username: 'user',
} as const;
function armConnectTimeout(
sock: Socket,
@@ -1,5 +1,5 @@
import type { WireType } from './types.ts';
import { buffer, cstring, dest_address_array, int8, unsuccess_sme_array } from './types.ts';
import type { WireType } from './field-types.ts';
import { buffer, cstring, dest_address_array, int8, unsuccess_sme_array } from './field-types.ts';
type CommandSpec = {
id: number;
@@ -1,6 +1,3 @@
/** The version declared on the wire. The tables below cover 5.0, which is a superset of it. */
export const defaultInterfaceVersion = 0x34;
/** Spec rule, not a preference: a peer declaring less than 3.4 is sent no optional parameters. */
export const optionalParamsMinVersion = 0x34;
+2 -2
View File
@@ -1,5 +1,5 @@
import type { Result } from './result.ts';
import { framingRefusal } from './pdu-refusal.ts';
import type { Result } from '../result.ts';
import { framingRefusal } from './refusal.ts';
/**
* Cuts a byte stream into whole PDUs.
+13 -13
View File
@@ -1,16 +1,16 @@
import type { CommandDefinition, CommandName, PduParams, PduParamsInput } from './defs/commands.ts';
import type { ErrorName } from './defs/errors.ts';
import type { ParamValue } from './defs/types.ts';
import type { PduHeader } from './pdu-refusal.ts';
import type { Result, VoidResult } from './result.ts';
import type { TlvInputs, Tlvs } from './defs/tlvs.ts';
import { PduRefusedError, framingRefusal } from './pdu-refusal.ts';
import { cmds, commandNameById, respNameFor } from './defs/commands.ts';
import { hasUdh } from './defs/constants.ts';
import { decodeMessage, encodeBody } from './message.ts';
import { errorNameById, errors, isErrorName } from './defs/errors.ts';
import { paramNumber, valueText } from './defs/types.ts';
import { parseTlvs, writeTlvs } from './defs/tlvs.ts';
import type { CommandDefinition, CommandName, PduParams, PduParamsInput } from './commands.ts';
import type { ErrorName } from './statuses.ts';
import type { ParamValue } from './field-types.ts';
import type { PduHeader } from './refusal.ts';
import type { Result, VoidResult } from '../result.ts';
import type { TlvInputs, Tlvs } from './tlvs.ts';
import { PduRefusedError, framingRefusal } from './refusal.ts';
import { cmds, commandNameById, respNameFor } from './commands.ts';
import { hasUdh } from './constants.ts';
import { decodeMessage, encodeBody } from '../message.ts';
import { errorNameById, errors, isErrorName } from './statuses.ts';
import { paramNumber, valueText } from './field-types.ts';
import { parseTlvs, writeTlvs } from './tlvs.ts';
/** The highest sequence number this library hands out; SMPP 3.4 4.7.1 reserves 0x7fffffff. */
export const maxSeqNr = 2147483646;
+3 -3
View File
@@ -1,6 +1,6 @@
import type { CommandName } from './defs/commands.ts';
import type { ErrorName } from './defs/errors.ts';
import { respNameFor } from './defs/commands.ts';
import type { CommandName } from './commands.ts';
import type { ErrorName } from './statuses.ts';
import { respNameFor } from './commands.ts';
/** A hostile peer must not be able to make us allocate arbitrarily. */
export const maxPduLength = 1024 * 1024;
@@ -1,6 +1,6 @@
import type { ParamValue } from './defs/types.ts';
import type { ParamValue } from './field-types.ts';
import type { PduObject } from './pdu.ts';
import { tlvOctets } from './defs/types.ts';
import { tlvOctets } from './field-types.ts';
/** Wire reads hand back views, so retaining one PDU would pin the whole chunk it arrived in. */
export function detach(pduObj: PduObject): PduObject {
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ParamValue, TlvValue, WireType } from './types.ts';
import type { ParamValue, TlvValue, WireType } from './field-types.ts';
import type { Result } from '../result.ts';
import { tlv } from './types.ts';
import { tlv } from './field-types.ts';
/** Only a tag read as octets or as a number may repeat, since its occurrences are listed as one of those. */
type Definition<Tag> = { id: number; multiple?: false; tag: Tag; type: WireType<Buffer | number | string> }
-19
View File
@@ -1,19 +0,0 @@
import { cmds, cmdsById } from './commands.ts';
import { consts, constsById } from './constants.ts';
import { encodings } from './encodings.ts';
import { errors, errorsById } from './errors.ts';
import { tlvs, tlvsById } from './tlvs.ts';
import { types } from './types.ts';
export const defs = {
cmds,
cmdsById,
consts,
constsById,
encodings,
errors,
errorsById,
tlvs,
tlvsById,
types,
};
-17
View File
@@ -1,17 +0,0 @@
/** Whatever was thrown or rejected, as an Error. `String()` throws on some values; this cannot. */
export function errorFrom(reason: unknown): Error {
if (reason instanceof Error) return reason;
try {
return new Error(String(reason));
} catch {
return new Error('A thrown value that cannot be converted to a string');
}
}
const printable: readonly string[] = ['boolean', 'number', 'string'];
/** String() throws on a null-prototype object, so anything but these is named by its type. */
export function namedValue(value: unknown): string {
return printable.includes(typeof value) ? String(value) : typeof value;
}
+49 -31
View File
@@ -1,13 +1,20 @@
export { client } from './client.ts';
export { server, SmppServer } from './server.ts';
import { cmds, cmdsById } from './codec/commands.ts';
import { consts, constsById } from './codec/constants.ts';
import { encodings } from './codec/encodings.ts';
import { errors, errorsById } from './codec/statuses.ts';
import { tlvs, tlvsById } from './codec/tlvs.ts';
import { types } from './codec/field-types.ts';
export { client } from './client/client.ts';
export { server, SmppServer } from './server/server.ts';
export { Session } from './session.ts';
export { cmds, cmdsById, commandNameById, isCommandName } from './defs/commands.ts';
export { consts, constsById } from './defs/constants.ts';
export { dataCodingByEncoding, detect, encodingByDataCoding, encodings, isEncodingName, messageClassOf, unencodable } from './defs/encodings.ts';
export { errorNameById, errors, errorsById, isErrorName } from './defs/errors.ts';
export { isTlvName, tlvs, tlvsById } from './defs/tlvs.ts';
export { types } from './defs/types.ts';
export { cmds, cmdsById, commandNameById, isCommandName } from './codec/commands.ts';
export { consts, constsById } from './codec/constants.ts';
export { dataCodingByEncoding, detect, encodingByDataCoding, encodings, isEncodingName, messageClassOf, unencodable } from './codec/encodings.ts';
export { errorNameById, errors, errorsById, isErrorName } from './codec/statuses.ts';
export { isTlvName, tlvs, tlvsById } from './codec/tlvs.ts';
export { types } from './codec/field-types.ts';
export {
isCommand,
@@ -16,9 +23,9 @@ export {
objToPdu,
pduReturn,
pduToObj,
} from './pdu.ts';
} from './codec/pdu.ts';
export { maxPduLength, PduRefusedError } from './pdu-refusal.ts';
export { maxPduLength, PduRefusedError } from './codec/refusal.ts';
export {
bitCount,
@@ -29,27 +36,27 @@ export {
splitMessage,
} from './message.ts';
export { dlrFromPdu, parseReceipt, receiptCodes } from './dlr.ts';
export { messageOctets } from './message-body.ts';
export { concatOf } from './concat.ts';
export { concatInfo } from './udh.ts';
export { PduFramer } from './pdu-framer.ts';
export { uuidv7 } from './uuid.ts';
export { dlrFromPdu, parseReceipt, receiptCodes } from './protocol/receipt.ts';
export { messageOctets } from './protocol/message-body.ts';
export { concatOf } from './protocol/concat.ts';
export { concatInfo } from './protocol/udh.ts';
export { PduFramer } from './codec/framer.ts';
export { uuidv7 } from './protocol/uuid.ts';
export type { BindType, ClientOptions } from './client.ts';
export type { Dlr, Receipt } from './dlr.ts';
export type { BindType, ClientOptions } from './client/client.ts';
export type { Dlr, Receipt } from './protocol/receipt.ts';
export type { SendDlrResult, SendRespOptions, Sms } from './sms.ts';
export type { Concat } from './concat.ts';
export type { ConcatInfo } from './udh.ts';
export type { Concat } from './protocol/concat.ts';
export type { ConcatInfo } from './protocol/udh.ts';
export type { Result, VoidResult } from './result.ts';
export type { SmppLog } from './log.ts';
export type { SmsIdFormat, SmsIdNotation } from './sms-id.ts';
export type { SmsIdFormat, SmsIdNotation } from './protocol/message-ids.ts';
export type {
AuthenticateInput,
AuthenticateResult,
ServerEvents,
ServerOptions,
} from './server.ts';
} from './server/server.ts';
export type {
CloseOptions,
MessageDlr,
@@ -60,15 +67,26 @@ export type {
SessionEvents,
SessionOptions,
} from './session.ts';
export type { CommandName, PduParams, PduParamsInput } from './defs/commands.ts';
export type { ConstGroup, MessageState, SubmitMessagingMode } from './defs/constants.ts';
export type { Encoding, EncodingName, Unencodable } from './defs/encodings.ts';
export type { ErrorName } from './defs/errors.ts';
export type { PduObject, PduObjectInput, TlvInputs } from './pdu.ts';
export type { PduHeader } from './pdu-refusal.ts';
export type { CommandName, PduParams, PduParamsInput } from './codec/commands.ts';
export type { ConstGroup, MessageState, SubmitMessagingMode } from './codec/constants.ts';
export type { Encoding, EncodingName, Unencodable } from './codec/encodings.ts';
export type { ErrorName } from './codec/statuses.ts';
export type { PduObject, PduObjectInput, TlvInputs } from './codec/pdu.ts';
export type { PduHeader } from './codec/refusal.ts';
export type { SplitOptions } from './message.ts';
export type { Tlv, TlvDefinition, TlvName, Tlvs } from './defs/tlvs.ts';
export type { DestAddress, ParamValue, TlvValue, UnsuccessSme, WireType } from './defs/types.ts';
export type { Tlv, TlvDefinition, TlvName, Tlvs } from './codec/tlvs.ts';
export type { DestAddress, ParamValue, TlvValue, UnsuccessSme, WireType } from './codec/field-types.ts';
/** The spec tables, grouped the way `larvitsmpp.defs` was in 0.4.0. */
export { defs } from './defs/index.ts';
export const defs = {
cmds,
cmdsById,
consts,
constsById,
encodings,
errors,
errorsById,
tlvs,
tlvsById,
types,
};
+4 -4
View File
@@ -1,8 +1,8 @@
import type { Result } from './result.ts';
import type { EncodingName } from './defs/encodings.ts';
import { dataCodingByEncoding, detect, encodingByDataCoding, encodings, unencodable, unencodableText } from './defs/encodings.ts';
import { hasUdh } from './defs/constants.ts';
import { udhLength } from './udh.ts';
import type { EncodingName } from './codec/encodings.ts';
import { dataCodingByEncoding, detect, encodingByDataCoding, encodings, unencodable, unencodableText } from './codec/encodings.ts';
import { hasUdh } from './codec/constants.ts';
import { udhLength } from './protocol/udh.ts';
/** A single SMS carries 1120 bits, whatever the alphabet. */
const singleMessageBits = 1120;
@@ -1,12 +1,13 @@
import type { Concat } from './concat.ts';
import type { PduObject } from './pdu.ts';
import type { SmppLog } from './log.ts';
import type { Concat } from '../protocol/concat.ts';
import type { PduObject } from '../codec/pdu.ts';
import type { SmppLog } from '../log.ts';
import { ExpiringGroups } from './expiring-groups.ts';
import { decodeMessage } from './message.ts';
import { detach, retainedOctets } from './retained-pdu.ts';
import { messageOctets } from './message-body.ts';
import { paramNumber, paramText } from './defs/types.ts';
import { uuidv7 } from './uuid.ts';
import { decodeMessage } from '../message.ts';
import { defaults } from '../options.ts';
import { detach, retainedOctets } from '../codec/retained.ts';
import { messageOctets } from '../protocol/message-body.ts';
import { paramNumber, paramText } from '../codec/field-types.ts';
import { uuidv7 } from '../protocol/uuid.ts';
/** A concatenated message given up on, whose segments the peer has already been answered for. */
export type LostGroup = {
@@ -42,8 +43,6 @@ export type Collected =
whole?: PduObject[] | undefined;
};
export const defaultMaxOctets = 64 * 1024 * 1024;
type Group = {
parts: Map<number, PduObject>;
smsId: string;
@@ -89,7 +88,7 @@ export class Reassembler {
private readonly onLost: (lost: LostGroup) => void;
constructor(options: ReassemblerOptions) {
this.maxOctets = options.maxOctets ?? defaultMaxOctets;
this.maxOctets = options.maxOctets ?? defaults.maxOctets;
this.groups = new ExpiringGroups<Group>({
max: options.max,
maxWeight: this.maxOctets,
@@ -1,8 +1,8 @@
import type { Dlr } from './dlr.ts';
import type { MessageState } from './defs/constants.ts';
import type { SmppLog } from './log.ts';
import type { Dlr } from '../protocol/receipt.ts';
import type { MessageState } from '../codec/constants.ts';
import type { SmppLog } from '../log.ts';
import { ExpiringGroups } from './expiring-groups.ts';
import { parseSegmentId } from './sms-id.ts';
import { parseSegmentId } from '../protocol/message-ids.ts';
export type MessageDlr = Dlr & { segments: Dlr[]; smsId: string };
+14 -14
View File
@@ -1,17 +1,17 @@
import type { EncodingName, Unencodable } from './defs/encodings.ts';
import type { ParamValue } from './defs/types.ts';
import type { SubmitMessagingMode } from './defs/constants.ts';
import type { PduObject, PduObjectInput } from './pdu.ts';
import type { Result } from './result.ts';
import type { SmppLog } from './log.ts';
import type { SmsIdNotation } from './sms-id.ts';
import { UnansweredError } from './unanswered-error.ts';
import { consts, defaultMessagingMode, isMessagingMode, isSubmitMessagingMode, submitMessagingModes } from './defs/constants.ts';
import { cstring, paramText } from './defs/types.ts';
import { dataCodingByEncoding, detect, encodingNames, isEncodingName, unencodable, unencodableText } from './defs/encodings.ts';
import { namedValue } from './error-from.ts';
import { normaliseSmsId } from './sms-id.ts';
import { maxSegments, smppTime, splitMessage } from './message.ts';
import type { EncodingName, Unencodable } from '../codec/encodings.ts';
import type { ParamValue } from '../codec/field-types.ts';
import type { SubmitMessagingMode } from '../codec/constants.ts';
import type { PduObject, PduObjectInput } from '../codec/pdu.ts';
import type { Result } from '../result.ts';
import type { SmppLog } from '../log.ts';
import type { SmsIdNotation } from '../protocol/message-ids.ts';
import { UnansweredError } from '../unanswered-error.ts';
import { consts, defaultMessagingMode, isMessagingMode, isSubmitMessagingMode, submitMessagingModes } from '../codec/constants.ts';
import { cstring, paramText } from '../codec/field-types.ts';
import { dataCodingByEncoding, detect, encodingNames, isEncodingName, unencodable, unencodableText } from '../codec/encodings.ts';
import { namedValue } from '../result.ts';
import { normaliseSmsId } from '../protocol/message-ids.ts';
import { maxSegments, smppTime, splitMessage } from '../message.ts';
export type SendSmsOptions = {
dlr?: boolean;
+24 -105
View File
@@ -1,77 +1,11 @@
import type { Dlr } from './dlr.ts';
import type { MessageDlr } from './dlr-merger.ts';
import type { PduObject } from './pdu.ts';
import type { PduRefusedError } from './pdu-refusal.ts';
import type { PduObject } from './codec/pdu.ts';
import type { Result, VoidResult } from './result.ts';
import type { Session } from './session.ts';
import type { SmppLog } from './log.ts';
import type { SmsIdFormat } from './sms-id.ts';
import type { Sms } from './sms.ts';
import type { SmsIdFormat } from './protocol/message-ids.ts';
import type { Socket } from 'node:net';
import { backoffDefaults } from './reconnect-loop.ts';
import { defaultMaxOctets } from './reassembly.ts';
import { isSmsIdNotation, smsIdNotations, smsIdPlaces } from './sms-id.ts';
import { namedValue } from './error-from.ts';
export type SessionEvents = {
close: [];
data: [Buffer];
disconnected: [];
dlr: [Dlr, PduObject];
incomingPdu: [Buffer];
incomingPduObj: [PduObject];
messageDlr: [MessageDlr];
reconnected: [];
sessionError: [Error | PduRefusedError];
sms: [Sms];
};
export const bindCommands: readonly string[] = [
'bind_receiver',
'bind_transceiver',
'bind_transmitter',
];
export type BindType = 'receiver' | 'transceiver' | 'transmitter';
/** Which end of the link a session is. Only `server()` is the SMSC; everything else is the ESME. */
export type LinkEnd = 'esme' | 'smsc';
export function bindTypeFromCommand(cmdName: string): BindType | undefined {
if (cmdName === 'bind_receiver') return 'receiver';
if (cmdName === 'bind_transceiver') return 'transceiver';
if (cmdName === 'bind_transmitter') return 'transmitter';
return undefined;
}
/**
* Which message-carrying command an inbound one stands in for. Every command but `data_sm` names
* its own direction; that one travels either way, so the end it arrived at is what says.
*/
export function standsInFor(cmdName: string, linkEnd: LinkEnd): string {
if (cmdName !== 'data_sm') return cmdName;
return linkEnd === 'smsc' ? 'submit_sm' : 'deliver_sm';
}
/**
* Whether a bind direction carries a command at all. A receiver-bound ESME submits nothing and a
* transmitter-bound one is delivered nothing, whichever end of the link is looking. A session that
* has not bound carries everything, since nothing has declared a direction yet.
*/
export function bindCarries(
bindType: BindType | undefined,
cmdName: string,
linkEnd: LinkEnd,
): boolean {
const carried = standsInFor(cmdName, linkEnd);
if (bindType === 'receiver') return carried !== 'submit_sm';
if (bindType === 'transmitter') return carried !== 'deliver_sm';
return true;
}
import { isSmsIdNotation, smsIdNotations, smsIdPlaces } from './protocol/message-ids.ts';
import { namedValue, quoted } from './result.ts';
export type SendOptions = { signal?: AbortSignal | undefined };
@@ -116,51 +50,36 @@ export type SessionOptions = {
systemId?: string | undefined;
};
export const defaultSystemId = '';
/** SMPP 3.4: a peer that declares no version at all is one from before optional parameters. */
export const undeclaredInterfaceVersion = 0x00;
export type SessionBind = { as: BindType; peerVersion: number };
function quoted(value: unknown): string {
return typeof value === 'string' ? JSON.stringify(value) : namedValue(value);
}
function isBindType(value: unknown): value is BindType {
return typeof value === 'string' && bindTypeFromCommand(`bind_${value}`) !== undefined;
}
/** A bind as `Session.bound()` records it: undefined declares no version, which is pre-3.4. */
export function checkedBind(bindType: unknown, declaredVersion: unknown): Result<{ bind: SessionBind }> {
if (!isBindType(bindType)) {
return { err: new Error(`bindType must be receiver, transceiver or transmitter, the bind command's name without "bind_", got ${quoted(bindType)}`) };
}
if (declaredVersion === undefined) return { bind: { as: bindType, peerVersion: undeclaredInterfaceVersion } };
if (typeof declaredVersion !== 'number' || !Number.isInteger(declaredVersion) || declaredVersion < 0 || declaredVersion > 0xFF) {
return { err: new Error(`declaredVersion must be an integer 0-255, the interface_version param or the sc_interface_version TLV's tagValue, or undefined where the peer declared none, got ${quoted(declaredVersion)}`) };
}
return { bind: { as: bindType, peerVersion: declaredVersion } };
}
export const defaults = {
bindType: 'transceiver',
connectTimeout: 10_000,
/** Receipts of a multipart message can be a working day apart, so the cap does the bounding. */
dlrMergeTimeout: 86_400_000,
enquireLinkInterval: 20_000,
/** The peer gave up on an unanswered message long before this; the bound is against growth. */
heldMessageTimeout: 300_000,
host: 'localhost',
/** The idle timeout is what notices a dead link, so it has to outlast one silent probe. */
idleTimeoutFactor: 2,
/** The version declared on the wire. */
interfaceVersion: 0x34,
maxDelay: 30_000,
maxDlrMerges: 1000,
maxHeldMessages: 1000,
maxHeldOctets: 64 * 1024 * 1024,
maxOctets: 64 * 1024 * 1024,
maxOutstanding: 10,
maxReassembly: 1000,
minDelay: 1000,
password: 'pass',
port: 2775,
reassemblyTimeout: 300_000,
responseTimeout: 30_000,
serverIdleTimeout: 40_000,
shutdownTimeout: 5000,
systemId: defaultSystemId,
};
systemId: '',
username: 'user',
} as const;
/**
* A count below 1 does not fail loudly anywhere downstream: `maxOutstanding: 0` leaves every send
@@ -187,7 +106,7 @@ export function checkSessionOptions(options: CheckableOptions): VoidResult {
function limitsOf(options: CheckableOptions): [string, number, number][] {
return [
['idleTimeout', options.idleTimeout ?? 0, 0],
['maxOctets', options.maxOctets ?? defaultMaxOctets, 1],
['maxOctets', options.maxOctets ?? defaults.maxOctets, 1],
['maxOutstanding', options.maxOutstanding ?? defaults.maxOutstanding, 1],
['maxReassembly', options.maxReassembly ?? defaults.maxReassembly, 1],
['reassemblyTimeout', options.reassemblyTimeout ?? defaults.reassemblyTimeout, 0],
@@ -243,8 +162,8 @@ function checkReconnect(reconnect: unknown): VoidResult {
return { err: new Error(`reconnect.fromStart must be true or false, got ${typeof reconnect.fromStart}`) };
}
const maxDelay = delayOr(reconnect.maxDelay, backoffDefaults.maxDelay);
const minDelay = delayOr(reconnect.minDelay, backoffDefaults.minDelay);
const maxDelay = delayOr(reconnect.maxDelay, defaults.maxDelay);
const minDelay = delayOr(reconnect.minDelay, defaults.minDelay);
// A delay of 0 never doubles, so the backoff never starts and every retry lands at once.
const checked = checkLimits([['maxDelay', maxDelay, 1], ['minDelay', minDelay, 1]]);
+73
View File
@@ -0,0 +1,73 @@
import type { Result } from '../result.ts';
import { quoted } from '../result.ts';
export const bindCommands: readonly string[] = [
'bind_receiver',
'bind_transceiver',
'bind_transmitter',
];
export type BindType = 'receiver' | 'transceiver' | 'transmitter';
/** Which end of the link a session is. Only `server()` is the SMSC; everything else is the ESME. */
export type LinkEnd = 'esme' | 'smsc';
export function bindTypeFromCommand(cmdName: string): BindType | undefined {
if (cmdName === 'bind_receiver') return 'receiver';
if (cmdName === 'bind_transceiver') return 'transceiver';
if (cmdName === 'bind_transmitter') return 'transmitter';
return undefined;
}
/**
* Which message-carrying command an inbound one stands in for. Every command but `data_sm` names
* its own direction; that one travels either way, so the end it arrived at is what says.
*/
export function standsInFor(cmdName: string, linkEnd: LinkEnd): string {
if (cmdName !== 'data_sm') return cmdName;
return linkEnd === 'smsc' ? 'submit_sm' : 'deliver_sm';
}
/**
* Whether a bind direction carries a command at all. A receiver-bound ESME submits nothing and a
* transmitter-bound one is delivered nothing, whichever end of the link is looking. A session that
* has not bound carries everything, since nothing has declared a direction yet.
*/
export function bindCarries(
bindType: BindType | undefined,
cmdName: string,
linkEnd: LinkEnd,
): boolean {
const carried = standsInFor(cmdName, linkEnd);
if (bindType === 'receiver') return carried !== 'submit_sm';
if (bindType === 'transmitter') return carried !== 'deliver_sm';
return true;
}
/** SMPP 3.4: a peer that declares no version at all is one from before optional parameters. */
export const undeclaredInterfaceVersion = 0x00;
export type SessionBind = { as: BindType; peerVersion: number };
function isBindType(value: unknown): value is BindType {
return typeof value === 'string' && bindTypeFromCommand(`bind_${value}`) !== undefined;
}
/** A bind as `Session.bound()` records it: undefined declares no version, which is pre-3.4. */
export function checkedBind(bindType: unknown, declaredVersion: unknown): Result<{ bind: SessionBind }> {
if (!isBindType(bindType)) {
return { err: new Error(`bindType must be receiver, transceiver or transmitter, the bind command's name without "bind_", got ${quoted(bindType)}`) };
}
if (declaredVersion === undefined) return { bind: { as: bindType, peerVersion: undeclaredInterfaceVersion } };
if (typeof declaredVersion !== 'number' || !Number.isInteger(declaredVersion) || declaredVersion < 0 || declaredVersion > 0xFF) {
return { err: new Error(`declaredVersion must be an integer 0-255, the interface_version param or the sc_interface_version TLV's tagValue, or undefined where the peer declared none, got ${quoted(declaredVersion)}`) };
}
return { bind: { as: bindType, peerVersion: declaredVersion } };
}
+3 -3
View File
@@ -1,9 +1,9 @@
import type { ConcatInfo } from './udh.ts';
import type { PduObject } from './pdu.ts';
import type { PduObject } from '../codec/pdu.ts';
import { concatInfo } from './udh.ts';
import { hasUdh } from './defs/constants.ts';
import { hasUdh } from '../codec/constants.ts';
import { messageOctets } from './message-body.ts';
import { paramNumber } from './defs/types.ts';
import { paramNumber } from '../codec/field-types.ts';
/** Where a segment sits in its message, and what ties it to the rest of that message. */
export type Concat = ConcatInfo & {
@@ -1,4 +1,4 @@
import type { PduObject } from './pdu.ts';
import type { PduObject } from '../codec/pdu.ts';
/**
* The user data, wherever the peer put it. SMPP 3.4 5.3.2.32 carries up to 64 KB in
@@ -1,5 +1,5 @@
import type { CommandName } from './defs/commands.ts';
import type { ParamValue } from './defs/types.ts';
import type { CommandName } from '../codec/commands.ts';
import type { ParamValue } from '../codec/field-types.ts';
const notations = {
decimal: { digits: /^[0-9]+$/, prefix: '' },
+8 -8
View File
@@ -1,12 +1,12 @@
import type { MessageState } from './defs/constants.ts';
import type { TlvValue } from './defs/types.ts';
import type { PduObject } from './pdu.ts';
import type { SmsIdFormat } from './sms-id.ts';
import { consts, constsById, hasUdh, messageTypeOf } from './defs/constants.ts';
import { encodings } from './defs/encodings.ts';
import type { MessageState } from '../codec/constants.ts';
import type { TlvValue } from '../codec/field-types.ts';
import type { PduObject } from '../codec/pdu.ts';
import type { SmsIdFormat } from './message-ids.ts';
import { consts, constsById, hasUdh, messageTypeOf } from '../codec/constants.ts';
import { encodings } from '../codec/encodings.ts';
import { messageOctets } from './message-body.ts';
import { normaliseSmsId } from './sms-id.ts';
import { paramNumber, paramText } from './defs/types.ts';
import { normaliseSmsId } from './message-ids.ts';
import { paramNumber, paramText } from '../codec/field-types.ts';
import { udhLength } from './udh.ts';
/**
View File
+3 -7
View File
@@ -1,11 +1,7 @@
import type { Result, VoidResult } from './result.ts';
import type { SmppLog } from './log.ts';
import type { Socket } from 'node:net';
export const backoffDefaults = {
maxDelay: 30_000,
minDelay: 1000,
};
import { defaults } from './options.ts';
export type ReconnectLoopOptions = {
connect: () => Promise<Result<{ sock: Socket }>>;
@@ -32,8 +28,8 @@ export class ReconnectLoop {
private upAt: number | undefined;
constructor(options: ReconnectLoopOptions) {
this.maxDelay = options.maxDelay ?? backoffDefaults.maxDelay;
this.minDelay = options.minDelay ?? backoffDefaults.minDelay;
this.maxDelay = options.maxDelay ?? defaults.maxDelay;
this.minDelay = options.minDelay ?? defaults.minDelay;
this.now = options.now ?? Date.now;
this.options = options;
this.delay = this.minDelay;
+23
View File
@@ -7,3 +7,26 @@ export type Result<T> =
| ({ err?: undefined } & T);
export type VoidResult = { err?: Error };
/** Whatever was thrown or rejected, as an Error. `String()` throws on some values; this cannot. */
export function errorFrom(reason: unknown): Error {
if (reason instanceof Error) return reason;
try {
return new Error(String(reason));
} catch {
return new Error('A thrown value that cannot be converted to a string');
}
}
const printable: readonly string[] = ['boolean', 'number', 'string'];
/** String() throws on a null-prototype object, so anything but these is named by its type. */
export function namedValue(value: unknown): string {
return printable.includes(typeof value) ? String(value) : typeof value;
}
/** A value named in an error: a string quoted, anything else as `namedValue()` names it. */
export function quoted(value: unknown): string {
return typeof value === 'string' ? JSON.stringify(value) : namedValue(value);
}
+13 -18
View File
@@ -1,19 +1,20 @@
import type { BindType, CloseOptions, OnRequest } from './session-options.ts';
import type { PduObject, TlvInputs } from './pdu.ts';
import type { Result, VoidResult } from './result.ts';
import type { BindType } from '../protocol/bind.ts';
import type { CloseOptions, OnRequest } from '../options.ts';
import type { PduObject, TlvInputs } from '../codec/pdu.ts';
import type { Result, VoidResult } from '../result.ts';
import type { Server as NetServer, Socket } from 'node:net';
import type { Server as TlsServer, TlsOptions } from 'node:tls';
import type { SmppLog } from './log.ts';
import type { SmppLog } from '../log.ts';
import { EventEmitter } from 'node:events';
import { Session, defaultSystemId } from './session.ts';
import { bindTypeFromCommand, checkSessionOptions } from './session-options.ts';
import { Session } from '../session.ts';
import { bindTypeFromCommand } from '../protocol/bind.ts';
import { checkSessionOptions, defaults } from '../options.ts';
import { createServer as createNetServer } from 'node:net';
import { createServer as createTlsServer } from 'node:tls';
import { defaultInterfaceVersion } from './defs/constants.ts';
import { errorFrom } from './error-from.ts';
import { paramText } from './defs/types.ts';
import { guardedLog } from './log.ts';
import { respNameFor } from './defs/commands.ts';
import { errorFrom } from '../result.ts';
import { paramText } from '../codec/field-types.ts';
import { guardedLog } from '../log.ts';
import { respNameFor } from '../codec/commands.ts';
export type AuthenticateResult = { userData?: unknown } | boolean;
@@ -49,12 +50,6 @@ export type ServerEvents = {
session: [Session];
};
const defaults = {
idleTimeout: 40_000,
interfaceVersion: defaultInterfaceVersion,
port: 2775,
systemId: defaultSystemId,
};
/** A listener may return a promise: an `async` one that rejects is routed like one that throws. */
type ServerListener<K extends keyof ServerEvents> = (...args: ServerEvents[K]) => unknown;
@@ -233,7 +228,7 @@ async function handleRequest(
function onConnection(sock: Socket, options: ServerOptions, server: SmppServer): void {
const log = guardedLog(options.log);
const session = new Session({
idleTimeout: options.idleTimeout ?? defaults.idleTimeout,
idleTimeout: options.idleTimeout ?? defaults.serverIdleTimeout,
log,
maxOutstanding: options.maxOutstanding,
maxOctets: options.maxOctets,
+37 -22
View File
@@ -1,30 +1,34 @@
import type { ErrorName } from './defs/errors.ts';
import type { MessageDlr } from './dlr-merger.ts';
import type { ParamValue } from './defs/types.ts';
import type { PduObject, PduObjectInput, TlvInputs } from './pdu.ts';
import type { PduRefusedError } from './pdu-refusal.ts';
import type { BindType, CloseOptions, LinkEnd, ReconnectOptions, SendOptions, SessionBind, SessionEvents, SessionOptions } from './session-options.ts';
import type { Dlr } from './protocol/receipt.ts';
import type { ErrorName } from './codec/statuses.ts';
import type { MessageDlr } from './messages/receipt-merge.ts';
import type { ParamValue } from './codec/field-types.ts';
import type { PduObject, PduObjectInput, TlvInputs } from './codec/pdu.ts';
import type { PduRefusedError } from './codec/refusal.ts';
import type { BindType, LinkEnd, SessionBind } from './protocol/bind.ts';
import type { CloseOptions, ReconnectOptions, SendOptions, SessionOptions } from './options.ts';
import type { Result, VoidResult } from './result.ts';
import type { SendSmsOptions, SendSmsResult } from './send-sms.ts';
import type { SendSmsOptions, SendSmsResult } from './messages/submit.ts';
import type { SmppLog } from './log.ts';
import type { Sms } from './sms.ts';
import type { Socket } from 'node:net';
import { DlrMerger } from './dlr-merger.ts';
import { DlrMerger } from './messages/receipt-merge.ts';
import { EventEmitter } from 'node:events';
import { IncomingRequests } from './incoming-requests.ts';
import { IncomingRequests } from './session/requests-in.ts';
import { LinkLife } from './link-life.ts';
import { LinkTimers } from './link-timers.ts';
import { OutgoingRequests } from './outgoing-requests.ts';
import { PduTransport } from './pdu-transport.ts';
import { LinkTimers } from './session/keepalive.ts';
import { OutgoingRequests } from './session/outgoing-requests.ts';
import { PduTransport } from './session/transport.ts';
import { ReconnectLoop } from './reconnect-loop.ts';
import { leftOf } from './idle-waiters.ts';
import { errorFrom } from './error-from.ts';
import { optionalParamsMinVersion } from './defs/constants.ts';
import { bindCarries, bindCommands, checkedBind, defaultSystemId, defaults } from './session-options.ts';
import { isResp, objToPdu, pduReturn } from './pdu.ts';
import { refusalAnswer } from './pdu-refusal.ts';
import { leftOf } from './session/waiting.ts';
import { errorFrom } from './result.ts';
import { optionalParamsMinVersion } from './codec/constants.ts';
import { bindCarries, checkedBind } from './protocol/bind.ts';
import { defaults } from './options.ts';
import { isResp, objToPdu, pduReturn } from './codec/pdu.ts';
import { refusalAnswer } from './codec/refusal.ts';
import { guardedLog } from './log.ts';
import { submitSms, unsent } from './send-sms.ts';
import { ConcatReference } from './udh.ts';
import { submitSms, unsent } from './messages/submit.ts';
import { ConcatReference } from './protocol/udh.ts';
export type {
CloseOptions,
@@ -33,11 +37,22 @@ export type {
SendOptions,
SendSmsOptions,
SendSmsResult,
SessionEvents,
SessionOptions,
};
export type { BindType };
export { bindCommands, defaultSystemId };
export type SessionEvents = {
close: [];
data: [Buffer];
disconnected: [];
dlr: [Dlr, PduObject];
incomingPdu: [Buffer];
incomingPduObj: [PduObject];
messageDlr: [MessageDlr];
reconnected: [];
sessionError: [Error | PduRefusedError];
sms: [Sms];
};
/** A listener may return a promise: an `async` one that rejects is routed like one that throws. */
type SessionListener<K extends keyof SessionEvents> = (...args: SessionEvents[K]) => unknown;
@@ -1,13 +1,13 @@
import type { LinkLife } from './link-life.ts';
import type { PduObject, PduObjectInput } from './pdu.ts';
import type { Result } from './result.ts';
import type { Session } from './session.ts';
import type { SmsHandlers } from './sms.ts';
import type { SmppLog } from './log.ts';
import { ExpiringGroups } from './expiring-groups.ts';
import { IdleWaiters } from './idle-waiters.ts';
import { createSms } from './sms.ts';
import { retainedOctets } from './retained-pdu.ts';
import type { LinkLife } from '../link-life.ts';
import type { PduObject, PduObjectInput } from '../codec/pdu.ts';
import type { Result } from '../result.ts';
import type { Session } from '../session.ts';
import type { SmsHandlers } from '../sms.ts';
import type { SmppLog } from '../log.ts';
import { ExpiringGroups } from '../messages/expiring-groups.ts';
import { IdleWaiters } from './waiting.ts';
import { createSms } from '../sms.ts';
import { retainedOctets } from '../codec/retained.ts';
export type HeldMessagesOptions = {
link: LinkLife;
@@ -1,4 +1,4 @@
import type { SmppLog } from './log.ts';
import type { SmppLog } from '../log.ts';
export type LinkTimersOptions = {
/** How long between enquire_link probes. Undefined or 0 never probes. */
@@ -1,14 +1,14 @@
import type { LinkLife } from './link-life.ts';
import type { PduObject, PduObjectInput } from './pdu.ts';
import type { PduTransport } from './pdu-transport.ts';
import type { Result, VoidResult } from './result.ts';
import type { SendOptions } from './session-options.ts';
import type { SmppLog } from './log.ts';
import type { LinkLife } from '../link-life.ts';
import type { PduObject, PduObjectInput } from '../codec/pdu.ts';
import type { PduTransport } from './transport.ts';
import type { Result, VoidResult } from '../result.ts';
import type { SendOptions } from '../options.ts';
import type { SmppLog } from '../log.ts';
import { PendingRequests } from './pending-requests.ts';
import { SendWindow } from './send-window.ts';
import { UnansweredError } from './unanswered-error.ts';
import { bindCommands } from './session-options.ts';
import { objToPdu } from './pdu.ts';
import { UnansweredError } from '../unanswered-error.ts';
import { bindCommands } from '../protocol/bind.ts';
import { objToPdu } from '../codec/pdu.ts';
export type OutgoingRequestsOptions = {
link: LinkLife;
@@ -1,7 +1,7 @@
import type { PduObject } from './pdu.ts';
import type { Result } from './result.ts';
import type { SmppLog } from './log.ts';
import { maxSeqNr } from './pdu.ts';
import type { PduObject } from '../codec/pdu.ts';
import type { Result } from '../result.ts';
import type { SmppLog } from '../log.ts';
import { maxSeqNr } from '../codec/pdu.ts';
export type WaitOptions = {
signal?: AbortSignal | undefined;
@@ -1,23 +1,24 @@
import type { Concat } from './concat.ts';
import type { DlrMerger } from './dlr-merger.ts';
import type { ErrorName } from './defs/errors.ts';
import type { Concat } from '../protocol/concat.ts';
import type { DlrMerger } from '../messages/receipt-merge.ts';
import type { ErrorName } from '../codec/statuses.ts';
import type { HeldMessagesOptions } from './held-messages.ts';
import type { LinkLife } from './link-life.ts';
import type { LostGroup, Refusal } from './reassembly.ts';
import type { OnRequest } from './session-options.ts';
import type { PduObject } from './pdu.ts';
import type { VoidResult } from './result.ts';
import type { Session } from './session.ts';
import type { SmppLog } from './log.ts';
import type { SmsIdFormat } from './sms-id.ts';
import type { LinkLife } from '../link-life.ts';
import type { LostGroup, Refusal } from '../messages/reassembly.ts';
import type { OnRequest } from '../options.ts';
import type { PduObject } from '../codec/pdu.ts';
import type { VoidResult } from '../result.ts';
import type { Session } from '../session.ts';
import type { SmppLog } from '../log.ts';
import type { SmsIdFormat } from '../protocol/message-ids.ts';
import { HeldMessages } from './held-messages.ts';
import { Reassembler } from './reassembly.ts';
import { bindCommands, defaults, standsInFor } from './session-options.ts';
import { concatOf } from './concat.ts';
import { detach } from './retained-pdu.ts';
import { dlrFromPdu } from './dlr.ts';
import { respIdParams, segmentId } from './sms-id.ts';
import { respNameFor } from './defs/commands.ts';
import { Reassembler } from '../messages/reassembly.ts';
import { bindCommands, standsInFor } from '../protocol/bind.ts';
import { defaults } from '../options.ts';
import { concatOf } from '../protocol/concat.ts';
import { detach } from '../codec/retained.ts';
import { dlrFromPdu } from '../protocol/receipt.ts';
import { respIdParams, segmentId } from '../protocol/message-ids.ts';
import { respNameFor } from '../codec/commands.ts';
/** Asks the peer to keep the message and retry. */
function throttledStatus(carriedAs: string): ErrorName {
@@ -1,6 +1,6 @@
import type { SmppLog } from './log.ts';
import type { VoidResult } from './result.ts';
import { IdleWaiters } from './idle-waiters.ts';
import type { SmppLog } from '../log.ts';
import type { VoidResult } from '../result.ts';
import { IdleWaiters } from './waiting.ts';
export type SendWindowOptions = {
limit: number;
@@ -1,10 +1,10 @@
import type { PduObject } from './pdu.ts';
import type { SmppLog } from './log.ts';
import type { PduObject } from '../codec/pdu.ts';
import type { SmppLog } from '../log.ts';
import type { Socket } from 'node:net';
import type { VoidResult } from './result.ts';
import { PduFramer } from './pdu-framer.ts';
import { PduRefusedError } from './pdu-refusal.ts';
import { pduToObj } from './pdu.ts';
import type { VoidResult } from '../result.ts';
import { PduFramer } from '../codec/framer.ts';
import { PduRefusedError } from '../codec/refusal.ts';
import { pduToObj } from '../codec/pdu.ts';
export type PduTransportOptions = {
log: SmppLog;
+10 -10
View File
@@ -1,17 +1,17 @@
import type { ErrorName } from './defs/errors.ts';
import type { MessageState } from './defs/constants.ts';
import type { PduObject, PduObjectInput, TlvInputs } from './pdu.ts';
import type { ErrorName } from './codec/statuses.ts';
import type { MessageState } from './codec/constants.ts';
import type { PduObject, PduObjectInput, TlvInputs } from './codec/pdu.ts';
import type { Result, VoidResult } from './result.ts';
import type { Session } from './session.ts';
import { UnansweredError } from './unanswered-error.ts';
import { consts } from './defs/constants.ts';
import { decodeSegments } from './reassembly.ts';
import { messageClassOf } from './defs/encodings.ts';
import { paramText } from './defs/types.ts';
import { receiptCodes, transientStates } from './dlr.ts';
import { consts } from './codec/constants.ts';
import { decodeSegments } from './messages/reassembly.ts';
import { messageClassOf } from './codec/encodings.ts';
import { paramText } from './codec/field-types.ts';
import { receiptCodes, transientStates } from './protocol/receipt.ts';
import { smppDate } from './message.ts';
import { respIdParams, segmentId } from './sms-id.ts';
import { uuidv7 } from './uuid.ts';
import { respIdParams, segmentId } from './protocol/message-ids.ts';
import { uuidv7 } from './protocol/uuid.ts';
/** `pduObjs` holds what the peer took, so a partial failure names what is already receipted. */
export type SendDlrResult = {
+2 -2
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { PduParams, PduParamsInput } from '../src/defs/commands.ts';
import { cmds, cmdsById, commandNameById, isCommandName } from '../src/defs/commands.ts';
import type { PduParams, PduParamsInput } from '../src/codec/commands.ts';
import { cmds, cmdsById, commandNameById, isCommandName } from '../src/codec/commands.ts';
describe('command table', () => {
test('every command is reachable by name and by id', () => {
+8 -8
View File
@@ -1,16 +1,16 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { bindToSmsc, dummySmsc } from './dummy-smsc.ts';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from './teardown.ts';
import { consts } from '../src/defs/constants.ts';
import { consts } from '../src/codec/constants.ts';
import { decodeMessage } from '../src/message.ts';
import { dlrFromPdu } from '../src/dlr.ts';
import { encodingByDataCoding, encodings } from '../src/defs/encodings.ts';
import { objToPdu, pduToObj } from '../src/pdu.ts';
import { paramNumber } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import type { PduObject } from '../src/pdu.ts';
import { dlrFromPdu } from '../src/protocol/receipt.ts';
import { encodingByDataCoding, encodings } from '../src/codec/encodings.ts';
import { objToPdu, pduToObj } from '../src/codec/pdu.ts';
import { paramNumber } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
import type { PduObject } from '../src/codec/pdu.ts';
const from = '46701113311';
const to = '46709771337';
+4 -4
View File
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { consts } from '../src/defs/constants.ts';
import { dlrFromPdu, parseReceipt, receiptCodes } from '../src/dlr.ts';
import { consts } from '../src/codec/constants.ts';
import { dlrFromPdu, parseReceipt, receiptCodes } from '../src/protocol/receipt.ts';
import { encodeMessage } from '../src/message.ts';
import { objToPdu, pduToObj } from '../src/pdu.ts';
import type { PduObject, TlvInputs } from '../src/pdu.ts';
import { objToPdu, pduToObj } from '../src/codec/pdu.ts';
import type { PduObject, TlvInputs } from '../src/codec/pdu.ts';
const receiptText = 'id:0195f0c7 sub:001 dlvrd:001 submit date:2508251430 done date:2508251431 stat:DELIVRD err:000 text:hello there';
+5 -5
View File
@@ -2,12 +2,12 @@ import assert from 'node:assert/strict';
import net from 'node:net';
import type { Session } from '../src/session.ts';
import type { TestContext } from 'node:test';
import { PduFramer } from '../src/pdu-framer.ts';
import { client } from '../src/client.ts';
import { PduFramer } from '../src/codec/framer.ts';
import { client } from '../src/client/client.ts';
import { closeAfter, closeListenerAfter } from './teardown.ts';
import { consts } from '../src/defs/constants.ts';
import { objToPdu, pduReturn, pduToObj } from '../src/pdu.ts';
import { uuidv7 } from '../src/uuid.ts';
import { consts } from '../src/codec/constants.ts';
import { objToPdu, pduReturn, pduToObj } from '../src/codec/pdu.ts';
import { uuidv7 } from '../src/protocol/uuid.ts';
export type DummySmsc = {
/** Writes a delivery receipt to the ESME, its body spelled as the test names it. */
+1 -1
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { dataCodingByEncoding, detect, encodingByDataCoding, encodings, isEncodingName, unencodable } from '../src/defs/encodings.ts';
import { dataCodingByEncoding, detect, encodingByDataCoding, encodings, isEncodingName, unencodable } from '../src/codec/encodings.ts';
describe('ASCII (GSM 03.38)', () => {
const samples: [string, number[]][] = [
+1 -1
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { errorFrom } from '../src/error-from.ts';
import { errorFrom } from '../src/result.ts';
test('carries an Error through and describes anything else, including what String() refuses', () => {
const original = new Error('the original');
+4 -4
View File
@@ -3,11 +3,11 @@ import test, { describe } from 'node:test';
import reference from 'smpp';
import type { ReferenceSession } from 'smpp';
import type { Sms } from '../src/sms.ts';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from './teardown.ts';
import { concatInfo } from '../src/udh.ts';
import { objToPdu, pduToObj } from '../src/pdu.ts';
import { server } from '../src/server.ts';
import { concatInfo } from '../src/protocol/udh.ts';
import { objToPdu, pduToObj } from '../src/codec/pdu.ts';
import { server } from '../src/server/server.ts';
import { splitMessage } from '../src/message.ts';
/**
+8 -8
View File
@@ -1,19 +1,19 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { PduObjectInput } from '../src/pdu.ts';
import type { SendSmsDeps } from '../src/send-sms.ts';
import type { PduObjectInput } from '../src/codec/pdu.ts';
import type { SendSmsDeps } from '../src/messages/submit.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import type { TestContext } from 'node:test';
import { bindToSmsc, dummySmsc } from './dummy-smsc.ts';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from './teardown.ts';
import { messageClassOf } from '../src/defs/encodings.ts';
import { paramNumber } from '../src/defs/types.ts';
import { pduToObj } from '../src/pdu.ts';
import { server } from '../src/server.ts';
import { messageClassOf } from '../src/codec/encodings.ts';
import { paramNumber } from '../src/codec/field-types.ts';
import { pduToObj } from '../src/codec/pdu.ts';
import { server } from '../src/server/server.ts';
import { silentLog } from '../src/log.ts';
import { submitSms } from '../src/send-sms.ts';
import { submitSms } from '../src/messages/submit.ts';
const from = '46701113311';
const to = '46709771337';
+1 -1
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { EncodingName } from '../src/defs/encodings.ts';
import type { EncodingName } from '../src/codec/encodings.ts';
import {
bitCount,
decodeMessage,
+7 -7
View File
@@ -1,16 +1,16 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { PduObjectInput } from '../src/pdu.ts';
import type { SendSmsDeps } from '../src/send-sms.ts';
import type { PduObjectInput } from '../src/codec/pdu.ts';
import type { SendSmsDeps } from '../src/messages/submit.ts';
import type { Session } from '../src/session.ts';
import type { SubmitMessagingMode } from '../src/defs/constants.ts';
import type { SubmitMessagingMode } from '../src/codec/constants.ts';
import type { TestContext } from 'node:test';
import { bindToSmsc, dummySmsc } from './dummy-smsc.ts';
import { consts, submitMessagingModes } from '../src/defs/constants.ts';
import { paramNumber } from '../src/defs/types.ts';
import { pduToObj } from '../src/pdu.ts';
import { consts, submitMessagingModes } from '../src/codec/constants.ts';
import { paramNumber } from '../src/codec/field-types.ts';
import { pduToObj } from '../src/codec/pdu.ts';
import { silentLog } from '../src/log.ts';
import { submitSms } from '../src/send-sms.ts';
import { submitSms } from '../src/messages/submit.ts';
const from = '46701113311';
const to = '46709771337';
+5 -5
View File
@@ -1,12 +1,12 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { Dlr, Receipt } from '../src/dlr.ts';
import type { Dlr, Receipt } from '../src/protocol/receipt.ts';
import type { MessageDlr } from '../src/session.ts';
import type { PduObject, TlvInputs } from '../src/pdu.ts';
import type { PduObject, TlvInputs } from '../src/codec/pdu.ts';
import { bindToSmsc, dummySmsc } from './dummy-smsc.ts';
import { consts } from '../src/defs/constants.ts';
import { dlrFromPdu, parseReceipt, receiptCodes, transientStates } from '../src/dlr.ts';
import { objToPdu, pduToObj } from '../src/pdu.ts';
import { consts } from '../src/codec/constants.ts';
import { dlrFromPdu, parseReceipt, receiptCodes, transientStates } from '../src/protocol/receipt.ts';
import { objToPdu, pduToObj } from '../src/codec/pdu.ts';
/**
* Receipt bodies as commercial operators document them, from `interop-tests/research/operator-quirks.md`
+2 -2
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { PduFramer } from '../src/pdu-framer.ts';
import { objToPdu } from '../src/pdu.ts';
import { PduFramer } from '../src/codec/framer.ts';
import { objToPdu } from '../src/codec/pdu.ts';
function pdu(seqNr: number): Buffer {
const { buffer } = objToPdu({ cmdName: 'enquire_link', seqNr });
+4 -4
View File
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { PduRefusedError, refusalAnswer } from '../src/pdu-refusal.ts';
import { isCommand, isResp, objToPdu, pduReturn, pduToObj } from '../src/pdu.ts';
import { paramText } from '../src/defs/types.ts';
import { isTlvName, tlvsById } from '../src/defs/tlvs.ts';
import { PduRefusedError, refusalAnswer } from '../src/codec/refusal.ts';
import { isCommand, isResp, objToPdu, pduReturn, pduToObj } from '../src/codec/pdu.ts';
import { paramText } from '../src/codec/field-types.ts';
import { isTlvName, tlvsById } from '../src/codec/tlvs.ts';
function encode(...args: Parameters<typeof objToPdu>): Buffer {
const { buffer, err } = objToPdu(...args);
+2 -2
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import type { PduObjectInput } from '../src/pdu.ts';
import { objToPdu } from '../src/pdu.ts';
import type { PduObjectInput } from '../src/codec/pdu.ts';
import { objToPdu } from '../src/codec/pdu.ts';
/** The octets a test writes straight to a socket, which objToPdu builds for every valid PDU. */
export function pduBytes(input: PduObjectInput): Buffer {
+6 -6
View File
@@ -1,16 +1,16 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { Dlr } from '../src/dlr.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { Session } from '../src/session.ts';
import type { Sms } from '../src/sms.ts';
import type { SmppLog } from '../src/log.ts';
import type { SmppServer } from '../src/server.ts';
import type { SmppServer } from '../src/server/server.ts';
import type { TestContext } from 'node:test';
import { PduRefusedError } from '../src/pdu-refusal.ts';
import { client } from '../src/client.ts';
import { PduRefusedError } from '../src/codec/refusal.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from './teardown.ts';
import { isCommand, objToPdu } from '../src/pdu.ts';
import { server } from '../src/server.ts';
import { isCommand, objToPdu } from '../src/codec/pdu.ts';
import { server } from '../src/server/server.ts';
function once<T>(register: (resolve: (value: T) => void) => void): Promise<T> {
return new Promise<T>((resolve, reject) => {
+25 -24
View File
@@ -1,42 +1,43 @@
import assert from 'node:assert/strict';
import net from 'node:net';
import test, { describe } from 'node:test';
import type { Collected, LostGroup } from '../src/reassembly.ts';
import type { Dlr } from '../src/dlr.ts';
import type { ErrorName } from '../src/defs/errors.ts';
import type { IncomingRequestsOptions } from '../src/incoming-requests.ts';
import type { HeldMessagesOptions, MessageHold } from '../src/held-messages.ts';
import type { MessageState } from '../src/defs/constants.ts';
import type { Collected, LostGroup } from '../src/messages/reassembly.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { ErrorName } from '../src/codec/statuses.ts';
import type { IncomingRequestsOptions } from '../src/session/requests-in.ts';
import type { HeldMessagesOptions, MessageHold } from '../src/session/held-messages.ts';
import type { MessageState } from '../src/codec/constants.ts';
import type { MessageDlr } from '../src/session.ts';
import type { PduObject, PduObjectInput } from '../src/pdu.ts';
import type { PduObject, PduObjectInput } from '../src/codec/pdu.ts';
import type { Result } from '../src/result.ts';
import type { SendSmsResult } from '../src/send-sms.ts';
import type { SendSmsResult } from '../src/messages/submit.ts';
import type { SmppLog } from '../src/log.ts';
import type { Sms } from '../src/sms.ts';
import type { SmppServer } from '../src/server.ts';
import type { SmppServer } from '../src/server/server.ts';
import type { TestContext } from 'node:test';
import { HeldMessages } from '../src/held-messages.ts';
import { IncomingRequests, refusedSegmentStatus } from '../src/incoming-requests.ts';
import { HeldMessages } from '../src/session/held-messages.ts';
import { IncomingRequests, refusedSegmentStatus } from '../src/session/requests-in.ts';
import { UnansweredError } from '../src/unanswered-error.ts';
import { createSms } from '../src/sms.ts';
import { LinkLife } from '../src/link-life.ts';
import { SendWindow } from '../src/send-window.ts';
import { Reassembler, decodeSegments } from '../src/reassembly.ts';
import { SendWindow } from '../src/session/send-window.ts';
import { Reassembler, decodeSegments } from '../src/messages/reassembly.ts';
import { Session } from '../src/session.ts';
import { DlrMerger } from '../src/dlr-merger.ts';
import { PduRefusedError } from '../src/pdu-refusal.ts';
import { objToPdu } from '../src/pdu.ts';
import { checkSessionOptions, defaults, standsInFor } from '../src/session-options.ts';
import { client } from '../src/client.ts';
import { DlrMerger } from '../src/messages/receipt-merge.ts';
import { PduRefusedError } from '../src/codec/refusal.ts';
import { objToPdu } from '../src/codec/pdu.ts';
import { checkSessionOptions, defaults } from '../src/options.ts';
import { standsInFor } from '../src/protocol/bind.ts';
import { client } from '../src/client/client.ts';
import { closeAfter, closeListenerAfter } from './teardown.ts';
import { concatOf } from '../src/concat.ts';
import { consts } from '../src/defs/constants.ts';
import { errors } from '../src/defs/errors.ts';
import { paramNumber, paramText } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import { concatOf } from '../src/protocol/concat.ts';
import { consts } from '../src/codec/constants.ts';
import { errors } from '../src/codec/statuses.ts';
import { paramNumber, paramText } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
import { silentLog } from '../src/log.ts';
import { splitMessage } from '../src/message.ts';
import { submitSms, submitSmParams } from '../src/send-sms.ts';
import { submitSms, submitSmParams } from '../src/messages/submit.ts';
async function startServer(
t: TestContext,
+14 -13
View File
@@ -1,25 +1,26 @@
import assert from 'node:assert/strict';
import net from 'node:net';
import test, { describe } from 'node:test';
import type { Dlr } from '../src/dlr.ts';
import type { PduObject, PduObjectInput } from '../src/pdu.ts';
import type { Dlr } from '../src/protocol/receipt.ts';
import type { PduObject, PduObjectInput } from '../src/codec/pdu.ts';
import type { Sms } from '../src/sms.ts';
import type { ServerOptions, SmppServer } from '../src/server.ts';
import type { ServerOptions, SmppServer } from '../src/server/server.ts';
import type { SmppLog } from '../src/log.ts';
import type { TestContext } from 'node:test';
import type { VoidResult } from '../src/result.ts';
import { DlrMerger } from '../src/dlr-merger.ts';
import { PduFramer } from '../src/pdu-framer.ts';
import { DlrMerger } from '../src/messages/receipt-merge.ts';
import { PduFramer } from '../src/codec/framer.ts';
import { ReconnectLoop } from '../src/reconnect-loop.ts';
import { Session, bindCommands } from '../src/session.ts';
import { checkSessionOptions } from '../src/session-options.ts';
import { client } from '../src/client.ts';
import { Session } from '../src/session.ts';
import { bindCommands } from '../src/protocol/bind.ts';
import { checkSessionOptions } from '../src/options.ts';
import { client } from '../src/client/client.ts';
import { closeAfter, closeListenerAfter } from './teardown.ts';
import { consts } from '../src/defs/constants.ts';
import { PduRefusedError } from '../src/pdu-refusal.ts';
import { isCommand, objToPdu, pduReturn, pduToObj } from '../src/pdu.ts';
import { paramText } from '../src/defs/types.ts';
import { server } from '../src/server.ts';
import { consts } from '../src/codec/constants.ts';
import { PduRefusedError } from '../src/codec/refusal.ts';
import { isCommand, objToPdu, pduReturn, pduToObj } from '../src/codec/pdu.ts';
import { paramText } from '../src/codec/field-types.ts';
import { server } from '../src/server/server.ts';
import { bareTlvHeader, pduBytes, shortened, truncatedTlv, withUnknownCmdId } from './raw-pdus.ts';
import { silentLog } from '../src/log.ts';
import { splitMessage } from '../src/message.ts';
+1 -1
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { normaliseSmsId, parseSegmentId, respIdParams, segmentId } from '../src/sms-id.ts';
import { normaliseSmsId, parseSegmentId, respIdParams, segmentId } from '../src/protocol/message-ids.ts';
describe('normaliseSmsId()', () => {
test('reads an id the length a message_id may be, and leaves a longer one alone', () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import type { CloseOptions } from '../src/session-options.ts';
import type { CloseOptions } from '../src/options.ts';
import type { Server, Socket } from 'node:net';
import type { TestContext } from 'node:test';
+3 -3
View File
@@ -2,14 +2,14 @@ import assert from 'node:assert/strict';
import net from 'node:net';
import test, { describe } from 'node:test';
import type { Sms } from '../src/sms.ts';
import type { SmppServer } from '../src/server.ts';
import type { SmppServer } from '../src/server/server.ts';
import type { TestContext } from 'node:test';
import { Log } from '@larvit/log';
import { TLSSocket } from 'node:tls';
import { client } from '../src/client.ts';
import { client } from '../src/client/client.ts';
import { closeAfter } from './teardown.ts';
import { generateKeyPairSync, randomBytes, sign } from 'node:crypto';
import { server } from '../src/server.ts';
import { server } from '../src/server/server.ts';
const host = 'localhost';
+3 -3
View File
@@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { DestAddress, UnsuccessSme } from '../src/defs/types.ts';
import { paramText, types } from '../src/defs/types.ts';
import { tlvs } from '../src/defs/tlvs.ts';
import type { DestAddress, UnsuccessSme } from '../src/codec/field-types.ts';
import { paramText, types } from '../src/codec/field-types.ts';
import { tlvs } from '../src/codec/tlvs.ts';
describe('integers', () => {
test('int8 reads, sizes and writes one octet', () => {
+6 -6
View File
@@ -1,14 +1,14 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import type { PduObjectInput } from '../src/pdu.ts';
import type { SendSmsDeps, SendSmsInput } from '../src/send-sms.ts';
import type { PduObjectInput } from '../src/codec/pdu.ts';
import type { SendSmsDeps, SendSmsInput } from '../src/messages/submit.ts';
import { bindToSmsc, dummySmsc } from './dummy-smsc.ts';
import { decodeMessage } from '../src/message.ts';
import { messageOctets } from '../src/message-body.ts';
import { objToPdu, pduToObj } from '../src/pdu.ts';
import { paramNumber, paramText } from '../src/defs/types.ts';
import { messageOctets } from '../src/protocol/message-body.ts';
import { objToPdu, pduToObj } from '../src/codec/pdu.ts';
import { paramNumber, paramText } from '../src/codec/field-types.ts';
import { silentLog } from '../src/log.ts';
import { submitSms } from '../src/send-sms.ts';
import { submitSms } from '../src/messages/submit.ts';
const from = '46701113311';
const to = '46709771337';
+9 -32
View File
@@ -215,7 +215,7 @@ comprehension-panel scoring run over the whole project. Each round:
- let no dimension drop, and record the four scores and the overall in this paragraph.
Each chunk also closes the items further down that it absorbs, and its PR names them: `hold` and
`refusing`, the three `defaults`, `ASCII`, `session-options.ts`, the flat `src/`, and the link that
`refusing`, `ASCII`, and the link that
dropped mid-rebind.
Every chunk that changes the public API updates README's examples, MIGRATION.md, CHANGELOG.md,
@@ -223,9 +223,6 @@ docs/decisions.md and the AGENTS.md map in its own PR, and deletes what it repla
file stand side by side. The architecture review of 2026-09-30 (ALIGN) set this order; its amendments
to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture-review-2026-09-30).
- [ ] **Move without changing behaviour.** `defs/` becomes `codec/`, `options.ts` becomes one defaults
table, and `result.ts` absorbs `error-from.ts`. Every file with one target moves to its folder
now, and the "`src/` stays flat" decision is retired in the same PR.
- [ ] **Build `protocol/`: every multi-fact octet read once into a named plain type.**
- `vocabulary.ts`: the glossary as types with one-line TSDoc.
- `data-coding.ts`: the `data_coding` table as rows, with a test that it equals today's function
@@ -277,7 +274,7 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
- [ ] **Return an `err` where `message` is not a string, rather than throwing.**
`sendSms({ message: undefined })` — a forgotten property — reaches `value.replace()` in
`defs/encodings.ts` through the alphabet detection `checkOptions()` runs, and the `TypeError`
`codec/encodings.ts` through the alphabet detection `checkOptions()` runs, and the `TypeError`
escapes `submitSms()` into the caller's process; `NaN` and `12345` do the same. README promises
"Never throws. Every fallible call resolves to `{ err?, … }`" and AGENTS.md hard rule 1 says it
again, so the docs are false for the likeliest caller mistake there is. From the stability
@@ -300,7 +297,7 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
Goals 2 then 3: `from: 1e21` is reported as sent to an address that reaches nobody, which is
the wrong answer about what happened before it is laxness in what we send. That a number is
accepted at all reaches a consumer in no sentence either: only the type comment at
`defs/commands.ts:239`, and one CHANGELOG line that stops being visible when
`codec/commands.ts`, and one CHANGELOG line that stops being visible when
0.7.0 is cut, while README's Building bullet reads as the whole rule for a text field. Whether
this is a supported spelling or 0.4.0 tolerance decides whether that sentence lands in
README.md or in MIGRATION.md — write it in the same change as the rule, so it is worded once.
@@ -319,7 +316,7 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
`responseTimeout`, `idleTimeout`, `shutdownTimeout` and `reassemblyTimeout` from below only,
and Node fires a larger delay after 1 ms. From the 2026-09-28 scoring run.
- [ ] **Keep a bare ESC out of GSM detection.** `gsmRegex` in `defs/encodings.ts` admits `\x1B`,
- [ ] **Keep a bare ESC out of GSM detection.** `gsmRegex` in `codec/encodings.ts` admits `\x1B`,
so `"\x1B("` is detected as GSM, goes out as 0x1B 0x28 and arrives as `{`. From the
2026-09-28 scoring run.
@@ -340,31 +337,17 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
### Shape — 6 today, and the gate is 7
- [ ] **Answer "is this a bind command" in one place.** `bindCommands` (read by
`incoming-requests.ts`, `outgoing-requests.ts` and `test/session.test.ts`) and
`session/requests-in.ts`, `session/outgoing-requests.ts` and `test/session.test.ts`) and
`bindTypeFromCommand()` (read by `server.ts` and `checkedBind()`) each list the three bind
commands, so a fourth added to one is missed by the other. Derive the list from the function,
or the reverse. From the stability review of #42.
- [ ] **Group `src/` into a second level, and retire whichever record loses.** 34 files on one
plane, where `src/defs/` at 7 proves the shape is known one level down. `docs/decisions.md`
says "`src/` stays flat until a module has to move for another reason. Valid while that map is
what a reader navigates by" — and both architects reported that the map is now AGENTS.md rather
than the tree, which is that premise failing. `todo.md` already carries the opposite
instruction under Worth doing. Two records, opposite answers; one has to go.
- [ ] **Split `test/session-extras.test.ts` by the question each block answers.** 3,010 lines, 19
unrelated `describe` blocks whose names are already the file names they should be. With
`session.test.ts` it is 54% of all test code and 84% the size of `src/`. "extras" names neither
a question nor a module — it names the rest — and AGENTS.md's own convention forbids exactly
that. `max-lines` covers `src/**` only, so nothing has stopped it growing.
- [ ] **Collapse the three objects named `defaults`.** `client.ts`, `server.ts` and
`session-options.ts` each export or hold one; `port: 2775` is written twice and the idle
timeout is derived two ways to the same 40 000, and 64 MiB is both `defaultMaxOctets` and
`defaults.maxHeldOctets`. "What is the default for X" has three answers
depending on the entrypoint, and nothing fails when they drift. Named by both architects as the
most likely first bug a new contributor ships.
- [ ] **Give `hold` one meaning, and rename `IncomingRequests.refusing` for what it does.**
`LinkLife.hold()` is a request's budget waiting for a link, `HeldMessages.hold()` a message the
application owes an answer; `refusing` decides no refusal — `held.full()` does — and only makes
@@ -377,12 +360,6 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
the breaking unit, so this is as cheap as it will ever be, and `todo.md` already requires the
`consts.ENCODING` names settled before the custom-encoding registry — this is the other half.
- [ ] **Split `session-options.ts` into the things it is.** Option types and their validator, the
`SessionEvents` map, and the bind-direction rules (`bindCommands`, `bindTypeFromCommand`,
`standsInFor`, `bindCarries`) are three questions in one file, and the `defaults` table mixes
option defaults with four hard bounds that are not options. Both architects named it as where
the codebase rots first: at 34-wide it is where anything session-shaped lands.
- [ ] **Name the base-versus-segment distinction in the message id types.** `Sms.smsId` is a base,
`sendSms().smsIds[]` are segment ids, `Dlr.smsId` is a segment id and `MessageDlr.smsId` is a
base again — four fields, one type, `string`. The whole multipart receipt mechanism turns on
@@ -464,9 +441,9 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
the fenced blocks at test time and assert each appears verbatim in the executed source, so an
edit to either fails the gate.
- [ ] **Narrow the `src/defs/*` lint exemption to the four table files.** Its stated reason — "the
- [ ] **Narrow the `src/codec/` table lint exemption to the four table files.** Its stated reason — "the
spec tables are data: their length tracks the specification, not any complexity" — is false for
`defs/types.ts`, which is 595 lines of wire codec with 25 functions and is the file that parses
`codec/field-types.ts`, which is 595 lines of wire codec with 25 functions and is the file that parses
hostile input from the network. It carries more over-budget methods than any other file in the
repo, under a suppression written for something else.
@@ -524,7 +501,7 @@ to the plan are [plan 3 §8](docs/comprehension-rewrite/plan-3.md#8-architecture
`idleTimeout: '5000'` is refused with `got 5000` — a value the reader reads as correct — where
`connectTimeout` quotes it. `namedValue()`'s four sites — `messagingMode`, `encoding`, the time
options and `smsIdFormat` — are the same defect once more: there `true` and `'true'` both print
as `true`. One fix closes all three, and `valueText()` in `defs/types.ts` is the quoted
as `true`. One fix closes all three, and `valueText()` in `codec/field-types.ts` is the quoted
spelling to take it from. Raised by review, 2026-09-20.
- [ ] **Refuse a send the codec cannot build before it waits for a link and a window slot.** Today
@@ -685,7 +662,7 @@ Each lands under goal 7: an option or a hook, with the call that passes none unc
### Encodings
- [ ] **Register a custom encoding.** Maintainer's ask, 2026-09-14. `EncodingName` is a closed union
of three (`defs/encodings.ts`). An entry needs a name, a `data_coding`, `encode`, `decode`,
of three (`codec/encodings.ts`). An entry needs a name, a `data_coding`, `encode`, `decode`,
`match`, whether `detect()` may pick it, and enough for `splitMessage()` to budget a segment
without halving a character. Take encodings as a client or server option rather than mutating a
module table as `smpp` does, so two sessions in one process cannot disagree about a name. A taken