@travetto/web 6.0.0-rc.6 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -8
- package/package.json +11 -12
- package/support/transformer.web.ts +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/web/DOC.tsx and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# Web API
|
|
4
4
|
|
|
5
|
-
## Declarative
|
|
5
|
+
## Declarative support creating for Web Applications
|
|
6
6
|
|
|
7
7
|
**Install: @travetto/web**
|
|
8
8
|
```bash
|
|
@@ -16,11 +16,10 @@ yarn add @travetto/web
|
|
|
16
16
|
The module provides a declarative API for creating and describing a Web application. Since the framework is declarative, decorators are used to configure almost everything. The general layout of an application is a collection of [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L9)s that employ some combination of [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)s to help manage which functionality is executed before the [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14) code, within the [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L9). This module will look at:
|
|
17
17
|
* Request/Response Pattern
|
|
18
18
|
* Defining a [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L9)
|
|
19
|
-
* Defining an [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14)
|
|
20
|
-
* Using [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
|
|
19
|
+
* Defining an [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14)
|
|
20
|
+
* Using a [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
|
|
21
21
|
* Creating a Custom [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
|
|
22
22
|
* Cookies
|
|
23
|
-
* Error Handling
|
|
24
23
|
|
|
25
24
|
## Request/Response Pattern
|
|
26
25
|
Unlike other frameworks (e.g. [express](https://expressjs.com), [fastify](https://www.fastify.io/)), this module takes an approach that is similar to [AWS Lambda](https://aws.amazon.com/lambda/)'s model for requests and responses. What you can see here is that [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) are very simple objects, with the focus being on the `payload` and `body`. This is intended to provide maximal compatibility with non-HTTP sources. The driving goal is to support more than just standard HTTP servers but also allow for seamless integration with tools like event queues, web sockets, etc.
|
|
@@ -727,7 +726,28 @@ export class SimpleAuthInterceptor implements WebInterceptor {
|
|
|
727
726
|
```
|
|
728
727
|
|
|
729
728
|
## Cookie Support
|
|
730
|
-
|
|
729
|
+
Cookies are a unique element, within the framework, as they sit on the request and response flows. Ideally we would separate these out, but given the support for key rotation, there is a scenario in which reading a cookie on the request, will result in a cookie needing to be written on the response. Because of this, cookies are treated as being outside the normal [WebRequest](https://github.com/travetto/travetto/tree/main/module/web/src/types/request.ts#L11) activity, and is exposed as the [@ContextParam](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/param.ts#L61) [CookieJar](https://github.com/travetto/travetto/tree/main/module/web/src/util/cookie.ts#L11). The [CookieJar](https://github.com/travetto/travetto/tree/main/module/web/src/util/cookie.ts#L11) has a fairly basic contract:
|
|
730
|
+
|
|
731
|
+
**Code: CookieJar contract**
|
|
732
|
+
```typescript
|
|
733
|
+
export class CookieJar {
|
|
734
|
+
static parseCookieHeader(header: string): Cookie[];
|
|
735
|
+
static parseSetCookieHeader(header: string): Cookie;
|
|
736
|
+
static responseSuffix(c: Cookie): string[];
|
|
737
|
+
constructor({ keys, ...options }: CookieJarOptions = {});
|
|
738
|
+
import(cookies: Cookie[]): this;
|
|
739
|
+
has(name: string, opts: CookieGetOptions = {}): boolean;
|
|
740
|
+
get(name: string, opts: CookieGetOptions = {}): string | undefined;
|
|
741
|
+
set(cookie: Cookie): void;
|
|
742
|
+
getAll(): Cookie[];
|
|
743
|
+
importCookieHeader(header: string | null | undefined): this;
|
|
744
|
+
importSetCookieHeader(headers: string[] | null | undefined): this;
|
|
745
|
+
exportCookieHeader(): string;
|
|
746
|
+
exportSetCookieHeader(): string[];
|
|
747
|
+
}
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
`.get()`/`.set()` will be the most commonly used methods, and should align with standard cookie reading/writing behavior.
|
|
731
751
|
|
|
732
752
|
**Code: Sample Cookie Usage**
|
|
733
753
|
```typescript
|
|
@@ -758,6 +778,3 @@ export class SimpleEndpoints {
|
|
|
758
778
|
}
|
|
759
779
|
}
|
|
760
780
|
```
|
|
761
|
-
|
|
762
|
-
## Full Config
|
|
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,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web",
|
|
3
|
-
"version": "6.0.0
|
|
4
|
-
"description": "Declarative
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "Declarative support creating for Web Applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
7
|
-
"dependency-injection",
|
|
8
7
|
"decorators",
|
|
9
8
|
"travetto",
|
|
10
9
|
"typescript"
|
|
@@ -26,12 +25,12 @@
|
|
|
26
25
|
"directory": "module/web"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@travetto/config": "^6.0.0
|
|
30
|
-
"@travetto/context": "^6.0.0
|
|
31
|
-
"@travetto/di": "^6.0.0
|
|
32
|
-
"@travetto/registry": "^6.0.0
|
|
33
|
-
"@travetto/runtime": "^6.0.0
|
|
34
|
-
"@travetto/schema": "^6.0.0
|
|
28
|
+
"@travetto/config": "^6.0.0",
|
|
29
|
+
"@travetto/context": "^6.0.0",
|
|
30
|
+
"@travetto/di": "^6.0.0",
|
|
31
|
+
"@travetto/registry": "^6.0.0",
|
|
32
|
+
"@travetto/runtime": "^6.0.0",
|
|
33
|
+
"@travetto/schema": "^6.0.0",
|
|
35
34
|
"@types/fresh": "^0.5.2",
|
|
36
35
|
"@types/keygrip": "^1.0.6",
|
|
37
36
|
"@types/negotiator": "^0.6.3",
|
|
@@ -41,9 +40,9 @@
|
|
|
41
40
|
"negotiator": "^1.0.0"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
44
|
-
"@travetto/cli": "^6.0.0
|
|
45
|
-
"@travetto/test": "^6.0.0
|
|
46
|
-
"@travetto/transformer": "^6.0.0
|
|
43
|
+
"@travetto/cli": "^6.0.0",
|
|
44
|
+
"@travetto/test": "^6.0.0",
|
|
45
|
+
"@travetto/transformer": "^6.0.0"
|
|
47
46
|
},
|
|
48
47
|
"peerDependenciesMeta": {
|
|
49
48
|
"@travetto/transformer": {
|
|
@@ -56,7 +56,7 @@ export class WebTransformer {
|
|
|
56
56
|
config.name = '';
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (paramType.key === 'managed') {
|
|
59
|
+
if (paramType.key === 'managed' && paramType.importName.startsWith('@travetto/')) {
|
|
60
60
|
if (paramType.name === 'WebResponse') {
|
|
61
61
|
throw new Error(`${paramType.name} must be registered using @ContextParam`);
|
|
62
62
|
} else if (paramType.name === 'WebRequest') {
|