@travetto/web-connect 8.0.0-alpha.22 → 8.0.0-alpha.23
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/README.md +2 -2
- package/__index__.ts +1 -1
- package/package.json +4 -4
- package/src/connect.ts +6 -9
- package/src/util.ts +4 -3
package/README.md
CHANGED
|
@@ -13,14 +13,14 @@ npm install @travetto/web-connect
|
|
|
13
13
|
yarn add @travetto/web-connect
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
This module provides basic integration for calling [connect](https://github.com/senchalabs/connect) related middleware with [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications"). This logic is not intended to be exhaustive, but intended to provide a quick bridge.
|
|
16
|
+
This module provides basic integration for calling [connect](https://github.com/senchalabs/connect) related middleware with [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications"). This logic is not intended to be exhaustive, but intended to provide a quick bridge. This only consumer of this is [Web Auth Passport](https://github.com/travetto/travetto/tree/main/module/auth-web-passport#readme "Web authentication integration support for the Travetto framework") as it needs to bind the [WebRequest](https://github.com/travetto/travetto/tree/main/module/web/src/types/request.ts#L11) and [WebResponse](https://github.com/travetto/travetto/tree/main/module/web/src/types/response.ts#L3) to standard contracts for [passport](http://passportjs.org).
|
|
17
17
|
|
|
18
18
|
This module is already most likely compatible with quite a bit of middleware, but will fail under any of the following conditions:
|
|
19
19
|
* The calling code expects the request or response to be a proper [EventEmitter](https://nodejs.org/api/events.html#class-eventemitter), beyond `.on('end', callback)`
|
|
20
20
|
* The calling code expects the request/response sockets to be live.
|
|
21
21
|
* The calling code modifies the shape of the objects (e.g. rewrites the close method on response).
|
|
22
22
|
|
|
23
|
-
Barring these exceptions, gaps will be filled in as more use cases arise.
|
|
23
|
+
Barring these exceptions, gaps will be filled in as more use cases arise. The above exceptions are non-negotiable as they are are enforced by the invocation method defined by [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications").
|
|
24
24
|
|
|
25
25
|
**Code: Example of using the Connect Adaptor with Passport**
|
|
26
26
|
```typescript
|
package/__index__.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './src/connect.ts';
|
|
2
|
-
export * from './src/util.ts';
|
|
2
|
+
export * from './src/util.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-connect",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Web integration for Connect-Like Resources",
|
|
6
6
|
"keywords": [
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"directory": "module/web-connect"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/web": "^8.0.0-alpha.
|
|
28
|
+
"@travetto/web": "^8.0.0-alpha.23"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
32
|
-
"@travetto/test": "^8.0.0-alpha.
|
|
31
|
+
"@travetto/cli": "^8.0.0-alpha.28",
|
|
32
|
+
"@travetto/test": "^8.0.0-alpha.21"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"@travetto/test": {
|
package/src/connect.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type BinaryArray, BinaryUtil, CodecUtil, castTo } from '@travetto/runtime';
|
|
4
4
|
import { type WebRequest, WebResponse } from '@travetto/web';
|
|
5
5
|
|
|
6
6
|
export class ConnectRequest implements Pick<IncomingMessage, 'url' | 'headers'> {
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Get a connect incoming message given a framework request
|
|
10
9
|
*/
|
|
@@ -34,11 +33,9 @@ export class ConnectRequest implements Pick<IncomingMessage, 'url' | 'headers'>
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
export class ConnectResponse
|
|
38
|
-
'getHeader' | 'getHeaderNames' | 'getHeaders' | 'hasHeader' |
|
|
39
|
-
|
|
40
|
-
> {
|
|
41
|
-
|
|
36
|
+
export class ConnectResponse
|
|
37
|
+
implements Pick<ServerResponse, 'getHeader' | 'getHeaderNames' | 'getHeaders' | 'hasHeader' | 'headersSent' | 'write' | 'flushHeaders'>
|
|
38
|
+
{
|
|
42
39
|
/**
|
|
43
40
|
* Get a connect server response given a framework response
|
|
44
41
|
*/
|
|
@@ -158,4 +155,4 @@ export class ConnectResponse implements Pick<ServerResponse,
|
|
|
158
155
|
throw this.#response;
|
|
159
156
|
}
|
|
160
157
|
}
|
|
161
|
-
}
|
|
158
|
+
}
|
package/src/util.ts
CHANGED
|
@@ -15,7 +15,8 @@ export class WebConnectUtil {
|
|
|
15
15
|
*
|
|
16
16
|
* NOTE: If a response is written, then it is thrown as an "error"
|
|
17
17
|
*/
|
|
18
|
-
static async invoke<T>(
|
|
18
|
+
static async invoke<T>(
|
|
19
|
+
ctx: WebFilterContext,
|
|
19
20
|
handler: (
|
|
20
21
|
request: IncomingMessage,
|
|
21
22
|
response: ServerResponse,
|
|
@@ -28,9 +29,9 @@ export class WebConnectUtil {
|
|
|
28
29
|
const promise = Promise.withResolvers<T | undefined>();
|
|
29
30
|
connectResponse.on('end', () => promise.resolve(null!));
|
|
30
31
|
|
|
31
|
-
handler(connectRequest, connectResponse, (error, value) => error ? promise.reject(error) : promise.resolve(value!));
|
|
32
|
+
handler(connectRequest, connectResponse, (error, value) => (error ? promise.reject(error) : promise.resolve(value!)));
|
|
32
33
|
const result = await promise.promise;
|
|
33
34
|
connectResponse.throwIfSent();
|
|
34
35
|
return result;
|
|
35
36
|
}
|
|
36
|
-
}
|
|
37
|
+
}
|