@twin.org/rights-management-service 0.0.2-next.3 → 0.0.2-next.5
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/cjs/index.cjs +557 -21
- package/dist/esm/index.mjs +552 -23
- package/dist/types/models/IRightsManagementServiceConstructorOptions.d.ts +10 -0
- package/dist/types/rightsManagementRoutes.d.ts +57 -1
- package/dist/types/rightsManagementService.d.ts +65 -5
- package/docs/changelog.md +45 -0
- package/docs/open-api/spec.json +1361 -163
- package/docs/reference/classes/RightsManagementService.md +262 -12
- package/docs/reference/functions/pnapGet.md +31 -0
- package/docs/reference/functions/pnapQuery.md +31 -0
- package/docs/reference/functions/pnapRemove.md +31 -0
- package/docs/reference/functions/pnapSet.md +31 -0
- package/docs/reference/functions/pnpNegotiate.md +31 -0
- package/docs/reference/functions/pnpNegotiationCancel.md +31 -0
- package/docs/reference/functions/pnpNegotiationState.md +31 -0
- package/docs/reference/index.md +7 -0
- package/docs/reference/interfaces/IRightsManagementServiceConstructorOptions.md +28 -0
- package/locales/en.json +8 -1
- package/package.json +4 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ const tags = [
|
|
|
27
27
|
* @returns The generated routes.
|
|
28
28
|
*/
|
|
29
29
|
function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
30
|
-
const
|
|
30
|
+
const papCreateRoute = {
|
|
31
31
|
operationId: "papCreate",
|
|
32
32
|
summary: "Create a policy",
|
|
33
33
|
tag: tags[0].name,
|
|
@@ -38,7 +38,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
38
38
|
type: "IPapCreateRequest",
|
|
39
39
|
examples: [
|
|
40
40
|
{
|
|
41
|
-
id: "
|
|
41
|
+
id: "papCreateRequestExample",
|
|
42
42
|
request: {
|
|
43
43
|
body: {
|
|
44
44
|
"@context": standardsW3cOdrl.OdrlContexts.ContextRoot,
|
|
@@ -71,7 +71,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
71
71
|
}
|
|
72
72
|
]
|
|
73
73
|
};
|
|
74
|
-
const
|
|
74
|
+
const papUpdateRoute = {
|
|
75
75
|
operationId: "papUpdate",
|
|
76
76
|
summary: "Update a policy",
|
|
77
77
|
tag: tags[0].name,
|
|
@@ -82,7 +82,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
82
82
|
type: "IPapUpdateRequest",
|
|
83
83
|
examples: [
|
|
84
84
|
{
|
|
85
|
-
id: "
|
|
85
|
+
id: "papUpdateRequestExample",
|
|
86
86
|
request: {
|
|
87
87
|
pathParams: {
|
|
88
88
|
id: "urn:rights-management:abc123def456"
|
|
@@ -108,7 +108,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
108
108
|
}
|
|
109
109
|
]
|
|
110
110
|
};
|
|
111
|
-
const
|
|
111
|
+
const papRetrieveRoute = {
|
|
112
112
|
operationId: "papRetrieve",
|
|
113
113
|
summary: "Retrieve a policy",
|
|
114
114
|
tag: tags[0].name,
|
|
@@ -119,7 +119,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
119
119
|
type: "IPapRetrieveRequest",
|
|
120
120
|
examples: [
|
|
121
121
|
{
|
|
122
|
-
id: "
|
|
122
|
+
id: "papRetrieveRequestExample",
|
|
123
123
|
request: {
|
|
124
124
|
pathParams: {
|
|
125
125
|
id: "urn:rights-management:abc123def456"
|
|
@@ -152,7 +152,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
152
152
|
}
|
|
153
153
|
]
|
|
154
154
|
};
|
|
155
|
-
const
|
|
155
|
+
const papRemoveRoute = {
|
|
156
156
|
operationId: "papRemove",
|
|
157
157
|
summary: "Remove a policy",
|
|
158
158
|
tag: tags[0].name,
|
|
@@ -163,7 +163,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
163
163
|
type: "IPapRemoveRequest",
|
|
164
164
|
examples: [
|
|
165
165
|
{
|
|
166
|
-
id: "
|
|
166
|
+
id: "papRemoveRequestExample",
|
|
167
167
|
request: {
|
|
168
168
|
pathParams: {
|
|
169
169
|
id: "urn:rights-management:abc123def456"
|
|
@@ -178,7 +178,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
178
178
|
}
|
|
179
179
|
]
|
|
180
180
|
};
|
|
181
|
-
const
|
|
181
|
+
const papQueryRoute = {
|
|
182
182
|
operationId: "papQuery",
|
|
183
183
|
summary: "Query policies",
|
|
184
184
|
tag: tags[0].name,
|
|
@@ -189,7 +189,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
189
189
|
type: "IPapQueryRequest",
|
|
190
190
|
examples: [
|
|
191
191
|
{
|
|
192
|
-
id: "
|
|
192
|
+
id: "papQueryRequestExample",
|
|
193
193
|
request: {
|
|
194
194
|
query: {
|
|
195
195
|
cursor: "optional-pagination-cursor"
|
|
@@ -227,7 +227,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
227
227
|
}
|
|
228
228
|
]
|
|
229
229
|
};
|
|
230
|
-
const
|
|
230
|
+
const pepInterceptRoute = {
|
|
231
231
|
operationId: "pepIntercept",
|
|
232
232
|
summary: "Intercept a request",
|
|
233
233
|
tag: tags[0].name,
|
|
@@ -238,7 +238,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
238
238
|
type: "IPepInterceptRequest",
|
|
239
239
|
examples: [
|
|
240
240
|
{
|
|
241
|
-
id: "
|
|
241
|
+
id: "pepInterceptRequestExample",
|
|
242
242
|
request: {
|
|
243
243
|
body: {
|
|
244
244
|
assetType: "document",
|
|
@@ -270,7 +270,289 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
270
270
|
}
|
|
271
271
|
]
|
|
272
272
|
};
|
|
273
|
-
|
|
273
|
+
const papNegotiateRoute = {
|
|
274
|
+
operationId: "pnpNegotiate",
|
|
275
|
+
summary: "Negotiate a policy",
|
|
276
|
+
tag: tags[0].name,
|
|
277
|
+
method: "POST",
|
|
278
|
+
path: `${baseRouteName}/pnp/negotiate`,
|
|
279
|
+
handler: async (httpRequestContext, request) => pnpNegotiate(httpRequestContext, componentName, request),
|
|
280
|
+
requestType: {
|
|
281
|
+
type: "IPnpNegotiateRequest",
|
|
282
|
+
examples: [
|
|
283
|
+
{
|
|
284
|
+
id: "pnpNegotiateRequestExample",
|
|
285
|
+
request: {
|
|
286
|
+
body: {
|
|
287
|
+
assetType: "document",
|
|
288
|
+
action: "view",
|
|
289
|
+
context: {
|
|
290
|
+
nodeIdentity: "urn:example:node:1"
|
|
291
|
+
},
|
|
292
|
+
proof: {
|
|
293
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
294
|
+
type: "DataIntegrityProof",
|
|
295
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
296
|
+
proofPurpose: "assertionMethod",
|
|
297
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
298
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
responseType: [
|
|
306
|
+
{
|
|
307
|
+
type: "IPnpNegotiateResponse",
|
|
308
|
+
examples: [
|
|
309
|
+
{
|
|
310
|
+
id: "IPnpNegotiateResponseExample",
|
|
311
|
+
response: {
|
|
312
|
+
body: {
|
|
313
|
+
id: "policy-1",
|
|
314
|
+
status: "approved"
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
skipAuth: true
|
|
322
|
+
};
|
|
323
|
+
const papNegotiationStateRoute = {
|
|
324
|
+
operationId: "pnpNegotiationState",
|
|
325
|
+
summary: "Get the state of a policy",
|
|
326
|
+
tag: tags[0].name,
|
|
327
|
+
method: "POST",
|
|
328
|
+
path: `${baseRouteName}/pnp/:policyId`,
|
|
329
|
+
handler: async (httpRequestContext, request) => pnpNegotiationState(httpRequestContext, componentName, request),
|
|
330
|
+
requestType: {
|
|
331
|
+
type: "IPnpNegotiationStateRequest",
|
|
332
|
+
examples: [
|
|
333
|
+
{
|
|
334
|
+
id: "pnpNegotiationStateRequestExample",
|
|
335
|
+
request: {
|
|
336
|
+
pathParams: {
|
|
337
|
+
policyId: "policy-1"
|
|
338
|
+
},
|
|
339
|
+
body: {
|
|
340
|
+
nodeIdentity: "urn:example:node:1",
|
|
341
|
+
proof: {
|
|
342
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
343
|
+
type: "DataIntegrityProof",
|
|
344
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
345
|
+
proofPurpose: "assertionMethod",
|
|
346
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
347
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
},
|
|
354
|
+
responseType: [
|
|
355
|
+
{
|
|
356
|
+
type: "IPnpNegotiationStateResponse",
|
|
357
|
+
examples: [
|
|
358
|
+
{
|
|
359
|
+
id: "IPnpNegotiationStateResponseExample",
|
|
360
|
+
response: {
|
|
361
|
+
body: {
|
|
362
|
+
id: "policy-1",
|
|
363
|
+
status: "approved"
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
],
|
|
370
|
+
skipAuth: true
|
|
371
|
+
};
|
|
372
|
+
const pnpNegotiationCancelRoute = {
|
|
373
|
+
operationId: "pnpCancel",
|
|
374
|
+
summary: "Cancel a policy negotiation",
|
|
375
|
+
tag: tags[0].name,
|
|
376
|
+
method: "DELETE",
|
|
377
|
+
path: `${baseRouteName}/pnp/:policyId`,
|
|
378
|
+
handler: async (httpRequestContext, request) => pnpNegotiationCancel(httpRequestContext, componentName, request),
|
|
379
|
+
requestType: {
|
|
380
|
+
type: "IPnpNegotiationCancelRequest",
|
|
381
|
+
examples: [
|
|
382
|
+
{
|
|
383
|
+
id: "pnpNegotiationCancelRequestExample",
|
|
384
|
+
request: {
|
|
385
|
+
pathParams: {
|
|
386
|
+
policyId: "policy-1"
|
|
387
|
+
},
|
|
388
|
+
body: {
|
|
389
|
+
nodeIdentity: "urn:example:node:1",
|
|
390
|
+
proof: {
|
|
391
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
392
|
+
type: "DataIntegrityProof",
|
|
393
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
394
|
+
proofPurpose: "assertionMethod",
|
|
395
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
396
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
},
|
|
403
|
+
responseType: [
|
|
404
|
+
{
|
|
405
|
+
type: "INoContentResponse"
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
skipAuth: true
|
|
409
|
+
};
|
|
410
|
+
const pnapGetRoute = {
|
|
411
|
+
operationId: "pnapGet",
|
|
412
|
+
summary: "Get a policy negotiation",
|
|
413
|
+
tag: tags[0].name,
|
|
414
|
+
method: web.HttpMethod.GET,
|
|
415
|
+
path: `${baseRouteName}/pnap/:policyId`,
|
|
416
|
+
handler: async (httpRequestContext, request) => pnapGet(httpRequestContext, componentName, request),
|
|
417
|
+
requestType: {
|
|
418
|
+
type: "IPnapGetRequest",
|
|
419
|
+
examples: [
|
|
420
|
+
{
|
|
421
|
+
id: "pnapGetRequestExample",
|
|
422
|
+
request: {
|
|
423
|
+
pathParams: { policyId: "policy-1" }
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
},
|
|
428
|
+
responseType: [
|
|
429
|
+
{
|
|
430
|
+
type: "IPnapGetResponse",
|
|
431
|
+
examples: [
|
|
432
|
+
{
|
|
433
|
+
id: "pnapGetResponseExample",
|
|
434
|
+
response: {
|
|
435
|
+
body: {
|
|
436
|
+
id: "policy-1",
|
|
437
|
+
status: "manual",
|
|
438
|
+
dateCreated: "2025-09-03T00:00:00.000Z",
|
|
439
|
+
assetType: "document",
|
|
440
|
+
action: "view",
|
|
441
|
+
context: {}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
]
|
|
448
|
+
};
|
|
449
|
+
const pnapSetRoute = {
|
|
450
|
+
operationId: "pnapSet",
|
|
451
|
+
summary: "Set a policy negotiation",
|
|
452
|
+
tag: tags[0].name,
|
|
453
|
+
method: web.HttpMethod.PUT,
|
|
454
|
+
path: `${baseRouteName}/pnap/:policyId`,
|
|
455
|
+
handler: async (httpRequestContext, request) => pnapSet(httpRequestContext, componentName, request),
|
|
456
|
+
requestType: {
|
|
457
|
+
type: "IPnapSetRequest",
|
|
458
|
+
examples: [
|
|
459
|
+
{
|
|
460
|
+
id: "pnapSetRequestExample",
|
|
461
|
+
request: {
|
|
462
|
+
pathParams: { policyId: "policy-1" },
|
|
463
|
+
body: {
|
|
464
|
+
id: "policy-1",
|
|
465
|
+
status: "approved",
|
|
466
|
+
dateCreated: "2025-09-03T00:00:00.000Z",
|
|
467
|
+
assetType: "document",
|
|
468
|
+
action: "view",
|
|
469
|
+
context: {}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
},
|
|
475
|
+
responseType: [{ type: "INoContentResponse" }]
|
|
476
|
+
};
|
|
477
|
+
const pnapRemoveRoute = {
|
|
478
|
+
operationId: "pnapRemove",
|
|
479
|
+
summary: "Remove a policy negotiation",
|
|
480
|
+
tag: tags[0].name,
|
|
481
|
+
method: web.HttpMethod.DELETE,
|
|
482
|
+
path: `${baseRouteName}/pnap/:policyId`,
|
|
483
|
+
handler: async (httpRequestContext, request) => pnapRemove(httpRequestContext, componentName, request),
|
|
484
|
+
requestType: {
|
|
485
|
+
type: "IPnapRemoveRequest",
|
|
486
|
+
examples: [
|
|
487
|
+
{
|
|
488
|
+
id: "pnapRemoveRequestExample",
|
|
489
|
+
request: {
|
|
490
|
+
pathParams: { policyId: "policy-1" }
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
},
|
|
495
|
+
responseType: [{ type: "INoContentResponse" }]
|
|
496
|
+
};
|
|
497
|
+
const pnapQueryRoute = {
|
|
498
|
+
operationId: "pnapQuery",
|
|
499
|
+
summary: "Query policy negotiations",
|
|
500
|
+
tag: tags[0].name,
|
|
501
|
+
method: web.HttpMethod.GET,
|
|
502
|
+
path: `${baseRouteName}/pnap`,
|
|
503
|
+
handler: async (httpRequestContext, request) => pnapQuery(httpRequestContext, componentName, request),
|
|
504
|
+
requestType: {
|
|
505
|
+
type: "IPnapQueryRequest",
|
|
506
|
+
examples: [
|
|
507
|
+
{
|
|
508
|
+
id: "pnapQueryRequestExample",
|
|
509
|
+
request: {
|
|
510
|
+
query: { status: "manual", cursor: "next-cursor" }
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
responseType: [
|
|
516
|
+
{
|
|
517
|
+
type: "IPnapQueryResponse",
|
|
518
|
+
examples: [
|
|
519
|
+
{
|
|
520
|
+
id: "pnapQueryResponseExample",
|
|
521
|
+
response: {
|
|
522
|
+
body: {
|
|
523
|
+
items: [
|
|
524
|
+
{
|
|
525
|
+
id: "policy-1",
|
|
526
|
+
status: "manual",
|
|
527
|
+
dateCreated: "2025-09-03T00:00:00.000Z",
|
|
528
|
+
assetType: "document",
|
|
529
|
+
action: "view",
|
|
530
|
+
context: {}
|
|
531
|
+
}
|
|
532
|
+
],
|
|
533
|
+
cursor: "next-cursor"
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
};
|
|
541
|
+
return [
|
|
542
|
+
papCreateRoute,
|
|
543
|
+
papUpdateRoute,
|
|
544
|
+
papRetrieveRoute,
|
|
545
|
+
papRemoveRoute,
|
|
546
|
+
papQueryRoute,
|
|
547
|
+
pepInterceptRoute,
|
|
548
|
+
papNegotiateRoute,
|
|
549
|
+
papNegotiationStateRoute,
|
|
550
|
+
pnpNegotiationCancelRoute,
|
|
551
|
+
pnapGetRoute,
|
|
552
|
+
pnapSetRoute,
|
|
553
|
+
pnapRemoveRoute,
|
|
554
|
+
pnapQueryRoute
|
|
555
|
+
];
|
|
274
556
|
}
|
|
275
557
|
/**
|
|
276
558
|
* PAP: Create a policy.
|
|
@@ -282,7 +564,6 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
282
564
|
async function papCreate(httpRequestContext, componentName, request) {
|
|
283
565
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
284
566
|
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
285
|
-
core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.nodeIdentity", httpRequestContext.nodeIdentity);
|
|
286
567
|
const component = core.ComponentFactory.get(componentName);
|
|
287
568
|
const policy = request.body;
|
|
288
569
|
const uid = await component.papCreate(policy);
|
|
@@ -305,7 +586,6 @@ async function papUpdate(httpRequestContext, componentName, request) {
|
|
|
305
586
|
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
306
587
|
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
307
588
|
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
308
|
-
core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.nodeIdentity", httpRequestContext.nodeIdentity);
|
|
309
589
|
const component = core.ComponentFactory.get(componentName);
|
|
310
590
|
await component.papUpdate(request.body);
|
|
311
591
|
return {
|
|
@@ -323,7 +603,6 @@ async function papRetrieve(httpRequestContext, componentName, request) {
|
|
|
323
603
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
324
604
|
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
325
605
|
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
326
|
-
core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.nodeIdentity", httpRequestContext.nodeIdentity);
|
|
327
606
|
const component = core.ComponentFactory.get(componentName);
|
|
328
607
|
const policy = await component.papRetrieve(request.pathParams.id);
|
|
329
608
|
return {
|
|
@@ -375,11 +654,132 @@ async function papQuery(httpRequestContext, componentName, request) {
|
|
|
375
654
|
async function pepIntercept(httpRequestContext, componentName, request) {
|
|
376
655
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
377
656
|
const component = core.ComponentFactory.get(componentName);
|
|
378
|
-
const result = await component.pepIntercept(request.body.assetType, request.body.action,
|
|
657
|
+
const result = await component.pepIntercept(request.body.assetType, request.body.action, {
|
|
658
|
+
...(request.body.context ?? {}),
|
|
659
|
+
userIdentity: httpRequestContext.userIdentity,
|
|
660
|
+
nodeIdentity: httpRequestContext.nodeIdentity
|
|
661
|
+
}, request.body.data);
|
|
662
|
+
return {
|
|
663
|
+
body: result
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* PNP: Negotiate.
|
|
668
|
+
* @param httpRequestContext The request context for the API.
|
|
669
|
+
* @param componentName The name of the component to use in the routes.
|
|
670
|
+
* @param request The request.
|
|
671
|
+
* @returns The response object with additional http response properties.
|
|
672
|
+
*/
|
|
673
|
+
async function pnpNegotiate(httpRequestContext, componentName, request) {
|
|
674
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
675
|
+
const component = core.ComponentFactory.get(componentName);
|
|
676
|
+
const result = await component.pnpNegotiate(request.body.assetType, request.body.action, request.body.resourceId, request.body.context, request.body.requesterInformation, request.body.proof);
|
|
379
677
|
return {
|
|
380
678
|
body: result
|
|
381
679
|
};
|
|
382
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* PNP: Negotiation State.
|
|
683
|
+
* @param httpRequestContext The request context for the API.
|
|
684
|
+
* @param componentName The name of the component to use in the routes.
|
|
685
|
+
* @param request The request.
|
|
686
|
+
* @returns The response object with additional http response properties.
|
|
687
|
+
*/
|
|
688
|
+
async function pnpNegotiationState(httpRequestContext, componentName, request) {
|
|
689
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
690
|
+
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
691
|
+
const component = core.ComponentFactory.get(componentName);
|
|
692
|
+
const result = await component.pnpNegotiationState(request.pathParams.policyId, request.body.nodeIdentity, request.body.proof);
|
|
693
|
+
return {
|
|
694
|
+
body: result
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* PNP: Negotiation Cancel.
|
|
699
|
+
* @param httpRequestContext The request context for the API.
|
|
700
|
+
* @param componentName The name of the component to use in the routes.
|
|
701
|
+
* @param request The request.
|
|
702
|
+
* @returns The response object with additional http response properties.
|
|
703
|
+
*/
|
|
704
|
+
async function pnpNegotiationCancel(httpRequestContext, componentName, request) {
|
|
705
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
706
|
+
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
707
|
+
const component = core.ComponentFactory.get(componentName);
|
|
708
|
+
await component.pnpNegotiationCancel(request.pathParams.policyId, request.body.nodeIdentity, request.body.proof);
|
|
709
|
+
return {
|
|
710
|
+
statusCode: web.HttpStatusCode.noContent
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* PNAP: Get a policy negotiation.
|
|
715
|
+
* @param httpRequestContext The request context for the API.
|
|
716
|
+
* @param componentName The name of the component to use in the routes.
|
|
717
|
+
* @param request The request.
|
|
718
|
+
* @returns The response object with additional http response properties.
|
|
719
|
+
*/
|
|
720
|
+
async function pnapGet(httpRequestContext, componentName, request) {
|
|
721
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
722
|
+
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
723
|
+
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
724
|
+
const component = core.ComponentFactory.get(componentName);
|
|
725
|
+
const negotiation = await component.pnapGet(request.pathParams.policyId);
|
|
726
|
+
return {
|
|
727
|
+
body: negotiation
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* PNAP: Set a policy negotiation.
|
|
732
|
+
* @param httpRequestContext The request context for the API.
|
|
733
|
+
* @param componentName The name of the component to use in the routes.
|
|
734
|
+
* @param request The request.
|
|
735
|
+
* @returns The response object with additional http response properties.
|
|
736
|
+
*/
|
|
737
|
+
async function pnapSet(httpRequestContext, componentName, request) {
|
|
738
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
739
|
+
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
740
|
+
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
741
|
+
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
742
|
+
const component = core.ComponentFactory.get(componentName);
|
|
743
|
+
await component.pnapSet(request.body);
|
|
744
|
+
return {
|
|
745
|
+
statusCode: web.HttpStatusCode.noContent
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* PNAP: Remove a policy negotiation.
|
|
750
|
+
* @param httpRequestContext The request context for the API.
|
|
751
|
+
* @param componentName The name of the component to use in the routes.
|
|
752
|
+
* @param request The request.
|
|
753
|
+
* @returns The response object with additional http response properties.
|
|
754
|
+
*/
|
|
755
|
+
async function pnapRemove(httpRequestContext, componentName, request) {
|
|
756
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
757
|
+
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
758
|
+
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
759
|
+
const component = core.ComponentFactory.get(componentName);
|
|
760
|
+
await component.pnapRemove(request.pathParams.policyId);
|
|
761
|
+
return {
|
|
762
|
+
statusCode: web.HttpStatusCode.noContent
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* PNAP: Query policy negotiations.
|
|
767
|
+
* @param httpRequestContext The request context for the API.
|
|
768
|
+
* @param componentName The name of the component to use in the routes.
|
|
769
|
+
* @param request The request.
|
|
770
|
+
* @returns The response object with additional http response properties.
|
|
771
|
+
*/
|
|
772
|
+
async function pnapQuery(httpRequestContext, componentName, request) {
|
|
773
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
774
|
+
const component = core.ComponentFactory.get(componentName);
|
|
775
|
+
const result = await component.pnapQuery(request.query?.status, request.query?.cursor);
|
|
776
|
+
return {
|
|
777
|
+
body: {
|
|
778
|
+
items: result.items,
|
|
779
|
+
cursor: result.cursor
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}
|
|
383
783
|
|
|
384
784
|
// Copyright 2024 IOTA Stiftung.
|
|
385
785
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -402,6 +802,16 @@ class RightsManagementService {
|
|
|
402
802
|
* @internal
|
|
403
803
|
*/
|
|
404
804
|
_policyEnforcementPointComponent;
|
|
805
|
+
/**
|
|
806
|
+
* The PNP component implementation.
|
|
807
|
+
* @internal
|
|
808
|
+
*/
|
|
809
|
+
_policyNegotiationPointComponent;
|
|
810
|
+
/**
|
|
811
|
+
* The PNAP component implementation.
|
|
812
|
+
* @internal
|
|
813
|
+
*/
|
|
814
|
+
_policyNegotiationAdminPointComponent;
|
|
405
815
|
/**
|
|
406
816
|
* Create a new instance of RightsManagementService.
|
|
407
817
|
* @param options The options for the service.
|
|
@@ -410,6 +820,9 @@ class RightsManagementService {
|
|
|
410
820
|
this._policyAdministrationPointComponent =
|
|
411
821
|
core.ComponentFactory.get(options?.policyAdministrationPointComponentType ?? "policy-administration-point");
|
|
412
822
|
this._policyEnforcementPointComponent = core.ComponentFactory.get(options?.policyEnforcementPointComponentType ?? "policy-enforcement-point");
|
|
823
|
+
this._policyNegotiationPointComponent = core.ComponentFactory.get(options?.policyNegotiationPointComponentType ?? "policy-negotiation-point");
|
|
824
|
+
this._policyNegotiationAdminPointComponent =
|
|
825
|
+
core.ComponentFactory.get(options?.policyNegotiationAdminPointComponentType ?? "policy-negotiation-admin-point");
|
|
413
826
|
}
|
|
414
827
|
/**
|
|
415
828
|
* PAP: Create a new policy with auto-generated UID.
|
|
@@ -498,22 +911,138 @@ class RightsManagementService {
|
|
|
498
911
|
* PEP: Process the data using Policy Decision Point (PDP) and return the manipulated data.
|
|
499
912
|
* @param assetType The type of asset being processed.
|
|
500
913
|
* @param action The action being performed on the asset.
|
|
914
|
+
* @param context The context to use in the decision making.
|
|
501
915
|
* @param data The data to process.
|
|
502
|
-
* @param userIdentity The user identity to use in the decision making.
|
|
503
|
-
* @param nodeIdentity The node identity to use in the decision making.
|
|
504
916
|
* @returns The manipulated data with any policies applied.
|
|
505
917
|
*/
|
|
506
|
-
async pepIntercept(assetType, action,
|
|
918
|
+
async pepIntercept(assetType, action, context, data) {
|
|
507
919
|
core.Guards.stringValue(this.CLASS_NAME, "assetType", assetType);
|
|
508
920
|
core.Guards.stringValue(this.CLASS_NAME, "action", action);
|
|
509
921
|
try {
|
|
510
|
-
const result = await this._policyEnforcementPointComponent.intercept(assetType, action,
|
|
922
|
+
const result = await this._policyEnforcementPointComponent.intercept(assetType, action, context, data);
|
|
511
923
|
return result;
|
|
512
924
|
}
|
|
513
925
|
catch (error) {
|
|
514
926
|
throw new core.GeneralError(this.CLASS_NAME, "pepInterceptFailed", undefined, error);
|
|
515
927
|
}
|
|
516
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* PNP: Negotiates the creation of a policy for the requested resource.
|
|
931
|
+
* @param assetType The type of asset being processed.
|
|
932
|
+
* @param action The action being performed on the asset.
|
|
933
|
+
* @param resourceId The ID of the resource being requested, can be empty if asset type access requested.
|
|
934
|
+
* @param context The context from the requesting node.
|
|
935
|
+
* @param requesterInformation Information provided by the requester to determine if a policy can be created.
|
|
936
|
+
* @param proof The proof provided by the requester to support the policy creation.
|
|
937
|
+
* @returns The state of the policy.
|
|
938
|
+
*/
|
|
939
|
+
async pnpNegotiate(assetType, action, resourceId, context, requesterInformation, proof) {
|
|
940
|
+
core.Guards.stringValue(this.CLASS_NAME, "assetType", assetType);
|
|
941
|
+
core.Guards.stringValue(this.CLASS_NAME, "action", action);
|
|
942
|
+
core.Guards.stringValue(this.CLASS_NAME, "resourceId", resourceId);
|
|
943
|
+
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
944
|
+
try {
|
|
945
|
+
const result = await this._policyNegotiationPointComponent.negotiate(assetType, action, resourceId, context, requesterInformation, proof);
|
|
946
|
+
return result;
|
|
947
|
+
}
|
|
948
|
+
catch (error) {
|
|
949
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiateFailed", undefined, error);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* PNP: Retrieves the current state of a policy.
|
|
954
|
+
* @param policyId The ID of the policy to retrieve the state for.
|
|
955
|
+
* @param nodeIdentity The identity of the node requesting the state.
|
|
956
|
+
* @param proof The proof provided by the requester.
|
|
957
|
+
* @returns The current state of the policy.
|
|
958
|
+
*/
|
|
959
|
+
async pnpNegotiationState(policyId, nodeIdentity, proof) {
|
|
960
|
+
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
961
|
+
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
962
|
+
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
963
|
+
try {
|
|
964
|
+
const result = await this._policyNegotiationPointComponent.negotiationState(policyId, nodeIdentity, proof);
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
catch (error) {
|
|
968
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiationState", undefined, error);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* PNP: Cancels an ongoing negotiation for a resource.
|
|
973
|
+
* @param policyId The ID of the policy to cancel.
|
|
974
|
+
* @param nodeIdentity The identity of the node requesting the cancellation.
|
|
975
|
+
* @param proof The proof provided by the requester.
|
|
976
|
+
* @returns Nothing.
|
|
977
|
+
*/
|
|
978
|
+
async pnpNegotiationCancel(policyId, nodeIdentity, proof) {
|
|
979
|
+
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
980
|
+
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
981
|
+
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
982
|
+
try {
|
|
983
|
+
await this._policyNegotiationPointComponent.negotiationCancel(policyId, nodeIdentity, proof);
|
|
984
|
+
}
|
|
985
|
+
catch (error) {
|
|
986
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiationCancelFailed", undefined, error);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* PNAP: Retrieves a policy negotiation.
|
|
991
|
+
* @param policyId The ID of the policy to retrieve the negotiation for.
|
|
992
|
+
* @returns The policy negotiation.
|
|
993
|
+
*/
|
|
994
|
+
async pnapGet(policyId) {
|
|
995
|
+
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
996
|
+
try {
|
|
997
|
+
return this._policyNegotiationAdminPointComponent.get(policyId);
|
|
998
|
+
}
|
|
999
|
+
catch (error) {
|
|
1000
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnapGetFailed", undefined, error);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* PNAP: Sets a policy negotiation.
|
|
1005
|
+
* @param negotiation The updated policy negotiation.
|
|
1006
|
+
* @returns Nothing.
|
|
1007
|
+
*/
|
|
1008
|
+
async pnapSet(negotiation) {
|
|
1009
|
+
core.Guards.object(this.CLASS_NAME, "negotiation", negotiation);
|
|
1010
|
+
try {
|
|
1011
|
+
return this._policyNegotiationAdminPointComponent.set(negotiation);
|
|
1012
|
+
}
|
|
1013
|
+
catch (error) {
|
|
1014
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnapSetFailed", undefined, error);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* PNAP: Removes a policy negotiation record.
|
|
1019
|
+
* @param policyId The ID of the policy negotiation to remove.
|
|
1020
|
+
* @returns Nothing.
|
|
1021
|
+
*/
|
|
1022
|
+
async pnapRemove(policyId) {
|
|
1023
|
+
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
1024
|
+
try {
|
|
1025
|
+
await this._policyNegotiationAdminPointComponent.remove(policyId);
|
|
1026
|
+
}
|
|
1027
|
+
catch (error) {
|
|
1028
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnapRemoveFailed", undefined, error);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* PNAP: Get a list of the negotiations.
|
|
1033
|
+
* @param status The state of the negotiations to retrieve.
|
|
1034
|
+
* @param cursor The cursor to use for pagination.
|
|
1035
|
+
* @returns A list of negotiations and cursor if there are more entries.
|
|
1036
|
+
*/
|
|
1037
|
+
async pnapQuery(status, cursor) {
|
|
1038
|
+
try {
|
|
1039
|
+
const result = await this._policyNegotiationAdminPointComponent.query(status, cursor);
|
|
1040
|
+
return result;
|
|
1041
|
+
}
|
|
1042
|
+
catch (error) {
|
|
1043
|
+
throw new core.GeneralError(this.CLASS_NAME, "pnapQueryFailed", undefined, error);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
517
1046
|
}
|
|
518
1047
|
|
|
519
1048
|
/**
|
|
@@ -536,5 +1065,12 @@ exports.papRemove = papRemove;
|
|
|
536
1065
|
exports.papRetrieve = papRetrieve;
|
|
537
1066
|
exports.papUpdate = papUpdate;
|
|
538
1067
|
exports.pepIntercept = pepIntercept;
|
|
1068
|
+
exports.pnapGet = pnapGet;
|
|
1069
|
+
exports.pnapQuery = pnapQuery;
|
|
1070
|
+
exports.pnapRemove = pnapRemove;
|
|
1071
|
+
exports.pnapSet = pnapSet;
|
|
1072
|
+
exports.pnpNegotiate = pnpNegotiate;
|
|
1073
|
+
exports.pnpNegotiationCancel = pnpNegotiationCancel;
|
|
1074
|
+
exports.pnpNegotiationState = pnpNegotiationState;
|
|
539
1075
|
exports.restEntryPoints = restEntryPoints;
|
|
540
1076
|
exports.tags = tags;
|