@nevermined-io/payments 1.3.2 → 1.4.1
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/api/agents-api.d.ts +4 -3
- package/dist/api/agents-api.d.ts.map +1 -1
- package/dist/api/agents-api.js +5 -5
- package/dist/api/agents-api.js.map +1 -1
- package/dist/api/base-payments.d.ts +49 -1
- package/dist/api/base-payments.d.ts.map +1 -1
- package/dist/api/base-payments.js +82 -16
- package/dist/api/base-payments.js.map +1 -1
- package/dist/api/nvm-api.d.ts +2 -1
- package/dist/api/nvm-api.d.ts.map +1 -1
- package/dist/api/nvm-api.js +2 -1
- package/dist/api/nvm-api.js.map +1 -1
- package/dist/api/organizations-api/organizations-api.d.ts +42 -1
- package/dist/api/organizations-api/organizations-api.d.ts.map +1 -1
- package/dist/api/organizations-api/organizations-api.js +91 -3
- package/dist/api/organizations-api/organizations-api.js.map +1 -1
- package/dist/api/organizations-api/types.d.ts +134 -0
- package/dist/api/organizations-api/types.d.ts.map +1 -1
- package/dist/api/organizations-api/types.js +52 -0
- package/dist/api/organizations-api/types.js.map +1 -1
- package/dist/api/plans-api.d.ts +15 -36
- package/dist/api/plans-api.d.ts.map +1 -1
- package/dist/api/plans-api.js +22 -57
- package/dist/api/plans-api.js.map +1 -1
- package/dist/common/types.d.ts +38 -15
- package/dist/common/types.d.ts.map +1 -1
- 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 +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- 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 +26 -1
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +43 -11
- package/dist/payments.js.map +1 -1
- package/dist/plans.d.ts +1 -1
- package/dist/plans.js +6 -6
- package/dist/plans.js.map +1 -1
- package/dist/x402/delegation-api.d.ts +34 -7
- package/dist/x402/delegation-api.d.ts.map +1 -1
- package/dist/x402/delegation-api.js +15 -3
- package/dist/x402/delegation-api.js.map +1 -1
- package/dist/x402/facilitator-api.d.ts +5 -6
- package/dist/x402/facilitator-api.d.ts.map +1 -1
- package/dist/x402/facilitator-api.js +17 -5
- package/dist/x402/facilitator-api.js.map +1 -1
- package/dist/x402/index.d.ts +2 -6
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +1 -4
- package/dist/x402/index.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/README.md
CHANGED
|
@@ -33,12 +33,14 @@ The library is designed for use in browser environments or as part of AI Agents:
|
|
|
33
33
|
## Quickstart
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
#
|
|
37
|
-
|
|
36
|
+
# pnpm
|
|
37
|
+
pnpm add @nevermined-io/payments@^1.1
|
|
38
38
|
|
|
39
39
|
# npm
|
|
40
|
-
npm install @nevermined-io/payments
|
|
40
|
+
npm install @nevermined-io/payments@^1.1
|
|
41
41
|
```
|
|
42
|
+
|
|
43
|
+
> Pin the major version (or rely on a committed lockfile) so SDK upgrades are explicit. Always commit `package-lock.json` / `pnpm-lock.yaml`.
|
|
42
44
|
## A2A Integration (Agents‑to‑Agents)
|
|
43
45
|
|
|
44
46
|
Nevermined Payments integrates with the A2A protocol to authorize and charge per request between agents:
|
package/dist/api/agents-api.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AgentAPIAttributes, AgentMetadata, NvmAPIResult, PaginationOptions, PaymentOptions, PlanCreditsConfig, PlanMetadata, PlanPriceConfig } from '../common/types.js';
|
|
2
|
-
import { BasePaymentsAPI } from './base-payments.js';
|
|
2
|
+
import { BasePaymentsAPI, PublicationOptions } from './base-payments.js';
|
|
3
|
+
export type { PublicationOptions } from './base-payments.js';
|
|
3
4
|
/**
|
|
4
5
|
* The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.
|
|
5
6
|
*/
|
|
@@ -38,7 +39,7 @@ export declare class AgentsAPI extends BasePaymentsAPI {
|
|
|
38
39
|
*
|
|
39
40
|
* @returns The unique identifier of the newly created agent (Agent Id).
|
|
40
41
|
*/
|
|
41
|
-
registerAgent(agentMetadata: AgentMetadata, agentApi: AgentAPIAttributes, paymentPlans: string[]): Promise<{
|
|
42
|
+
registerAgent(agentMetadata: AgentMetadata, agentApi: AgentAPIAttributes, paymentPlans: string[], publicationOptions?: PublicationOptions): Promise<{
|
|
42
43
|
agentId: string;
|
|
43
44
|
}>;
|
|
44
45
|
/**
|
|
@@ -75,7 +76,7 @@ export declare class AgentsAPI extends BasePaymentsAPI {
|
|
|
75
76
|
* @returns The unique identifier of the newly created agent (agentId).
|
|
76
77
|
* @returns The unique identifier of the newly created plan (planId).
|
|
77
78
|
*/
|
|
78
|
-
registerAgentAndPlan(agentMetadata: AgentMetadata, agentApi: AgentAPIAttributes, planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, accessLimit?: 'credits' | 'time'): Promise<{
|
|
79
|
+
registerAgentAndPlan(agentMetadata: AgentMetadata, agentApi: AgentAPIAttributes, planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, accessLimit?: 'credits' | 'time', publicationOptions?: PublicationOptions): Promise<{
|
|
79
80
|
agentId: string;
|
|
80
81
|
planId: string;
|
|
81
82
|
txHash: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents-api.d.ts","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"agents-api.d.ts","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAA6B,MAAM,oBAAoB,CAAA;AAWnG,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D;;GAEG;AACH,qBAAa,SAAU,SAAQ,eAAe;IAC5C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS;IAItD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,aAAa,CACxB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,kBAAkB,EAC5B,YAAY,EAAE,MAAM,EAAE,EACtB,kBAAkB,CAAC,EAAE,kBAAkB,GACtC,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAsB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACU,oBAAoB,CAC/B,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,kBAAkB,EAC5B,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,eAAe,EAC5B,aAAa,EAAE,iBAAiB,EAChC,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM,EAChC,kBAAkB,CAAC,EAAE,kBAAkB,GACtC,OAAO,CAAC;QACT,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,CAAA;QACd,MAAM,EAAE,MAAM,CAAA;KACf,CAAC;IAyCF;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,OAAO,EAAE,MAAM;IASrC;;;;;;;;;;;;;;;;OAgBG;IACU,mBAAmB,CAC9B,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,YAAY,CAAC;IAcxB;;;;;;;;;;;;;;;;;;OAkBG;IACU,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,oBAA0B;IAWhF;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAYnF;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAczF"}
|
package/dist/api/agents-api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PaymentsError } from '../common/payments.error.js';
|
|
2
2
|
import { PaginationOptions, } from '../common/types.js';
|
|
3
|
-
import { BasePaymentsAPI } from './base-payments.js';
|
|
3
|
+
import { BasePaymentsAPI, resolvePublicationHeaders } from './base-payments.js';
|
|
4
4
|
import { API_URL_ADD_PLAN_AGENT, API_URL_GET_AGENT, API_URL_GET_AGENT_PLANS, API_URL_REGISTER_AGENT, API_URL_REGISTER_AGENTS_AND_PLAN, API_URL_REMOVE_PLAN_AGENT, API_URL_UPDATE_AGENT, } from './nvm-api.js';
|
|
5
5
|
/**
|
|
6
6
|
* The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.
|
|
@@ -42,13 +42,13 @@ export class AgentsAPI extends BasePaymentsAPI {
|
|
|
42
42
|
*
|
|
43
43
|
* @returns The unique identifier of the newly created agent (Agent Id).
|
|
44
44
|
*/
|
|
45
|
-
async registerAgent(agentMetadata, agentApi, paymentPlans) {
|
|
45
|
+
async registerAgent(agentMetadata, agentApi, paymentPlans, publicationOptions) {
|
|
46
46
|
const body = {
|
|
47
47
|
metadataAttributes: agentMetadata,
|
|
48
48
|
agentApiAttributes: agentApi,
|
|
49
49
|
plans: paymentPlans,
|
|
50
50
|
};
|
|
51
|
-
const options = this.getBackendHTTPOptions('POST', body);
|
|
51
|
+
const options = this.getBackendHTTPOptions('POST', body, resolvePublicationHeaders(publicationOptions));
|
|
52
52
|
const url = new URL(API_URL_REGISTER_AGENT, this.environment.backend);
|
|
53
53
|
const response = await fetch(url, options);
|
|
54
54
|
if (!response.ok) {
|
|
@@ -91,7 +91,7 @@ export class AgentsAPI extends BasePaymentsAPI {
|
|
|
91
91
|
* @returns The unique identifier of the newly created agent (agentId).
|
|
92
92
|
* @returns The unique identifier of the newly created plan (planId).
|
|
93
93
|
*/
|
|
94
|
-
async registerAgentAndPlan(agentMetadata, agentApi, planMetadata, priceConfig, creditsConfig, accessLimit) {
|
|
94
|
+
async registerAgentAndPlan(agentMetadata, agentApi, planMetadata, priceConfig, creditsConfig, accessLimit, publicationOptions) {
|
|
95
95
|
if (accessLimit && !['credits', 'time'].includes(accessLimit)) {
|
|
96
96
|
throw new PaymentsError('Invalid access limit', 'accessLimit must be either "credits" or "time"');
|
|
97
97
|
}
|
|
@@ -110,7 +110,7 @@ export class AgentsAPI extends BasePaymentsAPI {
|
|
|
110
110
|
agentApiAttributes: agentApi,
|
|
111
111
|
},
|
|
112
112
|
};
|
|
113
|
-
const options = this.getBackendHTTPOptions('POST', body);
|
|
113
|
+
const options = this.getBackendHTTPOptions('POST', body, resolvePublicationHeaders(publicationOptions));
|
|
114
114
|
const url = new URL(API_URL_REGISTER_AGENTS_AND_PLAN, this.environment.backend);
|
|
115
115
|
const response = await fetch(url, options);
|
|
116
116
|
if (!response.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents-api.js","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAIL,iBAAiB,GAKlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,eAAe;IAC5C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACI,KAAK,CAAC,aAAa,CACxB,aAA4B,EAC5B,QAA4B,EAC5B,YAAsB;QAEtB,MAAM,IAAI,GAAG;YACX,kBAAkB,EAAE,aAAa;YACjC,kBAAkB,EAAE,QAAQ;YAC5B,KAAK,EAAE,YAAY;SACpB,CAAA;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAErE,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;QACD,MAA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,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAAC,6BAA6B,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;QACvF,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,KAAK,CAAC,mBAAmB,CAAC,MAAc,EAAE,OAAe;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,OAAO,CAC3E,UAAU,EACV,OAAO,CACR,CAAA;QACD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QACvD,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,kCAAkC,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5F,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { PaymentsError } from '../common/payments.error.js'\nimport {\n AgentAPIAttributes,\n AgentMetadata,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanCreditsConfig,\n PlanMetadata,\n PlanPriceConfig,\n} from '../common/types.js'\nimport { BasePaymentsAPI } from './base-payments.js'\nimport {\n API_URL_ADD_PLAN_AGENT,\n API_URL_GET_AGENT,\n API_URL_GET_AGENT_PLANS,\n API_URL_REGISTER_AGENT,\n API_URL_REGISTER_AGENTS_AND_PLAN,\n API_URL_REMOVE_PLAN_AGENT,\n API_URL_UPDATE_AGENT,\n} from './nvm-api.js'\n\n/**\n * The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.\n */\nexport class AgentsAPI extends BasePaymentsAPI {\n /**\n * This method is used to create a singleton instance of the AgentsAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the AgentsAPI class.\n */\n static getInstance(options: PaymentOptions): AgentsAPI {\n return new AgentsAPI(options)\n }\n\n /**\n *\n * It registers a new AI Agent on Nevermined.\n * The agent must be associated to one or multiple Payment Plans. Users that are subscribers of a payment plan can query the agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\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/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param paymentPlans - the list of payment plans giving access to the agent.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const paymentPlans = [planId]\n *\n * const { agentId } = await payments.agents.registerAgent(agentMetadata, agentApi, paymentPlans)\n * ```\n *\n * @returns The unique identifier of the newly created agent (Agent Id).\n */\n public async registerAgent(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n paymentPlans: string[],\n ): Promise<{ agentId: string }> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n plans: paymentPlans,\n }\n\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_REGISTER_AGENT, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent', await response.json())\n }\n const agentData = await response.json()\n return { agentId: agentData.data.agentId }\n }\n\n /**\n *\n * It registers a new AI Agent and a Payment Plan associated to this new agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\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/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { agentId, planId } = await payments.agents.registerAgentAndPlan(\n * agentMetadata,\n * agentApi,\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the newly created agent (agentId).\n * @returns The unique identifier of the newly created plan (planId).\n */\n public async registerAgentAndPlan(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n accessLimit?: 'credits' | 'time',\n ): Promise<{\n agentId: string\n planId: string\n txHash: string\n }> {\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 plan: {\n metadataAttributes: planMetadata,\n priceConfig: priceConfig,\n creditsConfig: creditsConfig,\n accessLimit,\n },\n agent: {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n },\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_REGISTER_AGENTS_AND_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent & plan', await response.json())\n }\n const result = await response.json()\n return {\n agentId: result.data.agentId,\n planId: result.data.planId,\n txHash: result.txHash,\n }\n }\n\n /**\n * Gets the metadata for a given Agent identifier.\n *\n * @param agentId - The unique identifier of the agent.\n * @returns A promise that resolves to the agent's metadata.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const plan = payments.agents.getAgent(agentId)\n * ```\n */\n public async getAgent(agentId: string) {\n const url = new URL(API_URL_GET_AGENT.replace(':agentId', agentId), this.environment.backend)\n const response = await fetch(url)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await response.json())\n }\n return response.json()\n }\n\n /**\n * Updates the metadata and API attributes of an existing AI Agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param agentMetadata - The new metadata attributes for the agent.\n * @param agentApi - The new API attributes for the agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if the agent is not found or if the update fails.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My Updated Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://nevermined.app/api/v1/agents/:agentId/tasks' }] }\n *\n * await payments.agents.updateAgentMetadata(agentId, agentMetadata, agentApi)\n * ```\n */\n public async updateAgentMetadata(\n agentId: string,\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n ): Promise<NvmAPIResult> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n }\n const url = new URL(API_URL_UPDATE_AGENT.replace(':agentId', agentId), this.environment.backend)\n const options = this.getBackendHTTPOptions('PUT', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Error updating agent', await response.json())\n }\n return response.json()\n }\n\n /**\n * Gets the list of plans that can be ordered to get access to an agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param pagination - Optional pagination options to control the number of results returned.p\n * @returns A promise that resolves to the list of all different plans giving access to the agent.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const result = payments.agents.getAgentPlans(planId)\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // plans: [ ..]\n * // }\n * ```\n */\n public async getAgentPlans(agentId: string, pagination = new PaginationOptions()) {\n const query =\n API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) + '?' + 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('Agent not found', await response.json())\n }\n return response.json()\n }\n\n /**\n * Adds an existing Payment Plan to an AI Agent.\n * After this operation, users with access to the Payment Plan will be able to access the AI Agent.\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 agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to add the plan to the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.addPlanToAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async addPlanToAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const endpoint = API_URL_ADD_PLAN_AGENT.replace(':planId', planId).replace(':agentId', agentId)\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to add plan to agent', await response.json())\n }\n\n return response.json()\n }\n\n /**\n * Removes a Payment Plan from an AI Agent.\n * After this operation, users with access to the Payment Plan will no longer be able to access the AI Agent.\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 agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to remove the plan from the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.removePlanFromAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async removePlanFromAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('DELETE')\n const endpoint = API_URL_REMOVE_PLAN_AGENT.replace(':planId', planId).replace(\n ':agentId',\n agentId,\n )\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to remove plan from agent', await response.json())\n }\n\n return response.json()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agents-api.js","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAIL,iBAAiB,GAKlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAsB,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAA;AAIrB;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,eAAe;IAC5C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACI,KAAK,CAAC,aAAa,CACxB,aAA4B,EAC5B,QAA4B,EAC5B,YAAsB,EACtB,kBAAuC;QAEvC,MAAM,IAAI,GAAG;Y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E,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAAC,kCAAkC,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5F,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { PaymentsError } from '../common/payments.error.js'\nimport {\n AgentAPIAttributes,\n AgentMetadata,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanCreditsConfig,\n PlanMetadata,\n PlanPriceConfig,\n} from '../common/types.js'\nimport { BasePaymentsAPI, PublicationOptions, resolvePublicationHeaders } from './base-payments.js'\nimport {\n API_URL_ADD_PLAN_AGENT,\n API_URL_GET_AGENT,\n API_URL_GET_AGENT_PLANS,\n API_URL_REGISTER_AGENT,\n API_URL_REGISTER_AGENTS_AND_PLAN,\n API_URL_REMOVE_PLAN_AGENT,\n API_URL_UPDATE_AGENT,\n} from './nvm-api.js'\n\nexport type { PublicationOptions } from './base-payments.js'\n\n/**\n * The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.\n */\nexport class AgentsAPI extends BasePaymentsAPI {\n /**\n * This method is used to create a singleton instance of the AgentsAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the AgentsAPI class.\n */\n static getInstance(options: PaymentOptions): AgentsAPI {\n return new AgentsAPI(options)\n }\n\n /**\n *\n * It registers a new AI Agent on Nevermined.\n * The agent must be associated to one or multiple Payment Plans. Users that are subscribers of a payment plan can query the agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\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/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param paymentPlans - the list of payment plans giving access to the agent.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const paymentPlans = [planId]\n *\n * const { agentId } = await payments.agents.registerAgent(agentMetadata, agentApi, paymentPlans)\n * ```\n *\n * @returns The unique identifier of the newly created agent (Agent Id).\n */\n public async registerAgent(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n paymentPlans: string[],\n publicationOptions?: PublicationOptions,\n ): Promise<{ agentId: string }> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n plans: paymentPlans,\n }\n\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENT, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent', await response.json())\n }\n const agentData = await response.json()\n return { agentId: agentData.data.agentId }\n }\n\n /**\n *\n * It registers a new AI Agent and a Payment Plan associated to this new agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\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/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { agentId, planId } = await payments.agents.registerAgentAndPlan(\n * agentMetadata,\n * agentApi,\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the newly created agent (agentId).\n * @returns The unique identifier of the newly created plan (planId).\n */\n public async registerAgentAndPlan(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n accessLimit?: 'credits' | 'time',\n publicationOptions?: PublicationOptions,\n ): Promise<{\n agentId: string\n planId: string\n txHash: string\n }> {\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 plan: {\n metadataAttributes: planMetadata,\n priceConfig: priceConfig,\n creditsConfig: creditsConfig,\n accessLimit,\n },\n agent: {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n },\n }\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENTS_AND_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent & plan', await response.json())\n }\n const result = await response.json()\n return {\n agentId: result.data.agentId,\n planId: result.data.planId,\n txHash: result.txHash,\n }\n }\n\n /**\n * Gets the metadata for a given Agent identifier.\n *\n * @param agentId - The unique identifier of the agent.\n * @returns A promise that resolves to the agent's metadata.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const plan = payments.agents.getAgent(agentId)\n * ```\n */\n public async getAgent(agentId: string) {\n const url = new URL(API_URL_GET_AGENT.replace(':agentId', agentId), this.environment.backend)\n const response = await fetch(url)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await response.json())\n }\n return response.json()\n }\n\n /**\n * Updates the metadata and API attributes of an existing AI Agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param agentMetadata - The new metadata attributes for the agent.\n * @param agentApi - The new API attributes for the agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if the agent is not found or if the update fails.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My Updated Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://nevermined.app/api/v1/agents/:agentId/tasks' }] }\n *\n * await payments.agents.updateAgentMetadata(agentId, agentMetadata, agentApi)\n * ```\n */\n public async updateAgentMetadata(\n agentId: string,\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n ): Promise<NvmAPIResult> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n }\n const url = new URL(API_URL_UPDATE_AGENT.replace(':agentId', agentId), this.environment.backend)\n const options = this.getBackendHTTPOptions('PUT', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Error updating agent', await response.json())\n }\n return response.json()\n }\n\n /**\n * Gets the list of plans that can be ordered to get access to an agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param pagination - Optional pagination options to control the number of results returned.p\n * @returns A promise that resolves to the list of all different plans giving access to the agent.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const result = payments.agents.getAgentPlans(planId)\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // plans: [ ..]\n * // }\n * ```\n */\n public async getAgentPlans(agentId: string, pagination = new PaginationOptions()) {\n const query =\n API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) + '?' + 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('Agent not found', await response.json())\n }\n return response.json()\n }\n\n /**\n * Adds an existing Payment Plan to an AI Agent.\n * After this operation, users with access to the Payment Plan will be able to access the AI Agent.\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 agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to add the plan to the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.addPlanToAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async addPlanToAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const endpoint = API_URL_ADD_PLAN_AGENT.replace(':planId', planId).replace(':agentId', agentId)\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to add plan to agent', await response.json())\n }\n\n return response.json()\n }\n\n /**\n * Removes a Payment Plan from an AI Agent.\n * After this operation, users with access to the Payment Plan will no longer be able to access the AI Agent.\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 agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to remove the plan from the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.removePlanFromAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async removePlanFromAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('DELETE')\n const endpoint = API_URL_REMOVE_PLAN_AGENT.replace(':planId', planId).replace(\n ':agentId',\n agentId,\n )\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to remove plan from agent', await response.json())\n }\n\n return response.json()\n }\n}\n"]}
|
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import { PaymentOptions, PaymentScheme } from '../common/types.js';
|
|
2
2
|
import { EnvironmentInfo, EnvironmentName } from '../environments.js';
|
|
3
|
+
/**
|
|
4
|
+
* Header used by the Nevermined backend to resolve the active organization
|
|
5
|
+
* context for an authenticated request. Resolution priority is:
|
|
6
|
+
* path `:orgId` > this header > API-key tag > fallback membership > personal.
|
|
7
|
+
* See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CURRENT_ORG_ID_HEADER = "X-Current-Org-Id";
|
|
10
|
+
/**
|
|
11
|
+
* Options accepted by publication methods (`registerAgent`,
|
|
12
|
+
* `registerAgentAndPlan`, `registerPlan`, …) that want to override the
|
|
13
|
+
* active organization workspace for a single call.
|
|
14
|
+
*/
|
|
15
|
+
export type PublicationOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Organization id (e.g. `org-…`) to publish into. When set, the SDK
|
|
18
|
+
* sends an `X-Current-Org-Id` header for this call only — the caller's
|
|
19
|
+
* instance-level pin (set via `Payments.setOrganizationId`) is not
|
|
20
|
+
* affected.
|
|
21
|
+
*/
|
|
22
|
+
organizationId?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Builds the `extraHeaders` argument for `getBackendHTTPOptions` from
|
|
26
|
+
* publication options. Returns `undefined` when no override is requested
|
|
27
|
+
* so existing callers receive identical request shapes.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolvePublicationHeaders(options?: PublicationOptions): Record<string, string> | undefined;
|
|
3
30
|
/**
|
|
4
31
|
* Base class extended by all Payments API classes.
|
|
5
32
|
* It provides common functionality such as parsing the NVM API Key and getting the account address.
|
|
@@ -14,6 +41,7 @@ export declare abstract class BasePaymentsAPI {
|
|
|
14
41
|
protected version?: string;
|
|
15
42
|
protected accountAddress: string;
|
|
16
43
|
protected heliconeApiKey: string;
|
|
44
|
+
protected currentOrganizationId: string | null;
|
|
17
45
|
isBrowserInstance: boolean;
|
|
18
46
|
constructor(options: PaymentOptions);
|
|
19
47
|
/**
|
|
@@ -34,14 +62,34 @@ export declare abstract class BasePaymentsAPI {
|
|
|
34
62
|
* @returns The account address extracted from the NVM API Key
|
|
35
63
|
*/
|
|
36
64
|
getAccountAddress(): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current organization context applied to every authenticated
|
|
67
|
+
* backend request via the `X-Current-Org-Id` header.
|
|
68
|
+
*
|
|
69
|
+
* `null` means "no pinned workspace" — the backend falls back to the
|
|
70
|
+
* caller's API-key tag or most-recent active membership.
|
|
71
|
+
*/
|
|
72
|
+
getOrganizationId(): string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Sets the organization context applied to every subsequent authenticated
|
|
75
|
+
* backend request via the `X-Current-Org-Id` header.
|
|
76
|
+
*
|
|
77
|
+
* Pass `null` to clear the pin and fall back to the backend default.
|
|
78
|
+
*
|
|
79
|
+
* @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.
|
|
80
|
+
*/
|
|
81
|
+
setOrganizationId(organizationId: string | null): void;
|
|
37
82
|
/**
|
|
38
83
|
* Returns the HTTP options required to query the backend.
|
|
39
84
|
* @param method - HTTP method.
|
|
40
85
|
* @param body - Optional request body.
|
|
86
|
+
* @param extraHeaders - Optional per-call header overrides. Use
|
|
87
|
+
* `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for
|
|
88
|
+
* one call without mutating the instance-level pin.
|
|
41
89
|
* @returns HTTP options object.
|
|
42
90
|
* @internal
|
|
43
91
|
*/
|
|
44
|
-
protected getBackendHTTPOptions(method: string, body?: any): any;
|
|
92
|
+
protected getBackendHTTPOptions(method: string, body?: any, extraHeaders?: Record<string, string>): any;
|
|
45
93
|
/**
|
|
46
94
|
* Get HTTP options for public backend requests (no authorization header).
|
|
47
95
|
* Converts body keys from snake_case to camelCase for consistency.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-payments.d.ts","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAgB,MAAM,oBAAoB,CAAA;AAEnF;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,MAAM,EAAE,aAAa,CAAA;IAC/B,SAAS,CAAC,WAAW,EAAE,eAAe,CAAA;IACtC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAA;IAC1C,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IAC1B,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;IAChC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"base-payments.d.ts","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAgB,MAAM,oBAAoB,CAAA;AAEnF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,qBAAqB,CAAA;AAUvD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAKpC;AAED;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,SAAS,EAA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|
2
2
|
import { jsonReplacer } from '../common/helper.js';
|
|
3
3
|
import { PaymentsError } from '../common/payments.error.js';
|
|
4
4
|
import { Environments } from '../environments.js';
|
|
5
|
+
/**
|
|
6
|
+
* Header used by the Nevermined backend to resolve the active organization
|
|
7
|
+
* context for an authenticated request. Resolution priority is:
|
|
8
|
+
* path `:orgId` > this header > API-key tag > fallback membership > personal.
|
|
9
|
+
* See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.
|
|
10
|
+
*/
|
|
11
|
+
export const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id';
|
|
12
|
+
/**
|
|
13
|
+
* Set of header names that callers can pass to `getBackendHTTPOptions` via
|
|
14
|
+
* `extraHeaders`. Anything outside this set is dropped silently so a stray
|
|
15
|
+
* `Authorization` or `Content-Type` override can't clobber the SDK's
|
|
16
|
+
* transport security headers.
|
|
17
|
+
*/
|
|
18
|
+
const ALLOWED_EXTRA_HEADERS = new Set([CURRENT_ORG_ID_HEADER]);
|
|
19
|
+
/**
|
|
20
|
+
* Builds the `extraHeaders` argument for `getBackendHTTPOptions` from
|
|
21
|
+
* publication options. Returns `undefined` when no override is requested
|
|
22
|
+
* so existing callers receive identical request shapes.
|
|
23
|
+
*/
|
|
24
|
+
export function resolvePublicationHeaders(options) {
|
|
25
|
+
if (options?.organizationId) {
|
|
26
|
+
return { [CURRENT_ORG_ID_HEADER]: options.organizationId };
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
5
30
|
/**
|
|
6
31
|
* Base class extended by all Payments API classes.
|
|
7
32
|
* It provides common functionality such as parsing the NVM API Key and getting the account address.
|
|
@@ -9,6 +34,15 @@ import { Environments } from '../environments.js';
|
|
|
9
34
|
export class BasePaymentsAPI {
|
|
10
35
|
constructor(options) {
|
|
11
36
|
this.isBrowserInstance = true;
|
|
37
|
+
// Type-level narrowing of PaymentScheme to 'nvm' won't protect callers
|
|
38
|
+
// pinned to an older .d.ts that still has 'visa' in the union — they
|
|
39
|
+
// would silently fall through to the standard pipeline and hit a
|
|
40
|
+
// misleading 'Invalid NVM API Key' from parseNvmApiKey when the
|
|
41
|
+
// legacy Visa path tolerated a non-JWT key. Reject up front with a
|
|
42
|
+
// clear migration message.
|
|
43
|
+
if (options.scheme && options.scheme !== 'nvm') {
|
|
44
|
+
throw new PaymentsError(`scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`);
|
|
45
|
+
}
|
|
12
46
|
this.nvmApiKey = options.nvmApiKey;
|
|
13
47
|
this.scheme = options.scheme || 'nvm';
|
|
14
48
|
this.returnUrl = options.returnUrl || '';
|
|
@@ -16,16 +50,10 @@ export class BasePaymentsAPI {
|
|
|
16
50
|
this.environmentName = options.environment;
|
|
17
51
|
this.appId = options.appId;
|
|
18
52
|
this.version = options.version;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const { accountAddress, heliconeApiKey } = this.parseNvmApiKey();
|
|
26
|
-
this.accountAddress = accountAddress;
|
|
27
|
-
this.heliconeApiKey = heliconeApiKey;
|
|
28
|
-
}
|
|
53
|
+
this.currentOrganizationId = options.organizationId ?? null;
|
|
54
|
+
const { accountAddress, heliconeApiKey } = this.parseNvmApiKey();
|
|
55
|
+
this.accountAddress = accountAddress;
|
|
56
|
+
this.heliconeApiKey = heliconeApiKey;
|
|
29
57
|
}
|
|
30
58
|
/**
|
|
31
59
|
* Parses the NVM API Key to extract the account address.
|
|
@@ -59,21 +87,59 @@ export class BasePaymentsAPI {
|
|
|
59
87
|
getAccountAddress() {
|
|
60
88
|
return this.accountAddress;
|
|
61
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns the current organization context applied to every authenticated
|
|
92
|
+
* backend request via the `X-Current-Org-Id` header.
|
|
93
|
+
*
|
|
94
|
+
* `null` means "no pinned workspace" — the backend falls back to the
|
|
95
|
+
* caller's API-key tag or most-recent active membership.
|
|
96
|
+
*/
|
|
97
|
+
getOrganizationId() {
|
|
98
|
+
return this.currentOrganizationId;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sets the organization context applied to every subsequent authenticated
|
|
102
|
+
* backend request via the `X-Current-Org-Id` header.
|
|
103
|
+
*
|
|
104
|
+
* Pass `null` to clear the pin and fall back to the backend default.
|
|
105
|
+
*
|
|
106
|
+
* @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.
|
|
107
|
+
*/
|
|
108
|
+
setOrganizationId(organizationId) {
|
|
109
|
+
this.currentOrganizationId = organizationId;
|
|
110
|
+
}
|
|
62
111
|
/**
|
|
63
112
|
* Returns the HTTP options required to query the backend.
|
|
64
113
|
* @param method - HTTP method.
|
|
65
114
|
* @param body - Optional request body.
|
|
115
|
+
* @param extraHeaders - Optional per-call header overrides. Use
|
|
116
|
+
* `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for
|
|
117
|
+
* one call without mutating the instance-level pin.
|
|
66
118
|
* @returns HTTP options object.
|
|
67
119
|
* @internal
|
|
68
120
|
*/
|
|
69
|
-
getBackendHTTPOptions(method, body) {
|
|
121
|
+
getBackendHTTPOptions(method, body, extraHeaders) {
|
|
122
|
+
const headers = {
|
|
123
|
+
Accept: 'application/json',
|
|
124
|
+
'Content-Type': 'application/json',
|
|
125
|
+
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
126
|
+
};
|
|
127
|
+
if (this.currentOrganizationId) {
|
|
128
|
+
headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId;
|
|
129
|
+
}
|
|
130
|
+
if (extraHeaders) {
|
|
131
|
+
// Allowlist callers' header overrides so a passed-in `Authorization`
|
|
132
|
+
// or `Content-Type` can't clobber the SDK's transport security
|
|
133
|
+
// headers. Today only `X-Current-Org-Id` is allowed through.
|
|
134
|
+
for (const [name, value] of Object.entries(extraHeaders)) {
|
|
135
|
+
if (ALLOWED_EXTRA_HEADERS.has(name)) {
|
|
136
|
+
headers[name] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
70
140
|
return {
|
|
71
141
|
method,
|
|
72
|
-
headers
|
|
73
|
-
Accept: 'application/json',
|
|
74
|
-
'Content-Type': 'application/json',
|
|
75
|
-
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
76
|
-
},
|
|
142
|
+
headers,
|
|
77
143
|
...(body && { body: JSON.stringify(body, jsonReplacer) }),
|
|
78
144
|
};
|
|
79
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAoC,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAYnC,YAAY,OAAuB;QAF5B,sBAAiB,GAAG,IAAI,CAAA;QAG7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAA;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,WAA8B,CAAC,CAAA;QACvE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,WAAW,CAAA;QAC1C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAE9B,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC3B,kDAAkD;YAClD,IAAI,CAAC,cAAc,GAAG,EAAE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;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAOT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport { EnvironmentInfo, EnvironmentName, Environments } from '../environments.js'\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environment = Environments[options.environment as EnvironmentName]\n this.environmentName = options.environment\n this.appId = options.appId\n this.version = options.version\n\n if (this.scheme === 'visa') {\n // Visa scheme does not use JWT-based NVM API keys\n this.accountAddress = ''\n this.heliconeApiKey = ''\n } else {\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(method: string, body?: any) {\n return {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n },\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: {\n Accept: string\n 'Content-Type': string\n }\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAoC,YAAY,EAAE,MAAM,oB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B,EAAE,CAAC;YAC/B,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAA;QAC7D,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,qEAAqE;YACrE,+DAA+D;YAC/D,6DAA6D;YAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;gBACzD,IAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM;YACN,OAAO;YACP,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAOT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport { EnvironmentInfo, EnvironmentName, Environments } from '../environments.js'\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` > this header > API-key tag > fallback membership > personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environment = Environments[options.environment as EnvironmentName]\n this.environmentName = options.environment\n this.appId = options.appId\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: {\n Accept: string\n 'Content-Type': string\n }\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
|
package/dist/api/nvm-api.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare const API_URL_MINT_PLAN = "/api/v1/protocol/plans/mint";
|
|
|
12
12
|
export declare const API_URL_MINT_EXPIRABLE_PLAN = "/api/v1/protocol/plans/mintExpirable";
|
|
13
13
|
export declare const API_URL_ADD_PLAN_AGENT = "/api/v1/protocol/agents/:agentId/plan/:planId";
|
|
14
14
|
export declare const API_URL_REMOVE_PLAN_AGENT = "/api/v1/protocol/agents/:agentId/plan/:planId";
|
|
15
|
-
export declare const API_URL_REDEEM_PLAN = "/api/v1/protocol/plans/redeem";
|
|
16
15
|
export declare const API_URL_PLAN_BALANCE = "/api/v1/protocol/plans/:planId/balance/:holderAddress";
|
|
17
16
|
export declare const API_URL_INITIALIZE_AGENT = "/api/v1/protocol/agents/initialize/:agentId";
|
|
18
17
|
export declare const API_URL_SIMULATE_AGENT_REQUEST = "/api/v1/protocol/agents/simulate/start";
|
|
@@ -25,6 +24,8 @@ export declare const API_URL_SETTLE_PERMISSIONS = "/api/v1/x402/settle";
|
|
|
25
24
|
export declare const API_URL_STRIPE_CHECKOUT = "/api/v1/fiat/stripe/payment";
|
|
26
25
|
export declare const API_URL_CREATE_USER = "/api/v1/organizations/account";
|
|
27
26
|
export declare const API_URL_GET_MEMBERS = "/api/v1/organizations/members";
|
|
27
|
+
export declare const API_URL_MY_MEMBERSHIPS = "/api/v1/organizations/my-memberships";
|
|
28
|
+
export declare const API_URL_ORG_ACTIVITY = "/api/v1/organizations/:orgId/activity";
|
|
28
29
|
export declare const API_URL_CONNECT_STRIPE_ACCOUNT = "/api/v1/fiat/stripe/account";
|
|
29
30
|
export interface BackendApiOptions {
|
|
30
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nvm-api.d.ts","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,2BAA2B,CAAA;AAC7D,eAAO,MAAM,sBAAsB,4BAA4B,CAAA;AAC/D,eAAO,MAAM,gCAAgC,kCAAkC,CAAA;AAC/E,eAAO,MAAM,iBAAiB,qCAAqC,CAAA;AACnE,eAAO,MAAM,oBAAoB,qCAAqC,CAAA;AACtE,eAAO,MAAM,uBAAuB,2CAA2C,CAAA;AAC/E,eAAO,MAAM,gBAAgB,mCAAmC,CAAA;AAChE,eAAO,MAAM,iBAAiB,2BAA2B,CAAA;AACzD,eAAO,MAAM,uBAAuB,0CAA0C,CAAA;AAC9E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I,EAAE,GAAG,EAAE,UAAU,EAAE,kBAAkB;IAI3D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,kBAAkB;IAI1D,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,kBAAkB;CAGpE"}
|
package/dist/api/nvm-api.js
CHANGED
|
@@ -13,7 +13,6 @@ export const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint';
|
|
|
13
13
|
export const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable';
|
|
14
14
|
export const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId';
|
|
15
15
|
export const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId';
|
|
16
|
-
export const API_URL_REDEEM_PLAN = '/api/v1/protocol/plans/redeem';
|
|
17
16
|
export const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress';
|
|
18
17
|
export const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId';
|
|
19
18
|
export const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start';
|
|
@@ -26,6 +25,8 @@ export const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle';
|
|
|
26
25
|
export const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment';
|
|
27
26
|
export const API_URL_CREATE_USER = '/api/v1/organizations/account';
|
|
28
27
|
export const API_URL_GET_MEMBERS = '/api/v1/organizations/members';
|
|
28
|
+
export const API_URL_MY_MEMBERSHIPS = '/api/v1/organizations/my-memberships';
|
|
29
|
+
export const API_URL_ORG_ACTIVITY = '/api/v1/organizations/:orgId/activity';
|
|
29
30
|
export const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account';
|
|
30
31
|
export class HTTPRequestOptions {
|
|
31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F,CAAA;YACH,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;QACxE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,aAAiC,EAAE,gBAAgB,EAAE,IAAI,EAAE;QAChF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACpD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import axios from 'axios'\n\nexport const API_URL_REGISTER_PLAN = '/api/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REDEEM_PLAN = '/api/v1/protocol/plans/redeem'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nvm-api.js","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAA;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAA;AAC/D,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAA;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,kCAAkC,CAAA;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,wCAAwC,CAAA;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,gCAAgC,CAAA;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,uCAAuC,CAAA;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAA;AAC9D,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,IAAI,EAAE,UAAU,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import axios from 'axios'\n\nexport const API_URL_REGISTER_PLAN = '/api/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_MY_MEMBERSHIPS = '/api/v1/organizations/my-memberships'\nexport const API_URL_ORG_ACTIVITY = '/api/v1/organizations/:orgId/activity'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PaymentOptions } from '../../common/types.js';
|
|
2
2
|
import { BasePaymentsAPI } from '../base-payments.js';
|
|
3
|
-
import { CreateUserResponse, OrganizationMemberRole, OrganizationMembersResponse, StripeCheckoutResult } from './types.js';
|
|
3
|
+
import { CreateUserResponse, MyMembership, OrganizationActivityFilters, OrganizationActivityPage, OrganizationMemberRole, OrganizationMembersResponse, StripeCheckoutResult } from './types.js';
|
|
4
4
|
export declare class OrganizationsAPI extends BasePaymentsAPI {
|
|
5
5
|
static getInstance(options: PaymentOptions): OrganizationsAPI;
|
|
6
6
|
/**
|
|
@@ -20,6 +20,47 @@ export declare class OrganizationsAPI extends BasePaymentsAPI {
|
|
|
20
20
|
* @returns The list of members
|
|
21
21
|
*/
|
|
22
22
|
getMembers(role?: OrganizationMemberRole, isActive?: boolean, page?: number, offset?: number): Promise<OrganizationMembersResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Lists every organization the authenticated user is an active member of,
|
|
25
|
+
* with their role and the organization's tier.
|
|
26
|
+
*
|
|
27
|
+
* Powers workspace pickers in third-party tools built on the SDK, and the
|
|
28
|
+
* "where will this publish?" UX when a user belongs to multiple orgs.
|
|
29
|
+
*
|
|
30
|
+
* @returns An array of {@link MyMembership} — empty when the user has no
|
|
31
|
+
* active memberships and operates as a personal account.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const memberships = await payments.organizations.getMyMemberships()
|
|
36
|
+
* for (const m of memberships) {
|
|
37
|
+
* console.log(`${m.orgName} — ${m.role}`)
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
getMyMemberships(): Promise<MyMembership[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Lists events emitted into the activity feed of an organization the
|
|
44
|
+
* caller is an active member of (member invites, customer events,
|
|
45
|
+
* subscription transitions, webhook deliveries, …).
|
|
46
|
+
*
|
|
47
|
+
* Requires the caller to be a Member or Admin of `orgId`; the backend
|
|
48
|
+
* returns 403 otherwise. Premium+ entitlement is enforced server-side.
|
|
49
|
+
*
|
|
50
|
+
* @param orgId - The organization id (e.g. `org-…`) whose feed to read.
|
|
51
|
+
* @param filters - Optional filter set — see {@link OrganizationActivityFilters}.
|
|
52
|
+
* @returns A paginated {@link OrganizationActivityPage}.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const page = await payments.organizations.getOrganizationActivity(orgId, {
|
|
57
|
+
* eventType: OrganizationActivityEventType.MemberInvited,
|
|
58
|
+
* page: 1,
|
|
59
|
+
* limit: 25,
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
getOrganizationActivity(orgId: string, filters?: OrganizationActivityFilters): Promise<OrganizationActivityPage>;
|
|
23
64
|
/**
|
|
24
65
|
* Connect user with Stripe
|
|
25
66
|
* @param userEmail - The email of the user
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizations-api.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"organizations-api.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAQrD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,qBAAa,gBAAiB,SAAQ,eAAe;IACnD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;IAI7D;;;;;;OAMG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAqB9B;;;;;;;OAOG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,sBAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,EAClB,IAAI,SAAI,EACR,MAAM,SAAM,GACX,OAAO,CAAC,2BAA2B,CAAC;IAuBvC;;;;;;;;;;;;;;;;;OAiBG;IACG,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAYjD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,uBAAuB,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,wBAAwB,CAAC;IAiCpC;;;;;;;OAOG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,CAAC;CAuBjC"}
|