@travetto/scaffold 5.0.24 → 6.0.0-rc.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
CHANGED
|
@@ -39,7 +39,7 @@ In addition to the core functionality, the `rest` feature has some useful sub-fe
|
|
|
39
39
|
[Logging](https://github.com/travetto/travetto/tree/main/module/log#readme "Logging framework that integrates at the console.log level.") support for better formatting, [debug](https://www.npmjs.com/package/debug) like support, and colorized output. This is generally useful for server logs, especially during development.
|
|
40
40
|
|
|
41
41
|
## Authentication
|
|
42
|
-
Authentication is also supported on the Restful endpoints by selecting [Rest Auth](https://github.com/travetto/travetto/tree/main/module/auth-rest#readme "Rest authentication integration support for the Travetto framework") during setup. This will support basic authentication running out of local memory
|
|
42
|
+
Authentication is also supported on the Restful endpoints by selecting [Rest Auth](https://github.com/travetto/travetto/tree/main/module/auth-rest#readme "Rest authentication integration support for the Travetto framework") during setup. This will support basic authentication running out of local memory.
|
|
43
43
|
|
|
44
44
|
## Testing
|
|
45
45
|
[Testing](https://github.com/travetto/travetto/tree/main/module/test#readme "Declarative test framework") can also be configured out of the box to provide simple test cases for the data model.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/scaffold",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-rc.0",
|
|
4
4
|
"description": "App Scaffold for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"trv-scaffold": "bin/trv-scaffold.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/cli": "^
|
|
31
|
-
"@travetto/runtime": "^
|
|
30
|
+
"@travetto/cli": "^6.0.0-rc.0",
|
|
31
|
+
"@travetto/runtime": "^6.0.0-rc.0",
|
|
32
32
|
"enquirer": "^2.4.1",
|
|
33
33
|
"mustache": "^4.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@travetto/model": "^
|
|
36
|
+
"@travetto/model": "^6.0.0-rc.0",
|
|
37
37
|
"@types/mustache": "^4.2.5"
|
|
38
38
|
},
|
|
39
39
|
"travetto": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Authorizer, Authenticator, AuthenticationError } from '@travetto/auth';
|
|
2
|
-
import { SessionModelSymbol } from '@travetto/
|
|
2
|
+
import { SessionModelSymbol } from '@travetto/auth-session';
|
|
3
3
|
import { InjectableFactory } from '@travetto/di';
|
|
4
4
|
import { ModelExpirySupport } from '@travetto/model';
|
|
5
5
|
import { MemoryModelService } from '@travetto/model-memory';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Controller, Get, Post, Redirect
|
|
2
|
-
import {
|
|
1
|
+
import { Controller, Get, Post, Redirect } from '@travetto/rest';
|
|
2
|
+
import { Login, Authenticated, Logout } from '@travetto/auth-rest';
|
|
3
3
|
import { Principal } from '@travetto/auth';
|
|
4
|
-
import { Inject } from '@travetto/di';
|
|
5
4
|
|
|
6
5
|
import { BasicAuthSymbol } from './auth.config';
|
|
7
6
|
|
|
@@ -11,11 +10,8 @@ import { BasicAuthSymbol } from './auth.config';
|
|
|
11
10
|
@Controller('/auth')
|
|
12
11
|
export class ApiController {
|
|
13
12
|
|
|
14
|
-
@Inject()
|
|
15
|
-
svc: AuthService;
|
|
16
|
-
|
|
17
13
|
@Post('/login')
|
|
18
|
-
@
|
|
14
|
+
@Login(BasicAuthSymbol)
|
|
19
15
|
async getAll(): Promise<Redirect> {
|
|
20
16
|
return new Redirect('/auth/self', 301);
|
|
21
17
|
}
|
|
@@ -27,9 +23,8 @@ export class ApiController {
|
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
@Get('/logout')
|
|
30
|
-
@
|
|
31
|
-
async logout(
|
|
32
|
-
await this.svc.logout(req);
|
|
26
|
+
@Logout()
|
|
27
|
+
async logout(): Promise<Redirect> {
|
|
33
28
|
return new Redirect('/auth/self', 301);
|
|
34
29
|
}
|
|
35
30
|
}
|
|
@@ -3,8 +3,11 @@ import { NotFoundError } from '@travetto/model';
|
|
|
3
3
|
import { Inject } from '@travetto/di';
|
|
4
4
|
import { ModelQuery } from '@travetto/model-query';
|
|
5
5
|
import { Schema } from '@travetto/schema';
|
|
6
|
+
// {{#modules.auth}}
|
|
7
|
+
import { AuthContext } from '@travetto/auth';
|
|
8
|
+
// {{/modules.auth}}
|
|
6
9
|
// {{#modules.auth_rest}}
|
|
7
|
-
import {
|
|
10
|
+
import { Authenticated } from '@travetto/auth-rest';
|
|
8
11
|
// {{/modules.auth_rest}}
|
|
9
12
|
// @ts-expect-error
|
|
10
13
|
import { $_modelService_$ } from '$_modelImport_$';
|
|
@@ -32,10 +35,10 @@ export class TodoController {
|
|
|
32
35
|
@Inject()
|
|
33
36
|
source: $_modelService_$;
|
|
34
37
|
|
|
35
|
-
// {{#modules.
|
|
38
|
+
// {{#modules.auth}}
|
|
36
39
|
@Inject()
|
|
37
|
-
|
|
38
|
-
// {{/modules.
|
|
40
|
+
authContext: AuthContext;
|
|
41
|
+
// {{/modules.auth}}
|
|
39
42
|
|
|
40
43
|
/**
|
|
41
44
|
* Get all Todos
|
|
@@ -44,7 +47,7 @@ export class TodoController {
|
|
|
44
47
|
async getAll(query: Query): Promise<Todo[]> {
|
|
45
48
|
query.q ??= {};
|
|
46
49
|
// {{#modules.auth_rest}}
|
|
47
|
-
query.q.userId = this.
|
|
50
|
+
query.q.userId = this.authContext.principal?.id;
|
|
48
51
|
// {{/modules.auth_rest}}
|
|
49
52
|
return this.source.query(Todo, { where: query.q });
|
|
50
53
|
}
|
|
@@ -57,7 +60,7 @@ export class TodoController {
|
|
|
57
60
|
const q: ModelQuery<Todo> = { where: { id } };
|
|
58
61
|
// {{#modules.auth_rest}}
|
|
59
62
|
if (typeof q.where !== 'string') {
|
|
60
|
-
q.where!.userId = this.
|
|
63
|
+
q.where!.userId = this.authContext.principal?.id;
|
|
61
64
|
}
|
|
62
65
|
// {{/modules.auth_rest}}
|
|
63
66
|
return this.source.queryOne(Todo, q);
|
|
@@ -69,7 +72,7 @@ export class TodoController {
|
|
|
69
72
|
@Post('/')
|
|
70
73
|
async save(todo: Todo): Promise<Todo> {
|
|
71
74
|
// {{#modules.auth_rest}}
|
|
72
|
-
todo.userId = this.
|
|
75
|
+
todo.userId = this.authContext.principal?.id;
|
|
73
76
|
// {{/modules.auth_rest}}
|
|
74
77
|
return this.source.create(Todo, todo);
|
|
75
78
|
}
|
|
@@ -80,7 +83,7 @@ export class TodoController {
|
|
|
80
83
|
@Put('/:id')
|
|
81
84
|
async update(todo: Todo): Promise<Todo> {
|
|
82
85
|
// {{#modules.auth_rest}}
|
|
83
|
-
todo.userId = this.
|
|
86
|
+
todo.userId = this.authContext.principal?.id;
|
|
84
87
|
// {{/modules.auth_rest}}
|
|
85
88
|
return this.source.update(Todo, todo);
|
|
86
89
|
}
|
|
@@ -93,7 +96,7 @@ export class TodoController {
|
|
|
93
96
|
const q: ModelQuery<Todo> = { where: { id } };
|
|
94
97
|
// {{#modules.auth_rest}}
|
|
95
98
|
if (typeof q.where !== 'string') {
|
|
96
|
-
q.where!.userId = this.
|
|
99
|
+
q.where!.userId = this.authContext.principal?.id;
|
|
97
100
|
}
|
|
98
101
|
// {{/modules.auth_rest}}
|
|
99
102
|
if (await this.source.deleteByQuery(Todo, q) !== 1) {
|
package/support/bin/features.ts
CHANGED
|
@@ -45,8 +45,7 @@ export const FEATURES: Feature[] = [
|
|
|
45
45
|
title: 'Rest Authentication',
|
|
46
46
|
package: '@travetto/auth-rest',
|
|
47
47
|
addons: [
|
|
48
|
-
{ title: '
|
|
49
|
-
{ title: 'Auth Rest Session', package: ['@travetto/auth-rest-session', '@travetto/model-memory'] },
|
|
48
|
+
{ title: 'Session Support', package: ['@travetto/auth-session', '@travetto/auth-rest-session', '@travetto/model-memory'] },
|
|
50
49
|
]
|
|
51
50
|
},
|
|
52
51
|
{
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 ArcSine Technologies
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|