@3sixty/api-tenant-processor 0.0.0-stage → 0.20.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/entities/tenant.js +77 -0
- package/dist/es/entities/tenant.js.map +1 -0
- package/dist/es/entities/tenantV0.js +61 -0
- package/dist/es/entities/tenantV0.js.map +1 -0
- package/dist/es/entities/tenantV1.js +77 -0
- package/dist/es/entities/tenantV1.js.map +1 -0
- package/dist/es/index.js +29 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/ISingleTenantProcessorConfig.js +4 -0
- package/dist/es/models/ISingleTenantProcessorConfig.js.map +1 -0
- package/dist/es/models/ISingleTenantProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ISingleTenantProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantAdminServiceConfig.js +4 -0
- package/dist/es/models/ITenantAdminServiceConfig.js.map +1 -0
- package/dist/es/models/ITenantAdminServiceConstructorOptions.js +2 -0
- package/dist/es/models/ITenantAdminServiceConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantOverrideProcessorConfig.js +4 -0
- package/dist/es/models/ITenantOverrideProcessorConfig.js.map +1 -0
- package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantProcessorConfig.js +4 -0
- package/dist/es/models/ITenantProcessorConfig.js.map +1 -0
- package/dist/es/models/ITenantProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ITenantProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/api/ITenantCreateRequest.js +2 -0
- package/dist/es/models/api/ITenantCreateRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByApiKeyRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByApiKeyRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByIdRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByIdRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByPublicOriginRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByPublicOriginRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetResponse.js +2 -0
- package/dist/es/models/api/ITenantGetResponse.js.map +1 -0
- package/dist/es/models/api/ITenantListRequest.js +4 -0
- package/dist/es/models/api/ITenantListRequest.js.map +1 -0
- package/dist/es/models/api/ITenantListResponse.js +2 -0
- package/dist/es/models/api/ITenantListResponse.js.map +1 -0
- package/dist/es/models/api/ITenantRemoveRequest.js +4 -0
- package/dist/es/models/api/ITenantRemoveRequest.js.map +1 -0
- package/dist/es/models/api/ITenantUpdateRequest.js +2 -0
- package/dist/es/models/api/ITenantUpdateRequest.js.map +1 -0
- package/dist/es/restEntryPoints.js +13 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/schema.js +64 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/es/singleTenantProcessor.js +81 -0
- package/dist/es/singleTenantProcessor.js.map +1 -0
- package/dist/es/tenantAdminService.js +500 -0
- package/dist/es/tenantAdminService.js.map +1 -0
- package/dist/es/tenantIdContextIdHandler.js +47 -0
- package/dist/es/tenantIdContextIdHandler.js.map +1 -0
- package/dist/es/tenantOverrideProcessor.js +119 -0
- package/dist/es/tenantOverrideProcessor.js.map +1 -0
- package/dist/es/tenantProcessor.js +164 -0
- package/dist/es/tenantProcessor.js.map +1 -0
- package/dist/es/tenantRoutes.js +404 -0
- package/dist/es/tenantRoutes.js.map +1 -0
- package/dist/es/utils/tenantIdHelper.js +23 -0
- package/dist/es/utils/tenantIdHelper.js.map +1 -0
- package/dist/types/entities/tenant.d.ts +37 -0
- package/dist/types/entities/tenantV0.d.ts +29 -0
- package/dist/types/entities/tenantV1.d.ts +37 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/models/ISingleTenantProcessorConfig.d.ts +9 -0
- package/dist/types/models/ISingleTenantProcessorConstructorOptions.d.ts +10 -0
- package/dist/types/models/ITenantAdminServiceConfig.d.ts +24 -0
- package/dist/types/models/ITenantAdminServiceConstructorOptions.d.ts +15 -0
- package/dist/types/models/ITenantOverrideProcessorConfig.d.ts +13 -0
- package/dist/types/models/ITenantOverrideProcessorConstructorOptions.d.ts +15 -0
- package/dist/types/models/ITenantProcessorConfig.d.ts +18 -0
- package/dist/types/models/ITenantProcessorConstructorOptions.d.ts +15 -0
- package/dist/types/models/api/ITenantCreateRequest.d.ts +12 -0
- package/dist/types/models/api/ITenantGetByApiKeyRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetByIdRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetByPublicOriginRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetResponse.d.ts +10 -0
- package/dist/types/models/api/ITenantListRequest.d.ts +27 -0
- package/dist/types/models/api/ITenantListResponse.d.ts +17 -0
- package/dist/types/models/api/ITenantRemoveRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantUpdateRequest.d.ts +19 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/schema.d.ts +5 -0
- package/dist/types/singleTenantProcessor.d.ts +41 -0
- package/dist/types/tenantAdminService.d.ts +109 -0
- package/dist/types/tenantIdContextIdHandler.d.ts +33 -0
- package/dist/types/tenantOverrideProcessor.d.ts +44 -0
- package/dist/types/tenantProcessor.d.ts +34 -0
- package/dist/types/tenantRoutes.d.ts +78 -0
- package/dist/types/utils/tenantIdHelper.d.ts +15 -0
- package/docs/changelog.md +0 -0
- package/docs/examples.md +81 -0
- package/docs/reference/classes/SingleTenantProcessor.md +128 -0
- package/docs/reference/classes/Tenant.md +77 -0
- package/docs/reference/classes/TenantAdminService.md +393 -0
- package/docs/reference/classes/TenantIdContextIdHandler.md +123 -0
- package/docs/reference/classes/TenantIdHelper.md +41 -0
- package/docs/reference/classes/TenantOverrideProcessor.md +119 -0
- package/docs/reference/classes/TenantProcessor.md +101 -0
- package/docs/reference/functions/generateRestRoutesTenants.md +25 -0
- package/docs/reference/functions/initSchema.md +10 -0
- package/docs/reference/functions/tenantByApiKey.md +31 -0
- package/docs/reference/functions/tenantById.md +31 -0
- package/docs/reference/functions/tenantByPublicOrigin.md +31 -0
- package/docs/reference/functions/tenantCreate.md +37 -0
- package/docs/reference/functions/tenantList.md +31 -0
- package/docs/reference/functions/tenantRemove.md +31 -0
- package/docs/reference/functions/tenantUpdate.md +31 -0
- package/docs/reference/index.md +47 -0
- package/docs/reference/interfaces/ISingleTenantProcessorConfig.md +11 -0
- package/docs/reference/interfaces/ISingleTenantProcessorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/ITenantAdminServiceConfig.md +49 -0
- package/docs/reference/interfaces/ITenantAdminServiceConstructorOptions.md +25 -0
- package/docs/reference/interfaces/ITenantCreateRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByApiKeyRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByIdRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByPublicOriginRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetResponse.md +11 -0
- package/docs/reference/interfaces/ITenantListRequest.md +36 -0
- package/docs/reference/interfaces/ITenantListResponse.md +23 -0
- package/docs/reference/interfaces/ITenantOverrideProcessorConfig.md +19 -0
- package/docs/reference/interfaces/ITenantOverrideProcessorConstructorOptions.md +25 -0
- package/docs/reference/interfaces/ITenantProcessorConfig.md +33 -0
- package/docs/reference/interfaces/ITenantProcessorConstructorOptions.md +25 -0
- package/docs/reference/interfaces/ITenantRemoveRequest.md +17 -0
- package/docs/reference/interfaces/ITenantUpdateRequest.md +25 -0
- package/docs/reference/variables/tagsTenants.md +5 -0
- package/locales/en.json +24 -0
- package/package.json +57 -5
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { HttpContextIdKeys, HttpHeaderHelper, HttpParameterHelper, HttpUrlHelper } from "@3sixty/api-models";
|
|
4
|
+
import { ContextIdStore } from "@3sixty/context";
|
|
5
|
+
import { Coerce, ComponentFactory, Guards, Is } from "@3sixty/core";
|
|
6
|
+
import { HeaderTypes, HttpStatusCode } from "@3sixty/web";
|
|
7
|
+
/**
|
|
8
|
+
* The source used when communicating about these routes.
|
|
9
|
+
*/
|
|
10
|
+
const ROUTES_SOURCE = "tenantRoutes";
|
|
11
|
+
/**
|
|
12
|
+
* The tag to associate with the routes.
|
|
13
|
+
*/
|
|
14
|
+
export const tagsTenants = [
|
|
15
|
+
{
|
|
16
|
+
name: "Tenants",
|
|
17
|
+
description: "Tenants endpoints for the REST server."
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* The REST routes for tenant management.
|
|
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 generateRestRoutesTenants(baseRouteName, componentName) {
|
|
27
|
+
const tenantListRoute = {
|
|
28
|
+
operationId: "tenantList",
|
|
29
|
+
summary: "Get the list of tenants",
|
|
30
|
+
tag: tagsTenants[0].name,
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: `${baseRouteName}/`,
|
|
33
|
+
handler: async (httpRequestContext, request) => tenantList(httpRequestContext, componentName, request),
|
|
34
|
+
responseType: [
|
|
35
|
+
{
|
|
36
|
+
type: "ITenantListResponse",
|
|
37
|
+
examples: [
|
|
38
|
+
{
|
|
39
|
+
id: "tenantListResponse",
|
|
40
|
+
description: "The response for the list tenants request.",
|
|
41
|
+
response: {
|
|
42
|
+
headers: {
|
|
43
|
+
[HeaderTypes.Link]: '<https://api.3sixty.global/tenants/1>; rel="next"'
|
|
44
|
+
},
|
|
45
|
+
body: [
|
|
46
|
+
{
|
|
47
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4",
|
|
48
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
49
|
+
label: "node",
|
|
50
|
+
dateCreated: "2026-01-19T03:59:35.742Z",
|
|
51
|
+
dateModified: "2026-01-19T03:59:35.742Z",
|
|
52
|
+
publicOrigin: "https://example.com:4321",
|
|
53
|
+
organizationId: "org-1"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
requiredScope: ["tenant-admin"]
|
|
62
|
+
};
|
|
63
|
+
const tenantGetByIdRoute = {
|
|
64
|
+
operationId: "tenantGetById",
|
|
65
|
+
summary: "Get the tenant by id",
|
|
66
|
+
tag: tagsTenants[0].name,
|
|
67
|
+
method: "GET",
|
|
68
|
+
path: `${baseRouteName}/:id`,
|
|
69
|
+
handler: async (httpRequestContext, request) => tenantById(httpRequestContext, componentName, request),
|
|
70
|
+
requestType: {
|
|
71
|
+
type: "ITenantGetByIdRequest",
|
|
72
|
+
examples: [
|
|
73
|
+
{
|
|
74
|
+
id: "tenantGetByIdRequestExample",
|
|
75
|
+
request: {
|
|
76
|
+
pathParams: {
|
|
77
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
responseType: [
|
|
84
|
+
{
|
|
85
|
+
type: "ITenantGetResponse",
|
|
86
|
+
examples: [
|
|
87
|
+
{
|
|
88
|
+
id: "tenantGetByIdResponse",
|
|
89
|
+
description: "The response for the get tenant by id request.",
|
|
90
|
+
response: {
|
|
91
|
+
body: {
|
|
92
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4",
|
|
93
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
94
|
+
label: "node",
|
|
95
|
+
dateCreated: "2026-01-19T03:59:35.742Z",
|
|
96
|
+
dateModified: "2026-01-19T03:59:35.742Z",
|
|
97
|
+
publicOrigin: "https://example.com:4321",
|
|
98
|
+
organizationId: "org-1"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
requiredScope: ["tenant-admin"]
|
|
106
|
+
};
|
|
107
|
+
const tenantGetByApiKeyRoute = {
|
|
108
|
+
operationId: "tenantGetByApiKey",
|
|
109
|
+
summary: "Get the tenant by api key",
|
|
110
|
+
tag: tagsTenants[0].name,
|
|
111
|
+
method: "GET",
|
|
112
|
+
path: `${baseRouteName}/api-key/:apiKey`,
|
|
113
|
+
handler: async (httpRequestContext, request) => tenantByApiKey(httpRequestContext, componentName, request),
|
|
114
|
+
responseType: [
|
|
115
|
+
{
|
|
116
|
+
type: "ITenantGetResponse",
|
|
117
|
+
examples: [
|
|
118
|
+
{
|
|
119
|
+
id: "tenantGetByApiKeyResponse",
|
|
120
|
+
description: "The response for the get tenant by api key request.",
|
|
121
|
+
response: {
|
|
122
|
+
body: {
|
|
123
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4",
|
|
124
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
125
|
+
label: "node",
|
|
126
|
+
dateCreated: "2026-01-19T03:59:35.742Z",
|
|
127
|
+
dateModified: "2026-01-19T03:59:35.742Z",
|
|
128
|
+
publicOrigin: "https://example.com:4321",
|
|
129
|
+
organizationId: "org-1"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
requiredScope: ["tenant-admin"]
|
|
137
|
+
};
|
|
138
|
+
const tenantGetByPublicOriginRoute = {
|
|
139
|
+
operationId: "tenantGetByPublicOrigin",
|
|
140
|
+
summary: "Get the tenant by public origin",
|
|
141
|
+
tag: tagsTenants[0].name,
|
|
142
|
+
method: "GET",
|
|
143
|
+
path: `${baseRouteName}/public-origin/:publicOrigin`,
|
|
144
|
+
handler: async (httpRequestContext, request) => tenantByPublicOrigin(httpRequestContext, componentName, request),
|
|
145
|
+
responseType: [
|
|
146
|
+
{
|
|
147
|
+
type: "ITenantGetResponse",
|
|
148
|
+
examples: [
|
|
149
|
+
{
|
|
150
|
+
id: "tenantGetByPublicOriginResponse",
|
|
151
|
+
description: "The response for the get tenant by public origin request.",
|
|
152
|
+
response: {
|
|
153
|
+
body: {
|
|
154
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4",
|
|
155
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
156
|
+
label: "node",
|
|
157
|
+
dateCreated: "2026-01-19T03:59:35.742Z",
|
|
158
|
+
publicOrigin: "https://example.com:4321"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
requiredScope: ["tenant-admin"]
|
|
166
|
+
};
|
|
167
|
+
const tenantRemoveRoute = {
|
|
168
|
+
operationId: "tenantRemove",
|
|
169
|
+
summary: "Remove the tenant by id",
|
|
170
|
+
tag: tagsTenants[0].name,
|
|
171
|
+
method: "DELETE",
|
|
172
|
+
path: `${baseRouteName}/:id`,
|
|
173
|
+
handler: async (httpRequestContext, request) => tenantRemove(httpRequestContext, componentName, request),
|
|
174
|
+
requestType: {
|
|
175
|
+
type: "ITenantRemoveRequest",
|
|
176
|
+
examples: [
|
|
177
|
+
{
|
|
178
|
+
id: "tenantRemoveRequestExample",
|
|
179
|
+
description: "The request for the remove tenant by id request.",
|
|
180
|
+
request: {
|
|
181
|
+
pathParams: {
|
|
182
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4"
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
responseType: [
|
|
189
|
+
{
|
|
190
|
+
type: "INoContentResponse"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
requiredScope: ["tenant-admin"]
|
|
194
|
+
};
|
|
195
|
+
const tenantCreateRoute = {
|
|
196
|
+
operationId: "tenantCreate",
|
|
197
|
+
summary: "Create a new tenant",
|
|
198
|
+
tag: tagsTenants[0].name,
|
|
199
|
+
method: "POST",
|
|
200
|
+
path: `${baseRouteName}/`,
|
|
201
|
+
handler: async (httpRequestContext, request) => tenantCreate(httpRequestContext, componentName, request, baseRouteName),
|
|
202
|
+
requestType: {
|
|
203
|
+
type: "ITenantCreateRequest",
|
|
204
|
+
examples: [
|
|
205
|
+
{
|
|
206
|
+
id: "tenantCreateRequestExample",
|
|
207
|
+
description: "The request for the create tenant request.",
|
|
208
|
+
request: {
|
|
209
|
+
body: {
|
|
210
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
211
|
+
label: "node",
|
|
212
|
+
publicOrigin: "https://example.com:4321",
|
|
213
|
+
organizationId: "org-1"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
responseType: [
|
|
220
|
+
{
|
|
221
|
+
type: "ICreatedResponse"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
requiredScope: ["tenant-admin"]
|
|
225
|
+
};
|
|
226
|
+
const tenantUpdateRoute = {
|
|
227
|
+
operationId: "tenantUpdate",
|
|
228
|
+
summary: "Update an existing tenant",
|
|
229
|
+
tag: tagsTenants[0].name,
|
|
230
|
+
method: "PUT",
|
|
231
|
+
path: `${baseRouteName}/:id`,
|
|
232
|
+
handler: async (httpRequestContext, request) => tenantUpdate(httpRequestContext, componentName, request),
|
|
233
|
+
requestType: {
|
|
234
|
+
type: "ITenantUpdateRequest",
|
|
235
|
+
examples: [
|
|
236
|
+
{
|
|
237
|
+
id: "tenantUpdateRequestExample",
|
|
238
|
+
description: "The request for the update tenant request.",
|
|
239
|
+
request: {
|
|
240
|
+
pathParams: {
|
|
241
|
+
id: "2a39d6e62d98aa5372432f2e5d2208d4"
|
|
242
|
+
},
|
|
243
|
+
body: {
|
|
244
|
+
apiKey: "ad7a5b0b816ca314b69c813ae1368232",
|
|
245
|
+
label: "node",
|
|
246
|
+
publicOrigin: "https://example.com:4321",
|
|
247
|
+
organizationId: "org-1"
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
},
|
|
253
|
+
responseType: [
|
|
254
|
+
{
|
|
255
|
+
type: "INoContentResponse"
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
requiredScope: ["tenant-admin"]
|
|
259
|
+
};
|
|
260
|
+
return [
|
|
261
|
+
tenantListRoute,
|
|
262
|
+
tenantCreateRoute,
|
|
263
|
+
tenantGetByIdRoute,
|
|
264
|
+
tenantGetByApiKeyRoute,
|
|
265
|
+
tenantGetByPublicOriginRoute,
|
|
266
|
+
tenantRemoveRoute,
|
|
267
|
+
tenantUpdateRoute
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get the list of tenants.
|
|
272
|
+
* @param httpRequestContext The request context for the API.
|
|
273
|
+
* @param componentName The name of the component to use in the routes.
|
|
274
|
+
* @param request The request.
|
|
275
|
+
* @returns The response object with additional http response properties.
|
|
276
|
+
*/
|
|
277
|
+
export async function tenantList(httpRequestContext, componentName, request) {
|
|
278
|
+
const component = ComponentFactory.get(componentName);
|
|
279
|
+
const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions), HttpParameterHelper.arrayFromString(request.query?.properties), request.query?.cursor, Coerce.integer(request.query?.limit));
|
|
280
|
+
const headers = {};
|
|
281
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
282
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
283
|
+
HttpHeaderHelper.buildCursor(headers, httpRequestContext.serverRequest.url, publicOrigin, result.cursor);
|
|
284
|
+
return {
|
|
285
|
+
headers,
|
|
286
|
+
body: result.tenants.map(t => ({
|
|
287
|
+
...t,
|
|
288
|
+
publicOrigin: t.publicOrigin ?? publicOrigin
|
|
289
|
+
}))
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get the tenant by id.
|
|
294
|
+
* @param httpRequestContext The request context for the API.
|
|
295
|
+
* @param componentName The name of the component to use in the routes.
|
|
296
|
+
* @param request The request.
|
|
297
|
+
* @returns The response object with additional http response properties.
|
|
298
|
+
*/
|
|
299
|
+
export async function tenantById(httpRequestContext, componentName, request) {
|
|
300
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
301
|
+
const component = ComponentFactory.get(componentName);
|
|
302
|
+
const result = await component.get(request.pathParams.id);
|
|
303
|
+
if (!Is.stringValue(result.publicOrigin)) {
|
|
304
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
305
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
306
|
+
result.publicOrigin ??= publicOrigin;
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
body: result
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the tenant by api key.
|
|
314
|
+
* @param httpRequestContext The request context for the API.
|
|
315
|
+
* @param componentName The name of the component to use in the routes.
|
|
316
|
+
* @param request The request.
|
|
317
|
+
* @returns The response object with additional http response properties.
|
|
318
|
+
*/
|
|
319
|
+
export async function tenantByApiKey(httpRequestContext, componentName, request) {
|
|
320
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.apiKey", request.pathParams.apiKey);
|
|
321
|
+
const component = ComponentFactory.get(componentName);
|
|
322
|
+
const result = await component.getByApiKey(request.pathParams.apiKey);
|
|
323
|
+
if (!Is.stringValue(result.publicOrigin)) {
|
|
324
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
325
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
326
|
+
result.publicOrigin ??= publicOrigin;
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
body: result
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get the tenant by public origin.
|
|
334
|
+
* @param httpRequestContext The request context for the API.
|
|
335
|
+
* @param componentName The name of the component to use in the routes.
|
|
336
|
+
* @param request The request.
|
|
337
|
+
* @returns The response object with additional http response properties.
|
|
338
|
+
*/
|
|
339
|
+
export async function tenantByPublicOrigin(httpRequestContext, componentName, request) {
|
|
340
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.publicOrigin", request.pathParams.publicOrigin);
|
|
341
|
+
const component = ComponentFactory.get(componentName);
|
|
342
|
+
const result = await component.getByPublicOrigin(request.pathParams.publicOrigin);
|
|
343
|
+
if (!Is.stringValue(result.publicOrigin)) {
|
|
344
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
345
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
346
|
+
result.publicOrigin ??= publicOrigin;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
body: result
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Remove the tenant by id.
|
|
354
|
+
* @param httpRequestContext The request context for the API.
|
|
355
|
+
* @param componentName The name of the component to use in the routes.
|
|
356
|
+
* @param request The request.
|
|
357
|
+
* @returns The response object with additional http response properties.
|
|
358
|
+
*/
|
|
359
|
+
export async function tenantRemove(httpRequestContext, componentName, request) {
|
|
360
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
361
|
+
const component = ComponentFactory.get(componentName);
|
|
362
|
+
await component.remove(request.pathParams.id);
|
|
363
|
+
return {
|
|
364
|
+
statusCode: HttpStatusCode.noContent
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Create the tenant.
|
|
369
|
+
* @param httpRequestContext The request context for the API.
|
|
370
|
+
* @param componentName The name of the component to use in the routes.
|
|
371
|
+
* @param request The request.
|
|
372
|
+
* @param baseRouteName The base route name for the tenant.
|
|
373
|
+
* @returns The response object with additional http response properties.
|
|
374
|
+
*/
|
|
375
|
+
export async function tenantCreate(httpRequestContext, componentName, request, baseRouteName) {
|
|
376
|
+
Guards.stringValue(ROUTES_SOURCE, "request.body", request.body);
|
|
377
|
+
const component = ComponentFactory.get(componentName);
|
|
378
|
+
const createdId = await component.create(request.body);
|
|
379
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
380
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
381
|
+
const headers = {};
|
|
382
|
+
HttpHeaderHelper.buildId(headers, createdId, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`));
|
|
383
|
+
return {
|
|
384
|
+
statusCode: HttpStatusCode.created,
|
|
385
|
+
headers
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Update the tenant.
|
|
390
|
+
* @param httpRequestContext The request context for the API.
|
|
391
|
+
* @param componentName The name of the component to use in the routes.
|
|
392
|
+
* @param request The request.
|
|
393
|
+
* @returns The response object with additional http response properties.
|
|
394
|
+
*/
|
|
395
|
+
export async function tenantUpdate(httpRequestContext, componentName, request) {
|
|
396
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
397
|
+
Guards.stringValue(ROUTES_SOURCE, "request.body", request.body);
|
|
398
|
+
const component = ComponentFactory.get(componentName);
|
|
399
|
+
await component.update(request.body);
|
|
400
|
+
return {
|
|
401
|
+
statusCode: HttpStatusCode.noContent
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
//# sourceMappingURL=tenantRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantRoutes.js","sourceRoot":"","sources":["../../src/tenantRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,a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OAAO,CACvB,OAAO,EACP,SAAS,EACT,aAAa,CAAC,iBAAiB,CAAC,YAAY,EAAE,GAAG,aAAa,MAAM,CAAC,CACrE,CAAC;IAEF,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,OAAO;QAClC,OAAO;KACP,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,kBAAuC,EACvC,aAAqB,EACrB,OAA6B;IAE7B,MAAM,CAAC,WAAW,CAAC,aAAa,2BAAiC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACxF,MAAM,CAAC,WAAW,CAAC,aAAa,kBAAwB,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAwB,aAAa,CAAC,CAAC;IAE7E,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAErC,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpParameterHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag,\n\ttype ITenantAdminComponent\n} from \"@3sixty/api-models\";\nimport { ContextIdStore } from \"@3sixty/context\";\nimport { Coerce, ComponentFactory, Guards, Is } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HeaderTypes, HttpStatusCode, type IHttpHeaders } from \"@3sixty/web\";\nimport type { ITenantCreateRequest } from \"./models/api/ITenantCreateRequest.js\";\nimport type { ITenantGetByApiKeyRequest } from \"./models/api/ITenantGetByApiKeyRequest.js\";\nimport type { ITenantGetByIdRequest } from \"./models/api/ITenantGetByIdRequest.js\";\nimport type { ITenantGetByPublicOriginRequest } from \"./models/api/ITenantGetByPublicOriginRequest.js\";\nimport type { ITenantGetResponse } from \"./models/api/ITenantGetResponse.js\";\nimport type { ITenantListRequest } from \"./models/api/ITenantListRequest.js\";\nimport type { ITenantListResponse } from \"./models/api/ITenantListResponse.js\";\nimport type { ITenantRemoveRequest } from \"./models/api/ITenantRemoveRequest.js\";\nimport type { ITenantUpdateRequest } from \"./models/api/ITenantUpdateRequest.js\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"tenantRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsTenants: ITag[] = [\n\t{\n\t\tname: \"Tenants\",\n\t\tdescription: \"Tenants endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for tenant management.\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 generateRestRoutesTenants(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst tenantListRoute: IRestRoute<ITenantListRequest, ITenantListResponse> = {\n\t\toperationId: \"tenantList\",\n\t\tsummary: \"Get the list of tenants\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantList(httpRequestContext, componentName, request),\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITenantListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"tenantListResponse\",\n\t\t\t\t\t\tdescription: \"The response for the list tenants request.\",\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.Link]: '<https://api.3sixty.global/tenants/1>; rel=\"next\"'\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{\n\t\t\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\",\n\t\t\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\t\t\tdateCreated: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\t\tdateModified: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\",\n\t\t\t\t\t\t\t\t\torganizationId: \"org-1\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantGetByIdRoute: IRestRoute<ITenantGetByIdRequest, ITenantGetResponse> = {\n\t\toperationId: \"tenantGetById\",\n\t\tsummary: \"Get the tenant by id\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantById(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITenantGetByIdRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"tenantGetByIdRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\"\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<ITenantGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"tenantGetByIdResponse\",\n\t\t\t\t\t\tdescription: \"The response for the get tenant by id request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\",\n\t\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\t\tdateCreated: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\tdateModified: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\",\n\t\t\t\t\t\t\t\torganizationId: \"org-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\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantGetByApiKeyRoute: IRestRoute<ITenantGetByApiKeyRequest, ITenantGetResponse> = {\n\t\toperationId: \"tenantGetByApiKey\",\n\t\tsummary: \"Get the tenant by api key\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/api-key/:apiKey`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantByApiKey(httpRequestContext, componentName, request),\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITenantGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"tenantGetByApiKeyResponse\",\n\t\t\t\t\t\tdescription: \"The response for the get tenant by api key request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\",\n\t\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\t\tdateCreated: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\tdateModified: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\",\n\t\t\t\t\t\t\t\torganizationId: \"org-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\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantGetByPublicOriginRoute: IRestRoute = {\n\t\toperationId: \"tenantGetByPublicOrigin\",\n\t\tsummary: \"Get the tenant by public origin\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/public-origin/:publicOrigin`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantByPublicOrigin(httpRequestContext, componentName, request),\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITenantGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"tenantGetByPublicOriginResponse\",\n\t\t\t\t\t\tdescription: \"The response for the get tenant by public origin request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\",\n\t\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\t\tdateCreated: \"2026-01-19T03:59:35.742Z\",\n\t\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\"\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\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantRemoveRoute: IRestRoute<ITenantRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"tenantRemove\",\n\t\tsummary: \"Remove the tenant by id\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITenantRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"tenantRemoveRequestExample\",\n\t\t\t\t\tdescription: \"The request for the remove tenant by id request.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantCreateRoute: IRestRoute<ITenantCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"tenantCreate\",\n\t\tsummary: \"Create a new tenant\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantCreate(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<ITenantCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"tenantCreateRequestExample\",\n\t\t\t\t\tdescription: \"The request for the create tenant request.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\",\n\t\t\t\t\t\t\torganizationId: \"org-1\"\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}\n\t\t],\n\t\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\tconst tenantUpdateRoute: IRestRoute<ITenantUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"tenantUpdate\",\n\t\tsummary: \"Update an existing tenant\",\n\t\ttag: tagsTenants[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttenantUpdate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITenantUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"tenantUpdateRequestExample\",\n\t\t\t\t\tdescription: \"The request for the update tenant request.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"2a39d6e62d98aa5372432f2e5d2208d4\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tapiKey: \"ad7a5b0b816ca314b69c813ae1368232\",\n\t\t\t\t\t\t\tlabel: \"node\",\n\t\t\t\t\t\t\tpublicOrigin: \"https://example.com:4321\",\n\t\t\t\t\t\t\torganizationId: \"org-1\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"tenant-admin\"]\n\t};\n\n\treturn [\n\t\ttenantListRoute,\n\t\ttenantCreateRoute,\n\t\ttenantGetByIdRoute,\n\t\ttenantGetByApiKeyRoute,\n\t\ttenantGetByPublicOriginRoute,\n\t\ttenantRemoveRoute,\n\t\ttenantUpdateRoute\n\t];\n}\n\n/**\n * Get the list of tenants.\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 tenantList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantListRequest\n): Promise<ITenantListResponse> {\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tconst result = await component.query(\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\tHttpParameterHelper.arrayFromString(request.query?.properties),\n\t\trequest.query?.cursor,\n\t\tCoerce.integer(request.query?.limit)\n\t);\n\n\tconst headers: ITenantListResponse[\"headers\"] = {};\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tHttpHeaderHelper.buildCursor(\n\t\theaders,\n\t\thttpRequestContext.serverRequest.url,\n\t\tpublicOrigin,\n\t\tresult.cursor\n\t);\n\n\treturn {\n\t\theaders,\n\t\tbody: result.tenants.map(t => ({\n\t\t\t...t,\n\t\t\tpublicOrigin: t.publicOrigin ?? publicOrigin\n\t\t}))\n\t};\n}\n\n/**\n * Get the tenant by id.\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 tenantById(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantGetByIdRequest\n): Promise<ITenantGetResponse> {\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tconst result = await component.get(request.pathParams.id);\n\n\tif (!Is.stringValue(result.publicOrigin)) {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\t\tresult.publicOrigin ??= publicOrigin;\n\t}\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get the tenant by api key.\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 tenantByApiKey(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantGetByApiKeyRequest\n): Promise<ITenantGetResponse> {\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.apiKey), request.pathParams.apiKey);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tconst result = await component.getByApiKey(request.pathParams.apiKey);\n\n\tif (!Is.stringValue(result.publicOrigin)) {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\t\tresult.publicOrigin ??= publicOrigin;\n\t}\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get the tenant by public origin.\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 tenantByPublicOrigin(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantGetByPublicOriginRequest\n): Promise<ITenantGetResponse> {\n\tGuards.stringValue(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams.publicOrigin),\n\t\trequest.pathParams.publicOrigin\n\t);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tconst result = await component.getByPublicOrigin(request.pathParams.publicOrigin);\n\n\tif (!Is.stringValue(result.publicOrigin)) {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\t\tresult.publicOrigin ??= publicOrigin;\n\t}\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Remove the tenant by id.\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 tenantRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tawait component.remove(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Create the tenant.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name for the tenant.\n * @returns The response object with additional http response properties.\n */\nexport async function tenantCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tconst createdId = await component.create(request.body);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\tcreatedId,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * Update the tenant.\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 tenantUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITenantUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\tconst component = ComponentFactory.get<ITenantAdminComponent>(componentName);\n\n\tawait component.update(request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2025 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { RandomHelper } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for tenant id related operations.
|
|
6
|
+
*/
|
|
7
|
+
export class TenantIdHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Generates a new tenant ID.
|
|
10
|
+
* @returns A new tenant ID.
|
|
11
|
+
*/
|
|
12
|
+
static generateTenantId() {
|
|
13
|
+
return RandomHelper.generateUuidV7("compact");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates a new API Key.
|
|
17
|
+
* @returns A new API Key.
|
|
18
|
+
*/
|
|
19
|
+
static generateApiKey() {
|
|
20
|
+
return RandomHelper.generateUuidV7("compact");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=tenantIdHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantIdHelper.js","sourceRoot":"","sources":["../../../src/utils/tenantIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B;;;OAGG;IACI,MAAM,CAAC,gBAAgB;QAC7B,OAAO,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc;QAC3B,OAAO,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;CACD","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { RandomHelper } from \"@3sixty/core\";\n\n/**\n * Helper class for tenant id related operations.\n */\nexport class TenantIdHelper {\n\t/**\n\t * Generates a new tenant ID.\n\t * @returns A new tenant ID.\n\t */\n\tpublic static generateTenantId(): string {\n\t\treturn RandomHelper.generateUuidV7(\"compact\");\n\t}\n\n\t/**\n\t * Generates a new API Key.\n\t * @returns A new API Key.\n\t */\n\tpublic static generateApiKey(): string {\n\t\treturn RandomHelper.generateUuidV7(\"compact\");\n\t}\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Tenant {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The organization id for the tenant.
|
|
31
|
+
*/
|
|
32
|
+
organizationId: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of organization aliases that can be used for legacy lookups, indexed format.
|
|
35
|
+
*/
|
|
36
|
+
organizationIdLegacy?: string[];
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TenantV0 {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TenantV1 {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The organization id for the tenant.
|
|
31
|
+
*/
|
|
32
|
+
organizationId: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of organization aliases that can be used for legacy lookups, indexed format.
|
|
35
|
+
*/
|
|
36
|
+
organizationIdLegacy?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./entities/tenant.js";
|
|
2
|
+
export * from "./models/api/ITenantCreateRequest.js";
|
|
3
|
+
export * from "./models/api/ITenantGetByApiKeyRequest.js";
|
|
4
|
+
export * from "./models/api/ITenantGetByIdRequest.js";
|
|
5
|
+
export * from "./models/api/ITenantGetByPublicOriginRequest.js";
|
|
6
|
+
export * from "./models/api/ITenantGetResponse.js";
|
|
7
|
+
export * from "./models/api/ITenantListRequest.js";
|
|
8
|
+
export * from "./models/api/ITenantListResponse.js";
|
|
9
|
+
export * from "./models/api/ITenantRemoveRequest.js";
|
|
10
|
+
export * from "./models/api/ITenantUpdateRequest.js";
|
|
11
|
+
export * from "./models/ISingleTenantProcessorConfig.js";
|
|
12
|
+
export * from "./models/ISingleTenantProcessorConstructorOptions.js";
|
|
13
|
+
export * from "./models/ITenantAdminServiceConfig.js";
|
|
14
|
+
export * from "./models/ITenantAdminServiceConstructorOptions.js";
|
|
15
|
+
export * from "./models/ITenantOverrideProcessorConfig.js";
|
|
16
|
+
export * from "./models/ITenantOverrideProcessorConstructorOptions.js";
|
|
17
|
+
export * from "./models/ITenantProcessorConfig.js";
|
|
18
|
+
export * from "./models/ITenantProcessorConstructorOptions.js";
|
|
19
|
+
export * from "./schema.js";
|
|
20
|
+
export * from "./singleTenantProcessor.js";
|
|
21
|
+
export * from "./tenantAdminService.js";
|
|
22
|
+
export * from "./tenantIdContextIdHandler.js";
|
|
23
|
+
export * from "./tenantOverrideProcessor.js";
|
|
24
|
+
export * from "./tenantProcessor.js";
|
|
25
|
+
export * from "./tenantRoutes.js";
|
|
26
|
+
export * from "./utils/tenantIdHelper.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ISingleTenantProcessorConfig } from "./ISingleTenantProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Single Tenant Processor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface ISingleTenantProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config?: ISingleTenantProcessorConfig;
|
|
10
|
+
}
|