@oneaddress/partner-sdk 1.6.0 → 1.6.2
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 +117 -0
- package/README.md +25 -12
- package/dist/{chunk-CE6M64CX.mjs → chunk-3VG6MTRH.mjs} +12 -1
- package/dist/edge.js +12 -1
- package/dist/edge.mjs +1 -1
- package/dist/index.d.mts +35 -8
- package/dist/index.d.ts +35 -8
- package/dist/index.js +12 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,123 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.6.2] - 2026-08-21
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **The quick start did not compile.** The first code block in the README — the
|
|
15
|
+
one every partner copies — read `event.customer.name`,
|
|
16
|
+
`event.customer.known_names`, and passed `event.customer.account_number` into
|
|
17
|
+
a `(n: string)` parameter. `customer` is `customer?:` on the address events
|
|
18
|
+
(it is absent entirely under blind-index matching) and `account_number` is
|
|
19
|
+
`string | null`, so compiled verbatim under `strict` that block is four
|
|
20
|
+
errors: three `TS18048: 'event.customer' is possibly 'undefined'` and one
|
|
21
|
+
`TS2345: 'string | null' is not assignable to 'string'`.
|
|
22
|
+
|
|
23
|
+
Marlowe wrote JavaScript throughout the engagement and so never met it, which
|
|
24
|
+
is why 126 issues over seven days did not surface the opening example of the
|
|
25
|
+
document being unbuildable for a TypeScript partner.
|
|
26
|
+
|
|
27
|
+
The narrowing is now shown rather than elided, because **both checks are real
|
|
28
|
+
rather than defensive noise** and a reader who deletes them gets the errors
|
|
29
|
+
back. The same fix is applied to the account-verify, D5 and KMS examples.
|
|
30
|
+
|
|
31
|
+
- **The SDK's own doc comments carried the same two mistakes, in the
|
|
32
|
+
higher-traffic copy.** `src/index.ts` is what an editor shows on hover and on
|
|
33
|
+
autocomplete, so a partner meets it without opening the README:
|
|
34
|
+
- `confirmUpdate`'s `@example` passed `dispatchId: event.dispatch_id`, and the
|
|
35
|
+
prose above `ConfirmUpdateOptions.dispatchId` stated in plain English that
|
|
36
|
+
the handler "surfaces it as `event.dispatch_id`". It does not, and never
|
|
37
|
+
did. Fixing the README and leaving this is how one bug gets reported twice.
|
|
38
|
+
- The module-level usage example dereferenced `event.customer` unguarded,
|
|
39
|
+
exactly as the quick start did.
|
|
40
|
+
|
|
41
|
+
- **The module-level usage example told partners to do the thing the README
|
|
42
|
+
spends a paragraph warning against.** It showed
|
|
43
|
+
`app.post('/webhook/oneaddress', express.raw(...), handler)` — passing the
|
|
44
|
+
Fetch-shaped handler straight into Express, which throws `req.text is not a
|
|
45
|
+
function` on the first delivery. It now shows `toExpressHandler(handler)` and
|
|
46
|
+
says why the adapter exists.
|
|
47
|
+
|
|
48
|
+
- **`transformAddress`'s example keyed a datastore on a field that is always
|
|
49
|
+
empty.** It called `db.storeEncryptedAddress(event.customer.email, kmsBlob)`.
|
|
50
|
+
`customer.email` is `''` on every dispatch (OneAddress never learns a
|
|
51
|
+
consumer's email for a dispatch it is not sent for) — a fact stated twelve
|
|
52
|
+
hundred lines above in the same file. Copied as written, that files every
|
|
53
|
+
address under one empty-string row, with no error and no exception: it works,
|
|
54
|
+
and it is wrong. Now keys on `account_number`.
|
|
55
|
+
|
|
56
|
+
`src/readme-event-fields.test.ts` was widened to cover both files and to fail
|
|
57
|
+
on an optional event field dereferenced without narrowing, not just on a field
|
|
58
|
+
that does not exist.
|
|
59
|
+
|
|
60
|
+
- **The README's `confirmUpdate` examples read a field that does not exist.**
|
|
61
|
+
Both passed `dispatchId: event.dispatch_id`. The field is **`event.dispatchId`**.
|
|
62
|
+
`event.dispatch_id` is `undefined`, so `confirmUpdate` refuses to send and
|
|
63
|
+
returns `{ ok: false, error: 'dispatchId must be a positive integer, received
|
|
64
|
+
undefined' }`. It fails safely, and it fails — in the flagship snippet of the
|
|
65
|
+
section written to stop partners hand-rolling the confirm callback.
|
|
66
|
+
|
|
67
|
+
The README used the correct spelling five times elsewhere, so it contradicted
|
|
68
|
+
itself, and the wrong one was in the example most likely to be copied.
|
|
69
|
+
|
|
70
|
+
**Why the mistake is easy to make, which is the part worth knowing:** the
|
|
71
|
+
event object deliberately mixes naming conventions. `partner_id`, `loa_ref`,
|
|
72
|
+
`batch_id` and `user_id` are wire fields passed through as they arrive;
|
|
73
|
+
**`dispatchId` is camelCase because it is derived from the
|
|
74
|
+
`X-OneAddress-Dispatch` HEADER, not from the body.** Nothing on the page said
|
|
75
|
+
so, so both spellings looked equally plausible.
|
|
76
|
+
|
|
77
|
+
Now guarded by `src/readme-event-fields.test.ts`, which parses the field names
|
|
78
|
+
off the four event interfaces and fails if the README reads one that is not
|
|
79
|
+
there. Parsed rather than hand-listed, because a hand-listed set stops
|
|
80
|
+
covering a field the moment one is added.
|
|
81
|
+
|
|
82
|
+
### Notes
|
|
83
|
+
|
|
84
|
+
- No runtime change. `confirmUpdate` was already correct: it coerces a string
|
|
85
|
+
`dispatchId` to a number, validates it is a positive integer, and posts the
|
|
86
|
+
number — `/api/confirm` requires a JSON integer and rejects a numeric string
|
|
87
|
+
with `400 dispatch_id must be a positive integer`. That coercion is exactly
|
|
88
|
+
what a hand-rolled confirm has to remember, and is the reason the helper
|
|
89
|
+
exists.
|
|
90
|
+
|
|
91
|
+
## [1.6.1] - 2026-08-21
|
|
92
|
+
|
|
93
|
+
### Fixed
|
|
94
|
+
|
|
95
|
+
- **The skipped-event warning blamed your SDK version for something only your
|
|
96
|
+
own handler can fix.** Three of the four events this SDK handles are
|
|
97
|
+
conditional on a callback you supply: `address.verify` on `onVerify`,
|
|
98
|
+
`account.verify` on `onAccountVerify`, and `address.test` on `onTest`. Leave
|
|
99
|
+
the callback out and the event falls through to the unhandled branch even
|
|
100
|
+
though the build knows it perfectly well.
|
|
101
|
+
|
|
102
|
+
The single message that branch logged then said the event was *"not handled
|
|
103
|
+
by this build"* while listing that same event under *"this build handles"*,
|
|
104
|
+
and closed by advising `update @oneaddress/partner-sdk` — the one action that
|
|
105
|
+
cannot help, because the SDK is already new enough. An integrator who reads
|
|
106
|
+
it goes looking for a release that does not exist instead of adding four
|
|
107
|
+
lines to their handler.
|
|
108
|
+
|
|
109
|
+
It now names the missing callback, states plainly that upgrading will not fix
|
|
110
|
+
it, and says the sender saw a clean `200` and processed nothing — which is
|
|
111
|
+
why this goes unnoticed at all. The upgrade advice is kept for the case it
|
|
112
|
+
actually fits: an event this build has never heard of.
|
|
113
|
+
|
|
114
|
+
**Upgrading to 1.6.0 does not by itself make a receiver answer
|
|
115
|
+
`address.test`.** The event was added in 1.5.0, but `onTest` is opt-in, so a
|
|
116
|
+
handler that does not pass it still skips connection-verification records and
|
|
117
|
+
still returns five clean `200`s. That is marlowe-reports#125 surviving the
|
|
118
|
+
release that was supposed to end it, and this warning is what makes it
|
|
119
|
+
visible rather than silent.
|
|
120
|
+
|
|
121
|
+
Note also what conformance cannot tell you here: the *"acknowledges unknown
|
|
122
|
+
event type gracefully"* check asserts a clean no-op ack for a genuinely
|
|
123
|
+
unrecognised event. It passed before 1.5.0 and passes now, on a receiver with
|
|
124
|
+
`onTest` wired and on one without. A green conformance run is not evidence
|
|
125
|
+
that `address.test` is handled.
|
|
126
|
+
|
|
10
127
|
## [1.6.0] - 2026-08-20
|
|
11
128
|
|
|
12
129
|
### Added
|
package/README.md
CHANGED
|
@@ -34,8 +34,17 @@ export const handler = createOneAddressHandler({
|
|
|
34
34
|
// event.address is already decrypted. event.customer.email is always ''
|
|
35
35
|
// on this event (OneAddress never learns a consumer's email for a
|
|
36
36
|
// dispatch it isn't sent for) - match on account_number and/or name.
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
//
|
|
38
|
+
// BOTH CHECKS BELOW ARE REAL, not defensive noise. `customer` is absent
|
|
39
|
+
// entirely if you have opted into blind-index matching, and
|
|
40
|
+
// `account_number` is null when the consumer did not supply one. Under
|
|
41
|
+
// `strict` TypeScript neither compiles without narrowing.
|
|
42
|
+
const customer = event.customer;
|
|
43
|
+
if (!customer?.account_number) {
|
|
44
|
+
throw new Error('Dispatch carried no account number to match on');
|
|
45
|
+
}
|
|
46
|
+
const providedNames = [customer.name, ...customer.known_names];
|
|
47
|
+
const record = await db.findByAccountNumber(customer.account_number);
|
|
39
48
|
if (!record || !namePoolMatches(providedNames, record.fullName)) {
|
|
40
49
|
throw new Error('No matching customer for this dispatch');
|
|
41
50
|
}
|
|
@@ -134,7 +143,7 @@ if (!(await verifyD5LOA(loa, loaKey))) throw new Error('LOA signature invalid');
|
|
|
134
143
|
// a valid signed consent. It carries no name in the clear.
|
|
135
144
|
await confirmUpdate({
|
|
136
145
|
partnerId, secret: process.env.OA_CONFIRM_SECRET!,
|
|
137
|
-
dispatchId: event.
|
|
146
|
+
dispatchId: event.dispatchId,
|
|
138
147
|
status: 'confirmed', loaRef: d5LoaRef(loa),
|
|
139
148
|
});
|
|
140
149
|
```
|
|
@@ -258,7 +267,7 @@ import { confirmUpdate } from '@oneaddress/partner-sdk';
|
|
|
258
267
|
const res = await confirmUpdate({
|
|
259
268
|
partnerId: process.env.OA_PARTNER_ID!,
|
|
260
269
|
secret: process.env.OA_CONFIRM_SECRET!, // see "which secret" below
|
|
261
|
-
dispatchId: event.
|
|
270
|
+
dispatchId: event.dispatchId, // from X-OneAddress-Dispatch
|
|
262
271
|
status: 'confirmed',
|
|
263
272
|
note: 'Address updated in CRM',
|
|
264
273
|
});
|
|
@@ -303,7 +312,7 @@ async onUpdate(event) {
|
|
|
303
312
|
if (seen) return; // idempotent no-op
|
|
304
313
|
}
|
|
305
314
|
|
|
306
|
-
await db.updateAddress({ accountNumber: event.customer
|
|
315
|
+
await db.updateAddress({ accountNumber: event.customer?.account_number, ...event.address });
|
|
307
316
|
|
|
308
317
|
if (event.dispatchId) {
|
|
309
318
|
await db.dispatches.insert({ dispatchId: event.dispatchId });
|
|
@@ -345,7 +354,7 @@ export const handler = createOneAddressHandler({
|
|
|
345
354
|
}),
|
|
346
355
|
|
|
347
356
|
async onUpdate(event) {
|
|
348
|
-
await db.updateAddress({ accountNumber: event.customer
|
|
357
|
+
await db.updateAddress({ accountNumber: event.customer?.account_number, ...event.address });
|
|
349
358
|
},
|
|
350
359
|
});
|
|
351
360
|
```
|
|
@@ -538,16 +547,20 @@ export const handler = createOneAddressHandler({
|
|
|
538
547
|
async onUpdate(event) { /* ... */ },
|
|
539
548
|
|
|
540
549
|
async onAccountVerify(event) {
|
|
541
|
-
// event.customer = { email, name, known_names, account_number }
|
|
550
|
+
// event.customer = { email, name, known_names, account_number }, and is
|
|
551
|
+
// OPTIONAL - absent under blind-index matching. Narrow once, then use it.
|
|
552
|
+
const customer = event.customer;
|
|
553
|
+
if (!customer) return { status: 'no_account' };
|
|
554
|
+
|
|
542
555
|
const row = await db.findCustomer({
|
|
543
|
-
accountNumber:
|
|
544
|
-
email:
|
|
556
|
+
accountNumber: customer.account_number,
|
|
557
|
+
email: customer.email,
|
|
545
558
|
});
|
|
546
559
|
|
|
547
560
|
if (!row) return { status: 'no_account' };
|
|
548
561
|
|
|
549
562
|
// Use namePoolMatches, not a naive string comparison - see "Name matching" above.
|
|
550
|
-
const providedNames = [
|
|
563
|
+
const providedNames = [customer.name, ...customer.known_names];
|
|
551
564
|
const nameOk = namePoolMatches(providedNames, row.full_name);
|
|
552
565
|
|
|
553
566
|
return nameOk ? { status: 'match' } : { status: 'no_match' };
|
|
@@ -647,7 +660,7 @@ async onUpdate(event) {
|
|
|
647
660
|
event.partner_id,
|
|
648
661
|
process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
|
|
649
662
|
);
|
|
650
|
-
await db.storeEncryptedAddress(event.customer
|
|
663
|
+
await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
|
|
651
664
|
}
|
|
652
665
|
```
|
|
653
666
|
|
|
@@ -676,7 +689,7 @@ async onUpdate(event) {
|
|
|
676
689
|
);
|
|
677
690
|
// Use event.customer (decrypted by the handler), not body.customer - under
|
|
678
691
|
// D5 the raw webhook body carries no cleartext customer block at all.
|
|
679
|
-
await db.storeEncryptedAddress(event.customer
|
|
692
|
+
await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
|
|
680
693
|
}
|
|
681
694
|
```
|
|
682
695
|
|
|
@@ -831,10 +831,21 @@ function createOneAddressHandler(options) {
|
|
|
831
831
|
});
|
|
832
832
|
}
|
|
833
833
|
const evt = typeof body.event === "string" ? body.event : "(none)";
|
|
834
|
+
const callbackFor = {
|
|
835
|
+
"address.verify": onVerify,
|
|
836
|
+
"account.verify": onAccountVerify,
|
|
837
|
+
"address.test": onTest
|
|
838
|
+
};
|
|
839
|
+
const callbackNameFor = {
|
|
840
|
+
"address.verify": "onVerify",
|
|
841
|
+
"account.verify": "onAccountVerify",
|
|
842
|
+
"address.test": "onTest"
|
|
843
|
+
};
|
|
844
|
+
const unwired = evt in callbackFor && !callbackFor[evt] ? callbackNameFor[evt] : null;
|
|
834
845
|
if (!warnedUnhandledEvents.has(evt)) {
|
|
835
846
|
warnedUnhandledEvents.add(evt);
|
|
836
847
|
console.warn(
|
|
837
|
-
`[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
848
|
+
unwired ? `[OneAddress SDK] Event "${evt}" was SKIPPED because you did not pass a \`${unwired}\` callback to createOneAddressHandler. This build supports "${evt}" - upgrading the SDK will NOT fix it. It was acknowledged with 200 so OneAddress does not retry, which means the sender sees a clean delivery and nothing was processed. Add \`${unwired}\` to your handler options.` : `[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
838
849
|
// NOSONAR
|
|
839
850
|
);
|
|
840
851
|
}
|
package/dist/edge.js
CHANGED
|
@@ -4945,10 +4945,21 @@ function createOneAddressHandler(options) {
|
|
|
4945
4945
|
});
|
|
4946
4946
|
}
|
|
4947
4947
|
const evt = typeof body.event === "string" ? body.event : "(none)";
|
|
4948
|
+
const callbackFor = {
|
|
4949
|
+
"address.verify": onVerify,
|
|
4950
|
+
"account.verify": onAccountVerify,
|
|
4951
|
+
"address.test": onTest
|
|
4952
|
+
};
|
|
4953
|
+
const callbackNameFor = {
|
|
4954
|
+
"address.verify": "onVerify",
|
|
4955
|
+
"account.verify": "onAccountVerify",
|
|
4956
|
+
"address.test": "onTest"
|
|
4957
|
+
};
|
|
4958
|
+
const unwired = evt in callbackFor && !callbackFor[evt] ? callbackNameFor[evt] : null;
|
|
4948
4959
|
if (!warnedUnhandledEvents.has(evt)) {
|
|
4949
4960
|
warnedUnhandledEvents.add(evt);
|
|
4950
4961
|
console.warn(
|
|
4951
|
-
`[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
4962
|
+
unwired ? `[OneAddress SDK] Event "${evt}" was SKIPPED because you did not pass a \`${unwired}\` callback to createOneAddressHandler. This build supports "${evt}" - upgrading the SDK will NOT fix it. It was acknowledged with 200 so OneAddress does not retry, which means the sender sees a clean delivery and nothing was processed. Add \`${unwired}\` to your handler options.` : `[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
4952
4963
|
// NOSONAR
|
|
4953
4964
|
);
|
|
4954
4965
|
}
|
package/dist/edge.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -95,20 +95,40 @@ declare const SUPPORTED_VERSIONS: readonly ["2026.1"];
|
|
|
95
95
|
* Official Node.js SDK for OneAddress partner integrations.
|
|
96
96
|
*
|
|
97
97
|
* Usage:
|
|
98
|
-
* import { createOneAddressHandler } from '@oneaddress/partner-sdk';
|
|
98
|
+
* import { createOneAddressHandler, toExpressHandler } from '@oneaddress/partner-sdk';
|
|
99
99
|
*
|
|
100
100
|
* export const handler = createOneAddressHandler({
|
|
101
101
|
* webhookSecret: process.env.OA_WEBHOOK_SECRET!,
|
|
102
102
|
* privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
103
103
|
* async onUpdate(event) {
|
|
104
|
-
* //
|
|
105
|
-
*
|
|
104
|
+
* // `customer` is ABSENT under blind-index matching and `account_number`
|
|
105
|
+
* // is null when the consumer supplied none, so both checks are real
|
|
106
|
+
* // rather than defensive noise: under `strict` this does not compile
|
|
107
|
+
* // without them. `email` is always '' here - match on account_number
|
|
108
|
+
* // and/or name.
|
|
109
|
+
* const customer = event.customer;
|
|
110
|
+
* if (!customer?.account_number) throw new Error('no account number to match on');
|
|
111
|
+
* const record = await db.findByAccountNumber(customer.account_number);
|
|
112
|
+
* if (!record) throw new Error('no matching customer');
|
|
106
113
|
* await db.updateAddress({ id: record.id, ...event.address });
|
|
107
114
|
* },
|
|
108
115
|
* });
|
|
109
116
|
*
|
|
110
|
-
* //
|
|
111
|
-
* //
|
|
117
|
+
* // Next.js App Router: export { handler as POST };
|
|
118
|
+
* //
|
|
119
|
+
* // Express needs the adapter. The handler is Fetch-shaped (it reads
|
|
120
|
+
* // req.text() and returns a Response), which is what lets one piece of code
|
|
121
|
+
* // run on App Router, Workers, Deno and Bun; Express gives neither, so
|
|
122
|
+
* // passing `handler` in directly throws "req.text is not a function" on
|
|
123
|
+
* // your first delivery. express.raw on this route is also not optional:
|
|
124
|
+
* // the signature is an HMAC over the raw bytes, and express.json() has
|
|
125
|
+
* // already thrown them away.
|
|
126
|
+
* //
|
|
127
|
+
* // app.post(
|
|
128
|
+
* // '/webhook/oneaddress',
|
|
129
|
+
* // express.raw({ type: 'application/json' }),
|
|
130
|
+
* // toExpressHandler(handler),
|
|
131
|
+
* // );
|
|
112
132
|
*/
|
|
113
133
|
|
|
114
134
|
/**
|
|
@@ -814,7 +834,10 @@ declare function decryptSession(share: SessionKeyShare, envelopeB64: string, pri
|
|
|
814
834
|
* event.partner_id,
|
|
815
835
|
* process.env.KMS_PUBLIC_KEY_SPKI_PEM!,
|
|
816
836
|
* );
|
|
817
|
-
*
|
|
837
|
+
* // Key on the account number, NOT on `customer.email`: that field is always
|
|
838
|
+
* // '' on a dispatch, so keying on it files every partner's addresses under
|
|
839
|
+
* // one empty-string row, silently and without an error.
|
|
840
|
+
* await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
|
|
818
841
|
*/
|
|
819
842
|
declare function transformAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
|
|
820
843
|
/**
|
|
@@ -884,7 +907,11 @@ interface ConfirmUpdateOptions {
|
|
|
884
907
|
* From the `X-OneAddress-Dispatch` header on the webhook you are confirming.
|
|
885
908
|
*
|
|
886
909
|
* Not in the body and not in the envelope: capture it when the request
|
|
887
|
-
* arrives. `createOneAddressHandler` surfaces it as `event.
|
|
910
|
+
* arrives. `createOneAddressHandler` surfaces it as `event.dispatchId` -
|
|
911
|
+
* camelCase, unlike the snake_case wire fields beside it, precisely because
|
|
912
|
+
* it is header-derived rather than part of the body. There is no snake_case
|
|
913
|
+
* twin of it on the event; reading one yields `undefined` and this helper
|
|
914
|
+
* then refuses to send.
|
|
888
915
|
*/
|
|
889
916
|
dispatchId: number | string;
|
|
890
917
|
/** Defaults to `'confirmed'`. See {@link OneAddressConfirmStatus}. */
|
|
@@ -941,7 +968,7 @@ interface ConfirmUpdateResult {
|
|
|
941
968
|
* const res = await confirmUpdate({
|
|
942
969
|
* partnerId: process.env.OA_PARTNER_ID!,
|
|
943
970
|
* secret: process.env.OA_CONFIRM_SECRET!,
|
|
944
|
-
* dispatchId: event.
|
|
971
|
+
* dispatchId: event.dispatchId,
|
|
945
972
|
* status: 'confirmed',
|
|
946
973
|
* note: 'Address updated in CRM',
|
|
947
974
|
* });
|
package/dist/index.d.ts
CHANGED
|
@@ -95,20 +95,40 @@ declare const SUPPORTED_VERSIONS: readonly ["2026.1"];
|
|
|
95
95
|
* Official Node.js SDK for OneAddress partner integrations.
|
|
96
96
|
*
|
|
97
97
|
* Usage:
|
|
98
|
-
* import { createOneAddressHandler } from '@oneaddress/partner-sdk';
|
|
98
|
+
* import { createOneAddressHandler, toExpressHandler } from '@oneaddress/partner-sdk';
|
|
99
99
|
*
|
|
100
100
|
* export const handler = createOneAddressHandler({
|
|
101
101
|
* webhookSecret: process.env.OA_WEBHOOK_SECRET!,
|
|
102
102
|
* privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
103
103
|
* async onUpdate(event) {
|
|
104
|
-
* //
|
|
105
|
-
*
|
|
104
|
+
* // `customer` is ABSENT under blind-index matching and `account_number`
|
|
105
|
+
* // is null when the consumer supplied none, so both checks are real
|
|
106
|
+
* // rather than defensive noise: under `strict` this does not compile
|
|
107
|
+
* // without them. `email` is always '' here - match on account_number
|
|
108
|
+
* // and/or name.
|
|
109
|
+
* const customer = event.customer;
|
|
110
|
+
* if (!customer?.account_number) throw new Error('no account number to match on');
|
|
111
|
+
* const record = await db.findByAccountNumber(customer.account_number);
|
|
112
|
+
* if (!record) throw new Error('no matching customer');
|
|
106
113
|
* await db.updateAddress({ id: record.id, ...event.address });
|
|
107
114
|
* },
|
|
108
115
|
* });
|
|
109
116
|
*
|
|
110
|
-
* //
|
|
111
|
-
* //
|
|
117
|
+
* // Next.js App Router: export { handler as POST };
|
|
118
|
+
* //
|
|
119
|
+
* // Express needs the adapter. The handler is Fetch-shaped (it reads
|
|
120
|
+
* // req.text() and returns a Response), which is what lets one piece of code
|
|
121
|
+
* // run on App Router, Workers, Deno and Bun; Express gives neither, so
|
|
122
|
+
* // passing `handler` in directly throws "req.text is not a function" on
|
|
123
|
+
* // your first delivery. express.raw on this route is also not optional:
|
|
124
|
+
* // the signature is an HMAC over the raw bytes, and express.json() has
|
|
125
|
+
* // already thrown them away.
|
|
126
|
+
* //
|
|
127
|
+
* // app.post(
|
|
128
|
+
* // '/webhook/oneaddress',
|
|
129
|
+
* // express.raw({ type: 'application/json' }),
|
|
130
|
+
* // toExpressHandler(handler),
|
|
131
|
+
* // );
|
|
112
132
|
*/
|
|
113
133
|
|
|
114
134
|
/**
|
|
@@ -814,7 +834,10 @@ declare function decryptSession(share: SessionKeyShare, envelopeB64: string, pri
|
|
|
814
834
|
* event.partner_id,
|
|
815
835
|
* process.env.KMS_PUBLIC_KEY_SPKI_PEM!,
|
|
816
836
|
* );
|
|
817
|
-
*
|
|
837
|
+
* // Key on the account number, NOT on `customer.email`: that field is always
|
|
838
|
+
* // '' on a dispatch, so keying on it files every partner's addresses under
|
|
839
|
+
* // one empty-string row, silently and without an error.
|
|
840
|
+
* await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
|
|
818
841
|
*/
|
|
819
842
|
declare function transformAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
|
|
820
843
|
/**
|
|
@@ -884,7 +907,11 @@ interface ConfirmUpdateOptions {
|
|
|
884
907
|
* From the `X-OneAddress-Dispatch` header on the webhook you are confirming.
|
|
885
908
|
*
|
|
886
909
|
* Not in the body and not in the envelope: capture it when the request
|
|
887
|
-
* arrives. `createOneAddressHandler` surfaces it as `event.
|
|
910
|
+
* arrives. `createOneAddressHandler` surfaces it as `event.dispatchId` -
|
|
911
|
+
* camelCase, unlike the snake_case wire fields beside it, precisely because
|
|
912
|
+
* it is header-derived rather than part of the body. There is no snake_case
|
|
913
|
+
* twin of it on the event; reading one yields `undefined` and this helper
|
|
914
|
+
* then refuses to send.
|
|
888
915
|
*/
|
|
889
916
|
dispatchId: number | string;
|
|
890
917
|
/** Defaults to `'confirmed'`. See {@link OneAddressConfirmStatus}. */
|
|
@@ -941,7 +968,7 @@ interface ConfirmUpdateResult {
|
|
|
941
968
|
* const res = await confirmUpdate({
|
|
942
969
|
* partnerId: process.env.OA_PARTNER_ID!,
|
|
943
970
|
* secret: process.env.OA_CONFIRM_SECRET!,
|
|
944
|
-
* dispatchId: event.
|
|
971
|
+
* dispatchId: event.dispatchId,
|
|
945
972
|
* status: 'confirmed',
|
|
946
973
|
* note: 'Address updated in CRM',
|
|
947
974
|
* });
|
package/dist/index.js
CHANGED
|
@@ -5082,10 +5082,21 @@ function createOneAddressHandler(options) {
|
|
|
5082
5082
|
});
|
|
5083
5083
|
}
|
|
5084
5084
|
const evt = typeof body.event === "string" ? body.event : "(none)";
|
|
5085
|
+
const callbackFor = {
|
|
5086
|
+
"address.verify": onVerify,
|
|
5087
|
+
"account.verify": onAccountVerify,
|
|
5088
|
+
"address.test": onTest
|
|
5089
|
+
};
|
|
5090
|
+
const callbackNameFor = {
|
|
5091
|
+
"address.verify": "onVerify",
|
|
5092
|
+
"account.verify": "onAccountVerify",
|
|
5093
|
+
"address.test": "onTest"
|
|
5094
|
+
};
|
|
5095
|
+
const unwired = evt in callbackFor && !callbackFor[evt] ? callbackNameFor[evt] : null;
|
|
5085
5096
|
if (!warnedUnhandledEvents.has(evt)) {
|
|
5086
5097
|
warnedUnhandledEvents.add(evt);
|
|
5087
5098
|
console.warn(
|
|
5088
|
-
`[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
5099
|
+
unwired ? `[OneAddress SDK] Event "${evt}" was SKIPPED because you did not pass a \`${unwired}\` callback to createOneAddressHandler. This build supports "${evt}" - upgrading the SDK will NOT fix it. It was acknowledged with 200 so OneAddress does not retry, which means the sender sees a clean delivery and nothing was processed. Add \`${unwired}\` to your handler options.` : `[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
5089
5100
|
// NOSONAR
|
|
5090
5101
|
);
|
|
5091
5102
|
}
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneaddress/partner-sdk",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Official OneAddress partner integration SDK — webhook verification, address decryption (legacy + D5 session-envelope), LOA validation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|