@nevermined-io/payments 0.5.0 → 0.5.2
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 +34 -19
- package/dist/api/nvm-backend.d.ts.map +1 -1
- package/dist/api/nvm-backend.js +32 -36
- package/dist/api/nvm-backend.js.map +1 -1
- package/dist/api/query-api.d.ts +16 -1
- package/dist/api/query-api.d.ts.map +1 -1
- package/dist/api/query-api.js +56 -33
- package/dist/api/query-api.js.map +1 -1
- package/dist/common/{utils.d.ts → helper.d.ts} +1 -2
- package/dist/common/helper.d.ts.map +1 -0
- package/dist/common/helper.js +10 -0
- package/dist/common/helper.js.map +1 -0
- package/dist/common/payments.error.js +5 -1
- package/dist/common/payments.error.js.map +1 -1
- package/dist/common/types.js +7 -4
- package/dist/common/types.js.map +1 -1
- package/dist/environments.js +5 -2
- package/dist/environments.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/dist/payments.d.ts +99 -5
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +155 -30
- package/dist/payments.js.map +1 -1
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +39 -0
- package/dist/utils.js.map +1 -0
- package/package.json +4 -2
- package/dist/common/utils.d.ts.map +0 -1
- package/dist/common/utils.js +0 -10
- package/dist/common/utils.js.map +0 -1
package/dist/environments.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Environments = exports.ZeroAddress = void 0;
|
|
4
|
+
exports.ZeroAddress = '0x0000000000000000000000000000000000000000';
|
|
2
5
|
/**
|
|
3
6
|
* Represents the different environments and their corresponding URLs.
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
exports.Environments = {
|
|
6
9
|
/**
|
|
7
10
|
* The local environment URLs.
|
|
8
11
|
*/
|
package/dist/environments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../src/environments.ts"],"names":[],"mappings":";;;AAOa,QAAA,WAAW,GAAG,4CAA4C,CAAA;AAIvE;;GAEG;AACU,QAAA,YAAY,GAA6C;IACpE;;OAEG;IACH,KAAK,EAAE;QACL,QAAQ,EAAE,uBAAuB;QACjC,OAAO,EAAE,uBAAuB;QAChC,gBAAgB,EAAE,qBAAqB;QACvC,KAAK,EAAE,uBAAuB;KAC/B;IACD;;OAEG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,gCAAgC;QAC1C,OAAO,EAAE,4CAA4C;QACrD,gBAAgB,EAAE,0CAA0C;QAC5D,KAAK,EAAE,sCAAsC;KAC9C;IACD;;OAEG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,gCAAgC;QAC1C,OAAO,EAAE,4CAA4C;QACrD,gBAAgB,EAAE,0CAA0C;QAC5D,KAAK,EAAE,sCAAsC;KAC9C;IACD;;OAEG;IACH,QAAQ,EAAE;QACR,QAAQ,EAAE,wBAAwB;QAClC,OAAO,EAAE,6CAA6C;QACtD,gBAAgB,EAAE,2CAA2C;QAC7D,KAAK,EAAE,uCAAuC;KAC/C;IACD;;OAEG;IACH,IAAI,EAAE;QACJ,QAAQ,EAAE,6BAA6B;QACvC,OAAO,EAAE,yCAAyC;QAClD,gBAAgB,EAAE,uCAAuC;QACzD,KAAK,EAAE,mCAAmC;KAC3C;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,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,qBAAqB;QACxE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,uBAAuB;KAC5D;CACF,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './environments';
|
|
2
2
|
export * from './payments';
|
|
3
|
+
export * from './utils';
|
|
3
4
|
export * from './common/types';
|
|
4
5
|
export * from './common/payments.error';
|
|
5
|
-
export * from './common/
|
|
6
|
+
export * from './common/helper';
|
|
6
7
|
export * from './api/query-api';
|
|
7
8
|
export { BackendApiOptions, BackendWebSocketOptions } from './api/nvm-backend';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
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,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./environments"), exports);
|
|
18
|
+
__exportStar(require("./payments"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./common/types"), exports);
|
|
21
|
+
__exportStar(require("./common/payments.error"), exports);
|
|
22
|
+
__exportStar(require("./common/helper"), exports);
|
|
23
|
+
__exportStar(require("./api/query-api"), exports);
|
|
7
24
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,6CAA0B;AAC1B,0CAAuB;AACvB,iDAA8B;AAC9B,0DAAuC;AACvC,kDAA+B;AAC/B,kDAA+B"}
|
package/dist/payments.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ export declare class Payments {
|
|
|
193
193
|
* tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
194
194
|
* amountOfCredits: 30,
|
|
195
195
|
* tags: ["test"]
|
|
196
|
-
* }
|
|
196
|
+
* })
|
|
197
197
|
* ```
|
|
198
198
|
*
|
|
199
199
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
@@ -232,13 +232,13 @@ export declare class Payments {
|
|
|
232
232
|
* @example
|
|
233
233
|
* ```
|
|
234
234
|
* const { did } = await payments.createTimePlan({
|
|
235
|
-
* name: "My 1
|
|
235
|
+
* name: "My 1 Month Plan",
|
|
236
236
|
* description: "test",
|
|
237
237
|
* price: 10000000n,
|
|
238
238
|
* tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
239
239
|
* duration: 30,
|
|
240
240
|
* tags: ["test"]
|
|
241
|
-
* }
|
|
241
|
+
* })
|
|
242
242
|
* ```
|
|
243
243
|
*
|
|
244
244
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
@@ -253,6 +253,80 @@ export declare class Payments {
|
|
|
253
253
|
}): Promise<{
|
|
254
254
|
did: string;
|
|
255
255
|
}>;
|
|
256
|
+
/**
|
|
257
|
+
* It creates a new AI Agent on Nevermined.
|
|
258
|
+
* The agent must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent.
|
|
259
|
+
* Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.
|
|
260
|
+
* 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.
|
|
261
|
+
*
|
|
262
|
+
* @remarks
|
|
263
|
+
*
|
|
264
|
+
* This method is oriented to AI Builders
|
|
265
|
+
*
|
|
266
|
+
* @see https://docs.nevermined.app/docs/tutorials/builders/register-agent
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const agentDID = await paymentsBuilder.createService({
|
|
271
|
+
* planDID,
|
|
272
|
+
* name: 'E2E Payments Agent',
|
|
273
|
+
* description: 'description',
|
|
274
|
+
* serviceType: 'agent',
|
|
275
|
+
* serviceChargeType: 'fixed',
|
|
276
|
+
* authType: 'bearer',
|
|
277
|
+
* token: 'changeme',
|
|
278
|
+
* amountOfCredits: 1,
|
|
279
|
+
* endpoints: agentEndpoints,
|
|
280
|
+
* openEndpoints: ['https://example.com/api/v1/rest/docs-json']
|
|
281
|
+
* })
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @param planDID - The plan unique identifier of the Plan (DID). @see {@link createCreditsPlan} or {@link createTimePlan}
|
|
285
|
+
* @param name - The name of the AI Agent/Service.
|
|
286
|
+
* @param description - The description of the AI Agent/Service.
|
|
287
|
+
* @param tags - The tags describing the AI Agent/Service.
|
|
288
|
+
* @param usesAIHub - If the agent is using the AI Hub. If true, the agent will be configured to use the AI Hub endpoints.
|
|
289
|
+
* @param serviceChargeType - The service charge type ('fixed' or 'dynamic').
|
|
290
|
+
* @param amountOfCredits - The amount of credits to charge per request to the agent.
|
|
291
|
+
* @param minCreditsToCharge - The minimum credits to charge.
|
|
292
|
+
* @param maxCreditsToCharge - The maximum credits to charge.
|
|
293
|
+
* @param authType - The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').
|
|
294
|
+
* @param username - The upstream agent/service username for authentication. Only if `authType` is 'basic'.
|
|
295
|
+
* @param password - The upstream agent/service password for authentication. Only if `authType` is 'basic'.
|
|
296
|
+
* @param token - The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.
|
|
297
|
+
* @param endpoints - The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.
|
|
298
|
+
* @param openEndpoints - 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.
|
|
299
|
+
* @param openApiUrl - The URL to the OpenAPI description of the Upstream API. The access to the OpenAPI definition don't require subscription to the Payment Plan.
|
|
300
|
+
* @param integration - Some description or instructions about how to integrate the Agent.
|
|
301
|
+
* @param sampleLink - A link to some same usage of the Agent.
|
|
302
|
+
* @param apiDescription - Text describing the API of the Agent.
|
|
303
|
+
* @param curation - The curation details.
|
|
304
|
+
* @returns A promise that resolves to the created agent DID.
|
|
305
|
+
*/
|
|
306
|
+
createAgent({ planDID, name, description, amountOfCredits, tags, usesAIHub, serviceChargeType, minCreditsToCharge, maxCreditsToCharge, authType, username, password, token, endpoints, openEndpoints, openApiUrl, integration, sampleLink, apiDescription, curation, }: {
|
|
307
|
+
planDID: string;
|
|
308
|
+
name: string;
|
|
309
|
+
description: string;
|
|
310
|
+
usesAIHub?: boolean;
|
|
311
|
+
serviceChargeType: 'fixed' | 'dynamic';
|
|
312
|
+
authType?: 'none' | 'basic' | 'oauth' | 'bearer';
|
|
313
|
+
amountOfCredits?: number;
|
|
314
|
+
minCreditsToCharge?: number;
|
|
315
|
+
maxCreditsToCharge?: number;
|
|
316
|
+
username?: string;
|
|
317
|
+
password?: string;
|
|
318
|
+
token?: string;
|
|
319
|
+
endpoints?: Endpoint[];
|
|
320
|
+
openEndpoints?: string[];
|
|
321
|
+
openApiUrl?: string;
|
|
322
|
+
integration?: string;
|
|
323
|
+
sampleLink?: string;
|
|
324
|
+
apiDescription?: string;
|
|
325
|
+
curation?: object;
|
|
326
|
+
tags?: string[];
|
|
327
|
+
}): Promise<{
|
|
328
|
+
did: string;
|
|
329
|
+
}>;
|
|
256
330
|
/**
|
|
257
331
|
* It creates a new AI Agent or Service on Nevermined.
|
|
258
332
|
* The agent/service must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent/service.
|
|
@@ -265,6 +339,26 @@ export declare class Payments {
|
|
|
265
339
|
*
|
|
266
340
|
* @see https://docs.nevermined.app/docs/tutorials/builders/register-agent
|
|
267
341
|
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const agentEndpoints: Endpoint[] = [
|
|
345
|
+
* { 'POST': `https://example.com/api/v1/agents/(.*)/tasks` },
|
|
346
|
+
* { 'GET': `https://example.com/api/v1/agents/(.*)/tasks/(.*)` }
|
|
347
|
+
* ]
|
|
348
|
+
* const agentDID = await paymentsBuilder.createService({
|
|
349
|
+
* planDID,
|
|
350
|
+
* name: 'E2E Payments Agent',
|
|
351
|
+
* description: 'description',
|
|
352
|
+
* serviceType: 'agent',
|
|
353
|
+
* serviceChargeType: 'fixed',
|
|
354
|
+
* authType: 'bearer',
|
|
355
|
+
* token: 'changeme',
|
|
356
|
+
* amountOfCredits: 1,
|
|
357
|
+
* endpoints: agentEndpoints,
|
|
358
|
+
* openEndpoints: ['https://example.com/api/v1/rest/docs-json']
|
|
359
|
+
* })
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
268
362
|
* @param planDID - The plan unique identifier of the Plan (DID). @see {@link createCreditsPlan} or {@link createTimePlan}
|
|
269
363
|
* @param name - The name of the AI Agent/Service.
|
|
270
364
|
* @param description - The description of the AI Agent/Service.
|
|
@@ -293,7 +387,7 @@ export declare class Payments {
|
|
|
293
387
|
description: string;
|
|
294
388
|
serviceType: 'service' | 'agent' | 'assistant';
|
|
295
389
|
serviceChargeType: 'fixed' | 'dynamic';
|
|
296
|
-
authType
|
|
390
|
+
authType?: 'none' | 'basic' | 'oauth' | 'bearer';
|
|
297
391
|
amountOfCredits?: number;
|
|
298
392
|
minCreditsToCharge?: number;
|
|
299
393
|
maxCreditsToCharge?: number;
|
|
@@ -434,7 +528,7 @@ export declare class Payments {
|
|
|
434
528
|
* @param agreementId - The unique identifier of the purchase transaction (aka agreement ID). When this parameter is given, it assumes there is a previous payment step and will request the payment plan.
|
|
435
529
|
* @returns A promise that resolves to the agreement ID and a boolean indicating if the operation was successful.
|
|
436
530
|
*/
|
|
437
|
-
|
|
531
|
+
orderPlan(planDID: string, agreementId?: string): Promise<{
|
|
438
532
|
agreementId: string;
|
|
439
533
|
success: boolean;
|
|
440
534
|
}>;
|
package/dist/payments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAg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AO,CAAC;QACxD,WAAW,EAAE,MAAM,CAAA;QACnB,kBAAkB,EAAE,MAAM,CAAA;KAC3B,CAAC;IAkBF;;;;;;;;;OASG;IACU,SAAS,CACpB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAoBrD;;;;;OAKG;IACU,aAAa,CAAC,OAAO,EAAE,MAAM;IAgC1C;;;;;;;OAOG;IACI,cAAc,CAAC,OAAO,EAAE,MAAM;IAKrC;;;;;;;;OAQG;IACI,iBAAiB,CAAC,GAAG,EAAE,MAAM;IAKpC;;;;;;;;OAQG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM;IAKjC;;;;;;;;OAQG;IACI,oBAAoB,CAAC,GAAG,EAAE,MAAM;IAKvC;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAoBjF;;;;;;;;;;;OAWG;IACU,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAmBhE"}
|
package/dist/payments.js
CHANGED
|
@@ -1,15 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Payments = void 0;
|
|
30
|
+
const js_file_download_1 = __importDefault(require("js-file-download"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const environments_1 = require("./environments");
|
|
33
|
+
const jose_1 = require("jose");
|
|
34
|
+
const payments_error_1 = require("./common/payments.error");
|
|
35
|
+
const query_api_1 = require("./api/query-api");
|
|
36
|
+
const helper_1 = require("./common/helper");
|
|
37
|
+
const utils_1 = require("./utils");
|
|
38
|
+
const utils_2 = require("./utils");
|
|
8
39
|
/**
|
|
9
40
|
* Main class that interacts with the Nevermined payments API.
|
|
10
41
|
* To get an instance of this class use the `getInstance` method.
|
|
11
42
|
*/
|
|
12
|
-
|
|
43
|
+
class Payments {
|
|
13
44
|
/**
|
|
14
45
|
* The options get's an instance of the payments class.
|
|
15
46
|
*
|
|
@@ -27,7 +58,7 @@ export class Payments {
|
|
|
27
58
|
*/
|
|
28
59
|
static getInstance(options) {
|
|
29
60
|
if (!options.nvmApiKey) {
|
|
30
|
-
throw new PaymentsError('nvmApiKey is required');
|
|
61
|
+
throw new payments_error_1.PaymentsError('nvmApiKey is required');
|
|
31
62
|
}
|
|
32
63
|
return new Payments(options, false);
|
|
33
64
|
}
|
|
@@ -54,7 +85,7 @@ export class Payments {
|
|
|
54
85
|
*/
|
|
55
86
|
static getBrowserInstance(options) {
|
|
56
87
|
if (!options.returnUrl) {
|
|
57
|
-
throw new PaymentsError('nvmApiKey is required');
|
|
88
|
+
throw new payments_error_1.PaymentsError('nvmApiKey is required');
|
|
58
89
|
}
|
|
59
90
|
return new Payments(options, true);
|
|
60
91
|
}
|
|
@@ -69,7 +100,7 @@ export class Payments {
|
|
|
69
100
|
this.isBrowserInstance = true;
|
|
70
101
|
this.nvmApiKey = options.nvmApiKey;
|
|
71
102
|
this.returnUrl = options.returnUrl || '';
|
|
72
|
-
this.environment = Environments[options.environment];
|
|
103
|
+
this.environment = environments_1.Environments[options.environment];
|
|
73
104
|
this.appId = options.appId;
|
|
74
105
|
this.version = options.version;
|
|
75
106
|
this.isBrowserInstance = isBrowserInstance;
|
|
@@ -83,19 +114,18 @@ export class Payments {
|
|
|
83
114
|
*/
|
|
84
115
|
parseNvmApiKey() {
|
|
85
116
|
try {
|
|
86
|
-
const jwt = decodeJwt(this.nvmApiKey);
|
|
87
|
-
console.log(jwt);
|
|
117
|
+
const jwt = (0, jose_1.decodeJwt)(this.nvmApiKey);
|
|
88
118
|
this.accountAddress = jwt.sub;
|
|
89
119
|
}
|
|
90
120
|
catch (error) {
|
|
91
|
-
throw new PaymentsError('Invalid NVM API Key');
|
|
121
|
+
throw new payments_error_1.PaymentsError('Invalid NVM API Key');
|
|
92
122
|
}
|
|
93
123
|
}
|
|
94
124
|
/**
|
|
95
125
|
* Initializes the AI Query Protocol API.
|
|
96
126
|
*/
|
|
97
127
|
initializeApi() {
|
|
98
|
-
this.query = new AIQueryApi({
|
|
128
|
+
this.query = new query_api_1.AIQueryApi({
|
|
99
129
|
backendHost: this.environment.backend,
|
|
100
130
|
apiKey: this.nvmApiKey,
|
|
101
131
|
webSocketHost: this.environment.websocketBackend,
|
|
@@ -224,7 +254,7 @@ export class Payments {
|
|
|
224
254
|
* tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
225
255
|
* amountOfCredits: 30,
|
|
226
256
|
* tags: ["test"]
|
|
227
|
-
* }
|
|
257
|
+
* })
|
|
228
258
|
* ```
|
|
229
259
|
*
|
|
230
260
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
@@ -268,8 +298,6 @@ export class Payments {
|
|
|
268
298
|
metadata,
|
|
269
299
|
serviceAttributes,
|
|
270
300
|
};
|
|
271
|
-
console.log(body);
|
|
272
|
-
console.log(JSON.stringify(body, jsonReplacer));
|
|
273
301
|
const options = {
|
|
274
302
|
method: 'POST',
|
|
275
303
|
headers: {
|
|
@@ -277,9 +305,8 @@ export class Payments {
|
|
|
277
305
|
'Content-Type': 'application/json',
|
|
278
306
|
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
279
307
|
},
|
|
280
|
-
body: JSON.stringify(body, jsonReplacer),
|
|
308
|
+
body: JSON.stringify(body, helper_1.jsonReplacer),
|
|
281
309
|
};
|
|
282
|
-
console.log(options);
|
|
283
310
|
const url = new URL('/api/v1/payments/subscription', this.environment.backend);
|
|
284
311
|
const response = await fetch(url, options);
|
|
285
312
|
if (!response.ok) {
|
|
@@ -311,13 +338,13 @@ export class Payments {
|
|
|
311
338
|
* @example
|
|
312
339
|
* ```
|
|
313
340
|
* const { did } = await payments.createTimePlan({
|
|
314
|
-
* name: "My 1
|
|
341
|
+
* name: "My 1 Month Plan",
|
|
315
342
|
* description: "test",
|
|
316
343
|
* price: 10000000n,
|
|
317
344
|
* tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
318
345
|
* duration: 30,
|
|
319
346
|
* tags: ["test"]
|
|
320
|
-
* }
|
|
347
|
+
* })
|
|
321
348
|
* ```
|
|
322
349
|
*
|
|
323
350
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
@@ -369,7 +396,7 @@ export class Payments {
|
|
|
369
396
|
'Content-Type': 'application/json',
|
|
370
397
|
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
371
398
|
},
|
|
372
|
-
body: JSON.stringify(body, jsonReplacer),
|
|
399
|
+
body: JSON.stringify(body, helper_1.jsonReplacer),
|
|
373
400
|
};
|
|
374
401
|
const url = new URL('/api/v1/payments/subscription', this.environment.backend);
|
|
375
402
|
const response = await fetch(url, options);
|
|
@@ -378,6 +405,86 @@ export class Payments {
|
|
|
378
405
|
}
|
|
379
406
|
return response.json();
|
|
380
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* It creates a new AI Agent on Nevermined.
|
|
410
|
+
* The agent must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent.
|
|
411
|
+
* Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.
|
|
412
|
+
* 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.
|
|
413
|
+
*
|
|
414
|
+
* @remarks
|
|
415
|
+
*
|
|
416
|
+
* This method is oriented to AI Builders
|
|
417
|
+
*
|
|
418
|
+
* @see https://docs.nevermined.app/docs/tutorials/builders/register-agent
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const agentDID = await paymentsBuilder.createService({
|
|
423
|
+
* planDID,
|
|
424
|
+
* name: 'E2E Payments Agent',
|
|
425
|
+
* description: 'description',
|
|
426
|
+
* serviceType: 'agent',
|
|
427
|
+
* serviceChargeType: 'fixed',
|
|
428
|
+
* authType: 'bearer',
|
|
429
|
+
* token: 'changeme',
|
|
430
|
+
* amountOfCredits: 1,
|
|
431
|
+
* endpoints: agentEndpoints,
|
|
432
|
+
* openEndpoints: ['https://example.com/api/v1/rest/docs-json']
|
|
433
|
+
* })
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* @param planDID - The plan unique identifier of the Plan (DID). @see {@link createCreditsPlan} or {@link createTimePlan}
|
|
437
|
+
* @param name - The name of the AI Agent/Service.
|
|
438
|
+
* @param description - The description of the AI Agent/Service.
|
|
439
|
+
* @param tags - The tags describing the AI Agent/Service.
|
|
440
|
+
* @param usesAIHub - If the agent is using the AI Hub. If true, the agent will be configured to use the AI Hub endpoints.
|
|
441
|
+
* @param serviceChargeType - The service charge type ('fixed' or 'dynamic').
|
|
442
|
+
* @param amountOfCredits - The amount of credits to charge per request to the agent.
|
|
443
|
+
* @param minCreditsToCharge - The minimum credits to charge.
|
|
444
|
+
* @param maxCreditsToCharge - The maximum credits to charge.
|
|
445
|
+
* @param authType - The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').
|
|
446
|
+
* @param username - The upstream agent/service username for authentication. Only if `authType` is 'basic'.
|
|
447
|
+
* @param password - The upstream agent/service password for authentication. Only if `authType` is 'basic'.
|
|
448
|
+
* @param token - The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.
|
|
449
|
+
* @param endpoints - The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.
|
|
450
|
+
* @param openEndpoints - 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.
|
|
451
|
+
* @param openApiUrl - The URL to the OpenAPI description of the Upstream API. The access to the OpenAPI definition don't require subscription to the Payment Plan.
|
|
452
|
+
* @param integration - Some description or instructions about how to integrate the Agent.
|
|
453
|
+
* @param sampleLink - A link to some same usage of the Agent.
|
|
454
|
+
* @param apiDescription - Text describing the API of the Agent.
|
|
455
|
+
* @param curation - The curation details.
|
|
456
|
+
* @returns A promise that resolves to the created agent DID.
|
|
457
|
+
*/
|
|
458
|
+
async createAgent({ planDID, name, description, amountOfCredits, tags, usesAIHub, serviceChargeType, minCreditsToCharge, maxCreditsToCharge, authType, username, password, token, endpoints, openEndpoints, openApiUrl, integration, sampleLink, apiDescription, curation, }) {
|
|
459
|
+
if (usesAIHub) {
|
|
460
|
+
authType = 'bearer';
|
|
461
|
+
token = '';
|
|
462
|
+
endpoints = (0, utils_2.getQueryProtocolEndpoints)(this.environment.backend);
|
|
463
|
+
openApiUrl = (0, utils_2.getAIHubOpenApiUrl)(this.environment.backend);
|
|
464
|
+
}
|
|
465
|
+
return this.createService({
|
|
466
|
+
planDID,
|
|
467
|
+
name,
|
|
468
|
+
description,
|
|
469
|
+
serviceType: 'agent',
|
|
470
|
+
serviceChargeType,
|
|
471
|
+
authType,
|
|
472
|
+
amountOfCredits,
|
|
473
|
+
minCreditsToCharge,
|
|
474
|
+
maxCreditsToCharge,
|
|
475
|
+
username,
|
|
476
|
+
password,
|
|
477
|
+
token,
|
|
478
|
+
endpoints,
|
|
479
|
+
openEndpoints,
|
|
480
|
+
openApiUrl,
|
|
481
|
+
integration,
|
|
482
|
+
sampleLink,
|
|
483
|
+
apiDescription,
|
|
484
|
+
curation,
|
|
485
|
+
tags,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
381
488
|
/**
|
|
382
489
|
* It creates a new AI Agent or Service on Nevermined.
|
|
383
490
|
* The agent/service must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent/service.
|
|
@@ -390,6 +497,26 @@ export class Payments {
|
|
|
390
497
|
*
|
|
391
498
|
* @see https://docs.nevermined.app/docs/tutorials/builders/register-agent
|
|
392
499
|
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const agentEndpoints: Endpoint[] = [
|
|
503
|
+
* { 'POST': `https://example.com/api/v1/agents/(.*)/tasks` },
|
|
504
|
+
* { 'GET': `https://example.com/api/v1/agents/(.*)/tasks/(.*)` }
|
|
505
|
+
* ]
|
|
506
|
+
* const agentDID = await paymentsBuilder.createService({
|
|
507
|
+
* planDID,
|
|
508
|
+
* name: 'E2E Payments Agent',
|
|
509
|
+
* description: 'description',
|
|
510
|
+
* serviceType: 'agent',
|
|
511
|
+
* serviceChargeType: 'fixed',
|
|
512
|
+
* authType: 'bearer',
|
|
513
|
+
* token: 'changeme',
|
|
514
|
+
* amountOfCredits: 1,
|
|
515
|
+
* endpoints: agentEndpoints,
|
|
516
|
+
* openEndpoints: ['https://example.com/api/v1/rest/docs-json']
|
|
517
|
+
* })
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
393
520
|
* @param planDID - The plan unique identifier of the Plan (DID). @see {@link createCreditsPlan} or {@link createTimePlan}
|
|
394
521
|
* @param name - The name of the AI Agent/Service.
|
|
395
522
|
* @param description - The description of the AI Agent/Service.
|
|
@@ -486,7 +613,6 @@ export class Payments {
|
|
|
486
613
|
serviceAttributes,
|
|
487
614
|
subscriptionDid: planDID,
|
|
488
615
|
};
|
|
489
|
-
console.log(JSON.stringify(body, jsonReplacer));
|
|
490
616
|
const options = {
|
|
491
617
|
method: 'POST',
|
|
492
618
|
headers: {
|
|
@@ -494,7 +620,7 @@ export class Payments {
|
|
|
494
620
|
'Content-Type': 'application/json',
|
|
495
621
|
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
496
622
|
},
|
|
497
|
-
body: JSON.stringify(body, jsonReplacer),
|
|
623
|
+
body: JSON.stringify(body, helper_1.jsonReplacer),
|
|
498
624
|
};
|
|
499
625
|
const url = new URL('/api/v1/payments/service', this.environment.backend);
|
|
500
626
|
const response = await fetch(url, options);
|
|
@@ -649,12 +775,10 @@ export class Payments {
|
|
|
649
775
|
* @returns A promise that resolves to the balance result.
|
|
650
776
|
*/
|
|
651
777
|
async getPlanBalance(planDID, accountAddress) {
|
|
652
|
-
console.log('getSubscriptionBalance', planDID, accountAddress);
|
|
653
778
|
const body = {
|
|
654
779
|
subscriptionDid: planDID,
|
|
655
|
-
accountAddress: isEthereumAddress(accountAddress) ? accountAddress : this.accountAddress,
|
|
780
|
+
accountAddress: (0, utils_1.isEthereumAddress)(accountAddress) ? accountAddress : this.accountAddress,
|
|
656
781
|
};
|
|
657
|
-
console.log(body);
|
|
658
782
|
const options = {
|
|
659
783
|
method: 'POST',
|
|
660
784
|
headers: {
|
|
@@ -713,7 +837,7 @@ export class Payments {
|
|
|
713
837
|
* @param agreementId - The unique identifier of the purchase transaction (aka agreement ID). When this parameter is given, it assumes there is a previous payment step and will request the payment plan.
|
|
714
838
|
* @returns A promise that resolves to the agreement ID and a boolean indicating if the operation was successful.
|
|
715
839
|
*/
|
|
716
|
-
async
|
|
840
|
+
async orderPlan(planDID, agreementId) {
|
|
717
841
|
const body = { subscriptionDid: planDID, agreementId };
|
|
718
842
|
const options = {
|
|
719
843
|
method: 'POST',
|
|
@@ -762,7 +886,7 @@ export class Payments {
|
|
|
762
886
|
}
|
|
763
887
|
}
|
|
764
888
|
const buff = await response.arrayBuffer();
|
|
765
|
-
|
|
889
|
+
(0, js_file_download_1.default)(buff, filename);
|
|
766
890
|
const destination = process.cwd();
|
|
767
891
|
return path.join(destination, filename);
|
|
768
892
|
}
|
|
@@ -879,4 +1003,5 @@ export class Payments {
|
|
|
879
1003
|
return response.json();
|
|
880
1004
|
}
|
|
881
1005
|
}
|
|
1006
|
+
exports.Payments = Payments;
|
|
882
1007
|
//# sourceMappingURL=payments.js.map
|