@oneaddress/partner-sdk 1.3.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,218 @@ All notable changes to `@oneaddress/partner-sdk` are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [1.6.1] - 2026-08-21
11
+
12
+ ### Fixed
13
+
14
+ - **The skipped-event warning blamed your SDK version for something only your
15
+ own handler can fix.** Three of the four events this SDK handles are
16
+ conditional on a callback you supply: `address.verify` on `onVerify`,
17
+ `account.verify` on `onAccountVerify`, and `address.test` on `onTest`. Leave
18
+ the callback out and the event falls through to the unhandled branch even
19
+ though the build knows it perfectly well.
20
+
21
+ The single message that branch logged then said the event was *"not handled
22
+ by this build"* while listing that same event under *"this build handles"*,
23
+ and closed by advising `update @oneaddress/partner-sdk` — the one action that
24
+ cannot help, because the SDK is already new enough. An integrator who reads
25
+ it goes looking for a release that does not exist instead of adding four
26
+ lines to their handler.
27
+
28
+ It now names the missing callback, states plainly that upgrading will not fix
29
+ it, and says the sender saw a clean `200` and processed nothing — which is
30
+ why this goes unnoticed at all. The upgrade advice is kept for the case it
31
+ actually fits: an event this build has never heard of.
32
+
33
+ **Upgrading to 1.6.0 does not by itself make a receiver answer
34
+ `address.test`.** The event was added in 1.5.0, but `onTest` is opt-in, so a
35
+ handler that does not pass it still skips connection-verification records and
36
+ still returns five clean `200`s. That is marlowe-reports#125 surviving the
37
+ release that was supposed to end it, and this warning is what makes it
38
+ visible rather than silent.
39
+
40
+ Note also what conformance cannot tell you here: the *"acknowledges unknown
41
+ event type gracefully"* check asserts a clean no-op ack for a genuinely
42
+ unrecognised event. It passed before 1.5.0 and passes now, on a receiver with
43
+ `onTest` wired and on one without. A green conformance run is not evidence
44
+ that `address.test` is handled.
45
+
46
+ ## [1.6.0] - 2026-08-20
47
+
48
+ ### Added
49
+
50
+ - **`confirmUpdate` — the reply half of the protocol, which the SDK did not have.**
51
+ Everything here helped a partner RECEIVE a dispatch and nothing at all helped
52
+ them answer one, and answering is not optional: until the callback lands, the
53
+ consumer's dashboard shows that business stuck on "dispatched" indefinitely,
54
+ however correctly the change was applied.
55
+
56
+ What partners were left to derive from a README example whose auth step was
57
+ the comment `/* …auth… */`: a Bearer token, a fresh unix-**seconds**
58
+ timestamp, and an HMAC-SHA256 over `` `${timestamp}.${rawBody}` ``. The three
59
+ ways that goes wrong all surface as the same unhelpful `401` —
60
+
61
+ 1. signing a JSON string and then handing `fetch` an object, which
62
+ re-serialises it (a byte of whitespace or a different key order is enough);
63
+ 2. milliseconds instead of seconds, which is outside the ±300s replay window
64
+ by a factor of a thousand and reports "stale or future request", reading
65
+ as an auth failure rather than a units one;
66
+ 3. clock drift on the partner's host, which reports the same thing.
67
+
68
+ `confirmUpdate` serialises once and sends exactly the bytes it signed, stamps
69
+ seconds, and **returns `{ ok, status, error }` rather than throwing** — a
70
+ confirm that fails has to be something the caller can see, because partners
71
+ wrap this in fire-and-forget `.catch()` and an exception there is
72
+ indistinguishable from success. That is the shape of marlowe-reports#125 in
73
+ the other direction: the update looks applied on the partner's side and the
74
+ consumer never sees it land.
75
+
76
+ It also refuses a missing or non-numeric `dispatchId` **before** sending.
77
+ `createOneAddressHandler` surfaces `''` when the `X-OneAddress-Dispatch`
78
+ header was absent, and `/api/confirm` treats an absent `dispatch_id` as a
79
+ no-op for the dispatch record — so coercing it and posting would return `200`
80
+ having closed no loop, which is the worst outcome available.
81
+
82
+ ### Changed
83
+
84
+ - The README's LOA example no longer hides the hard part behind
85
+ `/* …auth… */`, and there is a **Confirming back** section covering the three
86
+ statuses, which secret to use, and why the result must be logged.
87
+
88
+ ## [1.5.0]
89
+
90
+ ### Added
91
+
92
+ - **`toExpressHandler` — the Express adapter the README always implied existed.**
93
+ `createOneAddressHandler` returns a **Fetch-shaped** function: it calls
94
+ `req.text()` and `req.headers.get()` and returns a `Response`. That contract is
95
+ deliberate and is not changing — it is what lets one handler run unchanged on
96
+ Next.js App Router, Cloudflare Workers, Deno and Bun. Express provides none of
97
+ it, and the README's Express line implied `express.raw` was the only
98
+ adjustment needed:
99
+
100
+ ```js
101
+ // app.post('/webhook/oneaddress', express.raw(...), handler); // crashes
102
+ ```
103
+
104
+ Passing the handler straight in throws `TypeError: req.text is not a function`
105
+ on the **first delivery**. Reported by an external integrator who followed that
106
+ line exactly (marlowe-reports#123).
107
+
108
+ ```js
109
+ import { createOneAddressHandler, toExpressHandler } from '@oneaddress/partner-sdk';
110
+
111
+ app.post(
112
+ '/webhook/oneaddress',
113
+ express.raw({ type: 'application/json' }), // required — see below
114
+ toExpressHandler(handler),
115
+ );
116
+ ```
117
+
118
+ Structurally typed against Express's request/response shape, so the SDK gains
119
+ no dependency on Express and the adapter also covers Connect and the several
120
+ frameworks that copy the API.
121
+
122
+ - **The raw-body requirement is now enforced by name rather than assumed**, and
123
+ this is worth more than the adapter itself. The webhook signature is an HMAC
124
+ over the **raw request bytes**. If `express.json()` has already parsed the
125
+ body, those bytes are gone, and re-serialising the object does not reproduce
126
+ them — a different key order or a single space of whitespace is enough. The
127
+ symptom is a `401 Invalid signature` that is **indistinguishable from a wrong
128
+ signing secret**, which is a long afternoon for whoever is debugging it.
129
+
130
+ `toExpressHandler` refuses a parsed or missing body with a 500 and a log line
131
+ naming the cause and the middleware to add, before it can become a mystery
132
+ signature failure.
133
+
134
+ ### Notes
135
+
136
+ - No breaking changes. Existing Fetch-style call sites (App Router, Workers,
137
+ Deno, Bun) are untouched — `toExpressHandler` is purely additive and opt-in.
138
+
139
+ ## [1.4.0]
140
+
141
+ ### Added
142
+
143
+ - **`createSqlIdempotencyStore` + atomic `claim`/`complete` on `idempotencyStore`.**
144
+ The existing `has`/`set` pair cannot be made correct under concurrency - they
145
+ are two round-trips, so two retries arriving together both observe "not seen"
146
+ and both apply the update. `claim` is a single atomic
147
+ `INSERT ... ON CONFLICT DO NOTHING`. It also distinguishes three states rather
148
+ than two, and the third is the one that matters: a dispatch whose previous
149
+ attempt never reported completion returns `retry-after-incomplete` and is
150
+ **re-processed**, where a two-state store has to guess - and guessing
151
+ "duplicate" loses a paid address update permanently the first time a process
152
+ dies mid-write, with both sides reporting success.
153
+ `createSqlIdempotencyStore` implements this over any SQL database via a
154
+ caller-supplied `query` function, so the SDK stays dependency-free.
155
+ `has`/`set` remain supported and are used when `claim` is absent.
156
+
157
+ - **`readAddressParts` / `formatAddressParts` - tolerant address field reader.**
158
+ Extracts `line1` / `suburb` / `state` / `postcode` / `country` from a decrypted
159
+ payload regardless of which field-name spelling it uses (`street`,
160
+ `address_line1`, `city`, `locality`, `postalCode`, `zip`, and friends), with
161
+ `country` defaulting to `AU`. Every OneAddress reference receiver had
162
+ hand-rolled the same `a.line1 ?? a.address_line1 ?? a.street ?? …` ladder, so a
163
+ fix to one copy silently left the others behind - this is now one
164
+ implementation with its own tests. It is a *tolerant reader*, not a schema
165
+ declaration: it describes what the helper accepts and says nothing about what
166
+ OneAddress guarantees to send.
167
+
168
+ - **`namePoolMatches` / `findMatchingStoredName` - canonical name matching.**
169
+ Re-exported from `@oneaddress/name-match`, the same component-aware matcher
170
+ OneAddress's own reference receivers run. Match a decrypted `verified_name` /
171
+ `known_names` pool against your stored record without writing your own
172
+ comparison - a naive substring/prefix approach treats an email address as
173
+ just another name token, which is a real false-positive-match vector we
174
+ found and closed in our own systems. See the README's "Name matching"
175
+ section.
176
+
177
+ ### Fixed
178
+
179
+ - **Published `.d.ts` no longer references unresolved workspace-only modules.**
180
+ A deep-dive audit found that the built `dist/index.d.ts` left
181
+ `@oneaddress/crypto`, `@oneaddress/name-match`, and `@oneaddress/protocol`
182
+ as unresolved external re-exports - private workspace packages, never
183
+ published to npm. Every TypeScript partner installing this package got
184
+ `TS2307: Cannot find module` on exactly the functions the README instructs
185
+ them to import (`namePoolMatches`, `isFreshTimestamp`, `computeBlindIndex`,
186
+ ...). Fixed via a dedicated `tsconfig.build.json` (Bundler resolution +
187
+ explicit `paths`) and `tsup --dts-resolve`, so the dts bundler now inlines
188
+ these types the same way esbuild already inlined the runtime code. Verified
189
+ by simulating a real external `npm install` (no workspace) and typechecking
190
+ against it - confirmed clean. Guarded going forward by
191
+ `src/dist-exports.test.ts`, which rebuilds `dist/` and asserts no
192
+ unresolved `@oneaddress/*` re-export ever reappears (no prior test touched
193
+ the built artifact at all - only the source).
194
+ - **Quick-start example no longer uses the field it warns readers away from.**
195
+ `event.customer.email` is always `''` on `address.updated` (documented one
196
+ section later in the same README) - the flagship quick-start, idempotency,
197
+ and both `transform*` examples all used it anyway, so a partner following
198
+ them verbatim would write an empty string to their database and log
199
+ `"Address updated for :"` on every real dispatch. All four now match on
200
+ `account_number` instead. The `account.verify` example's own name
201
+ comparison has also been swapped from a naive case-insensitive string
202
+ match to `namePoolMatches` - the exact anti-pattern the "Name matching"
203
+ section above warns against, previously present in the very next example.
204
+ - **`edge.ts` now re-exports everything the README claims it does.**
205
+ `namePoolMatches`, `findMatchingStoredName`, `isEmailLike`,
206
+ `compareAddresses`, and `sendVerifyResult` (plus their types) were missing
207
+ from the `/edge` entry point despite none of them using anything
208
+ Node-specific.
209
+ - **Doc corrections, no behaviour change:** `loaPublicKeyPem` and
210
+ `customer_match` doc comments now state precisely which event types they
211
+ actually apply to (`loaPublicKeyPem` only enforces on `address.updated`;
212
+ `customer_match` is only ever populated on `address.verify` - it's a dead,
213
+ always-`undefined` field on `address.updated` and `account.verify`,
214
+ previously documented as if universally present). The stale "legacy
215
+ decryptAddress removed in v1.3.x" claim has been corrected - no removal is
216
+ currently scheduled. `package.json`'s `exports` map condition order fixed
217
+ (`types` must be listed before `import`/`require`, previously reversed and
218
+ silently ignored by resolvers that respect ordering).
219
+
8
220
  ## [1.3.0]
9
221
 
10
222
  The D5 "no cleartext" dispatch release. Dispatches no longer carry a cleartext
@@ -27,12 +239,15 @@ signed consent are all recovered by decrypting per-partner encrypted material.
27
239
  `@oneaddress/partner-sdk/edge` so Cloudflare Workers / Next.js Edge partners
28
240
  can verify the LOA standalone, without the full `createOneAddressHandler`
29
241
  factory.
30
- - **Blind-index matching (`customer_match`).** For partners who opt into
31
- blind-index matching, dispatches carry a `customer_match` block instead of a
32
- cleartext `customer`. New `computeBlindIndex` / `normalizeForBlindIndex`
33
- helpers compute the salted indexes (email, name, account number) under your
34
- portal-issued blind-index secret. Exactly one of `customer` / `customer_match`
35
- is present on any given dispatch.
242
+ - **Blind-index matching (`customer_match`).** Shipped earlier in the D5
243
+ migration, before the "no cleartext" mandate above superseded it as the
244
+ default: for partners who opted into blind-index matching, dispatches
245
+ carried a `customer_match` block instead of a cleartext `customer`. New
246
+ `computeBlindIndex` / `normalizeForBlindIndex` helpers compute the salted
247
+ indexes (email, name, account number) under your portal-issued blind-index
248
+ secret. See the README's "Blind-index matching" section for current status
249
+ (superseded for `address.updated`, but the helpers remain exported for
250
+ partners doing their own internal matching).
36
251
  - **Additional key-wrap schemes for `session_key_share`.** Alongside the default
37
252
  ECDH-ES (P-256) wrap, `decryptSession` now supports:
38
253
  - `RSA-OAEP-256+A256GCM` — for partners whose KMS/HSM key is RSA.