@oneaddress/partner-sdk 1.8.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,13 +7,202 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.1.0] - 2026-09-20
11
+
12
+ Unpublished as at this entry, and **still unpublished on 25 Sep 2026**, when the
13
+ dispatch-simulator correction below was folded into it rather than given a
14
+ version of its own — a version number is cheap until published and permanent
15
+ after, so work accumulates into the unpublished one.
16
+
17
+ A minor version: every change is additive or tightens a check that was
18
+ documented as already present. Two audits of the SDK on 20 Sep 2026 (one
19
+ security, one partner-usability) produced the original list; a
20
+ dashboard-to-receiver wiring audit on 25 Sep 2026 produced the addition.
21
+
22
+ ### Fixed (25 Sep 2026)
23
+
24
+ - **`buildSignedTestWebhook` sent a payload OneAddress does not send.** The
25
+ helper exists so you can unit-test your handler against "what the relay
26
+ sends", and measured against the relay's own composer it did not: it added
27
+ `version` and `encryption_status` — fields of the superseded
28
+ `address_encrypted` shape that never appear beside a `session_envelope` — it
29
+ always sent the body `id`, which the relay sends only on a key-crossover
30
+ copy, it sent `update_id` as a UUID where the relay sends the integer
31
+ `user_updates.id`, and it omitted `user_id` and `stripe_session_id`
32
+ altogether.
33
+
34
+ **This could make a correct-looking handler fail in production.** A handler
35
+ gated on `encryption_status === 'encrypted'`, pinned to `body.version`, or
36
+ keyed for idempotency on `body.id` went green against this helper and would
37
+ then have dropped — or double-written — every real update. **If your tests
38
+ assert on any of those three fields, they will now fail, and that failure is
39
+ the bug surfacing: production never carried them.** Deduplicate on the
40
+ `X-OneAddress-Dispatch` header, which is on every delivery.
41
+
42
+ The body's `timestamp` is ISO 8601; the `X-OneAddress-Timestamp` *header* is
43
+ Unix-epoch seconds. Both formats are in every dispatch, which is how two
44
+ separate conformance implementations came to put the header's format in the
45
+ body.
46
+
47
+ The field list now comes from an explicit contract that is verified by
48
+ EXECUTING the relay's own composer, so the helper cannot drift from the wire
49
+ again without a test failing.
50
+
51
+ ### Added (25 Sep 2026)
52
+
53
+ - `buildSignedTestWebhook` takes **`userId`** (default `test:consumer`) and
54
+ **`stripeSessionId`** (default `null` — the key is always present on the wire
55
+ even when the value is not). `id` and `crossover_key_ids` remain reachable
56
+ through `extraBody`, which is the circumstance the relay actually sends them
57
+ in. The helper also binds `update_id` to the envelope's `update_uid` as the
58
+ relay does, so a handler can bind a decrypted LOA to the update it arrived
59
+ with.
60
+
61
+ ### Security
62
+
63
+ - **The Letter of Authority must be PRESENT, not merely valid when present.**
64
+ With `loaPublicKeyPem` set, a dispatch that carried no `loa_encrypted` was
65
+ processed with no check at all: "verified" meant "verified if the relay
66
+ chose to include it". Such a dispatch is now refused with a 500, so
67
+ OneAddress retries and records the failure rather than being told a
68
+ delivery succeeded whose consent proof nobody saw. New option `requireLoa`
69
+ (default `true` when `loaPublicKeyPem` is set, `false` otherwise); set it
70
+ `false` to keep processing without a proof, in which case the handler warns
71
+ once per process that consent is unverified.
72
+ - **The LOA is bound to its envelope.** A decrypted LOA whose `update_uid`
73
+ differs from the session envelope's is refused, so a genuine consent for one
74
+ update cannot be replayed beside the envelope of another. Older dispatches
75
+ lacking the field on either side are unaffected.
76
+ - **`fetchLoaPublicKey` requires `https:`** except for `localhost` and
77
+ `127.0.0.1`. The key it fetches is what every consent signature is checked
78
+ against, and `http://oneaddress.io` passed the host allowlist.
79
+ - **`createOutboxConsumer`: `markProcessed`, `markFailed` and `release` now
80
+ match on the claim token this consumer holds as well as `dispatch_id`,** so
81
+ a write that lands after the lease expired and another consumer re-claimed
82
+ the row touches nothing. `maxAttempts` is validated (integer, zero or more)
83
+ before it is inlined into the statement, like `batchSize` already was.
84
+ - **Configuration is refused at construction, by name**: an empty
85
+ `webhookSecret`, a `privateKeyPem` that does not import, a
86
+ `timestampToleranceSecs` outside `(0, 86400]`, an unparseable
87
+ `webhookSecretGraceUntil`. Each used to surface on the first real delivery
88
+ as a 500 that OneAddress then retried for two days.
89
+ - A correctly signed body that is valid JSON but not an object (`null`, a
90
+ number, an array) is answered `400 Invalid JSON` instead of throwing out
91
+ of the handler.
92
+
93
+ ### Added
94
+
95
+ - **`confirm` option on `createOneAddressHandler`** (`{ partnerId,
96
+ confirmSecret, oneAddressApi? }`). When set, the handler calls
97
+ `confirmUpdate` after `onUpdate` returns, with the `status` it returned
98
+ (`confirmed` when omitted) and `event.loa_ref`. Fire-and-forget: a failed
99
+ confirm is logged and never fails the delivery. Exists because `onUpdate`'s
100
+ return value was only ever spread into the 200 body and reached nobody;
101
+ its docstring and the README said otherwise and are corrected.
102
+ - **`buildSignedTestWebhook`**: a correctly signed, correctly encrypted test
103
+ dispatch for your own unit tests, in the exact shape the relay sends,
104
+ lifted from the conformance suite. Optional real LOA signing with a key you
105
+ generate, so `loaPublicKeyPem` can be tested end to end. `HandlerRequest`
106
+ and `HandlerResponse` are exported alongside it.
107
+ - **`createSqlIdempotencyStore` takes `dialect`** (`postgres` | `sqlite` |
108
+ `mysql` | `mssql`). The claim statement was Postgres/SQLite-only
109
+ (`ON CONFLICT ... DO NOTHING RETURNING`) while the README said MySQL and
110
+ SQL Server "just change the placeholder". MySQL and SQL Server now get an
111
+ insert-if-absent under a per-call token; their table needs one extra
112
+ column, `claim_token VARCHAR(64) NULL`. An unknown dialect is refused with
113
+ the supported list.
114
+ - **`expectedAlg` option on `createOneAddressHandler`**, passed through to
115
+ `decryptSession` (and `decryptLoaEncrypted`, which gains the same optional
116
+ parameter) so the algorithm-downgrade pin is reachable from the handler.
117
+ - **A private key stored as one line with literal `\n` sequences is accepted**
118
+ everywhere a PEM is, which is what a secrets manager hands back when the key
119
+ was pasted as a single line.
120
+ - Outside test mode, a dispatch carrying `X-OneAddress-Dispatch` with no
121
+ `idempotencyStore` wired is processed and logged once per process, naming
122
+ `createSqlIdempotencyStore`. The test-mode throw is unchanged. The
123
+ `process.env` read is guarded for the edge build.
124
+
125
+ ### Changed
126
+
127
+ - **`privateKeyPem` on the handler accepts `string | PrivateKeyOperations`,
128
+ and so does `transformSession`.** The 1.8.0 entry below said the handler
129
+ already did; it did not, and `transformSession` was PEM-only. A delegate
130
+ covers the session-envelope paths; the legacy single-blob paths
131
+ (`address_encrypted`, `customer_encrypted`) still need the raw key and say
132
+ so by name.
133
+ - Documentation: `onUpdate`'s return value is stated NOT to reach OneAddress on
134
+ its own; the README's quick start returns `no_match` for an unknown customer
135
+ instead of throwing; all four confirm statuses are listed; a "Delivery
136
+ contract" section states our 10-second timeout, 28 attempts over 48 hours,
137
+ the `ok:false`-in-a-2xx rule and what each response status means to us; an
138
+ identifier table tells `event.id`, `dispatchId`, `update_uid`, `batch_id`
139
+ and `verification_id` apart; the `/edge` section lists what that entry
140
+ actually exports and says Cloudflare Workers need `nodejs_compat`; a
141
+ "Never do" list; `formatAddressParts` and `confirmUpdate`'s `note` no
142
+ longer suggest putting the address in a log or a note; `BYPASS_STRIPE` is
143
+ gone from partner-facing text in favour of "sandbox dispatches".
144
+
145
+ ## [2.0.0] - 2026-09-16
146
+
147
+ A major version because `OneAddressUpdateEvent.address` is now optional (see
148
+ Changed below): a TypeScript integration that dereferences it without
149
+ narrowing stops compiling on upgrade, and that is the intended outcome.
150
+ Runtime behaviour for an integration that declares nothing is unchanged.
151
+
152
+ ### Added
153
+
154
+ - **`acceptedUpdateTypes`: the receiver declares, in code, which kinds of
155
+ changed detail it can handle** (`address`, `phone`, `email`; default
156
+ address-only). The declaration rides every authenticated 2xx acknowledgement
157
+ as `accepted_update_types`, so the conformance run can read it, probe each
158
+ declared kind, probe an undeclared one and require a refusal, and fail the
159
+ run when the partner portal promises a kind the code did not declare. It is
160
+ withheld from a 401, so an unsigned caller learns nothing.
161
+ - **`contact.updated` is handled**, routed to the same `onUpdate` as
162
+ `address.updated`. The relay has sent it for a phone-only or email-only
163
+ dispatch since 14 Aug 2026, and every SDK build before this one acknowledged
164
+ it as an unknown event with `200 { ok: true, skipped: true }`, storing
165
+ nothing. `HANDLED_EVENTS` extended to match.
166
+ - `OneAddressUpdateEvent` gains `update_types` (literal; absent means
167
+ `['address']`), `new_phone` (E.164) and `new_email` (lowercased).
168
+
169
+ ### Changed
170
+
171
+ - **`OneAddressUpdateEvent.address` is now optional.** A contact-only update
172
+ genuinely has none. A TypeScript integration that dereferences
173
+ `event.address` without narrowing stops compiling on upgrade, which is the
174
+ intended outcome: that is exactly the code that would throw on its first
175
+ `contact.updated`. An integration that declares nothing never receives the
176
+ absent case at runtime. Versioning note for whoever cuts the release: this
177
+ is a type-level breaking change.
178
+ - A kind the envelope names that this build does not know is refused with
179
+ `422 invalid_update_types` rather than dropped. A kind the receiver did not
180
+ declare is refused with `422 update_type_not_accepted` before `onUpdate`
181
+ runs, leaving the idempotency claim incomplete so the retry after widening
182
+ the declaration is reprocessed. A declared kind whose value is missing from
183
+ the envelope is a fault (500, retried), not an update with a hole in it.
184
+
185
+ ### Security
186
+
187
+ - **`sendVerifyResult` pins the callback host to `oneaddress.io` and its
188
+ subdomains.** `isSafeWebhookUrl` refused SSRF targets but permitted any
189
+ public host, and `callback_url` arrives on the wire, so a leaked webhook
190
+ secret let a forged `address.verify` make the partner's own server POST the
191
+ callback token, batch id and match result to a host the attacker controls.
192
+ Every generated scaffold already pinned the host; the SDK's own `onVerify`
193
+ path did not, so delegating to the SDK was a silent downgrade. Near-miss
194
+ hostnames are refused. `OA_CALLBACK_HOST_ALLOWLIST` and `allowedCallbackHosts`
195
+ exist for staging and self-hosted relays only.
196
+
10
197
  ## [1.8.0] - 2026-08-25
11
198
 
12
199
  ### Added
13
200
 
14
201
  - **Delegated private-key operations for a KMS/HSM-held key
15
- (`PrivateKeyOperations`).** `createOneAddressHandler`, `decryptSession` and
16
- `decryptLoaEncrypted` now accept `privateKeyPem: string | PrivateKeyOperations`.
202
+ (`PrivateKeyOperations`).** `decryptSession` and `decryptLoaEncrypted` now
203
+ accept `privateKeyPem: string | PrivateKeyOperations`. (Correction, 2.1.0:
204
+ this entry originally also named `createOneAddressHandler`, whose option
205
+ stayed `string` until 2.1.0 widened it.)
17
206
  A key held in a KMS or HSM is never exported as a PEM by design, so passing a
18
207
  raw key was impossible for those integrators; a `PrivateKeyOperations`
19
208
  delegate performs the private-key step (ECDH-ES derivation / RSA-OAEP unwrap)
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 OneAddress Pty Ltd
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.