@nevermined-io/payments 1.5.0 → 1.7.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 (56) hide show
  1. package/README.md +121 -93
  2. package/dist/api/agents-api.d.ts.map +1 -1
  3. package/dist/api/agents-api.js +2 -2
  4. package/dist/api/agents-api.js.map +1 -1
  5. package/dist/api/base-payments.d.ts +6 -4
  6. package/dist/api/base-payments.d.ts.map +1 -1
  7. package/dist/api/base-payments.js +10 -0
  8. package/dist/api/base-payments.js.map +1 -1
  9. package/dist/api/contracts-api.js +1 -1
  10. package/dist/api/contracts-api.js.map +1 -1
  11. package/dist/api/plans-api.d.ts.map +1 -1
  12. package/dist/api/plans-api.js +3 -10
  13. package/dist/api/plans-api.js.map +1 -1
  14. package/dist/common/api-version.d.ts +24 -0
  15. package/dist/common/api-version.d.ts.map +1 -0
  16. package/dist/common/api-version.js +24 -0
  17. package/dist/common/api-version.js.map +1 -0
  18. package/dist/common/types.d.ts +73 -18
  19. package/dist/common/types.d.ts.map +1 -1
  20. package/dist/common/types.js.map +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/payments.d.ts +4 -3
  26. package/dist/payments.d.ts.map +1 -1
  27. package/dist/payments.js +5 -3
  28. package/dist/payments.js.map +1 -1
  29. package/dist/x402/index.d.ts +1 -1
  30. package/dist/x402/index.d.ts.map +1 -1
  31. package/dist/x402/index.js.map +1 -1
  32. package/dist/x402/langchain/agent.d.ts +96 -0
  33. package/dist/x402/langchain/agent.d.ts.map +1 -0
  34. package/dist/x402/langchain/agent.js +121 -0
  35. package/dist/x402/langchain/agent.js.map +1 -0
  36. package/dist/x402/langchain/decorator.d.ts +43 -4
  37. package/dist/x402/langchain/decorator.d.ts.map +1 -1
  38. package/dist/x402/langchain/decorator.js +173 -6
  39. package/dist/x402/langchain/decorator.js.map +1 -1
  40. package/dist/x402/langchain/index.d.ts +2 -1
  41. package/dist/x402/langchain/index.d.ts.map +1 -1
  42. package/dist/x402/langchain/index.js +2 -1
  43. package/dist/x402/langchain/index.js.map +1 -1
  44. package/dist/x402/langsmith/index.d.ts +15 -0
  45. package/dist/x402/langsmith/index.d.ts.map +1 -0
  46. package/dist/x402/langsmith/index.js +15 -0
  47. package/dist/x402/langsmith/index.js.map +1 -0
  48. package/dist/x402/langsmith/spans.d.ts +163 -0
  49. package/dist/x402/langsmith/spans.d.ts.map +1 -0
  50. package/dist/x402/langsmith/spans.js +341 -0
  51. package/dist/x402/langsmith/spans.js.map +1 -0
  52. package/dist/x402/token.d.ts +13 -10
  53. package/dist/x402/token.d.ts.map +1 -1
  54. package/dist/x402/token.js +46 -16
  55. package/dist/x402/token.js.map +1 -1
  56. package/package.json +16 -2
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAoC,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAA;AAEvD;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAiBtE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA4B;IAE5B,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;IAC5D,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAgB,e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L,MAAM;YACN,OAAO;YACP,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAOT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport { EnvironmentInfo, EnvironmentName, Environments } from '../environments.js'\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environment = Environments[options.environment as EnvironmentName]\n this.environmentName = options.environment\n this.appId = options.appId\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: {\n Accept: string\n 'Content-Type': string\n }\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
1
+ {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAoC,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAA;AAEvD;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAiBtE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA4B;IAE5B,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;IAC5D,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CA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AAqB,CAAA;QAC7D,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,qEAAqE;YACrE,+DAA+D;YAC/D,6DAA6D;YAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;gBACzD,IAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM;YACN,OAAO;YACP,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAIT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,OAAO,IAAI,kBAAkB;aACzD;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { API_VERSION_HEADER, LOCKED_API_VERSION } from '../common/api-version.js'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport { EnvironmentInfo, EnvironmentName, Environments } from '../environments.js'\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n /**\n * Backend API version (MAJOR.MINOR) pinned by this instance, set from\n * `options.version`. When unset, every request defaults to\n * {@link LOCKED_API_VERSION}.\n */\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environment = Environments[options.environment as EnvironmentName]\n this.environmentName = options.environment\n this.appId = options.appId\n // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as\n // Nevermined-Version. Fail fast on a malformed value rather than shipping\n // an invalid header (e.g. an SDK package version '1.0.0', 'v1.1', or '')\n // that the backend rejects with 400 on every call.\n if (options.version !== undefined && !/^\\d+\\.\\d+$/.test(options.version)) {\n throw new PaymentsError(\n `Invalid 'version' option '${options.version}': expected a backend API version as MAJOR.MINOR (e.g. '1.1'). Omit it to use the SDK's default pin.`,\n )\n }\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: Record<string, string>\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
@@ -16,7 +16,7 @@ export class ContractsAPI extends BasePaymentsAPI {
16
16
  return this.deploymentInfo;
17
17
  const infoUrl = new URL('/', this.environment.backend);
18
18
  try {
19
- const response = await fetch(infoUrl, { method: 'GET' });
19
+ const response = await fetch(infoUrl, this.getPublicHTTPOptions('GET'));
20
20
  if (!response.ok) {
21
21
  throw new PaymentsError(`Failed to fetch deployment info: ${response.status} ${response.statusText}`);
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"contracts-api.js","sourceRoot":"","sources":["../../src/api/contracts-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAQ3D;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,eAAe;IAG/C,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACrB,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,IAAI,CAAC,cAAc,CAAA;QAEnD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAEtD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;YACxD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,aAAa,CACrB,oCAAoC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAC7E,CAAA;YACH,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAoC,CAAA;YACvE,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;gBACnD,MAAM,IAAI,aAAa,CAAC,2CAA2C,CAAC,CAAA;YACtE,CAAC;YAED,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,CAAA;YACrC,OAAO,IAAI,CAAC,cAAc,CAAA;QAC5B,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,aAAa,CAAC,KAAK,EAAE,OAAO,IAAI,iCAAiC,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB,CAAC,YAAoB;QAC3C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACjD,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,CAAA;QACpD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,aAAa,CAAC,kCAAkC,YAAY,EAAE,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,OAAkB,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,4BAA4B;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import type { Address, PaymentOptions } from '../common/types.js'\nimport { BasePaymentsAPI } from './base-payments.js'\nimport { PaymentsError } from '../common/payments.error.js'\n\nexport interface DeploymentInfo {\n version?: string\n chainId?: number\n contracts: Record<string, string>\n}\n\n/**\n * Contracts API for accessing contract addresses from the Nevermined API info endpoint.\n */\nexport class ContractsAPI extends BasePaymentsAPI {\n private deploymentInfo?: DeploymentInfo\n\n constructor(options: PaymentOptions) {\n super(options)\n }\n\n /**\n * Fetch deployment info (including contract addresses) from the API root.\n * The result is cached after the first call.\n */\n async getDeploymentInfo(): Promise<DeploymentInfo> {\n if (this.deploymentInfo) return this.deploymentInfo\n\n const infoUrl = new URL('/', this.environment.backend)\n\n try {\n const response = await fetch(infoUrl, { method: 'GET' })\n if (!response.ok) {\n throw new PaymentsError(\n `Failed to fetch deployment info: ${response.status} ${response.statusText}`,\n )\n }\n\n const info = (await response.json()) as { deployment?: DeploymentInfo }\n if (!info.deployment || !info.deployment.contracts) {\n throw new PaymentsError('Deployment info not found in API response')\n }\n\n this.deploymentInfo = info.deployment\n return this.deploymentInfo\n } catch (error: any) {\n throw new PaymentsError(error?.message || 'Failed to fetch deployment info')\n }\n }\n\n /**\n * Get a contract address by name (e.g., \"PayAsYouGoTemplate\").\n */\n async getContractAddress(contractName: string): Promise<Address> {\n const deployment = await this.getDeploymentInfo()\n const address = deployment.contracts?.[contractName]\n if (!address) {\n throw new PaymentsError(`Contract address not found for ${contractName}`)\n }\n return address as Address\n }\n\n /**\n * Get the PayAsYouGoTemplate contract address (convenience accessor).\n */\n async getPayAsYouGoTemplateAddress(): Promise<Address> {\n return this.getContractAddress('PayAsYouGoTemplate')\n }\n}\n"]}
1
+ {"version":3,"file":"contracts-api.js","sourceRoot":"","sources":["../../src/api/contracts-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAQ3D;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,eAAe;IAG/C,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACrB,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,IAAI,CAAC,cAAc,CAAA;QAEnD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CA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js'\nimport { BasePaymentsAPI } from './base-payments.js'\nimport { PaymentsError } from '../common/payments.error.js'\n\nexport interface DeploymentInfo {\n version?: string\n chainId?: number\n contracts: Record<string, string>\n}\n\n/**\n * Contracts API for accessing contract addresses from the Nevermined API info endpoint.\n */\nexport class ContractsAPI extends BasePaymentsAPI {\n private deploymentInfo?: DeploymentInfo\n\n constructor(options: PaymentOptions) {\n super(options)\n }\n\n /**\n * Fetch deployment info (including contract addresses) from the API root.\n * The result is cached after the first call.\n */\n async getDeploymentInfo(): Promise<DeploymentInfo> {\n if (this.deploymentInfo) return this.deploymentInfo\n\n const infoUrl = new URL('/', this.environment.backend)\n\n try {\n const response = await fetch(infoUrl, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw new PaymentsError(\n `Failed to fetch deployment info: ${response.status} ${response.statusText}`,\n )\n }\n\n const info = (await response.json()) as { deployment?: DeploymentInfo }\n if (!info.deployment || !info.deployment.contracts) {\n throw new PaymentsError('Deployment info not found in API response')\n }\n\n this.deploymentInfo = info.deployment\n return this.deploymentInfo\n } catch (error: any) {\n throw new PaymentsError(error?.message || 'Failed to fetch deployment info')\n }\n }\n\n /**\n * Get a contract address by name (e.g., \"PayAsYouGoTemplate\").\n */\n async getContractAddress(contractName: string): Promise<Address> {\n const deployment = await this.getDeploymentInfo()\n const address = deployment.contracts?.[contractName]\n if (!address) {\n throw new PaymentsError(`Contract address not found for ${contractName}`)\n }\n return address as Address\n }\n\n /**\n * Get the PayAsYouGoTemplate contract address (convenience accessor).\n */\n async getPayAsYouGoTemplateAddress(): Promise<Address> {\n return this.getContractAddress('PayAsYouGoTemplate')\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"plans-api.d.ts","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY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AC,YAAY,CAAC;IAW7D;;;;;;;;;;;;;;;;OAgBG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;IAerF;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,eAAe,CAC1B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,OAAO,GACvB,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,iBAAiB,CAC5B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,OAAO,EACxB,eAAe,SAAK,GACnB,OAAO,CAAC,YAAY,CAAC;CAczB"}
@@ -376,7 +376,7 @@ export class PlansAPI extends BasePaymentsAPI {
376
376
  async getPlan(planId) {
377
377
  const query = API_URL_GET_PLAN.replace(':planId', planId);
378
378
  const url = new URL(query, this.environment.backend);
379
- const response = await fetch(url);
379
+ const response = await fetch(url, this.getPublicHTTPOptions('GET'));
380
380
  if (!response.ok) {
381
381
  throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response));
382
382
  }
@@ -427,7 +427,7 @@ export class PlansAPI extends BasePaymentsAPI {
427
427
  async getAgentsAssociatedToAPlan(planId, pagination = new PaginationOptions()) {
428
428
  const query = API_URL_GET_PLAN_AGENTS.replace(':planId', planId) + '?' + pagination.asQueryParams();
429
429
  const url = new URL(query, this.environment.backend);
430
- const response = await fetch(url);
430
+ const response = await fetch(url, this.getPublicHTTPOptions('GET'));
431
431
  if (!response.ok) {
432
432
  throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response));
433
433
  }
@@ -462,15 +462,8 @@ export class PlansAPI extends BasePaymentsAPI {
462
462
  throw new PaymentsError('Holder address is required');
463
463
  }
464
464
  const balanceUrl = API_URL_PLAN_BALANCE.replace(':planId', planId).replace(':holderAddress', holderAddress);
465
- const options = {
466
- method: 'GET',
467
- headers: {
468
- Accept: 'application/json',
469
- 'Content-Type': 'application/json',
470
- },
471
- };
472
465
  const url = new URL(balanceUrl, this.environment.backend);
473
- const response = await fetch(url, options);
466
+ const response = await fetch(url, this.getPublicHTTPOptions('GET'));
474
467
  if (!response.ok) {
475
468
  throw PaymentsError.fromBackend('Unable to get balance', await safeParseJson(response));
476
469
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plans-api.js","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAEL,QAAQ,EACR,kBAAkB,EAElB,iBAAiB,GAQlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,eAAe,EAAsB,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,eAAe;IAG3C,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;IAC/C,CAAC;IACD,oBAAoB;IACpB;;;;;;;;;;;OAWG;IACI,kBAAkB,CACvB,MAAc,EACd,QAAiB,EACjB,WAA8B,QAAQ,CAAC,GAAG;QAE1C,OAAO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AAM,IAAI,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,CAAA;QACxE,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,2BAA2B,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAC1E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAC7B,kCAAkC,EAClC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAC9B,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { safeParseJson } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport {\n Address,\n Currency,\n EURC_TOKEN_ADDRESS,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanBalance,\n PlanCreditsConfig,\n PlanRedemptionType,\n PlanMetadata,\n PlanPriceConfig,\n StripeCheckoutResult,\n} from '../common/types.js'\nimport { ZeroAddress } from '../environments.js'\nimport { getRandomBigInt, isEthereumAddress } from '../utils.js'\nimport { BasePaymentsAPI, PublicationOptions, resolvePublicationHeaders } from './base-payments.js'\nimport * as Plans from '../plans.js'\nimport { ContractsAPI } from './contracts-api.js'\nimport {\n API_URL_GET_PLAN,\n API_URL_GET_PLAN_AGENTS,\n API_URL_MINT_EXPIRABLE_PLAN,\n API_URL_MINT_PLAN,\n API_URL_ORDER_PLAN,\n API_URL_PLAN_BALANCE,\n API_URL_REGISTER_PLAN,\n API_URL_STRIPE_CHECKOUT,\n API_URL_GET_PLANS,\n} from './nvm-api.js'\n\n/**\n * The PlansAPI class provides methods to register and interact with payment plans on Nevermined.\n */\nexport class PlansAPI extends BasePaymentsAPI {\n private contractsApi: ContractsAPI\n\n constructor(options: PaymentOptions) {\n super(options)\n this.contractsApi = new ContractsAPI(options)\n }\n /** Price helpers */\n /**\n * Builds a Fiat price configuration for a plan.\n *\n * `amount` is in **6-decimal units** (USDC convention, NOT cents). To\n * charge $2.00, pass `2_000_000n`. Minimum is `1_000_000n` ($1.00) —\n * lower values are rejected server-side with `BCK.PROTOCOL.0047`.\n *\n * @param amount - Amount to charge in 6-decimal units (e.g. `2_000_000n` for $2.00) as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @param currency - Fiat currency code (default: 'USD'). Any ISO 4217 code accepted by Stripe.\n * @returns The PlanPriceConfig representing a fiat price.\n */\n public getFiatPriceConfig(\n amount: bigint,\n receiver: Address,\n currency: Currency | string = Currency.USD,\n ): PlanPriceConfig {\n return Plans.getFiatPriceConfig(amount, receiver, currency)\n }\n\n /**\n * Builds a Pay-As-You-Go price configuration using the template address from the API.\n */\n public async getPayAsYouGoPriceConfig(\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n ): Promise<PlanPriceConfig> {\n const templateAddress = await this.contractsApi.getPayAsYouGoTemplateAddress()\n return Plans.getPayAsYouGoPriceConfig(amount, receiver, tokenAddress, templateAddress)\n }\n\n /**\n * Builds a Pay-As-You-Go credits configuration.\n */\n public getPayAsYouGoCreditsConfig(): PlanCreditsConfig {\n return Plans.getPayAsYouGoCreditsConfig()\n }\n\n /**\n * Builds a crypto price configuration for a plan.\n *\n * @param amount - Amount to charge in token minor units as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @param tokenAddress - Optional ERC20 token address. If omitted, native token is assumed.\n * @returns The PlanPriceConfig representing a crypto price.\n */\n public getCryptoPriceConfig(\n amount: bigint,\n receiver: Address,\n tokenAddress?: Address,\n ): PlanPriceConfig {\n return Plans.getCryptoPriceConfig(amount, receiver, tokenAddress)\n }\n\n /**\n * Builds an ERC20 price configuration for a plan.\n *\n * @param amount - Amount to charge in token minor units as bigint.\n * @param tokenAddress - ERC20 token contract address.\n * @param receiver - Wallet address that will receive the payment.\n * @returns The PlanPriceConfig representing an ERC20 price.\n */\n public getERC20PriceConfig(\n amount: bigint,\n tokenAddress: Address,\n receiver: Address,\n ): PlanPriceConfig {\n return Plans.getERC20PriceConfig(amount, tokenAddress, receiver)\n }\n\n /**\n * Builds an EURC (Euro stablecoin) price configuration for a plan.\n *\n * @param amount - Amount to charge in EURC minor units (6 decimals) as bigint.\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 */\n public getEURCPriceConfig(\n amount: bigint,\n receiver: Address,\n eurcAddress: Address = EURC_TOKEN_ADDRESS,\n ): PlanPriceConfig {\n return Plans.getEURCPriceConfig(amount, receiver, eurcAddress)\n }\n\n /**\n * Builds a FREE price configuration (no payment required).\n * @returns The PlanPriceConfig representing a free plan.\n */\n public getFreePriceConfig(): PlanPriceConfig {\n return Plans.getFreePriceConfig()\n }\n\n /**\n * Builds a native token price configuration for a plan.\n *\n * @param amount - Amount to charge in native token minor units as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @returns The PlanPriceConfig representing a native token price.\n */\n public getNativeTokenPriceConfig(amount: bigint, receiver: Address): PlanPriceConfig {\n return Plans.getNativeTokenPriceConfig(amount, receiver)\n }\n\n /** Credits helpers */\n /**\n * Builds an EXPIRABLE credits configuration (time-based access).\n *\n * @param durationOfPlan - Duration in seconds.\n * @returns The PlanCreditsConfig representing expirable credits.\n */\n public getExpirableDurationConfig(durationOfPlan: bigint): PlanCreditsConfig {\n return Plans.getExpirableDurationConfig(durationOfPlan)\n }\n\n /**\n * Builds a NON-EXPIRABLE credits configuration (no expiration).\n * @returns The PlanCreditsConfig representing non-expirable credits.\n */\n public getNonExpirableDurationConfig(): PlanCreditsConfig {\n return Plans.getNonExpirableDurationConfig()\n }\n\n /**\n * Builds a FIXED credits configuration.\n *\n * @param creditsGranted - Total credits granted by the plan.\n * @param creditsPerRequest - Credits spent per request (default 1n).\n * @returns The PlanCreditsConfig representing fixed credits.\n */\n public getFixedCreditsConfig(creditsGranted: bigint, creditsPerRequest = 1n): PlanCreditsConfig {\n return Plans.getFixedCreditsConfig(creditsGranted, creditsPerRequest)\n }\n\n /**\n * Builds a DYNAMIC credits configuration (range-limited per request).\n *\n * @param creditsGranted - Total credits granted by the plan.\n * @param minCreditsPerRequest - Minimum credits per request.\n * @param maxCreditsPerRequest - Maximum credits per request.\n * @returns The PlanCreditsConfig representing dynamic credits.\n */\n public getDynamicCreditsConfig(\n creditsGranted: bigint,\n minCreditsPerRequest = 1n,\n maxCreditsPerRequest = 1n,\n ): PlanCreditsConfig {\n return Plans.getDynamicCreditsConfig(creditsGranted, minCreditsPerRequest, maxCreditsPerRequest)\n }\n\n /**\n * Sets the redemption type in a credits configuration.\n *\n * @param creditsConfig - Credits configuration to modify.\n * @param redemptionType - Redemption type to set.\n * @returns The updated PlanCreditsConfig.\n */\n public setRedemptionType(\n creditsConfig: PlanCreditsConfig,\n redemptionType: PlanRedemptionType,\n ): PlanCreditsConfig {\n return Plans.setRedemptionType(creditsConfig, redemptionType)\n }\n\n /**\n * Marks whether burns of these credits are mirrored on-chain.\n *\n * @param creditsConfig - Credits configuration to modify.\n * @param onchainMirror - Whether on-chain mirroring is enabled. Defaults\n * to `true` so calling `setOnchainMirror(config)` enables the mirror;\n * pass `false` explicitly to disable it. The `PlanCreditsConfig`\n * field itself defaults to `false` (set by all credits-config\n * builders) — when `false` the credits ledger lives in the API's\n * Postgres and burns are recorded off-chain only; when `true`, an\n * on-chain audit mirror replays each burn to `NFT1155Credits`.\n * @returns The updated PlanCreditsConfig.\n */\n public setOnchainMirror(\n creditsConfig: PlanCreditsConfig,\n onchainMirror = true,\n ): PlanCreditsConfig {\n return Plans.setOnchainMirror(creditsConfig, onchainMirror)\n }\n /**\n * This method is used to create a singleton instance of the PlansAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the PlansAPI class.\n */\n static getInstance(options: PaymentOptions): PlansAPI {\n return new PlansAPI(options)\n }\n\n /**\n *\n * It allows to an AI Builder to register a Payment Plan on Nevermined in a flexible manner.\n * A Payment Plan defines 2 main aspects:\n * 1. What a subscriber needs to pay to get the plan (i.e. 100 USDC, 5 USD, etc).\n * 2. What the subscriber gets in return to access the AI agents associated to the plan (i.e. 100 credits, 1 week of usage, etc).\n *\n * With Payment Plans, AI Builders control the usage to their AI Agents.\n *\n * Every time a user accesses an AI Agent to the Payment Plan, the usage consumes from a capped amount of credits (or when the plan duration expires).\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks\n * This method is oriented to AI Builders.\n * The NVM API Key must have publication permissions.\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n * @param nonce - Optional nonce to prevent replay attacks. Default is a random BigInt.\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const creditsConfig = getFixedCreditsConfig(100n)\n * const { planId } = await payments.plans.registerPlan({ name: 'AI Assistants Plan'}, cryptoPriceConfig, creditsConfig)\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n nonce = getRandomBigInt(),\n accessLimit?: 'credits' | 'time',\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n if (accessLimit && !['credits', 'time'].includes(accessLimit)) {\n throw new PaymentsError(\n 'Invalid access limit',\n 'accessLimit must be either \"credits\" or \"time\"',\n )\n }\n if (!accessLimit) {\n accessLimit = BigInt(creditsConfig.durationSecs) > 0n ? 'time' : 'credits'\n }\n const body = {\n metadataAttributes: planMetadata,\n priceConfig,\n creditsConfig,\n nonce,\n isTrialPlan: planMetadata.isTrialPlan || false,\n accessLimit,\n ...(priceConfig.currency && { currency: priceConfig.currency }),\n }\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw Error(`${response.statusText} - ${await response.text()}`)\n }\n\n return response.json()\n }\n\n /**\n *\n * It allows to an AI Builder to create a Payment Plan on Nevermined based on Credits.\n * A Nevermined Credits Plan limits the access by the access/usage of the Plan.\n * With them, AI Builders control the number of requests that can be made to an agent or service.\n * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits.\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const creditsConfig = getFixedCreditsConfig(100n)\n * const { planId } = await payments.plans.registerCreditsPlan(\n * { name: 'AI Credits Plan'},\n * cryptoPriceConfig,\n * creditsConfig\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerCreditsPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n // Credits plans must have durationSecs = 0 (non-expirable) and either fixed or dynamic redemption\n if (BigInt(creditsConfig.durationSecs) !== 0n)\n throw new PaymentsError(\n 'The creditsConfig.durationSecs must be 0 for credits plans (non-expirable)',\n )\n\n if (creditsConfig.minAmount > creditsConfig.maxAmount)\n throw new PaymentsError(\n 'The creditsConfig.minAmount can not be more than creditsConfig.maxAmount',\n )\n\n return this.registerPlan(\n planMetadata,\n priceConfig,\n creditsConfig,\n undefined,\n 'credits',\n publicationOptions,\n )\n }\n\n /**\n *\n * It allows to an AI Builder to create a Payment Plan on Nevermined limited by duration.\n * A Nevermined Credits Plan limits the access by the access/usage of the Plan.\n * With them, AI Builders control the number of requests that can be made to an agent or service.\n * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits.\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerTimePlan(\n * { name: 'Just for today plan'},\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerTimePlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n // Time plans must have durationSecs > 0 (expirable) and isRedemptionAmountFixed = false\n if (BigInt(creditsConfig.durationSecs) === 0n)\n throw new PaymentsError(\n 'The creditsConfig.durationSecs must be greater than 0 for time plans (expirable)',\n )\n\n if (creditsConfig.isRedemptionAmountFixed)\n throw new PaymentsError(\n 'The creditsConfig.isRedemptionAmountFixed must be false for time plans',\n )\n\n return this.registerPlan(\n planMetadata,\n priceConfig,\n creditsConfig,\n undefined,\n 'time',\n publicationOptions,\n )\n }\n\n /**\n *\n * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration.\n * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it.\n * A Trial plan is a plan that only can be purchased once by a user.\n * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent).\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const freePriceConfig = getFreePriceConfig()\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerCreditsTrialPlan(\n * {name: 'Trial plan'},\n * freePriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerCreditsTrialPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig, publicationOptions)\n }\n\n /**\n *\n * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration.\n * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it.\n * A Trial plan is a plan that only can be purchased once by a user.\n * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent).\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const freePriceConfig = getFreePriceConfig()\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerTimeTrialPlan(\n * {name: '1 day Trial plan'},\n * freePriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerTimeTrialPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerTimePlan(planMetadata, priceConfig, creditsConfig, publicationOptions)\n }\n\n /**\n * Gets the information about a Payment Plan by its identifier.\n *\n * @param planId - The unique identifier of the plan.\n * @returns A promise that resolves to the plan's description.\n * @throws PaymentsError if the plan is not found.\n * @example\n * ```\n * const plan = payments.plans.getPlan(planId)\n * ```\n */\n public async getPlan(planId: string) {\n const query = API_URL_GET_PLAN.replace(':planId', planId)\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n *\n * @param page - The page number to retrieve.\n * @param offset - The number of items per page.\n * @param sortBy - The field to sort the results by.\n * @param sortOrder - The order in which to sort the results.\n * @returns A promise that resolves to the list of all different plans.\n */\n public async getPlans(page = 1, offset = 100, sortBy = 'created', sortOrder = 'desc') {\n const url = new URL(API_URL_GET_PLANS, this.environment.backend)\n url.searchParams.set('page', page.toString())\n url.searchParams.set('offset', offset.toString())\n url.searchParams.set('sortBy', sortBy)\n url.searchParams.set('sortOrder', sortOrder)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get plans', await safeParseJson(response))\n }\n\n const data = await response.json()\n return data\n }\n\n /**\n * Gets the list of Agents that have associated a specific Payment Plan.\n * All the agents returned can be accessed by the users that are subscribed to the Payment Plan.\n *\n * @param planId - The unique identifier of the plan.\n * @param pagination - Optional pagination options to control the number of results returned.\n * @returns A promise that resolves to the list of agents associated with the plan.\n * @throws PaymentsError if the plan is not found.\n *\n * @example\n * ```\n * const result = payments.plans.getAgentsAssociatedToAPlan(planId)\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // agents: [ ..]\n * // }\n * ```\n */\n public async getAgentsAssociatedToAPlan(planId: string, pagination = new PaginationOptions()) {\n const query =\n API_URL_GET_PLAN_AGENTS.replace(':planId', planId) + '?' + pagination.asQueryParams()\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Gets the balance of an account for a Payment Plan.\n *\n * @param planId - The identifier of the Payment Plan.\n * @param accountAddress - The address of the account to get the balance for.\n * @returns @see {@link PlanBalance} A promise that resolves to the balance result.\n * @throws PaymentsError if unable to get the balance.\n *\n * ```\n * const balance = payments.plans.getPlanBalance(planId)\n * // {\n * // planId: '105906633592154016712415751065660953070604027297000423385655551747721326921578',\n * // planType: 'credits',\n * // holderAddress: '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359',\n * // creditsContract: '0xdd0240858fE744C3BF245DD377abBC04d1FDA443',\n * // balance: '100',\n * // isSubscriber: true\n * // }\n * ```\n *\n */\n public async getPlanBalance(planId: string, accountAddress?: Address): Promise<PlanBalance> {\n const holderAddress = isEthereumAddress(accountAddress)\n ? accountAddress\n : this.getAccountAddress()\n\n if (!holderAddress) {\n throw new PaymentsError('Holder address is required')\n }\n\n const balanceUrl = API_URL_PLAN_BALANCE.replace(':planId', planId).replace(\n ':holderAddress',\n holderAddress,\n )\n\n const options = {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n }\n const url = new URL(balanceUrl, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get balance', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Orders a Payment Plan requiring the payment in crypto. The user must have enough balance in the selected token.\n *\n * @remarks\n * The payment is done using crypto in the token (ERC20 or native) defined in the plan.\n *\n * @param planId - The unique identifier of the plan.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to order the plan.\n *\n * @example\n * ```\n * const result = await payments.plans.orderPlan(planId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async orderPlan(planId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const url = new URL(API_URL_ORDER_PLAN.replace(':planId', planId), this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to order plan', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Initiates the purchase of a Plan requiring the payment in Fiat. This method will return a URL where the user can complete the payment.\n *\n * @remarks\n * The payment is completed using a credit card in a external website (Stripe).\n * @remarks\n * This method is only valid for plans with price in Fiat.\n *\n * @param planId - The unique identifier of the plan.\n * @returns A promise that resolves indicating the URL to complete the payment.\n * @throws PaymentsError if unable to order the plan.\n *\n * @example\n * ```\n * const result = await payments.plans.orderFiatPlan(planId)\n * ```\n */\n public async orderFiatPlan(planId: string): Promise<{ result: StripeCheckoutResult }> {\n const body = {\n sessionType: 'embedded',\n planId,\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_STRIPE_CHECKOUT, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to order fiat plan', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Mints credits for a given Payment Plan and transfers them to a receiver.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param creditsAmount - The number of credits to mint.\n * @param creditsReceiver - The address of the receiver.\n * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.\n * @throws PaymentsError if unable to mint credits.\n *\n * @example\n * ```\n * const result = await payments.plans.mintPlanCredits(planId, 5n, '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359')\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async mintPlanCredits(\n planId: string,\n creditsAmount: bigint,\n creditsReceiver: Address,\n ): Promise<NvmAPIResult> {\n const body = { planId, amount: creditsAmount, creditsReceiver }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_MINT_PLAN, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to mint plan credits', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Mints expirable credits for a given Payment Plan and transfers them to a receiver.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param creditsAmount - The number of credits to mint.\n * @param creditsReceiver - The address of the receiver.\n * @param creditsDuration - The duration of the credits in seconds. Default is 0 (no expiration).\n * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.\n * @throws PaymentsError if unable to mint expirable credits.\n *\n * @example\n * ```\n * const result = await payments.plans.mintPlanExpirable(\n * planId,\n * 1n,\n * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359',\n * 86_400n // 1 day in seconds\n * )\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async mintPlanExpirable(\n planId: string,\n creditsAmount: bigint,\n creditsReceiver: Address,\n creditsDuration = 0n,\n ): Promise<NvmAPIResult> {\n const body = { planId, creditsAmount, creditsReceiver, creditsDuration }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_MINT_EXPIRABLE_PLAN, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to mint expirable credits',\n await safeParseJson(response),\n )\n }\n\n return response.json()\n }\n}\n"]}
1
+ {"version":3,"file":"plans-api.js","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAEL,QAAQ,EACR,kBAAkB,EAElB,iBAAiB,GAQlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,eAAe,EAAsB,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,eAAe;IAG3C,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;IAC/C,CAAC;IACD,oBAAoB;IACpB;;;;;;;;;;;OAWG;IACI,kBAAkB,CACvB,MAAc,EACd,QAAiB,EACjB,WAA8B,QAAQ,CAAC,GAAG;QAE1C,OAAO,KAAK,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC7D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,wBAAwB,CACnC,MAAc,EACd,QAAiB,EACjB,eAAwB,WAAW;Q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IAAI,GAAG,CAAC,2BAA2B,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAC1E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAC7B,kCAAkC,EAClC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAC9B,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { safeParseJson } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport {\n Address,\n Currency,\n EURC_TOKEN_ADDRESS,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanBalance,\n PlanCreditsConfig,\n PlanRedemptionType,\n PlanMetadata,\n PlanPriceConfig,\n StripeCheckoutResult,\n} from '../common/types.js'\nimport { ZeroAddress } from '../environments.js'\nimport { getRandomBigInt, isEthereumAddress } from '../utils.js'\nimport { BasePaymentsAPI, PublicationOptions, resolvePublicationHeaders } from './base-payments.js'\nimport * as Plans from '../plans.js'\nimport { ContractsAPI } from './contracts-api.js'\nimport {\n API_URL_GET_PLAN,\n API_URL_GET_PLAN_AGENTS,\n API_URL_MINT_EXPIRABLE_PLAN,\n API_URL_MINT_PLAN,\n API_URL_ORDER_PLAN,\n API_URL_PLAN_BALANCE,\n API_URL_REGISTER_PLAN,\n API_URL_STRIPE_CHECKOUT,\n API_URL_GET_PLANS,\n} from './nvm-api.js'\n\n/**\n * The PlansAPI class provides methods to register and interact with payment plans on Nevermined.\n */\nexport class PlansAPI extends BasePaymentsAPI {\n private contractsApi: ContractsAPI\n\n constructor(options: PaymentOptions) {\n super(options)\n this.contractsApi = new ContractsAPI(options)\n }\n /** Price helpers */\n /**\n * Builds a Fiat price configuration for a plan.\n *\n * `amount` is in **6-decimal units** (USDC convention, NOT cents). To\n * charge $2.00, pass `2_000_000n`. Minimum is `1_000_000n` ($1.00) —\n * lower values are rejected server-side with `BCK.PROTOCOL.0047`.\n *\n * @param amount - Amount to charge in 6-decimal units (e.g. `2_000_000n` for $2.00) as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @param currency - Fiat currency code (default: 'USD'). Any ISO 4217 code accepted by Stripe.\n * @returns The PlanPriceConfig representing a fiat price.\n */\n public getFiatPriceConfig(\n amount: bigint,\n receiver: Address,\n currency: Currency | string = Currency.USD,\n ): PlanPriceConfig {\n return Plans.getFiatPriceConfig(amount, receiver, currency)\n }\n\n /**\n * Builds a Pay-As-You-Go price configuration using the template address from the API.\n */\n public async getPayAsYouGoPriceConfig(\n amount: bigint,\n receiver: Address,\n tokenAddress: Address = ZeroAddress,\n ): Promise<PlanPriceConfig> {\n const templateAddress = await this.contractsApi.getPayAsYouGoTemplateAddress()\n return Plans.getPayAsYouGoPriceConfig(amount, receiver, tokenAddress, templateAddress)\n }\n\n /**\n * Builds a Pay-As-You-Go credits configuration.\n */\n public getPayAsYouGoCreditsConfig(): PlanCreditsConfig {\n return Plans.getPayAsYouGoCreditsConfig()\n }\n\n /**\n * Builds a crypto price configuration for a plan.\n *\n * @param amount - Amount to charge in token minor units as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @param tokenAddress - Optional ERC20 token address. If omitted, native token is assumed.\n * @returns The PlanPriceConfig representing a crypto price.\n */\n public getCryptoPriceConfig(\n amount: bigint,\n receiver: Address,\n tokenAddress?: Address,\n ): PlanPriceConfig {\n return Plans.getCryptoPriceConfig(amount, receiver, tokenAddress)\n }\n\n /**\n * Builds an ERC20 price configuration for a plan.\n *\n * @param amount - Amount to charge in token minor units as bigint.\n * @param tokenAddress - ERC20 token contract address.\n * @param receiver - Wallet address that will receive the payment.\n * @returns The PlanPriceConfig representing an ERC20 price.\n */\n public getERC20PriceConfig(\n amount: bigint,\n tokenAddress: Address,\n receiver: Address,\n ): PlanPriceConfig {\n return Plans.getERC20PriceConfig(amount, tokenAddress, receiver)\n }\n\n /**\n * Builds an EURC (Euro stablecoin) price configuration for a plan.\n *\n * @param amount - Amount to charge in EURC minor units (6 decimals) as bigint.\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 */\n public getEURCPriceConfig(\n amount: bigint,\n receiver: Address,\n eurcAddress: Address = EURC_TOKEN_ADDRESS,\n ): PlanPriceConfig {\n return Plans.getEURCPriceConfig(amount, receiver, eurcAddress)\n }\n\n /**\n * Builds a FREE price configuration (no payment required).\n * @returns The PlanPriceConfig representing a free plan.\n */\n public getFreePriceConfig(): PlanPriceConfig {\n return Plans.getFreePriceConfig()\n }\n\n /**\n * Builds a native token price configuration for a plan.\n *\n * @param amount - Amount to charge in native token minor units as bigint.\n * @param receiver - Wallet address that will receive the payment.\n * @returns The PlanPriceConfig representing a native token price.\n */\n public getNativeTokenPriceConfig(amount: bigint, receiver: Address): PlanPriceConfig {\n return Plans.getNativeTokenPriceConfig(amount, receiver)\n }\n\n /** Credits helpers */\n /**\n * Builds an EXPIRABLE credits configuration (time-based access).\n *\n * @param durationOfPlan - Duration in seconds.\n * @returns The PlanCreditsConfig representing expirable credits.\n */\n public getExpirableDurationConfig(durationOfPlan: bigint): PlanCreditsConfig {\n return Plans.getExpirableDurationConfig(durationOfPlan)\n }\n\n /**\n * Builds a NON-EXPIRABLE credits configuration (no expiration).\n * @returns The PlanCreditsConfig representing non-expirable credits.\n */\n public getNonExpirableDurationConfig(): PlanCreditsConfig {\n return Plans.getNonExpirableDurationConfig()\n }\n\n /**\n * Builds a FIXED credits configuration.\n *\n * @param creditsGranted - Total credits granted by the plan.\n * @param creditsPerRequest - Credits spent per request (default 1n).\n * @returns The PlanCreditsConfig representing fixed credits.\n */\n public getFixedCreditsConfig(creditsGranted: bigint, creditsPerRequest = 1n): PlanCreditsConfig {\n return Plans.getFixedCreditsConfig(creditsGranted, creditsPerRequest)\n }\n\n /**\n * Builds a DYNAMIC credits configuration (range-limited per request).\n *\n * @param creditsGranted - Total credits granted by the plan.\n * @param minCreditsPerRequest - Minimum credits per request.\n * @param maxCreditsPerRequest - Maximum credits per request.\n * @returns The PlanCreditsConfig representing dynamic credits.\n */\n public getDynamicCreditsConfig(\n creditsGranted: bigint,\n minCreditsPerRequest = 1n,\n maxCreditsPerRequest = 1n,\n ): PlanCreditsConfig {\n return Plans.getDynamicCreditsConfig(creditsGranted, minCreditsPerRequest, maxCreditsPerRequest)\n }\n\n /**\n * Sets the redemption type in a credits configuration.\n *\n * @param creditsConfig - Credits configuration to modify.\n * @param redemptionType - Redemption type to set.\n * @returns The updated PlanCreditsConfig.\n */\n public setRedemptionType(\n creditsConfig: PlanCreditsConfig,\n redemptionType: PlanRedemptionType,\n ): PlanCreditsConfig {\n return Plans.setRedemptionType(creditsConfig, redemptionType)\n }\n\n /**\n * Marks whether burns of these credits are mirrored on-chain.\n *\n * @param creditsConfig - Credits configuration to modify.\n * @param onchainMirror - Whether on-chain mirroring is enabled. Defaults\n * to `true` so calling `setOnchainMirror(config)` enables the mirror;\n * pass `false` explicitly to disable it. The `PlanCreditsConfig`\n * field itself defaults to `false` (set by all credits-config\n * builders) — when `false` the credits ledger lives in the API's\n * Postgres and burns are recorded off-chain only; when `true`, an\n * on-chain audit mirror replays each burn to `NFT1155Credits`.\n * @returns The updated PlanCreditsConfig.\n */\n public setOnchainMirror(\n creditsConfig: PlanCreditsConfig,\n onchainMirror = true,\n ): PlanCreditsConfig {\n return Plans.setOnchainMirror(creditsConfig, onchainMirror)\n }\n /**\n * This method is used to create a singleton instance of the PlansAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the PlansAPI class.\n */\n static getInstance(options: PaymentOptions): PlansAPI {\n return new PlansAPI(options)\n }\n\n /**\n *\n * It allows to an AI Builder to register a Payment Plan on Nevermined in a flexible manner.\n * A Payment Plan defines 2 main aspects:\n * 1. What a subscriber needs to pay to get the plan (i.e. 100 USDC, 5 USD, etc).\n * 2. What the subscriber gets in return to access the AI agents associated to the plan (i.e. 100 credits, 1 week of usage, etc).\n *\n * With Payment Plans, AI Builders control the usage to their AI Agents.\n *\n * Every time a user accesses an AI Agent to the Payment Plan, the usage consumes from a capped amount of credits (or when the plan duration expires).\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks\n * This method is oriented to AI Builders.\n * The NVM API Key must have publication permissions.\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n * @param nonce - Optional nonce to prevent replay attacks. Default is a random BigInt.\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const creditsConfig = getFixedCreditsConfig(100n)\n * const { planId } = await payments.plans.registerPlan({ name: 'AI Assistants Plan'}, cryptoPriceConfig, creditsConfig)\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n nonce = getRandomBigInt(),\n accessLimit?: 'credits' | 'time',\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n if (accessLimit && !['credits', 'time'].includes(accessLimit)) {\n throw new PaymentsError(\n 'Invalid access limit',\n 'accessLimit must be either \"credits\" or \"time\"',\n )\n }\n if (!accessLimit) {\n accessLimit = BigInt(creditsConfig.durationSecs) > 0n ? 'time' : 'credits'\n }\n const body = {\n metadataAttributes: planMetadata,\n priceConfig,\n creditsConfig,\n nonce,\n isTrialPlan: planMetadata.isTrialPlan || false,\n accessLimit,\n ...(priceConfig.currency && { currency: priceConfig.currency }),\n }\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw Error(`${response.statusText} - ${await response.text()}`)\n }\n\n return response.json()\n }\n\n /**\n *\n * It allows to an AI Builder to create a Payment Plan on Nevermined based on Credits.\n * A Nevermined Credits Plan limits the access by the access/usage of the Plan.\n * With them, AI Builders control the number of requests that can be made to an agent or service.\n * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits.\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const creditsConfig = getFixedCreditsConfig(100n)\n * const { planId } = await payments.plans.registerCreditsPlan(\n * { name: 'AI Credits Plan'},\n * cryptoPriceConfig,\n * creditsConfig\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerCreditsPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n // Credits plans must have durationSecs = 0 (non-expirable) and either fixed or dynamic redemption\n if (BigInt(creditsConfig.durationSecs) !== 0n)\n throw new PaymentsError(\n 'The creditsConfig.durationSecs must be 0 for credits plans (non-expirable)',\n )\n\n if (creditsConfig.minAmount > creditsConfig.maxAmount)\n throw new PaymentsError(\n 'The creditsConfig.minAmount can not be more than creditsConfig.maxAmount',\n )\n\n return this.registerPlan(\n planMetadata,\n priceConfig,\n creditsConfig,\n undefined,\n 'credits',\n publicationOptions,\n )\n }\n\n /**\n *\n * It allows to an AI Builder to create a Payment Plan on Nevermined limited by duration.\n * A Nevermined Credits Plan limits the access by the access/usage of the Plan.\n * With them, AI Builders control the number of requests that can be made to an agent or service.\n * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits.\n * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerTimePlan(\n * { name: 'Just for today plan'},\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerTimePlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n // Time plans must have durationSecs > 0 (expirable) and isRedemptionAmountFixed = false\n if (BigInt(creditsConfig.durationSecs) === 0n)\n throw new PaymentsError(\n 'The creditsConfig.durationSecs must be greater than 0 for time plans (expirable)',\n )\n\n if (creditsConfig.isRedemptionAmountFixed)\n throw new PaymentsError(\n 'The creditsConfig.isRedemptionAmountFixed must be false for time plans',\n )\n\n return this.registerPlan(\n planMetadata,\n priceConfig,\n creditsConfig,\n undefined,\n 'time',\n publicationOptions,\n )\n }\n\n /**\n *\n * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration.\n * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it.\n * A Trial plan is a plan that only can be purchased once by a user.\n * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent).\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const freePriceConfig = getFreePriceConfig()\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerCreditsTrialPlan(\n * {name: 'Trial plan'},\n * freePriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerCreditsTrialPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig, publicationOptions)\n }\n\n /**\n *\n * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration.\n * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it.\n * A Trial plan is a plan that only can be purchased once by a user.\n * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent).\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/create-plan\n *\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const freePriceConfig = getFreePriceConfig()\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { planId } = await payments.plans.registerTimeTrialPlan(\n * {name: '1 day Trial plan'},\n * freePriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the plan (Plan ID) of the newly created plan.\n */\n public async registerTimeTrialPlan(\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n publicationOptions?: PublicationOptions,\n ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerTimePlan(planMetadata, priceConfig, creditsConfig, publicationOptions)\n }\n\n /**\n * Gets the information about a Payment Plan by its identifier.\n *\n * @param planId - The unique identifier of the plan.\n * @returns A promise that resolves to the plan's description.\n * @throws PaymentsError if the plan is not found.\n * @example\n * ```\n * const plan = payments.plans.getPlan(planId)\n * ```\n */\n public async getPlan(planId: string) {\n const query = API_URL_GET_PLAN.replace(':planId', planId)\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n *\n * @param page - The page number to retrieve.\n * @param offset - The number of items per page.\n * @param sortBy - The field to sort the results by.\n * @param sortOrder - The order in which to sort the results.\n * @returns A promise that resolves to the list of all different plans.\n */\n public async getPlans(page = 1, offset = 100, sortBy = 'created', sortOrder = 'desc') {\n const url = new URL(API_URL_GET_PLANS, this.environment.backend)\n url.searchParams.set('page', page.toString())\n url.searchParams.set('offset', offset.toString())\n url.searchParams.set('sortBy', sortBy)\n url.searchParams.set('sortOrder', sortOrder)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get plans', await safeParseJson(response))\n }\n\n const data = await response.json()\n return data\n }\n\n /**\n * Gets the list of Agents that have associated a specific Payment Plan.\n * All the agents returned can be accessed by the users that are subscribed to the Payment Plan.\n *\n * @param planId - The unique identifier of the plan.\n * @param pagination - Optional pagination options to control the number of results returned.\n * @returns A promise that resolves to the list of agents associated with the plan.\n * @throws PaymentsError if the plan is not found.\n *\n * @example\n * ```\n * const result = payments.plans.getAgentsAssociatedToAPlan(planId)\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // agents: [ ..]\n * // }\n * ```\n */\n public async getAgentsAssociatedToAPlan(planId: string, pagination = new PaginationOptions()) {\n const query =\n API_URL_GET_PLAN_AGENTS.replace(':planId', planId) + '?' + pagination.asQueryParams()\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Plan not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Gets the balance of an account for a Payment Plan.\n *\n * @param planId - The identifier of the Payment Plan.\n * @param accountAddress - The address of the account to get the balance for.\n * @returns @see {@link PlanBalance} A promise that resolves to the balance result.\n * @throws PaymentsError if unable to get the balance.\n *\n * ```\n * const balance = payments.plans.getPlanBalance(planId)\n * // {\n * // planId: '105906633592154016712415751065660953070604027297000423385655551747721326921578',\n * // planType: 'credits',\n * // holderAddress: '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359',\n * // creditsContract: '0xdd0240858fE744C3BF245DD377abBC04d1FDA443',\n * // balance: '100',\n * // isSubscriber: true\n * // }\n * ```\n *\n */\n public async getPlanBalance(planId: string, accountAddress?: Address): Promise<PlanBalance> {\n const holderAddress = isEthereumAddress(accountAddress)\n ? accountAddress\n : this.getAccountAddress()\n\n if (!holderAddress) {\n throw new PaymentsError('Holder address is required')\n }\n\n const balanceUrl = API_URL_PLAN_BALANCE.replace(':planId', planId).replace(\n ':holderAddress',\n holderAddress,\n )\n\n const url = new URL(balanceUrl, this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get balance', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Orders a Payment Plan requiring the payment in crypto. The user must have enough balance in the selected token.\n *\n * @remarks\n * The payment is done using crypto in the token (ERC20 or native) defined in the plan.\n *\n * @param planId - The unique identifier of the plan.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to order the plan.\n *\n * @example\n * ```\n * const result = await payments.plans.orderPlan(planId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async orderPlan(planId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const url = new URL(API_URL_ORDER_PLAN.replace(':planId', planId), this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to order plan', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Initiates the purchase of a Plan requiring the payment in Fiat. This method will return a URL where the user can complete the payment.\n *\n * @remarks\n * The payment is completed using a credit card in a external website (Stripe).\n * @remarks\n * This method is only valid for plans with price in Fiat.\n *\n * @param planId - The unique identifier of the plan.\n * @returns A promise that resolves indicating the URL to complete the payment.\n * @throws PaymentsError if unable to order the plan.\n *\n * @example\n * ```\n * const result = await payments.plans.orderFiatPlan(planId)\n * ```\n */\n public async orderFiatPlan(planId: string): Promise<{ result: StripeCheckoutResult }> {\n const body = {\n sessionType: 'embedded',\n planId,\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_STRIPE_CHECKOUT, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to order fiat plan', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Mints credits for a given Payment Plan and transfers them to a receiver.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param creditsAmount - The number of credits to mint.\n * @param creditsReceiver - The address of the receiver.\n * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.\n * @throws PaymentsError if unable to mint credits.\n *\n * @example\n * ```\n * const result = await payments.plans.mintPlanCredits(planId, 5n, '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359')\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async mintPlanCredits(\n planId: string,\n creditsAmount: bigint,\n creditsReceiver: Address,\n ): Promise<NvmAPIResult> {\n const body = { planId, amount: creditsAmount, creditsReceiver }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_MINT_PLAN, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to mint plan credits', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Mints expirable credits for a given Payment Plan and transfers them to a receiver.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param creditsAmount - The number of credits to mint.\n * @param creditsReceiver - The address of the receiver.\n * @param creditsDuration - The duration of the credits in seconds. Default is 0 (no expiration).\n * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.\n * @throws PaymentsError if unable to mint expirable credits.\n *\n * @example\n * ```\n * const result = await payments.plans.mintPlanExpirable(\n * planId,\n * 1n,\n * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359',\n * 86_400n // 1 day in seconds\n * )\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async mintPlanExpirable(\n planId: string,\n creditsAmount: bigint,\n creditsReceiver: Address,\n creditsDuration = 0n,\n ): Promise<NvmAPIResult> {\n const body = { planId, creditsAmount, creditsReceiver, creditsDuration }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_MINT_EXPIRABLE_PLAN, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to mint expirable credits',\n await safeParseJson(response),\n )\n }\n\n return response.json()\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Nevermined **backend API** version (nvm-monorepo MAJOR.MINOR) this SDK
3
+ * release is built and tested against — NOT the version of the SDK package
4
+ * itself. Every HTTP request the SDK sends to the Nevermined backend carries
5
+ * this value in the {@link API_VERSION_HEADER} header so the backend keeps
6
+ * serving the matching API contract even after newer backend deployments.
7
+ *
8
+ * Bump this constant deliberately, and only when the SDK targets a newer
9
+ * backend contract: update the value, run the e2e suite against a staging
10
+ * backend running that version, then cut a minor SDK release.
11
+ *
12
+ * Callers can override the pin per `Payments` instance via
13
+ * `options.version`.
14
+ *
15
+ * @see https://docs.nevermined.app/api-reference/versioning
16
+ */
17
+ export declare const LOCKED_API_VERSION = "1.1";
18
+ /**
19
+ * Name of the HTTP request header carrying the backend API version the SDK
20
+ * is pinned to. Sent on every backend call with the resolved instance
21
+ * version (defaults to {@link LOCKED_API_VERSION}).
22
+ */
23
+ export declare const API_VERSION_HEADER = "Nevermined-Version";
24
+ //# sourceMappingURL=api-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-version.d.ts","sourceRoot":"","sources":["../../src/common/api-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,uBAAuB,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Nevermined **backend API** version (nvm-monorepo MAJOR.MINOR) this SDK
3
+ * release is built and tested against — NOT the version of the SDK package
4
+ * itself. Every HTTP request the SDK sends to the Nevermined backend carries
5
+ * this value in the {@link API_VERSION_HEADER} header so the backend keeps
6
+ * serving the matching API contract even after newer backend deployments.
7
+ *
8
+ * Bump this constant deliberately, and only when the SDK targets a newer
9
+ * backend contract: update the value, run the e2e suite against a staging
10
+ * backend running that version, then cut a minor SDK release.
11
+ *
12
+ * Callers can override the pin per `Payments` instance via
13
+ * `options.version`.
14
+ *
15
+ * @see https://docs.nevermined.app/api-reference/versioning
16
+ */
17
+ export const LOCKED_API_VERSION = '1.1';
18
+ /**
19
+ * Name of the HTTP request header carrying the backend API version the SDK
20
+ * is pinned to. Sent on every backend call with the resolved instance
21
+ * version (defaults to {@link LOCKED_API_VERSION}).
22
+ */
23
+ export const API_VERSION_HEADER = 'Nevermined-Version';
24
+ //# sourceMappingURL=api-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-version.js","sourceRoot":"","sources":["../../src/common/api-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA","sourcesContent":["/**\n * The Nevermined **backend API** version (nvm-monorepo MAJOR.MINOR) this SDK\n * release is built and tested against — NOT the version of the SDK package\n * itself. Every HTTP request the SDK sends to the Nevermined backend carries\n * this value in the {@link API_VERSION_HEADER} header so the backend keeps\n * serving the matching API contract even after newer backend deployments.\n *\n * Bump this constant deliberately, and only when the SDK targets a newer\n * backend contract: update the value, run the e2e suite against a staging\n * backend running that version, then cut a minor SDK release.\n *\n * Callers can override the pin per `Payments` instance via\n * `options.version`.\n *\n * @see https://docs.nevermined.app/api-reference/versioning\n */\nexport const LOCKED_API_VERSION = '1.1'\n\n/**\n * Name of the HTTP request header carrying the backend API version the SDK\n * is pinned to. Sent on every backend call with the resolved instance\n * version (defaults to {@link LOCKED_API_VERSION}).\n */\nexport const API_VERSION_HEADER = 'Nevermined-Version'\n"]}
@@ -32,7 +32,13 @@ export interface PaymentOptions {
32
32
  */
33
33
  appId?: string;
34
34
  /**
35
- * The version of the API to use.
35
+ * Pins the Nevermined backend API version (MAJOR.MINOR) sent with every
36
+ * request via the `Nevermined-Version` header. Defaults to
37
+ * {@link LOCKED_API_VERSION} — the backend contract this SDK release is
38
+ * built and tested against. Override only to deliberately target a
39
+ * different backend contract.
40
+ *
41
+ * @see https://docs.nevermined.app/api-reference/versioning
36
42
  */
37
43
  version?: string;
38
44
  /**
@@ -450,32 +456,77 @@ export declare function getDefaultNetwork(scheme: X402SchemeType, environment?:
450
456
  * Type guard to check if a value is a valid x402 scheme type.
451
457
  */
452
458
  export declare function isValidScheme(s: unknown): s is X402SchemeType;
459
+ /**
460
+ * Currency codes accepted for a delegation. Lowercase, mirroring the
461
+ * backend's `@IsIn(['usd','eur','usdc','eurc'])` constraint on
462
+ * `POST /api/v1/delegation/create` and the Python SDK's `DelegationCurrency`.
463
+ * Card providers use `'usd'`/`'eur'`; erc4337 uses `'usdc'`/`'eurc'`.
464
+ */
465
+ export type DelegationCurrency = 'usd' | 'eur' | 'usdc' | 'eurc';
453
466
  /**
454
467
  * Configuration for delegation-based payments (both crypto and card schemes).
455
468
  *
456
- * To reuse an existing delegation supply `delegationId`.
457
- * To reuse an existing card (PaymentMethod entity) supply `cardId`.
458
- * When creating a brand-new delegation provide `providerPaymentMethodId`,
459
- * `spendingLimitCents`, and `durationSecs`.
469
+ * The supported flow is **create-first**: create a delegation with
470
+ * {@link DelegationAPI.createDelegation}, then request the access token with
471
+ * `delegationConfig: { delegationId }`.
472
+ *
473
+ * @remarks
474
+ * The inline create-on-the-fly fields (`providerPaymentMethodId`,
475
+ * `spendingLimitCents`, `durationSecs`, `currency`, `merchantAccountId`,
476
+ * `maxTransactions`, `cardId`) are individually deprecated. Calling
477
+ * {@link X402TokenAPI.getX402AccessToken} with a `delegationConfig` that lacks
478
+ * `delegationId` but carries one of those fields emits a runtime deprecation
479
+ * warning; create the delegation first and pass only `delegationId` (optionally
480
+ * `apiKeyId`) here. The interface itself is NOT deprecated — the
481
+ * `{ delegationId }` reuse path is the supported way to configure a token request.
460
482
  */
461
483
  export interface DelegationConfig {
462
- /** PaymentMethod entity UUID — preferred way to reference an enrolled card */
484
+ /**
485
+ * PaymentMethod entity UUID — references an enrolled card.
486
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
487
+ */
463
488
  cardId?: string;
464
- /** Existing delegation UUID to reuse instead of creating a new one */
489
+ /** Existing delegation UUID to reuse instead of creating a new one. The supported (non-deprecated) path. */
465
490
  delegationId?: string;
466
- /** Stripe payment method ID (e.g., 'pm_...'). Required only for new delegations. */
491
+ /**
492
+ * Stripe payment method ID (e.g., 'pm_...'). Required only for new delegations.
493
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
494
+ */
467
495
  providerPaymentMethodId?: string;
468
- /** Maximum spending limit in cents. Required only for new delegations. */
496
+ /**
497
+ * Maximum spending limit in cents. Required only for new delegations.
498
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
499
+ */
469
500
  spendingLimitCents?: number;
470
- /** Duration of the delegation in seconds. Required only for new delegations. */
501
+ /**
502
+ * Duration of the delegation in seconds. Required only for new delegations.
503
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
504
+ */
471
505
  durationSecs?: number;
472
- /** Currency code (default: 'usd') */
473
- currency?: string;
474
- /** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */
506
+ /**
507
+ * Currency code (e.g., 'usd' for card providers, 'usdc' for erc4337).
508
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
509
+ */
510
+ currency?: DelegationCurrency;
511
+ /**
512
+ * Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId).
513
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
514
+ */
475
515
  merchantAccountId?: string;
476
- /** Maximum number of transactions allowed */
516
+ /**
517
+ * Maximum number of transactions allowed.
518
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
519
+ */
477
520
  maxTransactions?: number;
478
- /** NVM API Key ID to scope the delegation to */
521
+ /**
522
+ * Plan ID to scope a newly-created delegation to. Optional and additive:
523
+ * delegations are plan-agnostic by default; supplying `planId` opts into a
524
+ * plan-bound delegation. (Visa delegations are always plan-specific and
525
+ * require it server-side.)
526
+ * @deprecated Inline create-on-the-fly. Create the delegation first and pass `delegationId`.
527
+ */
528
+ planId?: string;
529
+ /** NVM API Key ID to scope the delegation to. Active (non-deprecated). */
479
530
  apiKeyId?: string;
480
531
  }
481
532
  /**
@@ -490,9 +541,13 @@ export interface CreateDelegationPayload {
490
541
  spendingLimitCents: number;
491
542
  /** Duration of the delegation in seconds */
492
543
  durationSecs: number;
493
- /** Currency code (default: 'usd') */
494
- currency?: string;
495
- /** Plan ID to scope the delegation to */
544
+ /** Currency code (e.g., 'usd' for card providers, 'usdc' for erc4337). Required by the backend — no silent default. */
545
+ currency: DelegationCurrency;
546
+ /**
547
+ * Plan ID to scope the delegation to. Optional and additive: delegations are
548
+ * plan-agnostic by default; supplying `planId` opts into a plan-bound
549
+ * delegation. (Visa delegations are always plan-specific and require it.)
550
+ */
496
551
  planId?: string;
497
552
  /** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */
498
553
  merchantAccountId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,CAAA;AAEjC,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,WAAW,EAAE,eAAe,CAAA;IAE5B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,C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