@twin.org/rights-management-service 0.9.1-next.2 → 0.9.1-next.4
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/es/policyAdministrationPointRoutes.js +8 -3
- package/dist/es/policyAdministrationPointRoutes.js.map +1 -1
- package/dist/es/policyNegotiationAdminPointRoutes.js +7 -4
- package/dist/es/policyNegotiationAdminPointRoutes.js.map +1 -1
- package/dist/types/policyAdministrationPointRoutes.d.ts +2 -1
- package/dist/types/policyNegotiationAdminPointRoutes.d.ts +2 -1
- package/docs/changelog.md +44 -0
- package/docs/reference/functions/papCreate.md +7 -1
- package/docs/reference/functions/pnapCreate.md +7 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2025 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { HttpContextIdKeys, HttpHeaderHelper, HttpParameterHelper } from "@twin.org/api-models";
|
|
3
|
+
import { HttpContextIdKeys, HttpHeaderHelper, HttpParameterHelper, HttpUrlHelper } from "@twin.org/api-models";
|
|
4
4
|
import { ContextIdStore } from "@twin.org/context";
|
|
5
5
|
import { Coerce, ComponentFactory, Guards } from "@twin.org/core";
|
|
6
6
|
import { POLICY_METADATA_CONTEXT } from "@twin.org/rights-management-models";
|
|
@@ -44,7 +44,7 @@ export function generateRestRoutesPolicyAdministrationPoint(baseRouteName, compo
|
|
|
44
44
|
tag: papTags[0].name,
|
|
45
45
|
method: "POST",
|
|
46
46
|
path: `${baseRouteName}/policy/admin`,
|
|
47
|
-
handler: async (httpRequestContext, request) => papCreate(httpRequestContext, componentName, request),
|
|
47
|
+
handler: async (httpRequestContext, request) => papCreate(httpRequestContext, componentName, request, baseRouteName),
|
|
48
48
|
requestType: {
|
|
49
49
|
type: "IPapCreateRequest",
|
|
50
50
|
examples: [
|
|
@@ -394,14 +394,19 @@ export function generateRestRoutesPolicyAdministrationPoint(baseRouteName, compo
|
|
|
394
394
|
* @param httpRequestContext The request context for the API.
|
|
395
395
|
* @param componentName The name of the component to use in the routes.
|
|
396
396
|
* @param request The request.
|
|
397
|
+
* @param baseRouteName The base route name to use for generating the location header.
|
|
397
398
|
* @returns The response object with additional http response properties.
|
|
398
399
|
*/
|
|
399
|
-
export async function papCreate(httpRequestContext, componentName, request) {
|
|
400
|
+
export async function papCreate(httpRequestContext, componentName, request, baseRouteName) {
|
|
400
401
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
401
402
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
402
403
|
const component = ComponentFactory.get(componentName);
|
|
403
404
|
const policy = request.body;
|
|
404
405
|
const uid = await component.create(policy);
|
|
406
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
407
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
408
|
+
const headers = {};
|
|
409
|
+
HttpHeaderHelper.buildId(headers, uid, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/policy/admin/:id`));
|
|
405
410
|
return {
|
|
406
411
|
statusCode: HttpStatusCode.created,
|
|
407
412
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policyAdministrationPointRoutes.js","sourceRoot":"","sources":["../../src/policyAdministrationPointRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EAMnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EACN,uBAAuB,EAevB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAwB,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,e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\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpParameterHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tPOLICY_METADATA_CONTEXT,\n\ttype IPapCreateRequest,\n\ttype IPapGetAgreementRequest,\n\ttype IPapGetAgreementResponse,\n\ttype IPapGetOfferRequest,\n\ttype IPapGetOfferResponse,\n\ttype IPapGetRequest,\n\ttype IPapGetResponse,\n\ttype IPapGetSetRequest,\n\ttype IPapGetSetResponse,\n\ttype IPapQueryRequest,\n\ttype IPapQueryResponse,\n\ttype IPapRemoveRequest,\n\ttype IPapUpdateRequest,\n\ttype IPolicyAdministrationPointComponent\n} from \"@twin.org/rights-management-models\";\nimport { OdrlContexts, OdrlPolicyType, type OdrlContextType } from \"@twin.org/standards-w3c-odrl\";\nimport { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"policyAdministrationPointRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const papTags: ITag[] = [\n\t{\n\t\tname: \"Policy Administration Point\",\n\t\tdescription: \"Endpoints for managing ODRL policies in the Policy Administration Point\"\n\t}\n];\n\n/**\n * Example JSON-LD context returned by PAP read endpoints for policies with metadata timestamps.\n * Uses `POLICY_METADATA_CONTEXT` from rights-management-models merged with ODRL context.\n */\nconst PAP_POLICY_RESPONSE_CONTEXT: OdrlContextType = [\n\tOdrlContexts.Context,\n\tPOLICY_METADATA_CONTEXT\n];\n\n/**\n * The REST routes for the Policy Administration Point.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesPolicyAdministrationPoint(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst papPolicyExampleLifecycle = {\n\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\tdateModified: \"2025-09-03T00:00:00.000Z\"\n\t};\n\n\tconst papCreateRoute: IRestRoute<IPapCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"papCreate\",\n\t\tsummary: \"Create a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/policy/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\"@context\": OdrlContexts.Context,\n\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: 201,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\tlocation: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papUpdateRoute: IRestRoute<IPapUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"papUpdate\",\n\t\tsummary: \"Update a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapUpdate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papUpdateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\"@context\": OdrlContexts.Context,\n\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/2\",\n\t\t\t\t\t\t\t\t\taction: \"read\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetRoute: IRestRoute<IPapGetRequest, IPapGetResponse> = {\n\t\toperationId: \"papGet\",\n\t\tsummary: \"Get a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetAgreementRoute: IRestRoute<IPapGetAgreementRequest, IPapGetAgreementResponse> = {\n\t\toperationId: \"papGetAgreement\",\n\t\tsummary: \"Get a policy agreement\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/agreement/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetAgreement(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetAgreementRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetAgreementRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetAgreementResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Agreement,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetOfferRoute: IRestRoute<IPapGetOfferRequest, IPapGetOfferResponse> = {\n\t\toperationId: \"papGetOffer\",\n\t\tsummary: \"Get a policy offer\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/offer/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetOffer(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetOfferRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetOfferRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetOfferResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Offer,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetSetRoute: IRestRoute<IPapGetSetRequest, IPapGetSetResponse> = {\n\t\toperationId: \"papGetSet\",\n\t\tsummary: \"Get a policy set\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/set/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetSetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetSetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetSetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papRemoveRoute: IRestRoute<IPapRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"papRemove\",\n\t\tsummary: \"Remove a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papQueryRoute: IRestRoute<IPapQueryRequest, IPapQueryResponse> = {\n\t\toperationId: \"papQuery\",\n\t\tsummary: \"Query policies\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papQueryRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tcursor: \"optional-pagination-cursor\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papQueryResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tpapCreateRoute,\n\t\tpapUpdateRoute,\n\t\tpapGetRoute,\n\t\tpapGetAgreementRoute,\n\t\tpapGetOfferRoute,\n\t\tpapGetSetRoute,\n\t\tpapRemoveRoute,\n\t\tpapQueryRoute\n\t];\n}\n\n/**\n * PAP: Create a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IPapCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\n\tconst policy = request.body;\n\tconst uid = await component.create(policy);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\tlocation: uid\n\t\t}\n\t};\n}\n\n/**\n * PAP: Update a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tawait component.update(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PAP: Get a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetRequest\n): Promise<IPapGetResponse> {\n\tGuards.object<IPapGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.get(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get a agreement.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetAgreement(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetAgreementRequest\n): Promise<IPapGetAgreementResponse> {\n\tGuards.object<IPapGetAgreementRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetAgreementRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getAgreement(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get an offer.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetOffer(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetOfferRequest\n): Promise<IPapGetOfferResponse> {\n\tGuards.object<IPapGetOfferRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetOfferRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getOffer(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get a set.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetSetRequest\n): Promise<IPapGetSetResponse> {\n\tGuards.object<IPapGetSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetSetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getSet(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Remove a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPapRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PAP: Query policies.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapQueryRequest\n): Promise<IPapQueryResponse> {\n\tGuards.object<IPapQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst result = await component.query(\n\t\t{\n\t\t\tassigner: request.query?.assigner,\n\t\t\tassignee: request.query?.assignee,\n\t\t\ttarget: request.query?.target,\n\t\t\taction: request.query?.action\n\t\t},\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\trequest.query?.cursor,\n\t\tCoerce.integer(request.query?.limit)\n\t);\n\n\tconst headers: IPapQueryResponse[\"headers\"] = {};\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tHttpHeaderHelper.buildCursor(\n\t\theaders,\n\t\thttpRequestContext.serverRequest.url,\n\t\tcontextIds?.[HttpContextIdKeys.PublicOrigin],\n\t\tresult.cursor\n\t);\n\n\treturn {\n\t\theaders,\n\t\tbody: result.policies\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"policyAdministrationPointRoutes.js","sourceRoot":"","sources":["../../src/policyAdministrationPointRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EAMb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,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AAE,UAAU,CAAC,EAC/D,OAAO,CAAC,KAAK,EAAE,MAAM,EACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,MAAM,OAAO,GAAiC,EAAE,CAAC;IAEjD,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;IACxD,gBAAgB,CAAC,WAAW,CAC3B,OAAO,EACP,kBAAkB,CAAC,aAAa,CAAC,GAAG,EACpC,UAAU,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAC5C,MAAM,CAAC,MAAM,CACb,CAAC;IAEF,OAAO;QACN,OAAO;QACP,IAAI,EAAE,MAAM,CAAC,QAAQ;KACrB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpParameterHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tPOLICY_METADATA_CONTEXT,\n\ttype IPapCreateRequest,\n\ttype IPapGetAgreementRequest,\n\ttype IPapGetAgreementResponse,\n\ttype IPapGetOfferRequest,\n\ttype IPapGetOfferResponse,\n\ttype IPapGetRequest,\n\ttype IPapGetResponse,\n\ttype IPapGetSetRequest,\n\ttype IPapGetSetResponse,\n\ttype IPapQueryRequest,\n\ttype IPapQueryResponse,\n\ttype IPapRemoveRequest,\n\ttype IPapUpdateRequest,\n\ttype IPolicyAdministrationPointComponent\n} from \"@twin.org/rights-management-models\";\nimport { OdrlContexts, OdrlPolicyType, type OdrlContextType } from \"@twin.org/standards-w3c-odrl\";\nimport { HttpStatusCode, type IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"policyAdministrationPointRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const papTags: ITag[] = [\n\t{\n\t\tname: \"Policy Administration Point\",\n\t\tdescription: \"Endpoints for managing ODRL policies in the Policy Administration Point\"\n\t}\n];\n\n/**\n * Example JSON-LD context returned by PAP read endpoints for policies with metadata timestamps.\n * Uses `POLICY_METADATA_CONTEXT` from rights-management-models merged with ODRL context.\n */\nconst PAP_POLICY_RESPONSE_CONTEXT: OdrlContextType = [\n\tOdrlContexts.Context,\n\tPOLICY_METADATA_CONTEXT\n];\n\n/**\n * The REST routes for the Policy Administration Point.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesPolicyAdministrationPoint(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst papPolicyExampleLifecycle = {\n\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\tdateModified: \"2025-09-03T00:00:00.000Z\"\n\t};\n\n\tconst papCreateRoute: IRestRoute<IPapCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"papCreate\",\n\t\tsummary: \"Create a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/policy/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapCreate(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\"@context\": OdrlContexts.Context,\n\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: 201,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\tlocation: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papUpdateRoute: IRestRoute<IPapUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"papUpdate\",\n\t\tsummary: \"Update a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapUpdate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papUpdateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\"@context\": OdrlContexts.Context,\n\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/2\",\n\t\t\t\t\t\t\t\t\taction: \"read\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetRoute: IRestRoute<IPapGetRequest, IPapGetResponse> = {\n\t\toperationId: \"papGet\",\n\t\tsummary: \"Get a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetAgreementRoute: IRestRoute<IPapGetAgreementRequest, IPapGetAgreementResponse> = {\n\t\toperationId: \"papGetAgreement\",\n\t\tsummary: \"Get a policy agreement\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/agreement/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetAgreement(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetAgreementRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetAgreementRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetAgreementResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Agreement,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetOfferRoute: IRestRoute<IPapGetOfferRequest, IPapGetOfferResponse> = {\n\t\toperationId: \"papGetOffer\",\n\t\tsummary: \"Get a policy offer\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/offer/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetOffer(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetOfferRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetOfferRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetOfferResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Offer,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papGetSetRoute: IRestRoute<IPapGetSetRequest, IPapGetSetResponse> = {\n\t\toperationId: \"papGetSet\",\n\t\tsummary: \"Get a policy set\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin/set/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapGetSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapGetSetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papGetSetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapGetSetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tassignee: \"did:example:receiver\",\n\t\t\t\t\t\t\t\tassigner: \"did:example:sender\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papRemoveRoute: IRestRoute<IPapRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"papRemove\",\n\t\tsummary: \"Remove a policy\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/policy/admin/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"urn:rights-management:abc123def456\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst papQueryRoute: IRestRoute<IPapQueryRequest, IPapQueryResponse> = {\n\t\toperationId: \"papQuery\",\n\t\tsummary: \"Query policies\",\n\t\ttag: papTags[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpapQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPapQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"papQueryRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tcursor: \"optional-pagination-cursor\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPapQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"papQueryResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"@context\": PAP_POLICY_RESPONSE_CONTEXT,\n\t\t\t\t\t\t\t\t\t\"@type\": OdrlPolicyType.Set,\n\t\t\t\t\t\t\t\t\t\"@id\": \"urn:rights-management:abc123def456\",\n\t\t\t\t\t\t\t\t\t...papPolicyExampleLifecycle,\n\t\t\t\t\t\t\t\t\tpermission: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttarget: \"http://example.com/asset/1\",\n\t\t\t\t\t\t\t\t\t\t\taction: \"use\"\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tpapCreateRoute,\n\t\tpapUpdateRoute,\n\t\tpapGetRoute,\n\t\tpapGetAgreementRoute,\n\t\tpapGetOfferRoute,\n\t\tpapGetSetRoute,\n\t\tpapRemoveRoute,\n\t\tpapQueryRoute\n\t];\n}\n\n/**\n * PAP: Create a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name to use for generating the location header.\n * @returns The response object with additional http response properties.\n */\nexport async function papCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<IPapCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\n\tconst policy = request.body;\n\tconst uid = await component.create(policy);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\tuid,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/policy/admin/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\tlocation: uid\n\t\t}\n\t};\n}\n\n/**\n * PAP: Update a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tawait component.update(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PAP: Get a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetRequest\n): Promise<IPapGetResponse> {\n\tGuards.object<IPapGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.get(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get a agreement.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetAgreement(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetAgreementRequest\n): Promise<IPapGetAgreementResponse> {\n\tGuards.object<IPapGetAgreementRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetAgreementRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getAgreement(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get an offer.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetOffer(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetOfferRequest\n): Promise<IPapGetOfferResponse> {\n\tGuards.object<IPapGetOfferRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetOfferRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getOffer(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Get a set.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papGetSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapGetSetRequest\n): Promise<IPapGetSetResponse> {\n\tGuards.object<IPapGetSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapGetSetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst policy = await component.getSet(request.pathParams.id);\n\n\treturn {\n\t\tbody: policy\n\t};\n}\n\n/**\n * PAP: Remove a policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPapRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPapRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PAP: Query policies.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function papQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPapQueryRequest\n): Promise<IPapQueryResponse> {\n\tGuards.object<IPapQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IPolicyAdministrationPointComponent>(componentName);\n\tconst result = await component.query(\n\t\t{\n\t\t\tassigner: request.query?.assigner,\n\t\t\tassignee: request.query?.assignee,\n\t\t\ttarget: request.query?.target,\n\t\t\taction: request.query?.action\n\t\t},\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\trequest.query?.cursor,\n\t\tCoerce.integer(request.query?.limit)\n\t);\n\n\tconst headers: IPapQueryResponse[\"headers\"] = {};\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tHttpHeaderHelper.buildCursor(\n\t\theaders,\n\t\thttpRequestContext.serverRequest.url,\n\t\tcontextIds?.[HttpContextIdKeys.PublicOrigin],\n\t\tresult.cursor\n\t);\n\n\treturn {\n\t\theaders,\n\t\tbody: result.policies\n\t};\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2025 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { HttpContextIdKeys, HttpHeaderHelper } from "@twin.org/api-models";
|
|
3
|
+
import { HttpContextIdKeys, HttpHeaderHelper, HttpUrlHelper } from "@twin.org/api-models";
|
|
4
4
|
import { ContextIdStore } from "@twin.org/context";
|
|
5
5
|
import { ComponentFactory, Guards } from "@twin.org/core";
|
|
6
6
|
import { DataspaceProtocolContractNegotiationStateType } from "@twin.org/standards-dataspace-protocol";
|
|
@@ -31,7 +31,7 @@ export function generateRestRoutesPolicyNegotiationAdminPoint(baseRouteName, com
|
|
|
31
31
|
tag: pnapTags[0].name,
|
|
32
32
|
method: HttpMethod.POST,
|
|
33
33
|
path: `${baseRouteName}/negotiations/admin`,
|
|
34
|
-
handler: async (httpRequestContext, request) => pnapCreate(httpRequestContext, componentName, request),
|
|
34
|
+
handler: async (httpRequestContext, request) => pnapCreate(httpRequestContext, componentName, request, baseRouteName),
|
|
35
35
|
requestType: {
|
|
36
36
|
type: "IPnapCreateRequest",
|
|
37
37
|
examples: [
|
|
@@ -197,15 +197,18 @@ export function generateRestRoutesPolicyNegotiationAdminPoint(baseRouteName, com
|
|
|
197
197
|
* @param httpRequestContext The request context for the API.
|
|
198
198
|
* @param componentName The name of the component to use in the routes.
|
|
199
199
|
* @param request The request.
|
|
200
|
+
* @param baseRouteName The base route name to use for the Location header.
|
|
200
201
|
* @returns The response object with additional http response properties.
|
|
201
202
|
*/
|
|
202
|
-
export async function pnapCreate(httpRequestContext, componentName, request) {
|
|
203
|
+
export async function pnapCreate(httpRequestContext, componentName, request, baseRouteName) {
|
|
203
204
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
204
205
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
205
206
|
const component = ComponentFactory.get(componentName);
|
|
206
207
|
const id = await component.create(request.body.id);
|
|
208
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
209
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
207
210
|
const headers = {};
|
|
208
|
-
HttpHeaderHelper.buildId(headers, id);
|
|
211
|
+
HttpHeaderHelper.buildId(headers, id, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/negotiations/admin/:id`));
|
|
209
212
|
return {
|
|
210
213
|
statusCode: HttpStatusCode.created,
|
|
211
214
|
headers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policyNegotiationAdminPointRoutes.js","sourceRoot":"","sources":["../../src/policyNegotiationAdminPointRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAMhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY1D,OAAO,EAAE,6CAA6C,EAAE,MAAM,wCAAwC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AAM,CAAC,aAAa,wBAA8B,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,CAAC,WAAW,CACjB,aAAa,iCAEb,OAAO,CAAC,UAAU,CAAC,QAAQ,CAC3B,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAwC,aAAa,CAAC,CAAC;IAC7F,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpD,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,kBAAuC,EACvC,aAAqB,EACrB,OAA0B;IAE1B,MAAM,CAAC,MAAM,CAAoB,aAAa,aAAmB,OAAO,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAwC,aAAa,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAElF,MAAM,OAAO,GAAkC,EAAE,CAAC;IAElD,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;IACxD,gBAAgB,CAAC,WAAW,CAC3B,OAAO,EACP,kBAAkB,CAAC,aAAa,CAAC,GAAG,EACpC,UAAU,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAC5C,MAAM,CAAC,MAAM,CACb,CAAC;IAEF,OAAO;QACN,OAAO;QACP,IAAI,EAAE,MAAM,CAAC,KAAK;KAClB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tIPnapCreateRequest,\n\tIPnapGetRequest,\n\tIPnapGetResponse,\n\tIPnapQueryRequest,\n\tIPnapQueryResponse,\n\tIPnapRemoveRequest,\n\tIPnapSetRequest,\n\tIPolicyNegotiationAdminPointComponent\n} from \"@twin.org/rights-management-models\";\nimport { DataspaceProtocolContractNegotiationStateType } from \"@twin.org/standards-dataspace-protocol\";\nimport { HeaderTypes, HttpMethod, HttpStatusCode, type IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"policyNegotiationAdminPointRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const pnapTags: ITag[] = [\n\t{\n\t\tname: \"Policy Negotiation Administration Point\",\n\t\tdescription:\n\t\t\t\"Endpoints for managing ODRL policies in the Policy Negotiation Administration Point\"\n\t}\n];\n\n/**\n * The REST routes for the Policy Negotiation Administration Point.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesPolicyNegotiationAdminPoint(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst pnapCreateRoute: IRestRoute<IPnapCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"pnapCreate\",\n\t\tsummary: \"Pre-register a consumer-side policy negotiation entry\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.POST,\n\t\tpath: `${baseRouteName}/negotiations/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"urn:contract-negotiation:consumer-pid\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: 201,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]:\n\t\t\t\t\t\t\t\t\t\"urn:contract-negotiation:01970000-0000-7000-8000-000000000000\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst pnapGetRoute: IRestRoute<IPnapGetRequest, IPnapGetResponse> = {\n\t\toperationId: \"pnapGet\",\n\t\tsummary: \"Get a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.GET,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPnapGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst pnapSetRoute: IRestRoute<IPnapSetRequest, INoContentResponse> = {\n\t\toperationId: \"pnapSet\",\n\t\tsummary: \"Set a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.PUT,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapSetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapSetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" },\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [{ type: nameof<INoContentResponse>() }]\n\t};\n\n\tconst pnapRemoveRoute: IRestRoute<IPnapRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"pnapRemove\",\n\t\tsummary: \"Remove a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.DELETE,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [{ type: nameof<INoContentResponse>() }]\n\t};\n\n\tconst pnapQueryRoute: IRestRoute<IPnapQueryRequest, IPnapQueryResponse> = {\n\t\toperationId: \"pnapQuery\",\n\t\tsummary: \"Query policy negotiations\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.GET,\n\t\tpath: `${baseRouteName}/negotiations/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapQueryRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.ACCEPTED,\n\t\t\t\t\t\t\tcursor: \"next-cursor\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPnapQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapQueryResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [pnapCreateRoute, pnapGetRoute, pnapSetRoute, pnapRemoveRoute, pnapQueryRoute];\n}\n\n/**\n * PNAP: Pre-register a consumer-side policy negotiation entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IPnapCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPnapCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst id = await component.create(request.body.id);\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(headers, id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * PNAP: Get a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapGetRequest\n): Promise<IPnapGetResponse> {\n\tGuards.object<IPnapGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst negotiation = await component.get(request.pathParams.policyId);\n\n\treturn {\n\t\tbody: negotiation\n\t};\n}\n\n/**\n * PNAP: Set a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapSetRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPnapSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tawait component.set(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PNAP: Remove a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPnapRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tawait component.remove(request.pathParams.policyId);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PNAP: Query policy negotiations.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapQueryRequest\n): Promise<IPnapQueryResponse> {\n\tGuards.object<IPnapQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst result = await component.query(request.query?.state, request.query?.cursor);\n\n\tconst headers: IPnapQueryResponse[\"headers\"] = {};\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tHttpHeaderHelper.buildCursor(\n\t\theaders,\n\t\thttpRequestContext.serverRequest.url,\n\t\tcontextIds?.[HttpContextIdKeys.PublicOrigin],\n\t\tresult.cursor\n\t);\n\n\treturn {\n\t\theaders,\n\t\tbody: result.items\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"policyNegotiationAdminPointRoutes.js","sourceRoot":"","sources":["../../src/policyNegotiationAdminPointRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAMb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY1D,OAAO,EAAE,6CAA6C,EAAE,MAAM,wCAAwC,CAAC;AACvG,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAE3F;;GAEG;AACH,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAW;IAC/B;QACC,IAAI,EAAE,yCAAyC;QAC/C,WAAW,EACV,qFAAqF;KACtF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,6CAA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CAAC,WAAW,CACjB,aAAa,iCAEb,OAAO,CAAC,UAAU,CAAC,QAAQ,CAC3B,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAwC,aAAa,CAAC,CAAC;IAC7F,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpD,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,kBAAuC,EACvC,aAAqB,EACrB,OAA0B;IAE1B,MAAM,CAAC,MAAM,CAAoB,aAAa,aAAmB,OAAO,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAwC,aAAa,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAElF,MAAM,OAAO,GAAkC,EAAE,CAAC;IAElD,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;IACxD,gBAAgB,CAAC,WAAW,CAC3B,OAAO,EACP,kBAAkB,CAAC,aAAa,CAAC,GAAG,EACpC,UAAU,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAC5C,MAAM,CAAC,MAAM,CACb,CAAC;IAEF,OAAO;QACN,OAAO;QACP,IAAI,EAAE,MAAM,CAAC,KAAK;KAClB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tIPnapCreateRequest,\n\tIPnapGetRequest,\n\tIPnapGetResponse,\n\tIPnapQueryRequest,\n\tIPnapQueryResponse,\n\tIPnapRemoveRequest,\n\tIPnapSetRequest,\n\tIPolicyNegotiationAdminPointComponent\n} from \"@twin.org/rights-management-models\";\nimport { DataspaceProtocolContractNegotiationStateType } from \"@twin.org/standards-dataspace-protocol\";\nimport { HeaderTypes, HttpMethod, HttpStatusCode, type IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"policyNegotiationAdminPointRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const pnapTags: ITag[] = [\n\t{\n\t\tname: \"Policy Negotiation Administration Point\",\n\t\tdescription:\n\t\t\t\"Endpoints for managing ODRL policies in the Policy Negotiation Administration Point\"\n\t}\n];\n\n/**\n * The REST routes for the Policy Negotiation Administration Point.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesPolicyNegotiationAdminPoint(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst pnapCreateRoute: IRestRoute<IPnapCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"pnapCreate\",\n\t\tsummary: \"Pre-register a consumer-side policy negotiation entry\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.POST,\n\t\tpath: `${baseRouteName}/negotiations/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapCreate(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"urn:contract-negotiation:consumer-pid\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: 201,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]:\n\t\t\t\t\t\t\t\t\t\"urn:contract-negotiation:01970000-0000-7000-8000-000000000000\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst pnapGetRoute: IRestRoute<IPnapGetRequest, IPnapGetResponse> = {\n\t\toperationId: \"pnapGet\",\n\t\tsummary: \"Get a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.GET,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPnapGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst pnapSetRoute: IRestRoute<IPnapSetRequest, INoContentResponse> = {\n\t\toperationId: \"pnapSet\",\n\t\tsummary: \"Set a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.PUT,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapSetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapSetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" },\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [{ type: nameof<INoContentResponse>() }]\n\t};\n\n\tconst pnapRemoveRoute: IRestRoute<IPnapRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"pnapRemove\",\n\t\tsummary: \"Remove a policy negotiation\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.DELETE,\n\t\tpath: `${baseRouteName}/negotiations/admin/:policyId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: { policyId: \"policy-1\" }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [{ type: nameof<INoContentResponse>() }]\n\t};\n\n\tconst pnapQueryRoute: IRestRoute<IPnapQueryRequest, IPnapQueryResponse> = {\n\t\toperationId: \"pnapQuery\",\n\t\tsummary: \"Query policy negotiations\",\n\t\ttag: pnapTags[0].name,\n\t\tmethod: HttpMethod.GET,\n\t\tpath: `${baseRouteName}/negotiations/admin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tpnapQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IPnapQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"pnapQueryRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.ACCEPTED,\n\t\t\t\t\t\t\tcursor: \"next-cursor\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IPnapQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"pnapQueryResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"pid\",\n\t\t\t\t\t\t\t\t\tcorrelationId: \"cid\",\n\t\t\t\t\t\t\t\t\tdateCreated: \"2025-09-03T00:00:00.000Z\",\n\t\t\t\t\t\t\t\t\tstate: DataspaceProtocolContractNegotiationStateType.REQUESTED,\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:iota:123456789abcdefghi\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [pnapCreateRoute, pnapGetRoute, pnapSetRoute, pnapRemoveRoute, pnapQueryRoute];\n}\n\n/**\n * PNAP: Pre-register a consumer-side policy negotiation entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name to use for the Location header.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<IPnapCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IPnapCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst id = await component.create(request.body.id);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\tid,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/negotiations/admin/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * PNAP: Get a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapGetRequest\n): Promise<IPnapGetResponse> {\n\tGuards.object<IPnapGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst negotiation = await component.get(request.pathParams.policyId);\n\n\treturn {\n\t\tbody: negotiation\n\t};\n}\n\n/**\n * PNAP: Set a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapSetRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPnapSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tawait component.set(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PNAP: Remove a policy negotiation.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IPnapRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.pathParams), request.pathParams);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.policyId),\n\t\trequest.pathParams.policyId\n\t);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tawait component.remove(request.pathParams.policyId);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * PNAP: Query policy negotiations.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function pnapQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IPnapQueryRequest\n): Promise<IPnapQueryResponse> {\n\tGuards.object<IPnapQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IPolicyNegotiationAdminPointComponent>(componentName);\n\tconst result = await component.query(request.query?.state, request.query?.cursor);\n\n\tconst headers: IPnapQueryResponse[\"headers\"] = {};\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tHttpHeaderHelper.buildCursor(\n\t\theaders,\n\t\thttpRequestContext.serverRequest.url,\n\t\tcontextIds?.[HttpContextIdKeys.PublicOrigin],\n\t\tresult.cursor\n\t);\n\n\treturn {\n\t\theaders,\n\t\tbody: result.items\n\t};\n}\n"]}
|
|
@@ -16,9 +16,10 @@ export declare function generateRestRoutesPolicyAdministrationPoint(baseRouteNam
|
|
|
16
16
|
* @param httpRequestContext The request context for the API.
|
|
17
17
|
* @param componentName The name of the component to use in the routes.
|
|
18
18
|
* @param request The request.
|
|
19
|
+
* @param baseRouteName The base route name to use for generating the location header.
|
|
19
20
|
* @returns The response object with additional http response properties.
|
|
20
21
|
*/
|
|
21
|
-
export declare function papCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IPapCreateRequest): Promise<ICreatedResponse>;
|
|
22
|
+
export declare function papCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IPapCreateRequest, baseRouteName: string): Promise<ICreatedResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* PAP: Update a policy.
|
|
24
25
|
* @param httpRequestContext The request context for the API.
|
|
@@ -16,9 +16,10 @@ export declare function generateRestRoutesPolicyNegotiationAdminPoint(baseRouteN
|
|
|
16
16
|
* @param httpRequestContext The request context for the API.
|
|
17
17
|
* @param componentName The name of the component to use in the routes.
|
|
18
18
|
* @param request The request.
|
|
19
|
+
* @param baseRouteName The base route name to use for the Location header.
|
|
19
20
|
* @returns The response object with additional http response properties.
|
|
20
21
|
*/
|
|
21
|
-
export declare function pnapCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IPnapCreateRequest): Promise<ICreatedResponse>;
|
|
22
|
+
export declare function pnapCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IPnapCreateRequest, baseRouteName: string): Promise<ICreatedResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* PNAP: Get a policy negotiation.
|
|
24
25
|
* @param httpRequestContext The request context for the API.
|
package/docs/changelog.md
CHANGED
|
@@ -6,6 +6,50 @@
|
|
|
6
6
|
|
|
7
7
|
* remove EcosystemPolicy support from PAP/REST routes and generated API surface for v2.
|
|
8
8
|
|
|
9
|
+
## [0.9.1-next.4](https://github.com/iotaledger/twin-rights-management/compare/rights-management-service-v0.9.1-next.3...rights-management-service-v0.9.1-next.4) (2026-07-02)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Miscellaneous Chores
|
|
13
|
+
|
|
14
|
+
* **rights-management-service:** Synchronize repo versions
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Dependencies
|
|
18
|
+
|
|
19
|
+
* The following workspace dependencies were updated
|
|
20
|
+
* dependencies
|
|
21
|
+
* @twin.org/rights-management-models bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
22
|
+
* devDependencies
|
|
23
|
+
* @twin.org/rights-management-pap-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
24
|
+
* @twin.org/rights-management-pdp-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
25
|
+
* @twin.org/rights-management-pep-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
26
|
+
* @twin.org/rights-management-pip-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
27
|
+
* @twin.org/rights-management-pmp-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
28
|
+
* @twin.org/rights-management-pnp-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
29
|
+
* @twin.org/rights-management-pxp-service bumped from 0.9.1-next.3 to 0.9.1-next.4
|
|
30
|
+
|
|
31
|
+
## [0.9.1-next.3](https://github.com/iotaledger/twin-rights-management/compare/rights-management-service-v0.9.1-next.2...rights-management-service-v0.9.1-next.3) (2026-06-30)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* rest enhancements ([#229](https://github.com/iotaledger/twin-rights-management/issues/229)) ([b48de25](https://github.com/iotaledger/twin-rights-management/commit/b48de25820eddb4cc53020bb2afbd91497d22de5))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/rights-management-models bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
44
|
+
* devDependencies
|
|
45
|
+
* @twin.org/rights-management-pap-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
46
|
+
* @twin.org/rights-management-pdp-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
47
|
+
* @twin.org/rights-management-pep-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
48
|
+
* @twin.org/rights-management-pip-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
49
|
+
* @twin.org/rights-management-pmp-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
50
|
+
* @twin.org/rights-management-pnp-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
51
|
+
* @twin.org/rights-management-pxp-service bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
52
|
+
|
|
9
53
|
## [0.9.1-next.2](https://github.com/iotaledger/twin-rights-management/compare/rights-management-service-v0.9.1-next.1...rights-management-service-v0.9.1-next.2) (2026-06-29)
|
|
10
54
|
|
|
11
55
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function: papCreate()
|
|
2
2
|
|
|
3
|
-
> **papCreate**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ICreatedResponse`\>
|
|
3
|
+
> **papCreate**(`httpRequestContext`, `componentName`, `request`, `baseRouteName`): `Promise`\<`ICreatedResponse`\>
|
|
4
4
|
|
|
5
5
|
PAP: Create a policy.
|
|
6
6
|
|
|
@@ -24,6 +24,12 @@ The name of the component to use in the routes.
|
|
|
24
24
|
|
|
25
25
|
The request.
|
|
26
26
|
|
|
27
|
+
### baseRouteName
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The base route name to use for generating the location header.
|
|
32
|
+
|
|
27
33
|
## Returns
|
|
28
34
|
|
|
29
35
|
`Promise`\<`ICreatedResponse`\>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function: pnapCreate()
|
|
2
2
|
|
|
3
|
-
> **pnapCreate**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ICreatedResponse`\>
|
|
3
|
+
> **pnapCreate**(`httpRequestContext`, `componentName`, `request`, `baseRouteName`): `Promise`\<`ICreatedResponse`\>
|
|
4
4
|
|
|
5
5
|
PNAP: Pre-register a consumer-side policy negotiation entry.
|
|
6
6
|
|
|
@@ -24,6 +24,12 @@ The name of the component to use in the routes.
|
|
|
24
24
|
|
|
25
25
|
The request.
|
|
26
26
|
|
|
27
|
+
### baseRouteName
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The base route name to use for the Location header.
|
|
32
|
+
|
|
27
33
|
## Returns
|
|
28
34
|
|
|
29
35
|
`Promise`\<`ICreatedResponse`\>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/rights-management-service",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.4",
|
|
4
4
|
"description": "Unified rights management service exposing policy and negotiation capabilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@twin.org/data-json-ld": "next",
|
|
25
25
|
"@twin.org/entity": "next",
|
|
26
26
|
"@twin.org/nameof": "next",
|
|
27
|
-
"@twin.org/rights-management-models": "0.9.1-next.
|
|
27
|
+
"@twin.org/rights-management-models": "0.9.1-next.4",
|
|
28
28
|
"@twin.org/standards-dataspace-protocol": "next",
|
|
29
29
|
"@twin.org/standards-w3c-did": "next",
|
|
30
30
|
"@twin.org/standards-w3c-odrl": "next",
|