@nevermined-io/payments 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +5 -3
  2. package/dist/api/base-payments.d.ts.map +1 -1
  3. package/dist/api/base-payments.js +12 -10
  4. package/dist/api/base-payments.js.map +1 -1
  5. package/dist/api/nvm-api.d.ts +0 -1
  6. package/dist/api/nvm-api.d.ts.map +1 -1
  7. package/dist/api/nvm-api.js +0 -1
  8. package/dist/api/nvm-api.js.map +1 -1
  9. package/dist/api/plans-api.d.ts +9 -30
  10. package/dist/api/plans-api.d.ts.map +1 -1
  11. package/dist/api/plans-api.js +11 -46
  12. package/dist/api/plans-api.js.map +1 -1
  13. package/dist/common/types.d.ts +23 -15
  14. package/dist/common/types.d.ts.map +1 -1
  15. package/dist/common/types.js.map +1 -1
  16. package/dist/environments.d.ts +0 -7
  17. package/dist/environments.d.ts.map +1 -1
  18. package/dist/environments.js +0 -13
  19. package/dist/environments.js.map +1 -1
  20. package/dist/index.d.ts +0 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +0 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/mcp/http/session-manager.d.ts.map +1 -1
  25. package/dist/mcp/http/session-manager.js +15 -1
  26. package/dist/mcp/http/session-manager.js.map +1 -1
  27. package/dist/payments.d.ts +17 -1
  28. package/dist/payments.d.ts.map +1 -1
  29. package/dist/payments.js +2 -10
  30. package/dist/payments.js.map +1 -1
  31. package/dist/plans.d.ts +1 -1
  32. package/dist/plans.js +6 -6
  33. package/dist/plans.js.map +1 -1
  34. package/dist/x402/delegation-api.d.ts +34 -7
  35. package/dist/x402/delegation-api.d.ts.map +1 -1
  36. package/dist/x402/delegation-api.js +15 -3
  37. package/dist/x402/delegation-api.js.map +1 -1
  38. package/dist/x402/facilitator-api.d.ts +5 -6
  39. package/dist/x402/facilitator-api.d.ts.map +1 -1
  40. package/dist/x402/facilitator-api.js +17 -5
  41. package/dist/x402/facilitator-api.js.map +1 -1
  42. package/dist/x402/index.d.ts +2 -6
  43. package/dist/x402/index.d.ts.map +1 -1
  44. package/dist/x402/index.js +1 -4
  45. package/dist/x402/index.js.map +1 -1
  46. package/package.json +23 -21
  47. package/dist/x402/visa-facilitator-api.d.ts +0 -150
  48. package/dist/x402/visa-facilitator-api.d.ts.map +0 -1
  49. package/dist/x402/visa-facilitator-api.js +0 -206
  50. package/dist/x402/visa-facilitator-api.js.map +0 -1
  51. package/dist/x402/visa-token-api.d.ts +0 -60
  52. package/dist/x402/visa-token-api.d.ts.map +0 -1
  53. package/dist/x402/visa-token-api.js +0 -99
  54. package/dist/x402/visa-token-api.js.map +0 -1
package/README.md CHANGED
@@ -33,12 +33,14 @@ The library is designed for use in browser environments or as part of AI Agents:
33
33
  ## Quickstart
34
34
 
35
35
  ```bash
36
- # yarn
37
- yarn add @nevermined-io/payments
36
+ # pnpm
37
+ pnpm add @nevermined-io/payments@^1.1
38
38
 
39
39
  # npm
40
- npm install @nevermined-io/payments
40
+ npm install @nevermined-io/payments@^1.1
41
41
  ```
42
+
43
+ > Pin the major version (or rely on a committed lockfile) so SDK upgrades are explicit. Always commit `package-lock.json` / `pnpm-lock.yaml`.
42
44
  ## A2A Integration (Agents‑to‑Agents)
43
45
 
44
46
  Nevermined Payments integrates with the A2A protocol to authorize and charge per request between agents:
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.d.ts","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAgB,MAAM,oBAAoB,CAAA;AAEnF;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,MAAM,EAAE,aAAa,CAAA;IAC/B,SAAS,CAAC,WAAW,EAAE,eAA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Ae,CAAA;IAC1C,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IAC1B,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;IAChC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;IACzB,iBAAiB,UAAO;gBAEnB,OAAO,EAAE,cAAc;IAyBnC;;;OAGG;IACH,SAAS,CAAC,cAAc,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE;IAc9E;;;OAGG;IACI,kBAAkB,IAAI,eAAe;IAI5C;;;OAGG;IACI,iBAAiB,IAAI,MAAM,GAAG,SAAS;IAI9C;;;;;;OAMG;IACH,SAAS,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;IAY1D;;;;;;;;OAQG;IACH,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;gBAE7C,MAAM;iBACL;YACP,MAAM,EAAE,MAAM,CAAA;YACd,cAAc,EAAE,MAAM,CAAA;SACvB;eACM,MAAM;;CAelB"}
@@ -9,6 +9,15 @@ import { Environments } from '../environments.js';
9
9
  export class BasePaymentsAPI {
10
10
  constructor(options) {
11
11
  this.isBrowserInstance = true;
12
+ // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers
13
+ // pinned to an older .d.ts that still has 'visa' in the union — they
14
+ // would silently fall through to the standard pipeline and hit a
15
+ // misleading 'Invalid NVM API Key' from parseNvmApiKey when the
16
+ // legacy Visa path tolerated a non-JWT key. Reject up front with a
17
+ // clear migration message.
18
+ if (options.scheme && options.scheme !== 'nvm') {
19
+ throw new PaymentsError(`scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`);
20
+ }
12
21
  this.nvmApiKey = options.nvmApiKey;
13
22
  this.scheme = options.scheme || 'nvm';
14
23
  this.returnUrl = options.returnUrl || '';
@@ -16,16 +25,9 @@ export class BasePaymentsAPI {
16
25
  this.environmentName = options.environment;
17
26
  this.appId = options.appId;
18
27
  this.version = options.version;
19
- if (this.scheme === 'visa') {
20
- // Visa scheme does not use JWT-based NVM API keys
21
- this.accountAddress = '';
22
- this.heliconeApiKey = '';
23
- }
24
- else {
25
- const { accountAddress, heliconeApiKey } = this.parseNvmApiKey();
26
- this.accountAddress = accountAddress;
27
- this.heliconeApiKey = heliconeApiKey;
28
- }
28
+ const { accountAddress, heliconeApiKey } = this.parseNvmApiKey();
29
+ this.accountAddress = accountAddress;
30
+ this.heliconeApiKey = heliconeApiKey;
29
31
  }
30
32
  /**
31
33
  * Parses the NVM API Key to extract the account address.
@@ -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;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAYnC,YAAY,OAAuB;QAF5B,sBAAiB,GAAG,IAAI,CAAA;QAG7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAA;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,WAA8B,CAAC,CAAA;QACvE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,WAAW,CAAA;QAC1C,IAAI,CAAC,KAAK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AClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C;YACD,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 * 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 public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\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\n if (this.scheme === 'visa') {\n // Visa scheme does not use JWT-based NVM API keys\n this.accountAddress = ''\n this.heliconeApiKey = ''\n } else {\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\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 HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(method: string, body?: any) {\n return {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n },\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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["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 * 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 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\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 HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(method: string, body?: any) {\n return {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n },\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"]}
@@ -12,7 +12,6 @@ export declare const API_URL_MINT_PLAN = "/api/v1/protocol/plans/mint";
12
12
  export declare const API_URL_MINT_EXPIRABLE_PLAN = "/api/v1/protocol/plans/mintExpirable";
13
13
  export declare const API_URL_ADD_PLAN_AGENT = "/api/v1/protocol/agents/:agentId/plan/:planId";
14
14
  export declare const API_URL_REMOVE_PLAN_AGENT = "/api/v1/protocol/agents/:agentId/plan/:planId";
15
- export declare const API_URL_REDEEM_PLAN = "/api/v1/protocol/plans/redeem";
16
15
  export declare const API_URL_PLAN_BALANCE = "/api/v1/protocol/plans/:planId/balance/:holderAddress";
17
16
  export declare const API_URL_INITIALIZE_AGENT = "/api/v1/protocol/agents/initialize/:agentId";
18
17
  export declare const API_URL_SIMULATE_AGENT_REQUEST = "/api/v1/protocol/agents/simulate/start";
@@ -1 +1 @@
1
- {"version":3,"file":"nvm-api.d.ts","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,2BAA2B,CAAA;AAC7D,eAAO,MAAM,sBAAsB,4BAA4B,CAAA;AAC/D,eAAO,MAAM,gCAAgC,kCAAkC,CAAA;AAC/E,eAAO,MAAM,iBAAiB,qCAAqC,CAAA;AACnE,eAAO,MAAM,oBAAoB,qCAAqC,CAAA;AACtE,eAAO,MAAM,uBAAuB,2CAA2C,CAAA;AAC/E,eAAO,MAAM,gBAAgB,mCAAmC,CAAA;AAChE,eAAO,MAAM,iBAAiB,2BAA2B,CAAA;AACzD,eAAO,MAAM,uBAAuB,0CAA0C,CAAA;AAC9E,eAAO,MAAM,kBAAkB,yCAAyC,CAAA;AACxE,eAAO,MAAM,iBAAiB,gCAAgC,CAAA;AAC9D,eAAO,MAAM,2BAA2B,yCAAyC,CAAA;AACjF,eAAO,MAAM,sBAAsB,kDAAkD,CAAA;AACrF,eAAO,MAAM,yBAAyB,kDAAkD,CAAA;AACxF,eAAO,MAAM,mBAAmB,kCAAkC,CAAA;AAClE,eAAO,MAAM,oBAAoB,0DAA0D,CAAA;AAC3F,eAAO,MAAM,wBAAwB,gDAAgD,CAAA;AACrF,eAAO,MAAM,8BAA8B,2CAA2C,CAAA;AACtF,eAAO,MAAM,qCAAqC,4CAA4C,CAAA;AAC9F,eAAO,MAAM,4BAA4B,qCAAqC,CAAA;AAC9E,eAAO,MAAM,mCAAmC,6CAA6C,CAAA;AAC7F,eAAO,MAAM,yBAAyB,6BAA6B,CAAA;AACnE,eAAO,MAAM,0BAA0B,wBAAwB,CAAA;AAC/D,eAAO,MAAM,0BAA0B,wBAAwB,CAAA;AAC/D,eAAO,MAAM,uBAAuB,gCAAgC,CAAA;AACp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@ export const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint';
13
13
  export const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable';
14
14
  export const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId';
15
15
  export const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId';
16
- export const API_URL_REDEEM_PLAN = '/api/v1/protocol/plans/redeem';
17
16
  export const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress';
18
17
  export const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId';
19
18
  export const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start';
@@ -1 +1 @@
1
- {"version":3,"file":"nvm-api.js","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAA;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAA;AAC/D,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAA;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,kCAAkC,CAAA;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,wCAAwC,CAAA;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,gCAAgC,CAAA;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,uCAAuC,CAAA;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAA;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,sCAAsC,CAA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/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REDEEM_PLAN = '/api/v1/protocol/plans/redeem'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
1
+ {"version":3,"file":"nvm-api.js","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAA;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAA;AAC/D,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAA;AAC/E,MAAM,CAAC,MAAM,iBAAi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ACpD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import axios from 'axios'\n\nexport const API_URL_REGISTER_PLAN = '/api/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
@@ -103,13 +103,19 @@ export declare class PlansAPI extends BasePaymentsAPI {
103
103
  */
104
104
  setRedemptionType(creditsConfig: PlanCreditsConfig, redemptionType: PlanRedemptionType): PlanCreditsConfig;
105
105
  /**
106
- * Marks whether proof is required in a credits configuration.
106
+ * Marks whether burns of these credits are mirrored on-chain.
107
107
  *
108
108
  * @param creditsConfig - Credits configuration to modify.
109
- * @param proofRequired - Whether proof is required (default true).
109
+ * @param onchainMirror - Whether on-chain mirroring is enabled. Defaults
110
+ * to `true` so calling `setOnchainMirror(config)` enables the mirror;
111
+ * pass `false` explicitly to disable it. The `PlanCreditsConfig`
112
+ * field itself defaults to `false` (set by all credits-config
113
+ * builders) — when `false` the credits ledger lives in the API's
114
+ * Postgres and burns are recorded off-chain only; when `true`, an
115
+ * on-chain audit mirror replays each burn to `NFT1155Credits`.
110
116
  * @returns The updated PlanCreditsConfig.
111
117
  */
112
- setProofRequired(creditsConfig: PlanCreditsConfig, proofRequired?: boolean): PlanCreditsConfig;
118
+ setOnchainMirror(creditsConfig: PlanCreditsConfig, onchainMirror?: boolean): PlanCreditsConfig;
113
119
  /**
114
120
  * This method is used to create a singleton instance of the PlansAPI class.
115
121
  *
@@ -433,32 +439,5 @@ export declare class PlansAPI extends BasePaymentsAPI {
433
439
  * ```
434
440
  */
435
441
  mintPlanExpirable(planId: string, creditsAmount: bigint, creditsReceiver: Address, creditsDuration?: bigint): Promise<NvmAPIResult>;
436
- /**
437
- * Burns/redeem credits for a given Payment Plan.
438
- *
439
- * @remarks
440
- * Only the owner of the Payment Plan can call this method.
441
- *
442
- * @param agentRequestId - The unique identifier of the agent request to track the operation. This ID is generated via the `requests.startProcessingRequest` method
443
- * @param planId - The unique identifier of the Payment Plan.
444
- * @param redeemFrom - The address of the account to redeem from.
445
- * @param creditsAmountToRedeem - The amount of credits to redeem.
446
- * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.
447
- * @throws PaymentsError if unable to burn credits.
448
- *
449
- * ```
450
- * const result = await payments.plans.redeemCredits(
451
- * 'request-id-12345', // The request ID to track the operation
452
- * planId,
453
- * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359', // The address of the account to redeem from
454
- * 5n
455
- * )
456
- * // {
457
- * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',
458
- * // success: true
459
- * // }
460
- * ```
461
- */
462
- redeemCredits(agentRequestId: string, planId: string, redeemFrom: Address, creditsAmountToRedeem: string): Promise<NvmAPIResult>;
463
442
  }
464
443
  //# sourceMappingURL=plans-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plans-api.d.ts","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAgBpD;;GAEG;AACH,qBAAa,QAAS,SAAQ,eAAe;IAC3C,OAAO,CAAC,YAAY,CAAc;gBAEtB,OAAO,EAAE,cAAc;IAInC,oBAAoB;IACpB;;;;;;;OAOG;IACI,kBAAkB,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,QAAQ,GAAE,QAAQ,GAAG,MAAqB,GACzC,eAAe;IAIlB;;OAEG;IACU,wBAAwB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,YAAY,GAAE,OAAqB,GAClC,OAAO,CAAC,eAAe,CAAC;IAK3B;;OAEG;IACI,0BAA0B,IAAI,iBAAiB;IAItD;;;;;;;OAOG;IACI,oBAAoB,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,YAAY,CAAC,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OG;IACU,QAAQ,CAAC,IAAI,SAAI,EAAE,MAAM,SAAM,EAAE,MAAM,SAAY,EAAE,SAAS,SAAS;IAgBpF;;;;;;;;;;;;;;;;;;;OAmBG;IACU,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,oBAA0B;IAW5F;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IA8B3F;;;;;;;;;;;;;;;;;;OAkBG;IACU,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,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;CAWzB"}
@@ -5,7 +5,7 @@ import { getRandomBigInt, isEthereumAddress } from '../utils.js';
5
5
  import { BasePaymentsAPI } from './base-payments.js';
6
6
  import * as Plans from '../plans.js';
7
7
  import { ContractsAPI } from './contracts-api.js';
8
- import { API_URL_REDEEM_PLAN, API_URL_GET_PLAN, API_URL_GET_PLAN_AGENTS, API_URL_MINT_EXPIRABLE_PLAN, API_URL_MINT_PLAN, API_URL_ORDER_PLAN, API_URL_PLAN_BALANCE, API_URL_REGISTER_PLAN, API_URL_STRIPE_CHECKOUT, API_URL_GET_PLANS, } from './nvm-api.js';
8
+ import { API_URL_GET_PLAN, API_URL_GET_PLAN_AGENTS, API_URL_MINT_EXPIRABLE_PLAN, API_URL_MINT_PLAN, API_URL_ORDER_PLAN, API_URL_PLAN_BALANCE, API_URL_REGISTER_PLAN, API_URL_STRIPE_CHECKOUT, API_URL_GET_PLANS, } from './nvm-api.js';
9
9
  /**
10
10
  * The PlansAPI class provides methods to register and interact with payment plans on Nevermined.
11
11
  */
@@ -138,14 +138,20 @@ export class PlansAPI extends BasePaymentsAPI {
138
138
  return Plans.setRedemptionType(creditsConfig, redemptionType);
139
139
  }
140
140
  /**
141
- * Marks whether proof is required in a credits configuration.
141
+ * Marks whether burns of these credits are mirrored on-chain.
142
142
  *
143
143
  * @param creditsConfig - Credits configuration to modify.
144
- * @param proofRequired - Whether proof is required (default true).
144
+ * @param onchainMirror - Whether on-chain mirroring is enabled. Defaults
145
+ * to `true` so calling `setOnchainMirror(config)` enables the mirror;
146
+ * pass `false` explicitly to disable it. The `PlanCreditsConfig`
147
+ * field itself defaults to `false` (set by all credits-config
148
+ * builders) — when `false` the credits ledger lives in the API's
149
+ * Postgres and burns are recorded off-chain only; when `true`, an
150
+ * on-chain audit mirror replays each burn to `NFT1155Credits`.
145
151
  * @returns The updated PlanCreditsConfig.
146
152
  */
147
- setProofRequired(creditsConfig, proofRequired = true) {
148
- return Plans.setProofRequired(creditsConfig, proofRequired);
153
+ setOnchainMirror(creditsConfig, onchainMirror = true) {
154
+ return Plans.setOnchainMirror(creditsConfig, onchainMirror);
149
155
  }
150
156
  /**
151
157
  * This method is used to create a singleton instance of the PlansAPI class.
@@ -591,46 +597,5 @@ export class PlansAPI extends BasePaymentsAPI {
591
597
  }
592
598
  return response.json();
593
599
  }
594
- /**
595
- * Burns/redeem credits for a given Payment Plan.
596
- *
597
- * @remarks
598
- * Only the owner of the Payment Plan can call this method.
599
- *
600
- * @param agentRequestId - The unique identifier of the agent request to track the operation. This ID is generated via the `requests.startProcessingRequest` method
601
- * @param planId - The unique identifier of the Payment Plan.
602
- * @param redeemFrom - The address of the account to redeem from.
603
- * @param creditsAmountToRedeem - The amount of credits to redeem.
604
- * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.
605
- * @throws PaymentsError if unable to burn credits.
606
- *
607
- * ```
608
- * const result = await payments.plans.redeemCredits(
609
- * 'request-id-12345', // The request ID to track the operation
610
- * planId,
611
- * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359', // The address of the account to redeem from
612
- * 5n
613
- * )
614
- * // {
615
- * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',
616
- * // success: true
617
- * // }
618
- * ```
619
- */
620
- async redeemCredits(agentRequestId, planId, redeemFrom, creditsAmountToRedeem) {
621
- const body = {
622
- agentRequestId,
623
- planId,
624
- redeemFrom,
625
- amount: creditsAmountToRedeem,
626
- };
627
- const options = this.getBackendHTTPOptions('POST', body);
628
- const url = new URL(API_URL_REDEEM_PLAN, this.environment.backend);
629
- const response = await fetch(url, options);
630
- if (!response.ok) {
631
- throw PaymentsError.fromBackend('Unable to redeem credits', await response.json());
632
- }
633
- return response.json();
634
- }
635
600
  }
636
601
  //# sourceMappingURL=plans-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plans-api.js","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAAA,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,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OA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,CAAC,CAAA;QAClE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAAC,0BAA0B,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;QACpF,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { 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 } from './base-payments.js'\nimport * as Plans from '../plans.js'\nimport { ContractsAPI } from './contracts-api.js'\nimport {\n API_URL_REDEEM_PLAN,\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 * @param amount - Amount to charge in minor units (e.g., cents) 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 proof is required in a credits configuration.\n *\n * @param creditsConfig - Credits configuration to modify.\n * @param proofRequired - Whether proof is required (default true).\n * @returns The updated PlanCreditsConfig.\n */\n public setProofRequired(\n creditsConfig: PlanCreditsConfig,\n proofRequired = true,\n ): PlanCreditsConfig {\n return Plans.setProofRequired(creditsConfig, proofRequired)\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 ): 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('POST', body)\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 ): 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(planMetadata, priceConfig, creditsConfig, undefined, 'credits')\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 ): 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(planMetadata, priceConfig, creditsConfig, undefined, 'time')\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 ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig)\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 ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerTimePlan(planMetadata, priceConfig, creditsConfig)\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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('Unable to mint expirable credits', await response.json())\n }\n\n return response.json()\n }\n\n /**\n * Burns/redeem credits for a given Payment Plan.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param agentRequestId - The unique identifier of the agent request to track the operation. This ID is generated via the `requests.startProcessingRequest` method\n * @param planId - The unique identifier of the Payment Plan.\n * @param redeemFrom - The address of the account to redeem from.\n * @param creditsAmountToRedeem - The amount of credits to redeem.\n * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation.\n * @throws PaymentsError if unable to burn credits.\n *\n * ```\n * const result = await payments.plans.redeemCredits(\n * 'request-id-12345', // The request ID to track the operation\n * planId,\n * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359', // The address of the account to redeem from\n * 5n\n * )\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async redeemCredits(\n agentRequestId: string,\n planId: string,\n redeemFrom: Address,\n creditsAmountToRedeem: string,\n ): Promise<NvmAPIResult> {\n const body = {\n agentRequestId,\n planId,\n redeemFrom,\n amount: creditsAmountToRedeem,\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_REDEEM_PLAN, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to redeem credits', await response.json())\n }\n\n return response.json()\n }\n}\n"]}
1
+ {"version":3,"file":"plans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QAC5F,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { 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 } 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 * @param amount - Amount to charge in minor units (e.g., cents) 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 ): 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('POST', body)\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 ): 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(planMetadata, priceConfig, creditsConfig, undefined, 'credits')\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 ): 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(planMetadata, priceConfig, creditsConfig, undefined, 'time')\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 ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig)\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 ): Promise<{ planId: string }> {\n planMetadata.isTrialPlan = true\n return this.registerTimePlan(planMetadata, priceConfig, creditsConfig)\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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 response.json())\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('Unable to mint expirable credits', await response.json())\n }\n\n return response.json()\n }\n}\n"]}