@oneaddress/partner-sdk 1.6.1 → 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 CHANGED
@@ -7,6 +7,87 @@ 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
+
10
91
  ## [1.6.1] - 2026-08-21
11
92
 
12
93
  ### Fixed
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
- const providedNames = [event.customer.name, ...event.customer.known_names];
38
- const record = await db.findByAccountNumber(event.customer.account_number);
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.dispatch_id,
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.dispatch_id, // from X-OneAddress-Dispatch
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.account_number, ...event.address });
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.account_number, ...event.address });
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: event.customer.account_number,
544
- email: event.customer.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 = [event.customer.name, ...event.customer.known_names];
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.account_number, kmsBlob);
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.account_number, kmsBlob);
692
+ await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
680
693
  }
681
694
  ```
682
695
 
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
- * // event.customer.email is always '' here - match on account_number / name.
105
- * const record = await db.findByAccountNumber(event.customer.account_number);
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
- * // Express: app.post('/webhook/oneaddress', express.raw({ type: 'application/json' }), handler);
111
- * // Next.js: export { handler as POST };
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
- * await db.storeEncryptedAddress(event.customer.email, kmsBlob);
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.dispatch_id`.
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.dispatch_id,
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
- * // event.customer.email is always '' here - match on account_number / name.
105
- * const record = await db.findByAccountNumber(event.customer.account_number);
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
- * // Express: app.post('/webhook/oneaddress', express.raw({ type: 'application/json' }), handler);
111
- * // Next.js: export { handler as POST };
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
- * await db.storeEncryptedAddress(event.customer.email, kmsBlob);
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.dispatch_id`.
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.dispatch_id,
971
+ * dispatchId: event.dispatchId,
945
972
  * status: 'confirmed',
946
973
  * note: 'Address updated in CRM',
947
974
  * });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaddress/partner-sdk",
3
- "version": "1.6.1",
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",