@travetto/web 6.0.0-rc.2 → 6.0.0-rc.3

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 CHANGED
@@ -20,7 +20,6 @@ The module provides a declarative API for creating and describing a Web applicat
20
20
  * Using [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)s
21
21
  * Creating a Custom [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
22
22
  * Cookies
23
- * SSL Support
24
23
  * Error Handling
25
24
 
26
25
  ## Request/Response Pattern
@@ -38,18 +37,53 @@ export class BaseWebMessage<B = unknown, C = unknown> implements WebMessage<B, C
38
37
 
39
38
  **Code: Request Shape**
40
39
  ```typescript
40
+ import { HttpMethod, HttpProtocol } from './core.ts';
41
+ import { BaseWebMessage } from './message.ts';
42
+
43
+ export interface WebConnection {
44
+ host?: string;
45
+ port?: number;
46
+ ip?: string;
47
+ httpProtocol?: HttpProtocol;
48
+ }
49
+
50
+ export interface WebRequestContext {
51
+ path: string;
52
+ pathParams?: Record<string, unknown>;
53
+ httpQuery?: Record<string, unknown>;
54
+ httpMethod?: HttpMethod;
55
+ connection?: WebConnection;
56
+ }
41
57
 
58
+ /**
59
+ * Web Request object
60
+ */
61
+ export class WebRequest<B = unknown> extends BaseWebMessage<B, Readonly<WebRequestContext>> {
62
+
63
+ }
42
64
  ```
43
65
 
44
66
  **Code: Response Shape**
45
67
  ```typescript
68
+ import { BaseWebMessage } from './message.ts';
69
+
70
+ export interface WebResponseContext {
71
+ httpStatusCode?: number;
72
+ }
73
+
74
+ /**
75
+ * Web Response as a simple object
76
+ */
46
77
  export class WebResponse<B = unknown> extends BaseWebMessage<B, WebResponseContext> {
78
+
47
79
  /**
48
80
  * Build the redirect
49
81
  * @param location Location to redirect to
50
82
  * @param statusCode Status code
51
83
  */
52
- static redirect(location: string, statusCode = 302): WebResponse<undefined>;
84
+ static redirect(location: string, statusCode = 302): WebResponse<undefined> {
85
+ return new WebResponse({ context: { httpStatusCode: statusCode }, headers: { Location: location } });
86
+ }
53
87
  }
54
88
  ```
55
89
 
@@ -60,6 +94,7 @@ To start, we must define a [@Controller](https://github.com/travetto/travetto/tr
60
94
  * `path` - The required context path the controller will operate atop
61
95
  * `title` - The definition of the controller
62
96
  * `description` - High level description fo the controller
97
+
63
98
  Additionally, the module is predicated upon [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support."), and so all standard injection techniques (constructor, fields) work for registering dependencies.
64
99
 
65
100
  [JSDoc](http://usejsdoc.org/about-getting-started.html) comments can also be used to define the `title` attribute.
@@ -85,9 +120,11 @@ The most common pattern is to register HTTP-driven endpoints. The HTTP methods
85
120
  * [@Patch](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L64)
86
121
  * [@Head](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L76)
87
122
  * [@Options](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L82)
123
+
88
124
  Similar to the Controller, each endpoint decorator handles the following config:
89
125
  * `title` - The definition of the endpoint
90
126
  * `description` - High level description fo the endpoint
127
+
91
128
  [JSDoc](http://usejsdoc.org/about-getting-started.html) comments can also be used to define the `title` attribute, as well as describing the parameters using `@param` tags in the comment.
92
129
 
93
130
  The return type of the method will also be used to describe the `responseType` if not specified manually.
@@ -121,11 +158,13 @@ Endpoints can be configured to describe and enforce parameter behavior. Request
121
158
  * [@QueryParam](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/param.ts#L43) - Query params - can be either a single value or bind to a whole object
122
159
  * [@Body](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/param.ts#L55) - Request body
123
160
  * [@HeaderParam](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/param.ts#L49) - Header values
161
+
124
162
  Each [@Param](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/param.ts#L24) can be configured to indicate:
125
163
  * `name` - Name of param, field name, defaults to handler parameter name if necessary
126
164
  * `description` - Description of param, pulled from [JSDoc](http://usejsdoc.org/about-getting-started.html), or defaults to name if empty
127
165
  * `required?` - Is the field required?, defaults to whether or not the parameter itself is optional
128
166
  * `type` - The class of the type to be enforced, pulled from parameter type
167
+
129
168
  [JSDoc](http://usejsdoc.org/about-getting-started.html) comments can also be used to describe parameters using `@param` tags in the comment.
130
169
 
131
170
  **Code: Full-fledged Controller with Endpoints**
@@ -720,15 +759,5 @@ export class SimpleEndpoints {
720
759
  }
721
760
  ```
722
761
 
723
- ## SSL Support
724
- Additionally the framework supports SSL out of the box, by allowing you to specify your public and private keys for the cert. In dev mode, the framework will also automatically generate a self-signed cert if:
725
- * SSL support is configured
726
- * [node-forge](https://www.npmjs.com/package/node-forge) is installed
727
- * Not running in prod
728
- * No keys provided
729
- This is useful for local development where you implicitly trust the cert.
730
-
731
- SSL support can be enabled by setting `web.ssl.active: true` in your config. The key/cert can be specified as string directly in the config file/environment variables. The key/cert can also be specified as a path to be picked up by [RuntimeResources](https://github.com/travetto/travetto/tree/main/module/runtime/src/resources.ts#L8).
732
-
733
762
  ## Full Config
734
763
  The entire [WebConfig](https://github.com/travetto/travetto/tree/main/module/web/src/config.ts#L7) which will show the full set of valid configuration parameters for the web module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web",
3
- "version": "6.0.0-rc.2",
3
+ "version": "6.0.0-rc.3",
4
4
  "description": "Declarative api for Web Applications with support for the dependency injection.",
5
5
  "keywords": [
6
6
  "web",
@@ -42,7 +42,7 @@
42
42
  "negotiator": "^1.0.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@travetto/cli": "^6.0.0-rc.2",
45
+ "@travetto/cli": "^6.0.0-rc.3",
46
46
  "@travetto/test": "^6.0.0-rc.2",
47
47
  "@travetto/transformer": "^6.0.0-rc.3"
48
48
  },
@@ -19,4 +19,6 @@ export interface WebRequestContext {
19
19
  /**
20
20
  * Web Request object
21
21
  */
22
- export class WebRequest<B = unknown> extends BaseWebMessage<B, Readonly<WebRequestContext>> { }
22
+ export class WebRequest<B = unknown> extends BaseWebMessage<B, Readonly<WebRequestContext>> {
23
+
24
+ }