@nevermined-io/payments 1.1.18 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/a2a/clientRegistry.d.ts.map +1 -1
- package/dist/a2a/clientRegistry.js +2 -2
- package/dist/a2a/clientRegistry.js.map +1 -1
- package/dist/a2a/paymentsClient.d.ts +2 -2
- package/dist/a2a/paymentsClient.d.ts.map +1 -1
- package/dist/a2a/paymentsClient.js +10 -6
- package/dist/a2a/paymentsClient.js.map +1 -1
- package/dist/a2a/server.d.ts.map +1 -1
- package/dist/a2a/server.js +3 -1
- package/dist/a2a/server.js.map +1 -1
- package/dist/a2a/types.d.ts +1 -0
- package/dist/a2a/types.d.ts.map +1 -1
- package/dist/a2a/types.js.map +1 -1
- package/dist/api/base-payments.d.ts.map +1 -1
- package/dist/api/base-payments.js +12 -10
- package/dist/api/base-payments.js.map +1 -1
- package/dist/api/nvm-api.d.ts +0 -1
- package/dist/api/nvm-api.d.ts.map +1 -1
- package/dist/api/nvm-api.js +0 -1
- package/dist/api/nvm-api.js.map +1 -1
- package/dist/api/plans-api.d.ts +21 -32
- package/dist/api/plans-api.d.ts.map +1 -1
- package/dist/api/plans-api.js +27 -49
- package/dist/api/plans-api.js.map +1 -1
- package/dist/common/types.d.ts +90 -19
- package/dist/common/types.d.ts.map +1 -1
- package/dist/common/types.js +16 -0
- package/dist/common/types.js.map +1 -1
- package/dist/environments.d.ts +0 -7
- package/dist/environments.d.ts.map +1 -1
- package/dist/environments.js +0 -13
- package/dist/environments.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/http/session-manager.d.ts.map +1 -1
- package/dist/mcp/http/session-manager.js +15 -1
- package/dist/mcp/http/session-manager.js.map +1 -1
- package/dist/payments.d.ts +17 -1
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +2 -10
- package/dist/payments.js.map +1 -1
- package/dist/plans.d.ts +14 -3
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +25 -8
- package/dist/plans.js.map +1 -1
- package/dist/x402/delegation-api.d.ts +119 -19
- package/dist/x402/delegation-api.d.ts.map +1 -1
- package/dist/x402/delegation-api.js +77 -23
- package/dist/x402/delegation-api.js.map +1 -1
- package/dist/x402/express/middleware.d.ts +4 -0
- package/dist/x402/express/middleware.d.ts.map +1 -1
- package/dist/x402/express/middleware.js +7 -4
- package/dist/x402/express/middleware.js.map +1 -1
- package/dist/x402/facilitator-api.d.ts +13 -5
- package/dist/x402/facilitator-api.d.ts.map +1 -1
- package/dist/x402/facilitator-api.js +41 -15
- package/dist/x402/facilitator-api.js.map +1 -1
- package/dist/x402/index.d.ts +3 -7
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +2 -5
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/token.d.ts +17 -17
- package/dist/x402/token.d.ts.map +1 -1
- package/dist/x402/token.js +27 -37
- package/dist/x402/token.js.map +1 -1
- package/package.json +23 -21
- package/dist/x402/visa-facilitator-api.d.ts +0 -150
- package/dist/x402/visa-facilitator-api.d.ts.map +0 -1
- package/dist/x402/visa-facilitator-api.js +0 -206
- package/dist/x402/visa-facilitator-api.js.map +0 -1
- package/dist/x402/visa-token-api.d.ts +0 -60
- package/dist/x402/visa-token-api.d.ts.map +0 -1
- package/dist/x402/visa-token-api.js +0 -99
- package/dist/x402/visa-token-api.js.map +0 -1
package/dist/common/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EnvironmentName } from '../environments.js';
|
|
2
2
|
/**
|
|
3
3
|
* The payment scheme to use.
|
|
4
|
-
* - 'nvm' (default): Nevermined
|
|
5
|
-
* -
|
|
4
|
+
* - 'nvm' (default): Nevermined-issued x402 access tokens covering both
|
|
5
|
+
* credit-based ERC-4337 payments and fiat card delegations (Stripe,
|
|
6
|
+
* Braintree, Visa).
|
|
6
7
|
*/
|
|
7
|
-
export type PaymentScheme = 'nvm'
|
|
8
|
+
export type PaymentScheme = 'nvm';
|
|
8
9
|
export interface PaymentOptions {
|
|
9
10
|
/**
|
|
10
11
|
* The Nevermined environment to connect to.
|
|
@@ -15,14 +16,11 @@ export interface PaymentOptions {
|
|
|
15
16
|
/**
|
|
16
17
|
* The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.
|
|
17
18
|
* You can get your API key by logging in to the Nevermined App.
|
|
18
|
-
* Required for 'nvm' scheme. Optional for 'visa' scheme.
|
|
19
19
|
* @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys
|
|
20
20
|
*/
|
|
21
21
|
nvmApiKey: string;
|
|
22
22
|
/**
|
|
23
23
|
* The payment scheme to use. Defaults to 'nvm'.
|
|
24
|
-
* - 'nvm': Nevermined credit-based payments
|
|
25
|
-
* - 'visa': Visa Token Service fiat payments
|
|
26
24
|
*/
|
|
27
25
|
scheme?: PaymentScheme;
|
|
28
26
|
/**
|
|
@@ -84,6 +82,11 @@ export interface PlanPriceConfig {
|
|
|
84
82
|
* Whether this is a crypto payment (true) or fiat payment (false)
|
|
85
83
|
*/
|
|
86
84
|
isCrypto: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Optional currency for the plan (e.g., 'USD', 'EUR', 'USDC', 'EURC').
|
|
87
|
+
* When omitted, the backend determines the default based on the payment type.
|
|
88
|
+
*/
|
|
89
|
+
currency?: Currency | string;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* Definition of the credits configuration for a payment plan
|
|
@@ -98,9 +101,12 @@ export interface PlanCreditsConfig {
|
|
|
98
101
|
*/
|
|
99
102
|
redemptionType: PlanRedemptionType;
|
|
100
103
|
/**
|
|
101
|
-
* Whether
|
|
104
|
+
* Whether burns of these credits are mirrored on-chain. When `false`
|
|
105
|
+
* (default) the credits ledger lives in the API's Postgres and burns
|
|
106
|
+
* are recorded off-chain only. When `true` an `OnchainMirrorWorker`
|
|
107
|
+
* replays each off-chain burn to `NFT1155Credits` for audit.
|
|
102
108
|
*/
|
|
103
|
-
|
|
109
|
+
onchainMirror: boolean;
|
|
104
110
|
/**
|
|
105
111
|
* The duration of the credits in seconds
|
|
106
112
|
* @remarks 0 means non-expirable
|
|
@@ -135,6 +141,21 @@ export declare enum PlanPriceType {
|
|
|
135
141
|
FIXED_FIAT_PRICE = 1,
|
|
136
142
|
SMART_CONTRACT_PRICE = 2
|
|
137
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Supported currencies for payment plans.
|
|
146
|
+
* - Fiat: USD, EUR (processed via Stripe)
|
|
147
|
+
* - Crypto: USDC, EURC (ERC20 stablecoins on Base)
|
|
148
|
+
*/
|
|
149
|
+
export declare enum Currency {
|
|
150
|
+
USD = "USD",
|
|
151
|
+
EUR = "EUR",
|
|
152
|
+
USDC = "USDC",
|
|
153
|
+
EURC = "EURC"
|
|
154
|
+
}
|
|
155
|
+
/** EURC token address on Base Mainnet (chain 8453) */
|
|
156
|
+
export declare const EURC_TOKEN_ADDRESS: Address;
|
|
157
|
+
/** EURC token address on Base Sepolia testnet (chain 84532) */
|
|
158
|
+
export declare const EURC_TOKEN_ADDRESS_TESTNET: Address;
|
|
138
159
|
/**
|
|
139
160
|
* Different types of credits that can be obtained when purchasing a plan
|
|
140
161
|
* @remarks 0 - EXPIRABLE, 1 - FIXED, 2 - DYNAMIC
|
|
@@ -279,17 +300,24 @@ export interface PlanMetadata extends AgentMetadata {
|
|
|
279
300
|
*/
|
|
280
301
|
export interface AgentAPIAttributes {
|
|
281
302
|
/**
|
|
282
|
-
*
|
|
303
|
+
* Optional allowlist of upstream endpoints that require a valid Payment Plan
|
|
304
|
+
* subscription. When provided, the Nevermined platform enforces this list as
|
|
305
|
+
* **Additional Security** (defense-in-depth) on top of any per-route gating
|
|
306
|
+
* the Payments library middleware applies in your agent. When omitted, no
|
|
307
|
+
* route-level allowlist is enforced — your library middleware remains the
|
|
308
|
+
* sole gate.
|
|
283
309
|
*/
|
|
284
|
-
endpoints
|
|
310
|
+
endpoints?: Endpoint[];
|
|
285
311
|
/**
|
|
286
312
|
* 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.
|
|
287
313
|
*/
|
|
288
314
|
openEndpoints?: string[];
|
|
289
315
|
/**
|
|
290
|
-
*
|
|
316
|
+
* Optional URL to a discoverable agent definition (OpenAPI spec, MCP
|
|
317
|
+
* Manifest, or A2A agent card). Stored as metadata for documentation /
|
|
318
|
+
* discovery — not consumed at runtime by the Nevermined platform.
|
|
291
319
|
*/
|
|
292
|
-
agentDefinitionUrl
|
|
320
|
+
agentDefinitionUrl?: string;
|
|
293
321
|
/**
|
|
294
322
|
* The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').
|
|
295
323
|
*/
|
|
@@ -408,21 +436,64 @@ export declare function getDefaultNetwork(scheme: X402SchemeType, environment?:
|
|
|
408
436
|
*/
|
|
409
437
|
export declare function isValidScheme(s: unknown): s is X402SchemeType;
|
|
410
438
|
/**
|
|
411
|
-
* Configuration for
|
|
439
|
+
* Configuration for delegation-based payments (both crypto and card schemes).
|
|
440
|
+
*
|
|
441
|
+
* To reuse an existing delegation supply `delegationId`.
|
|
442
|
+
* To reuse an existing card (PaymentMethod entity) supply `cardId`.
|
|
443
|
+
* When creating a brand-new delegation provide `providerPaymentMethodId`,
|
|
444
|
+
* `spendingLimitCents`, and `durationSecs`.
|
|
412
445
|
*/
|
|
413
|
-
export interface
|
|
414
|
-
/**
|
|
415
|
-
|
|
446
|
+
export interface DelegationConfig {
|
|
447
|
+
/** PaymentMethod entity UUID — preferred way to reference an enrolled card */
|
|
448
|
+
cardId?: string;
|
|
449
|
+
/** Existing delegation UUID to reuse instead of creating a new one */
|
|
450
|
+
delegationId?: string;
|
|
451
|
+
/** Stripe payment method ID (e.g., 'pm_...'). Required only for new delegations. */
|
|
452
|
+
providerPaymentMethodId?: string;
|
|
453
|
+
/** Maximum spending limit in cents. Required only for new delegations. */
|
|
454
|
+
spendingLimitCents?: number;
|
|
455
|
+
/** Duration of the delegation in seconds. Required only for new delegations. */
|
|
456
|
+
durationSecs?: number;
|
|
457
|
+
/** Currency code (default: 'usd') */
|
|
458
|
+
currency?: string;
|
|
459
|
+
/** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */
|
|
460
|
+
merchantAccountId?: string;
|
|
461
|
+
/** Maximum number of transactions allowed */
|
|
462
|
+
maxTransactions?: number;
|
|
463
|
+
/** NVM API Key ID to scope the delegation to */
|
|
464
|
+
apiKeyId?: string;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Payload for creating a new delegation via POST /api/v1/delegation/create.
|
|
468
|
+
*/
|
|
469
|
+
export interface CreateDelegationPayload {
|
|
470
|
+
/** Delegation provider: 'stripe' | 'braintree' | 'visa' for card, 'erc4337' for crypto */
|
|
471
|
+
provider: 'stripe' | 'braintree' | 'visa' | 'erc4337';
|
|
472
|
+
/** Payment method ID from the provider (Stripe 'pm_...', Braintree vault token, or Visa Agentic token id). Required for card providers. */
|
|
473
|
+
providerPaymentMethodId?: string;
|
|
416
474
|
/** Maximum spending limit in cents */
|
|
417
475
|
spendingLimitCents: number;
|
|
418
476
|
/** Duration of the delegation in seconds */
|
|
419
477
|
durationSecs: number;
|
|
420
478
|
/** Currency code (default: 'usd') */
|
|
421
479
|
currency?: string;
|
|
422
|
-
/**
|
|
480
|
+
/** Plan ID to scope the delegation to */
|
|
481
|
+
planId?: string;
|
|
482
|
+
/** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */
|
|
423
483
|
merchantAccountId?: string;
|
|
424
484
|
/** Maximum number of transactions allowed */
|
|
425
485
|
maxTransactions?: number;
|
|
486
|
+
/** NVM API Key ID to scope the delegation to */
|
|
487
|
+
apiKeyId?: string;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Response from creating a delegation.
|
|
491
|
+
*/
|
|
492
|
+
export interface CreateDelegationResponse {
|
|
493
|
+
/** Delegation token (for card delegations) */
|
|
494
|
+
delegationToken?: string;
|
|
495
|
+
/** Delegation UUID */
|
|
496
|
+
delegationId: string;
|
|
426
497
|
}
|
|
427
498
|
/**
|
|
428
499
|
* Options for x402 token generation that control scheme and delegation behavior.
|
|
@@ -432,7 +503,7 @@ export interface X402TokenOptions {
|
|
|
432
503
|
scheme?: X402SchemeType;
|
|
433
504
|
/** Network identifier (auto-derived from scheme if omitted) */
|
|
434
505
|
network?: string;
|
|
435
|
-
/**
|
|
436
|
-
delegationConfig?:
|
|
506
|
+
/** Delegation configuration for both erc4337 and card-delegation schemes */
|
|
507
|
+
delegationConfig?: DelegationConfig;
|
|
437
508
|
}
|
|
438
509
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,CAAA;AAEjC,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,WAAW,EAAE,eAAe,CAAA;IAE5B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,WA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IAC1B,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAA;IACpB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,sBAAsB;IACtB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC"}
|
package/dist/common/types.js
CHANGED
|
@@ -11,6 +11,22 @@ export var PlanPriceType;
|
|
|
11
11
|
PlanPriceType[PlanPriceType["FIXED_FIAT_PRICE"] = 1] = "FIXED_FIAT_PRICE";
|
|
12
12
|
PlanPriceType[PlanPriceType["SMART_CONTRACT_PRICE"] = 2] = "SMART_CONTRACT_PRICE";
|
|
13
13
|
})(PlanPriceType || (PlanPriceType = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Supported currencies for payment plans.
|
|
16
|
+
* - Fiat: USD, EUR (processed via Stripe)
|
|
17
|
+
* - Crypto: USDC, EURC (ERC20 stablecoins on Base)
|
|
18
|
+
*/
|
|
19
|
+
export var Currency;
|
|
20
|
+
(function (Currency) {
|
|
21
|
+
Currency["USD"] = "USD";
|
|
22
|
+
Currency["EUR"] = "EUR";
|
|
23
|
+
Currency["USDC"] = "USDC";
|
|
24
|
+
Currency["EURC"] = "EURC";
|
|
25
|
+
})(Currency || (Currency = {}));
|
|
26
|
+
/** EURC token address on Base Mainnet (chain 8453) */
|
|
27
|
+
export const EURC_TOKEN_ADDRESS = '0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42';
|
|
28
|
+
/** EURC token address on Base Sepolia testnet (chain 84532) */
|
|
29
|
+
export const EURC_TOKEN_ADDRESS_TESTNET = '0x808456652fdb597867f38412077A9182bf77359F';
|
|
14
30
|
/**
|
|
15
31
|
* Different types of credits that can be obtained when purchasing a plan
|
|
16
32
|
* @remarks 0 - EXPIRABLE, 1 - FIXED, 2 - DYNAMIC
|
package/dist/common/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AA0IA;;;;;;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,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,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB,EAAE,WAA6B;IACrF,IAAI,MAAM,KAAK,aAAa,IAAI,WAAW,EAAE,CAAC;QAC5C,OAAO,sBAAsB,CAAC,WAAW,CAAC,IAAI,cAAc,CAAA;IAC9D,CAAC;IACD,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,CAAU;IACtC,OAAO,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,qBAAqB,CAAA;AAC3D,CAAC","sourcesContent":["import { EnvironmentName } from '../environments.js'\n\n/**\n * The payment scheme to use.\n * - 'nvm' (default): Nevermined credit-based payments via ERC-4337 smart accounts.\n * - 'visa': Visa Token Service fiat payments via x402 HTTP transport.\n */\nexport type PaymentScheme = 'nvm' | 'visa'\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 * Required for 'nvm' scheme. Optional for 'visa' scheme.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n nvmApiKey: string\n\n /**\n * The payment scheme to use. Defaults to 'nvm'.\n * - 'nvm': Nevermined credit-based payments\n * - 'visa': Visa Token Service fiat payments\n */\n scheme?: PaymentScheme\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\n/**\n * x402 payment scheme type.\n * - 'nvm:erc4337': Crypto payments via ERC-4337 smart accounts\n * - 'nvm:card-delegation': Fiat/Stripe card delegation payments\n */\nexport type X402SchemeType = 'nvm:erc4337' | 'nvm:card-delegation'\n\n/**\n * Default network for each x402 scheme (backward-compat: defaults to Base Sepolia).\n */\nexport const X402_SCHEME_NETWORKS: Record<X402SchemeType, string> = {\n 'nvm:erc4337': 'eip155:84532',\n 'nvm:card-delegation': 'stripe',\n}\n\n/**\n * Environment-specific network for the erc4337 scheme.\n */\nconst ERC4337_NETWORK_BY_ENV: Record<string, string> = {\n sandbox: 'eip155:84532', // Base Sepolia\n staging_sandbox: 'eip155:84532', // Base Sepolia\n live: 'eip155:8453', // Base Mainnet\n staging_live: 'eip155:8453', // Base Mainnet\n}\n\n/**\n * Return the default network for a scheme, accounting for the environment.\n *\n * For `nvm:erc4337`, the network depends on the environment:\n * - sandbox / staging_sandbox → `eip155:84532` (Base Sepolia)\n * - live / staging_live → `eip155:8453` (Base Mainnet)\n *\n * Falls back to `X402_SCHEME_NETWORKS` when no environment is given.\n */\nexport function getDefaultNetwork(scheme: X402SchemeType, environment?: EnvironmentName): string {\n if (scheme === 'nvm:erc4337' && environment) {\n return ERC4337_NETWORK_BY_ENV[environment] ?? 'eip155:84532'\n }\n return X402_SCHEME_NETWORKS[scheme]\n}\n\n/**\n * Type guard to check if a value is a valid x402 scheme type.\n */\nexport function isValidScheme(s: unknown): s is X402SchemeType {\n return s === 'nvm:erc4337' || s === 'nvm:card-delegation'\n}\n\n/**\n * Configuration for card delegation (fiat/Stripe) payments.\n */\nexport interface CardDelegationConfig {\n /** Stripe payment method ID (e.g., 'pm_...') */\n providerPaymentMethodId: string\n /** Maximum spending limit in cents */\n spendingLimitCents: number\n /** Duration of the delegation in seconds */\n durationSecs: number\n /** Currency code (default: 'usd') */\n currency?: string\n /** Stripe Connect merchant account ID */\n merchantAccountId?: string\n /** Maximum number of transactions allowed */\n maxTransactions?: number\n}\n\n/**\n * Options for x402 token generation that control scheme and delegation behavior.\n */\nexport interface X402TokenOptions {\n /** The x402 scheme to use (defaults to 'nvm:erc4337') */\n scheme?: X402SchemeType\n /** Network identifier (auto-derived from scheme if omitted) */\n network?: string\n /** Card delegation configuration (only for 'nvm:card-delegation' scheme) */\n delegationConfig?: CardDelegationConfig\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAgJA;;;;;;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;;;;GAIG;AACH,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,yBAAa,CAAA;AACf,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB;AAED,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAY,4CAA4C,CAAA;AACvF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,0BAA0B,GAAY,4CAA4C,CAAA;AAE/F;;;;;;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;AA2KD;;G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CAChC,CAAA;AAED;;GAEG;AACH,MAAM,sBAAsB,GAA2B;IACrD,OAAO,EAAE,cAAc,EAAE,eAAe;IACxC,eAAe,EAAE,cAAc,EAAE,eAAe;IAChD,IAAI,EAAE,aAAa,EAAE,eAAe;IACpC,YAAY,EAAE,aAAa,EAAE,eAAe;CAC7C,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB,EAAE,WAA6B;IACrF,IAAI,MAAM,KAAK,aAAa,IAAI,WAAW,EAAE,CAAC;QAC5C,OAAO,sBAAsB,CAAC,WAAW,CAAC,IAAI,cAAc,CAAA;IAC9D,CAAC;IACD,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,CAAU;IACtC,OAAO,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,qBAAqB,CAAA;AAC3D,CAAC","sourcesContent":["import { EnvironmentName } from '../environments.js'\n\n/**\n * The payment scheme to use.\n * - 'nvm' (default): Nevermined-issued x402 access tokens covering both\n * credit-based ERC-4337 payments and fiat card delegations (Stripe,\n * Braintree, Visa).\n */\nexport type PaymentScheme = 'nvm'\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 payment scheme to use. Defaults to 'nvm'.\n */\n scheme?: PaymentScheme\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 * Optional currency for the plan (e.g., 'USD', 'EUR', 'USDC', 'EURC').\n * When omitted, the backend determines the default based on the payment type.\n */\n currency?: Currency | string\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 burns of these credits are mirrored on-chain. When `false`\n * (default) the credits ledger lives in the API's Postgres and burns\n * are recorded off-chain only. When `true` an `OnchainMirrorWorker`\n * replays each off-chain burn to `NFT1155Credits` for audit.\n */\n onchainMirror: 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 * Supported currencies for payment plans.\n * - Fiat: USD, EUR (processed via Stripe)\n * - Crypto: USDC, EURC (ERC20 stablecoins on Base)\n */\nexport enum Currency {\n USD = 'USD',\n EUR = 'EUR',\n USDC = 'USDC',\n EURC = 'EURC',\n}\n\n/** EURC token address on Base Mainnet (chain 8453) */\nexport const EURC_TOKEN_ADDRESS: Address = '0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42'\n/** EURC token address on Base Sepolia testnet (chain 84532) */\nexport const EURC_TOKEN_ADDRESS_TESTNET: Address = '0x808456652fdb597867f38412077A9182bf77359F'\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 * Optional allowlist of upstream endpoints that require a valid Payment Plan\n * subscription. When provided, the Nevermined platform enforces this list as\n * **Additional Security** (defense-in-depth) on top of any per-route gating\n * the Payments library middleware applies in your agent. When omitted, no\n * route-level allowlist is enforced — your library middleware remains the\n * sole gate.\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 * Optional URL to a discoverable agent definition (OpenAPI spec, MCP\n * Manifest, or A2A agent card). Stored as metadata for documentation /\n * discovery — not consumed at runtime by the Nevermined platform.\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\n/**\n * x402 payment scheme type.\n * - 'nvm:erc4337': Crypto payments via ERC-4337 smart accounts\n * - 'nvm:card-delegation': Fiat/Stripe card delegation payments\n */\nexport type X402SchemeType = 'nvm:erc4337' | 'nvm:card-delegation'\n\n/**\n * Default network for each x402 scheme (backward-compat: defaults to Base Sepolia).\n */\nexport const X402_SCHEME_NETWORKS: Record<X402SchemeType, string> = {\n 'nvm:erc4337': 'eip155:84532',\n 'nvm:card-delegation': 'stripe',\n}\n\n/**\n * Environment-specific network for the erc4337 scheme.\n */\nconst ERC4337_NETWORK_BY_ENV: Record<string, string> = {\n sandbox: 'eip155:84532', // Base Sepolia\n staging_sandbox: 'eip155:84532', // Base Sepolia\n live: 'eip155:8453', // Base Mainnet\n staging_live: 'eip155:8453', // Base Mainnet\n}\n\n/**\n * Return the default network for a scheme, accounting for the environment.\n *\n * For `nvm:erc4337`, the network depends on the environment:\n * - sandbox / staging_sandbox → `eip155:84532` (Base Sepolia)\n * - live / staging_live → `eip155:8453` (Base Mainnet)\n *\n * Falls back to `X402_SCHEME_NETWORKS` when no environment is given.\n */\nexport function getDefaultNetwork(scheme: X402SchemeType, environment?: EnvironmentName): string {\n if (scheme === 'nvm:erc4337' && environment) {\n return ERC4337_NETWORK_BY_ENV[environment] ?? 'eip155:84532'\n }\n return X402_SCHEME_NETWORKS[scheme]\n}\n\n/**\n * Type guard to check if a value is a valid x402 scheme type.\n */\nexport function isValidScheme(s: unknown): s is X402SchemeType {\n return s === 'nvm:erc4337' || s === 'nvm:card-delegation'\n}\n\n/**\n * Configuration for delegation-based payments (both crypto and card schemes).\n *\n * To reuse an existing delegation supply `delegationId`.\n * To reuse an existing card (PaymentMethod entity) supply `cardId`.\n * When creating a brand-new delegation provide `providerPaymentMethodId`,\n * `spendingLimitCents`, and `durationSecs`.\n */\nexport interface DelegationConfig {\n /** PaymentMethod entity UUID — preferred way to reference an enrolled card */\n cardId?: string\n /** Existing delegation UUID to reuse instead of creating a new one */\n delegationId?: string\n /** Stripe payment method ID (e.g., 'pm_...'). Required only for new delegations. */\n providerPaymentMethodId?: string\n /** Maximum spending limit in cents. Required only for new delegations. */\n spendingLimitCents?: number\n /** Duration of the delegation in seconds. Required only for new delegations. */\n durationSecs?: number\n /** Currency code (default: 'usd') */\n currency?: string\n /** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */\n merchantAccountId?: string\n /** Maximum number of transactions allowed */\n maxTransactions?: number\n /** NVM API Key ID to scope the delegation to */\n apiKeyId?: string\n}\n\n/**\n * Payload for creating a new delegation via POST /api/v1/delegation/create.\n */\nexport interface CreateDelegationPayload {\n /** Delegation provider: 'stripe' | 'braintree' | 'visa' for card, 'erc4337' for crypto */\n provider: 'stripe' | 'braintree' | 'visa' | 'erc4337'\n /** Payment method ID from the provider (Stripe 'pm_...', Braintree vault token, or Visa Agentic token id). Required for card providers. */\n providerPaymentMethodId?: string\n /** Maximum spending limit in cents */\n spendingLimitCents: number\n /** Duration of the delegation in seconds */\n durationSecs: number\n /** Currency code (default: 'usd') */\n currency?: string\n /** Plan ID to scope the delegation to */\n planId?: string\n /** Merchant account ID (Stripe Connect acct_xxx or Braintree merchantId) */\n merchantAccountId?: string\n /** Maximum number of transactions allowed */\n maxTransactions?: number\n /** NVM API Key ID to scope the delegation to */\n apiKeyId?: string\n}\n\n/**\n * Response from creating a delegation.\n */\nexport interface CreateDelegationResponse {\n /** Delegation token (for card delegations) */\n delegationToken?: string\n /** Delegation UUID */\n delegationId: string\n}\n\n/**\n * Options for x402 token generation that control scheme and delegation behavior.\n */\nexport interface X402TokenOptions {\n /** The x402 scheme to use (defaults to 'nvm:erc4337') */\n scheme?: X402SchemeType\n /** Network identifier (auto-derived from scheme if omitted) */\n network?: string\n /** Delegation configuration for both erc4337 and card-delegation schemes */\n delegationConfig?: DelegationConfig\n}\n"]}
|
package/dist/environments.d.ts
CHANGED
|
@@ -9,12 +9,5 @@ export type EnvironmentName = 'staging_sandbox' | 'staging_live' | 'sandbox' | '
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents the different environments and their corresponding URLs.
|
|
11
11
|
*/
|
|
12
|
-
/**
|
|
13
|
-
* Visa backend URLs mapped by environment name.
|
|
14
|
-
* When scheme is 'visa', the facilitator and token APIs use these URLs
|
|
15
|
-
* for verify, settle, and access-token operations while the main NVM
|
|
16
|
-
* backend (from Environments) is still used for plans, agents, etc.
|
|
17
|
-
*/
|
|
18
|
-
export declare const VisaBackendUrls: Record<EnvironmentName, string>;
|
|
19
12
|
export declare const Environments: Record<EnvironmentName, EnvironmentInfo>;
|
|
20
13
|
//# sourceMappingURL=environments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.d.ts","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,WAAW,+CAA+C,CAAA;AAEvE,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEhG;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"environments.d.ts","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,WAAW,+CAA+C,CAAA;AAEvE,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEhG;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,eAAe,EAAE,eAAe,CA2CjE,CAAA"}
|
package/dist/environments.js
CHANGED
|
@@ -2,19 +2,6 @@ export const ZeroAddress = '0x0000000000000000000000000000000000000000';
|
|
|
2
2
|
/**
|
|
3
3
|
* Represents the different environments and their corresponding URLs.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* Visa backend URLs mapped by environment name.
|
|
7
|
-
* When scheme is 'visa', the facilitator and token APIs use these URLs
|
|
8
|
-
* for verify, settle, and access-token operations while the main NVM
|
|
9
|
-
* backend (from Environments) is still used for plans, agents, etc.
|
|
10
|
-
*/
|
|
11
|
-
export const VisaBackendUrls = {
|
|
12
|
-
staging_sandbox: process.env.VISA_STAGING_SANDBOX_URL || 'https://visa.nevermined.dev/api/',
|
|
13
|
-
staging_live: process.env.VISA_STAGING_LIVE_URL || 'https://visa.nevermined.dev/api/',
|
|
14
|
-
sandbox: process.env.VISA_SANDBOX_URL || 'https://visa.nevermined.dev/api/',
|
|
15
|
-
live: process.env.VISA_LIVE_URL || 'https://visa.nevermined.dev/api/',
|
|
16
|
-
custom: process.env.VISA_BACKEND_URL || 'http://localhost:3000/api/',
|
|
17
|
-
};
|
|
18
5
|
export const Environments = {
|
|
19
6
|
/**
|
|
20
7
|
* The staging environment URLs.
|
package/dist/environments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,WAAW,GAAG,4CAA4C,CAAA;AAIvE;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,WAAW,GAAG,4CAA4C,CAAA;AAIvE;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAA6C;IACpE;;OAEG;IACH,eAAe,EAAE;QACf,QAAQ,EAAE,wBAAwB;QAClC,OAAO,EAAE,qCAAqC;QAC9C,KAAK,EAAE,sCAAsC;QAC7C,WAAW,EAAE,iCAAiC;KAC/C;IACD,YAAY,EAAE;QACZ,QAAQ,EAAE,wBAAwB;QAClC,OAAO,EAAE,kCAAkC;QAC3C,KAAK,EAAE,mCAAmC;QAC1C,WAAW,EAAE,iCAAiC;KAC/C;IACD;;OAEG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,wBAAwB;QAClC,OAAO,EAAE,qCAAqC;QAC9C,KAAK,EAAE,sCAAsC;QAC7C,WAAW,EAAE,iCAAiC;KAC/C;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,QAAQ,EAAE,wBAAwB;QAClC,OAAO,EAAE,kCAAkC;QAC3C,KAAK,EAAE,mCAAmC;QAC1C,WAAW,EAAE,iCAAiC;KAC/C;IACD;;OAEG;IACH,MAAM,EAAE;QACN,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,uBAAuB;QACjE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,uBAAuB;QAC/D,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,uBAAuB;QAC3D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,uBAAuB;KACjE;CACF,CAAA","sourcesContent":["export interface EnvironmentInfo {\n frontend: string\n backend: string\n proxy: string\n heliconeUrl: string\n}\n\nexport const ZeroAddress = '0x0000000000000000000000000000000000000000'\n\nexport type EnvironmentName = 'staging_sandbox' | 'staging_live' | 'sandbox' | 'live' | 'custom'\n\n/**\n * Represents the different environments and their corresponding URLs.\n */\nexport const Environments: Record<EnvironmentName, EnvironmentInfo> = {\n /**\n * The staging environment URLs.\n */\n staging_sandbox: {\n frontend: 'https://nevermined.dev',\n backend: 'https://api.sandbox.nevermined.dev/',\n proxy: 'https://proxy.sandbox.nevermined.dev',\n heliconeUrl: 'https://helicone.nevermined.dev',\n },\n staging_live: {\n frontend: 'https://nevermined.dev',\n backend: 'https://api.live.nevermined.dev/',\n proxy: 'https://proxy.live.nevermined.dev',\n heliconeUrl: 'https://helicone.nevermined.dev',\n },\n /**\n * The Sandbox environment URLs.\n */\n sandbox: {\n frontend: 'https://nevermined.app',\n backend: 'https://api.sandbox.nevermined.app/',\n proxy: 'https://proxy.sandbox.nevermined.app',\n heliconeUrl: 'https://helicone.nevermined.dev',\n },\n /**\n * The Live environment URLs.\n */\n live: {\n frontend: 'https://nevermined.app',\n backend: 'https://api.live.nevermined.app/',\n proxy: 'https://proxy.live.nevermined.app',\n heliconeUrl: 'https://helicone.nevermined.dev',\n },\n /**\n * A custom environment URLs.\n */\n custom: {\n frontend: process.env.NVM_FRONTEND_URL || 'http://localhost:4200',\n backend: process.env.NVM_BACKEND_URL || 'http://localhost:3001',\n proxy: process.env.NVM_PROXY_URL || 'https://localhost:443',\n heliconeUrl: process.env.HELICONE_URL || 'http://localhost:8585',\n },\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,13 +8,10 @@ export * from './api/query-api.js';
|
|
|
8
8
|
export * from './api/observability-api/observability-api.js';
|
|
9
9
|
export type { BackendApiOptions } from './api/nvm-api.js';
|
|
10
10
|
export { ContractsAPI } from './api/contracts-api.js';
|
|
11
|
-
export { buildPaymentRequired, resolveScheme } from './x402/facilitator-api.js';
|
|
11
|
+
export { buildPaymentRequired, resolveNetwork, resolveScheme } from './x402/facilitator-api.js';
|
|
12
12
|
export { DelegationAPI } from './x402/delegation-api.js';
|
|
13
|
-
export type { PaymentMethodSummary } from './x402/delegation-api.js';
|
|
13
|
+
export type { PaymentMethodSummary, UpdatePaymentMethodDto, DelegationSummary, DelegationListResponse, PurchasingPower, ListOptions, } from './x402/delegation-api.js';
|
|
14
14
|
export type { X402PaymentRequired, X402PaymentAccepted, X402Resource, X402Scheme, X402SchemeExtra, VerifyPermissionsParams, VerifyPermissionsResult, SettlePermissionsParams, SettlePermissionsResult, } from './x402/facilitator-api.js';
|
|
15
|
-
export { buildVisaPaymentRequired, VISA_X402_HEADERS } from './x402/visa-facilitator-api.js';
|
|
16
|
-
export type { VisaPaymentExtra, VisaPaymentRequirements, VisaPaymentRequired, VisaVerifyResponse, VisaSettlementResponse, } from './x402/visa-facilitator-api.js';
|
|
17
|
-
export type { VisaPaymentPayloadResponse } from './x402/visa-token-api.js';
|
|
18
15
|
export type { CreditsContext, CreditsOption, PaywallOptions, McpConfig, PaywallContext, AuthResult, } from './mcp/types/paywall.types.js';
|
|
19
16
|
export type { OAuthUrls, OAuthConfig, HttpRouterConfig, HttpServerConfig, HttpServerResult, } from './mcp/types/http.types.js';
|
|
20
17
|
export type { ExtendedMcpConfig } from './mcp/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,8CAA8C,CAAA;AAC5D,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC/
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,8CAA8C,CAAA;AAC5D,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,WAAW,GACZ,MAAM,0BAA0B,CAAA;AACjC,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,2BAA2B,CAAA;AAElC,YAAY,EACV,cAAc,EACd,aAAa,EACb,cAAc,EACd,SAAS,EACT,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAA;AAGrC,YAAY,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,2BAA2B,CAAA;AAGlC,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAExE,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,IAAI,EACJ,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,qCAAqC,EACrC,YAAY,EACZ,qCAAqC,GACtC,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,8 @@ export * from './api/query-api.js';
|
|
|
8
8
|
export * from './api/observability-api/observability-api.js';
|
|
9
9
|
export { ContractsAPI } from './api/contracts-api.js';
|
|
10
10
|
// x402 utilities and types
|
|
11
|
-
export { buildPaymentRequired, resolveScheme } from './x402/facilitator-api.js';
|
|
11
|
+
export { buildPaymentRequired, resolveNetwork, resolveScheme } from './x402/facilitator-api.js';
|
|
12
12
|
export { DelegationAPI } from './x402/delegation-api.js';
|
|
13
|
-
// Visa x402 utilities and types
|
|
14
|
-
export { buildVisaPaymentRequired, VISA_X402_HEADERS } from './x402/visa-facilitator-api.js';
|
|
15
13
|
// MCP HTTP utilities
|
|
16
14
|
export { createRequireAuthMiddleware } from './mcp/http/oauth-router.js';
|
|
17
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,8CAA8C,CAAA;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,2BAA2B;AAC3B,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC/
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,8CAA8C,CAAA;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,2BAA2B;AAC3B,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AA0CxD,qBAAqB;AACrB,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA","sourcesContent":["export * from './environments.js'\nexport * from './payments.js'\nexport * from './utils.js'\nexport * from './common/types.js'\nexport * from './common/payments.error.js'\nexport * from './common/helper.js'\nexport * from './api/query-api.js'\nexport * from './api/observability-api/observability-api.js'\nexport type { BackendApiOptions } from './api/nvm-api.js'\nexport { ContractsAPI } from './api/contracts-api.js'\n\n// x402 utilities and types\nexport { buildPaymentRequired, resolveNetwork, resolveScheme } from './x402/facilitator-api.js'\nexport { DelegationAPI } from './x402/delegation-api.js'\nexport type {\n PaymentMethodSummary,\n UpdatePaymentMethodDto,\n DelegationSummary,\n DelegationListResponse,\n PurchasingPower,\n ListOptions,\n} from './x402/delegation-api.js'\nexport type {\n X402PaymentRequired,\n X402PaymentAccepted,\n X402Resource,\n X402Scheme,\n X402SchemeExtra,\n VerifyPermissionsParams,\n VerifyPermissionsResult,\n SettlePermissionsParams,\n SettlePermissionsResult,\n} from './x402/facilitator-api.js'\n// MCP public types\nexport type {\n CreditsContext,\n CreditsOption,\n PaywallOptions,\n McpConfig,\n PaywallContext,\n AuthResult,\n} from './mcp/types/paywall.types.js'\n\n// MCP HTTP types\nexport type {\n OAuthUrls,\n OAuthConfig,\n HttpRouterConfig,\n HttpServerConfig,\n HttpServerResult,\n} from './mcp/types/http.types.js'\n\n// MCP extended config type\nexport type { ExtendedMcpConfig } from './mcp/index.js'\n\n// MCP HTTP utilities\nexport { createRequireAuthMiddleware } from './mcp/http/oauth-router.js'\n\nexport type {\n AgentCard,\n TaskHandlerResult,\n TaskStatusUpdateEvent,\n ExecutionEventBus,\n AgentExecutor,\n RequestContext,\n PushNotificationConfig,\n Task,\n MessageSendParams,\n SendMessageResponse,\n TaskQueryParams,\n GetTaskResponse,\n TaskPushNotificationConfig,\n SetTaskPushNotificationConfigResponse,\n TaskIdParams,\n GetTaskPushNotificationConfigResponse,\n} from './a2a/types.js'\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../src/mcp/http/session-manager.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;IACtD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;C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H,OAAO,CAAC,GAAG;CAGZ;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAEtF"}
|
|
@@ -82,6 +82,17 @@ export class SessionManager {
|
|
|
82
82
|
if (!this.mcpServer) {
|
|
83
83
|
throw new Error('MCP server not set. Call setMcpServer() first.');
|
|
84
84
|
}
|
|
85
|
+
// In stateless mode (sessionIdGenerator: undefined), each request gets a new transport
|
|
86
|
+
// but McpServer can only have one transport at a time. Close the existing connection
|
|
87
|
+
// before connecting the new transport so Protocol._transport is reset to undefined.
|
|
88
|
+
// The StreamableHTTPServerTransport with enableJsonResponse does not auto-close after
|
|
89
|
+
// sending a JSON response, so we must close it explicitly before each new connection.
|
|
90
|
+
try {
|
|
91
|
+
await this.mcpServer.close();
|
|
92
|
+
}
|
|
93
|
+
catch (_e) {
|
|
94
|
+
// Ignore close errors — server may not have been connected yet
|
|
95
|
+
}
|
|
85
96
|
const TransportClass = await getTransportClass();
|
|
86
97
|
// Use stateless mode (sessionIdGenerator: undefined) to avoid requiring
|
|
87
98
|
// Mcp-Session-Id header on every request. This allows clients to make
|
|
@@ -90,10 +101,13 @@ export class SessionManager {
|
|
|
90
101
|
sessionIdGenerator: undefined,
|
|
91
102
|
enableJsonResponse: true,
|
|
92
103
|
});
|
|
104
|
+
// Set onclose BEFORE connect() so the SDK chains it with its own handler.
|
|
105
|
+
// When the transport closes, both our cleanup and the SDK's cleanup run.
|
|
93
106
|
transport.onclose = () => {
|
|
94
|
-
this.log?.(`Transport closed for session ${sessionId}`);
|
|
95
107
|
this.sessions.delete(sessionId);
|
|
108
|
+
this.requestContexts.delete(sessionId);
|
|
96
109
|
this.config.onSessionDestroyed?.(sessionId);
|
|
110
|
+
this.log?.(`Transport closed for session ${sessionId}`);
|
|
97
111
|
};
|
|
98
112
|
await this.mcpServer.connect(transport);
|
|
99
113
|
// Force _initialized to true to allow requests without requiring initialize first.
|
|
@@ -1 +1 @@
|
|
|
1
|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,QAAQ,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAC3C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;QAChC,CAAC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,UAAU,CAAC,MAAM,WAAW,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACK,GAAG,CAAC,OAAe;QACzB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAA;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA+B,EAAE;IACpE,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC","sourcesContent":["/**\n * Session manager for MCP transports.\n * Handles creation, retrieval, and cleanup of StreamableHTTPServerTransport instances.\n * Also stores request context (headers) per session for authentication.\n */\nimport { randomUUID } from 'crypto'\n\n// We'll dynamically import the SDK to avoid hard dependency issues\nlet StreamableHTTPServerTransport: any = null\n\n/**\n * Request context stored per session.\n * Contains HTTP headers and other request info needed for authentication.\n */\nexport interface RequestContext {\n headers: Record<string, string | string[] | undefined>\n method?: string\n url?: string\n ip?: string\n}\n\n/**\n * Lazily load the MCP SDK transport.\n */\nasync function getTransportClass(): Promise<any> {\n if (!StreamableHTTPServerTransport) {\n try {\n const module = await import('@modelcontextprotocol/sdk/server/streamableHttp.js')\n StreamableHTTPServerTransport = module.StreamableHTTPServerTransport\n } catch (error) {\n throw new Error(\n 'Failed to load @modelcontextprotocol/sdk. Make sure it is installed: npm install @modelcontextprotocol/sdk',\n )\n }\n }\n return StreamableHTTPServerTransport\n}\n\n/**\n * Configuration for session manager.\n */\nexport interface SessionManagerConfig {\n /** Callback when a session is created */\n onSessionCreated?: (sessionId: string) => void\n /** Callback when a session is destroyed */\n onSessionDestroyed?: (sessionId: string) => void\n /** Logger function */\n log?: (message: string) => void\n}\n\n/**\n * Manages MCP transport sessions.\n */\nexport class SessionManager {\n private sessions: Map<string, any> = new Map()\n private requestContexts: Map<string, RequestContext> = new Map()\n private mcpServer: any = null\n private config: SessionManagerConfig\n\n constructor(config: SessionManagerConfig = {}) {\n this.config = config\n }\n\n /**\n * Set the MCP server that transports will connect to.\n */\n setMcpServer(server: any): void {\n this.mcpServer = server\n }\n\n /**\n * Generate a new session ID.\n */\n generateSessionId(): string {\n return randomUUID()\n }\n\n /**\n * Check if a session exists.\n */\n hasSession(sessionId: string): boolean {\n return this.sessions.has(sessionId)\n }\n\n /**\n * Get an existing session's transport.\n */\n getSession(sessionId: string): any | undefined {\n return this.sessions.get(sessionId)\n }\n\n /**\n * Store request context (headers, etc.) for a session.\n * This is called when an HTTP request arrives, before dispatching to MCP.\n */\n setRequestContext(sessionId: string, context: RequestContext): void {\n this.requestContexts.set(sessionId, context)\n }\n\n /**\n * Get the stored request context for a session.\n * Returns undefined if no context is stored.\n */\n getRequestContext(sessionId: string): RequestContext | undefined {\n return this.requestContexts.get(sessionId)\n }\n\n /**\n * Get or create a transport for a session.\n */\n async getOrCreateSession(sessionId: string): Promise<any> {\n if (this.sessions.has(sessionId)) {\n const existingSession = this.sessions.get(sessionId)\n if (existingSession) {\n return existingSession\n }\n }\n\n if (!this.mcpServer) {\n throw new Error('MCP server not set. Call setMcpServer() first.')\n }\n\n const TransportClass = await getTransportClass()\n\n // Use stateless mode (sessionIdGenerator: undefined) to avoid requiring\n // Mcp-Session-Id header on every request. This allows clients to make\n // direct JSON-RPC calls without the full MCP initialization handshake.\n const transport = new TransportClass({\n sessionIdGenerator: undefined,\n enableJsonResponse: true,\n })\n\n transport.onclose = () => {\n this.log?.(`Transport closed for session ${sessionId}`)\n this.sessions.delete(sessionId)\n this.config.onSessionDestroyed?.(sessionId)\n }\n\n await this.mcpServer.connect(transport)\n\n // Force _initialized to true to allow requests without requiring initialize first.\n // This maintains backward compatibility with clients that don't send initialize.\n // The SDK sets _initialized = true only after processing an initialize request,\n // but we want to accept tool/resource/prompt calls directly.\n if (transport._initialized === false) {\n transport._initialized = true\n }\n\n this.sessions.set(sessionId, transport)\n\n this.log?.(`Created new transport for session ${sessionId}`)\n this.config.onSessionCreated?.(sessionId)\n\n return transport\n }\n\n /**\n * Destroy a session.\n */\n destroySession(sessionId: string): boolean {\n if (this.sessions.has(sessionId)) {\n const transport = this.sessions.get(sessionId)\n this.sessions.delete(sessionId)\n this.requestContexts.delete(sessionId) // Clean up request context\n this.log?.(`Destroyed session ${sessionId}`)\n this.config.onSessionDestroyed?.(sessionId)\n\n // Try to close the transport if it has a close method\n if (transport && typeof transport.close === 'function') {\n try {\n transport.close()\n } catch {\n // Ignore close errors\n }\n }\n\n return true\n }\n return false\n }\n\n /**\n * Get all active session IDs.\n */\n getActiveSessions(): string[] {\n return Array.from(this.sessions.keys())\n }\n\n /**\n * Get the number of active sessions.\n */\n getSessionCount(): number {\n return this.sessions.size\n }\n\n /**\n * Destroy all sessions.\n */\n destroyAllSessions(): void {\n const sessionIds = this.getActiveSessions()\n for (const sessionId of sessionIds) {\n this.destroySession(sessionId)\n }\n this.log?.(`Destroyed all ${sessionIds.length} sessions`)\n }\n\n /**\n * Internal logging helper (no-op if log not provided).\n */\n private log(message: string): void {\n this.config.log?.(message)\n }\n}\n\n/**\n * Create a new session manager.\n */\nexport function createSessionManager(config: SessionManagerConfig = {}): SessionManager {\n return new SessionManager(config)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-manager.js","sourceRoot":"","sources":["../../../src/mcp/http/session-manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,mEAAmE;AACnE,IAAI,6BAA6B,GAAQ,IAAI,CAAA;AAa7C;;GAEG;AACH,KAAK,UAAU,iBAAiB;IAC9B,IAAI,CAAC,6BAA6B,EAAE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;IACH,eAAe;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAC3C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;QAChC,CAAC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,UAAU,CAAC,MAAM,WAAW,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACK,GAAG,CAAC,OAAe;QACzB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAA;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA+B,EAAE;IACpE,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC","sourcesContent":["/**\n * Session manager for MCP transports.\n * Handles creation, retrieval, and cleanup of StreamableHTTPServerTransport instances.\n * Also stores request context (headers) per session for authentication.\n */\nimport { randomUUID } from 'crypto'\n\n// We'll dynamically import the SDK to avoid hard dependency issues\nlet StreamableHTTPServerTransport: any = null\n\n/**\n * Request context stored per session.\n * Contains HTTP headers and other request info needed for authentication.\n */\nexport interface RequestContext {\n headers: Record<string, string | string[] | undefined>\n method?: string\n url?: string\n ip?: string\n}\n\n/**\n * Lazily load the MCP SDK transport.\n */\nasync function getTransportClass(): Promise<any> {\n if (!StreamableHTTPServerTransport) {\n try {\n const module = await import('@modelcontextprotocol/sdk/server/streamableHttp.js')\n StreamableHTTPServerTransport = module.StreamableHTTPServerTransport\n } catch (error) {\n throw new Error(\n 'Failed to load @modelcontextprotocol/sdk. Make sure it is installed: npm install @modelcontextprotocol/sdk',\n )\n }\n }\n return StreamableHTTPServerTransport\n}\n\n/**\n * Configuration for session manager.\n */\nexport interface SessionManagerConfig {\n /** Callback when a session is created */\n onSessionCreated?: (sessionId: string) => void\n /** Callback when a session is destroyed */\n onSessionDestroyed?: (sessionId: string) => void\n /** Logger function */\n log?: (message: string) => void\n}\n\n/**\n * Manages MCP transport sessions.\n */\nexport class SessionManager {\n private sessions: Map<string, any> = new Map()\n private requestContexts: Map<string, RequestContext> = new Map()\n private mcpServer: any = null\n private config: SessionManagerConfig\n\n constructor(config: SessionManagerConfig = {}) {\n this.config = config\n }\n\n /**\n * Set the MCP server that transports will connect to.\n */\n setMcpServer(server: any): void {\n this.mcpServer = server\n }\n\n /**\n * Generate a new session ID.\n */\n generateSessionId(): string {\n return randomUUID()\n }\n\n /**\n * Check if a session exists.\n */\n hasSession(sessionId: string): boolean {\n return this.sessions.has(sessionId)\n }\n\n /**\n * Get an existing session's transport.\n */\n getSession(sessionId: string): any | undefined {\n return this.sessions.get(sessionId)\n }\n\n /**\n * Store request context (headers, etc.) for a session.\n * This is called when an HTTP request arrives, before dispatching to MCP.\n */\n setRequestContext(sessionId: string, context: RequestContext): void {\n this.requestContexts.set(sessionId, context)\n }\n\n /**\n * Get the stored request context for a session.\n * Returns undefined if no context is stored.\n */\n getRequestContext(sessionId: string): RequestContext | undefined {\n return this.requestContexts.get(sessionId)\n }\n\n /**\n * Get or create a transport for a session.\n */\n async getOrCreateSession(sessionId: string): Promise<any> {\n if (this.sessions.has(sessionId)) {\n const existingSession = this.sessions.get(sessionId)\n if (existingSession) {\n return existingSession\n }\n }\n\n if (!this.mcpServer) {\n throw new Error('MCP server not set. Call setMcpServer() first.')\n }\n\n // In stateless mode (sessionIdGenerator: undefined), each request gets a new transport\n // but McpServer can only have one transport at a time. Close the existing connection\n // before connecting the new transport so Protocol._transport is reset to undefined.\n // The StreamableHTTPServerTransport with enableJsonResponse does not auto-close after\n // sending a JSON response, so we must close it explicitly before each new connection.\n try {\n await this.mcpServer.close()\n } catch (_e) {\n // Ignore close errors — server may not have been connected yet\n }\n\n const TransportClass = await getTransportClass()\n\n // Use stateless mode (sessionIdGenerator: undefined) to avoid requiring\n // Mcp-Session-Id header on every request. This allows clients to make\n // direct JSON-RPC calls without the full MCP initialization handshake.\n const transport = new TransportClass({\n sessionIdGenerator: undefined,\n enableJsonResponse: true,\n })\n\n // Set onclose BEFORE connect() so the SDK chains it with its own handler.\n // When the transport closes, both our cleanup and the SDK's cleanup run.\n transport.onclose = () => {\n this.sessions.delete(sessionId)\n this.requestContexts.delete(sessionId)\n this.config.onSessionDestroyed?.(sessionId)\n this.log?.(`Transport closed for session ${sessionId}`)\n }\n\n await this.mcpServer.connect(transport)\n\n // Force _initialized to true to allow requests without requiring initialize first.\n // This maintains backward compatibility with clients that don't send initialize.\n // The SDK sets _initialized = true only after processing an initialize request,\n // but we want to accept tool/resource/prompt calls directly.\n if (transport._initialized === false) {\n transport._initialized = true\n }\n\n this.sessions.set(sessionId, transport)\n\n this.log?.(`Created new transport for session ${sessionId}`)\n this.config.onSessionCreated?.(sessionId)\n\n return transport\n }\n\n /**\n * Destroy a session.\n */\n destroySession(sessionId: string): boolean {\n if (this.sessions.has(sessionId)) {\n const transport = this.sessions.get(sessionId)\n this.sessions.delete(sessionId)\n this.requestContexts.delete(sessionId) // Clean up request context\n this.log?.(`Destroyed session ${sessionId}`)\n this.config.onSessionDestroyed?.(sessionId)\n\n // Try to close the transport if it has a close method\n if (transport && typeof transport.close === 'function') {\n try {\n transport.close()\n } catch {\n // Ignore close errors\n }\n }\n\n return true\n }\n return false\n }\n\n /**\n * Get all active session IDs.\n */\n getActiveSessions(): string[] {\n return Array.from(this.sessions.keys())\n }\n\n /**\n * Get the number of active sessions.\n */\n getSessionCount(): number {\n return this.sessions.size\n }\n\n /**\n * Destroy all sessions.\n */\n destroyAllSessions(): void {\n const sessionIds = this.getActiveSessions()\n for (const sessionId of sessionIds) {\n this.destroySession(sessionId)\n }\n this.log?.(`Destroyed all ${sessionIds.length} sessions`)\n }\n\n /**\n * Internal logging helper (no-op if log not provided).\n */\n private log(message: string): void {\n this.config.log?.(message)\n }\n}\n\n/**\n * Create a new session manager.\n */\nexport function createSessionManager(config: SessionManagerConfig = {}): SessionManager {\n return new SessionManager(config)\n}\n"]}
|
package/dist/payments.d.ts
CHANGED
|
@@ -69,7 +69,23 @@ export declare class Payments extends BasePaymentsAPI {
|
|
|
69
69
|
configure: (options: mcpModule.ExtendedMcpConfig) => void;
|
|
70
70
|
withPaywall: {
|
|
71
71
|
<TArgs = any>(handler: (args: TArgs, extra?: any, context?: mcpModule.PaywallContext) => Promise<any> | any, options: import("./mcp/types/paywall.types.js").ToolOptions | import("./mcp/types/paywall.types.js").PromptOptions): (args: TArgs, extra?: any) => Promise<any>;
|
|
72
|
-
<TArgs = any>(handler: (args: TArgs, extra?: any, context
|
|
72
|
+
<TArgs = any>(handler: (args: TArgs, extra?: any, context
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a user is logged in.
|
|
75
|
+
* @example
|
|
76
|
+
* ```
|
|
77
|
+
* payments.isLoggedIn
|
|
78
|
+
* ```
|
|
79
|
+
* @returns True if the user is logged in.
|
|
80
|
+
*/
|
|
81
|
+
? /**
|
|
82
|
+
* Checks if a user is logged in.
|
|
83
|
+
* @example
|
|
84
|
+
* ```
|
|
85
|
+
* payments.isLoggedIn
|
|
86
|
+
* ```
|
|
87
|
+
* @returns True if the user is logged in.
|
|
88
|
+
*/: mcpModule.PaywallContext) => Promise<any> | any): (args: TArgs, extra?: any) => Promise<any>;
|
|
73
89
|
(handler: (uri: URL, variables: Record<string, string | string[]>, extra?: any, context?: mcpModule.PaywallContext) => Promise<any> | any, options: import("./mcp/types/paywall.types.js").ResourceOptions): (uri: URL, variables: Record<string, string | string[]>, extra?: any) => Promise<any>;
|
|
74
90
|
};
|
|
75
91
|
attach: (server: {
|
package/dist/payments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;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