@3sixty/api-models 0.0.0-stage → 0.20.0-next.1
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/errors/forbiddenError.js +23 -0
- package/dist/es/errors/forbiddenError.js.map +1 -0
- package/dist/es/errors/tooManyRequestsError.js +25 -0
- package/dist/es/errors/tooManyRequestsError.js.map +1 -0
- package/dist/es/factories/mimeTypeProcessorFactory.js +9 -0
- package/dist/es/factories/mimeTypeProcessorFactory.js.map +1 -0
- package/dist/es/factories/restClientProcessorFactory.js +9 -0
- package/dist/es/factories/restClientProcessorFactory.js.map +1 -0
- package/dist/es/factories/restRouteProcessorFactory.js +9 -0
- package/dist/es/factories/restRouteProcessorFactory.js.map +1 -0
- package/dist/es/factories/socketRouteProcessorFactory.js +9 -0
- package/dist/es/factories/socketRouteProcessorFactory.js.map +1 -0
- package/dist/es/helpers/httpErrorHelper.js +75 -0
- package/dist/es/helpers/httpErrorHelper.js.map +1 -0
- package/dist/es/helpers/httpHeaderHelper.js +120 -0
- package/dist/es/helpers/httpHeaderHelper.js.map +1 -0
- package/dist/es/helpers/httpParameterHelper.js +41 -0
- package/dist/es/helpers/httpParameterHelper.js.map +1 -0
- package/dist/es/helpers/httpUrlHelper.js +156 -0
- package/dist/es/helpers/httpUrlHelper.js.map +1 -0
- package/dist/es/index.js +81 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IHealth.js +2 -0
- package/dist/es/models/IHealth.js.map +1 -0
- package/dist/es/models/api/IServerFavIconResponse.js +2 -0
- package/dist/es/models/api/IServerFavIconResponse.js.map +1 -0
- package/dist/es/models/api/IServerHealthResponse.js +2 -0
- package/dist/es/models/api/IServerHealthResponse.js.map +1 -0
- package/dist/es/models/api/IServerInfoResponse.js +2 -0
- package/dist/es/models/api/IServerInfoResponse.js.map +1 -0
- package/dist/es/models/api/IServerLivezResponse.js +2 -0
- package/dist/es/models/api/IServerLivezResponse.js.map +1 -0
- package/dist/es/models/api/IServerReadyzResponse.js +2 -0
- package/dist/es/models/api/IServerReadyzResponse.js.map +1 -0
- package/dist/es/models/api/IServerRootResponse.js +2 -0
- package/dist/es/models/api/IServerRootResponse.js.map +1 -0
- package/dist/es/models/api/IServerSpecResponse.js +2 -0
- package/dist/es/models/api/IServerSpecResponse.js.map +1 -0
- package/dist/es/models/client/IRestClientProcessor.js +2 -0
- package/dist/es/models/client/IRestClientProcessor.js.map +1 -0
- package/dist/es/models/client/IRestClientProcessorContext.js +2 -0
- package/dist/es/models/client/IRestClientProcessorContext.js.map +1 -0
- package/dist/es/models/config/IBaseRestClientConfig.js +2 -0
- package/dist/es/models/config/IBaseRestClientConfig.js.map +1 -0
- package/dist/es/models/config/IBaseSocketClientConfig.js +2 -0
- package/dist/es/models/config/IBaseSocketClientConfig.js.map +1 -0
- package/dist/es/models/healthCategory.js +17 -0
- package/dist/es/models/healthCategory.js.map +1 -0
- package/dist/es/models/healthStatus.js +21 -0
- package/dist/es/models/healthStatus.js.map +1 -0
- package/dist/es/models/httpContextIdKeys.js +39 -0
- package/dist/es/models/httpContextIdKeys.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequest.js +2 -0
- package/dist/es/models/protocol/IHttpRequest.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestContext.js +2 -0
- package/dist/es/models/protocol/IHttpRequestContext.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestPathParams.js +4 -0
- package/dist/es/models/protocol/IHttpRequestPathParams.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestQuery.js +4 -0
- package/dist/es/models/protocol/IHttpRequestQuery.js.map +1 -0
- package/dist/es/models/protocol/IHttpResponse.js +2 -0
- package/dist/es/models/protocol/IHttpResponse.js.map +1 -0
- package/dist/es/models/protocol/IHttpServerRequest.js +2 -0
- package/dist/es/models/protocol/IHttpServerRequest.js.map +1 -0
- package/dist/es/models/protocol/ISocketRequestContext.js +2 -0
- package/dist/es/models/protocol/ISocketRequestContext.js.map +1 -0
- package/dist/es/models/protocol/ISocketServerRequest.js +2 -0
- package/dist/es/models/protocol/ISocketServerRequest.js.map +1 -0
- package/dist/es/models/requests/INoContentRequest.js +2 -0
- package/dist/es/models/requests/INoContentRequest.js.map +1 -0
- package/dist/es/models/responses/errors/IBadRequestResponse.js +2 -0
- package/dist/es/models/responses/errors/IBadRequestResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IConflictResponse.js +2 -0
- package/dist/es/models/responses/errors/IConflictResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IForbiddenResponse.js +2 -0
- package/dist/es/models/responses/errors/IForbiddenResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IInternalServerErrorResponse.js +2 -0
- package/dist/es/models/responses/errors/IInternalServerErrorResponse.js.map +1 -0
- package/dist/es/models/responses/errors/INotFoundResponse.js +2 -0
- package/dist/es/models/responses/errors/INotFoundResponse.js.map +1 -0
- package/dist/es/models/responses/errors/INotImplementedResponse.js +2 -0
- package/dist/es/models/responses/errors/INotImplementedResponse.js.map +1 -0
- package/dist/es/models/responses/errors/ITooManyRequestsResponse.js +2 -0
- package/dist/es/models/responses/errors/ITooManyRequestsResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IUnauthorizedResponse.js +2 -0
- package/dist/es/models/responses/errors/IUnauthorizedResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IUnprocessableEntityResponse.js +2 -0
- package/dist/es/models/responses/errors/IUnprocessableEntityResponse.js.map +1 -0
- package/dist/es/models/responses/success/IAcceptedResponse.js +2 -0
- package/dist/es/models/responses/success/IAcceptedResponse.js.map +1 -0
- package/dist/es/models/responses/success/ICreatedResponse.js +2 -0
- package/dist/es/models/responses/success/ICreatedResponse.js.map +1 -0
- package/dist/es/models/responses/success/INoContentResponse.js +2 -0
- package/dist/es/models/responses/success/INoContentResponse.js.map +1 -0
- package/dist/es/models/responses/success/IOkResponse.js +2 -0
- package/dist/es/models/responses/success/IOkResponse.js.map +1 -0
- package/dist/es/models/routes/IBaseRoute.js +2 -0
- package/dist/es/models/routes/IBaseRoute.js.map +1 -0
- package/dist/es/models/routes/IBaseRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/IBaseRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/IRestRoute.js +2 -0
- package/dist/es/models/routes/IRestRoute.js.map +1 -0
- package/dist/es/models/routes/IRestRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/IRestRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/IRestRouteExample.js +4 -0
- package/dist/es/models/routes/IRestRouteExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteRequestExample.js +2 -0
- package/dist/es/models/routes/IRestRouteRequestExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseAttachmentOptions.js +4 -0
- package/dist/es/models/routes/IRestRouteResponseAttachmentOptions.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseExample.js +2 -0
- package/dist/es/models/routes/IRestRouteResponseExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseOptions.js +2 -0
- package/dist/es/models/routes/IRestRouteResponseOptions.js.map +1 -0
- package/dist/es/models/routes/IRouteAuthorization.js +4 -0
- package/dist/es/models/routes/IRouteAuthorization.js.map +1 -0
- package/dist/es/models/routes/ISocketRoute.js +2 -0
- package/dist/es/models/routes/ISocketRoute.js.map +1 -0
- package/dist/es/models/routes/ISocketRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/ISocketRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/ITag.js +4 -0
- package/dist/es/models/routes/ITag.js.map +1 -0
- package/dist/es/models/routes/httpBodyLimit.js +17 -0
- package/dist/es/models/routes/httpBodyLimit.js.map +1 -0
- package/dist/es/models/server/IBaseRouteProcessor.js +2 -0
- package/dist/es/models/server/IBaseRouteProcessor.js.map +1 -0
- package/dist/es/models/server/IMimeTypeProcessor.js +2 -0
- package/dist/es/models/server/IMimeTypeProcessor.js.map +1 -0
- package/dist/es/models/server/IRestRouteProcessor.js +2 -0
- package/dist/es/models/server/IRestRouteProcessor.js.map +1 -0
- package/dist/es/models/server/ISocketRouteProcessor.js +2 -0
- package/dist/es/models/server/ISocketRouteProcessor.js.map +1 -0
- package/dist/es/models/server/IWebServer.js +2 -0
- package/dist/es/models/server/IWebServer.js.map +1 -0
- package/dist/es/models/server/IWebServerOptions.js +2 -0
- package/dist/es/models/server/IWebServerOptions.js.map +1 -0
- package/dist/es/models/services/IHealthApplicationCallback.js +2 -0
- package/dist/es/models/services/IHealthApplicationCallback.js.map +1 -0
- package/dist/es/models/services/IHealthComponent.js +2 -0
- package/dist/es/models/services/IHealthComponent.js.map +1 -0
- package/dist/es/models/services/IHealthProviderComponent.js +2 -0
- package/dist/es/models/services/IHealthProviderComponent.js.map +1 -0
- package/dist/es/models/services/IInformationComponent.js +2 -0
- package/dist/es/models/services/IInformationComponent.js.map +1 -0
- package/dist/es/models/services/IPlatformComponent.js +2 -0
- package/dist/es/models/services/IPlatformComponent.js.map +1 -0
- package/dist/es/models/services/IServerInfo.js +4 -0
- package/dist/es/models/services/IServerInfo.js.map +1 -0
- package/dist/es/models/services/ITenant.js +4 -0
- package/dist/es/models/services/ITenant.js.map +1 -0
- package/dist/es/models/services/ITenantAdminComponent.js +2 -0
- package/dist/es/models/services/ITenantAdminComponent.js.map +1 -0
- package/dist/es/models/services/tenantEventCallback.js +2 -0
- package/dist/es/models/services/tenantEventCallback.js.map +1 -0
- package/dist/es/models/services/tenantEventType.js +21 -0
- package/dist/es/models/services/tenantEventType.js.map +1 -0
- package/dist/types/errors/forbiddenError.d.ts +20 -0
- package/dist/types/errors/tooManyRequestsError.d.ts +22 -0
- package/dist/types/factories/mimeTypeProcessorFactory.d.ts +6 -0
- package/dist/types/factories/restClientProcessorFactory.d.ts +6 -0
- package/dist/types/factories/restRouteProcessorFactory.d.ts +6 -0
- package/dist/types/factories/socketRouteProcessorFactory.d.ts +6 -0
- package/dist/types/helpers/httpErrorHelper.d.ts +32 -0
- package/dist/types/helpers/httpHeaderHelper.d.ts +62 -0
- package/dist/types/helpers/httpParameterHelper.d.ts +29 -0
- package/dist/types/helpers/httpUrlHelper.d.ts +73 -0
- package/dist/types/index.d.ts +77 -0
- package/dist/types/models/IHealth.d.ts +42 -0
- package/dist/types/models/api/IServerFavIconResponse.d.ts +23 -0
- package/dist/types/models/api/IServerHealthResponse.d.ts +14 -0
- package/dist/types/models/api/IServerInfoResponse.d.ts +10 -0
- package/dist/types/models/api/IServerLivezResponse.d.ts +16 -0
- package/dist/types/models/api/IServerReadyzResponse.d.ts +16 -0
- package/dist/types/models/api/IServerRootResponse.d.ts +16 -0
- package/dist/types/models/api/IServerSpecResponse.d.ts +14 -0
- package/dist/types/models/client/IRestClientProcessor.d.ts +22 -0
- package/dist/types/models/client/IRestClientProcessorContext.d.ts +42 -0
- package/dist/types/models/config/IBaseRestClientConfig.d.ts +46 -0
- package/dist/types/models/config/IBaseSocketClientConfig.d.ts +22 -0
- package/dist/types/models/healthCategory.d.ts +17 -0
- package/dist/types/models/healthStatus.d.ts +21 -0
- package/dist/types/models/httpContextIdKeys.d.ts +38 -0
- package/dist/types/models/protocol/IHttpRequest.d.ts +24 -0
- package/dist/types/models/protocol/IHttpRequestContext.d.ts +20 -0
- package/dist/types/models/protocol/IHttpRequestPathParams.d.ts +6 -0
- package/dist/types/models/protocol/IHttpRequestQuery.d.ts +6 -0
- package/dist/types/models/protocol/IHttpResponse.d.ts +18 -0
- package/dist/types/models/protocol/IHttpServerRequest.d.ts +15 -0
- package/dist/types/models/protocol/ISocketRequestContext.d.ts +10 -0
- package/dist/types/models/protocol/ISocketServerRequest.d.ts +10 -0
- package/dist/types/models/requests/INoContentRequest.d.ts +22 -0
- package/dist/types/models/responses/errors/IBadRequestResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/IConflictResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/IForbiddenResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/IInternalServerErrorResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/INotFoundResponse.d.ts +20 -0
- package/dist/types/models/responses/errors/INotImplementedResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/ITooManyRequestsResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/IUnauthorizedResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/IUnprocessableEntityResponse.d.ts +15 -0
- package/dist/types/models/responses/success/IAcceptedResponse.d.ts +19 -0
- package/dist/types/models/responses/success/ICreatedResponse.d.ts +19 -0
- package/dist/types/models/responses/success/INoContentResponse.d.ts +10 -0
- package/dist/types/models/responses/success/IOkResponse.d.ts +10 -0
- package/dist/types/models/routes/IBaseRoute.d.ts +39 -0
- package/dist/types/models/routes/IBaseRouteEntryPoint.d.ts +22 -0
- package/dist/types/models/routes/IRestRoute.d.ts +80 -0
- package/dist/types/models/routes/IRestRouteEntryPoint.d.ts +6 -0
- package/dist/types/models/routes/IRestRouteExample.d.ts +13 -0
- package/dist/types/models/routes/IRestRouteRequestExample.d.ts +10 -0
- package/dist/types/models/routes/IRestRouteResponseAttachmentOptions.d.ts +17 -0
- package/dist/types/models/routes/IRestRouteResponseExample.d.ts +10 -0
- package/dist/types/models/routes/IRestRouteResponseOptions.d.ts +10 -0
- package/dist/types/models/routes/IRouteAuthorization.d.ts +17 -0
- package/dist/types/models/routes/ISocketRoute.d.ts +41 -0
- package/dist/types/models/routes/ISocketRouteEntryPoint.d.ts +6 -0
- package/dist/types/models/routes/ITag.d.ts +13 -0
- package/dist/types/models/routes/httpBodyLimit.d.ts +17 -0
- package/dist/types/models/server/IBaseRouteProcessor.d.ts +42 -0
- package/dist/types/models/server/IMimeTypeProcessor.d.ts +17 -0
- package/dist/types/models/server/IRestRouteProcessor.d.ts +24 -0
- package/dist/types/models/server/ISocketRouteProcessor.d.ts +38 -0
- package/dist/types/models/server/IWebServer.d.ts +36 -0
- package/dist/types/models/server/IWebServerOptions.d.ts +54 -0
- package/dist/types/models/services/IHealthApplicationCallback.d.ts +6 -0
- package/dist/types/models/services/IHealthComponent.d.ts +16 -0
- package/dist/types/models/services/IHealthProviderComponent.d.ts +31 -0
- package/dist/types/models/services/IInformationComponent.d.ts +41 -0
- package/dist/types/models/services/IPlatformComponent.d.ts +44 -0
- package/dist/types/models/services/IServerInfo.d.ts +13 -0
- package/dist/types/models/services/ITenant.d.ts +37 -0
- package/dist/types/models/services/ITenantAdminComponent.d.ts +70 -0
- package/dist/types/models/services/tenantEventCallback.d.ts +6 -0
- package/dist/types/models/services/tenantEventType.d.ts +21 -0
- package/docs/changelog.md +10 -0
- package/docs/examples.md +200 -0
- package/docs/reference/classes/ForbiddenError.md +57 -0
- package/docs/reference/classes/HttpErrorHelper.md +99 -0
- package/docs/reference/classes/HttpHeaderHelper.md +182 -0
- package/docs/reference/classes/HttpParameterHelper.md +125 -0
- package/docs/reference/classes/HttpUrlHelper.md +262 -0
- package/docs/reference/classes/TooManyRequestsError.md +69 -0
- package/docs/reference/index.md +95 -0
- package/docs/reference/interfaces/IAcceptedResponse.md +25 -0
- package/docs/reference/interfaces/IBadRequestResponse.md +19 -0
- package/docs/reference/interfaces/IBaseRestClientConfig.md +99 -0
- package/docs/reference/interfaces/IBaseRoute.md +89 -0
- package/docs/reference/interfaces/IBaseRouteEntryPoint.md +55 -0
- package/docs/reference/interfaces/IBaseRouteProcessor.md +134 -0
- package/docs/reference/interfaces/IBaseSocketClientConfig.md +35 -0
- package/docs/reference/interfaces/IConflictResponse.md +19 -0
- package/docs/reference/interfaces/ICreatedResponse.md +25 -0
- package/docs/reference/interfaces/IForbiddenResponse.md +19 -0
- package/docs/reference/interfaces/IHealth.md +71 -0
- package/docs/reference/interfaces/IHealthComponent.md +21 -0
- package/docs/reference/interfaces/IHealthProviderComponent.md +76 -0
- package/docs/reference/interfaces/IHttpRequest.md +46 -0
- package/docs/reference/interfaces/IHttpRequestContext.md +35 -0
- package/docs/reference/interfaces/IHttpRequestPathParams.md +7 -0
- package/docs/reference/interfaces/IHttpRequestQuery.md +7 -0
- package/docs/reference/interfaces/IHttpResponse.md +33 -0
- package/docs/reference/interfaces/IHttpServerRequest.md +81 -0
- package/docs/reference/interfaces/IInformationComponent.md +91 -0
- package/docs/reference/interfaces/IInternalServerErrorResponse.md +19 -0
- package/docs/reference/interfaces/IMimeTypeProcessor.md +43 -0
- package/docs/reference/interfaces/INoContentRequest.md +55 -0
- package/docs/reference/interfaces/INoContentResponse.md +11 -0
- package/docs/reference/interfaces/INotFoundResponse.md +27 -0
- package/docs/reference/interfaces/INotImplementedResponse.md +19 -0
- package/docs/reference/interfaces/IOkResponse.md +11 -0
- package/docs/reference/interfaces/IPlatformComponent.md +139 -0
- package/docs/reference/interfaces/IRestClientProcessor.md +69 -0
- package/docs/reference/interfaces/IRestClientProcessorContext.md +75 -0
- package/docs/reference/interfaces/IRestRoute.md +245 -0
- package/docs/reference/interfaces/IRestRouteExample.md +24 -0
- package/docs/reference/interfaces/IRestRouteProcessor.md +177 -0
- package/docs/reference/interfaces/IRestRouteRequestExample.md +45 -0
- package/docs/reference/interfaces/IRestRouteResponseAttachmentOptions.md +27 -0
- package/docs/reference/interfaces/IRestRouteResponseExample.md +45 -0
- package/docs/reference/interfaces/IRestRouteResponseOptions.md +11 -0
- package/docs/reference/interfaces/IRouteAuthorization.md +27 -0
- package/docs/reference/interfaces/IServerFavIconResponse.md +33 -0
- package/docs/reference/interfaces/IServerHealthResponse.md +19 -0
- package/docs/reference/interfaces/IServerInfo.md +19 -0
- package/docs/reference/interfaces/IServerInfoResponse.md +11 -0
- package/docs/reference/interfaces/IServerLivezResponse.md +23 -0
- package/docs/reference/interfaces/IServerReadyzResponse.md +23 -0
- package/docs/reference/interfaces/IServerRootResponse.md +23 -0
- package/docs/reference/interfaces/IServerSpecResponse.md +19 -0
- package/docs/reference/interfaces/ISocketRequestContext.md +55 -0
- package/docs/reference/interfaces/ISocketRoute.md +198 -0
- package/docs/reference/interfaces/ISocketRouteProcessor.md +247 -0
- package/docs/reference/interfaces/ISocketServerRequest.md +93 -0
- package/docs/reference/interfaces/ITag.md +19 -0
- package/docs/reference/interfaces/ITenant.md +67 -0
- package/docs/reference/interfaces/ITenantAdminComponent.md +227 -0
- package/docs/reference/interfaces/ITooManyRequestsResponse.md +19 -0
- package/docs/reference/interfaces/IUnauthorizedResponse.md +19 -0
- package/docs/reference/interfaces/IUnprocessableEntityResponse.md +19 -0
- package/docs/reference/interfaces/IWebServer.md +109 -0
- package/docs/reference/interfaces/IWebServerOptions.md +113 -0
- package/docs/reference/type-aliases/HealthApplicationCallback.md +16 -0
- package/docs/reference/type-aliases/HealthCategory.md +5 -0
- package/docs/reference/type-aliases/HealthStatus.md +5 -0
- package/docs/reference/type-aliases/HttpBodyLimit.md +5 -0
- package/docs/reference/type-aliases/HttpContextIdKeys.md +5 -0
- package/docs/reference/type-aliases/IRestRouteEntryPoint.md +5 -0
- package/docs/reference/type-aliases/ISocketRouteEntryPoint.md +5 -0
- package/docs/reference/type-aliases/TenantEventCallback.md +20 -0
- package/docs/reference/type-aliases/TenantEventType.md +5 -0
- package/docs/reference/variables/HealthCategory.md +19 -0
- package/docs/reference/variables/HealthStatus.md +25 -0
- package/docs/reference/variables/HttpBodyLimit.md +19 -0
- package/docs/reference/variables/HttpContextIdKeys.md +50 -0
- package/docs/reference/variables/MimeTypeProcessorFactory.md +5 -0
- package/docs/reference/variables/RestClientProcessorFactory.md +5 -0
- package/docs/reference/variables/RestRouteProcessorFactory.md +5 -0
- package/docs/reference/variables/SocketRouteProcessorFactory.md +5 -0
- package/docs/reference/variables/TenantEventType.md +25 -0
- package/locales/en.json +8 -0
- package/package.json +53 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 3Sixty API Models
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package provides shared API contracts, route types, and response models used across services and clients.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @3sixty/api-models
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
22
|
+
|
|
23
|
+
## Origin
|
|
24
|
+
|
|
25
|
+
This package is derived from the original [iotaledger/twin-api](https://github.com/iotaledger/twin-api/tree/next/packages/api-models) repository.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseError } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle errors which are triggered by forbidden actions.
|
|
6
|
+
*/
|
|
7
|
+
export class ForbiddenError extends BaseError {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "ForbiddenError";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of ForbiddenError.
|
|
14
|
+
* @param source The source of the error.
|
|
15
|
+
* @param message The message as a code.
|
|
16
|
+
* @param properties Any additional information for the error.
|
|
17
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
18
|
+
*/
|
|
19
|
+
constructor(source, message, properties, cause) {
|
|
20
|
+
super(ForbiddenError.CLASS_NAME, source, message, properties, cause);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=forbiddenError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbiddenError.js","sources":["../../../src/errors/forbiddenError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC5C;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,gBAAgB,CAAC;IAE7D;;;;;;OAMG;IACH,YACC,MAAc,EACd,OAAe,EACf,UAAsC,EACtC,KAAe;QAEf,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@3sixty/core\";\n\n\n/**\n * Class to handle errors which are triggered by forbidden actions.\n */\nexport class ForbiddenError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"ForbiddenError\";\n\n\t/**\n\t * Create a new instance of ForbiddenError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(ForbiddenError.CLASS_NAME, source, message, properties, cause);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseError } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle errors which are triggered by too many requests.
|
|
6
|
+
*/
|
|
7
|
+
export class TooManyRequestsError extends BaseError {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "TooManyRequestsError";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of TooManyRequestsError.
|
|
14
|
+
* @param source The source of the error.
|
|
15
|
+
* @param message The message as a code.
|
|
16
|
+
* @param requestCount The current request count.
|
|
17
|
+
* @param nextRequestTime The time when the next request can be made, as date ISO string.
|
|
18
|
+
* @param properties Any additional information for the error.
|
|
19
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
20
|
+
*/
|
|
21
|
+
constructor(source, message, requestCount, nextRequestTime, properties, cause) {
|
|
22
|
+
super(TooManyRequestsError.CLASS_NAME, source, message, { requestCount, nextRequestTime, ...properties }, cause);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tooManyRequestsError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooManyRequestsError.js","sources":["../../../src/errors/tooManyRequestsError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAClD;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,sBAAsB,CAAC;IAEnE;;;;;;;;OAQG;IACH,YACC,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,eAAuB,EACvB,UAAsC,EACtC,KAAe;QAEf,KAAK,CACJ,oBAAoB,CAAC,UAAU,EAC/B,MAAM,EACN,OAAO,EACP,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,EAChD,KAAK,CACL,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@3sixty/core\";\n\n\n/**\n * Class to handle errors which are triggered by too many requests.\n */\nexport class TooManyRequestsError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"TooManyRequestsError\";\n\n\t/**\n\t * Create a new instance of TooManyRequestsError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param requestCount The current request count.\n\t * @param nextRequestTime The time when the next request can be made, as date ISO string.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\trequestCount: number,\n\t\tnextRequestTime: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(\n\t\t\tTooManyRequestsError.CLASS_NAME,\n\t\t\tsource,\n\t\t\tmessage,\n\t\t\t{ requestCount, nextRequestTime, ...properties },\n\t\t\tcause\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating implementation of mime type processor types.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const MimeTypeProcessorFactory = Factory.createFactory("mime-type-processor");
|
|
9
|
+
//# sourceMappingURL=mimeTypeProcessorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mimeTypeProcessorFactory.js","sources":["../../../src/factories/mimeTypeProcessorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,wBAAwB,GACpC,OAAO,CAAC,aAAa,CAAqB,qBAAqB,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { IMimeTypeProcessor } from \"../models/server/IMimeTypeProcessor.js\";\n\n/**\n * Factory for creating implementation of mime type processor types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const MimeTypeProcessorFactory =\n\tFactory.createFactory<IMimeTypeProcessor>(\"mime-type-processor\");\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating implementation of REST client processor types.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const RestClientProcessorFactory = Factory.createFactory("rest-client-processor");
|
|
9
|
+
//# sourceMappingURL=restClientProcessorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restClientProcessorFactory.js","sources":["../../../src/factories/restClientProcessorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,0BAA0B,GACtC,OAAO,CAAC,aAAa,CAAuB,uBAAuB,CAAC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { IRestClientProcessor } from \"../models/client/IRestClientProcessor.js\";\n\n/**\n * Factory for creating implementation of REST client processor types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const RestClientProcessorFactory =\n\tFactory.createFactory<IRestClientProcessor>(\"rest-client-processor\");\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating implementation of REST route processor types.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const RestRouteProcessorFactory = Factory.createFactory("rest-route-processor");
|
|
9
|
+
//# sourceMappingURL=restRouteProcessorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restRouteProcessorFactory.js","sources":["../../../src/factories/restRouteProcessorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,yBAAyB,GACrC,OAAO,CAAC,aAAa,CAAsB,sBAAsB,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { IRestRouteProcessor } from \"../models/server/IRestRouteProcessor.js\";\n\n/**\n * Factory for creating implementation of REST route processor types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const RestRouteProcessorFactory =\n\tFactory.createFactory<IRestRouteProcessor>(\"rest-route-processor\");\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating implementation of socket route processor types.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const SocketRouteProcessorFactory = Factory.createFactory("socket-route-processor");
|
|
9
|
+
//# sourceMappingURL=socketRouteProcessorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketRouteProcessorFactory.js","sources":["../../../src/factories/socketRouteProcessorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,2BAA2B,GACvC,OAAO,CAAC,aAAa,CAAwB,wBAAwB,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@3sixty/core\";\nimport type { ISocketRouteProcessor } from \"../models/server/ISocketRouteProcessor.js\";\n\n/**\n * Factory for creating implementation of socket route processor types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const SocketRouteProcessorFactory =\n\tFactory.createFactory<ISocketRouteProcessor>(\"socket-route-processor\");\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { AlreadyExistsError, BaseError, ConflictError, GuardError, NotFoundError, NotImplementedError, UnauthorizedError, UnprocessableError, ValidationError } from "@3sixty/core";
|
|
4
|
+
import { HeaderTypes, HttpStatusCode, MimeTypes } from "@3sixty/web";
|
|
5
|
+
import { ForbiddenError } from "../errors/forbiddenError.js";
|
|
6
|
+
import { TooManyRequestsError } from "../errors/tooManyRequestsError.js";
|
|
7
|
+
/**
|
|
8
|
+
* Class to help with processing http errors.
|
|
9
|
+
*/
|
|
10
|
+
export class HttpErrorHelper {
|
|
11
|
+
/**
|
|
12
|
+
* Mapping of error types to status codes.
|
|
13
|
+
*/
|
|
14
|
+
static ERROR_TYPE_MAP = {
|
|
15
|
+
[GuardError.CLASS_NAME]: HttpStatusCode.badRequest,
|
|
16
|
+
[ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,
|
|
17
|
+
[ConflictError.CLASS_NAME]: HttpStatusCode.conflict,
|
|
18
|
+
[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,
|
|
19
|
+
[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,
|
|
20
|
+
[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,
|
|
21
|
+
[NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,
|
|
22
|
+
[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,
|
|
23
|
+
[TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,
|
|
24
|
+
[ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Process the errors from the routes.
|
|
28
|
+
* @param err The error to process.
|
|
29
|
+
* @param includeStack Should the stack be included in the error.
|
|
30
|
+
* @returns The status code and additional error data.
|
|
31
|
+
*/
|
|
32
|
+
static processError(err, includeStack) {
|
|
33
|
+
const error = BaseError.fromError(err);
|
|
34
|
+
// If the error or any of its sub errors are of the specific
|
|
35
|
+
// types then set the http response code accordingly
|
|
36
|
+
const flattened = BaseError.flatten(error);
|
|
37
|
+
let httpStatusCode = HttpStatusCode.internalServerError;
|
|
38
|
+
// First check the primary error, as we don't want to override that with a sub error
|
|
39
|
+
if (flattened.length > 0) {
|
|
40
|
+
const primaryError = flattened[0];
|
|
41
|
+
if (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {
|
|
42
|
+
httpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];
|
|
43
|
+
}
|
|
44
|
+
// The primary error is still internal server error, check the sub errors
|
|
45
|
+
if (httpStatusCode === HttpStatusCode.internalServerError) {
|
|
46
|
+
for (const className in HttpErrorHelper.ERROR_TYPE_MAP) {
|
|
47
|
+
if (flattened.some(e => BaseError.isErrorName(e, className))) {
|
|
48
|
+
httpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const returnError = error.toJsonObject(includeStack);
|
|
55
|
+
return {
|
|
56
|
+
error: returnError,
|
|
57
|
+
httpStatusCode
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build an error response.
|
|
62
|
+
* @param response The response to build the error into.
|
|
63
|
+
* @param error The error to build the response for.
|
|
64
|
+
* @param statusCode The status code to use for the error.
|
|
65
|
+
* @param includeStack Should the stack be included in the error.
|
|
66
|
+
*/
|
|
67
|
+
static buildResponse(response, error, statusCode, includeStack) {
|
|
68
|
+
response.headers ??= {};
|
|
69
|
+
response.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;
|
|
70
|
+
// Fastify treats an Error-typed body as a framework error and overrides the status with 500.
|
|
71
|
+
response.body = BaseError.fromError(error).toJsonObject(includeStack);
|
|
72
|
+
response.statusCode = statusCode;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=httpErrorHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpErrorHelper.js","sources":["../../../src/helpers/httpErrorHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,UAAU,EAEV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAGzE;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B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AC;YAED,yEAAyE;YACzE,IAAI,cAAc,KAAK,cAAc,CAAC,mBAAmB,EAAE,CAAC;gBAC3D,KAAK,MAAM,SAAS,IAAI,eAAe,CAAC,cAAc,EAAE,CAAC;oBACxD,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;wBAC9D,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;wBAC3D,MAAM;oBACP,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAErD,OAAO;YACN,KAAK,EAAE,WAAW;YAClB,cAAc;SACd,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,aAAa,CAC1B,QAAuB,EACvB,KAAa,EACb,UAA0B,EAC1B,YAAqB;QAErB,QAAQ,CAAC,OAAO,KAAK,EAAE,CAAC;QACxB,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC,IAAI,iBAAiB,CAAC;QAC/E,6FAA6F;QAC7F,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACtE,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAClC,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tConflictError,\n\tGuardError,\n\ttype IError,\n\tNotFoundError,\n\tNotImplementedError,\n\tUnauthorizedError,\n\tUnprocessableError,\n\tValidationError\n} from \"@3sixty/core\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@3sixty/web\";\nimport { ForbiddenError } from \"../errors/forbiddenError.js\";\nimport { TooManyRequestsError } from \"../errors/tooManyRequestsError.js\";\nimport type { IHttpResponse } from \"../models/protocol/IHttpResponse.js\";\n\n/**\n * Class to help with processing http errors.\n */\nexport class HttpErrorHelper {\n\t/**\n\t * Mapping of error types to status codes.\n\t */\n\tpublic static readonly ERROR_TYPE_MAP: { [id: string]: HttpStatusCode } = {\n\t\t[GuardError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ConflictError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,\n\t\t[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,\n\t\t[NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,\n\t\t[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,\n\t\t[TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,\n\t\t[ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden\n\t};\n\n\t/**\n\t * Process the errors from the routes.\n\t * @param err The error to process.\n\t * @param includeStack Should the stack be included in the error.\n\t * @returns The status code and additional error data.\n\t */\n\tpublic static processError(\n\t\terr: unknown,\n\t\tincludeStack?: boolean\n\t): {\n\t\terror: IError;\n\t\thttpStatusCode: HttpStatusCode;\n\t} {\n\t\tconst error: BaseError = BaseError.fromError(err);\n\n\t\t// If the error or any of its sub errors are of the specific\n\t\t// types then set the http response code accordingly\n\t\tconst flattened = BaseError.flatten(error);\n\n\t\tlet httpStatusCode: HttpStatusCode = HttpStatusCode.internalServerError;\n\n\t\t// First check the primary error, as we don't want to override that with a sub error\n\t\tif (flattened.length > 0) {\n\t\t\tconst primaryError = flattened[0];\n\t\t\tif (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {\n\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];\n\t\t\t}\n\n\t\t\t// The primary error is still internal server error, check the sub errors\n\t\t\tif (httpStatusCode === HttpStatusCode.internalServerError) {\n\t\t\t\tfor (const className in HttpErrorHelper.ERROR_TYPE_MAP) {\n\t\t\t\t\tif (flattened.some(e => BaseError.isErrorName(e, className))) {\n\t\t\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst returnError = error.toJsonObject(includeStack);\n\n\t\treturn {\n\t\t\terror: returnError,\n\t\t\thttpStatusCode\n\t\t};\n\t}\n\n\t/**\n\t * Build an error response.\n\t * @param response The response to build the error into.\n\t * @param error The error to build the response for.\n\t * @param statusCode The status code to use for the error.\n\t * @param includeStack Should the stack be included in the error.\n\t */\n\tpublic static buildResponse(\n\t\tresponse: IHttpResponse,\n\t\terror: IError,\n\t\tstatusCode: HttpStatusCode,\n\t\tincludeStack: boolean\n\t): void {\n\t\tresponse.headers ??= {};\n\t\tresponse.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;\n\t\t// Fastify treats an Error-typed body as a framework error and overrides the status with 500.\n\t\tresponse.body = BaseError.fromError(error).toJsonObject(includeStack);\n\t\tresponse.statusCode = statusCode;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { GeneralError, Guards, Is, StringHelper } from "@3sixty/core";
|
|
4
|
+
import { HeaderHelper, HeaderTypes, MimeTypes } from "@3sixty/web";
|
|
5
|
+
import { HttpUrlHelper } from "./httpUrlHelper.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class to help with handling http headers.
|
|
8
|
+
*/
|
|
9
|
+
export class HttpHeaderHelper {
|
|
10
|
+
/**
|
|
11
|
+
* Runtime name for the class.
|
|
12
|
+
*/
|
|
13
|
+
static CLASS_NAME = "HttpHeaderHelper";
|
|
14
|
+
/**
|
|
15
|
+
* Set the Link header with a next cursor relation when a cursor is present.
|
|
16
|
+
* @param headers The response headers to mutate.
|
|
17
|
+
* @param url The request URL used as the base for the link.
|
|
18
|
+
* @param publicOrigin The public origin to substitute into the URL, if any.
|
|
19
|
+
* @param cursor The cursor value; when undefined or empty the header is not set.
|
|
20
|
+
*/
|
|
21
|
+
static buildCursor(headers, url, publicOrigin, cursor) {
|
|
22
|
+
if (Is.stringValue(cursor)) {
|
|
23
|
+
const baseUrl = HttpUrlHelper.replaceOrigin(url, publicOrigin);
|
|
24
|
+
const cursorUrl = HttpUrlHelper.addQueryStringParam(baseUrl, "cursor", cursor);
|
|
25
|
+
headers[HeaderTypes.Link] = HeaderHelper.createLinkHeader(cursorUrl, undefined, "next");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set the Location header to the encoded ID, optionally placed within a URL template.
|
|
30
|
+
* When the template contains `:id` (e.g. "/path1/:id/path2" or "/path?p=:id") the
|
|
31
|
+
* encoded ID is substituted at that position; otherwise it is appended.
|
|
32
|
+
* When no template is provided the bare encoded ID is used.
|
|
33
|
+
* Callers that need to combine a public origin with a path should use
|
|
34
|
+
* HttpUrlHelper.combineOriginPath to build the template before calling this method.
|
|
35
|
+
* @param headers The response headers to mutate.
|
|
36
|
+
* @param id The resource ID to encode and place.
|
|
37
|
+
* @param urlTemplate The optional URL template (absolute or relative).
|
|
38
|
+
*/
|
|
39
|
+
static buildId(headers, id, urlTemplate) {
|
|
40
|
+
Guards.stringValue(HttpHeaderHelper.CLASS_NAME, "id", id);
|
|
41
|
+
const encodedId = encodeURIComponent(id);
|
|
42
|
+
if (Is.stringValue(urlTemplate)) {
|
|
43
|
+
if (/:id(?![a-zA-Z0-9])/.test(urlTemplate)) {
|
|
44
|
+
headers[HeaderTypes.Location] = urlTemplate.replace(/:id(?![a-zA-Z0-9])/, encodedId);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
headers[HeaderTypes.Location] =
|
|
48
|
+
`${StringHelper.trimTrailingSlashes(urlTemplate)}/${encodedId}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
headers[HeaderTypes.Location] = encodedId;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set the Content-Type header to JSON-LD or JSON depending on the request Accept header.
|
|
57
|
+
* Uses HeaderHelper.extractAccept which parses the Accept header per RFC 7231 and returns
|
|
58
|
+
* entries ordered by quality descending, preserving original order for equal q-values.
|
|
59
|
+
* @param headers The response headers to mutate.
|
|
60
|
+
* @param requestHeaders The request headers to inspect for the Accept value.
|
|
61
|
+
*/
|
|
62
|
+
static buildJsonContentType(headers, requestHeaders) {
|
|
63
|
+
const accepted = HeaderHelper.extractAccept(requestHeaders);
|
|
64
|
+
let contentType = MimeTypes.Json;
|
|
65
|
+
if (Is.arrayValue(accepted)) {
|
|
66
|
+
for (const { mimeType } of accepted) {
|
|
67
|
+
if (mimeType === MimeTypes.JsonLd) {
|
|
68
|
+
contentType = MimeTypes.JsonLd;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (mimeType === MimeTypes.Json || mimeType === "application/*" || mimeType === "*/*") {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
headers[HeaderTypes.ContentType] = contentType;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract the cursor from the Link header's next relation.
|
|
80
|
+
* @param headers The response headers to extract the cursor from.
|
|
81
|
+
* @returns The cursor value or undefined if not present.
|
|
82
|
+
*/
|
|
83
|
+
static extractCursor(headers) {
|
|
84
|
+
return HeaderHelper.extractLinkHeaderRelation(headers?.[HeaderTypes.Link], "next")
|
|
85
|
+
?.urlQueryParams?.cursor;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Extract the resource ID from the Location response header.
|
|
89
|
+
* Handles absolute URLs, relative paths, and bare ID values.
|
|
90
|
+
* When a templateUrl containing ':id' is supplied (e.g. "/path1/:id/path2" or
|
|
91
|
+
* "https://host/path/:id") the ID is extracted via pattern matching at the ':id'
|
|
92
|
+
* position. Without a matching template the last path segment is returned.
|
|
93
|
+
* @param headers The response headers containing the Location header.
|
|
94
|
+
* @param templateUrl Optional URL template containing the ':id' placeholder, e.g. "/path1/:id/path2".
|
|
95
|
+
* @returns The extracted ID string.
|
|
96
|
+
* @throws GeneralError If the Location header is missing or the ID cannot be extracted.
|
|
97
|
+
*/
|
|
98
|
+
static extractId(headers, templateUrl) {
|
|
99
|
+
const location = headers?.[HeaderTypes.Location];
|
|
100
|
+
if (!Is.stringValue(location)) {
|
|
101
|
+
throw new GeneralError(HttpHeaderHelper.CLASS_NAME, "locationMissing");
|
|
102
|
+
}
|
|
103
|
+
const withoutQuery = location.split("?")[0];
|
|
104
|
+
if (Is.stringValue(templateUrl) && templateUrl.includes(":id")) {
|
|
105
|
+
const escaped = templateUrl.replace(/[.+^${}()|[\]\\?]/g, "\\$&");
|
|
106
|
+
const pattern = new RegExp(escaped.replace(/:[a-zA-Z][a-zA-Z0-9]*/g, m => (m === ":id" ? "([^/?#]+)" : "[^/?#]+")));
|
|
107
|
+
const match = pattern.exec(location);
|
|
108
|
+
if (!Is.stringValue(match?.[1])) {
|
|
109
|
+
throw new GeneralError(HttpHeaderHelper.CLASS_NAME, "idNotFound");
|
|
110
|
+
}
|
|
111
|
+
return decodeURIComponent(match[1]);
|
|
112
|
+
}
|
|
113
|
+
const id = withoutQuery.includes("/") ? withoutQuery.split("/").pop() : withoutQuery;
|
|
114
|
+
if (!Is.stringValue(id)) {
|
|
115
|
+
throw new GeneralError(HttpHeaderHelper.CLASS_NAME, "idNotFound");
|
|
116
|
+
}
|
|
117
|
+
return decodeURIComponent(id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingUR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C,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;QAErF,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,YAAY,CAAC,gBAAgB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is, StringHelper } from \"@3sixty/core\";\n\nimport { HeaderHelper, HeaderTypes, MimeTypes, type IHttpHeaders } from \"@3sixty/web\";\nimport { HttpUrlHelper } from \"./httpUrlHelper.js\";\n\n/**\n * Class to help with handling http headers.\n */\nexport class HttpHeaderHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"HttpHeaderHelper\";\n\n\t/**\n\t * Set the Link header with a next cursor relation when a cursor is present.\n\t * @param headers The response headers to mutate.\n\t * @param url The request URL used as the base for the link.\n\t * @param publicOrigin The public origin to substitute into the URL, if any.\n\t * @param cursor The cursor value; when undefined or empty the header is not set.\n\t */\n\tpublic static buildCursor(\n\t\theaders: IHttpHeaders,\n\t\turl: string,\n\t\tpublicOrigin: string | undefined,\n\t\tcursor: string | undefined\n\t): asserts headers is IHttpHeaders & { [HeaderTypes.Link]: string | undefined } {\n\t\tif (Is.stringValue(cursor)) {\n\t\t\tconst baseUrl = HttpUrlHelper.replaceOrigin(url, publicOrigin);\n\t\t\tconst cursorUrl = HttpUrlHelper.addQueryStringParam(baseUrl, \"cursor\", cursor);\n\t\t\theaders[HeaderTypes.Link] = HeaderHelper.createLinkHeader(cursorUrl, undefined, \"next\");\n\t\t}\n\t}\n\n\t/**\n\t * Set the Location header to the encoded ID, optionally placed within a URL template.\n\t * When the template contains `:id` (e.g. \"/path1/:id/path2\" or \"/path?p=:id\") the\n\t * encoded ID is substituted at that position; otherwise it is appended.\n\t * When no template is provided the bare encoded ID is used.\n\t * Callers that need to combine a public origin with a path should use\n\t * HttpUrlHelper.combineOriginPath to build the template before calling this method.\n\t * @param headers The response headers to mutate.\n\t * @param id The resource ID to encode and place.\n\t * @param urlTemplate The optional URL template (absolute or relative).\n\t */\n\tpublic static buildId(\n\t\theaders: IHttpHeaders,\n\t\tid: string,\n\t\turlTemplate?: string\n\t): asserts headers is IHttpHeaders & { [HeaderTypes.Location]: string } {\n\t\tGuards.stringValue(HttpHeaderHelper.CLASS_NAME, \"id\", id);\n\t\tconst encodedId = encodeURIComponent(id);\n\n\t\tif (Is.stringValue(urlTemplate)) {\n\t\t\tif (/:id(?![a-zA-Z0-9])/.test(urlTemplate)) {\n\t\t\t\theaders[HeaderTypes.Location] = urlTemplate.replace(/:id(?![a-zA-Z0-9])/, encodedId);\n\t\t\t} else {\n\t\t\t\theaders[HeaderTypes.Location] =\n\t\t\t\t\t`${StringHelper.trimTrailingSlashes(urlTemplate)}/${encodedId}`;\n\t\t\t}\n\t\t} else {\n\t\t\theaders[HeaderTypes.Location] = encodedId;\n\t\t}\n\t}\n\n\t/**\n\t * Set the Content-Type header to JSON-LD or JSON depending on the request Accept header.\n\t * Uses HeaderHelper.extractAccept which parses the Accept header per RFC 7231 and returns\n\t * entries ordered by quality descending, preserving original order for equal q-values.\n\t * @param headers The response headers to mutate.\n\t * @param requestHeaders The request headers to inspect for the Accept value.\n\t */\n\tpublic static buildJsonContentType(\n\t\theaders: IHttpHeaders,\n\t\trequestHeaders?: IHttpHeaders\n\t): asserts headers is IHttpHeaders & {\n\t\t[HeaderTypes.ContentType]: typeof MimeTypes.JsonLd | typeof MimeTypes.Json;\n\t} {\n\t\tconst accepted = HeaderHelper.extractAccept(requestHeaders);\n\t\tlet contentType: string = MimeTypes.Json;\n\t\tif (Is.arrayValue(accepted)) {\n\t\t\tfor (const { mimeType } of accepted) {\n\t\t\t\tif (mimeType === MimeTypes.JsonLd) {\n\t\t\t\t\tcontentType = MimeTypes.JsonLd;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (mimeType === MimeTypes.Json || mimeType === \"application/*\" || mimeType === \"*/*\") {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\theaders[HeaderTypes.ContentType] = contentType;\n\t}\n\n\t/**\n\t * Extract the cursor from the Link header's next relation.\n\t * @param headers The response headers to extract the cursor from.\n\t * @returns The cursor value or undefined if not present.\n\t */\n\tpublic static extractCursor(headers?: IHttpHeaders): string | undefined {\n\t\treturn HeaderHelper.extractLinkHeaderRelation(headers?.[HeaderTypes.Link], \"next\")\n\t\t\t?.urlQueryParams?.cursor;\n\t}\n\n\t/**\n\t * Extract the resource ID from the Location response header.\n\t * Handles absolute URLs, relative paths, and bare ID values.\n\t * When a templateUrl containing ':id' is supplied (e.g. \"/path1/:id/path2\" or\n\t * \"https://host/path/:id\") the ID is extracted via pattern matching at the ':id'\n\t * position. Without a matching template the last path segment is returned.\n\t * @param headers The response headers containing the Location header.\n\t * @param templateUrl Optional URL template containing the ':id' placeholder, e.g. \"/path1/:id/path2\".\n\t * @returns The extracted ID string.\n\t * @throws GeneralError If the Location header is missing or the ID cannot be extracted.\n\t */\n\tpublic static extractId(headers?: IHttpHeaders, templateUrl?: string): string {\n\t\tconst location = headers?.[HeaderTypes.Location];\n\t\tif (!Is.stringValue(location)) {\n\t\t\tthrow new GeneralError(HttpHeaderHelper.CLASS_NAME, \"locationMissing\");\n\t\t}\n\n\t\tconst withoutQuery = location.split(\"?\")[0];\n\n\t\tif (Is.stringValue(templateUrl) && templateUrl.includes(\":id\")) {\n\t\t\tconst escaped = templateUrl.replace(/[.+^${}()|[\\]\\\\?]/g, \"\\\\$&\");\n\t\t\tconst pattern = new RegExp(\n\t\t\t\tescaped.replace(/:[a-zA-Z][a-zA-Z0-9]*/g, m => (m === \":id\" ? \"([^/?#]+)\" : \"[^/?#]+\"))\n\t\t\t);\n\t\t\tconst match = pattern.exec(location);\n\t\t\tif (!Is.stringValue(match?.[1])) {\n\t\t\t\tthrow new GeneralError(HttpHeaderHelper.CLASS_NAME, \"idNotFound\");\n\t\t\t}\n\t\t\treturn decodeURIComponent(match[1]);\n\t\t}\n\n\t\tconst id = withoutQuery.includes(\"/\") ? withoutQuery.split(\"/\").pop() : withoutQuery;\n\n\t\tif (!Is.stringValue(id)) {\n\t\t\tthrow new GeneralError(HttpHeaderHelper.CLASS_NAME, \"idNotFound\");\n\t\t}\n\t\treturn decodeURIComponent(id);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Is } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Class to help with handling http parameters.
|
|
6
|
+
*/
|
|
7
|
+
export class HttpParameterHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Convert list query to array.
|
|
10
|
+
* @param values The values query string.
|
|
11
|
+
* @returns The array of values.
|
|
12
|
+
*/
|
|
13
|
+
static arrayFromString(values) {
|
|
14
|
+
return values?.split(",");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert array of values to query string.
|
|
18
|
+
* @param values The values to combine string.
|
|
19
|
+
* @returns The combined.
|
|
20
|
+
*/
|
|
21
|
+
static arrayToString(values) {
|
|
22
|
+
return Is.arrayValue(values) ? values.join(",") : undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert object string to object.
|
|
26
|
+
* @param value The value query string.
|
|
27
|
+
* @returns The object.
|
|
28
|
+
*/
|
|
29
|
+
static objectFromString(value) {
|
|
30
|
+
return Is.json(value) ? JSON.parse(value) : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert object to query string.
|
|
34
|
+
* @param value The value to convert to a string.
|
|
35
|
+
* @returns The converted object.
|
|
36
|
+
*/
|
|
37
|
+
static objectToString(value) {
|
|
38
|
+
return Is.empty(value) ? undefined : JSON.stringify(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=httpParameterHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpParameterHelper.js","sources":["../../../src/helpers/httpParameterHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC/B;;;;OAIG;IACI,MAAM,CAAC,eAAe,CAAa,MAAe;QACxD,OAAO,MAAM,EAAE,KAAK,CAAC,GAAG,CAAQ,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAa,MAAY;QACnD,OAAO,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,gBAAgB,CAAc,KAAc;QACzD,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAc,KAAS;QAClD,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"@3sixty/core\";\n\n/**\n * Class to help with handling http parameters.\n */\nexport class HttpParameterHelper {\n\t/**\n\t * Convert list query to array.\n\t * @param values The values query string.\n\t * @returns The array of values.\n\t */\n\tpublic static arrayFromString<T = string>(values?: string): T[] | undefined {\n\t\treturn values?.split(\",\") as T[];\n\t}\n\n\t/**\n\t * Convert array of values to query string.\n\t * @param values The values to combine string.\n\t * @returns The combined.\n\t */\n\tpublic static arrayToString<T = string>(values?: T[]): string | undefined {\n\t\treturn Is.arrayValue(values) ? values.join(\",\") : undefined;\n\t}\n\n\t/**\n\t * Convert object string to object.\n\t * @param value The value query string.\n\t * @returns The object.\n\t */\n\tpublic static objectFromString<T = unknown>(value?: string): T | undefined {\n\t\treturn Is.json(value) ? (JSON.parse(value) as T) : undefined;\n\t}\n\n\t/**\n\t * Convert object to query string.\n\t * @param value The value to convert to a string.\n\t * @returns The converted object.\n\t */\n\tpublic static objectToString<T = unknown>(value?: T): string | undefined {\n\t\treturn Is.empty(value) ? undefined : JSON.stringify(value);\n\t}\n}\n"]}
|