@nevermined-io/payments 1.1.18 → 1.4.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 (77) hide show
  1. package/README.md +5 -3
  2. package/dist/a2a/clientRegistry.d.ts.map +1 -1
  3. package/dist/a2a/clientRegistry.js +2 -2
  4. package/dist/a2a/clientRegistry.js.map +1 -1
  5. package/dist/a2a/paymentsClient.d.ts +2 -2
  6. package/dist/a2a/paymentsClient.d.ts.map +1 -1
  7. package/dist/a2a/paymentsClient.js +10 -6
  8. package/dist/a2a/paymentsClient.js.map +1 -1
  9. package/dist/a2a/server.d.ts.map +1 -1
  10. package/dist/a2a/server.js +3 -1
  11. package/dist/a2a/server.js.map +1 -1
  12. package/dist/a2a/types.d.ts +1 -0
  13. package/dist/a2a/types.d.ts.map +1 -1
  14. package/dist/a2a/types.js.map +1 -1
  15. package/dist/api/base-payments.d.ts.map +1 -1
  16. package/dist/api/base-payments.js +12 -10
  17. package/dist/api/base-payments.js.map +1 -1
  18. package/dist/api/nvm-api.d.ts +0 -1
  19. package/dist/api/nvm-api.d.ts.map +1 -1
  20. package/dist/api/nvm-api.js +0 -1
  21. package/dist/api/nvm-api.js.map +1 -1
  22. package/dist/api/plans-api.d.ts +21 -32
  23. package/dist/api/plans-api.d.ts.map +1 -1
  24. package/dist/api/plans-api.js +27 -49
  25. package/dist/api/plans-api.js.map +1 -1
  26. package/dist/common/types.d.ts +90 -19
  27. package/dist/common/types.d.ts.map +1 -1
  28. package/dist/common/types.js +16 -0
  29. package/dist/common/types.js.map +1 -1
  30. package/dist/environments.d.ts +0 -7
  31. package/dist/environments.d.ts.map +1 -1
  32. package/dist/environments.js +0 -13
  33. package/dist/environments.js.map +1 -1
  34. package/dist/index.d.ts +2 -5
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -3
  37. package/dist/index.js.map +1 -1
  38. package/dist/mcp/http/session-manager.d.ts.map +1 -1
  39. package/dist/mcp/http/session-manager.js +15 -1
  40. package/dist/mcp/http/session-manager.js.map +1 -1
  41. package/dist/payments.d.ts +17 -1
  42. package/dist/payments.d.ts.map +1 -1
  43. package/dist/payments.js +2 -10
  44. package/dist/payments.js.map +1 -1
  45. package/dist/plans.d.ts +14 -3
  46. package/dist/plans.d.ts.map +1 -1
  47. package/dist/plans.js +25 -8
  48. package/dist/plans.js.map +1 -1
  49. package/dist/x402/delegation-api.d.ts +119 -19
  50. package/dist/x402/delegation-api.d.ts.map +1 -1
  51. package/dist/x402/delegation-api.js +77 -23
  52. package/dist/x402/delegation-api.js.map +1 -1
  53. package/dist/x402/express/middleware.d.ts +4 -0
  54. package/dist/x402/express/middleware.d.ts.map +1 -1
  55. package/dist/x402/express/middleware.js +7 -4
  56. package/dist/x402/express/middleware.js.map +1 -1
  57. package/dist/x402/facilitator-api.d.ts +13 -5
  58. package/dist/x402/facilitator-api.d.ts.map +1 -1
  59. package/dist/x402/facilitator-api.js +41 -15
  60. package/dist/x402/facilitator-api.js.map +1 -1
  61. package/dist/x402/index.d.ts +3 -7
  62. package/dist/x402/index.d.ts.map +1 -1
  63. package/dist/x402/index.js +2 -5
  64. package/dist/x402/index.js.map +1 -1
  65. package/dist/x402/token.d.ts +17 -17
  66. package/dist/x402/token.d.ts.map +1 -1
  67. package/dist/x402/token.js +27 -37
  68. package/dist/x402/token.js.map +1 -1
  69. package/package.json +23 -21
  70. package/dist/x402/visa-facilitator-api.d.ts +0 -150
  71. package/dist/x402/visa-facilitator-api.d.ts.map +0 -1
  72. package/dist/x402/visa-facilitator-api.js +0 -206
  73. package/dist/x402/visa-facilitator-api.js.map +0 -1
  74. package/dist/x402/visa-token-api.d.ts +0 -60
  75. package/dist/x402/visa-token-api.d.ts.map +0 -1
  76. package/dist/x402/visa-token-api.js +0 -99
  77. package/dist/x402/visa-token-api.js.map +0 -1
package/dist/payments.js CHANGED
@@ -14,8 +14,6 @@ import { OrganizationsAPI } from './api/organizations-api/organizations-api.js';
14
14
  import { FacilitatorAPI } from './x402/facilitator-api.js';
15
15
  import { X402TokenAPI } from './x402/token.js';
16
16
  import { DelegationAPI } from './x402/delegation-api.js';
17
- import { VisaFacilitatorAPI } from './x402/visa-facilitator-api.js';
18
- import { VisaTokenAPI } from './x402/visa-token-api.js';
19
17
  /**
20
18
  * Main class that interacts with the Nevermined payments API.
21
19
  * Use `Payments.getInstance` for server-side usage or `Payments.getBrowserInstance` for browser usage.
@@ -154,14 +152,8 @@ export class Payments extends BasePaymentsAPI {
154
152
  this.organizations = OrganizationsAPI.getInstance(options);
155
153
  this.query = AIQueryApi.getInstance();
156
154
  this.contracts = new ContractsAPI(options);
157
- if (options.scheme === 'visa') {
158
- this.facilitator = VisaFacilitatorAPI.getInstance(options);
159
- this.x402 = VisaTokenAPI.getInstance(options);
160
- }
161
- else {
162
- this.facilitator = FacilitatorAPI.getInstance(options);
163
- this.x402 = X402TokenAPI.getInstance(options);
164
- }
155
+ this.facilitator = FacilitatorAPI.getInstance(options);
156
+ this.x402 = X402TokenAPI.getInstance(options);
165
157
  }
166
158
  /**
167
159
  * Initiates the connect flow. The user's browser will be redirected to
@@ -1 +1 @@
1
- {"version":3,"file":"payments.js","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB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,CAAA;QAC/C,CAAC;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACI,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,iBAAiB;YAAE,OAAM;QACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oBAAoB,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QACpF,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;IACvC,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM;QACX,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;IAClC,CAAC;;AA5ID;;;GAGG;AACI,YAAG,GAAG,EAAE,qBAAqB,EAAE,CAAA","sourcesContent":["import { AIQueryApi } from './api/query-api.js'\nimport { PaymentsError } from './common/payments.error.js'\nimport { PaymentOptions } from './common/types.js'\nimport { BasePaymentsAPI } from './api/base-payments.js'\nimport { PlansAPI } from './api/plans-api.js'\nimport { ContractsAPI } from './api/contracts-api.js'\nimport { AgentsAPI } from './api/agents-api.js'\nimport { AgentRequestsAPI } from './api/requests-api.js'\nimport { ObservabilityAPI } from './api/observability-api/observability-api.js'\nimport { ClientRegistry } from './a2a/clientRegistry.js'\nimport type { PaymentsA2AServerOptions, PaymentsA2AServerResult } from './a2a/server.js'\nimport { PaymentsA2AServer } from './a2a/server.js'\nimport { buildPaymentAgentCard } from './a2a/agent-card.js'\nimport * as mcpModule from './mcp/index.js'\nimport { OrganizationsAPI } from './api/organizations-api/organizations-api.js'\nimport { FacilitatorAPI } from './x402/facilitator-api.js'\nimport { X402TokenAPI } from './x402/token.js'\nimport { DelegationAPI } from './x402/delegation-api.js'\nimport { VisaFacilitatorAPI } from './x402/visa-facilitator-api.js'\nimport { VisaTokenAPI } from './x402/visa-token-api.js'\n\n/**\n * Main class that interacts with the Nevermined payments API.\n * Use `Payments.getInstance` for server-side usage or `Payments.getBrowserInstance` for browser usage.\n * @remarks This API requires a Nevermined API Key, which can be obtained by logging in to the Nevermined App.\n *\n * The library provides methods to manage AI Agents, Plans & process AI Agent Requests.\n *\n * Each of these functionalities is encapsulated in its own API class:\n * - `plans`: Manages AI Plans, including registration and ordering and retrieving plan details.\n * - `agents`: Handles AI Agents, including registration of AI Agents and access token generation.\n * - `requests`: Manages requests received by AI Agents, including validation and tracking.\n * - `observability`: Provides observability and logging utilities for AI Agents with Helicone integration\n */\nexport class Payments extends BasePaymentsAPI {\n public query!: AIQueryApi\n public plans!: PlansAPI\n public agents!: AgentsAPI\n public requests!: AgentRequestsAPI\n public observability!: ObservabilityAPI\n public organizations!: OrganizationsAPI\n public contracts!: ContractsAPI\n public facilitator!: FacilitatorAPI\n public x402!: X402TokenAPI\n private _a2aRegistry?: ClientRegistry\n private _delegation?: DelegationAPI\n\n /**\n * Cached MCP integration to preserve configuration (e.g., agentId, serverName)\n * across multiple getter accesses. This ensures callers do not need to retain\n * a reference to a previously configured instance.\n */\n private _mcpIntegration?: ReturnType<typeof mcpModule.buildMcpIntegration>\n\n /**\n * Exposes A2A server and client registry methods.\n * The client registry is initialized only if getClient is called.\n */\n public get a2a() {\n return {\n /**\n * Starts the A2A server with payment integration.\n * @param options - Server options.\n */\n start: (\n options: Omit<PaymentsA2AServerOptions, 'paymentsService'>,\n ): PaymentsA2AServerResult => PaymentsA2AServer.start({ ...options, paymentsService: this }),\n\n /**\n * Gets (or creates) a RegisteredPaymentsClient for the given alias.\n * The registry is initialized only on first use.\n * @param options - ClientRegistryOptions.\n */\n getClient: async (options: any) => {\n if (!this._a2aRegistry) {\n this._a2aRegistry = new ClientRegistry(this)\n }\n return await this._a2aRegistry.getClient(options)\n },\n }\n }\n\n /**\n * Returns the MCP integration API. The instance is memoized so that configuration\n * set via `configure({ agentId, serverName })` persists across calls.\n */\n public get mcp() {\n if (!this._mcpIntegration) {\n this._mcpIntegration = mcpModule.buildMcpIntegration(this)\n }\n return this._mcpIntegration\n }\n\n /**\n * Returns the Delegation API for listing enrolled payment methods.\n * The instance is lazily initialized on first access.\n */\n public get delegation(): DelegationAPI {\n if (!this._delegation) {\n this._delegation = DelegationAPI.getInstance({\n nvmApiKey: this.nvmApiKey,\n environment: this.environmentName,\n })\n }\n return this._delegation\n }\n\n /**\n * Static A2A helpers and utilities.\n * Example: Payments.a2a.buildPaymentAgentCard(...)\n */\n static a2a = { buildPaymentAgentCard }\n\n /**\n * Get an instance of the Payments class for server-side usage.\n *\n * @param options - The options to initialize the payments class.\n * @example\n * ```\n * const payments = Payments.getInstance({\n * nvmApiKey: 'your-nvm-api-key',\n * environment: 'sandbox'\n * })\n * ```\n * @returns An instance of {@link Payments}\n * @throws PaymentsError if nvmApiKey is missing.\n */\n static getInstance(options: PaymentOptions) {\n if (!options.nvmApiKey) {\n throw new PaymentsError('Nevermined API Key is required')\n }\n return new Payments(options, false)\n }\n\n /**\n * Get an instance of the Payments class for browser usage.\n *\n * @remarks\n * This is a browser-only function.\n *\n * @param options - The options to initialize the payments class.\n * @example\n * ```\n * const payments = Payments.getBrowserInstance({\n * returnUrl: 'https://mysite.example',\n * environment: 'sandbox',\n * appId: 'my-app-id',\n * version: '1.0.0'\n * })\n * ```\n * @returns An instance of {@link Payments}\n * @throws PaymentsError if returnUrl is missing.\n */\n static getBrowserInstance(options: PaymentOptions) {\n if (!options.returnUrl) {\n throw new PaymentsError('returnUrl is required')\n }\n const url = new URL(window.location.href)\n const urlNvmApiKey = url.searchParams.get('nvmApiKey') as string\n if (urlNvmApiKey) {\n url.searchParams.delete('nvmApiKey')\n }\n\n const urlAccountAddress = url.searchParams.get('accountAddress') as string\n if (urlAccountAddress) {\n url.searchParams.delete('accountAddress')\n }\n\n history.replaceState(history.state, '', url.toString())\n\n return new Payments(options, true)\n }\n\n /**\n * Initializes the Payments class.\n *\n * @param options - The options to initialize the payments class.\n * @param isBrowserInstance - Whether this instance is for browser usage.\n */\n private constructor(options: PaymentOptions, isBrowserInstance = true) {\n super(options)\n\n this.isBrowserInstance = isBrowserInstance\n this.initializeApi(options)\n }\n\n /**\n * Initializes the AI Query Protocol API.\n */\n private initializeApi(options: PaymentOptions) {\n this.plans = PlansAPI.getInstance(options)\n this.agents = AgentsAPI.getInstance(options)\n this.requests = AgentRequestsAPI.getInstance(options)\n this.observability = ObservabilityAPI.getInstance(options)\n this.organizations = OrganizationsAPI.getInstance(options)\n this.query = AIQueryApi.getInstance()\n this.contracts = new ContractsAPI(options)\n if (options.scheme === 'visa') {\n this.facilitator = VisaFacilitatorAPI.getInstance(options)\n this.x402 = VisaTokenAPI.getInstance(options)\n } else {\n this.facilitator = FacilitatorAPI.getInstance(options)\n this.x402 = X402TokenAPI.getInstance(options)\n }\n }\n\n /**\n * Initiates the connect flow. The user's browser will be redirected to\n * the Nevermined App login page.\n *\n * @remarks\n * This is a browser-only function.\n * @example\n * ```\n * payments.connect()\n * ```\n */\n public connect() {\n if (!this.isBrowserInstance) return\n const url = new URL(`/login?returnUrl=${this.returnUrl}`, this.environment.frontend)\n window.location.href = url.toString()\n }\n\n /**\n * Logs out the user by removing the NVM API key.\n *\n * @remarks\n * This is a browser-only function.\n * @example\n * ```\n * payments.logout()\n * ```\n */\n public logout() {\n this.nvmApiKey = ''\n }\n\n /**\n * Checks if a user is logged in.\n * @example\n * ```\n * payments.isLoggedIn\n * ```\n * @returns True if the user is logged in.\n */\n get isLoggedIn(): boolean {\n return this.nvmApiKey.length > 0\n }\n}\n"]}
1
+ {"version":3,"file":"payments.js","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAA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AI,CAAC,IAAI,CAAC,iBAAiB;YAAE,OAAM;QACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oBAAoB,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QACpF,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;IACvC,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM;QACX,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;IAClC,CAAC;;AAvID;;;GAGG;AACI,YAAG,GAAG,EAAE,qBAAqB,EAAE,CAAA","sourcesContent":["import { AIQueryApi } from './api/query-api.js'\nimport { PaymentsError } from './common/payments.error.js'\nimport { PaymentOptions } from './common/types.js'\nimport { BasePaymentsAPI } from './api/base-payments.js'\nimport { PlansAPI } from './api/plans-api.js'\nimport { ContractsAPI } from './api/contracts-api.js'\nimport { AgentsAPI } from './api/agents-api.js'\nimport { AgentRequestsAPI } from './api/requests-api.js'\nimport { ObservabilityAPI } from './api/observability-api/observability-api.js'\nimport { ClientRegistry } from './a2a/clientRegistry.js'\nimport type { PaymentsA2AServerOptions, PaymentsA2AServerResult } from './a2a/server.js'\nimport { PaymentsA2AServer } from './a2a/server.js'\nimport { buildPaymentAgentCard } from './a2a/agent-card.js'\nimport * as mcpModule from './mcp/index.js'\nimport { OrganizationsAPI } from './api/organizations-api/organizations-api.js'\nimport { FacilitatorAPI } from './x402/facilitator-api.js'\nimport { X402TokenAPI } from './x402/token.js'\nimport { DelegationAPI } from './x402/delegation-api.js'\n\n/**\n * Main class that interacts with the Nevermined payments API.\n * Use `Payments.getInstance` for server-side usage or `Payments.getBrowserInstance` for browser usage.\n * @remarks This API requires a Nevermined API Key, which can be obtained by logging in to the Nevermined App.\n *\n * The library provides methods to manage AI Agents, Plans & process AI Agent Requests.\n *\n * Each of these functionalities is encapsulated in its own API class:\n * - `plans`: Manages AI Plans, including registration and ordering and retrieving plan details.\n * - `agents`: Handles AI Agents, including registration of AI Agents and access token generation.\n * - `requests`: Manages requests received by AI Agents, including validation and tracking.\n * - `observability`: Provides observability and logging utilities for AI Agents with Helicone integration\n */\nexport class Payments extends BasePaymentsAPI {\n public query!: AIQueryApi\n public plans!: PlansAPI\n public agents!: AgentsAPI\n public requests!: AgentRequestsAPI\n public observability!: ObservabilityAPI\n public organizations!: OrganizationsAPI\n public contracts!: ContractsAPI\n public facilitator!: FacilitatorAPI\n public x402!: X402TokenAPI\n private _a2aRegistry?: ClientRegistry\n private _delegation?: DelegationAPI\n\n /**\n * Cached MCP integration to preserve configuration (e.g., agentId, serverName)\n * across multiple getter accesses. This ensures callers do not need to retain\n * a reference to a previously configured instance.\n */\n private _mcpIntegration?: ReturnType<typeof mcpModule.buildMcpIntegration>\n\n /**\n * Exposes A2A server and client registry methods.\n * The client registry is initialized only if getClient is called.\n */\n public get a2a() {\n return {\n /**\n * Starts the A2A server with payment integration.\n * @param options - Server options.\n */\n start: (\n options: Omit<PaymentsA2AServerOptions, 'paymentsService'>,\n ): PaymentsA2AServerResult => PaymentsA2AServer.start({ ...options, paymentsService: this }),\n\n /**\n * Gets (or creates) a RegisteredPaymentsClient for the given alias.\n * The registry is initialized only on first use.\n * @param options - ClientRegistryOptions.\n */\n getClient: async (options: any) => {\n if (!this._a2aRegistry) {\n this._a2aRegistry = new ClientRegistry(this)\n }\n return await this._a2aRegistry.getClient(options)\n },\n }\n }\n\n /**\n * Returns the MCP integration API. The instance is memoized so that configuration\n * set via `configure({ agentId, serverName })` persists across calls.\n */\n public get mcp() {\n if (!this._mcpIntegration) {\n this._mcpIntegration = mcpModule.buildMcpIntegration(this)\n }\n return this._mcpIntegration\n }\n\n /**\n * Returns the Delegation API for listing enrolled payment methods.\n * The instance is lazily initialized on first access.\n */\n public get delegation(): DelegationAPI {\n if (!this._delegation) {\n this._delegation = DelegationAPI.getInstance({\n nvmApiKey: this.nvmApiKey,\n environment: this.environmentName,\n })\n }\n return this._delegation\n }\n\n /**\n * Static A2A helpers and utilities.\n * Example: Payments.a2a.buildPaymentAgentCard(...)\n */\n static a2a = { buildPaymentAgentCard }\n\n /**\n * Get an instance of the Payments class for server-side usage.\n *\n * @param options - The options to initialize the payments class.\n * @example\n * ```\n * const payments = Payments.getInstance({\n * nvmApiKey: 'your-nvm-api-key',\n * environment: 'sandbox'\n * })\n * ```\n * @returns An instance of {@link Payments}\n * @throws PaymentsError if nvmApiKey is missing.\n */\n static getInstance(options: PaymentOptions) {\n if (!options.nvmApiKey) {\n throw new PaymentsError('Nevermined API Key is required')\n }\n return new Payments(options, false)\n }\n\n /**\n * Get an instance of the Payments class for browser usage.\n *\n * @remarks\n * This is a browser-only function.\n *\n * @param options - The options to initialize the payments class.\n * @example\n * ```\n * const payments = Payments.getBrowserInstance({\n * returnUrl: 'https://mysite.example',\n * environment: 'sandbox',\n * appId: 'my-app-id',\n * version: '1.0.0'\n * })\n * ```\n * @returns An instance of {@link Payments}\n * @throws PaymentsError if returnUrl is missing.\n */\n static getBrowserInstance(options: PaymentOptions) {\n if (!options.returnUrl) {\n throw new PaymentsError('returnUrl is required')\n }\n const url = new URL(window.location.href)\n const urlNvmApiKey = url.searchParams.get('nvmApiKey') as string\n if (urlNvmApiKey) {\n url.searchParams.delete('nvmApiKey')\n }\n\n const urlAccountAddress = url.searchParams.get('accountAddress') as string\n if (urlAccountAddress) {\n url.searchParams.delete('accountAddress')\n }\n\n history.replaceState(history.state, '', url.toString())\n\n return new Payments(options, true)\n }\n\n /**\n * Initializes the Payments class.\n *\n * @param options - The options to initialize the payments class.\n * @param isBrowserInstance - Whether this instance is for browser usage.\n */\n private constructor(options: PaymentOptions, isBrowserInstance = true) {\n super(options)\n\n this.isBrowserInstance = isBrowserInstance\n this.initializeApi(options)\n }\n\n /**\n * Initializes the AI Query Protocol API.\n */\n private initializeApi(options: PaymentOptions) {\n this.plans = PlansAPI.getInstance(options)\n this.agents = AgentsAPI.getInstance(options)\n this.requests = AgentRequestsAPI.getInstance(options)\n this.observability = ObservabilityAPI.getInstance(options)\n this.organizations = OrganizationsAPI.getInstance(options)\n this.query = AIQueryApi.getInstance()\n this.contracts = new ContractsAPI(options)\n this.facilitator = FacilitatorAPI.getInstance(options)\n this.x402 = X402TokenAPI.getInstance(options)\n }\n\n /**\n * Initiates the connect flow. The user's browser will be redirected to\n * the Nevermined App login page.\n *\n * @remarks\n * This is a browser-only function.\n * @example\n * ```\n * payments.connect()\n * ```\n */\n public connect() {\n if (!this.isBrowserInstance) return\n const url = new URL(`/login?returnUrl=${this.returnUrl}`, this.environment.frontend)\n window.location.href = url.toString()\n }\n\n /**\n * Logs out the user by removing the NVM API key.\n *\n * @remarks\n * This is a browser-only function.\n * @example\n * ```\n * payments.logout()\n * ```\n */\n public logout() {\n this.nvmApiKey = ''\n }\n\n /**\n * Checks if a user is logged in.\n * @example\n * ```\n * payments.isLoggedIn\n * ```\n * @returns True if the user is logged in.\n */\n get isLoggedIn(): boolean {\n return this.nvmApiKey.length > 0\n }\n}\n"]}
package/dist/plans.d.ts CHANGED
@@ -1,11 +1,22 @@
1
- import { Address, PlanCreditsConfig, PlanPriceConfig, PlanRedemptionType } from './common/types.js';
1
+ import { Address, Currency, PlanCreditsConfig, PlanPriceConfig, PlanRedemptionType } from './common/types.js';
2
2
  export declare const ONE_DAY_DURATION = 86400n;
3
3
  export declare const ONE_WEEK_DURATION = 604800n;
4
4
  export declare const ONE_MONTH_DURATION = 2629746n;
5
5
  export declare const ONE_YEAR_DURATION = 31557600n;
6
- export declare const getFiatPriceConfig: (amount: bigint, receiver: Address) => PlanPriceConfig;
6
+ export declare const getFiatPriceConfig: (amount: bigint, receiver: Address, currency?: Currency | string) => PlanPriceConfig;
7
7
  export declare const getCryptoPriceConfig: (amount: bigint, receiver: Address, tokenAddress?: Address) => PlanPriceConfig;
8
8
  export declare const getERC20PriceConfig: (amount: bigint, tokenAddress: Address, receiver: Address) => PlanPriceConfig;
9
+ /**
10
+ * Builds a price configuration for EURC (Euro stablecoin) payments.
11
+ *
12
+ * EURC uses 6 decimal places. To charge €29.00, pass `29_000_000n`.
13
+ *
14
+ * @param amount - Amount in the token's smallest unit (6 decimals for EURC).
15
+ * @param receiver - Wallet address that will receive the payment.
16
+ * @param eurcAddress - Optional EURC token address. Defaults to Base Mainnet EURC.
17
+ * @returns The PlanPriceConfig representing an EURC price.
18
+ */
19
+ export declare const getEURCPriceConfig: (amount: bigint, receiver: Address, eurcAddress?: Address) => PlanPriceConfig;
9
20
  export declare const getFreePriceConfig: () => PlanPriceConfig;
10
21
  export declare const getNativeTokenPriceConfig: (amount: bigint, receiver: Address) => PlanPriceConfig;
11
22
  export declare const getExpirableDurationConfig: (durationOfPlan: bigint) => PlanCreditsConfig;
@@ -13,7 +24,7 @@ export declare const getNonExpirableDurationConfig: () => PlanCreditsConfig;
13
24
  export declare const getFixedCreditsConfig: (creditsGranted: bigint, creditsPerRequest?: bigint) => PlanCreditsConfig;
14
25
  export declare const getDynamicCreditsConfig: (creditsGranted: bigint, minCreditsPerRequest?: bigint, maxCreditsPerRequest?: bigint) => PlanCreditsConfig;
15
26
  export declare const setRedemptionType: (creditsConfig: PlanCreditsConfig, redemptionType: PlanRedemptionType) => PlanCreditsConfig;
16
- export declare const setProofRequired: (creditsConfig: PlanCreditsConfig, proofRequired?: boolean) => PlanCreditsConfig;
27
+ export declare const setOnchainMirror: (creditsConfig: PlanCreditsConfig, onchainMirror?: boolean) => PlanCreditsConfig;
17
28
  /**
18
29
  * Build a pay-as-you-go price configuration.
19
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAInG,eAAO,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,eAAO,MAAM,gBAAgB,GAC3B,eAAe,iBAAiB,EAChC,uBAAoB,KACnB,iBAKF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,EACd,UAAU,OAAO,EACjB,eAAc,OAAqB,EACnC,kBAAkB,OAAO,KACxB,eAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAAO,iBAU7C,CAAA"}
package/dist/plans.js CHANGED
@@ -1,11 +1,11 @@
1
- import { PlanRedemptionType } from './common/types.js';
1
+ import { Currency, EURC_TOKEN_ADDRESS, PlanRedemptionType, } from './common/types.js';
2
2
  import { ZeroAddress } from './environments.js';
3
3
  import { isEthereumAddress } from './utils.js';
4
4
  export const ONE_DAY_DURATION = 86400n; // 24 * 60 * 60 seconds
5
5
  export const ONE_WEEK_DURATION = 604800n; // 7 * 24 * 60 * 60 seconds
6
6
  export const ONE_MONTH_DURATION = 2629746n; // (365.25 days/year ÷ 12 months/year) × 24 × 60 × 60 ≈ 2,629,746 seconds
7
7
  export const ONE_YEAR_DURATION = 31557600n; // 365.25 * 24 * 60 * 60 seconds
8
- export const getFiatPriceConfig = (amount, receiver) => {
8
+ export const getFiatPriceConfig = (amount, receiver, currency = Currency.USD) => {
9
9
  if (!isEthereumAddress(receiver))
10
10
  throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`);
11
11
  return {
@@ -17,6 +17,7 @@ export const getFiatPriceConfig = (amount, receiver) => {
17
17
  externalPriceAddress: ZeroAddress,
18
18
  templateAddress: ZeroAddress,
19
19
  isCrypto: false,
20
+ currency,
20
21
  };
21
22
  };
22
23
  export const getCryptoPriceConfig = (amount, receiver, tokenAddress = ZeroAddress) => {
@@ -36,6 +37,22 @@ export const getCryptoPriceConfig = (amount, receiver, tokenAddress = ZeroAddres
36
37
  export const getERC20PriceConfig = (amount, tokenAddress, receiver) => {
37
38
  return getCryptoPriceConfig(amount, receiver, tokenAddress);
38
39
  };
40
+ /**
41
+ * Builds a price configuration for EURC (Euro stablecoin) payments.
42
+ *
43
+ * EURC uses 6 decimal places. To charge €29.00, pass `29_000_000n`.
44
+ *
45
+ * @param amount - Amount in the token's smallest unit (6 decimals for EURC).
46
+ * @param receiver - Wallet address that will receive the payment.
47
+ * @param eurcAddress - Optional EURC token address. Defaults to Base Mainnet EURC.
48
+ * @returns The PlanPriceConfig representing an EURC price.
49
+ */
50
+ export const getEURCPriceConfig = (amount, receiver, eurcAddress = EURC_TOKEN_ADDRESS) => {
51
+ return {
52
+ ...getERC20PriceConfig(amount, eurcAddress, receiver),
53
+ currency: Currency.EURC,
54
+ };
55
+ };
39
56
  export const getFreePriceConfig = () => {
40
57
  return {
41
58
  tokenAddress: ZeroAddress,
@@ -55,7 +72,7 @@ export const getExpirableDurationConfig = (durationOfPlan) => {
55
72
  return {
56
73
  isRedemptionAmountFixed: false,
57
74
  redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,
58
- proofRequired: false,
75
+ onchainMirror: false,
59
76
  durationSecs: durationOfPlan,
60
77
  amount: 1n,
61
78
  minAmount: 1n,
@@ -69,7 +86,7 @@ export const getFixedCreditsConfig = (creditsGranted, creditsPerRequest = 1n) =>
69
86
  return {
70
87
  isRedemptionAmountFixed: true,
71
88
  redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,
72
- proofRequired: false,
89
+ onchainMirror: false,
73
90
  durationSecs: 0n,
74
91
  amount: creditsGranted,
75
92
  minAmount: creditsPerRequest,
@@ -80,7 +97,7 @@ export const getDynamicCreditsConfig = (creditsGranted, minCreditsPerRequest = 1
80
97
  return {
81
98
  isRedemptionAmountFixed: false,
82
99
  redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,
83
- proofRequired: false,
100
+ onchainMirror: false,
84
101
  durationSecs: 0n,
85
102
  amount: creditsGranted,
86
103
  minAmount: minCreditsPerRequest,
@@ -93,10 +110,10 @@ export const setRedemptionType = (creditsConfig, redemptionType) => {
93
110
  redemptionType,
94
111
  };
95
112
  };
96
- export const setProofRequired = (creditsConfig, proofRequired = true) => {
113
+ export const setOnchainMirror = (creditsConfig, onchainMirror = true) => {
97
114
  return {
98
115
  ...creditsConfig,
99
- proofRequired,
116
+ onchainMirror,
100
117
  };
101
118
  };
102
119
  /**
@@ -130,7 +147,7 @@ export const getPayAsYouGoCreditsConfig = () => {
130
147
  return {
131
148
  isRedemptionAmountFixed: false,
132
149
  redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,
133
- proofRequired: false,
150
+ onchainMirror: false,
134
151
  durationSecs: 0n,
135
152
  amount: 1n,
136
153
  minAmount: 1n,
package/dist/plans.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plans.js","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAO,CAAA,CAAC,uBAAuB;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAQ,CAAA,CAAC,2BAA2B;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAU,CAAA,CAAC,yEAAyE;AACtH,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAW,CAAA,CAAC,gCAAgC;AAE7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,QAAiB,EAAmB,EAAE;IACvF,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,kCAAkC,CAAC,CAAA;IACjF,OAAO;QACL,YAAY,EAAE,WAAW;QACzB,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,eAAe,EAAE,WAAW;QAC5B,aAAa,EAAE,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ChC,aAAa,GAAG,IAAI,EACD,EAAE;IACrB,OAAO;QACL,GAAG,aAAa;QAChB,aAAa;KACd,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,MAAc,EACd,QAAiB,EACjB,eAAwB,WAAW,EACnC,eAAyB,EACR,EAAE;IACnB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,kCAAkC,CAAC,CAAA;IAEjF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAA;IACH,CAAC;IAED,OAAO;QACL,YAAY;QACZ,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,eAAe,EAAE,WAAW;QAC5B,aAAa,EAAE,WAAW;QAC1B,oBAAoB,EAAE,WAAW;QACjC,eAAe;QACf,QAAQ,EAAE,IAAI;KACf,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAsB,EAAE;IAChE,OAAO;QACL,uBAAuB,EAAE,KAAK;QAC9B,cAAc,EAAE,kBAAkB,CAAC,eAAe;QAClD,aAAa,EAAE,KAAK;QACpB,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QACV,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;KACd,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { Address, PlanCreditsConfig, PlanPriceConfig, PlanRedemptionType } from './common/types.js'\nimport { ZeroAddress } from './environments.js'\nimport { isEthereumAddress } from './utils.js'\n\nexport const ONE_DAY_DURATION = 86_400n // 24 * 60 * 60 seconds\nexport const ONE_WEEK_DURATION = 604_800n // 7 * 24 * 60 * 60 seconds\nexport const ONE_MONTH_DURATION = 2_629_746n // (365.25 days/year ÷ 12 months/year) × 24 × 60 × 60 ≈ 2,629,746 seconds\nexport const ONE_YEAR_DURATION = 31_557_600n // 365.25 * 24 * 60 * 60 seconds\n\nexport const getFiatPriceConfig = (amount: bigint, receiver: Address): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n return {\n tokenAddress: ZeroAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: false,\n }\n}\n\nexport const getCryptoPriceConfig = (\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n return {\n tokenAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: true,\n }\n}\n\nexport const getERC20PriceConfig = (\n amount: bigint,\n tokenAddress: Address,\n receiver: Address,\n): PlanPriceConfig => {\n return getCryptoPriceConfig(amount, receiver, tokenAddress)\n}\n\nexport const getFreePriceConfig = (): PlanPriceConfig => {\n return {\n tokenAddress: ZeroAddress,\n amounts: [],\n receivers: [],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: true,\n }\n}\n\nexport const getNativeTokenPriceConfig = (amount: bigint, receiver: Address): PlanPriceConfig => {\n return getCryptoPriceConfig(amount, receiver, ZeroAddress)\n}\n\nexport const getExpirableDurationConfig = (durationOfPlan: bigint): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n proofRequired: false,\n durationSecs: durationOfPlan,\n amount: 1n,\n minAmount: 1n,\n maxAmount: 1n,\n }\n}\n\nexport const getNonExpirableDurationConfig = (): PlanCreditsConfig => {\n return getExpirableDurationConfig(0n)\n}\n\nexport const getFixedCreditsConfig = (\n creditsGranted: bigint,\n creditsPerRequest = 1n,\n): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: true,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n proofRequired: false,\n durationSecs: 0n,\n amount: creditsGranted,\n minAmount: creditsPerRequest,\n maxAmount: creditsPerRequest,\n }\n}\n\nexport const getDynamicCreditsConfig = (\n creditsGranted: bigint,\n minCreditsPerRequest = 1n,\n maxCreditsPerRequest = 1n,\n): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n proofRequired: false,\n durationSecs: 0n,\n amount: creditsGranted,\n minAmount: minCreditsPerRequest,\n maxAmount: maxCreditsPerRequest,\n }\n}\n\nexport const setRedemptionType = (\n creditsConfig: PlanCreditsConfig,\n redemptionType: PlanRedemptionType,\n): PlanCreditsConfig => {\n return {\n ...creditsConfig,\n redemptionType,\n }\n}\n\nexport const setProofRequired = (\n creditsConfig: PlanCreditsConfig,\n proofRequired = true,\n): PlanCreditsConfig => {\n return {\n ...creditsConfig,\n proofRequired,\n }\n}\n\n/**\n * Build a pay-as-you-go price configuration.\n *\n * For pay-as-you-go plans, the template address must come from the API deployment info.\n */\nexport const getPayAsYouGoPriceConfig = (\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n templateAddress?: Address,\n): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n\n if (!templateAddress) {\n throw new Error(\n 'templateAddress is required. Use ContractsAPI.getPayAsYouGoTemplateAddress() or Payments.plans.getPayAsYouGoPriceConfig()',\n )\n }\n\n return {\n tokenAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress,\n isCrypto: true,\n }\n}\n\n/**\n * Build a pay-as-you-go credits configuration.\n *\n * Credits are not minted upfront; these values are required for validation only.\n */\nexport const getPayAsYouGoCreditsConfig = (): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n proofRequired: false,\n durationSecs: 0n,\n amount: 1n,\n minAmount: 1n,\n maxAmount: 1n,\n }\n}\n"]}
1
+ {"version":3,"file":"plans.js","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,kBAAkB,EAGlB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAO,CAAA,CAAC,uBAAuB;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAQ,CAAA,CAAC,2BAA2B;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAU,CAAA,CAAC,yEAAyE;AACtH,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAW,CAAA,CAAC,gCAAgC;AAE7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAc,EACd,QAAiB,EACjB,WAA8B,QAAQ,CAAC,GAAG,EACzB,EAAE;IACnB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,kCAAkC,CAAC,CAAA;IACjF,OAAO;QACL,YAAY,EAAE,WAAW;QACzB,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,eAAe,EAAE,WAAW;QAC5B,aAAa,EAAE,WAAW;QAC1B,oBAAoB,EAAE,WAAW;QACjC,eAAe,EAAE,WAAW;QAC5B,QAAQ,EAAE,KAAK;QACf,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M,iBAAiB,GAAG,CAC/B,aAAgC,EAChC,cAAkC,EACf,EAAE;IACrB,OAAO;QACL,GAAG,aAAa;QAChB,cAAc;KACf,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,aAAgC,EAChC,aAAa,GAAG,IAAI,EACD,EAAE;IACrB,OAAO;QACL,GAAG,aAAa;QAChB,aAAa;KACd,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,MAAc,EACd,QAAiB,EACjB,eAAwB,WAAW,EACnC,eAAyB,EACR,EAAE;IACnB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,kCAAkC,CAAC,CAAA;IAEjF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAA;IACH,CAAC;IAED,OAAO;QACL,YAAY;QACZ,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,eAAe,EAAE,WAAW;QAC5B,aAAa,EAAE,WAAW;QAC1B,oBAAoB,EAAE,WAAW;QACjC,eAAe;QACf,QAAQ,EAAE,IAAI;KACf,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAsB,EAAE;IAChE,OAAO;QACL,uBAAuB,EAAE,KAAK;QAC9B,cAAc,EAAE,kBAAkB,CAAC,eAAe;QAClD,aAAa,EAAE,KAAK;QACpB,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QACV,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;KACd,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {\n Address,\n Currency,\n EURC_TOKEN_ADDRESS,\n PlanCreditsConfig,\n PlanPriceConfig,\n PlanRedemptionType,\n} from './common/types.js'\nimport { ZeroAddress } from './environments.js'\nimport { isEthereumAddress } from './utils.js'\n\nexport const ONE_DAY_DURATION = 86_400n // 24 * 60 * 60 seconds\nexport const ONE_WEEK_DURATION = 604_800n // 7 * 24 * 60 * 60 seconds\nexport const ONE_MONTH_DURATION = 2_629_746n // (365.25 days/year ÷ 12 months/year) × 24 × 60 × 60 ≈ 2,629,746 seconds\nexport const ONE_YEAR_DURATION = 31_557_600n // 365.25 * 24 * 60 * 60 seconds\n\nexport const getFiatPriceConfig = (\n amount: bigint,\n receiver: Address,\n currency: Currency | string = Currency.USD,\n): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n return {\n tokenAddress: ZeroAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: false,\n currency,\n }\n}\n\nexport const getCryptoPriceConfig = (\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n return {\n tokenAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: true,\n }\n}\n\nexport const getERC20PriceConfig = (\n amount: bigint,\n tokenAddress: Address,\n receiver: Address,\n): PlanPriceConfig => {\n return getCryptoPriceConfig(amount, receiver, tokenAddress)\n}\n\n/**\n * Builds a price configuration for EURC (Euro stablecoin) payments.\n *\n * EURC uses 6 decimal places. To charge €29.00, pass `29_000_000n`.\n *\n * @param amount - Amount in the token's smallest unit (6 decimals for EURC).\n * @param receiver - Wallet address that will receive the payment.\n * @param eurcAddress - Optional EURC token address. Defaults to Base Mainnet EURC.\n * @returns The PlanPriceConfig representing an EURC price.\n */\nexport const getEURCPriceConfig = (\n amount: bigint,\n receiver: Address,\n eurcAddress: Address = EURC_TOKEN_ADDRESS,\n): PlanPriceConfig => {\n return {\n ...getERC20PriceConfig(amount, eurcAddress, receiver),\n currency: Currency.EURC,\n }\n}\n\nexport const getFreePriceConfig = (): PlanPriceConfig => {\n return {\n tokenAddress: ZeroAddress,\n amounts: [],\n receivers: [],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress: ZeroAddress,\n isCrypto: true,\n }\n}\n\nexport const getNativeTokenPriceConfig = (amount: bigint, receiver: Address): PlanPriceConfig => {\n return getCryptoPriceConfig(amount, receiver, ZeroAddress)\n}\n\nexport const getExpirableDurationConfig = (durationOfPlan: bigint): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n onchainMirror: false,\n durationSecs: durationOfPlan,\n amount: 1n,\n minAmount: 1n,\n maxAmount: 1n,\n }\n}\n\nexport const getNonExpirableDurationConfig = (): PlanCreditsConfig => {\n return getExpirableDurationConfig(0n)\n}\n\nexport const getFixedCreditsConfig = (\n creditsGranted: bigint,\n creditsPerRequest = 1n,\n): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: true,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n onchainMirror: false,\n durationSecs: 0n,\n amount: creditsGranted,\n minAmount: creditsPerRequest,\n maxAmount: creditsPerRequest,\n }\n}\n\nexport const getDynamicCreditsConfig = (\n creditsGranted: bigint,\n minCreditsPerRequest = 1n,\n maxCreditsPerRequest = 1n,\n): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n onchainMirror: false,\n durationSecs: 0n,\n amount: creditsGranted,\n minAmount: minCreditsPerRequest,\n maxAmount: maxCreditsPerRequest,\n }\n}\n\nexport const setRedemptionType = (\n creditsConfig: PlanCreditsConfig,\n redemptionType: PlanRedemptionType,\n): PlanCreditsConfig => {\n return {\n ...creditsConfig,\n redemptionType,\n }\n}\n\nexport const setOnchainMirror = (\n creditsConfig: PlanCreditsConfig,\n onchainMirror = true,\n): PlanCreditsConfig => {\n return {\n ...creditsConfig,\n onchainMirror,\n }\n}\n\n/**\n * Build a pay-as-you-go price configuration.\n *\n * For pay-as-you-go plans, the template address must come from the API deployment info.\n */\nexport const getPayAsYouGoPriceConfig = (\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n templateAddress?: Address,\n): PlanPriceConfig => {\n if (!isEthereumAddress(receiver))\n throw new Error(`Receiver address ${receiver} is not a valid Ethereum address`)\n\n if (!templateAddress) {\n throw new Error(\n 'templateAddress is required. Use ContractsAPI.getPayAsYouGoTemplateAddress() or Payments.plans.getPayAsYouGoPriceConfig()',\n )\n }\n\n return {\n tokenAddress,\n amounts: [amount],\n receivers: [receiver],\n contractAddress: ZeroAddress,\n feeController: ZeroAddress,\n externalPriceAddress: ZeroAddress,\n templateAddress,\n isCrypto: true,\n }\n}\n\n/**\n * Build a pay-as-you-go credits configuration.\n *\n * Credits are not minted upfront; these values are required for validation only.\n */\nexport const getPayAsYouGoCreditsConfig = (): PlanCreditsConfig => {\n return {\n isRedemptionAmountFixed: false,\n redemptionType: PlanRedemptionType.ONLY_SUBSCRIBER,\n onchainMirror: false,\n durationSecs: 0n,\n amount: 1n,\n minAmount: 1n,\n maxAmount: 1n,\n }\n}\n"]}
@@ -1,43 +1,143 @@
1
1
  /**
2
- * Delegation API for managing card-delegation payment methods.
2
+ * Delegation API for managing payment delegations (crypto and card schemes).
3
3
  *
4
- * Provides access to the user's enrolled Stripe payment methods
5
- * for use with the nvm:card-delegation x402 scheme.
4
+ * Provides access to the user's enrolled payment methods and delegations
5
+ * for use with the nvm:erc4337 and nvm:card-delegation x402 schemes.
6
6
  */
7
7
  import { BasePaymentsAPI } from '../api/base-payments.js';
8
- import { PaymentOptions } from '../common/types.js';
8
+ import { CreateDelegationPayload, CreateDelegationResponse, PaymentOptions } from '../common/types.js';
9
+ /**
10
+ * Card-delegation providers exposed by the SDK. Use this when you want to
11
+ * restrict to card-shape entries only (e.g., filtering the heterogeneous
12
+ * list returned by {@link DelegationAPI.listPaymentMethods}).
13
+ */
14
+ export type CardProvider = 'stripe' | 'braintree' | 'visa';
15
+ /**
16
+ * All delegation providers, including the crypto path. Matches the
17
+ * server-side union and aligns with {@link CreateDelegationPayload.provider}.
18
+ */
19
+ export type DelegationProvider = CardProvider | 'erc4337';
9
20
  /**
10
21
  * Summary of a user's enrolled payment method.
22
+ *
23
+ * The list returned by {@link DelegationAPI.listPaymentMethods} is
24
+ * heterogeneous: it includes enrolled cards (`provider` in
25
+ * `stripe` / `braintree` / `visa`) AND, when the user has a smart account
26
+ * configured, an entry for the user's ERC-4337 wallet
27
+ * (`provider: 'erc4337'`, `type: 'crypto_wallet'`, `brand: 'ethereum'`).
28
+ * Filter on `provider` when callers only want one shape.
11
29
  */
12
30
  export interface PaymentMethodSummary {
13
- /** Payment method ID (e.g., 'pm_...') */
31
+ /** Payment method ID (Stripe 'pm_...', Braintree vault token, Visa Agentic
32
+ * token id, or — for the erc4337 entry — the smart-account address) */
14
33
  id: string;
15
- /** Card brand (e.g., 'visa', 'mastercard') */
34
+ /** Payment method type ('card' | 'crypto_wallet' | 'paypal' | …) */
35
+ type: string;
36
+ /** Card brand (e.g., 'visa', 'mastercard'), 'ethereum' for the erc4337
37
+ * entry, or payment method type ('paypal', 'venmo') */
16
38
  brand: string;
17
- /** Last 4 digits of the card number */
39
+ /** Last 4 digits (cards), trailing 4 chars of the wallet address
40
+ * (erc4337), or email/username (PayPal/Venmo) */
18
41
  last4: string;
19
- /** Card expiration month */
42
+ /** Expiration month (0 for non-card methods) */
20
43
  expMonth: number;
21
- /** Card expiration year */
44
+ /** Expiration year (0 for non-card methods) */
22
45
  expYear: number;
46
+ /** Human-readable alias, if set */
47
+ alias?: string | null;
48
+ /** One of 'stripe' | 'braintree' | 'visa' | 'erc4337' */
49
+ provider?: DelegationProvider;
50
+ /** Current status ('Active' or 'Revoked') */
51
+ status?: string;
52
+ /** NVM API Key IDs allowed to use this payment method, or null if unrestricted */
53
+ allowedApiKeyIds?: string[] | null;
54
+ }
55
+ /**
56
+ * Summary of a delegation (card or crypto spending).
57
+ */
58
+ export interface DelegationSummary {
59
+ delegationId: string;
60
+ provider: string;
61
+ providerPaymentMethodId: string;
62
+ status: string;
63
+ spendingLimitCents: string;
64
+ amountSpentCents: string;
65
+ remainingBudgetCents: string;
66
+ currency: string;
67
+ transactionCount: number;
68
+ expiresAt: string;
69
+ createdAt: string;
70
+ apiKeyId: string | null;
71
+ }
72
+ /**
73
+ * Paginated list of delegations returned by the API.
74
+ */
75
+ export interface DelegationListResponse {
76
+ delegations: DelegationSummary[];
77
+ totalResults: number;
78
+ page: number;
79
+ offset: number;
80
+ }
81
+ /**
82
+ * Summary of an agent's purchasing power via card delegations.
83
+ */
84
+ export interface PurchasingPower {
85
+ cards: PaymentMethodSummary[];
86
+ delegations: DelegationSummary[];
87
+ totalRemainingBudgetCents: number;
88
+ currency: string;
89
+ }
90
+ /**
91
+ * DTO for updating a payment method's alias and allowed API keys.
92
+ */
93
+ export interface UpdatePaymentMethodDto {
94
+ alias?: string;
95
+ allowedApiKeyIds?: string[] | null;
96
+ }
97
+ /**
98
+ * Options for listing payment methods or delegations.
99
+ */
100
+ export interface ListOptions {
101
+ /** When true, return only items accessible to the requesting API key */
102
+ accessible?: boolean;
23
103
  }
24
104
  /**
25
- * API for listing enrolled payment methods for card delegation.
105
+ * API for managing payment methods and delegations (card and crypto).
26
106
  */
27
107
  export declare class DelegationAPI extends BasePaymentsAPI {
28
- /**
29
- * Get an instance of the DelegationAPI class.
30
- *
31
- * @param options - The options to initialize the API
32
- * @returns The instance of the DelegationAPI class
33
- */
34
108
  static getInstance(options: PaymentOptions): DelegationAPI;
35
109
  /**
36
110
  * List the user's enrolled payment methods for card delegation.
111
+ * When `accessible: true`, only cards accessible to the requesting API key are returned.
112
+ */
113
+ listPaymentMethods(options?: ListOptions): Promise<PaymentMethodSummary[]>;
114
+ /**
115
+ * List the user's existing delegations.
116
+ * When `accessible: true`, only usable delegations (Active, non-expired, with budget) are returned.
117
+ */
118
+ listDelegations(options?: ListOptions): Promise<DelegationListResponse>;
119
+ /**
120
+ * Get the agent's purchasing power — accessible cards, active delegations,
121
+ * and combined remaining budget.
122
+ */
123
+ getPurchasingPower(): Promise<PurchasingPower>;
124
+ /**
125
+ * Create a new delegation for any supported provider (stripe, braintree,
126
+ * visa, or erc4337).
127
+ *
128
+ * Note: Visa delegations require a per-delegation device-binding ceremony
129
+ * (FIDO/passkey + assuranceData) that must be performed in the browser
130
+ * via the Nevermined webapp. The SDK can list and consume an already-
131
+ * created Visa delegation but cannot create one programmatically.
37
132
  *
38
- * @returns A promise that resolves to an array of payment method summaries
39
- * @throws PaymentsError if the request fails
133
+ * @param payload - The delegation creation parameters
134
+ * @returns The created delegation ID (and token for card delegations)
135
+ */
136
+ createDelegation(payload: CreateDelegationPayload): Promise<CreateDelegationResponse>;
137
+ /**
138
+ * Update a payment method's alias and/or allowed API keys.
40
139
  */
41
- listPaymentMethods(): Promise<PaymentMethodSummary[]>;
140
+ updatePaymentMethod(paymentMethodId: string, dto: UpdatePaymentMethodDto): Promise<PaymentMethodSummary>;
141
+ private fetchJSON;
42
142
  }
43
143
  //# sourceMappingURL=delegation-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delegation-api.d.ts","sourceRoot":"","sources":["../../src/x402/delegation-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAA;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CAAC,oBAAoB,EAAE,CAAC;IAMhF;;;OAGG;IACG,eAAe,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAM7E;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAoBpD;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAK3F;;OAEG;IACG,mBAAmB,CACvB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,sBAAsB,GAC1B,OAAO,CAAC,oBAAoB,CAAC;YAOlB,SAAS;CAyBxB"}
@@ -1,53 +1,107 @@
1
1
  /**
2
- * Delegation API for managing card-delegation payment methods.
2
+ * Delegation API for managing payment delegations (crypto and card schemes).
3
3
  *
4
- * Provides access to the user's enrolled Stripe payment methods
5
- * for use with the nvm:card-delegation x402 scheme.
4
+ * Provides access to the user's enrolled payment methods and delegations
5
+ * for use with the nvm:erc4337 and nvm:card-delegation x402 schemes.
6
6
  */
7
7
  import { BasePaymentsAPI } from '../api/base-payments.js';
8
8
  import { PaymentsError } from '../common/payments.error.js';
9
9
  /**
10
- * API for listing enrolled payment methods for card delegation.
10
+ * API for managing payment methods and delegations (card and crypto).
11
11
  */
12
12
  export class DelegationAPI extends BasePaymentsAPI {
13
- /**
14
- * Get an instance of the DelegationAPI class.
15
- *
16
- * @param options - The options to initialize the API
17
- * @returns The instance of the DelegationAPI class
18
- */
19
13
  static getInstance(options) {
20
14
  return new DelegationAPI(options);
21
15
  }
22
16
  /**
23
17
  * List the user's enrolled payment methods for card delegation.
18
+ * When `accessible: true`, only cards accessible to the requesting API key are returned.
19
+ */
20
+ async listPaymentMethods(options) {
21
+ const url = new URL('/api/v1/payment-methods', this.environment.backend);
22
+ if (options?.accessible)
23
+ url.searchParams.set('accessible', 'true');
24
+ return this.fetchJSON(url, 'GET', 'list payment methods');
25
+ }
26
+ /**
27
+ * List the user's existing delegations.
28
+ * When `accessible: true`, only usable delegations (Active, non-expired, with budget) are returned.
29
+ */
30
+ async listDelegations(options) {
31
+ const url = new URL('/api/v1/delegation', this.environment.backend);
32
+ if (options?.accessible)
33
+ url.searchParams.set('accessible', 'true');
34
+ return this.fetchJSON(url, 'GET', 'list delegations');
35
+ }
36
+ /**
37
+ * Get the agent's purchasing power — accessible cards, active delegations,
38
+ * and combined remaining budget.
39
+ */
40
+ async getPurchasingPower() {
41
+ const accessible = { accessible: true };
42
+ const [cards, { delegations }] = await Promise.all([
43
+ this.listPaymentMethods(accessible),
44
+ this.listDelegations(accessible),
45
+ ]);
46
+ const totalRemainingBudgetCents = delegations.reduce((sum, d) => sum + (parseInt(d.remainingBudgetCents, 10) || 0), 0);
47
+ return {
48
+ cards,
49
+ delegations,
50
+ totalRemainingBudgetCents,
51
+ currency: delegations[0]?.currency ?? 'usd',
52
+ };
53
+ }
54
+ /**
55
+ * Create a new delegation for any supported provider (stripe, braintree,
56
+ * visa, or erc4337).
24
57
  *
25
- * @returns A promise that resolves to an array of payment method summaries
26
- * @throws PaymentsError if the request fails
58
+ * Note: Visa delegations require a per-delegation device-binding ceremony
59
+ * (FIDO/passkey + assuranceData) that must be performed in the browser
60
+ * via the Nevermined webapp. The SDK can list and consume an already-
61
+ * created Visa delegation but cannot create one programmatically.
62
+ *
63
+ * @param payload - The delegation creation parameters
64
+ * @returns The created delegation ID (and token for card delegations)
27
65
  */
28
- async listPaymentMethods() {
29
- const url = new URL('/api/v1/delegation/payment-methods', this.environment.backend);
30
- const options = this.getBackendHTTPOptions('GET');
66
+ async createDelegation(payload) {
67
+ const url = new URL('/api/v1/delegation/create', this.environment.backend);
68
+ return this.fetchJSON(url, 'POST', 'create delegation', payload);
69
+ }
70
+ /**
71
+ * Update a payment method's alias and/or allowed API keys.
72
+ */
73
+ async updatePaymentMethod(paymentMethodId, dto) {
74
+ const url = new URL(`/api/v1/payment-methods/${paymentMethodId}`, this.environment.backend);
75
+ return this.fetchJSON(url, 'PATCH', 'update payment method', dto);
76
+ }
77
+ // --- Private helpers ---
78
+ async fetchJSON(url, method, action, body) {
79
+ const options = this.getBackendHTTPOptions(method, body);
31
80
  try {
32
81
  const response = await fetch(url, options);
33
82
  if (!response.ok) {
34
- let errorMessage = 'Failed to list payment methods';
83
+ let msg = `Failed to ${action}`;
84
+ let code = `http_${response.status}`;
35
85
  try {
36
- const errorData = await response.json();
37
- errorMessage = errorData.message || errorMessage;
86
+ const err = await response.json();
87
+ if (err.message)
88
+ msg = err.message;
89
+ if (err.code)
90
+ code = err.code;
91
+ if (err.hint)
92
+ msg = `${msg} — ${err.hint}`;
38
93
  }
39
94
  catch {
40
- // Use default error message
95
+ // use default
41
96
  }
42
- throw PaymentsError.internal(`${errorMessage} (HTTP ${response.status})`);
97
+ throw new PaymentsError(`${msg} (HTTP ${response.status})`, code);
43
98
  }
44
99
  return await response.json();
45
100
  }
46
101
  catch (error) {
47
- if (error instanceof PaymentsError) {
102
+ if (error instanceof PaymentsError)
48
103
  throw error;
49
- }
50
- throw PaymentsError.internal(`Network error while listing payment methods: ${error instanceof Error ? error.message : String(error)}`);
104
+ throw PaymentsError.internal(`Network error while ${action}: ${error instanceof Error ? error.message : String(error)}`);
51
105
  }
52
106
  }
53
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"delegation-api.js","sourceRoot":"","sources":["../../src/x402/delegation-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAmB3D;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,eAAe;IAChD;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,kBAAkB;QACtB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oCAAoC,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QACnF,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;QAEjD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,IAAI,YAAY,GAAG,gCAAgC,CAAA;gBACnD,IAAI,CAAC;oBACH,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;oBACvC,YAAY,GAAG,SAAS,CAAC,OAAO,IAAI,YAAY,CAAA;gBAClD,CAAC;gBAAC,MAAM,CAAC;oBACP,4BAA4B;gBAC9B,CAAC;gBACD,MAAM,aAAa,CAAC,QAAQ,CAAC,GAAG,YAAY,UAAU,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAA;YAC3E,CAAC;YACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;gBACnC,MAAM,KAAK,CAAA;YACb,CAAC;YACD,MAAM,aAAa,CAAC,QAAQ,CAC1B,gDAAgD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACzG,CAAA;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Delegation API for managing card-delegation payment methods.\n *\n * Provides access to the user's enrolled Stripe payment methods\n * for use with the nvm:card-delegation x402 scheme.\n */\n\nimport { BasePaymentsAPI } from '../api/base-payments.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions } from '../common/types.js'\n\n/**\n * Summary of a user's enrolled payment method.\n */\nexport interface PaymentMethodSummary {\n /** Payment method ID (e.g., 'pm_...') */\n id: string\n /** Card brand (e.g., 'visa', 'mastercard') */\n brand: string\n /** Last 4 digits of the card number */\n last4: string\n /** Card expiration month */\n expMonth: number\n /** Card expiration year */\n expYear: number\n}\n\n/**\n * API for listing enrolled payment methods for card delegation.\n */\nexport class DelegationAPI extends BasePaymentsAPI {\n /**\n * Get an instance of the DelegationAPI class.\n *\n * @param options - The options to initialize the API\n * @returns The instance of the DelegationAPI class\n */\n static getInstance(options: PaymentOptions): DelegationAPI {\n return new DelegationAPI(options)\n }\n\n /**\n * List the user's enrolled payment methods for card delegation.\n *\n * @returns A promise that resolves to an array of payment method summaries\n * @throws PaymentsError if the request fails\n */\n async listPaymentMethods(): Promise<PaymentMethodSummary[]> {\n const url = new URL('/api/v1/delegation/payment-methods', this.environment.backend)\n const options = this.getBackendHTTPOptions('GET')\n\n try {\n const response = await fetch(url, options)\n if (!response.ok) {\n let errorMessage = 'Failed to list payment methods'\n try {\n const errorData = await response.json()\n errorMessage = errorData.message || errorMessage\n } catch {\n // Use default error message\n }\n throw PaymentsError.internal(`${errorMessage} (HTTP ${response.status})`)\n }\n return await response.json()\n } catch (error) {\n if (error instanceof PaymentsError) {\n throw error\n }\n throw PaymentsError.internal(\n `Network error while listing payment methods: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n}\n"]}
1
+ {"version":3,"file":"delegation-api.js","sourceRoot":"","sources":["../../src/x402/delegation-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AA8G3D;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,eAAe;IAChD,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,kBAAkB,CAAC,OAAqB;QAC5C,MAAM,GAAG,GAAG,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I,GAAG,CAAC,IAAI;wBAAE,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;gBAC5C,CAAC;gBAAC,MAAM,CAAC;oBACP,cAAc;gBAChB,CAAC;gBACD,MAAM,IAAI,aAAa,CAAC,GAAG,GAAG,UAAU,QAAQ,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,CAAA;YACnE,CAAC;YACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,aAAa;gBAAE,MAAM,KAAK,CAAA;YAC/C,MAAM,aAAa,CAAC,QAAQ,CAC1B,uBAAuB,MAAM,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC3F,CAAA;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Delegation API for managing payment delegations (crypto and card schemes).\n *\n * Provides access to the user's enrolled payment methods and delegations\n * for use with the nvm:erc4337 and nvm:card-delegation x402 schemes.\n */\n\nimport { BasePaymentsAPI } from '../api/base-payments.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport {\n CreateDelegationPayload,\n CreateDelegationResponse,\n PaymentOptions,\n} from '../common/types.js'\n\n/**\n * Card-delegation providers exposed by the SDK. Use this when you want to\n * restrict to card-shape entries only (e.g., filtering the heterogeneous\n * list returned by {@link DelegationAPI.listPaymentMethods}).\n */\nexport type CardProvider = 'stripe' | 'braintree' | 'visa'\n\n/**\n * All delegation providers, including the crypto path. Matches the\n * server-side union and aligns with {@link CreateDelegationPayload.provider}.\n */\nexport type DelegationProvider = CardProvider | 'erc4337'\n\n/**\n * Summary of a user's enrolled payment method.\n *\n * The list returned by {@link DelegationAPI.listPaymentMethods} is\n * heterogeneous: it includes enrolled cards (`provider` in\n * `stripe` / `braintree` / `visa`) AND, when the user has a smart account\n * configured, an entry for the user's ERC-4337 wallet\n * (`provider: 'erc4337'`, `type: 'crypto_wallet'`, `brand: 'ethereum'`).\n * Filter on `provider` when callers only want one shape.\n */\nexport interface PaymentMethodSummary {\n /** Payment method ID (Stripe 'pm_...', Braintree vault token, Visa Agentic\n * token id, or — for the erc4337 entry — the smart-account address) */\n id: string\n /** Payment method type ('card' | 'crypto_wallet' | 'paypal' | …) */\n type: string\n /** Card brand (e.g., 'visa', 'mastercard'), 'ethereum' for the erc4337\n * entry, or payment method type ('paypal', 'venmo') */\n brand: string\n /** Last 4 digits (cards), trailing 4 chars of the wallet address\n * (erc4337), or email/username (PayPal/Venmo) */\n last4: string\n /** Expiration month (0 for non-card methods) */\n expMonth: number\n /** Expiration year (0 for non-card methods) */\n expYear: number\n /** Human-readable alias, if set */\n alias?: string | null\n /** One of 'stripe' | 'braintree' | 'visa' | 'erc4337' */\n provider?: DelegationProvider\n /** Current status ('Active' or 'Revoked') */\n status?: string\n /** NVM API Key IDs allowed to use this payment method, or null if unrestricted */\n allowedApiKeyIds?: string[] | null\n}\n\n/**\n * Summary of a delegation (card or crypto spending).\n */\nexport interface DelegationSummary {\n delegationId: string\n provider: string\n providerPaymentMethodId: string\n status: string\n spendingLimitCents: string\n amountSpentCents: string\n remainingBudgetCents: string\n currency: string\n transactionCount: number\n expiresAt: string\n createdAt: string\n apiKeyId: string | null\n}\n\n/**\n * Paginated list of delegations returned by the API.\n */\nexport interface DelegationListResponse {\n delegations: DelegationSummary[]\n totalResults: number\n page: number\n offset: number\n}\n\n/**\n * Summary of an agent's purchasing power via card delegations.\n */\nexport interface PurchasingPower {\n cards: PaymentMethodSummary[]\n delegations: DelegationSummary[]\n totalRemainingBudgetCents: number\n currency: string\n}\n\n/**\n * DTO for updating a payment method's alias and allowed API keys.\n */\nexport interface UpdatePaymentMethodDto {\n alias?: string\n allowedApiKeyIds?: string[] | null\n}\n\n/**\n * Options for listing payment methods or delegations.\n */\nexport interface ListOptions {\n /** When true, return only items accessible to the requesting API key */\n accessible?: boolean\n}\n\n/**\n * API for managing payment methods and delegations (card and crypto).\n */\nexport class DelegationAPI extends BasePaymentsAPI {\n static getInstance(options: PaymentOptions): DelegationAPI {\n return new DelegationAPI(options)\n }\n\n /**\n * List the user's enrolled payment methods for card delegation.\n * When `accessible: true`, only cards accessible to the requesting API key are returned.\n */\n async listPaymentMethods(options?: ListOptions): Promise<PaymentMethodSummary[]> {\n const url = new URL('/api/v1/payment-methods', this.environment.backend)\n if (options?.accessible) url.searchParams.set('accessible', 'true')\n return this.fetchJSON(url, 'GET', 'list payment methods')\n }\n\n /**\n * List the user's existing delegations.\n * When `accessible: true`, only usable delegations (Active, non-expired, with budget) are returned.\n */\n async listDelegations(options?: ListOptions): Promise<DelegationListResponse> {\n const url = new URL('/api/v1/delegation', this.environment.backend)\n if (options?.accessible) url.searchParams.set('accessible', 'true')\n return this.fetchJSON(url, 'GET', 'list delegations')\n }\n\n /**\n * Get the agent's purchasing power — accessible cards, active delegations,\n * and combined remaining budget.\n */\n async getPurchasingPower(): Promise<PurchasingPower> {\n const accessible = { accessible: true } satisfies ListOptions\n const [cards, { delegations }] = await Promise.all([\n this.listPaymentMethods(accessible),\n this.listDelegations(accessible),\n ])\n\n const totalRemainingBudgetCents = delegations.reduce(\n (sum, d) => sum + (parseInt(d.remainingBudgetCents, 10) || 0),\n 0,\n )\n\n return {\n cards,\n delegations,\n totalRemainingBudgetCents,\n currency: delegations[0]?.currency ?? 'usd',\n }\n }\n\n /**\n * Create a new delegation for any supported provider (stripe, braintree,\n * visa, or erc4337).\n *\n * Note: Visa delegations require a per-delegation device-binding ceremony\n * (FIDO/passkey + assuranceData) that must be performed in the browser\n * via the Nevermined webapp. The SDK can list and consume an already-\n * created Visa delegation but cannot create one programmatically.\n *\n * @param payload - The delegation creation parameters\n * @returns The created delegation ID (and token for card delegations)\n */\n async createDelegation(payload: CreateDelegationPayload): Promise<CreateDelegationResponse> {\n const url = new URL('/api/v1/delegation/create', this.environment.backend)\n return this.fetchJSON(url, 'POST', 'create delegation', payload)\n }\n\n /**\n * Update a payment method's alias and/or allowed API keys.\n */\n async updatePaymentMethod(\n paymentMethodId: string,\n dto: UpdatePaymentMethodDto,\n ): Promise<PaymentMethodSummary> {\n const url = new URL(`/api/v1/payment-methods/${paymentMethodId}`, this.environment.backend)\n return this.fetchJSON(url, 'PATCH', 'update payment method', dto)\n }\n\n // --- Private helpers ---\n\n private async fetchJSON<T>(url: URL, method: string, action: string, body?: unknown): Promise<T> {\n const options = this.getBackendHTTPOptions(method, body)\n try {\n const response = await fetch(url, options)\n if (!response.ok) {\n let msg = `Failed to ${action}`\n let code = `http_${response.status}`\n try {\n const err = await response.json()\n if (err.message) msg = err.message\n if (err.code) code = err.code\n if (err.hint) msg = `${msg} — ${err.hint}`\n } catch {\n // use default\n }\n throw new PaymentsError(`${msg} (HTTP ${response.status})`, code)\n }\n return await response.json()\n } catch (error) {\n if (error instanceof PaymentsError) throw error\n throw PaymentsError.internal(\n `Network error while ${action}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n}\n"]}
@@ -69,6 +69,10 @@ export interface RouteConfig {
69
69
  network?: string;
70
70
  /** x402 scheme override (auto-detected from plan metadata if omitted) */
71
71
  scheme?: X402SchemeType;
72
+ /** Human-readable description of the protected resource */
73
+ description?: string;
74
+ /** Expected response MIME type (e.g., "application/json") */
75
+ mimeType?: string;
72
76
  }
73
77
  /**
74
78
  * Route configuration map: "METHOD \/path" -> RouteConfig