@nevermined-io/payments 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/dist/a2a/paymentsClient.d.ts +6 -0
- package/dist/a2a/paymentsClient.d.ts.map +1 -1
- package/dist/a2a/paymentsClient.js +8 -0
- package/dist/a2a/paymentsClient.js.map +1 -1
- package/dist/a2a/server.d.ts +0 -1
- package/dist/a2a/server.d.ts.map +1 -1
- package/dist/api/agents-api.d.ts +2 -2
- package/dist/api/agents-api.js +2 -2
- package/dist/api/agents-api.js.map +1 -1
- package/dist/api/base-payments.d.ts +2 -2
- package/dist/api/base-payments.d.ts.map +1 -1
- package/dist/api/nvm-api.d.ts +1 -1
- package/dist/api/nvm-api.js.map +1 -1
- package/dist/api/plans-api.d.ts +5 -5
- package/dist/api/plans-api.js +5 -5
- package/dist/api/plans-api.js.map +1 -1
- package/dist/common/helper.d.ts.map +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/common/types.js.map +1 -1
- package/dist/mcp/core/auth.d.ts +14 -2
- package/dist/mcp/core/auth.d.ts.map +1 -1
- package/dist/mcp/core/auth.js +107 -197
- package/dist/mcp/core/auth.js.map +1 -1
- package/dist/mcp/core/paywall.d.ts.map +1 -1
- package/dist/mcp/core/paywall.js +42 -20
- package/dist/mcp/core/paywall.js.map +1 -1
- package/dist/mcp/http/mcp-handler.d.ts +0 -1
- package/dist/mcp/http/mcp-handler.d.ts.map +1 -1
- package/dist/mcp/http/oauth-router.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +7 -8
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/types/http.types.d.ts +0 -1
- package/dist/mcp/types/http.types.d.ts.map +1 -1
- package/dist/mcp/types/paywall.types.d.ts +6 -0
- package/dist/mcp/types/paywall.types.d.ts.map +1 -1
- package/dist/mcp/types/paywall.types.js.map +1 -1
- package/dist/payments.d.ts +12 -13
- package/dist/payments.d.ts.map +1 -1
- package/dist/plans.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +7 -2
|
@@ -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,EAGL,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,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,eAAe;IAG3C,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;IAC/C,CAAC;IACD,oBAAoB;IACpB;;;;;;OAMG;IACI,kBAAkB,CAAC,MAAc,EAAE,QAAiB;QACzD,OAAO,KAAK,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,wBAAwB,CACnC,MAAc,EACd,QAAiB,EACjB,eAAwB,WAAW;QAEnC,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,4BAA4B,EAAE,CAAA;QAC9E,OAAO,KAAK,C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AC9B,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,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 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 * @returns The PlanPriceConfig representing a fiat price.\n */\n public getFiatPriceConfig(amount: bigint, receiver: Address): PlanPriceConfig {\n return Plans.getFiatPriceConfig(amount, receiver)\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 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://docs.nevermined.app/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 = 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 }\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://docs.nevermined.app/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 (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://docs.nevermined.app/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 (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://docs.nevermined.app/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://docs.nevermined.app/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-api.js","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAGL,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,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QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { PaymentsError } from '../common/payments.error.js'\nimport {\n 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 * @returns The PlanPriceConfig representing a fiat price.\n */\n public getFiatPriceConfig(amount: bigint, receiver: Address): PlanPriceConfig {\n return Plans.getFiatPriceConfig(amount, receiver)\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 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 = 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 }\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 (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 (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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/common/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,eAAO,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/common/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBAAsD,CAAA;AAEtF,eAAO,MAAM,YAAY,GAAI,MAAM,GAAG,EAAE,OAAO;IAAE,QAAQ,EAAE,MAAM,GAAG,CAAA;CAAE;cAAX,MAAM,GAAG;CAEnE,CAAA;AAED,eAAO,MAAM,2BAA2B,GAAI,WAAW,QAAQ,EAAE,KAAG,MAOnE,CAAA"}
|
package/dist/common/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface PaymentOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.
|
|
14
14
|
* You can get your API key by logging in to the Nevermined App.
|
|
15
|
-
* @see https://
|
|
15
|
+
* @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys
|
|
16
16
|
*/
|
|
17
17
|
nvmApiKey: string;
|
|
18
18
|
/**
|
package/dist/common/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AA8HA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,+DAAW,CAAA;IACX,yEAAgB,CAAA;IAChB,iFAAoB,CAAA;AACtB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,+DAAS,CAAA;IACT,uDAAK,CAAA;IACL,2DAAO,CAAA;AACT,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,mFAAoB,CAAA;IACpB,uEAAc,CAAA;IACd,+EAAkB,CAAA;IAClB,iFAAmB,CAAA;AACrB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAoKD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAsB5B;;;OAGG;IACH,YAAY,OAAoC;QApBhD;;;WAGG;QACH,cAAS,GAAmB,MAAM,CAAA;QAClC;;;WAGG;QACH,SAAI,GAAG,CAAC,CAAA;QACR;;;WAGG;QACH,WAAM,GAAG,EAAE,CAAA;QAOT,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;YAC5B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAA;YAC5C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAA;YAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;QACpC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,MAAM,MAAM,GAA2B,EAAE,CAAA;QACzC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAC7B,CAAC;QACD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QACjC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAClC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;QAExC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC/C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B","sourcesContent":["import { EnvironmentName } from '../environments.js'\n\n/**\n * Options to initialize the Payments class.\n */\nexport interface PaymentOptions {\n /**\n * The Nevermined environment to connect to.\n * If you are developing an agent it's recommended to use the \"sandbox\" environment.\n * When deploying to live use the \"live\" environment.\n */\n environment: EnvironmentName\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://docs.nevermined.app/docs/tutorials/integration/nvm-api-keys\n */\n nvmApiKey: string\n\n /**\n * The URL to return to the app after a successful login.\n */\n returnUrl?: string\n\n /**\n * The app id. This attribute is optional and helps to associate assets registered into Nevermined with a common identifier.\n */\n appId?: string\n\n /**\n * The version of the API to use.\n */\n version?: string\n}\n\nexport interface Endpoint {\n [verb: string]: string\n}\n\nexport interface ApiResponse<T> {\n success: boolean\n data?: T\n error?: string\n}\n\nexport type Address = `0x${string}`\n\n/**\n * Definition of the price configuration for a Payment Plan\n */\nexport interface PlanPriceConfig {\n /**\n * The address of the token (ERC20 or Native if zero address) for paying the plan\n */\n tokenAddress?: Address\n /**\n * The amounts to be paid for the plan\n */\n amounts: bigint[]\n /**\n * The receivers of the payments of the plan\n */\n receivers: string[]\n /**\n * The address of the smart contract that calculates the price\n */\n contractAddress?: Address\n /**\n * The address of the fee controller contract, if any\n * @remarks if not given, the fee controller is the default one\n */\n feeController?: Address\n /**\n * The address of the external price contract, if any\n */\n externalPriceAddress?: Address\n /**\n * The address of the template contract, if any\n */\n templateAddress?: Address\n /**\n * Whether this is a crypto payment (true) or fiat payment (false)\n */\n isCrypto: boolean\n}\n\n/**\n * Definition of the credits configuration for a payment plan\n */\nexport interface PlanCreditsConfig {\n /**\n * Whether the redemption amount is fixed (true) or dynamic (false)\n */\n isRedemptionAmountFixed: boolean\n /**\n * How the credits can be redeemed\n */\n redemptionType: PlanRedemptionType\n /**\n * Whether the credits burn proof signed by the user is required\n */\n proofRequired: boolean\n /**\n * The duration of the credits in seconds\n * @remarks 0 means non-expirable\n */\n durationSecs: bigint\n /**\n * The amount of credits that are granted when purchasing the plan (as string for API)\n */\n amount: bigint\n /**\n * The minimum number of credits redeemed when using the plan\n */\n minAmount: bigint\n /**\n * The maximum number of credits redeemed when using the plan\n */\n maxAmount: bigint\n /**\n * The address of the NFT contract that represents the plan's credits\n */\n nftAddress?: Address\n}\n\n/**\n * Different types of prices that can be configured for a plan\n * @remarks 0 - FIXED_PRICE, 1 - FIXED_FIAT_PRICE, 2 - SMART_CONTRACT_PRICE\n * If FIXED_PRICE it means the plan can be paid in crypto by a fixed amount of a ERC20 or Native token\n * If FIXED_FIAT_PRICE it means the plan can be paid in fiat by a fixed amount (typically USD)\n * If SMART_CONTRACT_PRICE it means the plan can be paid in crypto and the amount to be paid is calculated by a smart contract\n */\nexport enum PlanPriceType {\n FIXED_PRICE,\n FIXED_FIAT_PRICE,\n SMART_CONTRACT_PRICE,\n}\n\n/**\n * Different types of credits that can be obtained when purchasing a plan\n * @remarks 0 - EXPIRABLE, 1 - FIXED, 2 - DYNAMIC\n * If EXPIRABLE it means the credits can be used for a fixed amount of time (calculated in seconds)\n * If FIXED it means the credits can be used for a fixed amount of times\n * If DYNAMIC it means the credits can be used but the redemption amount is dynamic\n */\nexport enum PlanCreditsType {\n EXPIRABLE,\n FIXED,\n DYNAMIC,\n}\n\n/**\n * Different types of redemptions criterias that can be used when redeeming credits\n * @remarks 0 - ONLY_GLOBAL_ROLE, 1 - ONLY_OWNER, 2 - ROLE_AND_OWNER\n * If ONLY_GLOBAL_ROLE it means the credits can be redeemed only by an account with the `CREDITS_BURNER_ROLE`\n * If ONLY_OWNER it means the credits can be redeemed only by the owner of the Plan\n * If ONLY_PLAN_ROLE it means the credits can be redeemed by an account with specifics grants for the plan\n * If ONLY_SUBSCRIBER means only the subscriber (the one who holds the credits NFT) can redeem\n */\nexport enum PlanRedemptionType {\n ONLY_GLOBAL_ROLE = 0, // NVM Proxy can burn\n ONLY_OWNER = 1, // Agent can burn\n ONLY_PLAN_ROLE = 2,\n ONLY_SUBSCRIBER = 4, // Subscriber who ordered the plan can redeem\n}\n\nexport interface PlanBalance {\n planId: string\n planName: string\n planType: string\n holderAddress: Address\n balance: bigint\n creditsContract: Address\n isSubscriber: boolean\n pricePerCredit: number\n}\n\nexport interface StartAgentRequest {\n agentRequestId: string\n agentName: string\n agentId: string\n balance: PlanBalance\n urlMatching: string\n verbMatching: string\n batch: boolean\n}\n\nexport interface ValidationAgentRequest {\n balance: PlanBalance\n urlMatching: string\n verbMatching: string\n}\n\nexport interface AgentAccessCredentials {\n accessToken: string\n proxies?: string[]\n}\n\nexport interface SubscriberRequestStatus {\n planId: string\n agentId: string\n isValid: boolean\n code: number\n message?: string\n}\n\nexport interface NvmAPIResult {\n success: boolean\n message?: string\n txHash?: string\n httpStatus?: number\n data?: APIOutputData\n when?: Date\n}\n\nexport interface APIOutputData {\n [key: string]: any\n}\n\nexport interface StripeCheckoutResult {\n stripeCheckoutSessionId: string\n checkoutLink: string\n clientReferenceId: string\n paymentStatus?: string\n linkCreatedAt: number\n linkExpiresAt: number\n}\n\n/**\n * Metadata attributes describing the AI Agent.\n */\nexport interface AgentMetadata {\n /**\n * Name of the Agent\n */\n name: string\n /**\n * Description of the Agent\n */\n description?: string\n /**\n * The author of the Agent (organization or person) that own the Agent.\n */\n author?: string\n /**\n * The author of the Agent (organization or person) that own the Agent.\n */\n license?: string\n /**\n * Tags describing the AI Agent\n */\n tags?: string[]\n /**\n * Some description or instructions about how to integrate the Agent.\n */\n integration?: string\n /**\n * A link to some same usage of the Agent.\n */\n sampleLink?: string\n /**\n * Text describing the API of the Agent.\n */\n apiDescription?: string\n /**\n * The date when the Agent was created.\n */\n dateCreated?: Date\n\n // internalAttributes?: any\n}\n\n/**\n * Metadata attributes describing the Payment Plan.\n */\nexport interface PlanMetadata extends AgentMetadata {\n /**\n * Indicates if a payment plan is a Trial plan.\n * A Trial plan is a plan that allows users to test the AI Agents associated with it typically without any cost.\n * @remarks A Trial plan only can be purchased once by a user.\n */\n isTrialPlan?: boolean\n /**\n * Indicates if a payment plan is limited by credits.\n * If 'time', the plan will be limited by time.\n * If 'credits', the plan will be limited by credits.\n */\n accessLimit?: 'credits' | 'time'\n}\n\n/**\n * It describes the API exposed by an AI Agent.\n * This information is necessary to query the AI Agent and to know which endpoints are available.\n */\nexport interface AgentAPIAttributes {\n /**\n * The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.\n */\n endpoints: Endpoint[]\n /**\n * The list of endpoints of the upstream service that publicly available. The access to these endpoints don't require subscription to the Payment Plan. They are useful to expose documentation, etc.\n */\n openEndpoints?: string[]\n /**\n * The URL to the agent definition. Can be an OpenAPI spec, MCP Manifest, or A2A agent card. This field is mandatory and defines how the agent/service can be discovered and queried.\n */\n agentDefinitionUrl: string\n\n /////// AUTHORIZATION ///////\n\n /**\n * The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').\n */\n authType?: 'none' | 'basic' | 'oauth' | 'bearer'\n /**\n * The upstream agent/service username for authentication. Only if `authType` is 'basic'.\n */\n username?: string\n /**\n * The upstream agent/service password for authentication. Only if `authType` is 'basic'.\n */\n password?: string\n /**\n * The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.\n */\n token?: string\n}\n\n/**\n * Options for pagination in API requests to the Nevermined API.\n */\nexport class PaginationOptions {\n /**\n * The field to sort the results by.\n * If not provided, the default sorting defined by the API will be applied.\n */\n sortBy?: string\n /**\n * The order in which to sort the results.\n * Default is 'desc' (descending).\n */\n sortOrder: 'asc' | 'desc' = 'desc'\n /**\n * The page number to retrieve.\n * Default is 1.\n */\n page = 1\n /**\n * The number of items per page.\n * Default is 10.\n */\n offset = 10\n\n /**\n * Constructs a new PaginationOptions instance.\n * @param options - Optional initial values for the pagination options.\n */\n constructor(options?: Partial<PaginationOptions>) {\n if (options) {\n this.sortBy = options.sortBy\n this.sortOrder = options.sortOrder || 'desc'\n this.page = options.page || 1\n this.offset = options.offset || 10\n }\n }\n\n /**\n * It returns a string representation of the pagination options\n * @returns A string representation of the pagination options as URL query parameters.\n * This can be used to append to API requests for pagination.\n */\n asQueryParams(): string {\n const params: Record<string, string> = {}\n if (this.sortBy) {\n params.sortBy = this.sortBy\n }\n params.sortOrder = this.sortOrder\n params.page = this.page.toString()\n params.pageSize = this.offset.toString()\n\n return new URLSearchParams(params).toString()\n }\n}\n\n/**\n * Status of an agent task\n */\nexport enum AgentTaskStatus {\n SUCCESS = 'SUCCESS',\n FAILED = 'FAILED',\n PENDING = 'PENDING',\n}\n\n/**\n * Data transfer object for tracking agent sub tasks\n */\nexport interface TrackAgentSubTaskDto {\n /**\n * The unique identifier of the agent task\n */\n agentRequestId: string\n\n /**\n * The number of credits burned in this agent sub task (optional)\n * @defaultValue 0\n */\n creditsToRedeem?: number\n\n /**\n * A tag to categorize this agent sub task (optional)\n */\n tag?: string\n\n /**\n * A description of this agent sub task (optional)\n */\n description?: string\n\n /**\n * The status of the agent sub task (optional)\n */\n status?: AgentTaskStatus\n}\n\nexport type SimulationRequestOptions = {\n agentName?: string\n planName?: string\n batch?: boolean\n pricePerCredit?: number\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AA8HA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,+DAAW,CAAA;IACX,yEAAgB,CAAA;IAChB,iFAAoB,CAAA;AACtB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,+DAAS,CAAA;IACT,uDAAK,CAAA;IACL,2DAAO,CAAA;AACT,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,mFAAoB,CAAA;IACpB,uEAAc,CAAA;IACd,+EAAkB,CAAA;IAClB,iFAAmB,CAAA;AACrB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAoKD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAsB5B;;;OAGG;IACH,YAAY,OAAoC;QApBhD;;;WAGG;QACH,cAAS,GAAmB,MAAM,CAAA;QAClC;;;WAGG;QACH,SAAI,GAAG,CAAC,CAAA;QACR;;;WAGG;QACH,WAAM,GAAG,EAAE,CAAA;QAOT,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;YAC5B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAA;YAC5C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAA;YAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;QACpC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,MAAM,MAAM,GAA2B,EAAE,CAAA;QACzC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAC7B,CAAC;QACD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QACjC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAClC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;QAExC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC/C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B","sourcesContent":["import { EnvironmentName } from '../environments.js'\n\n/**\n * Options to initialize the Payments class.\n */\nexport interface PaymentOptions {\n /**\n * The Nevermined environment to connect to.\n * If you are developing an agent it's recommended to use the \"sandbox\" environment.\n * When deploying to live use the \"live\" environment.\n */\n environment: EnvironmentName\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 nvmApiKey: string\n\n /**\n * The URL to return to the app after a successful login.\n */\n returnUrl?: string\n\n /**\n * The app id. This attribute is optional and helps to associate assets registered into Nevermined with a common identifier.\n */\n appId?: string\n\n /**\n * The version of the API to use.\n */\n version?: string\n}\n\nexport interface Endpoint {\n [verb: string]: string\n}\n\nexport interface ApiResponse<T> {\n success: boolean\n data?: T\n error?: string\n}\n\nexport type Address = `0x${string}`\n\n/**\n * Definition of the price configuration for a Payment Plan\n */\nexport interface PlanPriceConfig {\n /**\n * The address of the token (ERC20 or Native if zero address) for paying the plan\n */\n tokenAddress?: Address\n /**\n * The amounts to be paid for the plan\n */\n amounts: bigint[]\n /**\n * The receivers of the payments of the plan\n */\n receivers: string[]\n /**\n * The address of the smart contract that calculates the price\n */\n contractAddress?: Address\n /**\n * The address of the fee controller contract, if any\n * @remarks if not given, the fee controller is the default one\n */\n feeController?: Address\n /**\n * The address of the external price contract, if any\n */\n externalPriceAddress?: Address\n /**\n * The address of the template contract, if any\n */\n templateAddress?: Address\n /**\n * Whether this is a crypto payment (true) or fiat payment (false)\n */\n isCrypto: boolean\n}\n\n/**\n * Definition of the credits configuration for a payment plan\n */\nexport interface PlanCreditsConfig {\n /**\n * Whether the redemption amount is fixed (true) or dynamic (false)\n */\n isRedemptionAmountFixed: boolean\n /**\n * How the credits can be redeemed\n */\n redemptionType: PlanRedemptionType\n /**\n * Whether the credits burn proof signed by the user is required\n */\n proofRequired: boolean\n /**\n * The duration of the credits in seconds\n * @remarks 0 means non-expirable\n */\n durationSecs: bigint\n /**\n * The amount of credits that are granted when purchasing the plan (as string for API)\n */\n amount: bigint\n /**\n * The minimum number of credits redeemed when using the plan\n */\n minAmount: bigint\n /**\n * The maximum number of credits redeemed when using the plan\n */\n maxAmount: bigint\n /**\n * The address of the NFT contract that represents the plan's credits\n */\n nftAddress?: Address\n}\n\n/**\n * Different types of prices that can be configured for a plan\n * @remarks 0 - FIXED_PRICE, 1 - FIXED_FIAT_PRICE, 2 - SMART_CONTRACT_PRICE\n * If FIXED_PRICE it means the plan can be paid in crypto by a fixed amount of a ERC20 or Native token\n * If FIXED_FIAT_PRICE it means the plan can be paid in fiat by a fixed amount (typically USD)\n * If SMART_CONTRACT_PRICE it means the plan can be paid in crypto and the amount to be paid is calculated by a smart contract\n */\nexport enum PlanPriceType {\n FIXED_PRICE,\n FIXED_FIAT_PRICE,\n SMART_CONTRACT_PRICE,\n}\n\n/**\n * Different types of credits that can be obtained when purchasing a plan\n * @remarks 0 - EXPIRABLE, 1 - FIXED, 2 - DYNAMIC\n * If EXPIRABLE it means the credits can be used for a fixed amount of time (calculated in seconds)\n * If FIXED it means the credits can be used for a fixed amount of times\n * If DYNAMIC it means the credits can be used but the redemption amount is dynamic\n */\nexport enum PlanCreditsType {\n EXPIRABLE,\n FIXED,\n DYNAMIC,\n}\n\n/**\n * Different types of redemptions criterias that can be used when redeeming credits\n * @remarks 0 - ONLY_GLOBAL_ROLE, 1 - ONLY_OWNER, 2 - ROLE_AND_OWNER\n * If ONLY_GLOBAL_ROLE it means the credits can be redeemed only by an account with the `CREDITS_BURNER_ROLE`\n * If ONLY_OWNER it means the credits can be redeemed only by the owner of the Plan\n * If ONLY_PLAN_ROLE it means the credits can be redeemed by an account with specifics grants for the plan\n * If ONLY_SUBSCRIBER means only the subscriber (the one who holds the credits NFT) can redeem\n */\nexport enum PlanRedemptionType {\n ONLY_GLOBAL_ROLE = 0, // NVM Proxy can burn\n ONLY_OWNER = 1, // Agent can burn\n ONLY_PLAN_ROLE = 2,\n ONLY_SUBSCRIBER = 4, // Subscriber who ordered the plan can redeem\n}\n\nexport interface PlanBalance {\n planId: string\n planName: string\n planType: string\n holderAddress: Address\n balance: bigint\n creditsContract: Address\n isSubscriber: boolean\n pricePerCredit: number\n}\n\nexport interface StartAgentRequest {\n agentRequestId: string\n agentName: string\n agentId: string\n balance: PlanBalance\n urlMatching: string\n verbMatching: string\n batch: boolean\n}\n\nexport interface ValidationAgentRequest {\n balance: PlanBalance\n urlMatching: string\n verbMatching: string\n}\n\nexport interface AgentAccessCredentials {\n accessToken: string\n proxies?: string[]\n}\n\nexport interface SubscriberRequestStatus {\n planId: string\n agentId: string\n isValid: boolean\n code: number\n message?: string\n}\n\nexport interface NvmAPIResult {\n success: boolean\n message?: string\n txHash?: string\n httpStatus?: number\n data?: APIOutputData\n when?: Date\n}\n\nexport interface APIOutputData {\n [key: string]: any\n}\n\nexport interface StripeCheckoutResult {\n stripeCheckoutSessionId: string\n checkoutLink: string\n clientReferenceId: string\n paymentStatus?: string\n linkCreatedAt: number\n linkExpiresAt: number\n}\n\n/**\n * Metadata attributes describing the AI Agent.\n */\nexport interface AgentMetadata {\n /**\n * Name of the Agent\n */\n name: string\n /**\n * Description of the Agent\n */\n description?: string\n /**\n * The author of the Agent (organization or person) that own the Agent.\n */\n author?: string\n /**\n * The author of the Agent (organization or person) that own the Agent.\n */\n license?: string\n /**\n * Tags describing the AI Agent\n */\n tags?: string[]\n /**\n * Some description or instructions about how to integrate the Agent.\n */\n integration?: string\n /**\n * A link to some same usage of the Agent.\n */\n sampleLink?: string\n /**\n * Text describing the API of the Agent.\n */\n apiDescription?: string\n /**\n * The date when the Agent was created.\n */\n dateCreated?: Date\n\n // internalAttributes?: any\n}\n\n/**\n * Metadata attributes describing the Payment Plan.\n */\nexport interface PlanMetadata extends AgentMetadata {\n /**\n * Indicates if a payment plan is a Trial plan.\n * A Trial plan is a plan that allows users to test the AI Agents associated with it typically without any cost.\n * @remarks A Trial plan only can be purchased once by a user.\n */\n isTrialPlan?: boolean\n /**\n * Indicates if a payment plan is limited by credits.\n * If 'time', the plan will be limited by time.\n * If 'credits', the plan will be limited by credits.\n */\n accessLimit?: 'credits' | 'time'\n}\n\n/**\n * It describes the API exposed by an AI Agent.\n * This information is necessary to query the AI Agent and to know which endpoints are available.\n */\nexport interface AgentAPIAttributes {\n /**\n * The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.\n */\n endpoints: Endpoint[]\n /**\n * The list of endpoints of the upstream service that publicly available. The access to these endpoints don't require subscription to the Payment Plan. They are useful to expose documentation, etc.\n */\n openEndpoints?: string[]\n /**\n * The URL to the agent definition. Can be an OpenAPI spec, MCP Manifest, or A2A agent card. This field is mandatory and defines how the agent/service can be discovered and queried.\n */\n agentDefinitionUrl: string\n\n /////// AUTHORIZATION ///////\n\n /**\n * The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').\n */\n authType?: 'none' | 'basic' | 'oauth' | 'bearer'\n /**\n * The upstream agent/service username for authentication. Only if `authType` is 'basic'.\n */\n username?: string\n /**\n * The upstream agent/service password for authentication. Only if `authType` is 'basic'.\n */\n password?: string\n /**\n * The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.\n */\n token?: string\n}\n\n/**\n * Options for pagination in API requests to the Nevermined API.\n */\nexport class PaginationOptions {\n /**\n * The field to sort the results by.\n * If not provided, the default sorting defined by the API will be applied.\n */\n sortBy?: string\n /**\n * The order in which to sort the results.\n * Default is 'desc' (descending).\n */\n sortOrder: 'asc' | 'desc' = 'desc'\n /**\n * The page number to retrieve.\n * Default is 1.\n */\n page = 1\n /**\n * The number of items per page.\n * Default is 10.\n */\n offset = 10\n\n /**\n * Constructs a new PaginationOptions instance.\n * @param options - Optional initial values for the pagination options.\n */\n constructor(options?: Partial<PaginationOptions>) {\n if (options) {\n this.sortBy = options.sortBy\n this.sortOrder = options.sortOrder || 'desc'\n this.page = options.page || 1\n this.offset = options.offset || 10\n }\n }\n\n /**\n * It returns a string representation of the pagination options\n * @returns A string representation of the pagination options as URL query parameters.\n * This can be used to append to API requests for pagination.\n */\n asQueryParams(): string {\n const params: Record<string, string> = {}\n if (this.sortBy) {\n params.sortBy = this.sortBy\n }\n params.sortOrder = this.sortOrder\n params.page = this.page.toString()\n params.pageSize = this.offset.toString()\n\n return new URLSearchParams(params).toString()\n }\n}\n\n/**\n * Status of an agent task\n */\nexport enum AgentTaskStatus {\n SUCCESS = 'SUCCESS',\n FAILED = 'FAILED',\n PENDING = 'PENDING',\n}\n\n/**\n * Data transfer object for tracking agent sub tasks\n */\nexport interface TrackAgentSubTaskDto {\n /**\n * The unique identifier of the agent task\n */\n agentRequestId: string\n\n /**\n * The number of credits burned in this agent sub task (optional)\n * @defaultValue 0\n */\n creditsToRedeem?: number\n\n /**\n * A tag to categorize this agent sub task (optional)\n */\n tag?: string\n\n /**\n * A description of this agent sub task (optional)\n */\n description?: string\n\n /**\n * The status of the agent sub task (optional)\n */\n status?: AgentTaskStatus\n}\n\nexport type SimulationRequestOptions = {\n agentName?: string\n planName?: string\n batch?: boolean\n pricePerCredit?: number\n}\n"]}
|
package/dist/mcp/core/auth.d.ts
CHANGED
|
@@ -23,18 +23,30 @@ export declare class PaywallAuthenticator {
|
|
|
23
23
|
* @returns HTTP endpoint URL or undefined if context is not available
|
|
24
24
|
*/
|
|
25
25
|
private buildHttpUrlFromContext;
|
|
26
|
+
/**
|
|
27
|
+
* Core verification logic shared by authenticate and authenticateMeta.
|
|
28
|
+
* Tries logical URL first, falls back to HTTP URL if available.
|
|
29
|
+
*/
|
|
30
|
+
private verifyWithFallback;
|
|
31
|
+
/**
|
|
32
|
+
* Verify permissions against a single endpoint URL.
|
|
33
|
+
* Resolves planId from the token or from the agent's plans as fallback.
|
|
34
|
+
*/
|
|
35
|
+
private verifyWithEndpoint;
|
|
26
36
|
/**
|
|
27
37
|
* Authenticate an MCP request
|
|
28
38
|
*/
|
|
29
39
|
authenticate(extra: any, options: {
|
|
30
|
-
planId?: string
|
|
40
|
+
planId?: string;
|
|
41
|
+
maxAmount?: bigint;
|
|
31
42
|
} | undefined, agentId: string, serverName: string, name: string, kind: 'tool' | 'resource' | 'prompt', argsOrVars: any): Promise<AuthResult>;
|
|
32
43
|
/**
|
|
33
44
|
* Authenticate generic MCP meta operations (e.g., initialize, tools/list, resources/list, prompts/list).
|
|
34
45
|
* Returns an AuthResult compatible with paywall flows (without redeem step).
|
|
35
46
|
*/
|
|
36
47
|
authenticateMeta(extra: any, options: {
|
|
37
|
-
planId?: string
|
|
48
|
+
planId?: string;
|
|
49
|
+
maxAmount?: bigint;
|
|
38
50
|
} | undefined, agentId: string, serverName: string, method: string): Promise<AuthResult>;
|
|
39
51
|
}
|
|
40
52
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAgBtD;;GAEG;AACH,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEtC;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;IAepC;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAuB/B;;;OAGG;YACW,kBAAkB;IAoEhC;;;OAGG;YACW,kBAAkB;IAoDhC;;OAEG;IACG,YAAY,CAChB,KAAK,EAAE,GAAG,EACV,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,YAAK,EACrD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,EACpC,UAAU,EAAE,GAAG,GACd,OAAO,CAAC,UAAU,CAAC;IAkBtB;;;OAGG;IACG,gBAAgB,CACpB,KAAK,EAAE,GAAG,EACV,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,YAAK,EACrD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC;CAiBvB"}
|