@oneaddress/conformance 2.0.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.
Files changed (3) hide show
  1. package/README.md +35 -0
  2. package/dist/index.js +138 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -19,6 +19,40 @@ Runs a suite of end-to-end checks against a partner's webhook endpoint, covering
19
19
 
20
20
  Checks 9 and 10 are skipped unless `--customer-url` is provided.
21
21
 
22
+ ### Update kinds: what your receiver's code says it can take
23
+
24
+ A dispatch can carry a new address, a new phone number or a new email address.
25
+ Since 14 Aug 2026 the run has probed each contact kind you pass with `--accept`
26
+ (`check-contact-phone`, `check-contact-email`), sending a real contact-only
27
+ envelope announced as `contact.updated` and failing a receiver that
28
+ acknowledges it with `skipped: true`, which is a 200 with the value dropped.
29
+
30
+ A receiver on the current `@oneaddress/partner-sdk` also DECLARES, on every
31
+ authenticated acknowledgement, which kinds its code handles
32
+ (`accepted_update_types`, from the handler's `acceptedUpdateTypes` option).
33
+ The run reads that off `check-1` and adds:
34
+
35
+ - `check-kinds-declared`: the declaration is present and well-formed. A
36
+ receiver that makes none is not failed, but the run says so, because its
37
+ accept-set is then tested on trust.
38
+ - `check-kinds-consent-declared`: every kind in `--accept` (what a person
39
+ ticked in the partner portal) is also declared by the code. FAILS otherwise:
40
+ that is a dispatch that will be refused after the consumer has paid.
41
+ - `check-kinds-refuses-undeclared`: one kind the receiver did NOT declare is
42
+ sent and must be refused with a 4xx. This is the check that matters most: it
43
+ is the difference between a receiver that stores only what it promised and
44
+ one that acknowledges anything. Skipped for a receiver that made no
45
+ declaration, since check 7 requires such a receiver to acknowledge events it
46
+ does not recognise.
47
+
48
+ Contact kinds are probed only where `--accept` and the declaration agree, so a
49
+ kind the portal accepts but the code did not declare is reported once, by the
50
+ comparison, rather than probed into a second red row.
51
+
52
+ The partner portal's own conformance button runs the same checks with the same
53
+ ids and pass rules, reading the accept-set from your portal record instead of a
54
+ flag. A pass in one and a fail in the other is a bug in ours, not in yours.
55
+
22
56
  ## Installation
23
57
 
24
58
  ```bash
@@ -54,6 +88,7 @@ oneaddress-conformance test https://api.mycompany.com/oneaddress \
54
88
  | `--partner-id` | Built-in test UUID | Your partner UUID |
55
89
  | `--public-key` | Built-in test ECDH SPKI | Your ECDH P-256 public key, base64 SPKI |
56
90
  | `--customer-url` | — | Customer-app base URL; when set, adds pull-API checks |
91
+ | `--accept` | `address` | Comma-separated update kinds you accept in the partner portal (`address,phone,email`). Adds one contact probe per kind and is compared against what your receiver declares. Match it to the portal: the portal governs what OneAddress sends, this governs what gets tested. |
57
92
 
58
93
  ## Exit codes
59
94
 
package/dist/index.js CHANGED
@@ -3245,6 +3245,55 @@ async function encryptEnvelopeForPartner(payload, partner) {
3245
3245
  // ../protocol/src/types.ts
3246
3246
  var CURRENT_VERSION = "2026.1";
3247
3247
 
3248
+ // ../protocol/src/update-kinds.ts
3249
+ var UPDATE_KINDS = ["address", "phone", "email"];
3250
+ var CONTACT_KINDS = ["phone", "email"];
3251
+ function isUpdateKind(value) {
3252
+ return typeof value === "string" && UPDATE_KINDS.includes(value);
3253
+ }
3254
+ function normaliseUpdateKinds(raw) {
3255
+ const kept = new Set(
3256
+ (Array.isArray(raw) ? raw : []).filter((v) => typeof v === "string")
3257
+ );
3258
+ return UPDATE_KINDS.filter((k) => k === "address" || kept.has(k));
3259
+ }
3260
+ function readAcceptedUpdateKindsFromAck(body) {
3261
+ const none = (malformed = false) => ({
3262
+ declared: false,
3263
+ kinds: ["address"],
3264
+ malformed,
3265
+ ignored: []
3266
+ });
3267
+ let parsed = body;
3268
+ if (typeof body === "string") {
3269
+ try {
3270
+ parsed = JSON.parse(body);
3271
+ } catch {
3272
+ return none();
3273
+ }
3274
+ }
3275
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return none();
3276
+ const raw = parsed.accepted_update_types;
3277
+ if (raw === void 0 || raw === null) return none();
3278
+ if (!Array.isArray(raw)) return none(true);
3279
+ const ignored = [...new Set(
3280
+ raw.filter((v) => !isUpdateKind(v)).map((v) => typeof v === "string" ? v : JSON.stringify(v))
3281
+ )];
3282
+ return { declared: true, kinds: normaliseUpdateKinds(raw), malformed: false, ignored };
3283
+ }
3284
+ var UNDEFINED_PROBE_KIND = "conformance_undeclared_kind";
3285
+ function kindProbePlan(declaration, acceptedInPortal) {
3286
+ const accepted = normaliseUpdateKinds(acceptedInPortal).filter((k) => k !== "address");
3287
+ if (!declaration.declared) {
3288
+ return { accept: accepted, refuse: null, consentBeyondDeclaration: [] };
3289
+ }
3290
+ const declaredContact = declaration.kinds.filter((k) => k !== "address");
3291
+ const accept = accepted.filter((k) => declaredContact.includes(k));
3292
+ const consentBeyondDeclaration = accepted.filter((k) => !declaredContact.includes(k));
3293
+ const undeclared = CONTACT_KINDS.find((k) => !declaration.kinds.includes(k));
3294
+ return { accept, refuse: undeclared ?? UNDEFINED_PROBE_KIND, consentBeyondDeclaration };
3295
+ }
3296
+
3248
3297
  // src/credentials.ts
3249
3298
  var TEST_WEBHOOK_SECRET = (
3250
3299
  // NOSONAR — intentional test credential, not a real secret
@@ -3333,6 +3382,33 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3333
3382
  session_key_share: loaEnvelope.session_key_share
3334
3383
  },
3335
3384
  encryption_status: "encrypted",
3385
+ /**
3386
+ * THIS DISPATCH IS A DRILL, AND IT SAYS SO IN THE SIGNED BODY.
3387
+ *
3388
+ * Check 11 sends a payload the receiver CANNOT open, deliberately, and
3389
+ * passes the receiver for refusing it. A receiver that quarantines held
3390
+ * dispatches therefore ends a SUCCESSFUL conformance run with a red fault
3391
+ * panel, a `failed` counter that never returns to zero, and a `decrypt_failed`
3392
+ * line naming the partner's real `key_id`. Reported from a real run: the
3393
+ * dashboard said the receiver was broken at the moment it proved it was not.
3394
+ *
3395
+ * WHY THE BODY AND NOT THE DISPATCH-ID HEADER. `X-OneAddress-Dispatch`
3396
+ * carries a recognisable prefix already (`undecryptable-…`) and keying off it
3397
+ * would be wrong: the HMAC covers `${timestamp}.${rawBody}` and NOTHING ELSE,
3398
+ * so every header except the timestamp is outside the signature and anything
3399
+ * on the path can change it without invalidating anything. A marker that
3400
+ * changes how an operator's fault panel behaves has to be inside the signed
3401
+ * material. This field is.
3402
+ *
3403
+ * PRECEDENT: `crossover_key_ids` (check 15) is already a signed-body field
3404
+ * that tells a receiver how to treat a payload it cannot decrypt. Same shape,
3405
+ * different cause.
3406
+ *
3407
+ * Sent on EVERY conformance body, not only the undecryptable one, because a
3408
+ * receiver has a legitimate interest in knowing which of its stored records
3409
+ * came from a drill rather than from a consumer.
3410
+ */
3411
+ conformance: true,
3336
3412
  ...extraFields
3337
3413
  });
3338
3414
  }
@@ -3348,9 +3424,10 @@ async function post(url, body, headers, timeoutMs = 12e3) {
3348
3424
  signal: controller.signal,
3349
3425
  redirect: "error"
3350
3426
  });
3351
- return { status: res.status, durationMs: Date.now() - start };
3427
+ const text = await res.text().catch(() => "");
3428
+ return { status: res.status, durationMs: Date.now() - start, body: text };
3352
3429
  } catch (err) {
3353
- return { status: 0, durationMs: Date.now() - start, error: String(err) };
3430
+ return { status: 0, durationMs: Date.now() - start, body: "", error: String(err) };
3354
3431
  } finally {
3355
3432
  clearTimeout(timer);
3356
3433
  }
@@ -3399,11 +3476,15 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3399
3476
  }
3400
3477
  const results = [];
3401
3478
  const sharedBody = await buildBody(partnerId, publicKeyB64);
3479
+ let declaration = readAcceptedUpdateKindsFromAck(null);
3480
+ let check1Accepted;
3402
3481
  {
3403
3482
  const ts = String(Math.floor(Date.now() / 1e3));
3404
3483
  const sig = sign(sharedBody, ts, secret);
3405
- const { status, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "1"));
3484
+ const { status, error, body: ackBody } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "1"));
3406
3485
  const passed = !error && status >= 200 && status < 300;
3486
+ check1Accepted = passed;
3487
+ if (passed) declaration = readAcceptedUpdateKindsFromAck(ackBody);
3407
3488
  results.push({
3408
3489
  id: "check-1",
3409
3490
  basis: "acceptance",
@@ -3598,7 +3679,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3598
3679
  basis: "rejection",
3599
3680
  label: "Reports undecryptable payload as a failure (not 200 ok:true)",
3600
3681
  passed,
3601
- detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${bodyFailure ? " with ok:false" : ""} \u2014 correctly reported as a failed delivery` : `HTTP ${status} without ok:false \u2014 a payload this receiver CANNOT decrypt was reported as delivered. OneAddress will mark it delivered and never retry it. Return a 4xx/5xx, or 200 with { ok: false }, when decryption fails.`
3682
+ detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${bodyFailure ? " with ok:false" : ""} \u2014 correctly reported as a failed delivery. This probe is now held by your receiver, which is how the check was passed: it is one undecryptable dispatch, not a fault in your setup. Clear it with [d] on the dashboard.` : `HTTP ${status} without ok:false \u2014 a payload this receiver CANNOT decrypt was reported as delivered. OneAddress will mark it delivered and never retry it. Return a 4xx/5xx, or 200 with { ok: false }, when decryption fails.`
3602
3683
  });
3603
3684
  }
3604
3685
  if (verifiesAccountReference) {
@@ -3631,11 +3712,19 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3631
3712
  basis: "rejection",
3632
3713
  label: "Refuses an account reference that matches no record (no name fallback)",
3633
3714
  passed,
3634
- detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Report it as a failure so the consumer is told, which is what they were promised before they paid.`
3715
+ detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Answer the webhook with ok:false so the consumer is told, which is what they were promised before they paid, and confirm the dispatch as "no_match" rather than "failed": "failed" means YOUR system broke and makes the update refundable at your expense, while "no_match" says the person is simply not on your books. This check reads the webhook response only, so it cannot see which status you send; getting it wrong costs you money rather than failing here.`
3635
3716
  });
3636
3717
  }
3718
+ const plan = kindProbePlan(declaration, acceptedUpdateTypes);
3719
+ results.push({
3720
+ id: "check-kinds-declared",
3721
+ basis: "declaration",
3722
+ label: "Declares the update kinds its code accepts (accepted_update_types on the ack)",
3723
+ passed: check1Accepted && !declaration.malformed,
3724
+ detail: !check1Accepted ? "No acknowledgement to read: check-1 did not pass." : declaration.malformed ? "accepted_update_types was present but not an array. That is a broken receiver, not an older one: the field must be a list of kinds (address, phone, email)." : !declaration.declared ? "No declaration on the acknowledgement. This receiver predates capability declarations, so the kinds accepted in the partner portal are tested on trust and cannot be refused by the receiver when undeclared. Upgrade @oneaddress/partner-sdk and set acceptedUpdateTypes." : `Declares: ${declaration.kinds.join(", ")}` + (declaration.ignored.length > 0 ? `. Also named ${declaration.ignored.join(", ")}, which this tool does not define and did not record (newer SDK than conformance tool?).` : ".")
3725
+ });
3637
3726
  {
3638
- const contactKinds = ["phone", "email"].filter((k) => acceptedUpdateTypes.includes(k));
3727
+ const contactKinds = plan.accept;
3639
3728
  for (const kind of contactKinds) {
3640
3729
  const article = kind === "email" ? "an" : "a";
3641
3730
  const body = await buildBody(partnerId, publicKeyB64, void 0, kind);
@@ -3671,16 +3760,52 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3671
3760
  parsed = JSON.parse(bodyText);
3672
3761
  } catch {
3673
3762
  }
3674
- const passed = res !== null && status >= 200 && status < 300 && parsed.ok !== false && parsed.skipped !== true;
3763
+ const refusedForItsAccount = verifiesAccountReference && parsed.ok === false && parsed.error === "account_not_matched";
3764
+ const passed = res !== null && status >= 200 && status < 300 && (parsed.ok !== false || refusedForItsAccount) && parsed.skipped !== true;
3675
3765
  results.push({
3676
3766
  id: `check-contact-${kind}`,
3677
3767
  basis: "acceptance",
3678
3768
  label: `Accepts ${article} ${kind}-only update (no address in the envelope)`,
3679
3769
  passed,
3680
- detail: res === null ? "Network error: no response" : passed ? `HTTP ${status} \u2014 accepted. NOTE: this proves the envelope was accepted, not that the ${kind} was stored. Confirm your outbox has a column for it.` : parsed.skipped === true ? `HTTP ${status} with skipped:true \u2014 this receiver ACKNOWLEDGED the update and stored nothing. It is treating '${"contact.updated"}' as an unknown event, which means it predates contact updates. Upgrade it, or narrow your accept-set in the partner portal until you have. A 200 here would otherwise look identical to a delivery.` : `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 this receiver did not accept ${article} ${kind}-only update, but your OneAddress accept-set says you take them. A contact update carries NO new_address: code that reads it unguarded will throw. Either handle the absent address, or narrow your accept-set in the partner portal.`
3770
+ detail: res === null ? "Network error: no response" : passed && refusedForItsAccount ? `HTTP ${status} with ok:false (account_not_matched) \u2014 handled. This probe's account is not one of yours, and you check the account reference, so refusing it is correct. It shows the envelope with no address was read and not thrown on; it does not show the ${kind} is stored.` : passed ? `HTTP ${status} \u2014 accepted. NOTE: this proves the envelope was accepted, not that the ${kind} was stored. Confirm your outbox has a column for it.` : parsed.skipped === true ? `HTTP ${status} with skipped:true \u2014 this receiver ACKNOWLEDGED the update and stored nothing. It is treating '${"contact.updated"}' as an unknown event, which means it predates contact updates. Upgrade it, or narrow your accept-set in the partner portal until you have. A 200 here would otherwise look identical to a delivery.` : `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 this receiver did not accept ${article} ${kind}-only update, but your OneAddress accept-set says you take them. A contact update carries NO new_address: code that reads it unguarded will throw. Either handle the absent address, or narrow your accept-set in the partner portal.`
3681
3771
  });
3682
3772
  }
3683
3773
  }
3774
+ results.push({
3775
+ id: "check-kinds-consent-declared",
3776
+ basis: "declaration",
3777
+ label: "Every kind accepted in the partner portal is declared by the receiver",
3778
+ passed: plan.consentBeyondDeclaration.length === 0,
3779
+ detail: !declaration.declared ? "Nothing to compare: the receiver made no declaration (see check-kinds-declared)." : plan.consentBeyondDeclaration.length === 0 ? `Portal accepts ${["address", ...plan.accept].join(", ")}; the receiver declares ${declaration.kinds.join(", ")}.` : `The portal accepts ${plan.consentBeyondDeclaration.join(" and ")} but the receiver's code declares only ${declaration.kinds.join(", ")}. A dispatch of that kind would be refused (422) and retried until it gave up, after the consumer had paid. Narrow the accept-set in the partner portal, or widen acceptedUpdateTypes once onUpdate stores the value.`
3780
+ });
3781
+ if (plan.refuse !== null) {
3782
+ const probe = plan.refuse;
3783
+ const body = await buildBody(partnerId, publicKeyB64, void 0, probe);
3784
+ const ts = String(Math.floor(Date.now() / 1e3));
3785
+ const sig = sign(body, ts, secret);
3786
+ const res = await fetch(targetUrl, {
3787
+ method: "POST",
3788
+ headers: buildHeaders(
3789
+ partnerId,
3790
+ ts,
3791
+ sig,
3792
+ `refuse-${probe}-${import_node_crypto.default.randomUUID().slice(0, 8)}`,
3793
+ "contact.updated"
3794
+ ),
3795
+ body,
3796
+ signal: AbortSignal.timeout(12e3)
3797
+ }).catch(() => null);
3798
+ const status = res?.status ?? 0;
3799
+ if (res) await res.text().catch(() => "");
3800
+ const passed = res !== null && status >= 400 && status < 500;
3801
+ results.push({
3802
+ id: "check-kinds-refuses-undeclared",
3803
+ basis: "rejection",
3804
+ label: `Refuses an update kind it did not declare (${probe})`,
3805
+ passed,
3806
+ detail: res === null ? "Network error: no response" : passed ? `HTTP ${status}, a dispatch carrying an undeclared kind was refused, so nothing it did not promise to handle can be acknowledged and dropped.` : `HTTP ${status}, this receiver ACKNOWLEDGED a dispatch carrying a kind (${probe}) it never declared. That is the silent-loss shape: the consumer is told the update was delivered and the value went nowhere. Refuse it with a 4xx (the SDK answers 422 update_type_not_accepted) so OneAddress retries once you have widened acceptedUpdateTypes.`
3807
+ });
3808
+ }
3684
3809
  if (supportsKeyCrossover) {
3685
3810
  const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
3686
3811
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
@@ -3792,10 +3917,10 @@ function markUnprovenChecks(results) {
3792
3917
  }
3793
3918
 
3794
3919
  // src/report.ts
3795
- var PASS = "\u2705";
3796
- var FAIL = "\u274C";
3797
- var UNPROVEN = "\u2754";
3798
- var ICON_COLUMNS = 2;
3920
+ var PASS = "\u2713";
3921
+ var FAIL = "\u2717";
3922
+ var UNPROVEN = "?";
3923
+ var ICON_COLUMNS = 1;
3799
3924
  function verdictOf(r) {
3800
3925
  if (r.unproven) return { icon: UNPROVEN, status: "UNPROVEN" };
3801
3926
  return r.passed ? { icon: PASS, status: "PASSED" } : { icon: FAIL, status: "FAILED" };
@@ -3991,7 +4116,7 @@ async function main() {
3991
4116
  process.exit(1);
3992
4117
  }
3993
4118
  if (parsedTarget.protocol === "http:" && isLocalhost) {
3994
- console.warn("\n \u26A0 HTTP detected \u2014 acceptable for local testing only.\n");
4119
+ console.warn("\n ! HTTP detected \u2014 acceptable for local testing only.\n");
3995
4120
  }
3996
4121
  console.log(`
3997
4122
  Running conformance checks against: ${targetUrl}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaddress/conformance",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Conformance test tool for OneAddress partner integrations",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {