@nevermined-io/commons 0.0.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.
Files changed (56) hide show
  1. package/README.md +7 -0
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +4 -0
  5. package/dist/lib/constants/AssetConstants.d.ts +4 -0
  6. package/dist/lib/constants/AssetConstants.d.ts.map +1 -0
  7. package/dist/lib/constants/AssetConstants.js +3 -0
  8. package/dist/lib/constants/index.d.ts +3 -0
  9. package/dist/lib/constants/index.d.ts.map +1 -0
  10. package/dist/lib/constants/index.js +1 -0
  11. package/dist/lib/ddo/DDO.d.ts +40 -0
  12. package/dist/lib/ddo/DDO.d.ts.map +1 -0
  13. package/dist/lib/ddo/DDO.js +97 -0
  14. package/dist/lib/ddo/index.d.ts +2 -0
  15. package/dist/lib/ddo/index.d.ts.map +1 -0
  16. package/dist/lib/ddo/index.js +1 -0
  17. package/dist/lib/types/ApiResponseTypes.d.ts +46 -0
  18. package/dist/lib/types/ApiResponseTypes.d.ts.map +1 -0
  19. package/dist/lib/types/ApiResponseTypes.js +39 -0
  20. package/dist/lib/types/ContractsTypes.d.ts +90 -0
  21. package/dist/lib/types/ContractsTypes.d.ts.map +1 -0
  22. package/dist/lib/types/ContractsTypes.js +26 -0
  23. package/dist/lib/types/DDOTypes.d.ts +134 -0
  24. package/dist/lib/types/DDOTypes.d.ts.map +1 -0
  25. package/dist/lib/types/DDOTypes.js +14 -0
  26. package/dist/lib/types/GeneralTypes.d.ts +28 -0
  27. package/dist/lib/types/GeneralTypes.d.ts.map +1 -0
  28. package/dist/lib/types/GeneralTypes.js +1 -0
  29. package/dist/lib/types/MetadataTypes.d.ts +130 -0
  30. package/dist/lib/types/MetadataTypes.d.ts.map +1 -0
  31. package/dist/lib/types/MetadataTypes.js +62 -0
  32. package/dist/lib/types/OrganizationResponseTypes.d.ts +150 -0
  33. package/dist/lib/types/OrganizationResponseTypes.d.ts.map +1 -0
  34. package/dist/lib/types/OrganizationResponseTypes.js +124 -0
  35. package/dist/lib/types/TranscoderTypes.d.ts +28 -0
  36. package/dist/lib/types/TranscoderTypes.d.ts.map +1 -0
  37. package/dist/lib/types/TranscoderTypes.js +30 -0
  38. package/dist/lib/types/index.d.ts +7 -0
  39. package/dist/lib/types/index.d.ts.map +1 -0
  40. package/dist/lib/types/index.js +6 -0
  41. package/dist/lib/types/types.d.ts +228 -0
  42. package/dist/lib/types/types.d.ts.map +1 -0
  43. package/dist/lib/types/types.js +152 -0
  44. package/package.json +22 -0
  45. package/src/index.ts +4 -0
  46. package/src/lib/constants/AssetConstants.ts +7 -0
  47. package/src/lib/constants/index.ts +2 -0
  48. package/src/lib/ddo/DDO.ts +121 -0
  49. package/src/lib/ddo/index.ts +1 -0
  50. package/src/lib/types/ContractsTypes.ts +113 -0
  51. package/src/lib/types/DDOTypes.ts +149 -0
  52. package/src/lib/types/GeneralTypes.ts +31 -0
  53. package/src/lib/types/MetadataTypes.ts +145 -0
  54. package/src/lib/types/TranscoderTypes.ts +29 -0
  55. package/src/lib/types/index.ts +6 -0
  56. package/src/lib/types/types.ts +264 -0
@@ -0,0 +1,228 @@
1
+ import * as jose from 'jose';
2
+ export declare enum AuthRoles {
3
+ Admin = "admin"
4
+ }
5
+ export interface AuthUser {
6
+ userId: string;
7
+ address: string;
8
+ hash: string;
9
+ roles?: AuthRoles[];
10
+ nvmApiKey?: jose.JWTPayload;
11
+ }
12
+ export interface Request<G> {
13
+ hostname: string;
14
+ body?: G;
15
+ query?: G;
16
+ params?: G;
17
+ client: {
18
+ localPort: number;
19
+ };
20
+ protocol: string;
21
+ url: string;
22
+ user?: AuthUser;
23
+ }
24
+ export type DistinctPlans = {
25
+ page: number;
26
+ totalPages: number;
27
+ totalResults: number;
28
+ results: any[];
29
+ };
30
+ export declare enum PointsRulesCategory {
31
+ wau = "wau",
32
+ supply = "supply",
33
+ purchases = "purchases",
34
+ demand = "demand",
35
+ curation = "curation",
36
+ network = "network",
37
+ other = "other"
38
+ }
39
+ export declare enum PointsRulesRecurrency {
40
+ unlimitted = "unlimitted",
41
+ timeslimitted = "timeslimitted",
42
+ onlyonce = "onlyonce",
43
+ onceperitem = "onceperitem",
44
+ capday = "capday",
45
+ capweek = "capweek",
46
+ capmonth = "capmonth",
47
+ capyear = "capyear",
48
+ other = "other"
49
+ }
50
+ export declare enum PointsEventStatus {
51
+ Pending = "Pending",
52
+ Processed = "Processed",
53
+ Failed = "Failed",
54
+ Skipped = "Skipped",
55
+ Other = "Other"
56
+ }
57
+ export declare enum NotificationType {
58
+ SubscriptionReceived = "SubscriptionReceived",
59
+ SubscriptionPurchased = "SubscriptionPurchased",
60
+ AccountSetup = "AccountSetup",
61
+ EmailValidation = "EmailValidation",
62
+ Other = "Other"
63
+ }
64
+ export declare enum NotificationOriginator {
65
+ Nevermined = "Nevermined",
66
+ Other = "Other"
67
+ }
68
+ export declare enum NotificationReadStatus {
69
+ Pending = "Pending",
70
+ Read = "Read",
71
+ Deleted = "Deleted",
72
+ Other = "Other"
73
+ }
74
+ export declare enum NotificationDeliveryStatus {
75
+ Pending = "Pending",
76
+ Sent = "Sent",
77
+ Failed = "Failed",
78
+ NotRequired = "NotRequired",
79
+ Skipped = "Skipped",
80
+ Other = "Other"
81
+ }
82
+ export declare enum EmailChallengeStatus {
83
+ Pending = "Pending",
84
+ Validated = "Validated",
85
+ Failed = "Failed"
86
+ }
87
+ export declare enum PlanTransactionType {
88
+ Purchase = "Purchase",
89
+ Mint = "Mint",
90
+ Burn = "Burn",
91
+ Transfer = "Transfer",
92
+ Error = "Error",
93
+ Other = "Other"
94
+ }
95
+ export declare enum PlanTransactionPaymentType {
96
+ Crypto = "Crypto",
97
+ Fiat = "Fiat"
98
+ }
99
+ export declare enum CheckoutSessionType {
100
+ embedded = "embedded",
101
+ redirect = "redirect"
102
+ }
103
+ export declare enum WidgetLayout {
104
+ Horizontal = "Horizontal",
105
+ Vertical = "Vertical",
106
+ Reduced = "Reduced"
107
+ }
108
+ export declare enum StripeEventStatus {
109
+ Pending = "Pending",
110
+ Done = "Done",
111
+ Error = "Error",
112
+ Ignored = "Ignored",
113
+ Other = "Other"
114
+ }
115
+ export declare enum ResultType {
116
+ matrix = "matrix",
117
+ vector = "vector",
118
+ scalar = "scalar",
119
+ string = "string"
120
+ }
121
+ export declare enum ApiKeyTxType {
122
+ NewPlan = "NewPlan",
123
+ NewAgent = "NewAgent",
124
+ EditPlan = "EditPlan",
125
+ EditAgent = "EditAgent",
126
+ Purchase = "Purchase",
127
+ Download = "Download",
128
+ AccessHit = "AccessHit",
129
+ Mint = "Mint",
130
+ Burn = "Burn",
131
+ AgentExecution = "AgentExecution",
132
+ Other = "Other"
133
+ }
134
+ export interface Metric {
135
+ consumer: string;
136
+ did: string;
137
+ endpoint: string;
138
+ job: string;
139
+ namespace: string;
140
+ owner: string;
141
+ access_date: Date;
142
+ }
143
+ export interface AccessHistory {
144
+ date: string;
145
+ owner: string;
146
+ consumer: string;
147
+ endpoint: string;
148
+ }
149
+ export interface LineItem {
150
+ planId: string;
151
+ currency: string;
152
+ name: string;
153
+ price: number;
154
+ quantity: number;
155
+ description?: string;
156
+ imageUrl?: string;
157
+ }
158
+ export interface StripeLineItem {
159
+ price_data: {
160
+ currency: string;
161
+ product_data: {
162
+ name: string;
163
+ description?: string;
164
+ images?: string[];
165
+ metadata?: [string, string];
166
+ };
167
+ unit_amount_decimal: number;
168
+ };
169
+ quantity: number;
170
+ }
171
+ export declare const DEFAULT_PAGE = 1;
172
+ export declare const DEFAULT_OFFSET = 10000;
173
+ export interface PaginationOptions {
174
+ page: number;
175
+ skip: number;
176
+ offset: number;
177
+ sortBy?: string;
178
+ sortOrder?: 'asc' | 'desc';
179
+ }
180
+ export declare enum TaskLogLevel {
181
+ debug = "debug",
182
+ info = "info",
183
+ warn = "warn",
184
+ error = "error"
185
+ }
186
+ export declare enum PaymentPlanTypes {
187
+ expirable = "expirable",
188
+ credits = "credits"
189
+ }
190
+ export interface OrderResult {
191
+ txHash: `0x${string}`;
192
+ planId: bigint;
193
+ planReceiver: `0x${string}`;
194
+ currency: string;
195
+ totalAmount: bigint;
196
+ numCredits: bigint;
197
+ paymentMethod: PlanTransactionPaymentType;
198
+ tokenAddress?: `0x${string}`;
199
+ }
200
+ export declare const NVM_USERID_HEADER = "NVM-User-id";
201
+ export declare const NVM_COST_HEADER = "NVMCreditsConsumed";
202
+ export declare const DEFAULT_COST_CREDITS = "1";
203
+ export declare enum OrganizationType {
204
+ Free = "Free",
205
+ Premium = "Premium",
206
+ Enterprise = "Enterprise",
207
+ Other = "Other"
208
+ }
209
+ export declare enum OrganizationMemberRole {
210
+ Admin = "Admin",
211
+ Member = "Member"
212
+ }
213
+ export interface Branding {
214
+ themeName?: string;
215
+ logo?: string;
216
+ leftPanelHeadingTextColor?: string;
217
+ leftPanelBodyTextColor?: string;
218
+ leftPanelBackgroundColor1?: string;
219
+ leftPanelBackgroundColor2?: string;
220
+ leftPanelBackgroundImageUrl?: string;
221
+ rightCardTextColor?: string;
222
+ rightCardButtonBackgroundColor?: string;
223
+ rightCardButtonTextColor?: string;
224
+ rightCardBackgroundColor1?: string;
225
+ rightCardBackgroundColor2?: string;
226
+ rightCardBackgroundImageUrl?: string;
227
+ }
228
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,oBAAY,SAAS;IACnB,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;IACnB,SAAS,CAAC,EAAE,IAAI,CAAC,UAAU,CAAA;CAC5B;AAED,MAAM,WAAW,OAAO,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+ export var PointsRulesCategory;
6
+ (function (PointsRulesCategory) {
7
+ PointsRulesCategory["wau"] = "wau";
8
+ PointsRulesCategory["supply"] = "supply";
9
+ PointsRulesCategory["purchases"] = "purchases";
10
+ PointsRulesCategory["demand"] = "demand";
11
+ PointsRulesCategory["curation"] = "curation";
12
+ PointsRulesCategory["network"] = "network";
13
+ PointsRulesCategory["other"] = "other";
14
+ })(PointsRulesCategory || (PointsRulesCategory = {}));
15
+ export var PointsRulesRecurrency;
16
+ (function (PointsRulesRecurrency) {
17
+ PointsRulesRecurrency["unlimitted"] = "unlimitted";
18
+ PointsRulesRecurrency["timeslimitted"] = "timeslimitted";
19
+ PointsRulesRecurrency["onlyonce"] = "onlyonce";
20
+ PointsRulesRecurrency["onceperitem"] = "onceperitem";
21
+ PointsRulesRecurrency["capday"] = "capday";
22
+ PointsRulesRecurrency["capweek"] = "capweek";
23
+ PointsRulesRecurrency["capmonth"] = "capmonth";
24
+ PointsRulesRecurrency["capyear"] = "capyear";
25
+ PointsRulesRecurrency["other"] = "other";
26
+ })(PointsRulesRecurrency || (PointsRulesRecurrency = {}));
27
+ export var PointsEventStatus;
28
+ (function (PointsEventStatus) {
29
+ PointsEventStatus["Pending"] = "Pending";
30
+ PointsEventStatus["Processed"] = "Processed";
31
+ PointsEventStatus["Failed"] = "Failed";
32
+ PointsEventStatus["Skipped"] = "Skipped";
33
+ PointsEventStatus["Other"] = "Other";
34
+ })(PointsEventStatus || (PointsEventStatus = {}));
35
+ export var NotificationType;
36
+ (function (NotificationType) {
37
+ NotificationType["SubscriptionReceived"] = "SubscriptionReceived";
38
+ NotificationType["SubscriptionPurchased"] = "SubscriptionPurchased";
39
+ NotificationType["AccountSetup"] = "AccountSetup";
40
+ NotificationType["EmailValidation"] = "EmailValidation";
41
+ NotificationType["Other"] = "Other";
42
+ })(NotificationType || (NotificationType = {}));
43
+ export var NotificationOriginator;
44
+ (function (NotificationOriginator) {
45
+ NotificationOriginator["Nevermined"] = "Nevermined";
46
+ NotificationOriginator["Other"] = "Other";
47
+ })(NotificationOriginator || (NotificationOriginator = {}));
48
+ export var NotificationReadStatus;
49
+ (function (NotificationReadStatus) {
50
+ NotificationReadStatus["Pending"] = "Pending";
51
+ NotificationReadStatus["Read"] = "Read";
52
+ NotificationReadStatus["Deleted"] = "Deleted";
53
+ NotificationReadStatus["Other"] = "Other";
54
+ })(NotificationReadStatus || (NotificationReadStatus = {}));
55
+ export var NotificationDeliveryStatus;
56
+ (function (NotificationDeliveryStatus) {
57
+ NotificationDeliveryStatus["Pending"] = "Pending";
58
+ NotificationDeliveryStatus["Sent"] = "Sent";
59
+ NotificationDeliveryStatus["Failed"] = "Failed";
60
+ NotificationDeliveryStatus["NotRequired"] = "NotRequired";
61
+ NotificationDeliveryStatus["Skipped"] = "Skipped";
62
+ NotificationDeliveryStatus["Other"] = "Other";
63
+ })(NotificationDeliveryStatus || (NotificationDeliveryStatus = {}));
64
+ export var EmailChallengeStatus;
65
+ (function (EmailChallengeStatus) {
66
+ EmailChallengeStatus["Pending"] = "Pending";
67
+ EmailChallengeStatus["Validated"] = "Validated";
68
+ EmailChallengeStatus["Failed"] = "Failed";
69
+ })(EmailChallengeStatus || (EmailChallengeStatus = {}));
70
+ export var PlanTransactionType;
71
+ (function (PlanTransactionType) {
72
+ PlanTransactionType["Purchase"] = "Purchase";
73
+ PlanTransactionType["Mint"] = "Mint";
74
+ PlanTransactionType["Burn"] = "Burn";
75
+ PlanTransactionType["Transfer"] = "Transfer";
76
+ PlanTransactionType["Error"] = "Error";
77
+ PlanTransactionType["Other"] = "Other";
78
+ })(PlanTransactionType || (PlanTransactionType = {}));
79
+ export var PlanTransactionPaymentType;
80
+ (function (PlanTransactionPaymentType) {
81
+ PlanTransactionPaymentType["Crypto"] = "Crypto";
82
+ PlanTransactionPaymentType["Fiat"] = "Fiat";
83
+ })(PlanTransactionPaymentType || (PlanTransactionPaymentType = {}));
84
+ export var CheckoutSessionType;
85
+ (function (CheckoutSessionType) {
86
+ CheckoutSessionType["embedded"] = "embedded";
87
+ CheckoutSessionType["redirect"] = "redirect";
88
+ })(CheckoutSessionType || (CheckoutSessionType = {}));
89
+ export var WidgetLayout;
90
+ (function (WidgetLayout) {
91
+ WidgetLayout["Horizontal"] = "Horizontal";
92
+ WidgetLayout["Vertical"] = "Vertical";
93
+ WidgetLayout["Reduced"] = "Reduced";
94
+ })(WidgetLayout || (WidgetLayout = {}));
95
+ export var StripeEventStatus;
96
+ (function (StripeEventStatus) {
97
+ StripeEventStatus["Pending"] = "Pending";
98
+ StripeEventStatus["Done"] = "Done";
99
+ StripeEventStatus["Error"] = "Error";
100
+ StripeEventStatus["Ignored"] = "Ignored";
101
+ StripeEventStatus["Other"] = "Other";
102
+ })(StripeEventStatus || (StripeEventStatus = {}));
103
+ export var ResultType;
104
+ (function (ResultType) {
105
+ ResultType["matrix"] = "matrix";
106
+ ResultType["vector"] = "vector";
107
+ ResultType["scalar"] = "scalar";
108
+ ResultType["string"] = "string";
109
+ })(ResultType || (ResultType = {}));
110
+ export var ApiKeyTxType;
111
+ (function (ApiKeyTxType) {
112
+ ApiKeyTxType["NewPlan"] = "NewPlan";
113
+ ApiKeyTxType["NewAgent"] = "NewAgent";
114
+ ApiKeyTxType["EditPlan"] = "EditPlan";
115
+ ApiKeyTxType["EditAgent"] = "EditAgent";
116
+ ApiKeyTxType["Purchase"] = "Purchase";
117
+ ApiKeyTxType["Download"] = "Download";
118
+ ApiKeyTxType["AccessHit"] = "AccessHit";
119
+ ApiKeyTxType["Mint"] = "Mint";
120
+ ApiKeyTxType["Burn"] = "Burn";
121
+ ApiKeyTxType["AgentExecution"] = "AgentExecution";
122
+ ApiKeyTxType["Other"] = "Other";
123
+ })(ApiKeyTxType || (ApiKeyTxType = {}));
124
+ export const DEFAULT_PAGE = 1;
125
+ export const DEFAULT_OFFSET = 10_000;
126
+ export var TaskLogLevel;
127
+ (function (TaskLogLevel) {
128
+ TaskLogLevel["debug"] = "debug";
129
+ TaskLogLevel["info"] = "info";
130
+ TaskLogLevel["warn"] = "warn";
131
+ TaskLogLevel["error"] = "error";
132
+ })(TaskLogLevel || (TaskLogLevel = {}));
133
+ export var PaymentPlanTypes;
134
+ (function (PaymentPlanTypes) {
135
+ PaymentPlanTypes["expirable"] = "expirable";
136
+ PaymentPlanTypes["credits"] = "credits";
137
+ })(PaymentPlanTypes || (PaymentPlanTypes = {}));
138
+ export const NVM_USERID_HEADER = 'NVM-User-id';
139
+ export const NVM_COST_HEADER = 'NVMCreditsConsumed';
140
+ export const DEFAULT_COST_CREDITS = '1';
141
+ export var OrganizationType;
142
+ (function (OrganizationType) {
143
+ OrganizationType["Free"] = "Free";
144
+ OrganizationType["Premium"] = "Premium";
145
+ OrganizationType["Enterprise"] = "Enterprise";
146
+ OrganizationType["Other"] = "Other";
147
+ })(OrganizationType || (OrganizationType = {}));
148
+ export var OrganizationMemberRole;
149
+ (function (OrganizationMemberRole) {
150
+ OrganizationMemberRole["Admin"] = "Admin";
151
+ OrganizationMemberRole["Member"] = "Member";
152
+ })(OrganizationMemberRole || (OrganizationMemberRole = {}));
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@nevermined-io/commons",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "private": false,
6
+ "main": "../dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "src",
11
+ "dist",
12
+ "!**/*.tsbuildinfo"
13
+ ],
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
20
+ }
21
+ }
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './lib/types/index.js'
2
+ export * from './lib/ddo/index.js'
3
+ export * from './lib/constants/index.js'
4
+ export { DDO } from './lib/ddo/DDO.js'
@@ -0,0 +1,7 @@
1
+ export const NETWORK_FEE_DENOMINATOR = 10000n
2
+
3
+ // The type of the encryption methods supported for the private data included in the metadata
4
+ export type EncryptionMethod = 'PSK-RSA' | 'PSK-ECDSA'
5
+
6
+ // The default encryption method
7
+ export const DEFAULT_ENCRYPTION_METHOD = 'PSK-RSA' as EncryptionMethod
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_ENCRYPTION_METHOD, NETWORK_FEE_DENOMINATOR } from './AssetConstants.js'
2
+ export type { EncryptionMethod } from './AssetConstants.js'
@@ -0,0 +1,121 @@
1
+ import { CreditsConfig, DIDAgent, Plan, PriceConfig } from '../types/ContractsTypes.js'
2
+ import { Metadata, NvmConfig } from '../types/DDOTypes.js'
3
+
4
+ const jsonReplacer = (_key: string, value: unknown) => {
5
+ // Modify the value or return undefined to exclude the property
6
+ return typeof value === 'bigint' ? value.toString() : value
7
+ }
8
+
9
+ // Union type for registry
10
+ type Registry = DIDAgent | Plan
11
+
12
+ export class DDO {
13
+ /**
14
+ * Serializes the DDO object.
15
+ * @param ddo - The {@link DDO} to be serialized.
16
+ * @returns DDO serialized.
17
+ */
18
+ public static serialize(ddo: DDO): string {
19
+ return JSON.stringify(ddo, jsonReplacer, 2)
20
+ }
21
+
22
+ /**
23
+ * Deserializes the DDO object.
24
+ * @param ddoString - The serialized {@link DDO} to be deserialized.
25
+ * @returns The deserialized {@link DDO}.
26
+ */
27
+ public static deserialize(ddoString: string): DDO {
28
+ const ddo = JSON.parse(ddoString)
29
+
30
+ return new DDO(ddo)
31
+ }
32
+
33
+ /**
34
+ * DID, decentralizes ID.
35
+ */
36
+ public id = ''
37
+
38
+ // public didSeed = ''
39
+
40
+ public ['@context'] = 'https://w3id.org/did/v1'
41
+
42
+ public _nvm: NvmConfig = { userId: '', userAddress: '', appId: '', versions: [] }
43
+
44
+ public created: string = new Date().toISOString().replace(/\.[0-9]{3}/, '')
45
+
46
+ public updated?: string
47
+
48
+ public metadata: Metadata = {
49
+ serviceEndpoint: '',
50
+ main: {
51
+ name: '',
52
+ description: '',
53
+ dateCreated: '',
54
+ datePublished: '',
55
+ license: '',
56
+ tags: [],
57
+ },
58
+ curation: {
59
+ numVotes: 0,
60
+ rating: 0,
61
+ schema: '',
62
+ isListed: true,
63
+ },
64
+ }
65
+
66
+ public registry: Registry
67
+
68
+ public constructor(ddo: Partial<DDO> = {}) {
69
+ Object.assign(this, ddo, {
70
+ created: (ddo && ddo.created) || new Date().toISOString().replace(/\.[0-9]{3}/, ''),
71
+ })
72
+ }
73
+ }
74
+
75
+ export class AgentDDO extends DDO {
76
+ public override registry: DIDAgent = {
77
+ owner: '0x',
78
+ creator: '0x',
79
+ url: '',
80
+ lastUpdated: 0n,
81
+ plans: [],
82
+ }
83
+
84
+ public constructor(ddo: Partial<AgentDDO> = {}) {
85
+ super(ddo)
86
+ }
87
+
88
+ public static getInstance(userId: string, userAddress: string, appId?: string): AgentDDO {
89
+ return new AgentDDO({
90
+ id: '',
91
+ _nvm: { userId, userAddress, appId: appId || '', versions: [] },
92
+ registry: { owner: '0x', creator: '0x', url: '', lastUpdated: 0n, plans: [] },
93
+ })
94
+ }
95
+ }
96
+
97
+ export class PlanDDO extends DDO {
98
+ public override registry: Plan = {
99
+ owner: '0x',
100
+ price: {} as PriceConfig,
101
+ credits: {} as CreditsConfig,
102
+ lastUpdated: 0n,
103
+ }
104
+
105
+ public constructor(ddo: Partial<PlanDDO> = {}) {
106
+ super(ddo)
107
+ }
108
+
109
+ public static getInstance(userId: string, userAddress: string, appId?: string): PlanDDO {
110
+ return new PlanDDO({
111
+ id: '',
112
+ _nvm: { userId, userAddress, appId: appId || '', versions: [] },
113
+ registry: {
114
+ owner: '0x',
115
+ price: {} as PriceConfig,
116
+ credits: {} as CreditsConfig,
117
+ lastUpdated: 0n,
118
+ },
119
+ })
120
+ }
121
+ }
@@ -0,0 +1 @@
1
+ export * from './DDO.js'
@@ -0,0 +1,113 @@
1
+ import { Address } from 'viem'
2
+
3
+ /// Different types of redemptions criterias that can be used when redeeming credits
4
+ /// @notice 0 - ONLY_GLOBAL_ROLE, 1 - ONLY_OWNER, 2 - ROLE_AND_OWNER
5
+ /// If ONLY_GLOBAL_ROLE it means the credits can be redeemed only by an account with the `CREDITS_BURNER_ROLE`
6
+ /// If ONLY_OWNER it means the credits can be redeemed only by the owner of the Plan
7
+ /// If ONLY_PLAN_ROLE it means the credits can be redeemed by an account with specifics grants for the plan
8
+ /// If OWNER_OR_GLOBAL_ROLE means Only the owner OR accounts with CREDITS_BURNER_ROLE can redeem
9
+ /// If ONLY_SUBSCRIBER means only the subscriber (the one who holds the credits NFT) can redeem
10
+ export enum RedemptionType {
11
+ ONLY_GLOBAL_ROLE,
12
+ ONLY_OWNER,
13
+ ONLY_PLAN_ROLE,
14
+ OWNER_OR_GLOBAL_ROLE,
15
+ ONLY_SUBSCRIBER,
16
+ }
17
+
18
+ export interface DIDAgent {
19
+ // The owner of the asset
20
+ owner: Address
21
+ // Asset original creator, this can't be modified after the asset is registered
22
+ creator: Address
23
+ // URL to the metadata associated to the DID
24
+ url: string
25
+ // When was the DID last updated
26
+ lastUpdated: bigint
27
+ // Array of plans that can be used to purchase access to the asset
28
+ plans: bigint[]
29
+ }
30
+
31
+ /// Definition of the price configuration for a plan
32
+ export interface PriceConfig {
33
+ /**
34
+ * @notice Indicates if the price is in cryptocurrency (true) or fiat currency (false)
35
+ */
36
+ isCrypto: boolean
37
+ /**
38
+ * @notice Indicates if the price is in cryptocurrency (true) or fiat currency (false)
39
+ */
40
+ tokenAddress?: Address
41
+ /**
42
+ * The amounts to be paid for the plan
43
+ * @notice only if the price is not calculated by a smart contract
44
+ */
45
+ amounts: bigint[]
46
+ /**
47
+ * The receivers of the payments of the plan
48
+ * @notice only if the price is not calculated by a smart contract
49
+ */
50
+ receivers: string[]
51
+ /**
52
+ * The address of the smart contract that calculates the price
53
+ */
54
+ externalPriceAddress?: Address
55
+ /**
56
+ * The address of the fee controller contract, if any
57
+ * @notice if not given, the fee controller is the default one
58
+ */
59
+ feeController?: Address
60
+ /**
61
+ * @notice The template contract address associated with the plan
62
+ */
63
+ templateAddress?: Address
64
+ }
65
+
66
+ /// Definition of the credits configuration for a plan
67
+ export interface CreditsConfig {
68
+ /**
69
+ * @notice Indicates if the redemption amount is fixed (true) or dynamic (false)
70
+ */
71
+ isRedemptionAmountFixed: boolean
72
+ /**
73
+ * How the credits can be redeemed
74
+ */
75
+ redemptionType: RedemptionType
76
+ /**
77
+ * Whether the credits burn proof signed by the user is required
78
+ */
79
+ proofRequired: boolean
80
+ /**
81
+ * The duration of the credits in seconds
82
+ */
83
+ durationSecs: bigint
84
+ /**
85
+ * The amount of credits that are granted when purchasing the plan
86
+ */
87
+ amount: bigint
88
+ /**
89
+ * The minimum number of credits redeemed when using the plan
90
+ */
91
+ minAmount: bigint
92
+ /**
93
+ * The maximum number of credits redeemed when using the plan
94
+ * @notice only if isRedemptionAmountFixed is false
95
+ */
96
+ maxAmount: bigint
97
+ /**
98
+ * The address of the NFT contract that represents the plan's credits
99
+ */
100
+ nftAddress?: Address
101
+ }
102
+
103
+ /// Definition of a plan
104
+ export class Plan {
105
+ // The owner of the Plan
106
+ owner: Address
107
+ // The price configuration of the plan
108
+ price: PriceConfig
109
+ // The credits configuration of the plan
110
+ credits: CreditsConfig
111
+ // The timestamp of the last time the plan definition was updated
112
+ lastUpdated: bigint
113
+ }