Outboundtypetype Outbound = { readonly contentType: string; readonly body: string };A document to send.
The transports of exchange (commons integrations 0004-integrations-physical): an ExchangeTransport is a port, a record of functions, and this module gives HTTPS on Net's transport (a POST of a document to a partner's endpoint, with a bearer secret), the token request of OAuth2 backend services in the manner of SMART (a client credentials grant with a signed assertion, the signing a port), and the framing of MLLP over TCP. SFTP, AS2 and AS4 are specified and Planned.
What a partner answers is a payload: it is returned to the caller and never put in a failure, a log or a trace; a failure holds a kind and a status.
Outboundtypetype Outbound = { readonly contentType: string; readonly body: string };A document to send.
Deliveredtypeno test imports ittype Delivered = { readonly status: number; readonly body: string };What a partner gave back: a status and a body, which is a payload.
TransportFailuretypeno test imports ittype TransportFailure = { readonly kind: "refused" } | { readonly kind: "network" } | { readonly kind: "rejected"; readonly status: number };Why nothing was delivered.
type ExchangeTransport = { readonly send: (message: Outbound) => Promise<Result<Delivered, TransportFailure>> };The transport port of exchange.
httpsTransportfunctionfunction httpsTransport(t: Transport, endpoint: string, bearer: Secret): ExchangeTransportHTTPS: a POST of the document to the endpoint, authorized by a bearer secret; a status of 400 or more is rejected, with the status only.
AssertionClaimstypetype AssertionClaims = { readonly iss: string; readonly sub: string; readonly aud: string; readonly jti: string; readonly exp: number };The claims of the assertion that proves the client to a token endpoint.
AssertionSignertypeno test imports ittype AssertionSigner = { readonly sign: (claims: AssertionClaims) => Promise<Result<Secret, { readonly kind: "signing-failed" }>> };The port that signs an assertion with the client's key: the key never leaves it.
TokenFailuretypeno test imports ittype TokenFailure = { readonly kind: "signing-failed" } | { readonly kind: "refused" } | { readonly kind: "network" } | { readonly kind: "rejected"; readonly status: number } | { readonly kind: "malformed" };Why a token was not obtained.
backendServicesFormfunctionfunction backendServicesForm(assertion: Secret, scope: string): stringThe form of a client credentials request that carries a signed assertion (RFC 7523, as SMART Backend Services uses it).
requestTokenfunctionfunction requestToken(t: Transport, tokenUrl: string, signer: AssertionSigner, claims: AssertionClaims, scope: string): Promise<Result<Secret, TokenFailure>>A bearer secret from the token endpoint: it signs an assertion, posts the form and reads access_token of the answer.
MLLPconstno test imports itconst MLLP: { readonly start: "\v"; readonly end: "\u001C"; readonly cr: "\r"; }MLLP start block, end block and carriage return.
mllpFrameconstconst mllpFrame: (message: string) => stringA message in the framing of MLLP.
mllpUnframefunctionfunction mllpUnframe(frame: string): string | undefinedThe message of a frame, or undefined where the text is not one whole frame.