@twin.org/api-auth-entity-storage-service 0.0.3-next.4 → 0.0.3-next.41

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 (104) hide show
  1. package/README.md +2 -2
  2. package/dist/es/entities/authenticationAuditEntry.js +101 -0
  3. package/dist/es/entities/authenticationAuditEntry.js.map +1 -0
  4. package/dist/es/entities/authenticationRateEntry.js +37 -0
  5. package/dist/es/entities/authenticationRateEntry.js.map +1 -0
  6. package/dist/es/entities/authenticationUser.js +17 -1
  7. package/dist/es/entities/authenticationUser.js.map +1 -1
  8. package/dist/es/index.js +11 -1
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -1
  11. package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -1
  12. package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js +4 -0
  13. package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js.map +1 -0
  14. package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js +2 -0
  15. package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js.map +1 -0
  16. package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js +2 -0
  17. package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js.map +1 -0
  18. package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js +2 -0
  19. package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js.map +1 -0
  20. package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js +0 -2
  21. package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -1
  22. package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -1
  23. package/dist/es/processors/authHeaderProcessor.js +62 -10
  24. package/dist/es/processors/authHeaderProcessor.js.map +1 -1
  25. package/dist/es/restEntryPoints.js +14 -0
  26. package/dist/es/restEntryPoints.js.map +1 -1
  27. package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +362 -0
  28. package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -0
  29. package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +174 -0
  30. package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +1 -0
  31. package/dist/es/routes/entityStorageAuthenticationRoutes.js +20 -21
  32. package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -1
  33. package/dist/es/schema.js +4 -0
  34. package/dist/es/schema.js.map +1 -1
  35. package/dist/es/services/entityStorageAuthenticationAdminService.js +161 -55
  36. package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -1
  37. package/dist/es/services/entityStorageAuthenticationAuditService.js +179 -0
  38. package/dist/es/services/entityStorageAuthenticationAuditService.js.map +1 -0
  39. package/dist/es/services/entityStorageAuthenticationRateService.js +202 -0
  40. package/dist/es/services/entityStorageAuthenticationRateService.js.map +1 -0
  41. package/dist/es/services/entityStorageAuthenticationService.js +200 -14
  42. package/dist/es/services/entityStorageAuthenticationService.js.map +1 -1
  43. package/dist/es/utils/passwordHelper.js +45 -16
  44. package/dist/es/utils/passwordHelper.js.map +1 -1
  45. package/dist/es/utils/tokenHelper.js +45 -21
  46. package/dist/es/utils/tokenHelper.js.map +1 -1
  47. package/dist/types/entities/authenticationAuditEntry.d.ts +49 -0
  48. package/dist/types/entities/authenticationRateEntry.d.ts +17 -0
  49. package/dist/types/entities/authenticationUser.d.ts +8 -0
  50. package/dist/types/index.d.ts +11 -1
  51. package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +14 -0
  52. package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +5 -0
  53. package/dist/types/models/IEntityStorageAuthenticationAuditServiceConfig.d.ts +9 -0
  54. package/dist/types/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.d.ts +15 -0
  55. package/dist/types/models/IEntityStorageAuthenticationRateServiceConfig.d.ts +10 -0
  56. package/dist/types/models/IEntityStorageAuthenticationRateServiceConstructorOptions.d.ts +20 -0
  57. package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +22 -1
  58. package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +17 -3
  59. package/dist/types/processors/authHeaderProcessor.d.ts +1 -1
  60. package/dist/types/routes/entityStorageAuthenticationAdminRoutes.d.ts +61 -0
  61. package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +29 -0
  62. package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +23 -6
  63. package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +53 -0
  64. package/dist/types/services/entityStorageAuthenticationRateService.d.ts +60 -0
  65. package/dist/types/services/entityStorageAuthenticationService.d.ts +8 -3
  66. package/dist/types/utils/passwordHelper.d.ts +13 -5
  67. package/dist/types/utils/tokenHelper.d.ts +9 -2
  68. package/docs/changelog.md +674 -64
  69. package/docs/examples.md +178 -1
  70. package/docs/reference/classes/AuthHeaderProcessor.md +10 -10
  71. package/docs/reference/classes/AuthenticationAuditEntry.md +101 -0
  72. package/docs/reference/classes/AuthenticationRateEntry.md +37 -0
  73. package/docs/reference/classes/AuthenticationUser.md +21 -5
  74. package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +78 -18
  75. package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +157 -0
  76. package/docs/reference/classes/EntityStorageAuthenticationRateService.md +227 -0
  77. package/docs/reference/classes/EntityStorageAuthenticationService.md +36 -16
  78. package/docs/reference/classes/PasswordHelper.md +37 -12
  79. package/docs/reference/classes/TokenHelper.md +44 -8
  80. package/docs/reference/functions/authenticationAdminCreateUser.md +31 -0
  81. package/docs/reference/functions/authenticationAdminGetUser.md +31 -0
  82. package/docs/reference/functions/authenticationAdminGetUserByIdentity.md +31 -0
  83. package/docs/reference/functions/authenticationAdminRemoveUser.md +31 -0
  84. package/docs/reference/functions/authenticationAdminUpdateUser.md +31 -0
  85. package/docs/reference/functions/authenticationAdminUpdateUserPassword.md +31 -0
  86. package/docs/reference/functions/authenticationAuditCreate.md +31 -0
  87. package/docs/reference/functions/authenticationAuditQuery.md +31 -0
  88. package/docs/reference/functions/generateRestRoutesAuthenticationAdmin.md +25 -0
  89. package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +25 -0
  90. package/docs/reference/index.md +20 -0
  91. package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +4 -4
  92. package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +40 -4
  93. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +2 -2
  94. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +18 -4
  95. package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConfig.md +11 -0
  96. package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConstructorOptions.md +25 -0
  97. package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConfig.md +17 -0
  98. package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConstructorOptions.md +39 -0
  99. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +61 -5
  100. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +46 -10
  101. package/docs/reference/variables/tagsAuthenticationAdmin.md +5 -0
  102. package/docs/reference/variables/tagsAuthenticationAudit.md +5 -0
  103. package/locales/en.json +17 -3
  104. package/package.json +8 -7
@@ -0,0 +1,362 @@
1
+ import { ComponentFactory, Guards } from "@twin.org/core";
2
+ import { HeaderTypes, HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The source used when communicating about these routes.
5
+ */
6
+ const ROUTES_SOURCE = "authenticationAdminRoutes";
7
+ /**
8
+ * The tag to associate with the routes.
9
+ */
10
+ export const tagsAuthenticationAdmin = [
11
+ {
12
+ name: "Authentication Admin",
13
+ description: "Authentication Admin endpoints for the REST server."
14
+ }
15
+ ];
16
+ /**
17
+ * The REST routes for authentication admin.
18
+ * @param baseRouteName Prefix to prepend to the paths.
19
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
20
+ * @returns The generated routes.
21
+ */
22
+ export function generateRestRoutesAuthenticationAdmin(baseRouteName, componentName) {
23
+ const createUserRoute = {
24
+ operationId: "authenticationAdminCreateUser",
25
+ summary: "Create a new user",
26
+ tag: tagsAuthenticationAdmin[0].name,
27
+ method: "POST",
28
+ path: `${baseRouteName}/users`,
29
+ handler: async (httpRequestContext, request) => authenticationAdminCreateUser(httpRequestContext, componentName, request),
30
+ requestType: {
31
+ type: "IAdminUserCreateRequest",
32
+ examples: [
33
+ {
34
+ id: "createUserRequestExample",
35
+ description: "The request to create a new user.",
36
+ request: {
37
+ body: {
38
+ email: "user@example.com",
39
+ password: "MyPassword123!",
40
+ userIdentity: "did:example:123456789abcdefghi",
41
+ organizationIdentity: "did:example:123456789abcdefghi",
42
+ scope: ["scope1", "scope2"]
43
+ }
44
+ }
45
+ }
46
+ ]
47
+ },
48
+ responseType: [
49
+ {
50
+ type: "INoContentResponse"
51
+ },
52
+ {
53
+ type: "IUnauthorizedResponse"
54
+ }
55
+ ],
56
+ requiredScope: ["user-admin"]
57
+ };
58
+ const updateUserRoute = {
59
+ operationId: "authenticationAdminUpdateUser",
60
+ summary: "Update an existing user",
61
+ tag: tagsAuthenticationAdmin[0].name,
62
+ method: "PUT",
63
+ path: `${baseRouteName}/users/:email`,
64
+ handler: async (httpRequestContext, request) => authenticationAdminUpdateUser(httpRequestContext, componentName, request),
65
+ requestType: {
66
+ type: "IAdminUserUpdateRequest",
67
+ examples: [
68
+ {
69
+ id: "updateUserRequestExample",
70
+ description: "The request to update an existing user.",
71
+ request: {
72
+ pathParams: {
73
+ email: "user@example.com"
74
+ },
75
+ body: {
76
+ userIdentity: "did:example:123456789abcdefghi",
77
+ organizationIdentity: "did:example:123456789abcdefghi",
78
+ scope: ["scope1", "scope2"]
79
+ }
80
+ }
81
+ }
82
+ ]
83
+ },
84
+ responseType: [
85
+ {
86
+ type: "INoContentResponse"
87
+ },
88
+ {
89
+ type: "IUnauthorizedResponse"
90
+ }
91
+ ],
92
+ requiredScope: ["user-admin"]
93
+ };
94
+ const updateUserPasswordRoute = {
95
+ operationId: "authenticationAdminUpdateUserPassword",
96
+ summary: "Update an existing user password",
97
+ tag: tagsAuthenticationAdmin[0].name,
98
+ method: "PUT",
99
+ path: `${baseRouteName}/users/:email/password`,
100
+ handler: async (httpRequestContext, request) => authenticationAdminUpdateUserPassword(httpRequestContext, componentName, request),
101
+ requestType: {
102
+ type: "IAdminUserUpdatePasswordRequest",
103
+ examples: [
104
+ {
105
+ id: "updateUserPasswordRequestExample",
106
+ description: "The request to update an existing user password.",
107
+ request: {
108
+ pathParams: {
109
+ email: "user@example.com"
110
+ },
111
+ body: {
112
+ newPassword: "MyNewPassword123!"
113
+ }
114
+ }
115
+ }
116
+ ]
117
+ },
118
+ responseType: [
119
+ {
120
+ type: "INoContentResponse"
121
+ },
122
+ {
123
+ type: "IUnauthorizedResponse"
124
+ }
125
+ ],
126
+ requiredScope: ["user-admin"]
127
+ };
128
+ const getUserRoute = {
129
+ operationId: "authenticationAdminGetUser",
130
+ summary: "Get existing user",
131
+ tag: tagsAuthenticationAdmin[0].name,
132
+ method: "GET",
133
+ path: `${baseRouteName}/users/:email`,
134
+ handler: async (httpRequestContext, request) => authenticationAdminGetUser(httpRequestContext, componentName, request),
135
+ requestType: {
136
+ type: "IAdminUserGetRequest",
137
+ examples: [
138
+ {
139
+ id: "getUserRequestExample",
140
+ description: "The request to get an existing user.",
141
+ request: {
142
+ pathParams: {
143
+ email: "user@example.com"
144
+ }
145
+ }
146
+ }
147
+ ]
148
+ },
149
+ responseType: [
150
+ {
151
+ type: "IAdminUserGetResponse",
152
+ examples: [
153
+ {
154
+ id: "getUserResponseExample",
155
+ description: "The response to get an existing user.",
156
+ response: {
157
+ body: {
158
+ email: "user@example.com",
159
+ userIdentity: "did:example:123456789abcdefghi",
160
+ organizationIdentity: "did:example:123456789abcdefghi",
161
+ scope: ["scope1", "scope2"]
162
+ }
163
+ }
164
+ }
165
+ ]
166
+ },
167
+ {
168
+ type: "IUnauthorizedResponse"
169
+ }
170
+ ],
171
+ requiredScope: ["user-admin"]
172
+ };
173
+ const getByIdentityUserRoute = {
174
+ operationId: "authenticationAdminGetByIdentityUser",
175
+ summary: "Get existing user by identity",
176
+ tag: tagsAuthenticationAdmin[0].name,
177
+ method: "GET",
178
+ path: `${baseRouteName}/users/identity/:identity`,
179
+ handler: async (httpRequestContext, request) => authenticationAdminGetUserByIdentity(httpRequestContext, componentName, request),
180
+ requestType: {
181
+ type: "IAdminUserGetByIdentityRequest",
182
+ examples: [
183
+ {
184
+ id: "getUserByIdentityRequestExample",
185
+ description: "The request to get an existing user by identity.",
186
+ request: {
187
+ pathParams: {
188
+ identity: "did:example:123456789abcdefghi"
189
+ }
190
+ }
191
+ }
192
+ ]
193
+ },
194
+ responseType: [
195
+ {
196
+ type: "IAdminUserGetResponse",
197
+ examples: [
198
+ {
199
+ id: "getUserResponseExample",
200
+ description: "The response to get an existing user.",
201
+ response: {
202
+ body: {
203
+ email: "user@example.com",
204
+ userIdentity: "did:example:123456789abcdefghi",
205
+ organizationIdentity: "did:example:123456789abcdefghi",
206
+ scope: ["scope1", "scope2"]
207
+ }
208
+ }
209
+ }
210
+ ]
211
+ },
212
+ {
213
+ type: "IUnauthorizedResponse"
214
+ }
215
+ ],
216
+ requiredScope: ["user-admin"]
217
+ };
218
+ const removeUserRoute = {
219
+ operationId: "authenticationAdminRemoveUser",
220
+ summary: "Remove existing user",
221
+ tag: tagsAuthenticationAdmin[0].name,
222
+ method: "DELETE",
223
+ path: `${baseRouteName}/users/:email`,
224
+ handler: async (httpRequestContext, request) => authenticationAdminRemoveUser(httpRequestContext, componentName, request),
225
+ requestType: {
226
+ type: "IAdminUserRemoveRequest",
227
+ examples: [
228
+ {
229
+ id: "removeUserRequestExample",
230
+ description: "The request to remove an existing user.",
231
+ request: {
232
+ pathParams: {
233
+ email: "user@example.com"
234
+ }
235
+ }
236
+ }
237
+ ]
238
+ },
239
+ responseType: [
240
+ {
241
+ type: "INoContentResponse"
242
+ },
243
+ {
244
+ type: "IUnauthorizedResponse"
245
+ }
246
+ ],
247
+ requiredScope: ["user-admin"]
248
+ };
249
+ return [
250
+ createUserRoute,
251
+ updateUserRoute,
252
+ updateUserPasswordRoute,
253
+ getUserRoute,
254
+ getByIdentityUserRoute,
255
+ removeUserRoute
256
+ ];
257
+ }
258
+ /**
259
+ * Create a new user.
260
+ * @param httpRequestContext The request context for the API.
261
+ * @param componentName The name of the component to use in the routes.
262
+ * @param request The request.
263
+ * @returns The response object with additional http response properties.
264
+ */
265
+ export async function authenticationAdminCreateUser(httpRequestContext, componentName, request) {
266
+ Guards.object(ROUTES_SOURCE, "request", request);
267
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
268
+ const component = ComponentFactory.get(componentName);
269
+ await component.create(request.body);
270
+ return {
271
+ statusCode: HttpStatusCode.created,
272
+ headers: {
273
+ [HeaderTypes.Location]: request.body.email
274
+ }
275
+ };
276
+ }
277
+ /**
278
+ * Update an existing user.
279
+ * @param httpRequestContext The request context for the API.
280
+ * @param componentName The name of the component to use in the routes.
281
+ * @param request The request.
282
+ * @returns The response object with additional http response properties.
283
+ */
284
+ export async function authenticationAdminUpdateUser(httpRequestContext, componentName, request) {
285
+ Guards.object(ROUTES_SOURCE, "request", request);
286
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
287
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
288
+ const component = ComponentFactory.get(componentName);
289
+ await component.update({
290
+ ...request.body,
291
+ email: request.pathParams.email
292
+ });
293
+ return {
294
+ statusCode: HttpStatusCode.noContent
295
+ };
296
+ }
297
+ /**
298
+ * Update an existing user password.
299
+ * @param httpRequestContext The request context for the API.
300
+ * @param componentName The name of the component to use in the routes.
301
+ * @param request The request.
302
+ * @returns The response object with additional http response properties.
303
+ */
304
+ export async function authenticationAdminUpdateUserPassword(httpRequestContext, componentName, request) {
305
+ Guards.object(ROUTES_SOURCE, "request", request);
306
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
307
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
308
+ const component = ComponentFactory.get(componentName);
309
+ await component.updatePassword(request.pathParams.email, request.body.newPassword);
310
+ return {
311
+ statusCode: HttpStatusCode.noContent
312
+ };
313
+ }
314
+ /**
315
+ * Get an existing user.
316
+ * @param httpRequestContext The request context for the API.
317
+ * @param componentName The name of the component to use in the routes.
318
+ * @param request The request.
319
+ * @returns The response object with additional http response properties.
320
+ */
321
+ export async function authenticationAdminGetUser(httpRequestContext, componentName, request) {
322
+ Guards.object(ROUTES_SOURCE, "request", request);
323
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
324
+ const component = ComponentFactory.get(componentName);
325
+ const result = await component.get(request.pathParams.email);
326
+ return {
327
+ body: result
328
+ };
329
+ }
330
+ /**
331
+ * Get an existing user by identity.
332
+ * @param httpRequestContext The request context for the API.
333
+ * @param componentName The name of the component to use in the routes.
334
+ * @param request The request.
335
+ * @returns The response object with additional http response properties.
336
+ */
337
+ export async function authenticationAdminGetUserByIdentity(httpRequestContext, componentName, request) {
338
+ Guards.object(ROUTES_SOURCE, "request", request);
339
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
340
+ const component = ComponentFactory.get(componentName);
341
+ const result = await component.getByIdentity(request.pathParams.identity);
342
+ return {
343
+ body: result
344
+ };
345
+ }
346
+ /**
347
+ * Remove an existing user.
348
+ * @param httpRequestContext The request context for the API.
349
+ * @param componentName The name of the component to use in the routes.
350
+ * @param request The request.
351
+ * @returns The response object with additional http response properties.
352
+ */
353
+ export async function authenticationAdminRemoveUser(httpRequestContext, componentName, request) {
354
+ Guards.object(ROUTES_SOURCE, "request", request);
355
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
356
+ const component = ComponentFactory.get(componentName);
357
+ await component.remove(request.pathParams.email);
358
+ return {
359
+ statusCode: HttpStatusCode.noContent
360
+ };
361
+ }
362
+ //# sourceMappingURL=entityStorageAuthenticationAdminRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageAuthenticationAdminRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationAdminRoutes.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC9C;QACC,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,qDAAqD;KAClE;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CACpD,aAAqB,EACrB,aAAqB;IAErB,MAAM,eAAe,GAA0D;QAC9E,WAAW,EAAE,+BAA+B;QAC5C,OAAO,EAAE,mBAAmB;QAC5B,GAAG,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,IAAI;QACpC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,QAAQ;QAC9B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,6BAA6B,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QAC1E,WAAW,EAAE;YACZ,IAAI,2BAAmC;YACvC,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,0BAA0B;oBAC9B,WAAW,EAAE,mCAAmC;oBAChD,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,KAAK,EAAE,kBAAkB;4BACzB,QAAQ,EAAE,gBAAgB;4BAC1B,YAAY,EAAE,gCAAgC;4BAC9C,oBAAoB,EAAE,gCAAgC;4BACtD,KAAK,EAAE,CAAC,QA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AAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAdminUserCreateRequest,\n\tIAdminUserGetByIdentityRequest,\n\tIAdminUserGetRequest,\n\tIAdminUserGetResponse,\n\tIAdminUserRemoveRequest,\n\tIAdminUserUpdatePasswordRequest,\n\tIAdminUserUpdateRequest,\n\tIAuthenticationAdminComponent\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tITag,\n\tIUnauthorizedResponse\n} from \"@twin.org/api-models\";\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationAdminRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthenticationAdmin: ITag[] = [\n\t{\n\t\tname: \"Authentication Admin\",\n\t\tdescription: \"Authentication Admin endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication admin.\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 generateRestRoutesAuthenticationAdmin(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createUserRoute: IRestRoute<IAdminUserCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"authenticationAdminCreateUser\",\n\t\tsummary: \"Create a new user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/users`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminCreateUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"createUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to create a new user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\",\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\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\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst updateUserRoute: IRestRoute<IAdminUserUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUser\",\n\t\tsummary: \"Update an existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\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\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst updateUserPasswordRoute: IRestRoute<IAdminUserUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUserPassword\",\n\t\tsummary: \"Update an existing user password\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUserPassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserUpdatePasswordRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserPasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\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\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst getUserRoute: IRestRoute<IAdminUserGetRequest, IAdminUserGetResponse> = {\n\t\toperationId: \"authenticationAdminGetUser\",\n\t\tsummary: \"Get existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminGetUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"getUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to get an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\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<IAdminUserGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\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<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst getByIdentityUserRoute: IRestRoute<IAdminUserGetByIdentityRequest, IAdminUserGetResponse> =\n\t\t{\n\t\t\toperationId: \"authenticationAdminGetByIdentityUser\",\n\t\t\tsummary: \"Get existing user by identity\",\n\t\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\t\tmethod: \"GET\",\n\t\t\tpath: `${baseRouteName}/users/identity/:identity`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tauthenticationAdminGetUserByIdentity(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IAdminUserGetByIdentityRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserByIdentityRequestExample\",\n\t\t\t\t\t\tdescription: \"The request to get an existing user by identity.\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\t\tidentity: \"did:example: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\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IAdminUserGetResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\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\t{\n\t\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t\t}\n\t\t\t],\n\t\t\trequiredScope: [\"user-admin\"]\n\t\t};\n\n\tconst removeUserRoute: IRestRoute<IAdminUserRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminRemoveUser\",\n\t\tsummary: \"Remove existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminRemoveUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"removeUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to remove an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\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\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\treturn [\n\t\tcreateUserRoute,\n\t\tupdateUserRoute,\n\t\tupdateUserPasswordRoute,\n\t\tgetUserRoute,\n\t\tgetByIdentityUserRoute,\n\t\tremoveUserRoute\n\t];\n}\n\n/**\n * Create a new user.\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 authenticationAdminCreateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IAdminUserCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.create(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: request.body.email\n\t\t}\n\t};\n}\n\n/**\n * Update an existing user.\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 authenticationAdminUpdateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserUpdateRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.update({\n\t\t...request.body,\n\t\temail: request.pathParams.email\n\t});\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Update an existing user password.\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 authenticationAdminUpdateUserPassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdatePasswordRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.updatePassword(request.pathParams.email, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get an existing user.\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 authenticationAdminGetUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.get(request.pathParams.email);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get an existing user by identity.\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 authenticationAdminGetUserByIdentity(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetByIdentityRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetByIdentityRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserGetByIdentityRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.getByIdentity(request.pathParams.identity);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Remove an existing user.\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 authenticationAdminRemoveUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.remove(request.pathParams.email);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
@@ -0,0 +1,174 @@
1
+ import { Coerce, ComponentFactory, Guards } from "@twin.org/core";
2
+ import { HeaderTypes, HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The source used when communicating about these routes.
5
+ */
6
+ const ROUTES_SOURCE = "authenticationAuditRoutes";
7
+ /**
8
+ * The tag to associate with the routes.
9
+ */
10
+ export const tagsAuthenticationAudit = [
11
+ {
12
+ name: "Authentication Audit",
13
+ description: "Authentication audit endpoints for the REST server."
14
+ }
15
+ ];
16
+ /**
17
+ * The REST routes for authentication audit.
18
+ * @param baseRouteName Prefix to prepend to the paths.
19
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
20
+ * @returns The generated routes.
21
+ */
22
+ export function generateRestRoutesAuthenticationAudit(baseRouteName, componentName) {
23
+ const createRoute = {
24
+ operationId: "authenticationAuditCreate",
25
+ summary: "Create an authentication audit entry",
26
+ tag: tagsAuthenticationAudit[0].name,
27
+ method: "POST",
28
+ path: `${baseRouteName}`,
29
+ handler: async (httpRequestContext, request) => authenticationAuditCreate(httpRequestContext, componentName, request),
30
+ requestType: {
31
+ type: "IAuditCreateRequest",
32
+ examples: [
33
+ {
34
+ id: "authenticationAuditCreateRequestExample",
35
+ description: "The request to create an authentication audit entry.",
36
+ request: {
37
+ body: {
38
+ actorId: "user@example.com",
39
+ event: "login-success",
40
+ data: {
41
+ organizationIdentity: "did:example:org1"
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ]
47
+ },
48
+ responseType: [
49
+ {
50
+ type: "ICreatedResponse",
51
+ examples: [
52
+ {
53
+ id: "authenticationAuditCreateResponseExample",
54
+ description: "The response for creating an authentication audit entry.",
55
+ response: {
56
+ statusCode: 201,
57
+ headers: {
58
+ [HeaderTypes.Location]: "018f0b53d5d5704fa3a06d6ed2478575"
59
+ }
60
+ }
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ type: "IUnauthorizedResponse"
66
+ }
67
+ ],
68
+ requiredScope: ["user-admin"]
69
+ };
70
+ const queryRoute = {
71
+ operationId: "authenticationAuditQuery",
72
+ summary: "Query authentication audit entries",
73
+ tag: tagsAuthenticationAudit[0].name,
74
+ method: "GET",
75
+ path: `${baseRouteName}`,
76
+ handler: async (httpRequestContext, request) => authenticationAuditQuery(httpRequestContext, componentName, request),
77
+ requestType: {
78
+ type: "IAuditQueryRequest",
79
+ examples: [
80
+ {
81
+ id: "authenticationAuditQueryRequestExample",
82
+ description: "The request to query authentication audit entries.",
83
+ request: {
84
+ query: {
85
+ actorId: "user@example.com",
86
+ event: "login-success",
87
+ startDate: "2026-01-01T00:00:00.000Z",
88
+ endDate: "2026-01-31T23:59:59.999Z",
89
+ limit: "50"
90
+ }
91
+ }
92
+ }
93
+ ]
94
+ },
95
+ responseType: [
96
+ {
97
+ type: "IAuditQueryResponse",
98
+ examples: [
99
+ {
100
+ id: "authenticationAuditQueryResponseExample",
101
+ description: "The response for querying authentication audit entries.",
102
+ response: {
103
+ body: {
104
+ entries: [
105
+ {
106
+ id: "018f0b53d5d5704fa3a06d6ed2478575",
107
+ actorId: "user@example.com",
108
+ dateCreated: "2026-01-12T09:05:23.123Z",
109
+ event: "login-success",
110
+ data: {
111
+ organizationIdentity: "did:example:org1"
112
+ }
113
+ }
114
+ ],
115
+ cursor: "next-cursor"
116
+ }
117
+ }
118
+ }
119
+ ]
120
+ },
121
+ {
122
+ type: "IUnauthorizedResponse"
123
+ }
124
+ ],
125
+ requiredScope: ["user-admin"]
126
+ };
127
+ return [createRoute, queryRoute];
128
+ }
129
+ /**
130
+ * Create an authentication audit entry.
131
+ * @param httpRequestContext The request context for the API.
132
+ * @param componentName The name of the component to use in the routes.
133
+ * @param request The request.
134
+ * @returns The response object with additional http response properties.
135
+ */
136
+ export async function authenticationAuditCreate(httpRequestContext, componentName, request) {
137
+ Guards.object(ROUTES_SOURCE, "request", request);
138
+ Guards.object(ROUTES_SOURCE, "request.body", request.body);
139
+ const component = ComponentFactory.get(componentName);
140
+ const id = await component.create(request.body);
141
+ return {
142
+ statusCode: HttpStatusCode.created,
143
+ headers: {
144
+ [HeaderTypes.Location]: id
145
+ }
146
+ };
147
+ }
148
+ /**
149
+ * Query authentication audit entries.
150
+ * @param httpRequestContext The request context for the API.
151
+ * @param componentName The name of the component to use in the routes.
152
+ * @param request The request.
153
+ * @returns The response object with additional http response properties.
154
+ */
155
+ export async function authenticationAuditQuery(httpRequestContext, componentName, request) {
156
+ Guards.object(ROUTES_SOURCE, "request", request);
157
+ const component = ComponentFactory.get(componentName);
158
+ const result = await component.query({
159
+ actorId: request.query?.actorId,
160
+ organizationId: request.query?.organizationId,
161
+ tenantId: request.query?.tenantId,
162
+ nodeId: request.query?.nodeId,
163
+ event: request.query?.event,
164
+ startDate: request.query?.startDate,
165
+ endDate: request.query?.endDate
166
+ }, request.query?.cursor, Coerce.integer(request.query?.limit));
167
+ return {
168
+ body: {
169
+ entries: result.entries,
170
+ cursor: result.cursor
171
+ }
172
+ };
173
+ }
174
+ //# sourceMappingURL=entityStorageAuthenticationAuditRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageAuthenticationAuditRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationAuditRoutes.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC9C;QACC,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,qDAAqD;KAClE;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CACpD,aAAqB,EACrB,aAAqB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\tIAuthenticationAuditComponent\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tIRestRoute,\n\tITag,\n\tIUnauthorizedResponse\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationAuditRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthenticationAudit: ITag[] = [\n\t{\n\t\tname: \"Authentication Audit\",\n\t\tdescription: \"Authentication audit endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication audit.\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 generateRestRoutesAuthenticationAudit(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IAuditCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"authenticationAuditCreate\",\n\t\tsummary: \"Create an authentication audit entry\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditCreateRequestExample\",\n\t\t\t\t\tdescription: \"The request to create an authentication audit entry.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\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: \"authenticationAuditCreateResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for creating an authentication audit entry.\",\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]: \"018f0b53d5d5704fa3a06d6ed2478575\"\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<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst queryRoute: IRestRoute<IAuditQueryRequest, IAuditQueryResponse> = {\n\t\toperationId: \"authenticationAuditQuery\",\n\t\tsummary: \"Query authentication audit entries\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditQueryRequestExample\",\n\t\t\t\t\tdescription: \"The request to query authentication audit entries.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\tstartDate: \"2026-01-01T00:00:00.000Z\",\n\t\t\t\t\t\t\tendDate: \"2026-01-31T23:59:59.999Z\",\n\t\t\t\t\t\t\tlimit: \"50\"\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<IAuditQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"authenticationAuditQueryResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for querying authentication audit entries.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentries: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\",\n\t\t\t\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\t\t\t\tdateCreated: \"2026-01-12T09:05:23.123Z\",\n\t\t\t\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\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: \"next-cursor\"\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<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\treturn [createRoute, queryRoute];\n}\n\n/**\n * Create an authentication audit 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 authenticationAuditCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IAuditCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAuditCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tconst id = await component.create(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: id\n\t\t}\n\t};\n}\n\n/**\n * Query authentication audit entries.\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 authenticationAuditQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditQueryRequest\n): Promise<IAuditQueryResponse> {\n\tGuards.object<IAuditQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tconst result = await component.query(\n\t\t{\n\t\t\tactorId: request.query?.actorId,\n\t\t\torganizationId: request.query?.organizationId,\n\t\t\ttenantId: request.query?.tenantId,\n\t\t\tnodeId: request.query?.nodeId,\n\t\t\tevent: request.query?.event,\n\t\t\tstartDate: request.query?.startDate,\n\t\t\tendDate: request.query?.endDate\n\t\t},\n\t\trequest.query?.cursor,\n\t\tCoerce.integer(request.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: {\n\t\t\tentries: result.entries,\n\t\t\tcursor: result.cursor\n\t\t}\n\t};\n}\n"]}