@oneaddress/partner-sdk 1.7.0 → 2.0.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,6 +7,91 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0] - 2026-09-16
11
+
12
+ A major version because `OneAddressUpdateEvent.address` is now optional (see
13
+ Changed below): a TypeScript integration that dereferences it without
14
+ narrowing stops compiling on upgrade, and that is the intended outcome.
15
+ Runtime behaviour for an integration that declares nothing is unchanged.
16
+
17
+ ### Added
18
+
19
+ - **`acceptedUpdateTypes`: the receiver declares, in code, which kinds of
20
+ changed detail it can handle** (`address`, `phone`, `email`; default
21
+ address-only). The declaration rides every authenticated 2xx acknowledgement
22
+ as `accepted_update_types`, so the conformance run can read it, probe each
23
+ declared kind, probe an undeclared one and require a refusal, and fail the
24
+ run when the partner portal promises a kind the code did not declare. It is
25
+ withheld from a 401, so an unsigned caller learns nothing.
26
+ - **`contact.updated` is handled**, routed to the same `onUpdate` as
27
+ `address.updated`. The relay has sent it for a phone-only or email-only
28
+ dispatch since 14 Aug 2026, and every SDK build before this one acknowledged
29
+ it as an unknown event with `200 { ok: true, skipped: true }`, storing
30
+ nothing. `HANDLED_EVENTS` extended to match.
31
+ - `OneAddressUpdateEvent` gains `update_types` (literal; absent means
32
+ `['address']`), `new_phone` (E.164) and `new_email` (lowercased).
33
+
34
+ ### Changed
35
+
36
+ - **`OneAddressUpdateEvent.address` is now optional.** A contact-only update
37
+ genuinely has none. A TypeScript integration that dereferences
38
+ `event.address` without narrowing stops compiling on upgrade, which is the
39
+ intended outcome: that is exactly the code that would throw on its first
40
+ `contact.updated`. An integration that declares nothing never receives the
41
+ absent case at runtime. Versioning note for whoever cuts the release: this
42
+ is a type-level breaking change.
43
+ - A kind the envelope names that this build does not know is refused with
44
+ `422 invalid_update_types` rather than dropped. A kind the receiver did not
45
+ declare is refused with `422 update_type_not_accepted` before `onUpdate`
46
+ runs, leaving the idempotency claim incomplete so the retry after widening
47
+ the declaration is reprocessed. A declared kind whose value is missing from
48
+ the envelope is a fault (500, retried), not an update with a hole in it.
49
+
50
+ ### Security
51
+
52
+ - **`sendVerifyResult` pins the callback host to `oneaddress.io` and its
53
+ subdomains.** `isSafeWebhookUrl` refused SSRF targets but permitted any
54
+ public host, and `callback_url` arrives on the wire, so a leaked webhook
55
+ secret let a forged `address.verify` make the partner's own server POST the
56
+ callback token, batch id and match result to a host the attacker controls.
57
+ Every generated scaffold already pinned the host; the SDK's own `onVerify`
58
+ path did not, so delegating to the SDK was a silent downgrade. Near-miss
59
+ hostnames are refused. `OA_CALLBACK_HOST_ALLOWLIST` and `allowedCallbackHosts`
60
+ exist for staging and self-hosted relays only.
61
+
62
+ ## [1.8.0] - 2026-08-25
63
+
64
+ ### Added
65
+
66
+ - **Delegated private-key operations for a KMS/HSM-held key
67
+ (`PrivateKeyOperations`).** `createOneAddressHandler`, `decryptSession` and
68
+ `decryptLoaEncrypted` now accept `privateKeyPem: string | PrivateKeyOperations`.
69
+ A key held in a KMS or HSM is never exported as a PEM by design, so passing a
70
+ raw key was impossible for those integrators; a `PrivateKeyOperations`
71
+ delegate performs the private-key step (ECDH-ES derivation / RSA-OAEP unwrap)
72
+ without surrendering the key. Passing a PEM string is unchanged, so this is
73
+ additive — existing code compiles and runs as before.
74
+
75
+ - **`address.test-dispatch` is now handled as a test event.** The admin stress
76
+ test sends `address.test-dispatch` — the same fabricated, encrypted shape as a
77
+ connection-verification `address.test` record, only the label differs. It was
78
+ in no prior SDK version's handled set, so every stress test ack-200-skipped and
79
+ logged as "unhandled" — a warning that read like the partner's bug and was
80
+ ours. It now rides the exact same branch as `address.test`: decrypted and
81
+ handed to `onTest`, **never** `onUpdate` (the identity and address inside are
82
+ fabricated). `OneAddressTestEvent.event` widened to
83
+ `'address.test' | 'address.test-dispatch'` so a handler can count stress
84
+ dispatches separately; `HANDLED_EVENTS` extended to match.
85
+
86
+ ### Fixed
87
+
88
+ - **The unhandled-event warning now names `onTest` for an unwired
89
+ `address.test-dispatch` too.** When `onTest` is not supplied, a
90
+ `address.test-dispatch` event falls through to the unhandled branch. It was
91
+ taking the "this event is unknown — upgrade the SDK" message, which cannot
92
+ help (the build already supports it); it now takes the same "add an `onTest`
93
+ callback" message as `address.test`.
94
+
10
95
  ## [1.7.0] - 2026-08-21
11
96
 
12
97
  ### Added
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.
package/README.md CHANGED
@@ -31,6 +31,11 @@ export const handler = createOneAddressHandler({
31
31
  webhookSecret: process.env.OA_WEBHOOK_SECRET!,
32
32
  privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
33
33
 
34
+ // Which kinds of changed detail THIS CODE can handle. Address only is the
35
+ // default. Declare phone or email only once onUpdate stores them; see
36
+ // "Phone and email updates" below.
37
+ acceptedUpdateTypes: ['address'],
38
+
34
39
  async onUpdate(event) {
35
40
  // event.address is already decrypted. event.customer.email is always ''
36
41
  // on this event (OneAddress never learns a consumer's email for a
@@ -59,11 +64,13 @@ export const handler = createOneAddressHandler({
59
64
  // fictitious, and writing them into real customer records is exactly what a
60
65
  // separate event type exists to prevent.
61
66
  //
62
- // Leave it out and address.test is acknowledged with 200, skipped, and
63
- // logged as skipped. You will not be able to complete connection
67
+ // Handles both address.test (connection verification) and address.test-dispatch
68
+ // (the admin stress test) - same fabricated, encrypted test record, only the
69
+ // event label differs. Leave it out and both are acknowledged with 200,
70
+ // skipped, and logged as skipped; you will not be able to complete connection
64
71
  // verification through the SDK.
65
72
  async onTest(event) {
66
- console.log(`test record ${event.index}/${event.total}`,
73
+ console.log(`test record (${event.event}) ${event.index}/${event.total}`,
67
74
  event.customer.name, event.address);
68
75
  },
69
76
  });
@@ -94,6 +101,75 @@ export { handler as POST };
94
101
 
95
102
  ---
96
103
 
104
+ ## Phone and email updates
105
+
106
+ *Available from 2.0.0.*
107
+
108
+ A OneAddress dispatch can carry a new **postal address**, a new **telephone
109
+ number** or a new **email address**, alone or together. Two things decide what
110
+ you receive:
111
+
112
+ 1. **Consent**, ticked by a person in the partner portal (`accepted_update_types`).
113
+ 2. **Capability**, declared by this code with `acceptedUpdateTypes`.
114
+
115
+ A kind is dispatched to you only where BOTH hold, and the conformance run is
116
+ what ties them together: it reads your declaration off your first
117
+ acknowledgement, sends a real contact-only envelope for every kind you declared,
118
+ sends one kind you did NOT declare and requires you to refuse it, and fails the
119
+ run if the portal promises a kind this code has not declared.
120
+
121
+ ```typescript
122
+ export const handler = createOneAddressHandler({
123
+ webhookSecret: process.env.OA_WEBHOOK_SECRET!,
124
+ privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
125
+ acceptedUpdateTypes: ['address', 'phone', 'email'],
126
+
127
+ async onUpdate(event) {
128
+ const account = event.customer?.account_number;
129
+ if (!account) throw new Error('Dispatch carried no account number to match on');
130
+
131
+ // `update_types` says what is inside; read it rather than probing fields.
132
+ // A phone-only change arrives as ['phone'] with NO address at all.
133
+ if (event.address) await db.updateAddress(account, event.address);
134
+ if (event.new_phone) await db.updatePhone(account, event.new_phone); // E.164
135
+ if (event.new_email) await db.updateEmail(account, event.new_email); // lowercased
136
+ },
137
+ });
138
+ ```
139
+
140
+ What the handler guarantees:
141
+
142
+ | Situation | Response | `onUpdate` |
143
+ |---|---|---|
144
+ | Every kind in the envelope is declared | `200 { ok: true, accepted_update_types }` | runs |
145
+ | A kind you did not declare | `422 update_type_not_accepted` | never runs |
146
+ | A kind name this SDK build does not know | `422 invalid_update_types` | never runs |
147
+ | `contact.updated` without a session envelope | `400 missing_session_envelope` | never runs |
148
+
149
+ - **`address.updated` vs `contact.updated`.** A dispatch carrying an address is
150
+ `address.updated` exactly as before, whether or not a contact detail rides
151
+ beside it. One carrying no address is `contact.updated`. Both reach the same
152
+ `onUpdate`; route on `update_types`, not on the event name.
153
+ - **`event.address` is optional now.** Every dispatch that existed before
154
+ September 2026 has one, and if you declare nothing you will never see the
155
+ absent case, but TypeScript will ask you to narrow: bind it to a local and
156
+ check it, or test it with `if` as the example does.
157
+ - **`update_types` is literal.** `['phone']` means the phone number changed and
158
+ nothing else. It is never widened to include `address`.
159
+ - **Refusal is deliberate.** Acknowledging a kind you cannot store would look
160
+ identical to success on both sides while the consumer has already paid. The
161
+ 422 leaves the dispatch incomplete in your idempotency store, so once you
162
+ widen `acceptedUpdateTypes` OneAddress's retry is processed rather than
163
+ dismissed as a duplicate.
164
+ - **`accepted_update_types` rides every authenticated 2xx.** It is how the
165
+ conformance run discovers what you declared. It is never included in a 401,
166
+ so an unsigned caller learns nothing about your receiver.
167
+ - **Declare a kind only once you store it.** The conformance run can prove your
168
+ code ACCEPTED a phone-only envelope. It cannot see whether your outbox has a
169
+ column for the number.
170
+
171
+ ---
172
+
97
173
  ## D5 — session-envelope decryption (added in v1.3.0)
98
174
 
99
175
  OneAddress is rolling out a new dispatch architecture (D5 + D1 + D2 in the design doc) where each `address.updated` webhook carries:
@@ -626,6 +702,20 @@ await sendVerifyResult({
626
702
  (OneAddress skips the dispatch) and `match: false → 'mismatch' + address_match false`
627
703
  (the update proceeds). It throws if the callback POST returns a non-2xx status.
628
704
 
705
+ ### The callback host is pinned
706
+
707
+ `callback_url` arrives on the wire, so it is only as trustworthy as the webhook
708
+ secret. The SDK has always refused SSRF targets (loopback, private ranges, cloud
709
+ metadata) but would POST to any public host, which meant a leaked secret let an
710
+ attacker forge an `address.verify` and have your server send the callback token,
711
+ batch id and match result wherever they liked. `sendVerifyResult` now posts only
712
+ to `https://oneaddress.io` or a subdomain of it, and near-miss hostnames
713
+ (`notoneaddress.io`, `evil-oneaddress.io`, `oneaddress.io.evil.com`) are
714
+ refused. For a staging or self-hosted relay, name the extra host in
715
+ `OA_CALLBACK_HOST_ALLOWLIST` (comma-separated) or pass `allowedCallbackHosts` to
716
+ `sendVerifyResult` or `createOneAddressHandler`. Every host you add is a host a
717
+ forged request could reach, so keep it empty in production.
718
+
629
719
  ---
630
720
 
631
721
  ## Account verification (pre-payment, guest flow)
@@ -668,7 +758,7 @@ The three statuses surface to the consumer as:
668
758
  | Returned | Consumer sees |
669
759
  |----------|--------------|
670
760
  | `{ status: 'match' }` | ✓ Account found |
671
- | `{ status: 'no_match' }` | ⚠ Couldn't verify — check your account number (editable, retriable) |
761
+ | `{ status: 'no_match' }` | Couldn't verify — check your account number (editable, retriable) |
672
762
  | `{ status: 'no_account' }` | ✗ No account found (editable, retriable) |
673
763
 
674
764
  Any other 2xx response — including the default behaviour when you don't supply `onAccountVerify` at all — surfaces as "—" (skipped). The consumer can still pay and dispatch.
@@ -820,3 +910,13 @@ npx @oneaddress/conformance test http://localhost:3001/webhook
820
910
  ```
821
911
 
822
912
  Or use the **Integration Conformance** card in the Partner Portal to run the same checks against your configured webhook URL from within the portal.
913
+
914
+ ## Licence
915
+
916
+ Apache License 2.0. See [LICENSE](./LICENSE).
917
+
918
+ Apache-2.0 rather than MIT deliberately: it carries an **express patent grant**,
919
+ bounded to this package. OneAddress holds a pending patent application over the
920
+ address-change notification architecture, and this SDK is the recipient half of
921
+ it. Partners using it is the entire point, so an explicit, bounded grant is
922
+ clearer for you than MIT's silence on patents.