@adcp/sdk 14.0.0 → 14.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.
- package/dist/lib/adapters/implicit-account-store.d.mts +12 -7
- package/dist/lib/adapters/implicit-account-store.d.ts +12 -7
- package/dist/lib/adapters/implicit-account-store.js +69 -15
- package/dist/lib/adapters/implicit-account-store.mjs +69 -15
- package/dist/lib/core/AgentClient.d.mts +1 -0
- package/dist/lib/core/AgentClient.d.ts +1 -0
- package/dist/lib/core/AgentClient.js +3 -0
- package/dist/lib/core/AgentClient.mjs +3 -0
- package/dist/lib/core/SingleAgentClient.d.mts +31 -1
- package/dist/lib/core/SingleAgentClient.d.ts +31 -1
- package/dist/lib/core/SingleAgentClient.js +355 -35
- package/dist/lib/core/SingleAgentClient.mjs +365 -37
- package/dist/lib/core/TaskExecutor.js +2 -1
- package/dist/lib/core/TaskExecutor.mjs +2 -1
- package/dist/lib/core/account-key.d.mts +3 -0
- package/dist/lib/core/account-key.d.ts +3 -0
- package/dist/lib/core/account-key.js +41 -0
- package/dist/lib/core/account-key.mjs +17 -0
- package/dist/lib/core/account-resolution.d.mts +2 -0
- package/dist/lib/core/account-resolution.d.ts +2 -0
- package/dist/lib/core/buyer-account-registry.d.mts +65 -0
- package/dist/lib/core/buyer-account-registry.d.ts +65 -0
- package/dist/lib/core/buyer-account-registry.js +518 -0
- package/dist/lib/core/buyer-account-registry.mjs +494 -0
- package/dist/lib/core/product-cache.d.mts +18 -0
- package/dist/lib/core/product-cache.d.ts +18 -0
- package/dist/lib/core/product-cache.js +137 -0
- package/dist/lib/core/product-cache.mjs +112 -0
- package/dist/lib/errors/index.d.mts +40 -1
- package/dist/lib/errors/index.d.ts +40 -1
- package/dist/lib/errors/index.js +69 -3
- package/dist/lib/errors/index.mjs +64 -3
- package/dist/lib/governance/authorization.d.mts +17 -1
- package/dist/lib/governance/authorization.d.ts +17 -1
- package/dist/lib/governance/authorization.js +55 -7
- package/dist/lib/governance/authorization.mjs +59 -7
- package/dist/lib/governance/index.d.mts +2 -2
- package/dist/lib/governance/index.d.ts +2 -2
- package/dist/lib/governance/index.js +2 -0
- package/dist/lib/governance/index.mjs +3 -1
- package/dist/lib/index.d.mts +5 -3
- package/dist/lib/index.d.ts +5 -3
- package/dist/lib/index.js +20 -0
- package/dist/lib/index.mjs +19 -0
- package/dist/lib/protocols/a2a.js +9 -1
- package/dist/lib/protocols/a2a.mjs +9 -1
- package/dist/lib/protocols/index.js +9 -2
- package/dist/lib/protocols/index.mjs +9 -2
- package/dist/lib/protocols/mcp-modern.js +2 -1
- package/dist/lib/protocols/mcp-modern.mjs +2 -1
- package/dist/lib/protocols/mcp.js +5 -2
- package/dist/lib/protocols/mcp.mjs +5 -2
- package/dist/lib/protocols/rawResponseCapture.d.mts +6 -0
- package/dist/lib/protocols/rawResponseCapture.d.ts +6 -0
- package/dist/lib/protocols/rawResponseCapture.js +41 -29
- package/dist/lib/protocols/rawResponseCapture.mjs +40 -29
- package/dist/lib/protocols/signedRequestRejection.d.mts +9 -0
- package/dist/lib/protocols/signedRequestRejection.d.ts +9 -0
- package/dist/lib/protocols/signedRequestRejection.js +209 -0
- package/dist/lib/protocols/signedRequestRejection.mjs +189 -0
- package/dist/lib/protocols/transportDiagnostics.d.mts +1 -0
- package/dist/lib/protocols/transportDiagnostics.d.ts +1 -0
- package/dist/lib/protocols/transportDiagnostics.js +2 -0
- package/dist/lib/protocols/transportDiagnostics.mjs +1 -0
- package/dist/lib/registry/types.generated.d.mts +112 -45
- package/dist/lib/registry/types.generated.d.ts +112 -45
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/server/account-provisioning.d.mts +2 -0
- package/dist/lib/server/account-provisioning.d.ts +2 -0
- package/dist/lib/server/account-provisioning.js +30 -0
- package/dist/lib/server/account-provisioning.mjs +6 -0
- package/dist/lib/server/account-reference-warnings.d.mts +12 -0
- package/dist/lib/server/account-reference-warnings.d.ts +12 -0
- package/dist/lib/server/account-reference-warnings.js +48 -0
- package/dist/lib/server/account-reference-warnings.mjs +23 -0
- package/dist/lib/server/auth-signature.js +1 -0
- package/dist/lib/server/auth-signature.mjs +1 -0
- package/dist/lib/server/create-adcp-server.d.mts +34 -0
- package/dist/lib/server/create-adcp-server.d.ts +34 -0
- package/dist/lib/server/create-adcp-server.js +225 -14
- package/dist/lib/server/create-adcp-server.mjs +225 -14
- package/dist/lib/server/decisioning/account.d.mts +2 -0
- package/dist/lib/server/decisioning/account.d.ts +2 -0
- package/dist/lib/server/decisioning/runtime/from-platform.js +49 -10
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +49 -10
- package/dist/lib/server/index.d.mts +2 -2
- package/dist/lib/server/index.d.ts +2 -2
- package/dist/lib/server/index.js +2 -0
- package/dist/lib/server/index.mjs +3 -1
- package/dist/lib/signing/agent-resolver/consistency.d.mts +6 -13
- package/dist/lib/signing/agent-resolver/consistency.d.ts +6 -13
- package/dist/lib/signing/agent-resolver/consistency.js +0 -1
- package/dist/lib/signing/agent-resolver/consistency.mjs +0 -1
- package/dist/lib/signing/agent-resolver/errors.d.mts +1 -1
- package/dist/lib/signing/agent-resolver/errors.d.ts +1 -1
- package/dist/lib/signing/agent-resolver/fetch-helpers.d.mts +2 -0
- package/dist/lib/signing/agent-resolver/fetch-helpers.d.ts +2 -0
- package/dist/lib/signing/agent-resolver/fetch-helpers.js +2 -1
- package/dist/lib/signing/agent-resolver/fetch-helpers.mjs +2 -1
- package/dist/lib/signing/agent-resolver/jwks-set.js +24 -3
- package/dist/lib/signing/agent-resolver/jwks-set.mjs +24 -3
- package/dist/lib/signing/agent-resolver/legacy-brand.d.mts +15 -0
- package/dist/lib/signing/agent-resolver/legacy-brand.d.ts +15 -0
- package/dist/lib/signing/agent-resolver/legacy-brand.js +60 -0
- package/dist/lib/signing/agent-resolver/legacy-brand.mjs +36 -0
- package/dist/lib/signing/agent-resolver/operator-authorization.d.mts +13 -0
- package/dist/lib/signing/agent-resolver/operator-authorization.d.ts +13 -0
- package/dist/lib/signing/agent-resolver/operator-authorization.js +108 -0
- package/dist/lib/signing/agent-resolver/operator-authorization.mjs +84 -0
- package/dist/lib/signing/agent-resolver/resolve-agent.d.mts +14 -4
- package/dist/lib/signing/agent-resolver/resolve-agent.d.ts +14 -4
- package/dist/lib/signing/agent-resolver/resolve-agent.js +101 -132
- package/dist/lib/signing/agent-resolver/resolve-agent.mjs +102 -133
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.mts +7 -1
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.ts +7 -1
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.js +50 -17
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.mjs +50 -17
- package/dist/lib/signing/agent-resolver/select-agent.d.mts +14 -15
- package/dist/lib/signing/agent-resolver/select-agent.d.ts +14 -15
- package/dist/lib/signing/agent-resolver/select-agent.js +98 -13
- package/dist/lib/signing/agent-resolver/select-agent.mjs +95 -13
- package/dist/lib/signing/brand-jwks.d.mts +27 -75
- package/dist/lib/signing/brand-jwks.d.ts +27 -75
- package/dist/lib/signing/brand-jwks.js +112 -182
- package/dist/lib/signing/brand-jwks.mjs +112 -182
- package/dist/lib/signing/errors.d.mts +3 -1
- package/dist/lib/signing/errors.d.ts +3 -1
- package/dist/lib/signing/errors.js +4 -1
- package/dist/lib/signing/errors.mjs +4 -1
- package/dist/lib/signing/jwks-https.d.mts +7 -0
- package/dist/lib/signing/jwks-https.d.ts +7 -0
- package/dist/lib/signing/jwks-https.js +31 -8
- package/dist/lib/signing/jwks-https.mjs +31 -8
- package/dist/lib/signing/jwks.d.mts +8 -0
- package/dist/lib/signing/jwks.d.ts +8 -0
- package/dist/lib/signing/middleware.js +2 -1
- package/dist/lib/signing/middleware.mjs +2 -1
- package/dist/lib/signing/publisher-pins.d.mts +11 -0
- package/dist/lib/signing/publisher-pins.d.ts +11 -0
- package/dist/lib/signing/publisher-pins.js +125 -0
- package/dist/lib/signing/publisher-pins.mjs +101 -0
- package/dist/lib/signing/server.d.mts +1 -0
- package/dist/lib/signing/server.d.ts +1 -0
- package/dist/lib/signing/types.d.mts +5 -0
- package/dist/lib/signing/types.d.ts +5 -0
- package/dist/lib/signing/verifier.js +49 -4
- package/dist/lib/signing/verifier.mjs +49 -4
- package/dist/lib/signing/webhook-verifier.d.mts +7 -2
- package/dist/lib/signing/webhook-verifier.d.ts +7 -2
- package/dist/lib/signing/webhook-verifier.js +42 -2
- package/dist/lib/signing/webhook-verifier.mjs +43 -3
- package/dist/lib/testing/storyboard/account-policy.d.mts +2 -0
- package/dist/lib/testing/storyboard/account-policy.d.ts +2 -0
- package/dist/lib/testing/storyboard/account-policy.js +35 -0
- package/dist/lib/testing/storyboard/account-policy.mjs +11 -0
- package/dist/lib/testing/storyboard/context.js +6 -0
- package/dist/lib/testing/storyboard/context.mjs +6 -0
- package/dist/lib/testing/storyboard/request-builder.js +12 -2
- package/dist/lib/testing/storyboard/request-builder.mjs +12 -2
- package/dist/lib/testing/storyboard/runner.js +3 -2
- package/dist/lib/testing/storyboard/runner.mjs +3 -2
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/dist/lib/wholesale-feed-sync/sync.d.mts +1 -0
- package/dist/lib/wholesale-feed-sync/sync.d.ts +1 -0
- package/dist/lib/wholesale-feed-sync/sync.js +92 -21
- package/dist/lib/wholesale-feed-sync/sync.mjs +92 -21
- package/dist/lib/wholesale-feed-sync/types.d.mts +4 -3
- package/dist/lib/wholesale-feed-sync/types.d.ts +4 -3
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/guides/BUILD-AN-AGENT.md +2 -2
- package/docs/guides/BUYER-QUICKSTART-3.2.md +2 -0
- package/docs/guides/FIRST-CALL-TO-A-SELLER.md +104 -0
- package/docs/guides/SIGNING-GUIDE.md +16 -7
- package/docs/guides/account-resolution.md +86 -0
- package/docs/llms.txt +3 -2
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/docs/migration-4.x-to-5.x.md +1 -0
- package/docs/migration-agent-resolution-3.3.md +123 -0
- package/docs/recipes/verifying-inbound-webhooks.md +56 -15
- package/package.json +2 -2
|
@@ -23,6 +23,7 @@ import { createSigningFetch } from "../signing/fetch.mjs";
|
|
|
23
23
|
import { createSigningFetchAsync } from "../signing/fetch-async.mjs";
|
|
24
24
|
import { redactArgsForLog } from "../utils/redact-args.mjs";
|
|
25
25
|
import { wrapFetchWithCapture } from "./rawResponseCapture.mjs";
|
|
26
|
+
import { getSignedRequestRejection, wrapFetchWithSignedRequestRejection } from "./signedRequestRejection.mjs";
|
|
26
27
|
import { wrapFetchWithSizeLimit } from "./responseSizeLimit.mjs";
|
|
27
28
|
import { wrapFetchWithTransportDiagnostics } from "./transportDiagnostics.mjs";
|
|
28
29
|
import { DEFAULT_REQUEST_TIMEOUT_MS, resolveRequestTimeoutMs, withAbortSignal } from "./abort.mjs";
|
|
@@ -306,6 +307,7 @@ function buildFetchImpl(authToken, agentUrl) {
|
|
|
306
307
|
const networkFetch = wrapFetchWithTransportDiagnostics(
|
|
307
308
|
wrapFetchWithSizeLimit((input, init) => pinnedFetch(input, init))
|
|
308
309
|
);
|
|
310
|
+
const rejectionFetch = signingContext ? wrapFetchWithSignedRequestRejection(networkFetch, agentUrl) : networkFetch;
|
|
309
311
|
const baseFetch = async (url, options) => {
|
|
310
312
|
const context = callContextStorage.getStore();
|
|
311
313
|
const urlString = typeof url === "string" ? url : url instanceof URL ? url.toString() : url.url;
|
|
@@ -354,7 +356,11 @@ function buildFetchImpl(authToken, agentUrl) {
|
|
|
354
356
|
const response = await withAbortSignal(
|
|
355
357
|
[context?.signal, options?.signal],
|
|
356
358
|
requestTimeoutMs,
|
|
357
|
-
(signal) =>
|
|
359
|
+
(signal) => rejectionFetch(url, {
|
|
360
|
+
...options,
|
|
361
|
+
headers,
|
|
362
|
+
signal
|
|
363
|
+
})
|
|
358
364
|
);
|
|
359
365
|
if (response.status === 401 && context) {
|
|
360
366
|
context.got401Ref.value = true;
|
|
@@ -532,6 +538,8 @@ async function callA2AToolImpl(agentUrl, toolName, parameters, authToken, debugL
|
|
|
532
538
|
message: `A2A: Authentication required for ${agentUrl}`,
|
|
533
539
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
534
540
|
});
|
|
541
|
+
const signedRejection = getSignedRequestRejection(error);
|
|
542
|
+
if (signedRejection) throw signedRejection;
|
|
535
543
|
const challenge = await probeAuthChallenge(agentUrl, {
|
|
536
544
|
fetchFn: context.fetchFn,
|
|
537
545
|
allowPrivateIp: context.allowPrivateIp ?? isLikelyPrivateUrl(agentUrl)
|
|
@@ -68,6 +68,7 @@ var import_oauth = require('../auth/oauth/index.js');
|
|
|
68
68
|
var import_authorization_required = require('../auth/oauth/authorization-required.js');
|
|
69
69
|
var import_provider_cache = require('../auth/oauth/provider-cache.js');
|
|
70
70
|
var import_errors = require('../errors/index.js');
|
|
71
|
+
var import_signedRequestRejection = require('./signedRequestRejection.js');
|
|
71
72
|
var import_net = require('../net/index.js');
|
|
72
73
|
var import_validation = require('../validation/index.js');
|
|
73
74
|
var import_tracing = require('../observability/tracing.js');
|
|
@@ -369,7 +370,7 @@ class ProtocolClient {
|
|
|
369
370
|
}
|
|
370
371
|
);
|
|
371
372
|
} catch (err) {
|
|
372
|
-
if (agent.oauth_client_credentials && (0, import_errors.is401Error)(err)) {
|
|
373
|
+
if (agent.oauth_client_credentials && (0, import_errors.is401Error)(err) && (0, import_signedRequestRejection.getSignedRequestRejection)(err)?.challenge?.scheme !== "signature") {
|
|
373
374
|
const ccStorage = (0, import_oauth.getAgentStorage)(agent);
|
|
374
375
|
const allowPrivateIp = transport?.allowPrivateIp ?? (0, import_net.isLikelyPrivateUrl)(agent.agent_uri);
|
|
375
376
|
await (0, import_oauth.ensureClientCredentialsTokens)(agent, {
|
|
@@ -401,6 +402,8 @@ class ProtocolClient {
|
|
|
401
402
|
}
|
|
402
403
|
);
|
|
403
404
|
} catch (retryErr) {
|
|
405
|
+
const rejection = (0, import_signedRequestRejection.getSignedRequestRejection)(retryErr) ?? ((0, import_errors.is401Error)(retryErr) ? (0, import_signedRequestRejection.getSignedRequestRejection)(err) : void 0);
|
|
406
|
+
if (rejection) throw rejection;
|
|
404
407
|
await rethrowAsNeedsAuthorization(
|
|
405
408
|
retryErr,
|
|
406
409
|
agent.agent_uri,
|
|
@@ -441,7 +444,7 @@ class ProtocolClient {
|
|
|
441
444
|
transport?.legacyCompat
|
|
442
445
|
);
|
|
443
446
|
} catch (err) {
|
|
444
|
-
if (agent.oauth_client_credentials && (0, import_errors.is401Error)(err)) {
|
|
447
|
+
if (agent.oauth_client_credentials && (0, import_errors.is401Error)(err) && (0, import_signedRequestRejection.getSignedRequestRejection)(err)?.challenge?.scheme !== "signature") {
|
|
445
448
|
const ccStorage = (0, import_oauth.getAgentStorage)(agent);
|
|
446
449
|
const allowPrivateIp = transport?.allowPrivateIp ?? (0, import_net.isLikelyPrivateUrl)(agent.agent_uri);
|
|
447
450
|
await (0, import_oauth.ensureClientCredentialsTokens)(agent, {
|
|
@@ -470,6 +473,8 @@ class ProtocolClient {
|
|
|
470
473
|
transport?.legacyCompat
|
|
471
474
|
);
|
|
472
475
|
} catch (retryErr) {
|
|
476
|
+
const rejection = (0, import_signedRequestRejection.getSignedRequestRejection)(retryErr) ?? ((0, import_errors.is401Error)(retryErr) ? (0, import_signedRequestRejection.getSignedRequestRejection)(err) : void 0);
|
|
477
|
+
if (rejection) throw rejection;
|
|
473
478
|
await rethrowAsNeedsAuthorization(
|
|
474
479
|
retryErr,
|
|
475
480
|
agent.agent_uri,
|
|
@@ -501,6 +506,8 @@ class ProtocolClient {
|
|
|
501
506
|
}
|
|
502
507
|
}
|
|
503
508
|
async function rethrowAsNeedsAuthorization(err, agentUrl, fetchFn, signal, configuredAllowPrivateIp, recoveryMode = "discover") {
|
|
509
|
+
const signedRejection = (0, import_signedRequestRejection.getSignedRequestRejection)(err);
|
|
510
|
+
if (signedRejection) throw signedRejection;
|
|
504
511
|
if (err instanceof import_oauth.NeedsAuthorizationError) throw err;
|
|
505
512
|
if (!(0, import_errors.is401Error)(err)) return;
|
|
506
513
|
if (recoveryMode === "static") {
|
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
import { hasValidatedMcpAuthorizationRequirements } from "../auth/oauth/authorization-required.mjs";
|
|
54
54
|
import { getNonInteractiveOAuthProvider } from "../auth/oauth/provider-cache.mjs";
|
|
55
55
|
import { AuthenticationCredentialsRejectedError, is401Error } from "../errors/index.mjs";
|
|
56
|
+
import { getSignedRequestRejection } from "./signedRequestRejection.mjs";
|
|
56
57
|
import { isLikelyPrivateUrl } from "../net/index.mjs";
|
|
57
58
|
import { validateAgentUrl } from "../validation/index.mjs";
|
|
58
59
|
import { withSpan } from "../observability/tracing.mjs";
|
|
@@ -349,7 +350,7 @@ class ProtocolClient {
|
|
|
349
350
|
}
|
|
350
351
|
);
|
|
351
352
|
} catch (err) {
|
|
352
|
-
if (agent.oauth_client_credentials && is401Error(err)) {
|
|
353
|
+
if (agent.oauth_client_credentials && is401Error(err) && getSignedRequestRejection(err)?.challenge?.scheme !== "signature") {
|
|
353
354
|
const ccStorage = getAgentStorage(agent);
|
|
354
355
|
const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);
|
|
355
356
|
await ensureClientCredentialsTokens(agent, {
|
|
@@ -381,6 +382,8 @@ class ProtocolClient {
|
|
|
381
382
|
}
|
|
382
383
|
);
|
|
383
384
|
} catch (retryErr) {
|
|
385
|
+
const rejection = getSignedRequestRejection(retryErr) ?? (is401Error(retryErr) ? getSignedRequestRejection(err) : void 0);
|
|
386
|
+
if (rejection) throw rejection;
|
|
384
387
|
await rethrowAsNeedsAuthorization(
|
|
385
388
|
retryErr,
|
|
386
389
|
agent.agent_uri,
|
|
@@ -421,7 +424,7 @@ class ProtocolClient {
|
|
|
421
424
|
transport?.legacyCompat
|
|
422
425
|
);
|
|
423
426
|
} catch (err) {
|
|
424
|
-
if (agent.oauth_client_credentials && is401Error(err)) {
|
|
427
|
+
if (agent.oauth_client_credentials && is401Error(err) && getSignedRequestRejection(err)?.challenge?.scheme !== "signature") {
|
|
425
428
|
const ccStorage = getAgentStorage(agent);
|
|
426
429
|
const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);
|
|
427
430
|
await ensureClientCredentialsTokens(agent, {
|
|
@@ -450,6 +453,8 @@ class ProtocolClient {
|
|
|
450
453
|
transport?.legacyCompat
|
|
451
454
|
);
|
|
452
455
|
} catch (retryErr) {
|
|
456
|
+
const rejection = getSignedRequestRejection(retryErr) ?? (is401Error(retryErr) ? getSignedRequestRejection(err) : void 0);
|
|
457
|
+
if (rejection) throw rejection;
|
|
453
458
|
await rethrowAsNeedsAuthorization(
|
|
454
459
|
retryErr,
|
|
455
460
|
agent.agent_uri,
|
|
@@ -481,6 +486,8 @@ class ProtocolClient {
|
|
|
481
486
|
}
|
|
482
487
|
}
|
|
483
488
|
async function rethrowAsNeedsAuthorization(err, agentUrl, fetchFn, signal, configuredAllowPrivateIp, recoveryMode = "discover") {
|
|
489
|
+
const signedRejection = getSignedRequestRejection(err);
|
|
490
|
+
if (signedRejection) throw signedRejection;
|
|
484
491
|
if (err instanceof NeedsAuthorizationError) throw err;
|
|
485
492
|
if (!is401Error(err)) return;
|
|
486
493
|
if (recoveryMode === "static") {
|
|
@@ -34,6 +34,7 @@ var import_session_termination = require('./session-termination.js');
|
|
|
34
34
|
var import_client2 = require('../signing/client.js');
|
|
35
35
|
var import_abort = require('./abort.js');
|
|
36
36
|
var import_rawResponseCapture = require('./rawResponseCapture.js');
|
|
37
|
+
var import_signedRequestRejection = require('./signedRequestRejection.js');
|
|
37
38
|
var import_responseSizeLimit = require('./responseSizeLimit.js');
|
|
38
39
|
var import_transportDiagnostics = require('./transportDiagnostics.js');
|
|
39
40
|
var import_agent_transport_fetch = require('../net/agent-transport-fetch.js');
|
|
@@ -228,7 +229,7 @@ async function createNegotiatedClient(cacheKey, options, authHeaders, useCachedD
|
|
|
228
229
|
const networkFetch = (input, init) => (0, import_abort.withAbortSignal)([init?.signal], requestTimeoutMs, (signal) => rawNetworkFetch(input, { ...init, signal }));
|
|
229
230
|
const diagnosticFetch = (0, import_transportDiagnostics.wrapFetchWithTransportDiagnostics)((0, import_responseSizeLimit.wrapFetchWithSizeLimit)(networkFetch));
|
|
230
231
|
const signedFetch = options.signingContext ? (0, import_client2.buildAgentSigningFetch)({
|
|
231
|
-
upstream: diagnosticFetch,
|
|
232
|
+
upstream: (0, import_signedRequestRejection.wrapFetchWithSignedRequestRejection)(diagnosticFetch, options.agentUrl),
|
|
232
233
|
signing: options.signingContext.signing,
|
|
233
234
|
getCapability: options.signingContext.getCapability,
|
|
234
235
|
adcpVersion: options.signingContext.adcpVersion
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
withAbortSignal
|
|
29
29
|
} from "./abort.mjs";
|
|
30
30
|
import { wrapFetchWithCapture } from "./rawResponseCapture.mjs";
|
|
31
|
+
import { wrapFetchWithSignedRequestRejection } from "./signedRequestRejection.mjs";
|
|
31
32
|
import { wrapFetchWithSizeLimit } from "./responseSizeLimit.mjs";
|
|
32
33
|
import { wrapFetchWithTransportDiagnostics } from "./transportDiagnostics.mjs";
|
|
33
34
|
import { createAgentTransportFetch } from "../net/agent-transport-fetch.mjs";
|
|
@@ -222,7 +223,7 @@ async function createNegotiatedClient(cacheKey, options, authHeaders, useCachedD
|
|
|
222
223
|
const networkFetch = (input, init) => withAbortSignal([init?.signal], requestTimeoutMs, (signal) => rawNetworkFetch(input, { ...init, signal }));
|
|
223
224
|
const diagnosticFetch = wrapFetchWithTransportDiagnostics(wrapFetchWithSizeLimit(networkFetch));
|
|
224
225
|
const signedFetch = options.signingContext ? buildAgentSigningFetch({
|
|
225
|
-
upstream: diagnosticFetch,
|
|
226
|
+
upstream: wrapFetchWithSignedRequestRejection(diagnosticFetch, options.agentUrl),
|
|
226
227
|
signing: options.signingContext.signing,
|
|
227
228
|
getCapability: options.signingContext.getCapability,
|
|
228
229
|
adcpVersion: options.signingContext.adcpVersion
|
|
@@ -40,6 +40,7 @@ var import_tracing = require('../observability/tracing.js');
|
|
|
40
40
|
var import_client2 = require('../signing/client.js');
|
|
41
41
|
var import_redact_args = require('../utils/redact-args.js');
|
|
42
42
|
var import_rawResponseCapture = require('./rawResponseCapture.js');
|
|
43
|
+
var import_signedRequestRejection = require('./signedRequestRejection.js');
|
|
43
44
|
var import_responseSizeLimit = require('./responseSizeLimit.js');
|
|
44
45
|
var import_transportDiagnostics = require('./transportDiagnostics.js');
|
|
45
46
|
var import_abort = require('./abort.js');
|
|
@@ -482,7 +483,7 @@ async function connectMCPWithFallbackImpl(url, authHeaders, debugLogs = [], labe
|
|
|
482
483
|
const sizeLimited = (0, import_responseSizeLimit.wrapFetchWithSizeLimit)(networkFetch);
|
|
483
484
|
const diagnosticFetch = (0, import_transportDiagnostics.wrapFetchWithTransportDiagnostics)(sizeLimited);
|
|
484
485
|
const baseFetch = signingContext ? (0, import_client2.buildAgentSigningFetch)({
|
|
485
|
-
upstream: diagnosticFetch,
|
|
486
|
+
upstream: (0, import_signedRequestRejection.wrapFetchWithSignedRequestRejection)(diagnosticFetch, url.toString()),
|
|
486
487
|
signing: signingContext.signing,
|
|
487
488
|
getCapability: signingContext.getCapability,
|
|
488
489
|
adcpVersion: signingContext.adcpVersion
|
|
@@ -771,7 +772,7 @@ async function connectMCP(options) {
|
|
|
771
772
|
);
|
|
772
773
|
const diagnosticFetch = (0, import_transportDiagnostics.wrapFetchWithTransportDiagnostics)(sizeLimited);
|
|
773
774
|
const signedFetch = signingContext ? (0, import_client2.buildAgentSigningFetch)({
|
|
774
|
-
upstream: diagnosticFetch,
|
|
775
|
+
upstream: (0, import_signedRequestRejection.wrapFetchWithSignedRequestRejection)(diagnosticFetch, agentUrl),
|
|
775
776
|
signing: signingContext.signing,
|
|
776
777
|
getCapability: signingContext.getCapability,
|
|
777
778
|
adcpVersion: signingContext.adcpVersion
|
|
@@ -788,6 +789,8 @@ async function connectMCP(options) {
|
|
|
788
789
|
});
|
|
789
790
|
return { client: mcpClient, transport };
|
|
790
791
|
} catch (error) {
|
|
792
|
+
const signedRejection = (0, import_signedRequestRejection.getSignedRequestRejection)(error);
|
|
793
|
+
if (signedRejection) throw signedRejection;
|
|
791
794
|
if (authProvider && error instanceof import_auth.UnauthorizedError) {
|
|
792
795
|
debugLogs.push({
|
|
793
796
|
type: "info",
|
|
@@ -17,6 +17,7 @@ import { withSpan, injectTraceHeaders } from "../observability/tracing.mjs";
|
|
|
17
17
|
import { buildAgentSigningFetch, signingContextStorage } from "../signing/client.mjs";
|
|
18
18
|
import { redactArgsForLog } from "../utils/redact-args.mjs";
|
|
19
19
|
import { wrapFetchWithCapture } from "./rawResponseCapture.mjs";
|
|
20
|
+
import { getSignedRequestRejection, wrapFetchWithSignedRequestRejection } from "./signedRequestRejection.mjs";
|
|
20
21
|
import { wrapFetchWithSizeLimit } from "./responseSizeLimit.mjs";
|
|
21
22
|
import { sanitizeTransportUrl, wrapFetchWithTransportDiagnostics } from "./transportDiagnostics.mjs";
|
|
22
23
|
import {
|
|
@@ -469,7 +470,7 @@ async function connectMCPWithFallbackImpl(url, authHeaders, debugLogs = [], labe
|
|
|
469
470
|
const sizeLimited = wrapFetchWithSizeLimit(networkFetch);
|
|
470
471
|
const diagnosticFetch = wrapFetchWithTransportDiagnostics(sizeLimited);
|
|
471
472
|
const baseFetch = signingContext ? buildAgentSigningFetch({
|
|
472
|
-
upstream: diagnosticFetch,
|
|
473
|
+
upstream: wrapFetchWithSignedRequestRejection(diagnosticFetch, url.toString()),
|
|
473
474
|
signing: signingContext.signing,
|
|
474
475
|
getCapability: signingContext.getCapability,
|
|
475
476
|
adcpVersion: signingContext.adcpVersion
|
|
@@ -758,7 +759,7 @@ async function connectMCP(options) {
|
|
|
758
759
|
);
|
|
759
760
|
const diagnosticFetch = wrapFetchWithTransportDiagnostics(sizeLimited);
|
|
760
761
|
const signedFetch = signingContext ? buildAgentSigningFetch({
|
|
761
|
-
upstream: diagnosticFetch,
|
|
762
|
+
upstream: wrapFetchWithSignedRequestRejection(diagnosticFetch, agentUrl),
|
|
762
763
|
signing: signingContext.signing,
|
|
763
764
|
getCapability: signingContext.getCapability,
|
|
764
765
|
adcpVersion: signingContext.adcpVersion
|
|
@@ -775,6 +776,8 @@ async function connectMCP(options) {
|
|
|
775
776
|
});
|
|
776
777
|
return { client: mcpClient, transport };
|
|
777
778
|
} catch (error) {
|
|
779
|
+
const signedRejection = getSignedRequestRejection(error);
|
|
780
|
+
if (signedRejection) throw signedRejection;
|
|
778
781
|
if (authProvider && error instanceof UnauthorizedError) {
|
|
779
782
|
debugLogs.push({
|
|
780
783
|
type: "info",
|
|
@@ -55,4 +55,10 @@ export declare function getCapturesFromError(err: unknown): RawHttpCapture[] | u
|
|
|
55
55
|
* slot is set.
|
|
56
56
|
*/
|
|
57
57
|
export declare function wrapFetchWithCapture(upstream: typeof fetch): typeof fetch;
|
|
58
|
+
/** Record an already bounded response without cloning or reading its stream. */
|
|
59
|
+
export declare function recordRawResponseCapture(input: RequestInfo | URL, init: RequestInit | undefined, response: Response, body: string, bodyTruncated: boolean, startedAt: number, safeMetadata?: {
|
|
60
|
+
url?: string;
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
latencyMs?: number;
|
|
63
|
+
}): void;
|
|
58
64
|
export {};
|
|
@@ -55,4 +55,10 @@ export declare function getCapturesFromError(err: unknown): RawHttpCapture[] | u
|
|
|
55
55
|
* slot is set.
|
|
56
56
|
*/
|
|
57
57
|
export declare function wrapFetchWithCapture(upstream: typeof fetch): typeof fetch;
|
|
58
|
+
/** Record an already bounded response without cloning or reading its stream. */
|
|
59
|
+
export declare function recordRawResponseCapture(input: RequestInfo | URL, init: RequestInit | undefined, response: Response, body: string, bodyTruncated: boolean, startedAt: number, safeMetadata?: {
|
|
60
|
+
url?: string;
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
latencyMs?: number;
|
|
63
|
+
}): void;
|
|
58
64
|
export {};
|
|
@@ -21,6 +21,7 @@ __export(rawResponseCapture_exports, {
|
|
|
21
21
|
getCaptureOverflowFromError: () => getCaptureOverflowFromError,
|
|
22
22
|
getCapturesFromError: () => getCapturesFromError,
|
|
23
23
|
rawResponseCaptureStorage: () => rawResponseCaptureStorage,
|
|
24
|
+
recordRawResponseCapture: () => recordRawResponseCapture,
|
|
24
25
|
withRawResponseCapture: () => withRawResponseCapture,
|
|
25
26
|
wrapFetchWithCapture: () => wrapFetchWithCapture
|
|
26
27
|
});
|
|
@@ -88,44 +89,54 @@ function wrapFetchWithCapture(upstream) {
|
|
|
88
89
|
const wrapped = async (input, init) => {
|
|
89
90
|
const slot = rawResponseCaptureStorage.getStore();
|
|
90
91
|
if (!slot) return upstream(input, init);
|
|
91
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
92
|
-
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
93
|
-
const requestMetadata = extractSafeRequestMetadata(init?.body, slot.maxBodyBytes);
|
|
94
92
|
const startedAt = Date.now();
|
|
95
93
|
const response = await upstream(input, init);
|
|
96
94
|
const latencyMs = Date.now() - startedAt;
|
|
97
95
|
const cloneForRead = response.clone();
|
|
98
96
|
const { body, bodyTruncated } = await readBodyBounded(cloneForRead, slot.maxBodyBytes);
|
|
99
|
-
|
|
100
|
-
response.headers.forEach((value, key) => {
|
|
101
|
-
const lower = key.toLowerCase();
|
|
102
|
-
headers[key] = REDACTED_HEADER_NAMES.has(lower) ? REDACTED_PLACEHOLDER : value;
|
|
103
|
-
});
|
|
104
|
-
if (slot.maxCaptures !== void 0 && slot.captures.length >= slot.maxCaptures) {
|
|
105
|
-
slot.overflowed ??= "captures";
|
|
106
|
-
return response;
|
|
107
|
-
}
|
|
108
|
-
const redactedBody = redactBearerInBody(body);
|
|
109
|
-
if (slot.maxTotalBodyBytes !== void 0 && slot.totalBodyBytes + redactedBody.length > slot.maxTotalBodyBytes) {
|
|
110
|
-
slot.overflowed ??= "bytes";
|
|
111
|
-
return response;
|
|
112
|
-
}
|
|
113
|
-
slot.totalBodyBytes += redactedBody.length;
|
|
114
|
-
slot.captures.push({
|
|
115
|
-
url,
|
|
116
|
-
method,
|
|
117
|
-
...requestMetadata,
|
|
118
|
-
status: response.status,
|
|
119
|
-
headers,
|
|
120
|
-
body: redactedBody,
|
|
121
|
-
latencyMs,
|
|
122
|
-
timestamp: new Date(startedAt).toISOString(),
|
|
123
|
-
bodyTruncated
|
|
124
|
-
});
|
|
97
|
+
recordRawResponseCapture(input, init, response, body, bodyTruncated, startedAt, { latencyMs });
|
|
125
98
|
return response;
|
|
126
99
|
};
|
|
127
100
|
return wrapped;
|
|
128
101
|
}
|
|
102
|
+
function recordRawResponseCapture(input, init, response, body, bodyTruncated, startedAt, safeMetadata) {
|
|
103
|
+
const slot = rawResponseCaptureStorage.getStore();
|
|
104
|
+
if (!slot) return;
|
|
105
|
+
const url = safeMetadata?.url ?? (typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
|
|
106
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
107
|
+
const requestMetadata = extractSafeRequestMetadata(init?.body, slot.maxBodyBytes);
|
|
108
|
+
const latencyMs = safeMetadata?.latencyMs ?? Date.now() - startedAt;
|
|
109
|
+
if (body.length > slot.maxBodyBytes) {
|
|
110
|
+
body = body.slice(0, slot.maxBodyBytes);
|
|
111
|
+
bodyTruncated = true;
|
|
112
|
+
}
|
|
113
|
+
const headers = {};
|
|
114
|
+
response.headers.forEach((value, key) => {
|
|
115
|
+
const lower = key.toLowerCase();
|
|
116
|
+
headers[key] = REDACTED_HEADER_NAMES.has(lower) ? REDACTED_PLACEHOLDER : value;
|
|
117
|
+
});
|
|
118
|
+
if (slot.maxCaptures !== void 0 && slot.captures.length >= slot.maxCaptures) {
|
|
119
|
+
slot.overflowed ??= "captures";
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const redactedBody = redactBearerInBody(body);
|
|
123
|
+
if (slot.maxTotalBodyBytes !== void 0 && slot.totalBodyBytes + redactedBody.length > slot.maxTotalBodyBytes) {
|
|
124
|
+
slot.overflowed ??= "bytes";
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
slot.totalBodyBytes += redactedBody.length;
|
|
128
|
+
slot.captures.push({
|
|
129
|
+
url,
|
|
130
|
+
method,
|
|
131
|
+
...requestMetadata,
|
|
132
|
+
status: response.status,
|
|
133
|
+
headers: safeMetadata?.headers ?? headers,
|
|
134
|
+
body: redactedBody,
|
|
135
|
+
latencyMs,
|
|
136
|
+
timestamp: new Date(startedAt).toISOString(),
|
|
137
|
+
bodyTruncated
|
|
138
|
+
});
|
|
139
|
+
}
|
|
129
140
|
function extractSafeRequestMetadata(body, maxBodyBytes) {
|
|
130
141
|
if (typeof body !== "string" || body.length > maxBodyBytes) return {};
|
|
131
142
|
let parsed;
|
|
@@ -175,6 +186,7 @@ async function readBodyBounded(response, maxBodyBytes) {
|
|
|
175
186
|
getCaptureOverflowFromError,
|
|
176
187
|
getCapturesFromError,
|
|
177
188
|
rawResponseCaptureStorage,
|
|
189
|
+
recordRawResponseCapture,
|
|
178
190
|
withRawResponseCapture,
|
|
179
191
|
wrapFetchWithCapture
|
|
180
192
|
});
|
|
@@ -66,44 +66,54 @@ function wrapFetchWithCapture(upstream) {
|
|
|
66
66
|
const wrapped = async (input, init) => {
|
|
67
67
|
const slot = rawResponseCaptureStorage.getStore();
|
|
68
68
|
if (!slot) return upstream(input, init);
|
|
69
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
70
|
-
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
71
|
-
const requestMetadata = extractSafeRequestMetadata(init?.body, slot.maxBodyBytes);
|
|
72
69
|
const startedAt = Date.now();
|
|
73
70
|
const response = await upstream(input, init);
|
|
74
71
|
const latencyMs = Date.now() - startedAt;
|
|
75
72
|
const cloneForRead = response.clone();
|
|
76
73
|
const { body, bodyTruncated } = await readBodyBounded(cloneForRead, slot.maxBodyBytes);
|
|
77
|
-
|
|
78
|
-
response.headers.forEach((value, key) => {
|
|
79
|
-
const lower = key.toLowerCase();
|
|
80
|
-
headers[key] = REDACTED_HEADER_NAMES.has(lower) ? REDACTED_PLACEHOLDER : value;
|
|
81
|
-
});
|
|
82
|
-
if (slot.maxCaptures !== void 0 && slot.captures.length >= slot.maxCaptures) {
|
|
83
|
-
slot.overflowed ??= "captures";
|
|
84
|
-
return response;
|
|
85
|
-
}
|
|
86
|
-
const redactedBody = redactBearerInBody(body);
|
|
87
|
-
if (slot.maxTotalBodyBytes !== void 0 && slot.totalBodyBytes + redactedBody.length > slot.maxTotalBodyBytes) {
|
|
88
|
-
slot.overflowed ??= "bytes";
|
|
89
|
-
return response;
|
|
90
|
-
}
|
|
91
|
-
slot.totalBodyBytes += redactedBody.length;
|
|
92
|
-
slot.captures.push({
|
|
93
|
-
url,
|
|
94
|
-
method,
|
|
95
|
-
...requestMetadata,
|
|
96
|
-
status: response.status,
|
|
97
|
-
headers,
|
|
98
|
-
body: redactedBody,
|
|
99
|
-
latencyMs,
|
|
100
|
-
timestamp: new Date(startedAt).toISOString(),
|
|
101
|
-
bodyTruncated
|
|
102
|
-
});
|
|
74
|
+
recordRawResponseCapture(input, init, response, body, bodyTruncated, startedAt, { latencyMs });
|
|
103
75
|
return response;
|
|
104
76
|
};
|
|
105
77
|
return wrapped;
|
|
106
78
|
}
|
|
79
|
+
function recordRawResponseCapture(input, init, response, body, bodyTruncated, startedAt, safeMetadata) {
|
|
80
|
+
const slot = rawResponseCaptureStorage.getStore();
|
|
81
|
+
if (!slot) return;
|
|
82
|
+
const url = safeMetadata?.url ?? (typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
|
|
83
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
84
|
+
const requestMetadata = extractSafeRequestMetadata(init?.body, slot.maxBodyBytes);
|
|
85
|
+
const latencyMs = safeMetadata?.latencyMs ?? Date.now() - startedAt;
|
|
86
|
+
if (body.length > slot.maxBodyBytes) {
|
|
87
|
+
body = body.slice(0, slot.maxBodyBytes);
|
|
88
|
+
bodyTruncated = true;
|
|
89
|
+
}
|
|
90
|
+
const headers = {};
|
|
91
|
+
response.headers.forEach((value, key) => {
|
|
92
|
+
const lower = key.toLowerCase();
|
|
93
|
+
headers[key] = REDACTED_HEADER_NAMES.has(lower) ? REDACTED_PLACEHOLDER : value;
|
|
94
|
+
});
|
|
95
|
+
if (slot.maxCaptures !== void 0 && slot.captures.length >= slot.maxCaptures) {
|
|
96
|
+
slot.overflowed ??= "captures";
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const redactedBody = redactBearerInBody(body);
|
|
100
|
+
if (slot.maxTotalBodyBytes !== void 0 && slot.totalBodyBytes + redactedBody.length > slot.maxTotalBodyBytes) {
|
|
101
|
+
slot.overflowed ??= "bytes";
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
slot.totalBodyBytes += redactedBody.length;
|
|
105
|
+
slot.captures.push({
|
|
106
|
+
url,
|
|
107
|
+
method,
|
|
108
|
+
...requestMetadata,
|
|
109
|
+
status: response.status,
|
|
110
|
+
headers: safeMetadata?.headers ?? headers,
|
|
111
|
+
body: redactedBody,
|
|
112
|
+
latencyMs,
|
|
113
|
+
timestamp: new Date(startedAt).toISOString(),
|
|
114
|
+
bodyTruncated
|
|
115
|
+
});
|
|
116
|
+
}
|
|
107
117
|
function extractSafeRequestMetadata(body, maxBodyBytes) {
|
|
108
118
|
if (typeof body !== "string" || body.length > maxBodyBytes) return {};
|
|
109
119
|
let parsed;
|
|
@@ -152,6 +162,7 @@ export {
|
|
|
152
162
|
getCaptureOverflowFromError,
|
|
153
163
|
getCapturesFromError,
|
|
154
164
|
rawResponseCaptureStorage,
|
|
165
|
+
recordRawResponseCapture,
|
|
155
166
|
withRawResponseCapture,
|
|
156
167
|
wrapFetchWithCapture
|
|
157
168
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthenticationRequiredError } from '../errors/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Install below the SDK signer, on the actual outbound transport. Only a
|
|
4
|
+
* request carrying Signature is classified as signed; signing configuration
|
|
5
|
+
* alone says nothing about unsigned discovery/housekeeping calls.
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapFetchWithSignedRequestRejection(upstream: typeof fetch, agentUrl?: string): typeof fetch;
|
|
8
|
+
/** Official clients may retain fetch failures under a transport error cause. */
|
|
9
|
+
export declare function getSignedRequestRejection(error: unknown): AuthenticationRequiredError | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthenticationRequiredError } from '../errors';
|
|
2
|
+
/**
|
|
3
|
+
* Install below the SDK signer, on the actual outbound transport. Only a
|
|
4
|
+
* request carrying Signature is classified as signed; signing configuration
|
|
5
|
+
* alone says nothing about unsigned discovery/housekeeping calls.
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapFetchWithSignedRequestRejection(upstream: typeof fetch, agentUrl?: string): typeof fetch;
|
|
8
|
+
/** Official clients may retain fetch failures under a transport error cause. */
|
|
9
|
+
export declare function getSignedRequestRejection(error: unknown): AuthenticationRequiredError | undefined;
|