@didit-protocol/sdk-node 2.13.0 → 2.13.1

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/dist/index.d.cts CHANGED
@@ -23764,7 +23764,7 @@ declare class TokenVerificationError extends DiditError {
23764
23764
  constructor(reason: TokenVerificationReason, message: string);
23765
23765
  }
23766
23766
 
23767
- declare const VERSION = "2.13.0";
23767
+ declare const VERSION = "2.13.1";
23768
23768
 
23769
23769
  /**
23770
23770
  * The canonical JSON of a parsed webhook body: the text `X-Signature-V2` signs
package/dist/index.d.ts CHANGED
@@ -23764,7 +23764,7 @@ declare class TokenVerificationError extends DiditError {
23764
23764
  constructor(reason: TokenVerificationReason, message: string);
23765
23765
  }
23766
23766
 
23767
- declare const VERSION = "2.13.0";
23767
+ declare const VERSION = "2.13.1";
23768
23768
 
23769
23769
  /**
23770
23770
  * The canonical JSON of a parsed webhook body: the text `X-Signature-V2` signs
package/dist/index.js CHANGED
@@ -188,6 +188,52 @@ function makeStatusError(status, body, headers, secrets = []) {
188
188
  const ErrorClass = STATUS_ERRORS[status] ?? (status >= 500 ? InternalServerError : APIStatusError);
189
189
  return new ErrorClass(message, status, cleanBody, redactHeaders(headers, secrets));
190
190
  }
191
+ var REDACTED = "[redacted]";
192
+ function redactStructured(value, secrets) {
193
+ const active = secrets.filter((s) => s.length > 0);
194
+ const text = (input) => active.some((secret) => input.includes(secret)) ? REDACTED : input;
195
+ const scrub = (input) => {
196
+ if (typeof input === "string") return text(input);
197
+ if (Array.isArray(input)) return input.map(scrub);
198
+ if (isRecord(input)) {
199
+ const out = /* @__PURE__ */ new Map();
200
+ const taken = new Set(Object.keys(input).filter((key) => text(key) === key));
201
+ let next = 1;
202
+ for (const [key, item] of Object.entries(input)) {
203
+ let name = key;
204
+ if (text(key) !== key) {
205
+ do {
206
+ name = next === 1 ? REDACTED : `${REDACTED}${next}`;
207
+ next++;
208
+ } while (taken.has(name));
209
+ taken.add(name);
210
+ }
211
+ out.set(name, scrub(item));
212
+ }
213
+ return Object.fromEntries(out);
214
+ }
215
+ return input;
216
+ };
217
+ return scrub(value);
218
+ }
219
+ function sanitizeResponse(headers, text, secrets) {
220
+ const clean = new Headers();
221
+ headers.forEach((value, name) => {
222
+ const folded = name.toLowerCase();
223
+ if (!secrets.some((secret) => secret && folded.includes(secret.toLowerCase()))) {
224
+ clean.append(name, redactStructured(value, secrets));
225
+ }
226
+ });
227
+ let body = REDACTED;
228
+ if (text) {
229
+ try {
230
+ body = JSON.stringify(redactStructured(JSON.parse(text), secrets));
231
+ } catch {
232
+ body = REDACTED;
233
+ }
234
+ }
235
+ return { headers: clean, text: body };
236
+ }
191
237
 
192
238
  // src/core/api-promise.ts
193
239
  var APIPromise = class extends Promise {
@@ -278,7 +324,7 @@ function decodeDates(value, plan, named, depth = 0) {
278
324
  }
279
325
 
280
326
  // src/core/version.ts
281
- var VERSION = "2.13.0";
327
+ var VERSION = "2.13.1";
282
328
 
283
329
  // src/core/runtime.ts
284
330
  function processLike() {
@@ -11171,11 +11217,15 @@ async function send(transport, request) {
11171
11217
  log(null, null, "timeout");
11172
11218
  return new APITimeoutError(
11173
11219
  `The issuer did not answer ${method} ${path} within ${transport.timeout} ms.`,
11174
- { cause }
11220
+ // A request that carries secrets keeps no cause: a transport may quote the serialized body in it.
11221
+ request.structuredRedaction ? void 0 : { cause }
11175
11222
  );
11176
11223
  }
11177
11224
  log(null, null, "connection_error");
11178
- return new APIConnectionError(`Could not reach the issuer for ${method} ${path}.`, { cause });
11225
+ return new APIConnectionError(
11226
+ `Could not reach the issuer for ${method} ${path}.`,
11227
+ request.structuredRedaction ? void 0 : { cause }
11228
+ );
11179
11229
  };
11180
11230
  let status;
11181
11231
  let responseHeaders;
@@ -11203,19 +11253,28 @@ async function send(transport, request) {
11203
11253
  } finally {
11204
11254
  clearTimeout(timer);
11205
11255
  }
11206
- log(status, responseHeaders);
11256
+ const secrets = request.secrets ?? [];
11257
+ const sanitized = request.structuredRedaction ? sanitizeResponse(responseHeaders, text, secrets) : null;
11258
+ const errorHeaders = sanitized?.headers ?? responseHeaders;
11259
+ log(status, errorHeaders);
11207
11260
  if (status < 200 || status > 299) {
11208
- throw makeStatusError(status, bodyOf(text), responseHeaders, request.secrets ?? []);
11261
+ throw makeStatusError(
11262
+ status,
11263
+ bodyOf(sanitized?.text ?? text),
11264
+ errorHeaders,
11265
+ sanitized ? [] : secrets
11266
+ );
11209
11267
  }
11210
- if (status === 204 || !text) return { status, headers: responseHeaders, data: null };
11268
+ if (status === 204 || !text)
11269
+ return { status, headers: responseHeaders, errorHeaders, data: null };
11211
11270
  try {
11212
- return { status, headers: responseHeaders, data: JSON.parse(text) };
11271
+ return { status, headers: responseHeaders, errorHeaders, data: JSON.parse(text) };
11213
11272
  } catch {
11214
- const type = responseHeaders.get("content-type") ?? "no content type";
11273
+ const type = errorHeaders.get("content-type") ?? "no content type";
11215
11274
  throw new APIResponseValidationError(
11216
11275
  `Expected a JSON response from ${method} ${path}, got ${type}.`,
11217
11276
  status,
11218
- responseHeaders
11277
+ errorHeaders
11219
11278
  );
11220
11279
  }
11221
11280
  }
@@ -11320,10 +11379,16 @@ function textList(value, name) {
11320
11379
  }
11321
11380
  return [...value];
11322
11381
  }
11382
+ var MIN_SECRET_LENGTH = 16;
11323
11383
  function assertionSecrets(value) {
11324
- if (typeof value === "string") return value.length > 0 ? [value] : [];
11384
+ if (typeof value === "string") return value.length >= MIN_SECRET_LENGTH ? [value] : [];
11325
11385
  if (Array.isArray(value)) return value.flatMap(assertionSecrets);
11326
- if (isRecord4(value)) return Object.values(value).flatMap(assertionSecrets);
11386
+ if (isRecord4(value)) {
11387
+ return Object.entries(value).flatMap(([key, item]) => [
11388
+ ...assertionSecrets(key),
11389
+ ...assertionSecrets(item)
11390
+ ]);
11391
+ }
11327
11392
  return [];
11328
11393
  }
11329
11394
  function optionalText(value, name) {
@@ -11603,7 +11668,6 @@ var Authentication = class _Authentication {
11603
11668
  if (assertion !== void 0 && assertion !== null) {
11604
11669
  if (!isRecord4(assertion)) throw new TypeError("assertion must be an object.");
11605
11670
  body.assertion = assertion;
11606
- secrets.push(...assertionSecrets(assertion));
11607
11671
  }
11608
11672
  const scopes = given.scopes;
11609
11673
  if (scopes !== void 0 && scopes !== null) body.scopes = textList(scopes, "scopes");
@@ -11618,7 +11682,19 @@ var Authentication = class _Authentication {
11618
11682
  }
11619
11683
  body.lifetime = lifetime;
11620
11684
  }
11621
- const call = { ...this.#bearerCall("POST", AGENT_CONSENT_PATH, token), json: body, secrets };
11685
+ let sent;
11686
+ try {
11687
+ sent = JSON.parse(JSON.stringify(body));
11688
+ } catch {
11689
+ throw new TypeError("Could not encode the agent consent request.");
11690
+ }
11691
+ secrets.push(...assertionSecrets(sent.assertion));
11692
+ const call = {
11693
+ ...this.#bearerCall("POST", AGENT_CONSENT_PATH, token),
11694
+ json: sent,
11695
+ secrets,
11696
+ structuredRedaction: true
11697
+ };
11622
11698
  return await this.#object(call);
11623
11699
  }
11624
11700
  /**
@@ -11634,7 +11710,8 @@ var Authentication = class _Authentication {
11634
11710
  const call = {
11635
11711
  ...this.#bearerCall("POST", AGENT_CONSENT_PASSKEY_PATH, token),
11636
11712
  json: { challenge },
11637
- secrets: [token, challenge]
11713
+ secrets: [token, challenge],
11714
+ structuredRedaction: true
11638
11715
  };
11639
11716
  return await this.#object(call);
11640
11717
  }
@@ -11654,7 +11731,7 @@ var Authentication = class _Authentication {
11654
11731
  throw new APIResponseValidationError(
11655
11732
  `Expected a JSON object from ${call.method} ${pathOf(call.url)}.`,
11656
11733
  response.status,
11657
- response.headers
11734
+ response.errorHeaders
11658
11735
  );
11659
11736
  }
11660
11737
  return response.data;