@agentcash/router 1.2.1 → 1.2.3

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.cjs CHANGED
@@ -741,30 +741,53 @@ async function buildChallengeRequirements(server, request, price, accepts, resou
741
741
  function needsFacilitatorEnrichment(accepts) {
742
742
  return accepts.some((accept) => accept.scheme !== "exact") || hasSolanaAccepts(accepts);
743
743
  }
744
+ async function enrichGroup(group, resource) {
745
+ const accepted = await enrichRequirementsWithFacilitatorAccepts(
746
+ group.facilitator,
747
+ resource,
748
+ group.items.map(({ requirement }) => requirement)
749
+ );
750
+ if (accepted.length !== group.items.length) {
751
+ throw new Error(
752
+ `Facilitator /accepts returned ${accepted.length} requirements for ${group.items.length} inputs on ${group.facilitator.url ?? group.facilitator.network}`
753
+ );
754
+ }
755
+ return accepted;
756
+ }
744
757
  async function enrichChallengeRequirements(requirements, resource, facilitatorsByNetwork) {
745
758
  const groups = collectEnrichmentGroups(requirements, facilitatorsByNetwork);
746
759
  if (groups.length === 0) return requirements;
747
- const enrichedRequirements = [...requirements];
748
- await Promise.all(
760
+ const results = await Promise.all(
749
761
  groups.map(async (group) => {
750
- const enriched = await enrichRequirementsWithFacilitatorAccepts(
751
- group.facilitator,
752
- resource,
753
- group.items.map(({ requirement }) => requirement)
754
- );
755
- if (enriched.length !== group.items.length) {
756
- throw new Error(
757
- `Facilitator /accepts returned ${enriched.length} requirements for ${group.items.length} inputs on ${group.facilitator.url ?? group.facilitator.network}`
762
+ try {
763
+ return { success: true, group, accepted: await enrichGroup(group, resource) };
764
+ } catch (err) {
765
+ const label = group.facilitator.url ?? group.facilitator.network;
766
+ const reason = err instanceof Error ? err.message : String(err);
767
+ console.warn(
768
+ `[router] ${label} /accepts failed, dropping ${group.items.length} requirement(s): ${reason}`
758
769
  );
770
+ return { success: false, group };
759
771
  }
760
- enriched.forEach((requirement, offset) => {
761
- const index = group.items[offset]?.index;
762
- if (index === void 0) return;
763
- enrichedRequirements[index] = requirement;
764
- });
765
772
  })
766
773
  );
767
- return enrichedRequirements;
774
+ const enriched = [...requirements];
775
+ results.filter((r) => r.success).forEach(({ group, accepted }) => {
776
+ accepted.forEach((req, offset) => {
777
+ const index = group.items[offset]?.index;
778
+ if (index !== void 0) enriched[index] = req;
779
+ });
780
+ });
781
+ const failedIndices = new Set(
782
+ results.filter((r) => !r.success).flatMap(({ group }) => group.items.map(({ index }) => index))
783
+ );
784
+ const remaining = enriched.filter((_, i) => !failedIndices.has(i));
785
+ if (remaining.length === 0) {
786
+ throw new Error(
787
+ "All facilitator enrichments failed; no payment requirements remain for challenge"
788
+ );
789
+ }
790
+ return remaining;
768
791
  }
769
792
  function collectEnrichmentGroups(requirements, facilitatorsByNetwork) {
770
793
  const groups = [];
@@ -2206,6 +2229,7 @@ function createOpenAPIHandler(registry, baseUrl, pricesKeys, discovery) {
2206
2229
  title: discovery.title,
2207
2230
  description: discovery.description,
2208
2231
  version: discovery.version,
2232
+ ...guidance !== void 0 && { "x-guidance": guidance },
2209
2233
  guidance,
2210
2234
  ...discovery.contact && { contact: discovery.contact }
2211
2235
  },
package/dist/index.js CHANGED
@@ -702,30 +702,53 @@ async function buildChallengeRequirements(server, request, price, accepts, resou
702
702
  function needsFacilitatorEnrichment(accepts) {
703
703
  return accepts.some((accept) => accept.scheme !== "exact") || hasSolanaAccepts(accepts);
704
704
  }
705
+ async function enrichGroup(group, resource) {
706
+ const accepted = await enrichRequirementsWithFacilitatorAccepts(
707
+ group.facilitator,
708
+ resource,
709
+ group.items.map(({ requirement }) => requirement)
710
+ );
711
+ if (accepted.length !== group.items.length) {
712
+ throw new Error(
713
+ `Facilitator /accepts returned ${accepted.length} requirements for ${group.items.length} inputs on ${group.facilitator.url ?? group.facilitator.network}`
714
+ );
715
+ }
716
+ return accepted;
717
+ }
705
718
  async function enrichChallengeRequirements(requirements, resource, facilitatorsByNetwork) {
706
719
  const groups = collectEnrichmentGroups(requirements, facilitatorsByNetwork);
707
720
  if (groups.length === 0) return requirements;
708
- const enrichedRequirements = [...requirements];
709
- await Promise.all(
721
+ const results = await Promise.all(
710
722
  groups.map(async (group) => {
711
- const enriched = await enrichRequirementsWithFacilitatorAccepts(
712
- group.facilitator,
713
- resource,
714
- group.items.map(({ requirement }) => requirement)
715
- );
716
- if (enriched.length !== group.items.length) {
717
- throw new Error(
718
- `Facilitator /accepts returned ${enriched.length} requirements for ${group.items.length} inputs on ${group.facilitator.url ?? group.facilitator.network}`
723
+ try {
724
+ return { success: true, group, accepted: await enrichGroup(group, resource) };
725
+ } catch (err) {
726
+ const label = group.facilitator.url ?? group.facilitator.network;
727
+ const reason = err instanceof Error ? err.message : String(err);
728
+ console.warn(
729
+ `[router] ${label} /accepts failed, dropping ${group.items.length} requirement(s): ${reason}`
719
730
  );
731
+ return { success: false, group };
720
732
  }
721
- enriched.forEach((requirement, offset) => {
722
- const index = group.items[offset]?.index;
723
- if (index === void 0) return;
724
- enrichedRequirements[index] = requirement;
725
- });
726
733
  })
727
734
  );
728
- return enrichedRequirements;
735
+ const enriched = [...requirements];
736
+ results.filter((r) => r.success).forEach(({ group, accepted }) => {
737
+ accepted.forEach((req, offset) => {
738
+ const index = group.items[offset]?.index;
739
+ if (index !== void 0) enriched[index] = req;
740
+ });
741
+ });
742
+ const failedIndices = new Set(
743
+ results.filter((r) => !r.success).flatMap(({ group }) => group.items.map(({ index }) => index))
744
+ );
745
+ const remaining = enriched.filter((_, i) => !failedIndices.has(i));
746
+ if (remaining.length === 0) {
747
+ throw new Error(
748
+ "All facilitator enrichments failed; no payment requirements remain for challenge"
749
+ );
750
+ }
751
+ return remaining;
729
752
  }
730
753
  function collectEnrichmentGroups(requirements, facilitatorsByNetwork) {
731
754
  const groups = [];
@@ -2167,6 +2190,7 @@ function createOpenAPIHandler(registry, baseUrl, pricesKeys, discovery) {
2167
2190
  title: discovery.title,
2168
2191
  description: discovery.description,
2169
2192
  version: discovery.version,
2193
+ ...guidance !== void 0 && { "x-guidance": guidance },
2170
2194
  guidance,
2171
2195
  ...discovery.contact && { contact: discovery.contact }
2172
2196
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Unified route builder for Next.js App Router APIs with x402, MPP, SIWX, and API key auth",
5
5
  "type": "module",
6
6
  "exports": {
@@ -61,7 +61,7 @@
61
61
  "@x402/extensions": "^2.3.0",
62
62
  "@x402/svm": "2.3.0",
63
63
  "eslint": "^10.0.0",
64
- "mppx": "^0.4.2",
64
+ "mppx": "^0.4.8",
65
65
  "next": "^15.0.0",
66
66
  "prettier": "^3.8.1",
67
67
  "react": "^19.0.0",