@twin.org/identity-service 0.0.2-next.9 → 0.0.3-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/es/identityProfileRoutes.js +389 -0
  2. package/dist/es/identityProfileRoutes.js.map +1 -0
  3. package/dist/es/identityProfileService.js +165 -0
  4. package/dist/es/identityProfileService.js.map +1 -0
  5. package/dist/es/identityResolverRoutes.js +87 -0
  6. package/dist/es/identityResolverRoutes.js.map +1 -0
  7. package/dist/es/identityResolverService.js +98 -0
  8. package/dist/es/identityResolverService.js.map +1 -0
  9. package/dist/es/identityRoutes.js +946 -0
  10. package/dist/es/identityRoutes.js.map +1 -0
  11. package/dist/es/identityService.js +391 -0
  12. package/dist/es/identityService.js.map +1 -0
  13. package/dist/es/index.js +15 -0
  14. package/dist/es/index.js.map +1 -0
  15. package/dist/es/models/IIdentityProfileServiceConstructorOptions.js +2 -0
  16. package/dist/es/models/IIdentityProfileServiceConstructorOptions.js.map +1 -0
  17. package/dist/es/models/IIdentityResolverServiceConfig.js +4 -0
  18. package/dist/es/models/IIdentityResolverServiceConfig.js.map +1 -0
  19. package/dist/es/models/IIdentityResolverServiceConstructorOptions.js +2 -0
  20. package/dist/es/models/IIdentityResolverServiceConstructorOptions.js.map +1 -0
  21. package/dist/es/models/IIdentityServiceConfig.js +4 -0
  22. package/dist/es/models/IIdentityServiceConfig.js.map +1 -0
  23. package/dist/es/models/IIdentityServiceConstructorOptions.js +2 -0
  24. package/dist/es/models/IIdentityServiceConstructorOptions.js.map +1 -0
  25. package/dist/es/restEntryPoints.js +24 -0
  26. package/dist/es/restEntryPoints.js.map +1 -0
  27. package/dist/types/identityProfileService.d.ts +6 -1
  28. package/dist/types/identityResolverService.d.ts +6 -1
  29. package/dist/types/identityService.d.ts +6 -1
  30. package/dist/types/index.d.ts +12 -12
  31. package/dist/types/models/IIdentityResolverServiceConstructorOptions.d.ts +1 -1
  32. package/dist/types/models/IIdentityServiceConstructorOptions.d.ts +1 -1
  33. package/docs/changelog.md +66 -0
  34. package/docs/open-api/spec.json +115 -130
  35. package/docs/reference/classes/IdentityProfileService.md +18 -0
  36. package/docs/reference/classes/IdentityResolverService.md +18 -0
  37. package/docs/reference/classes/IdentityService.md +22 -4
  38. package/package.json +7 -8
  39. package/dist/cjs/index.cjs +0 -2071
  40. package/dist/esm/index.mjs +0 -2039
@@ -0,0 +1,389 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { HttpParameterHelper } from "@twin.org/api-models";
4
+ import { ContextIdHelper, ContextIdKeys, ContextIdStore } from "@twin.org/context";
5
+ import { Coerce, ComponentFactory, Guards } from "@twin.org/core";
6
+ import { HeaderTypes, HttpStatusCode, MimeTypes } from "@twin.org/web";
7
+ /**
8
+ * The source used when communicating about these routes.
9
+ */
10
+ const ROUTES_SOURCE = "identityProfileRoutes";
11
+ /**
12
+ * The tag to associate with the routes.
13
+ */
14
+ export const tagsIdentityProfile = [
15
+ {
16
+ name: "Identity Profile",
17
+ description: "Service to provide all features related to digital identity profiles."
18
+ }
19
+ ];
20
+ /**
21
+ * The REST routes for identity.
22
+ * @param baseRouteName Prefix to prepend to the paths.
23
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
24
+ * @returns The generated routes.
25
+ */
26
+ export function generateRestRoutesIdentityProfile(baseRouteName, componentName) {
27
+ const identityProfileCreateRoute = {
28
+ operationId: "identityProfileCreate",
29
+ summary: "Create an identity profile",
30
+ tag: tagsIdentityProfile[0].name,
31
+ method: "POST",
32
+ path: `${baseRouteName}/`,
33
+ handler: async (httpRequestContext, request) => identityProfileCreate(httpRequestContext, componentName, request),
34
+ requestType: {
35
+ type: "IIdentityProfileCreateRequest",
36
+ examples: [
37
+ {
38
+ id: "identityProfileCreateRequestExample",
39
+ request: {
40
+ body: {
41
+ publicProfile: {
42
+ "@context": "https://schema.org",
43
+ "@type": "Person",
44
+ jobTitle: "Professor",
45
+ name: "Jane Doe"
46
+ },
47
+ privateProfile: {
48
+ "@context": "https://schema.org",
49
+ "@type": "Person",
50
+ telephone: "(425) 123-4567",
51
+ url: "http://www.janedoe.com"
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ]
57
+ },
58
+ responseType: [
59
+ {
60
+ type: "INoContentResponse"
61
+ },
62
+ {
63
+ type: "IConflictResponse"
64
+ }
65
+ ]
66
+ };
67
+ const identityProfileGetRoute = {
68
+ operationId: "identityProfileGet",
69
+ summary: "Get the identity profile properties",
70
+ tag: tagsIdentityProfile[0].name,
71
+ method: "GET",
72
+ path: `${baseRouteName}/`,
73
+ handler: async (httpRequestContext, request) => identityGet(httpRequestContext, componentName, request),
74
+ requestType: {
75
+ type: "IIdentityProfileGetRequest",
76
+ examples: [
77
+ {
78
+ id: "identityGetProfileRequestExample",
79
+ request: {
80
+ query: {
81
+ publicPropertyNames: "name,jobTitle"
82
+ }
83
+ }
84
+ }
85
+ ]
86
+ },
87
+ responseType: [
88
+ {
89
+ type: "IIdentityProfileGetResponse",
90
+ examples: [
91
+ {
92
+ id: "identityGetResponseExample",
93
+ response: {
94
+ body: {
95
+ identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
96
+ publicProfile: {
97
+ "@context": "https://schema.org",
98
+ "@type": "Person",
99
+ jobTitle: "Professor",
100
+ name: "Jane Doe"
101
+ }
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ {
108
+ type: "INotFoundResponse"
109
+ }
110
+ ]
111
+ };
112
+ const identityProfileGetPublicRoute = {
113
+ operationId: "identityProfileGetPublic",
114
+ summary: "Get the identity profile public properties",
115
+ tag: tagsIdentityProfile[0].name,
116
+ method: "GET",
117
+ path: `${baseRouteName}/:identity/public`,
118
+ handler: async (httpRequestContext, request) => identityGetPublic(httpRequestContext, componentName, request),
119
+ requestType: {
120
+ type: "IIdentityProfileGetPublicRequest",
121
+ examples: [
122
+ {
123
+ id: "identityGetPublicProfileRequestExample",
124
+ request: {
125
+ pathParams: {
126
+ identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70"
127
+ },
128
+ query: {
129
+ propertyNames: "role,email,name"
130
+ }
131
+ }
132
+ }
133
+ ]
134
+ },
135
+ responseType: [
136
+ {
137
+ type: "IIdentityProfileGetPublicResponse",
138
+ mimeType: MimeTypes.JsonLd,
139
+ examples: [
140
+ {
141
+ id: "identityGetPublicResponseExample",
142
+ response: {
143
+ headers: {
144
+ [HeaderTypes.ContentType]: MimeTypes.JsonLd
145
+ },
146
+ body: {
147
+ "@context": "https://schema.org",
148
+ "@type": "Person",
149
+ jobTitle: "Professor",
150
+ name: "Jane Doe"
151
+ }
152
+ }
153
+ }
154
+ ]
155
+ },
156
+ {
157
+ type: "INotFoundResponse"
158
+ }
159
+ ],
160
+ skipAuth: true
161
+ };
162
+ const identityProfileUpdateRoute = {
163
+ operationId: "identityProfileUpdate",
164
+ summary: "Update an identity profile properties",
165
+ tag: tagsIdentityProfile[0].name,
166
+ method: "PUT",
167
+ path: `${baseRouteName}/`,
168
+ handler: async (httpRequestContext, request) => identityProfileUpdate(httpRequestContext, componentName, request),
169
+ requestType: {
170
+ type: "IIdentityProfileUpdateRequest",
171
+ examples: [
172
+ {
173
+ id: "identityProfileUpdateRequestExample",
174
+ request: {
175
+ body: {
176
+ publicProfile: {
177
+ "@context": "https://schema.org",
178
+ "@type": "Person",
179
+ jobTitle: "Professor",
180
+ name: "Jane Doe"
181
+ },
182
+ privateProfile: {
183
+ "@context": "https://schema.org",
184
+ "@type": "Person",
185
+ telephone: "(425) 123-4567",
186
+ url: "http://www.janedoe.com"
187
+ }
188
+ }
189
+ }
190
+ }
191
+ ]
192
+ },
193
+ responseType: [
194
+ {
195
+ type: "INoContentResponse"
196
+ },
197
+ {
198
+ type: "INotFoundResponse"
199
+ }
200
+ ]
201
+ };
202
+ const identityProfileRemoveRoute = {
203
+ operationId: "identityProfileRemove",
204
+ summary: "Remove an identity profile",
205
+ tag: tagsIdentityProfile[0].name,
206
+ method: "DELETE",
207
+ path: `${baseRouteName}/`,
208
+ handler: async (httpRequestContext, request) => identityProfileRemove(httpRequestContext, componentName, request),
209
+ responseType: [
210
+ {
211
+ type: "INoContentResponse"
212
+ },
213
+ {
214
+ type: "INotFoundResponse"
215
+ }
216
+ ]
217
+ };
218
+ const identityProfileListRoute = {
219
+ operationId: "identitiesProfileList",
220
+ summary: "Get the list of profile data for identities",
221
+ tag: tagsIdentityProfile[0].name,
222
+ method: "GET",
223
+ path: `${baseRouteName}/query/`,
224
+ handler: async (httpRequestContext, request) => identitiesList(httpRequestContext, componentName, request),
225
+ requestType: {
226
+ type: "IIdentityProfileListRequest",
227
+ examples: [
228
+ {
229
+ id: "identityProfileListRequestExample",
230
+ request: {
231
+ query: {}
232
+ }
233
+ },
234
+ {
235
+ id: "identityProfileListRequestFilteredExample",
236
+ request: {
237
+ query: {
238
+ publicFilters: "jobTitle:Professor"
239
+ }
240
+ }
241
+ }
242
+ ]
243
+ },
244
+ responseType: [
245
+ {
246
+ type: "IIdentityProfileListResponse",
247
+ examples: [
248
+ {
249
+ id: "identitiesProfileListResponseExample",
250
+ response: {
251
+ body: {
252
+ items: [
253
+ {
254
+ identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
255
+ publicProfile: {
256
+ "@context": "https://schema.org",
257
+ "@type": "Person",
258
+ jobTitle: "Professor",
259
+ name: "Jane Doe"
260
+ }
261
+ }
262
+ ],
263
+ cursor: "1"
264
+ }
265
+ }
266
+ }
267
+ ]
268
+ }
269
+ ]
270
+ };
271
+ return [
272
+ identityProfileCreateRoute,
273
+ identityProfileGetRoute,
274
+ identityProfileGetPublicRoute,
275
+ identityProfileUpdateRoute,
276
+ identityProfileRemoveRoute,
277
+ identityProfileListRoute
278
+ ];
279
+ }
280
+ /**
281
+ * Create an identity profile.
282
+ * @param httpRequestContext The request context for the API.
283
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
284
+ * @param request The request.
285
+ * @returns The response object with additional http response properties.
286
+ */
287
+ export async function identityProfileCreate(httpRequestContext, componentName, request) {
288
+ Guards.object(ROUTES_SOURCE, "request", request);
289
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
290
+ const contextIds = await ContextIdStore.getContextIds();
291
+ ContextIdHelper.guard(contextIds, ContextIdKeys.User);
292
+ const component = ComponentFactory.get(componentName);
293
+ await component.create(request.body.publicProfile, request.body.privateProfile, contextIds[ContextIdKeys.User]);
294
+ return {
295
+ statusCode: HttpStatusCode.noContent
296
+ };
297
+ }
298
+ /**
299
+ * Get the identity profile.
300
+ * @param httpRequestContext The request context for the API.
301
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
302
+ * @param request The request.
303
+ * @returns The response object with additional http response properties.
304
+ */
305
+ export async function identityGet(httpRequestContext, componentName, request) {
306
+ Guards.object(ROUTES_SOURCE, "request", request);
307
+ const contextIds = await ContextIdStore.getContextIds();
308
+ ContextIdHelper.guard(contextIds, ContextIdKeys.User);
309
+ const component = ComponentFactory.get(componentName);
310
+ const result = await component.get(HttpParameterHelper.arrayFromString(request?.query?.publicPropertyNames), HttpParameterHelper.arrayFromString(request?.query?.privatePropertyNames), contextIds[ContextIdKeys.User]);
311
+ return {
312
+ body: result
313
+ };
314
+ }
315
+ /**
316
+ * Get the identity public profile.
317
+ * @param httpRequestContext The request context for the API.
318
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
319
+ * @param request The request.
320
+ * @returns The response object with additional http response properties.
321
+ */
322
+ export async function identityGetPublic(httpRequestContext, componentName, request) {
323
+ Guards.object(ROUTES_SOURCE, "request", request);
324
+ Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams?.identity);
325
+ const component = ComponentFactory.get(componentName);
326
+ const result = await component.getPublic(request?.pathParams.identity, HttpParameterHelper.arrayFromString(request?.query?.propertyNames));
327
+ return {
328
+ headers: {
329
+ [HeaderTypes.ContentType]: MimeTypes.JsonLd
330
+ },
331
+ body: result
332
+ };
333
+ }
334
+ /**
335
+ * Update an identity profile.
336
+ * @param httpRequestContext The request context for the API.
337
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
338
+ * @param request The request.
339
+ * @returns The response object with additional http response properties.
340
+ */
341
+ export async function identityProfileUpdate(httpRequestContext, componentName, request) {
342
+ Guards.object(ROUTES_SOURCE, "request", request);
343
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
344
+ const contextIds = await ContextIdStore.getContextIds();
345
+ ContextIdHelper.guard(contextIds, ContextIdKeys.User);
346
+ const component = ComponentFactory.get(componentName);
347
+ await component.update(request.body.publicProfile, request.body.privateProfile, contextIds[ContextIdKeys.User]);
348
+ return {
349
+ statusCode: HttpStatusCode.noContent
350
+ };
351
+ }
352
+ /**
353
+ * Remove an identity profile.
354
+ * @param httpRequestContext The request context for the API.
355
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
356
+ * @param request The request.
357
+ * @returns The response object with additional http response properties.
358
+ */
359
+ export async function identityProfileRemove(httpRequestContext, componentName, request) {
360
+ const contextIds = await ContextIdStore.getContextIds();
361
+ ContextIdHelper.guard(contextIds, ContextIdKeys.User);
362
+ const component = ComponentFactory.get(componentName);
363
+ await component.remove(contextIds[ContextIdKeys.User]);
364
+ return {
365
+ statusCode: HttpStatusCode.noContent
366
+ };
367
+ }
368
+ /**
369
+ * Get the list of organizations.
370
+ * @param httpRequestContext The request context for the API.
371
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
372
+ * @param request The request.
373
+ * @returns The response object with additional http response properties.
374
+ */
375
+ export async function identitiesList(httpRequestContext, componentName, request) {
376
+ const component = ComponentFactory.get(componentName);
377
+ const publicFilterPairs = HttpParameterHelper.arrayFromString(request?.query?.publicFilters);
378
+ const publicFilters = publicFilterPairs?.map(pair => {
379
+ const parts = pair.split(":");
380
+ return {
381
+ propertyName: parts[0],
382
+ propertyValue: parts[1]
383
+ };
384
+ });
385
+ return {
386
+ body: await component.list(publicFilters, HttpParameterHelper.arrayFromString(request?.query?.publicPropertyNames), request?.query?.cursor, Coerce.integer(request.query?.limit))
387
+ };
388
+ }
389
+ //# sourceMappingURL=identityProfileRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityProfileRoutes.js","sourceRoot":"","sources":["../../src/identityProfileRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,mBAAmB,EAQnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAclE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvE;;GAEG;AACH,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAW;IAC1C;QACC,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,uEAAuE;KACpF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAChD,aAAqB,EACrB,aAAqB;IAErB,MAAM,0BAA0B,GAC/B;QACC,WAAW,EAAE,uBAAuB;QACpC,OAAO,EAAE,4BAA4B;QACrC,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI;QAChC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,GAAG;QACzB,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,qBAAqB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QAClE,WAAW,EAAE;YACZ,IAAI,iCAAyC;YAC7C,QAAQ,EAAE;gBACT;oBACC,EAAE,E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: Apache-2.0.\nimport {\n\tHttpParameterHelper,\n\ttype IConflictResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentRequest,\n\ttype INoContentResponse,\n\ttype INotFoundResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdHelper, ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport type { IJsonLdDocument } from \"@twin.org/data-json-ld\";\nimport type {\n\tIIdentityProfileComponent,\n\tIIdentityProfileCreateRequest,\n\tIIdentityProfileGetPublicRequest,\n\tIIdentityProfileGetPublicResponse,\n\tIIdentityProfileGetRequest,\n\tIIdentityProfileGetResponse,\n\tIIdentityProfileListRequest,\n\tIIdentityProfileListResponse,\n\tIIdentityProfileUpdateRequest\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"identityProfileRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsIdentityProfile: ITag[] = [\n\t{\n\t\tname: \"Identity Profile\",\n\t\tdescription: \"Service to provide all features related to digital identity profiles.\"\n\t}\n];\n\n/**\n * The REST routes for identity.\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 generateRestRoutesIdentityProfile(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst identityProfileCreateRoute: IRestRoute<IIdentityProfileCreateRequest, INoContentResponse> =\n\t\t{\n\t\t\toperationId: \"identityProfileCreate\",\n\t\t\tsummary: \"Create an identity profile\",\n\t\t\ttag: tagsIdentityProfile[0].name,\n\t\t\tmethod: \"POST\",\n\t\t\tpath: `${baseRouteName}/`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tidentityProfileCreate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IIdentityProfileCreateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"identityProfileCreateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tpublicProfile: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\tjobTitle: \"Professor\",\n\t\t\t\t\t\t\t\t\tname: \"Jane Doe\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tprivateProfile: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\ttelephone: \"(425) 123-4567\",\n\t\t\t\t\t\t\t\t\turl: \"http://www.janedoe.com\"\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\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IConflictResponse>()\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst identityProfileGetRoute: IRestRoute<\n\t\tIIdentityProfileGetRequest,\n\t\tIIdentityProfileGetResponse\n\t> = {\n\t\toperationId: \"identityProfileGet\",\n\t\tsummary: \"Get the identity profile properties\",\n\t\ttag: tagsIdentityProfile[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tidentityGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IIdentityProfileGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"identityGetProfileRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tpublicPropertyNames: \"name,jobTitle\"\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<IIdentityProfileGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"identityGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tidentity:\n\t\t\t\t\t\t\t\t\t\"did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70\",\n\t\t\t\t\t\t\t\tpublicProfile: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\tjobTitle: \"Professor\",\n\t\t\t\t\t\t\t\t\tname: \"Jane Doe\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst identityProfileGetPublicRoute: IRestRoute<\n\t\tIIdentityProfileGetPublicRequest,\n\t\tIIdentityProfileGetPublicResponse\n\t> = {\n\t\toperationId: \"identityProfileGetPublic\",\n\t\tsummary: \"Get the identity profile public properties\",\n\t\ttag: tagsIdentityProfile[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:identity/public`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tidentityGetPublic(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IIdentityProfileGetPublicRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"identityGetPublicProfileRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tidentity:\n\t\t\t\t\t\t\t\t\"did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tpropertyNames: \"role,email,name\"\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<IIdentityProfileGetPublicResponse>(),\n\t\t\t\tmimeType: MimeTypes.JsonLd,\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"identityGetPublicResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.ContentType]: MimeTypes.JsonLd\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\tjobTitle: \"Professor\",\n\t\t\t\t\t\t\t\tname: \"Jane Doe\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t],\n\t\tskipAuth: true\n\t};\n\n\tconst identityProfileUpdateRoute: IRestRoute<IIdentityProfileUpdateRequest, INoContentResponse> =\n\t\t{\n\t\t\toperationId: \"identityProfileUpdate\",\n\t\t\tsummary: \"Update an identity profile properties\",\n\t\t\ttag: tagsIdentityProfile[0].name,\n\t\t\tmethod: \"PUT\",\n\t\t\tpath: `${baseRouteName}/`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tidentityProfileUpdate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IIdentityProfileUpdateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"identityProfileUpdateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tpublicProfile: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\tjobTitle: \"Professor\",\n\t\t\t\t\t\t\t\t\tname: \"Jane Doe\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tprivateProfile: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\ttelephone: \"(425) 123-4567\",\n\t\t\t\t\t\t\t\t\turl: \"http://www.janedoe.com\"\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\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst identityProfileRemoveRoute: IRestRoute<INoContentRequest, INoContentResponse> = {\n\t\toperationId: \"identityProfileRemove\",\n\t\tsummary: \"Remove an identity profile\",\n\t\ttag: tagsIdentityProfile[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tidentityProfileRemove(httpRequestContext, componentName, request),\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst identityProfileListRoute: IRestRoute<\n\t\tIIdentityProfileListRequest,\n\t\tIIdentityProfileListResponse\n\t> = {\n\t\toperationId: \"identitiesProfileList\",\n\t\tsummary: \"Get the list of profile data for identities\",\n\t\ttag: tagsIdentityProfile[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/query/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tidentitiesList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IIdentityProfileListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"identityProfileListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"identityProfileListRequestFilteredExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tpublicFilters: \"jobTitle:Professor\"\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<IIdentityProfileListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"identitiesProfileListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\titems: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tidentity:\n\t\t\t\t\t\t\t\t\t\t\t\"did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70\",\n\t\t\t\t\t\t\t\t\t\tpublicProfile: {\n\t\t\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\t\t\t\t\tjobTitle: \"Professor\",\n\t\t\t\t\t\t\t\t\t\t\tname: \"Jane Doe\"\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\tcursor: \"1\"\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\tidentityProfileCreateRoute,\n\t\tidentityProfileGetRoute,\n\t\tidentityProfileGetPublicRoute,\n\t\tidentityProfileUpdateRoute,\n\t\tidentityProfileRemoveRoute,\n\t\tidentityProfileListRoute\n\t];\n}\n\n/**\n * Create an identity profile.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identityProfileCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IIdentityProfileCreateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IIdentityProfileCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IIdentityProfileCreateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.User);\n\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tawait component.create(\n\t\trequest.body.publicProfile,\n\t\trequest.body.privateProfile,\n\t\tcontextIds[ContextIdKeys.User]\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get the identity profile.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identityGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IIdentityProfileGetRequest\n): Promise<IIdentityProfileGetResponse> {\n\tGuards.object<IIdentityProfileGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.User);\n\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tconst result = await component.get(\n\t\tHttpParameterHelper.arrayFromString<keyof IJsonLdDocument>(request?.query?.publicPropertyNames),\n\t\tHttpParameterHelper.arrayFromString<keyof IJsonLdDocument>(\n\t\t\trequest?.query?.privatePropertyNames\n\t\t),\n\t\tcontextIds[ContextIdKeys.User]\n\t);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get the identity public profile.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identityGetPublic(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IIdentityProfileGetPublicRequest\n): Promise<IIdentityProfileGetPublicResponse> {\n\tGuards.object<IIdentityProfileGetPublicRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams?.identity),\n\t\trequest.pathParams?.identity\n\t);\n\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tconst result = await component.getPublic(\n\t\trequest?.pathParams.identity,\n\t\tHttpParameterHelper.arrayFromString<keyof IJsonLdDocument>(request?.query?.propertyNames)\n\t);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n\n/**\n * Update an identity profile.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identityProfileUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IIdentityProfileUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IIdentityProfileUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tGuards.object<IIdentityProfileUpdateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.User);\n\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tawait component.update(\n\t\trequest.body.publicProfile,\n\t\trequest.body.privateProfile,\n\t\tcontextIds[ContextIdKeys.User]\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove an identity profile.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identityProfileRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: INoContentRequest\n): Promise<INoContentResponse> {\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.User);\n\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tawait component.remove(contextIds[ContextIdKeys.User]);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get the list of organizations.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function identitiesList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IIdentityProfileListRequest\n): Promise<IIdentityProfileListResponse> {\n\tconst component = ComponentFactory.get<IIdentityProfileComponent>(componentName);\n\n\tconst publicFilterPairs = HttpParameterHelper.arrayFromString(request?.query?.publicFilters);\n\tconst publicFilters = publicFilterPairs?.map(pair => {\n\t\tconst parts = pair.split(\":\");\n\t\treturn {\n\t\t\tpropertyName: parts[0],\n\t\t\tpropertyValue: parts[1]\n\t\t};\n\t});\n\n\treturn {\n\t\tbody: await component.list(\n\t\t\tpublicFilters,\n\t\t\tHttpParameterHelper.arrayFromString<keyof IJsonLdDocument>(\n\t\t\t\trequest?.query?.publicPropertyNames\n\t\t\t),\n\t\t\trequest?.query?.cursor,\n\t\t\tCoerce.integer(request.query?.limit)\n\t\t)\n\t};\n}\n"]}
@@ -0,0 +1,165 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError, GeneralError, Guards, Is, NotFoundError } from "@twin.org/core";
4
+ import { IdentityProfileConnectorFactory } from "@twin.org/identity-models";
5
+ import { IdentityService } from "./identityService.js";
6
+ /**
7
+ * Class which implements the identity profile contract.
8
+ */
9
+ export class IdentityProfileService {
10
+ /**
11
+ * Runtime name for the class.
12
+ */
13
+ static CLASS_NAME = "IdentityProfileService";
14
+ /**
15
+ * The identity profile connector.
16
+ * @internal
17
+ */
18
+ _identityProfileConnector;
19
+ /**
20
+ * Create a new instance of IdentityProfileService.
21
+ * @param options The dependencies for the identity profile service.
22
+ */
23
+ constructor(options) {
24
+ this._identityProfileConnector = IdentityProfileConnectorFactory.get(options?.profileEntityConnectorType ?? "identity-profile");
25
+ }
26
+ /**
27
+ * Returns the class name of the component.
28
+ * @returns The class name of the component.
29
+ */
30
+ className() {
31
+ return IdentityService.CLASS_NAME;
32
+ }
33
+ /**
34
+ * Create the profile properties for an identity.
35
+ * @param publicProfile The public profile data as JSON-LD.
36
+ * @param privateProfile The private profile data as JSON-LD.
37
+ * @param identity The identity to perform the profile operation on.
38
+ * @returns Nothing.
39
+ */
40
+ async create(publicProfile, privateProfile, identity) {
41
+ Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
42
+ try {
43
+ await this._identityProfileConnector.create(identity, publicProfile, privateProfile);
44
+ }
45
+ catch (error) {
46
+ if (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
47
+ throw error;
48
+ }
49
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "createFailed", { identity }, error);
50
+ }
51
+ }
52
+ /**
53
+ * Get the profile properties for an identity.
54
+ * @param publicPropertyNames The public properties to get for the profile, defaults to all.
55
+ * @param privatePropertyNames The private properties to get for the profile, defaults to all.
56
+ * @param identity The identity to perform the profile operation on.
57
+ * @returns The items identity and the properties.
58
+ */
59
+ async get(publicPropertyNames, privatePropertyNames, identity) {
60
+ Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
61
+ try {
62
+ const result = await this._identityProfileConnector.get(identity, publicPropertyNames, privatePropertyNames);
63
+ if (Is.undefined(result)) {
64
+ throw new NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
65
+ }
66
+ return {
67
+ identity,
68
+ publicProfile: result.publicProfile,
69
+ privateProfile: result.privateProfile
70
+ };
71
+ }
72
+ catch (error) {
73
+ if (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
74
+ throw error;
75
+ }
76
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "getFailed", undefined, error);
77
+ }
78
+ }
79
+ /**
80
+ * Get the public profile properties for an identity.
81
+ * @param identity The identity to perform the profile operation on.
82
+ * @param propertyNames The properties to get for the item, defaults to all.
83
+ * @returns The items properties.
84
+ */
85
+ async getPublic(identity, propertyNames) {
86
+ Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
87
+ try {
88
+ const result = await this._identityProfileConnector.get(identity, propertyNames);
89
+ if (Is.undefined(result)) {
90
+ throw new NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
91
+ }
92
+ return result.publicProfile;
93
+ }
94
+ catch (error) {
95
+ if (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
96
+ throw error;
97
+ }
98
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "getPublicFailed", undefined, error);
99
+ }
100
+ }
101
+ /**
102
+ * Update the profile properties of an identity.
103
+ * @param publicProfile The public profile data as JSON-LD.
104
+ * @param privateProfile The private profile data as JSON-LD.
105
+ * @param identity The identity to perform the profile operation on.
106
+ * @returns Nothing.
107
+ */
108
+ async update(publicProfile, privateProfile, identity) {
109
+ Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
110
+ try {
111
+ const result = await this._identityProfileConnector.get(identity);
112
+ if (Is.undefined(result)) {
113
+ throw new NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
114
+ }
115
+ await this._identityProfileConnector.update(identity, publicProfile, privateProfile);
116
+ }
117
+ catch (error) {
118
+ if (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
119
+ throw error;
120
+ }
121
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "updateFailed", { identity }, error);
122
+ }
123
+ }
124
+ /**
125
+ * Delete the profile for an identity.
126
+ * @param identity The identity to perform the profile operation on.
127
+ * @returns Nothing.
128
+ */
129
+ async remove(identity) {
130
+ Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
131
+ try {
132
+ const result = await this._identityProfileConnector.get(identity);
133
+ if (Is.undefined(result)) {
134
+ throw new NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
135
+ }
136
+ await this._identityProfileConnector.remove(identity);
137
+ }
138
+ catch (error) {
139
+ if (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
140
+ throw error;
141
+ }
142
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "removeFailed", { identity }, error);
143
+ }
144
+ }
145
+ /**
146
+ * Get a list of the requested types.
147
+ * @param publicFilters The filters to apply to the identities public profiles.
148
+ * @param publicPropertyNames The public properties to get for the profile, defaults to all.
149
+ * @param cursor The cursor for paged requests.
150
+ * @param limit The maximum number of items in a page.
151
+ * @returns The list of items and cursor for paging.
152
+ */
153
+ async list(publicFilters, publicPropertyNames, cursor, limit) {
154
+ try {
155
+ // We don't want to return private profile for this type of query
156
+ // as it would expose the values to the REST api
157
+ const result = await this._identityProfileConnector.list(publicFilters, undefined, publicPropertyNames, undefined, cursor, limit);
158
+ return result;
159
+ }
160
+ catch (error) {
161
+ throw new GeneralError(IdentityProfileService.CLASS_NAME, "listFailed", undefined, error);
162
+ }
163
+ }
164
+ }
165
+ //# sourceMappingURL=identityProfileService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityProfileService.js","sourceRoot":"","sources":["../../src/identityProfileService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpF,OAAO,EACN,+BAA+B,EAG/B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAKlC;;OAEG;IACI,MAAM,CAAU,UAAU,4BAA4C;IAE7E;;;OAGG;IACc,yBAAyB,CAAkC;IAE5E;;;OAGG;IACH,YAAY,OAAmD;QAC9D,IAAI,CAAC,yBAAyB,GAAG,+BAA+B,CAAC,GAAG,CAElE,OAAO,EAAE,0BAA0B,IAAI,kBAAkB,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,eAAe,CAAC,UAAU,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,MAAM,CAAC,aAAiB,EAAE,cAAkB,EAAE,QAAiB;QAC3E,MAAM,CAAC,WAAW,CAAC,sBAAsB,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QAElF,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;QACtF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC,UAAU,CAAC,EAAE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,YAAY,CAAC,sBAAsB,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC3F,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, GeneralError, Guards, Is, NotFoundError } from \"@twin.org/core\";\nimport type { IJsonLdDocument } from \"@twin.org/data-json-ld\";\nimport {\n\tIdentityProfileConnectorFactory,\n\ttype IIdentityProfileComponent,\n\ttype IIdentityProfileConnector\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { IdentityService } from \"./identityService.js\";\nimport type { IIdentityProfileServiceConstructorOptions } from \"./models/IIdentityProfileServiceConstructorOptions.js\";\n\n/**\n * Class which implements the identity profile contract.\n */\nexport class IdentityProfileService<\n\tT extends IJsonLdDocument = IJsonLdDocument,\n\tU extends IJsonLdDocument = IJsonLdDocument\n> implements IIdentityProfileComponent<T, U>\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityProfileService>();\n\n\t/**\n\t * The identity profile connector.\n\t * @internal\n\t */\n\tprivate readonly _identityProfileConnector: IIdentityProfileConnector<T, U>;\n\n\t/**\n\t * Create a new instance of IdentityProfileService.\n\t * @param options The dependencies for the identity profile service.\n\t */\n\tconstructor(options?: IIdentityProfileServiceConstructorOptions) {\n\t\tthis._identityProfileConnector = IdentityProfileConnectorFactory.get<\n\t\t\tIIdentityProfileConnector<T, U>\n\t\t>(options?.profileEntityConnectorType ?? \"identity-profile\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IdentityService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create the profile properties for an identity.\n\t * @param publicProfile The public profile data as JSON-LD.\n\t * @param privateProfile The private profile data as JSON-LD.\n\t * @param identity The identity to perform the profile operation on.\n\t * @returns Nothing.\n\t */\n\tpublic async create(publicProfile?: T, privateProfile?: U, identity?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityProfileService.CLASS_NAME, nameof(identity), identity);\n\n\t\ttry {\n\t\t\tawait this._identityProfileConnector.create(identity, publicProfile, privateProfile);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityProfileService.CLASS_NAME,\n\t\t\t\t\"createFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the profile properties for an identity.\n\t * @param publicPropertyNames The public properties to get for the profile, defaults to all.\n\t * @param privatePropertyNames The private properties to get for the profile, defaults to all.\n\t * @param identity The identity to perform the profile operation on.\n\t * @returns The items identity and the properties.\n\t */\n\tpublic async get(\n\t\tpublicPropertyNames?: (keyof T)[],\n\t\tprivatePropertyNames?: (keyof U)[],\n\t\tidentity?: string\n\t): Promise<{\n\t\tidentity: string;\n\t\tpublicProfile?: Partial<T>;\n\t\tprivateProfile?: Partial<U>;\n\t}> {\n\t\tGuards.stringValue(IdentityProfileService.CLASS_NAME, nameof(identity), identity);\n\n\t\ttry {\n\t\t\tconst result = await this._identityProfileConnector.get(\n\t\t\t\tidentity,\n\t\t\t\tpublicPropertyNames,\n\t\t\t\tprivatePropertyNames\n\t\t\t);\n\t\t\tif (Is.undefined(result)) {\n\t\t\t\tthrow new NotFoundError(IdentityProfileService.CLASS_NAME, \"notFound\", identity);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tidentity,\n\t\t\t\tpublicProfile: result.publicProfile,\n\t\t\t\tprivateProfile: result.privateProfile\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(IdentityProfileService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the public profile properties for an identity.\n\t * @param identity The identity to perform the profile operation on.\n\t * @param propertyNames The properties to get for the item, defaults to all.\n\t * @returns The items properties.\n\t */\n\tpublic async getPublic(identity: string, propertyNames?: (keyof T)[]): Promise<Partial<T>> {\n\t\tGuards.stringValue(IdentityProfileService.CLASS_NAME, nameof(identity), identity);\n\n\t\ttry {\n\t\t\tconst result = await this._identityProfileConnector.get(identity, propertyNames);\n\t\t\tif (Is.undefined(result)) {\n\t\t\t\tthrow new NotFoundError(IdentityProfileService.CLASS_NAME, \"notFound\", identity);\n\t\t\t}\n\t\t\treturn result.publicProfile;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityProfileService.CLASS_NAME,\n\t\t\t\t\"getPublicFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update the profile properties of an identity.\n\t * @param publicProfile The public profile data as JSON-LD.\n\t * @param privateProfile The private profile data as JSON-LD.\n\t * @param identity The identity to perform the profile operation on.\n\t * @returns Nothing.\n\t */\n\tpublic async update(publicProfile?: T, privateProfile?: U, identity?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityProfileService.CLASS_NAME, nameof(identity), identity);\n\n\t\ttry {\n\t\t\tconst result = await this._identityProfileConnector.get(identity);\n\t\t\tif (Is.undefined(result)) {\n\t\t\t\tthrow new NotFoundError(IdentityProfileService.CLASS_NAME, \"notFound\", identity);\n\t\t\t}\n\t\t\tawait this._identityProfileConnector.update(identity, publicProfile, privateProfile);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityProfileService.CLASS_NAME,\n\t\t\t\t\"updateFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Delete the profile for an identity.\n\t * @param identity The identity to perform the profile operation on.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(identity?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityProfileService.CLASS_NAME, nameof(identity), identity);\n\n\t\ttry {\n\t\t\tconst result = await this._identityProfileConnector.get(identity);\n\t\t\tif (Is.undefined(result)) {\n\t\t\t\tthrow new NotFoundError(IdentityProfileService.CLASS_NAME, \"notFound\", identity);\n\t\t\t}\n\t\t\tawait this._identityProfileConnector.remove(identity);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityProfileService.CLASS_NAME,\n\t\t\t\t\"removeFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get a list of the requested types.\n\t * @param publicFilters The filters to apply to the identities public profiles.\n\t * @param publicPropertyNames The public properties to get for the profile, defaults to all.\n\t * @param cursor The cursor for paged requests.\n\t * @param limit The maximum number of items in a page.\n\t * @returns The list of items and cursor for paging.\n\t */\n\tpublic async list(\n\t\tpublicFilters?: {\n\t\t\tpropertyName: string;\n\t\t\tpropertyValue: unknown;\n\t\t}[],\n\t\tpublicPropertyNames?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The identities.\n\t\t */\n\t\titems: { identity: string; publicProfile?: Partial<T>; privateProfile?: Partial<U> }[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\ttry {\n\t\t\t// We don't want to return private profile for this type of query\n\t\t\t// as it would expose the values to the REST api\n\t\t\tconst result = await this._identityProfileConnector.list(\n\t\t\t\tpublicFilters,\n\t\t\t\tundefined,\n\t\t\t\tpublicPropertyNames,\n\t\t\t\tundefined,\n\t\t\t\tcursor,\n\t\t\t\tlimit\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityProfileService.CLASS_NAME, \"listFailed\", undefined, error);\n\t\t}\n\t}\n}\n"]}