@nevermined-io/payments 0.8.1 → 0.8.3
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/dist/common/helper.d.ts +1 -1
- package/dist/common/helper.d.ts.map +1 -1
- package/dist/common/types.d.ts +251 -0
- package/dist/common/types.d.ts.map +1 -1
- package/dist/common/types.js.map +1 -1
- package/dist/payments.d.ts +101 -192
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +252 -176
- package/dist/payments.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/payments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EACL,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAgB,MAAM,gBAAgB,CAAA;AAG9D;;;GAGG;AACH,qBAAa,QAAQ;IACZ,KAAK,EAAG,UAAU,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,eAAe,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAQ;IACnB,iBAAiB,UAAO;IAE/B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc;IAO1C;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,kBAAkB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ACZ,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB;IAmBD;;;;;;;;;;;;;;;OAeG;IACU,YAAY,CAAC,EACxB,IAAI,EACJ,IAAQ,EACR,MAAW,GACZ,EAAE;QACD,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB;CAkBF"}
|
package/dist/payments.js
CHANGED
|
@@ -27,15 +27,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Payments = void 0;
|
|
30
|
+
const jose_1 = require("jose");
|
|
30
31
|
const js_file_download_1 = __importDefault(require("js-file-download"));
|
|
31
32
|
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
33
|
const query_api_1 = require("./api/query-api");
|
|
36
34
|
const helper_1 = require("./common/helper");
|
|
35
|
+
const payments_error_1 = require("./common/payments.error");
|
|
36
|
+
const environments_1 = require("./environments");
|
|
37
37
|
const utils_1 = require("./utils");
|
|
38
|
-
const utils_2 = require("./utils");
|
|
39
38
|
/**
|
|
40
39
|
* Main class that interacts with the Nevermined payments API.
|
|
41
40
|
* To get an instance of this class use the `getInstance` method.
|
|
@@ -238,12 +237,7 @@ class Payments {
|
|
|
238
237
|
*
|
|
239
238
|
* @see https://docs.nevermined.app/docs/tutorials/builders/create-plan
|
|
240
239
|
*
|
|
241
|
-
* @param
|
|
242
|
-
* @param description - A description of what the plan offers.
|
|
243
|
-
* @param price - The price of the plan. It must be given in the lowest denomination of the currency.
|
|
244
|
-
* @param tokenAddress - The address of the ERC20 contract used for the payment. Using the `ZeroAddress` will use the chain's native currency instead.
|
|
245
|
-
* @param amountOfCredits - The number of credits that are transferred to the user when purchases the plan.
|
|
246
|
-
* @param tags - An array of tags or keywords that best fit the subscription.
|
|
240
|
+
* @param createPlanCreditsDto - @see {@link CreatePlanCreditsDto}
|
|
247
241
|
*
|
|
248
242
|
* @example
|
|
249
243
|
* ```
|
|
@@ -259,10 +253,10 @@ class Payments {
|
|
|
259
253
|
*
|
|
260
254
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
261
255
|
*/
|
|
262
|
-
async createCreditsPlan(
|
|
256
|
+
async createCreditsPlan(createPlanCreditsDto) {
|
|
263
257
|
const metadata = {
|
|
264
258
|
main: {
|
|
265
|
-
name,
|
|
259
|
+
name: createPlanCreditsDto.name,
|
|
266
260
|
type: 'subscription',
|
|
267
261
|
license: 'No License Specified',
|
|
268
262
|
files: [],
|
|
@@ -273,8 +267,8 @@ class Payments {
|
|
|
273
267
|
},
|
|
274
268
|
},
|
|
275
269
|
additionalInformation: {
|
|
276
|
-
description,
|
|
277
|
-
tags: tags || [],
|
|
270
|
+
description: createPlanCreditsDto.description,
|
|
271
|
+
tags: createPlanCreditsDto.tags || [],
|
|
278
272
|
customData: {
|
|
279
273
|
dateMeasure: 'days',
|
|
280
274
|
plan: 'custom',
|
|
@@ -285,16 +279,16 @@ class Payments {
|
|
|
285
279
|
const serviceAttributes = [
|
|
286
280
|
{
|
|
287
281
|
serviceType: 'nft-sales',
|
|
288
|
-
price,
|
|
282
|
+
price: createPlanCreditsDto.price,
|
|
289
283
|
nft: {
|
|
290
|
-
amount: amountOfCredits,
|
|
284
|
+
amount: createPlanCreditsDto.amountOfCredits,
|
|
291
285
|
nftTransfer: false,
|
|
292
286
|
},
|
|
293
287
|
},
|
|
294
288
|
];
|
|
295
289
|
const body = {
|
|
296
|
-
price,
|
|
297
|
-
tokenAddress,
|
|
290
|
+
price: createPlanCreditsDto.price,
|
|
291
|
+
tokenAddress: createPlanCreditsDto.tokenAddress,
|
|
298
292
|
metadata,
|
|
299
293
|
serviceAttributes,
|
|
300
294
|
};
|
|
@@ -327,13 +321,7 @@ class Payments {
|
|
|
327
321
|
*
|
|
328
322
|
* @see https://docs.nevermined.app/docs/tutorials/builders/create-plan
|
|
329
323
|
*
|
|
330
|
-
* @param
|
|
331
|
-
* @param description - A description of what the plan offers.
|
|
332
|
-
* @param price - The price of the plan. It must be given in the lowest denomination of the currency.
|
|
333
|
-
* @param tokenAddress - The address of the ERC20 contract used for the payment. Using the `ZeroAddress` will use the chain's native currency instead.
|
|
334
|
-
* @param tags - An array of tags or keywords that best fit the subscription.
|
|
335
|
-
* @param duration - The duration of the plan in days. If `duration` is left undefined an unlimited time duration subscription will be created.
|
|
336
|
-
* @param tags - An array of tags or keywords that best fit the subscription.
|
|
324
|
+
* @param createPlanTimeDto - @see {@link CreatePlanTimeDto}
|
|
337
325
|
*
|
|
338
326
|
* @example
|
|
339
327
|
* ```
|
|
@@ -349,10 +337,10 @@ class Payments {
|
|
|
349
337
|
*
|
|
350
338
|
* @returns The unique identifier of the plan (Plan DID) of the newly created plan.
|
|
351
339
|
*/
|
|
352
|
-
async createTimePlan(
|
|
340
|
+
async createTimePlan(createPlanTimeDto) {
|
|
353
341
|
const metadata = {
|
|
354
342
|
main: {
|
|
355
|
-
name,
|
|
343
|
+
name: createPlanTimeDto.name,
|
|
356
344
|
type: 'subscription',
|
|
357
345
|
license: 'No License Specified',
|
|
358
346
|
files: [],
|
|
@@ -363,8 +351,8 @@ class Payments {
|
|
|
363
351
|
},
|
|
364
352
|
},
|
|
365
353
|
additionalInformation: {
|
|
366
|
-
description,
|
|
367
|
-
tags: tags || [],
|
|
354
|
+
description: createPlanTimeDto.description,
|
|
355
|
+
tags: createPlanTimeDto.tags || [],
|
|
368
356
|
customData: {
|
|
369
357
|
dateMeasure: 'days',
|
|
370
358
|
plan: 'custom',
|
|
@@ -375,17 +363,17 @@ class Payments {
|
|
|
375
363
|
const serviceAttributes = [
|
|
376
364
|
{
|
|
377
365
|
serviceType: 'nft-sales',
|
|
378
|
-
price,
|
|
366
|
+
price: createPlanTimeDto.price,
|
|
379
367
|
nft: {
|
|
380
|
-
duration,
|
|
368
|
+
duration: createPlanTimeDto.duration,
|
|
381
369
|
amount: 1,
|
|
382
370
|
nftTransfer: false,
|
|
383
371
|
},
|
|
384
372
|
},
|
|
385
373
|
];
|
|
386
374
|
const body = {
|
|
387
|
-
price,
|
|
388
|
-
tokenAddress,
|
|
375
|
+
price: createPlanTimeDto.price,
|
|
376
|
+
tokenAddress: createPlanTimeDto.tokenAddress,
|
|
389
377
|
metadata,
|
|
390
378
|
serviceAttributes,
|
|
391
379
|
};
|
|
@@ -433,67 +421,124 @@ class Payments {
|
|
|
433
421
|
* })
|
|
434
422
|
* ```
|
|
435
423
|
*
|
|
436
|
-
* @param
|
|
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 implementsQueryProtocol - It the agent implements the Nevermined Query Protocol. @see https://docs.nevermined.io/docs/protocol/query-protocol
|
|
442
|
-
* @param serviceChargeType - The service charge type ('fixed' or 'dynamic').
|
|
443
|
-
* @param amountOfCredits - The amount of credits to charge per request to the agent.
|
|
444
|
-
* @param minCreditsToCharge - The minimum credits to charge.
|
|
445
|
-
* @param maxCreditsToCharge - The maximum credits to charge.
|
|
446
|
-
* @param authType - The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').
|
|
447
|
-
* @param username - The upstream agent/service username for authentication. Only if `authType` is 'basic'.
|
|
448
|
-
* @param password - The upstream agent/service password for authentication. Only if `authType` is 'basic'.
|
|
449
|
-
* @param token - The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.
|
|
450
|
-
* @param endpoints - The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.
|
|
451
|
-
* @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.
|
|
452
|
-
* @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.
|
|
453
|
-
* @param integration - Some description or instructions about how to integrate the Agent.
|
|
454
|
-
* @param sampleLink - A link to some same usage of the Agent.
|
|
455
|
-
* @param apiDescription - Text describing the API of the Agent.
|
|
456
|
-
* @param curation - The curation details.
|
|
424
|
+
* @param createAgentDto - @see {@link CreateAgentDto}
|
|
457
425
|
* @returns A promise that resolves to the created agent DID.
|
|
458
426
|
*/
|
|
459
|
-
async createAgent(
|
|
460
|
-
if (usesAIHub) {
|
|
461
|
-
authType = 'bearer';
|
|
462
|
-
token = '';
|
|
463
|
-
endpoints = (0,
|
|
464
|
-
openApiUrl = (0,
|
|
465
|
-
implementsQueryProtocol = true;
|
|
427
|
+
async createAgent(createAgentDto) {
|
|
428
|
+
if (createAgentDto.usesAIHub) {
|
|
429
|
+
createAgentDto.authType = 'bearer';
|
|
430
|
+
createAgentDto.token = '';
|
|
431
|
+
createAgentDto.endpoints = (0, utils_1.getQueryProtocolEndpoints)(this.environment.backend);
|
|
432
|
+
createAgentDto.openApiUrl = (0, utils_1.getAIHubOpenApiUrl)(this.environment.backend);
|
|
433
|
+
createAgentDto.implementsQueryProtocol = true;
|
|
466
434
|
}
|
|
467
435
|
else {
|
|
468
|
-
if (!endpoints) {
|
|
436
|
+
if (!createAgentDto.endpoints) {
|
|
469
437
|
throw new payments_error_1.PaymentsError('endpoints are required');
|
|
470
438
|
}
|
|
471
439
|
}
|
|
472
440
|
return this.createService({
|
|
473
|
-
planDID,
|
|
474
|
-
name,
|
|
475
|
-
description,
|
|
476
|
-
usesAIHub,
|
|
477
|
-
implementsQueryProtocol,
|
|
441
|
+
planDID: createAgentDto.planDID,
|
|
442
|
+
name: createAgentDto.name,
|
|
443
|
+
description: createAgentDto.description,
|
|
444
|
+
usesAIHub: createAgentDto.usesAIHub,
|
|
445
|
+
implementsQueryProtocol: createAgentDto.implementsQueryProtocol,
|
|
478
446
|
serviceType: 'agent',
|
|
479
|
-
serviceChargeType,
|
|
480
|
-
authType,
|
|
481
|
-
amountOfCredits,
|
|
482
|
-
minCreditsToCharge,
|
|
483
|
-
maxCreditsToCharge,
|
|
484
|
-
username,
|
|
485
|
-
password,
|
|
486
|
-
token,
|
|
487
|
-
endpoints,
|
|
488
|
-
openEndpoints,
|
|
489
|
-
openApiUrl,
|
|
490
|
-
integration,
|
|
491
|
-
sampleLink,
|
|
492
|
-
apiDescription,
|
|
493
|
-
curation,
|
|
494
|
-
tags,
|
|
447
|
+
serviceChargeType: createAgentDto.serviceChargeType,
|
|
448
|
+
authType: createAgentDto.authType,
|
|
449
|
+
amountOfCredits: createAgentDto.amountOfCredits,
|
|
450
|
+
minCreditsToCharge: createAgentDto.minCreditsToCharge,
|
|
451
|
+
maxCreditsToCharge: createAgentDto.maxCreditsToCharge,
|
|
452
|
+
username: createAgentDto.username,
|
|
453
|
+
password: createAgentDto.password,
|
|
454
|
+
token: createAgentDto.token,
|
|
455
|
+
endpoints: createAgentDto.endpoints,
|
|
456
|
+
openEndpoints: createAgentDto.openEndpoints,
|
|
457
|
+
openApiUrl: createAgentDto.openApiUrl,
|
|
458
|
+
integration: createAgentDto.integration,
|
|
459
|
+
sampleLink: createAgentDto.sampleLink,
|
|
460
|
+
apiDescription: createAgentDto.apiDescription,
|
|
461
|
+
curation: createAgentDto.curation,
|
|
462
|
+
tags: createAgentDto.tags,
|
|
495
463
|
});
|
|
496
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
*
|
|
467
|
+
* It creates a new AI Agent and a Payment Plan on Nevermined.
|
|
468
|
+
*
|
|
469
|
+
* @remarks
|
|
470
|
+
*
|
|
471
|
+
* This method is oriented to AI Builders
|
|
472
|
+
*
|
|
473
|
+
* @see https://docs.nevermined.app/docs/tutorials/builders/register-agent
|
|
474
|
+
*
|
|
475
|
+
* @param plan - @see {@link CreatePlanCreditsDto}
|
|
476
|
+
* @param agent - @see {@link CreateAgentDto} PlanDID is generated automatically.
|
|
477
|
+
* @returns A promise that resolves to the Plan DID and Agent DID.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```
|
|
481
|
+
* const { planDID, agentDID } = await paymentsBuilder.createAgentAndPlan(
|
|
482
|
+
* {
|
|
483
|
+
* name: 'My AI Payments Plan',
|
|
484
|
+
* description: 'AI stuff',
|
|
485
|
+
* price: 10000000n,
|
|
486
|
+
* tokenAddress: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
|
|
487
|
+
* amountOfCredits: 30,
|
|
488
|
+
* },
|
|
489
|
+
* {
|
|
490
|
+
* name: 'Payments Agent name',
|
|
491
|
+
* description: 'description',
|
|
492
|
+
* amountOfCredits: 1,
|
|
493
|
+
* tags: ['test'],
|
|
494
|
+
* usesAIHub: true,
|
|
495
|
+
* implementsQueryProtocol: true,
|
|
496
|
+
* serviceChargeType: 'fixed',
|
|
497
|
+
* authType: 'bearer',
|
|
498
|
+
* token,
|
|
499
|
+
* endpoints,
|
|
500
|
+
* integration: 'integration details',
|
|
501
|
+
* apiDescription: 'description',
|
|
502
|
+
* curation: {}
|
|
503
|
+
* })
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @returns A promise that resolves to the Plan DID and Agent DID.
|
|
507
|
+
*/
|
|
508
|
+
async createAgentAndPlan(plan, agent) {
|
|
509
|
+
const { did: planDID } = await this.createCreditsPlan({
|
|
510
|
+
name: plan.name,
|
|
511
|
+
description: plan.description,
|
|
512
|
+
price: plan.price,
|
|
513
|
+
tokenAddress: plan.tokenAddress,
|
|
514
|
+
amountOfCredits: plan.amountOfCredits,
|
|
515
|
+
tags: plan.tags,
|
|
516
|
+
});
|
|
517
|
+
const { did: agentDID } = await this.createAgent({
|
|
518
|
+
planDID,
|
|
519
|
+
name: agent.name,
|
|
520
|
+
description: agent.description,
|
|
521
|
+
amountOfCredits: agent.amountOfCredits,
|
|
522
|
+
tags: agent.tags,
|
|
523
|
+
usesAIHub: agent.usesAIHub,
|
|
524
|
+
implementsQueryProtocol: agent.implementsQueryProtocol,
|
|
525
|
+
serviceChargeType: agent.serviceChargeType,
|
|
526
|
+
minCreditsToCharge: agent.minCreditsToCharge,
|
|
527
|
+
maxCreditsToCharge: agent.maxCreditsToCharge,
|
|
528
|
+
authType: agent.authType,
|
|
529
|
+
username: agent.username,
|
|
530
|
+
password: agent.password,
|
|
531
|
+
token: agent.token,
|
|
532
|
+
endpoints: agent.endpoints,
|
|
533
|
+
openEndpoints: agent.openEndpoints,
|
|
534
|
+
openApiUrl: agent.openApiUrl,
|
|
535
|
+
integration: agent.integration,
|
|
536
|
+
sampleLink: agent.sampleLink,
|
|
537
|
+
apiDescription: agent.apiDescription,
|
|
538
|
+
curation: agent.curation,
|
|
539
|
+
});
|
|
540
|
+
return { planDID, agentDID };
|
|
541
|
+
}
|
|
497
542
|
/**
|
|
498
543
|
* It creates a new AI Agent or Service on Nevermined.
|
|
499
544
|
* The agent/service must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent/service.
|
|
@@ -526,55 +571,34 @@ class Payments {
|
|
|
526
571
|
* })
|
|
527
572
|
* ```
|
|
528
573
|
*
|
|
529
|
-
* @param
|
|
530
|
-
* @param name - The name of the AI Agent/Service.
|
|
531
|
-
* @param description - The description of the AI Agent/Service.
|
|
532
|
-
* @param tags - The tags describing the AI Agent/Service.
|
|
533
|
-
* @param usesAIHub - If the agent is using the AI Hub. If true, the agent will be configured to use the AI Hub endpoints.
|
|
534
|
-
* @param implementsQueryProtocol - It the agent implements the Nevermined Query Protocol. @see https://docs.nevermined.io/docs/protocol/query-protocol
|
|
535
|
-
* @param serviceType - The service type ('service', 'agent', or 'assistant').
|
|
536
|
-
* @param serviceChargeType - The service charge type ('fixed' or 'dynamic').
|
|
537
|
-
* @param amountOfCredits - The amount of credits to charge per request to the agent.
|
|
538
|
-
* @param minCreditsToCharge - The minimum credits to charge.
|
|
539
|
-
* @param maxCreditsToCharge - The maximum credits to charge.
|
|
540
|
-
* @param authType - The upstream agent/service authentication type ('none', 'basic', 'bearer' or 'oauth').
|
|
541
|
-
* @param username - The upstream agent/service username for authentication. Only if `authType` is 'basic'.
|
|
542
|
-
* @param password - The upstream agent/service password for authentication. Only if `authType` is 'basic'.
|
|
543
|
-
* @param token - The upstream agent/service bearer token for authentication. Only if `authType` is 'bearer' or 'oauth'.
|
|
544
|
-
* @param endpoints - The list endpoints of the upstream service. All these endpoints are protected and only accessible to subscribers of the Payment Plan.
|
|
545
|
-
* @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.
|
|
546
|
-
* @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.
|
|
547
|
-
* @param integration - Some description or instructions about how to integrate the Agent.
|
|
548
|
-
* @param sampleLink - A link to some same usage of the Agent.
|
|
549
|
-
* @param apiDescription - Text describing the API of the Agent.
|
|
550
|
-
* @param curation - The curation details.
|
|
574
|
+
* @param createServiceDto - @see {@link CreateServiceDto}
|
|
551
575
|
* @returns A promise that resolves to the created agent DID.
|
|
552
576
|
*/
|
|
553
|
-
async createService(
|
|
577
|
+
async createService(createServiceDto) {
|
|
554
578
|
let authentication = {};
|
|
555
579
|
let _headers = [];
|
|
556
|
-
if (authType === 'basic') {
|
|
580
|
+
if (createServiceDto.authType === 'basic') {
|
|
557
581
|
authentication = {
|
|
558
582
|
type: 'basic',
|
|
559
|
-
username,
|
|
560
|
-
password,
|
|
583
|
+
username: createServiceDto.username,
|
|
584
|
+
password: createServiceDto.password,
|
|
561
585
|
};
|
|
562
586
|
}
|
|
563
|
-
else if (authType === 'oauth' || authType === 'bearer') {
|
|
587
|
+
else if (createServiceDto.authType === 'oauth' || createServiceDto.authType === 'bearer') {
|
|
564
588
|
authentication = {
|
|
565
|
-
type: authType,
|
|
566
|
-
token,
|
|
589
|
+
type: createServiceDto.authType,
|
|
590
|
+
token: createServiceDto.token,
|
|
567
591
|
};
|
|
568
|
-
_headers = [{ Authorization: `Bearer ${token}` }];
|
|
592
|
+
_headers = [{ Authorization: `Bearer ${createServiceDto.token}` }];
|
|
569
593
|
}
|
|
570
594
|
else {
|
|
571
595
|
authentication = { type: 'none' };
|
|
572
596
|
}
|
|
573
597
|
const metadata = {
|
|
574
598
|
main: {
|
|
575
|
-
name,
|
|
599
|
+
name: createServiceDto.name,
|
|
576
600
|
license: 'No License Specified',
|
|
577
|
-
type: serviceType,
|
|
601
|
+
type: createServiceDto.serviceType,
|
|
578
602
|
files: [],
|
|
579
603
|
ercType: 'nft1155',
|
|
580
604
|
nftType: 'nft1155Credit',
|
|
@@ -583,30 +607,30 @@ class Payments {
|
|
|
583
607
|
subscriptionType: 'credits',
|
|
584
608
|
},
|
|
585
609
|
webService: {
|
|
586
|
-
endpoints: endpoints,
|
|
587
|
-
openEndpoints: openEndpoints,
|
|
588
|
-
chargeType: serviceChargeType,
|
|
589
|
-
isNeverminedHosted: usesAIHub,
|
|
590
|
-
implementsQueryProtocol,
|
|
591
|
-
...(implementsQueryProtocol && { queryProtocolVersion: 'v1' }),
|
|
592
|
-
serviceHost: (0, helper_1.getServiceHostFromEndpoints)(endpoints),
|
|
610
|
+
endpoints: createServiceDto.endpoints,
|
|
611
|
+
openEndpoints: createServiceDto.openEndpoints,
|
|
612
|
+
chargeType: createServiceDto.serviceChargeType,
|
|
613
|
+
isNeverminedHosted: createServiceDto.usesAIHub,
|
|
614
|
+
implementsQueryProtocol: createServiceDto.implementsQueryProtocol,
|
|
615
|
+
...(createServiceDto.implementsQueryProtocol && { queryProtocolVersion: 'v1' }),
|
|
616
|
+
serviceHost: (0, helper_1.getServiceHostFromEndpoints)(createServiceDto.endpoints),
|
|
593
617
|
internalAttributes: {
|
|
594
618
|
authentication,
|
|
595
619
|
headers: _headers,
|
|
596
|
-
chargeType: serviceChargeType,
|
|
620
|
+
chargeType: createServiceDto.serviceChargeType,
|
|
597
621
|
},
|
|
598
622
|
},
|
|
599
|
-
...(curation && { curation }),
|
|
623
|
+
...(createServiceDto.curation && { curation: createServiceDto.curation }),
|
|
600
624
|
additionalInformation: {
|
|
601
|
-
description,
|
|
602
|
-
tags: tags ? tags : [],
|
|
625
|
+
description: createServiceDto.description,
|
|
626
|
+
tags: createServiceDto.tags ? createServiceDto.tags : [],
|
|
603
627
|
customData: {
|
|
604
|
-
openApiUrl,
|
|
605
|
-
integration,
|
|
606
|
-
sampleLink,
|
|
607
|
-
apiDescription,
|
|
628
|
+
openApiUrl: createServiceDto.openApiUrl,
|
|
629
|
+
integration: createServiceDto.integration,
|
|
630
|
+
sampleLink: createServiceDto.sampleLink,
|
|
631
|
+
apiDescription: createServiceDto.apiDescription,
|
|
608
632
|
plan: 'custom',
|
|
609
|
-
serviceChargeType,
|
|
633
|
+
serviceChargeType: createServiceDto.serviceChargeType,
|
|
610
634
|
},
|
|
611
635
|
},
|
|
612
636
|
},
|
|
@@ -615,11 +639,11 @@ class Payments {
|
|
|
615
639
|
{
|
|
616
640
|
serviceType: 'nft-access',
|
|
617
641
|
nft: {
|
|
618
|
-
amount: amountOfCredits ? amountOfCredits : 1,
|
|
619
|
-
tokenId: planDID,
|
|
620
|
-
minCreditsToCharge,
|
|
621
|
-
minCreditsRequired: minCreditsToCharge,
|
|
622
|
-
maxCreditsToCharge,
|
|
642
|
+
amount: createServiceDto.amountOfCredits ? createServiceDto.amountOfCredits : 1,
|
|
643
|
+
tokenId: createServiceDto.planDID,
|
|
644
|
+
minCreditsToCharge: createServiceDto.minCreditsToCharge,
|
|
645
|
+
minCreditsRequired: createServiceDto.minCreditsToCharge,
|
|
646
|
+
maxCreditsToCharge: createServiceDto.maxCreditsToCharge,
|
|
623
647
|
nftTransfer: false,
|
|
624
648
|
},
|
|
625
649
|
},
|
|
@@ -627,7 +651,7 @@ class Payments {
|
|
|
627
651
|
const body = {
|
|
628
652
|
metadata,
|
|
629
653
|
serviceAttributes,
|
|
630
|
-
subscriptionDid: planDID,
|
|
654
|
+
subscriptionDid: createServiceDto.planDID,
|
|
631
655
|
};
|
|
632
656
|
const options = {
|
|
633
657
|
method: 'POST',
|
|
@@ -657,52 +681,35 @@ class Payments {
|
|
|
657
681
|
*
|
|
658
682
|
* @see https://docs.nevermined.app/docs/tutorials/builders/register-file-asset
|
|
659
683
|
*
|
|
660
|
-
* @param
|
|
661
|
-
* @param assetType - The type of asset ('dataset' | 'algorithm' | 'model' | 'file' | 'other')
|
|
662
|
-
* @param name - The name of the file.
|
|
663
|
-
* @param description - The description of the file.
|
|
664
|
-
* @param files - The array of files that can be downloaded for users that are subscribers of the Payment Plan.
|
|
665
|
-
* @param amountOfCredits - The cost in credits of downloading a file. This parameter is only required if the Payment Plan attached to the file is based on credits.
|
|
666
|
-
* @param tags - The array of tags describing the file.
|
|
667
|
-
* @param dataSchema - The data schema of the files.
|
|
668
|
-
* @param sampleCode - Some sample code related to the file.
|
|
669
|
-
* @param filesFormat - The format of the files.
|
|
670
|
-
* @param usageExample - The usage example.
|
|
671
|
-
* @param programmingLanguage - The programming language used in the files.
|
|
672
|
-
* @param framework - The framework used for creating the file.
|
|
673
|
-
* @param task - The task creating the file.
|
|
674
|
-
* @param trainingDetails - The training details.
|
|
675
|
-
* @param variations - The variations.
|
|
676
|
-
* @param fineTunable - Indicates if the file is fine-tunable.
|
|
677
|
-
* @param curation - The curation object.
|
|
684
|
+
* @param createFileDto - @see {@link CreateFileDto}
|
|
678
685
|
* @returns The promise that resolves to the created file's DID.
|
|
679
686
|
*/
|
|
680
|
-
async createFile(
|
|
687
|
+
async createFile(createFileDto) {
|
|
681
688
|
const metadata = {
|
|
682
689
|
main: {
|
|
683
|
-
name,
|
|
690
|
+
name: createFileDto.name,
|
|
684
691
|
license: 'No License Specified',
|
|
685
|
-
type: assetType,
|
|
686
|
-
files,
|
|
692
|
+
type: createFileDto.assetType,
|
|
693
|
+
files: createFileDto.files,
|
|
687
694
|
ercType: 'nft1155',
|
|
688
695
|
nftType: 'nft1155Credit',
|
|
689
696
|
},
|
|
690
|
-
...(curation && { curation }),
|
|
697
|
+
...(createFileDto.curation && { curation: createFileDto.curation }),
|
|
691
698
|
additionalInformation: {
|
|
692
|
-
description,
|
|
693
|
-
tags: tags ? tags : [],
|
|
699
|
+
description: createFileDto.description,
|
|
700
|
+
tags: createFileDto.tags ? createFileDto.tags : [],
|
|
694
701
|
customData: {
|
|
695
|
-
dataSchema,
|
|
696
|
-
sampleCode,
|
|
697
|
-
usageExample,
|
|
698
|
-
filesFormat,
|
|
699
|
-
programmingLanguage,
|
|
700
|
-
framework,
|
|
701
|
-
task,
|
|
702
|
-
architecture: task,
|
|
703
|
-
trainingDetails,
|
|
704
|
-
variations,
|
|
705
|
-
fineTunable,
|
|
702
|
+
dataSchema: createFileDto.dataSchema,
|
|
703
|
+
sampleCode: createFileDto.sampleCode,
|
|
704
|
+
usageExample: createFileDto.usageExample,
|
|
705
|
+
filesFormat: createFileDto.filesFormat,
|
|
706
|
+
programmingLanguage: createFileDto.programmingLanguage,
|
|
707
|
+
framework: createFileDto.framework,
|
|
708
|
+
task: createFileDto.task,
|
|
709
|
+
architecture: createFileDto.task,
|
|
710
|
+
trainingDetails: createFileDto.trainingDetails,
|
|
711
|
+
variations: createFileDto.variations,
|
|
712
|
+
fineTunable: createFileDto.fineTunable,
|
|
706
713
|
plan: 'custom',
|
|
707
714
|
},
|
|
708
715
|
},
|
|
@@ -711,8 +718,8 @@ class Payments {
|
|
|
711
718
|
{
|
|
712
719
|
serviceType: 'nft-access',
|
|
713
720
|
nft: {
|
|
714
|
-
tokenId: planDID,
|
|
715
|
-
amount: amountOfCredits ? amountOfCredits : 1,
|
|
721
|
+
tokenId: createFileDto.planDID,
|
|
722
|
+
amount: createFileDto.amountOfCredits ? createFileDto.amountOfCredits : 1,
|
|
716
723
|
nftTransfer: false,
|
|
717
724
|
},
|
|
718
725
|
},
|
|
@@ -720,7 +727,7 @@ class Payments {
|
|
|
720
727
|
const body = {
|
|
721
728
|
metadata,
|
|
722
729
|
serviceAttributes,
|
|
723
|
-
subscriptionDid: planDID,
|
|
730
|
+
subscriptionDid: createFileDto.planDID,
|
|
724
731
|
};
|
|
725
732
|
const options = {
|
|
726
733
|
method: 'POST',
|
|
@@ -834,6 +841,7 @@ class Payments {
|
|
|
834
841
|
};
|
|
835
842
|
const url = new URL('/api/v1/payments/subscription/order', this.environment.backend);
|
|
836
843
|
const response = await fetch(url, options);
|
|
844
|
+
console.log(response);
|
|
837
845
|
if (!response.ok) {
|
|
838
846
|
throw Error(`${response.statusText} - ${await response.text()}`);
|
|
839
847
|
}
|
|
@@ -986,6 +994,74 @@ class Payments {
|
|
|
986
994
|
}
|
|
987
995
|
return response.json();
|
|
988
996
|
}
|
|
997
|
+
/**
|
|
998
|
+
*
|
|
999
|
+
* Search for Payment Plans based on a text query.
|
|
1000
|
+
*
|
|
1001
|
+
* @example
|
|
1002
|
+
* ```
|
|
1003
|
+
* const plans = await payments.searchPlans({ text: 'test' })
|
|
1004
|
+
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @param text - The text query to search for Payment Plans.
|
|
1007
|
+
* @param page - The page number for pagination.
|
|
1008
|
+
* @param offset - The number of items per page.
|
|
1009
|
+
* @returns A Promise that resolves to the JSON response from the server.
|
|
1010
|
+
* @throws Error if the server response is not successful.
|
|
1011
|
+
*
|
|
1012
|
+
*/
|
|
1013
|
+
async searchPlans({ text, page = 1, offset = 10, }) {
|
|
1014
|
+
const body = { text: text, page: page, offset: offset };
|
|
1015
|
+
const options = {
|
|
1016
|
+
method: 'POST',
|
|
1017
|
+
headers: {
|
|
1018
|
+
Accept: 'application/json',
|
|
1019
|
+
'Content-Type': 'application/json',
|
|
1020
|
+
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
1021
|
+
},
|
|
1022
|
+
body: JSON.stringify(body),
|
|
1023
|
+
};
|
|
1024
|
+
const url = new URL('/api/v1/payments/search/plan', this.environment.backend);
|
|
1025
|
+
const response = await fetch(url, options);
|
|
1026
|
+
if (!response.ok) {
|
|
1027
|
+
throw Error(`${response.statusText} - ${await response.text()}`);
|
|
1028
|
+
}
|
|
1029
|
+
return response.json();
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
*
|
|
1033
|
+
* Search for AI Agents based on a text query.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```
|
|
1037
|
+
* const agents = await payments.searchAgents({ text: 'test' })
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* @param text - The text query to search for Payment Plans.
|
|
1041
|
+
* @param page - The page number for pagination.
|
|
1042
|
+
* @param offset - The number of items per page.
|
|
1043
|
+
* @returns A Promise that resolves to the JSON response from the server.
|
|
1044
|
+
* @throws Error if the server response is not successful.
|
|
1045
|
+
*
|
|
1046
|
+
*/
|
|
1047
|
+
async searchAgents({ text, page = 1, offset = 10, }) {
|
|
1048
|
+
const body = { text: text, page: page, offset: offset };
|
|
1049
|
+
const options = {
|
|
1050
|
+
method: 'POST',
|
|
1051
|
+
headers: {
|
|
1052
|
+
Accept: 'application/json',
|
|
1053
|
+
'Content-Type': 'application/json',
|
|
1054
|
+
Authorization: `Bearer ${this.nvmApiKey}`,
|
|
1055
|
+
},
|
|
1056
|
+
body: JSON.stringify(body),
|
|
1057
|
+
};
|
|
1058
|
+
const url = new URL('/api/v1/payments/search/agent', this.environment.backend);
|
|
1059
|
+
const response = await fetch(url, options);
|
|
1060
|
+
if (!response.ok) {
|
|
1061
|
+
throw Error(`${response.statusText} - ${await response.text()}`);
|
|
1062
|
+
}
|
|
1063
|
+
return response.json();
|
|
1064
|
+
}
|
|
989
1065
|
}
|
|
990
1066
|
exports.Payments = Payments;
|
|
991
1067
|
//# sourceMappingURL=payments.js.map
|