@3sixty/api-core-server 0.20.0-next.0 → 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.
Files changed (31) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +20 -2
  3. package/dist/es/baseServer.js +666 -0
  4. package/dist/es/baseServer.js.map +1 -0
  5. package/dist/es/index.js +8 -0
  6. package/dist/es/index.js.map +1 -0
  7. package/dist/es/models/IBaseServerConstructorOptions.js +2 -0
  8. package/dist/es/models/IBaseServerConstructorOptions.js.map +1 -0
  9. package/dist/es/models/IRestProcessorChains.js +2 -0
  10. package/dist/es/models/IRestProcessorChains.js.map +1 -0
  11. package/dist/es/models/IServerCorsOptions.js +2 -0
  12. package/dist/es/models/IServerCorsOptions.js.map +1 -0
  13. package/dist/es/models/ISocketProcessorChains.js +2 -0
  14. package/dist/es/models/ISocketProcessorChains.js.map +1 -0
  15. package/dist/types/baseServer.d.ts +232 -0
  16. package/dist/types/index.d.ts +5 -0
  17. package/dist/types/models/IBaseServerConstructorOptions.d.ts +19 -0
  18. package/dist/types/models/IRestProcessorChains.d.ts +18 -0
  19. package/dist/types/models/IServerCorsOptions.d.ts +26 -0
  20. package/dist/types/models/ISocketProcessorChains.d.ts +26 -0
  21. package/docs/changelog.md +16 -0
  22. package/docs/examples.md +78 -0
  23. package/docs/reference/classes/BaseServer.md +730 -0
  24. package/docs/reference/index.md +12 -0
  25. package/docs/reference/interfaces/IBaseServerConstructorOptions.md +33 -0
  26. package/docs/reference/interfaces/IRestProcessorChains.md +171 -0
  27. package/docs/reference/interfaces/IServerCorsOptions.md +43 -0
  28. package/docs/reference/interfaces/ISocketProcessorChains.md +245 -0
  29. package/locales/.validate-ignore +3 -0
  30. package/locales/en.json +33 -0
  31. package/package.json +54 -6
@@ -0,0 +1,33 @@
1
+ # Interface: IBaseServerConstructorOptions
2
+
3
+ Options for constructing a base server.
4
+
5
+ ## Properties
6
+
7
+ ### loggingComponentType? {#loggingcomponenttype}
8
+
9
+ > `optional` **loggingComponentType?**: `string`
10
+
11
+ The type of the logging component to use, defaults to no logging.
12
+
13
+ ***
14
+
15
+ ### mimeTypeProcessors? {#mimetypeprocessors}
16
+
17
+ > `optional` **mimeTypeProcessors?**: `IMimeTypeProcessor`[]
18
+
19
+ The mime type processors to use for the request bodies.
20
+
21
+ ***
22
+
23
+ ### includeErrorStack? {#includeerrorstack}
24
+
25
+ > `optional` **includeErrorStack?**: `boolean`
26
+
27
+ Include the stack with errors.
28
+
29
+ #### Default
30
+
31
+ ```ts
32
+ false
33
+ ```
@@ -0,0 +1,171 @@
1
+ # Interface: IRestProcessorChains
2
+
3
+ The REST processor phase chains, bound to their processors when the server is built.
4
+
5
+ ## Properties
6
+
7
+ ### pre {#pre}
8
+
9
+ > **pre**: ((`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`) => `Promise`\<`void`\>)[]
10
+
11
+ The pre processing phase.
12
+
13
+ Pre process the REST request for the specified route.
14
+
15
+ #### Parameters
16
+
17
+ ##### request
18
+
19
+ `IHttpServerRequest`
20
+
21
+ The request to handle.
22
+
23
+ ##### response
24
+
25
+ `IHttpResponse`
26
+
27
+ The response data to send if any.
28
+
29
+ ##### route
30
+
31
+ `IRestRoute`\<`any`, `any`\> \| `undefined`
32
+
33
+ The route being requested, if a matching one was found.
34
+
35
+ ##### contextIds
36
+
37
+ `IContextIds`
38
+
39
+ The context IDs of the request.
40
+
41
+ ##### processorState
42
+
43
+ \{\[`id`: `string`\]: `unknown`; \}
44
+
45
+ The state handed through the processors.
46
+
47
+ ##### componentTypes?
48
+
49
+ The component types for the request.
50
+
51
+ ###### loggingComponentType?
52
+
53
+ `string`
54
+
55
+ The logging component type.
56
+
57
+ #### Returns
58
+
59
+ `Promise`\<`void`\>
60
+
61
+ Promise that resolves when the request is processed.
62
+
63
+ ***
64
+
65
+ ### process {#process}
66
+
67
+ > **process**: ((`request`, `response`, `route`, `processorState`, `componentTypes?`) => `Promise`\<`void`\>)[]
68
+
69
+ The main processing phase.
70
+
71
+ Process the REST request for the specified route.
72
+
73
+ #### Parameters
74
+
75
+ ##### request
76
+
77
+ `IHttpServerRequest`
78
+
79
+ The request to handle.
80
+
81
+ ##### response
82
+
83
+ `IHttpResponse`
84
+
85
+ The response data to send if any.
86
+
87
+ ##### route
88
+
89
+ `IRestRoute`\<`any`, `any`\> \| `undefined`
90
+
91
+ The route being requested, if a matching one was found.
92
+
93
+ ##### processorState
94
+
95
+ \{\[`id`: `string`\]: `unknown`; \}
96
+
97
+ The state handed through the processors.
98
+
99
+ ##### componentTypes?
100
+
101
+ The component types for the request.
102
+
103
+ ###### loggingComponentType?
104
+
105
+ `string`
106
+
107
+ The logging component type.
108
+
109
+ #### Returns
110
+
111
+ `Promise`\<`void`\>
112
+
113
+ Promise that resolves when the request is processed.
114
+
115
+ ***
116
+
117
+ ### post {#post}
118
+
119
+ > **post**: ((`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`) => `Promise`\<`void`\>)[]
120
+
121
+ The post processing phase.
122
+
123
+ Post process the REST request for the specified route.
124
+
125
+ #### Parameters
126
+
127
+ ##### request
128
+
129
+ `IHttpServerRequest`
130
+
131
+ The request to handle.
132
+
133
+ ##### response
134
+
135
+ `IHttpResponse`
136
+
137
+ The response data to send if any.
138
+
139
+ ##### route
140
+
141
+ `IRestRoute`\<`any`, `any`\> \| `undefined`
142
+
143
+ The route being requested, if a matching one was found.
144
+
145
+ ##### contextIds
146
+
147
+ `IContextIds`
148
+
149
+ The context IDs of the request.
150
+
151
+ ##### processorState
152
+
153
+ \{\[`id`: `string`\]: `unknown`; \}
154
+
155
+ The state handed through the processors.
156
+
157
+ ##### componentTypes?
158
+
159
+ The component types for the request.
160
+
161
+ ###### loggingComponentType?
162
+
163
+ `string`
164
+
165
+ The logging component type.
166
+
167
+ #### Returns
168
+
169
+ `Promise`\<`void`\>
170
+
171
+ Promise that resolves when the request is processed.
@@ -0,0 +1,43 @@
1
+ # Interface: IServerCorsOptions
2
+
3
+ The resolved CORS options for a server.
4
+
5
+ ## Properties
6
+
7
+ ### origins {#origins}
8
+
9
+ > **origins**: `string`[]
10
+
11
+ The allowed origins.
12
+
13
+ ***
14
+
15
+ ### hasWildcardOrigin {#haswildcardorigin}
16
+
17
+ > **hasWildcardOrigin**: `boolean`
18
+
19
+ Whether the allowed origins include the wildcard, in which case any origin is allowed.
20
+
21
+ ***
22
+
23
+ ### methods {#methods}
24
+
25
+ > **methods**: `HttpMethod`[]
26
+
27
+ The allowed methods.
28
+
29
+ ***
30
+
31
+ ### allowedHeaders {#allowedheaders}
32
+
33
+ > **allowedHeaders**: `string`[]
34
+
35
+ The allowed headers.
36
+
37
+ ***
38
+
39
+ ### exposedHeaders {#exposedheaders}
40
+
41
+ > **exposedHeaders**: `string`[]
42
+
43
+ The exposed headers.
@@ -0,0 +1,245 @@
1
+ # Interface: ISocketProcessorChains
2
+
3
+ The socket processor phase chains, bound to their processors when the server is built.
4
+
5
+ ## Properties
6
+
7
+ ### connected {#connected}
8
+
9
+ > **connected**: ((`request`, `route`, `loggingComponentType?`) => `Promise`\<`void`\>)[]
10
+
11
+ The socket connected phase.
12
+
13
+ Process the connected event.
14
+
15
+ #### Parameters
16
+
17
+ ##### request
18
+
19
+ `ISocketServerRequest`
20
+
21
+ The server request object containing the socket id and other parameters.
22
+
23
+ ##### route
24
+
25
+ `ISocketRoute`\<`any`, `any`\> \| `undefined`
26
+
27
+ The route being requested, if a matching one was found.
28
+
29
+ ##### loggingComponentType?
30
+
31
+ `string`
32
+
33
+ The logging component type for the request.
34
+
35
+ #### Returns
36
+
37
+ `Promise`\<`void`\>
38
+
39
+ Promise that resolves when the request is processed.
40
+
41
+ ***
42
+
43
+ ### disconnected {#disconnected}
44
+
45
+ > **disconnected**: ((`request`, `route`, `loggingComponentType?`) => `Promise`\<`void`\>)[]
46
+
47
+ The socket disconnected phase.
48
+
49
+ Process the disconnected event.
50
+
51
+ #### Parameters
52
+
53
+ ##### request
54
+
55
+ `ISocketServerRequest`
56
+
57
+ The server request object containing the socket id and other parameters.
58
+
59
+ ##### route
60
+
61
+ `ISocketRoute`\<`any`, `any`\> \| `undefined`
62
+
63
+ The route being requested, if a matching one was found.
64
+
65
+ ##### loggingComponentType?
66
+
67
+ `string`
68
+
69
+ The logging component type for the request.
70
+
71
+ #### Returns
72
+
73
+ `Promise`\<`void`\>
74
+
75
+ Promise that resolves when the request is processed.
76
+
77
+ ***
78
+
79
+ ### pre {#pre}
80
+
81
+ > **pre**: ((`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`) => `Promise`\<`void`\>)[]
82
+
83
+ The pre processing phase.
84
+
85
+ Pre process the REST request for the specified route.
86
+
87
+ #### Parameters
88
+
89
+ ##### request
90
+
91
+ `ISocketServerRequest`
92
+
93
+ The request to handle.
94
+
95
+ ##### response
96
+
97
+ `IHttpResponse`
98
+
99
+ The response data to send if any.
100
+
101
+ ##### route
102
+
103
+ `ISocketRoute`\<`any`, `any`\> \| `undefined`
104
+
105
+ The route being requested, if a matching one was found.
106
+
107
+ ##### contextIds
108
+
109
+ `IContextIds`
110
+
111
+ The context IDs of the request.
112
+
113
+ ##### processorState
114
+
115
+ \{\[`id`: `string`\]: `unknown`; \}
116
+
117
+ The state handed through the processors.
118
+
119
+ ##### componentTypes?
120
+
121
+ The component types for the request.
122
+
123
+ ###### loggingComponentType?
124
+
125
+ `string`
126
+
127
+ The logging component type.
128
+
129
+ #### Returns
130
+
131
+ `Promise`\<`void`\>
132
+
133
+ Promise that resolves when the request is processed.
134
+
135
+ ***
136
+
137
+ ### process {#process}
138
+
139
+ > **process**: ((`request`, `response`, `route`, `processorState`, `responseEmitter`, `loggingComponentType?`) => `Promise`\<`void`\>)[]
140
+
141
+ The main processing phase.
142
+
143
+ Process the REST request for the specified route.
144
+
145
+ #### Parameters
146
+
147
+ ##### request
148
+
149
+ `ISocketServerRequest`
150
+
151
+ The server request object containing the socket id and other parameters.
152
+
153
+ ##### response
154
+
155
+ `IHttpResponse`
156
+
157
+ The response data to send if any.
158
+
159
+ ##### route
160
+
161
+ `ISocketRoute`\<`any`, `any`\> \| `undefined`
162
+
163
+ The route being requested, if a matching one was found.
164
+
165
+ ##### processorState
166
+
167
+ \{\[`id`: `string`\]: `unknown`; \}
168
+
169
+ The state handed through the processors.
170
+
171
+ ##### responseEmitter
172
+
173
+ (`topic`, `response`) => `Promise`\<`void`\>
174
+
175
+ The function to emit a response.
176
+
177
+ ##### loggingComponentType?
178
+
179
+ `string`
180
+
181
+ The logging component type for the request.
182
+
183
+ #### Returns
184
+
185
+ `Promise`\<`void`\>
186
+
187
+ Promise that resolves when the request is processed.
188
+
189
+ ***
190
+
191
+ ### post {#post}
192
+
193
+ > **post**: ((`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`) => `Promise`\<`void`\>)[]
194
+
195
+ The post processing phase.
196
+
197
+ Post process the REST request for the specified route.
198
+
199
+ #### Parameters
200
+
201
+ ##### request
202
+
203
+ `ISocketServerRequest`
204
+
205
+ The request to handle.
206
+
207
+ ##### response
208
+
209
+ `IHttpResponse`
210
+
211
+ The response data to send if any.
212
+
213
+ ##### route
214
+
215
+ `ISocketRoute`\<`any`, `any`\> \| `undefined`
216
+
217
+ The route being requested, if a matching one was found.
218
+
219
+ ##### contextIds
220
+
221
+ `IContextIds`
222
+
223
+ The context IDs of the request.
224
+
225
+ ##### processorState
226
+
227
+ \{\[`id`: `string`\]: `unknown`; \}
228
+
229
+ The state handed through the processors.
230
+
231
+ ##### componentTypes?
232
+
233
+ The component types for the request.
234
+
235
+ ###### loggingComponentType?
236
+
237
+ `string`
238
+
239
+ The logging component type.
240
+
241
+ #### Returns
242
+
243
+ `Promise`\<`void`\>
244
+
245
+ Promise that resolves when the request is processed.
@@ -0,0 +1,3 @@
1
+ # Host literals used when normalising the bind address in baseServer.ts, not locale keys
2
+ 127.0.0.1
3
+ 0.0.0.0
@@ -0,0 +1,33 @@
1
+ {
2
+ "error": {
3
+ "baseServer": {
4
+ "startFailed": "The Web Server failed to start",
5
+ "noRestProcessors": "You must configure at least one REST processor",
6
+ "noSocketProcessors": "You must configure at least one socket processor",
7
+ "postProcessorError": "There was a failure in a post processor for route \"{route}\"",
8
+ "invalidPublicOrigin": "The public origin \"{publicOrigin}\" is not a valid origin URL, it should be in the format \"protocol://host[:port]\".",
9
+ "invalidBodyLimit": "The body limit named \"{bodyLimit}\" must be an integer greater than zero, but it is \"{value}\"",
10
+ "invalidStatusCode": "The response status code \"{statusCode}\" is not valid",
11
+ "invalidHeader": "The response header \"{header}\" has an invalid name or value"
12
+ }
13
+ },
14
+ "info": {
15
+ "baseServer": {
16
+ "building": "Building Web Server",
17
+ "starting": "Starting Web Server with binding \"{host}\" on port \"{port}\"",
18
+ "started": "The Web Server started on {addresses}",
19
+ "stopped": "The Web Server was stopped"
20
+ }
21
+ },
22
+ "health": {
23
+ "baseServer": {
24
+ "healthConnectivityDescription": "Checks if the Web Server is reachable",
25
+ "reachable": "The Web Server is reachable",
26
+ "unreachable": "The Web Server is unreachable",
27
+ "healthApplicationDescription": "Checks if the root endpoint is reachable",
28
+ "rootEndpointReachable": "The root endpoint is reachable",
29
+ "rootEndpointError": "The root endpoint returned an unexpected response",
30
+ "serverNotBuilt": "The server has not been built"
31
+ }
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
- {
2
- "name": "@3sixty/api-core-server",
3
- "version": "0.20.0-next.0",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@3sixty/api-core-server",
3
+ "version": "0.20.0-next.1",
4
+ "description": "Base server class with transport agnostic route processing for building web servers.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/3sixtyglobal/api.git",
8
+ "directory": "packages/api-core-server"
9
+ },
10
+ "author": "martyn.janes@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=24.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@3sixty/api-models": "0.20.0-next.1",
18
+ "@3sixty/api-processors": "0.20.0-next.1",
19
+ "@3sixty/context": "next",
20
+ "@3sixty/core": "next",
21
+ "@3sixty/logging-models": "next",
22
+ "@3sixty/nameof": "next",
23
+ "@3sixty/web": "next"
24
+ },
25
+ "main": "./dist/es/index.js",
26
+ "types": "./dist/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types/index.d.ts",
30
+ "import": "./dist/es/index.js",
31
+ "default": "./dist/es/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist/es",
36
+ "dist/types",
37
+ "locales",
38
+ "docs"
39
+ ],
40
+ "keywords": [
41
+ "twin",
42
+ "trade",
43
+ "iota",
44
+ "framework",
45
+ "blockchain",
46
+ "api",
47
+ "server",
48
+ "core"
49
+ ],
50
+ "bugs": {
51
+ "url": "git+https://github.com/3sixtyglobal/api/issues"
52
+ },
53
+ "homepage": "https://3sixty.global"
54
+ }