vona-cli-set-api 1.0.11 → 1.0.13
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/cli/templates/create/project/basic/boilerplate/.vscode/extensions.json +1 -1
- package/cli/templates/create/project/basic/boilerplate/env/.env +4 -0
- package/cli/templates/create/project/basic/boilerplate/package.original.json +8 -3
- package/cli/templates/create/project/basic/boilerplate/src/backend/config/config/config.local.ts +5 -0
- package/cli/templates/create/project/basic/boilerplate/src/backend/config/config/config.test.ts +5 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/package.json +51 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/.metadata/index.ts +96 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/.metadata/this.ts +2 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/controller/menu.ts +17 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/index.ts +1 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/src/service/menu.ts +20 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/tsconfig.build.json +8 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-base/tsconfig.json +7 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/package.json +51 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/.metadata/index.ts +95 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/.metadata/this.ts +2 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/bean/meta.printTip.ts +13 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/config/locale/en-us.ts +4 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/config/locale/zh-cn.ts +4 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/controller/home.ts +18 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/src/index.ts +1 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/static/img/vona.png +0 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/tsconfig.build.json +8 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-index/tsconfig.json +7 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/package.json +52 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/.metadata/index.ts +275 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/.metadata/this.ts +2 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/bean/meta.version.ts +30 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/config/config.ts +13 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/controller/passport.ts +115 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/dto/auth.ts +13 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/dto/passport.ts +16 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/dto/passportJwt.ts +16 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/entity/user.ts +19 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/index.ts +3 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/lib/authAdapter.ts +11 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/lib/index.ts +2 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/lib/userAdapter.ts +28 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/model/user.ts +5 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/service/authInnerAdapter.ts +14 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/service/authTokenAdapter.ts +34 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/service/passportAdapter.ts +30 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/service/redisToken.ts +63 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/service/userInnerAdapter.ts +35 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/types/auth.ts +3 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/types/index.ts +3 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/types/passport.ts +16 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/src/types/user.ts +8 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/tsconfig.build.json +8 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/modules/home-user/tsconfig.json +7 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/package.json +15 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/tsconfig.base.json +4 -0
- package/cli/templates/create/project/basic/boilerplate/src/suite/a-home/tsconfig.json +16 -0
- package/package.json +7 -7
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { BeanScopeUtil, TypeModuleConfig } from 'vona';
|
|
2
|
+
import type { IDecoratorModelOptions } from 'vona-module-a-database';
|
|
3
|
+
import type { TypeControllerOptionsActions } from 'vona-module-a-openapi';
|
|
4
|
+
import type { TypeEntityOptionsFields } from 'vona-module-a-openapi';
|
|
5
|
+
import type { config } from '../config/config.ts';
|
|
6
|
+
|
|
7
|
+
import type { IControllerOptionsPassport } from '../controller/passport.ts';
|
|
8
|
+
/** controller: end */
|
|
9
|
+
/** controller: begin */
|
|
10
|
+
// @ts-ignore ignore
|
|
11
|
+
import type { ControllerPassport } from '../controller/passport.ts';
|
|
12
|
+
|
|
13
|
+
import type { IDtoOptionsAuth } from '../dto/auth.ts';
|
|
14
|
+
/** dto: end */
|
|
15
|
+
/** dto: begin */
|
|
16
|
+
import type { DtoAuth } from '../dto/auth.ts';
|
|
17
|
+
import type { IDtoOptionsPassport } from '../dto/passport.ts';
|
|
18
|
+
import type { DtoPassport } from '../dto/passport.ts';
|
|
19
|
+
import type { IDtoOptionsPassportJwt } from '../dto/passportJwt.ts';
|
|
20
|
+
import type { DtoPassportJwt } from '../dto/passportJwt.ts';
|
|
21
|
+
import type { IEntityOptionsUser } from '../entity/user.ts';
|
|
22
|
+
/** entity: end */
|
|
23
|
+
/** entity: begin */
|
|
24
|
+
import type { EntityUser } from '../entity/user.ts';
|
|
25
|
+
|
|
26
|
+
/** model: end */
|
|
27
|
+
/** model: begin */
|
|
28
|
+
import type { ModelUser } from '../model/user.ts';
|
|
29
|
+
/** service: end */
|
|
30
|
+
/** service: begin */
|
|
31
|
+
import type { ServiceAuthInnerAdapter } from '../service/authInnerAdapter.ts';
|
|
32
|
+
import type { ServiceAuthTokenAdapter } from '../service/authTokenAdapter.ts';
|
|
33
|
+
import type { ServicePassportAdapter } from '../service/passportAdapter.ts';
|
|
34
|
+
import type { ServiceRedisToken } from '../service/redisToken.ts';
|
|
35
|
+
import type { ServiceUserInnerAdapter } from '../service/userInnerAdapter.ts';
|
|
36
|
+
/** config: end */
|
|
37
|
+
/** scope: begin */
|
|
38
|
+
import { BeanScopeBase } from 'vona';
|
|
39
|
+
/** service: end */
|
|
40
|
+
/** service: begin */
|
|
41
|
+
|
|
42
|
+
import { Scope } from 'vona-module-a-bean';
|
|
43
|
+
import 'vona';
|
|
44
|
+
import 'vona';
|
|
45
|
+
import 'vona';
|
|
46
|
+
import 'vona';
|
|
47
|
+
import 'vona';
|
|
48
|
+
import 'vona';
|
|
49
|
+
|
|
50
|
+
import 'vona';
|
|
51
|
+
/** model: end */
|
|
52
|
+
/** meta: begin */
|
|
53
|
+
export * from '../bean/meta.version.ts';
|
|
54
|
+
declare module 'vona-module-a-database' {
|
|
55
|
+
|
|
56
|
+
export interface IEntityRecord {
|
|
57
|
+
'home-user:user': IEntityOptionsUser;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
declare module 'vona-module-home-user' {
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
export interface IModuleEntity {
|
|
65
|
+
user: EntityUser;
|
|
66
|
+
}
|
|
67
|
+
/** entity: end */
|
|
68
|
+
/** entity: begin */
|
|
69
|
+
declare module 'vona-module-home-user' {
|
|
70
|
+
|
|
71
|
+
export interface EntityUser {
|
|
72
|
+
$column: <K extends keyof Omit<EntityUser, '$column' | '$columns' | '$table'>>(column: K) => K;
|
|
73
|
+
$columns: <K extends keyof Omit<EntityUser, '$column' | '$columns' | '$table'>>(...columns: K[]) => K[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface IEntityOptionsUser {
|
|
77
|
+
fields?: TypeEntityOptionsFields<EntityUser, IEntityOptionsUser['fieldsMore']>;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** controller: end */
|
|
81
|
+
/** config: begin */
|
|
82
|
+
export * from '../config/config.ts';
|
|
83
|
+
declare module 'vona-module-a-database' {
|
|
84
|
+
|
|
85
|
+
export interface IModelRecord {
|
|
86
|
+
'home-user:user': IDecoratorModelOptions;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
declare module 'vona-module-home-user' {
|
|
91
|
+
|
|
92
|
+
export interface ModelUser {
|
|
93
|
+
/** @internal */
|
|
94
|
+
get scope(): ScopeModuleHomeUser;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export interface IModuleModel {
|
|
98
|
+
user: ModelUser;
|
|
99
|
+
}
|
|
100
|
+
/** service: end */
|
|
101
|
+
/** controller: begin */
|
|
102
|
+
export * from '../controller/passport.ts';
|
|
103
|
+
declare module 'vona' {
|
|
104
|
+
|
|
105
|
+
export interface IMetaRecord {
|
|
106
|
+
'home-user:version': never;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
declare module 'vona-module-home-user' {
|
|
111
|
+
|
|
112
|
+
export interface MetaVersion {
|
|
113
|
+
/** @internal */
|
|
114
|
+
get scope(): ScopeModuleHomeUser;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** meta: end */
|
|
118
|
+
/** dto: begin */
|
|
119
|
+
export * from '../dto/auth.ts';
|
|
120
|
+
export * from '../dto/passport.ts';
|
|
121
|
+
export * from '../dto/passportJwt.ts';
|
|
122
|
+
declare module 'vona-module-a-web' {
|
|
123
|
+
|
|
124
|
+
export interface IDtoRecord {
|
|
125
|
+
'home-user:auth': IDtoOptionsAuth;
|
|
126
|
+
'home-user:passport': IDtoOptionsPassport;
|
|
127
|
+
'home-user:passportJwt': IDtoOptionsPassportJwt;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
declare module 'vona-module-home-user' {
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
declare module 'vona-module-home-user' {
|
|
135
|
+
|
|
136
|
+
export interface IDtoOptionsAuth {
|
|
137
|
+
fields?: TypeEntityOptionsFields<DtoAuth, IDtoOptionsAuth['fieldsMore']>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface IDtoOptionsPassport {
|
|
141
|
+
fields?: TypeEntityOptionsFields<DtoPassport, IDtoOptionsPassport['fieldsMore']>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface IDtoOptionsPassportJwt {
|
|
145
|
+
fields?: TypeEntityOptionsFields<DtoPassportJwt, IDtoOptionsPassportJwt['fieldsMore']>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** entity: begin */
|
|
149
|
+
export * from '../entity/user.ts';
|
|
150
|
+
/** entity: end */
|
|
151
|
+
/** model: begin */
|
|
152
|
+
export * from '../model/user.ts';
|
|
153
|
+
/** dto: end */
|
|
154
|
+
/** service: begin */
|
|
155
|
+
export * from '../service/authInnerAdapter.ts';
|
|
156
|
+
export * from '../service/authTokenAdapter.ts';
|
|
157
|
+
export * from '../service/passportAdapter.ts';
|
|
158
|
+
declare module 'vona-module-a-web' {
|
|
159
|
+
|
|
160
|
+
export interface IServiceRecord {
|
|
161
|
+
'home-user:authInnerAdapter': never;
|
|
162
|
+
'home-user:authTokenAdapter': never;
|
|
163
|
+
'home-user:passportAdapter': never;
|
|
164
|
+
'home-user:redisToken': never;
|
|
165
|
+
'home-user:userInnerAdapter': never;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
declare module 'vona-module-home-user' {
|
|
170
|
+
|
|
171
|
+
export interface ServiceAuthInnerAdapter {
|
|
172
|
+
/** @internal */
|
|
173
|
+
get scope(): ScopeModuleHomeUser;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface ServiceAuthTokenAdapter {
|
|
177
|
+
/** @internal */
|
|
178
|
+
get scope(): ScopeModuleHomeUser;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ServicePassportAdapter {
|
|
182
|
+
/** @internal */
|
|
183
|
+
get scope(): ScopeModuleHomeUser;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface ServiceRedisToken {
|
|
187
|
+
/** @internal */
|
|
188
|
+
get scope(): ScopeModuleHomeUser;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface ServiceUserInnerAdapter {
|
|
192
|
+
/** @internal */
|
|
193
|
+
get scope(): ScopeModuleHomeUser;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export interface IModuleService {
|
|
197
|
+
authInnerAdapter: ServiceAuthInnerAdapter;
|
|
198
|
+
authTokenAdapter: ServiceAuthTokenAdapter;
|
|
199
|
+
passportAdapter: ServicePassportAdapter;
|
|
200
|
+
redisToken: ServiceRedisToken;
|
|
201
|
+
userInnerAdapter: ServiceUserInnerAdapter;
|
|
202
|
+
}
|
|
203
|
+
declare module 'vona' {
|
|
204
|
+
export interface IBeanRecordGeneral {
|
|
205
|
+
'home-user.service.authInnerAdapter': ServiceAuthInnerAdapter;
|
|
206
|
+
'home-user.service.authTokenAdapter': ServiceAuthTokenAdapter;
|
|
207
|
+
'home-user.service.passportAdapter': ServicePassportAdapter;
|
|
208
|
+
'home-user.service.redisToken': ServiceRedisToken;
|
|
209
|
+
'home-user.service.userInnerAdapter': ServiceUserInnerAdapter;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export * from '../service/redisToken.ts';
|
|
213
|
+
declare module 'vona-module-a-web' {
|
|
214
|
+
|
|
215
|
+
export interface IControllerRecord {
|
|
216
|
+
'home-user:passport': IControllerOptionsPassport;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
declare module 'vona-module-home-user' {
|
|
221
|
+
|
|
222
|
+
export interface ControllerPassport {
|
|
223
|
+
/** @internal */
|
|
224
|
+
get scope(): ScopeModuleHomeUser;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
declare module 'vona-module-home-user' {
|
|
228
|
+
|
|
229
|
+
export interface IControllerOptionsPassport {
|
|
230
|
+
actions?: TypeControllerOptionsActions<ControllerPassport>;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
declare module 'vona-module-a-web' {
|
|
234
|
+
export interface IApiPathGetRecord {
|
|
235
|
+
'/home/user/passport/current': undefined;
|
|
236
|
+
'/home/user/passport/login/:module/:providerName/:clientName?': undefined;
|
|
237
|
+
'/home/user/passport/associate/:module/:providerName/:clientName?': undefined;
|
|
238
|
+
'/home/user/passport/migrate/:module/:providerName/:clientName?': undefined;
|
|
239
|
+
}
|
|
240
|
+
export interface IApiPathPostRecord {
|
|
241
|
+
'/home/user/passport/logout': undefined;
|
|
242
|
+
'/home/user/passport/login': undefined;
|
|
243
|
+
'/home/user/passport/refreshAuthToken': undefined;
|
|
244
|
+
'/home/user/passport/createPassportJwtFromOauthCode': undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
export * from '../service/userInnerAdapter.ts';
|
|
249
|
+
|
|
250
|
+
@Scope()
|
|
251
|
+
export class ScopeModuleHomeUser extends BeanScopeBase {}
|
|
252
|
+
|
|
253
|
+
export interface ScopeModuleHomeUser {
|
|
254
|
+
util: BeanScopeUtil;
|
|
255
|
+
config: TypeModuleConfig<typeof config>;
|
|
256
|
+
entity: IModuleEntity;
|
|
257
|
+
model: IModuleModel;
|
|
258
|
+
service: IModuleService;
|
|
259
|
+
}
|
|
260
|
+
declare module 'vona' {
|
|
261
|
+
export interface IBeanScopeRecord {
|
|
262
|
+
'home-user': ScopeModuleHomeUser;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface IBeanScopeContainer {
|
|
266
|
+
homeUser: ScopeModuleHomeUser;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface IBeanScopeConfig {
|
|
270
|
+
'home-user': ReturnType<typeof config>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** scope: end */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IMetaVersionInit, IMetaVersionInitOptions, IMetaVersionUpdate, IMetaVersionUpdateOptions } from 'vona-module-a-version';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { Meta } from 'vona-module-a-meta';
|
|
4
|
+
|
|
5
|
+
@Meta()
|
|
6
|
+
export class MetaVersion extends BeanBase implements IMetaVersionUpdate, IMetaVersionInit {
|
|
7
|
+
async update(options: IMetaVersionUpdateOptions) {
|
|
8
|
+
if (options.version === 1) {
|
|
9
|
+
// homeUser
|
|
10
|
+
const entityUser = this.scope.entity.user;
|
|
11
|
+
await this.bean.model.createTable(entityUser.$table, table => {
|
|
12
|
+
table.basicFields();
|
|
13
|
+
table.string(entityUser.$column('name'), 255);
|
|
14
|
+
table.string(entityUser.$column('avatar'), 255);
|
|
15
|
+
table.string(entityUser.$column('locale'), 255);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async init(options: IMetaVersionInitOptions) {
|
|
21
|
+
if (options.version === 1) {
|
|
22
|
+
// admin
|
|
23
|
+
await this.scope.model.user.insert({
|
|
24
|
+
name: 'admin',
|
|
25
|
+
avatar: ':emoji:flower',
|
|
26
|
+
locale: undefined,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VonaApplication } from 'vona';
|
|
2
|
+
import type { IServiceRecord } from 'vona-module-a-web';
|
|
3
|
+
|
|
4
|
+
export function config(_app: VonaApplication) {
|
|
5
|
+
return {
|
|
6
|
+
adapter: {
|
|
7
|
+
authInner: 'a-auth:authInnerAdapter' as keyof IServiceRecord,
|
|
8
|
+
},
|
|
9
|
+
redisToken: {
|
|
10
|
+
maxAge: 30 * 24 * 60 * 60,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { IAuthenticateOptions, IAuthProviderRecord } from 'vona-module-a-auth';
|
|
2
|
+
import type { IJwtToken } from 'vona-module-a-jwt';
|
|
3
|
+
import type { IDecoratorControllerOptions } from 'vona-module-a-web';
|
|
4
|
+
import type { EntityUser } from '../entity/user.ts';
|
|
5
|
+
import { BeanBase } from 'vona';
|
|
6
|
+
import { DtoAuthSimple } from 'vona-module-a-authsimple';
|
|
7
|
+
import { DtoJwtToken } from 'vona-module-a-jwt';
|
|
8
|
+
import { Api, Arg, v } from 'vona-module-a-openapi';
|
|
9
|
+
import { Passport } from 'vona-module-a-user';
|
|
10
|
+
import { Controller, Web } from 'vona-module-a-web';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { DtoPassport } from '../dto/passport.ts';
|
|
13
|
+
import { DtoPassportJwt } from '../dto/passportJwt.ts';
|
|
14
|
+
|
|
15
|
+
export interface IControllerOptionsPassport extends IDecoratorControllerOptions {}
|
|
16
|
+
|
|
17
|
+
@Controller<IControllerOptionsPassport>('passport')
|
|
18
|
+
export class ControllerPassport extends BeanBase {
|
|
19
|
+
@Web.get('current')
|
|
20
|
+
@Api.body(v.optional(), v.object(DtoPassport))
|
|
21
|
+
current(): DtoPassport | undefined {
|
|
22
|
+
return this._combineDtoPassport();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Web.post('logout')
|
|
26
|
+
async logout() {
|
|
27
|
+
return await this.bean.passport.signout();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Web.post('login')
|
|
31
|
+
@Passport.public()
|
|
32
|
+
@Api.body(v.object(DtoPassportJwt))
|
|
33
|
+
async loginSimple(@Arg.body() clientOptions: DtoAuthSimple): Promise<DtoPassportJwt> {
|
|
34
|
+
const jwt = await this.bean.authSimple.authenticate(clientOptions, 'default');
|
|
35
|
+
return this._combineDtoPassportJwt(jwt);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Web.get('login/:module/:providerName/:clientName?')
|
|
39
|
+
@Passport.public()
|
|
40
|
+
@Api.body(v.object(DtoPassportJwt))
|
|
41
|
+
async login<T extends keyof IAuthProviderRecord>(
|
|
42
|
+
@Arg.param('module') module: string,
|
|
43
|
+
@Arg.param('providerName') providerName: string,
|
|
44
|
+
@Arg.param('clientName', z.string().optional()) clientName?: IAuthenticateOptions<IAuthProviderRecord[T]>['clientName'],
|
|
45
|
+
@Arg.query('redirect', v.optional()) redirect?: string,
|
|
46
|
+
): Promise<DtoPassportJwt> {
|
|
47
|
+
const jwt = await this.bean.auth.authenticate(`${module}:${providerName}` as T, {
|
|
48
|
+
state: { intention: 'login', redirect },
|
|
49
|
+
clientName,
|
|
50
|
+
});
|
|
51
|
+
return this._combineDtoPassportJwt(jwt);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Web.get('associate/:module/:providerName/:clientName?')
|
|
55
|
+
@Api.body(v.object(DtoPassportJwt))
|
|
56
|
+
async associate<T extends keyof IAuthProviderRecord>(
|
|
57
|
+
@Arg.param('module') module: string,
|
|
58
|
+
@Arg.param('providerName') providerName: string,
|
|
59
|
+
@Arg.param('clientName', z.string().optional()) clientName?: IAuthenticateOptions<IAuthProviderRecord[T]>['clientName'],
|
|
60
|
+
@Arg.query('redirect', v.optional()) redirect?: string,
|
|
61
|
+
): Promise<DtoPassportJwt> {
|
|
62
|
+
const jwt = await this.bean.auth.authenticate(`${module}:${providerName}` as T, {
|
|
63
|
+
state: { intention: 'associate', redirect },
|
|
64
|
+
clientName,
|
|
65
|
+
});
|
|
66
|
+
return this._combineDtoPassportJwt(jwt);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Web.get('migrate/:module/:providerName/:clientName?')
|
|
70
|
+
@Api.body(v.object(DtoPassportJwt))
|
|
71
|
+
async migrate<T extends keyof IAuthProviderRecord>(
|
|
72
|
+
@Arg.param('module') module: string,
|
|
73
|
+
@Arg.param('providerName') providerName: string,
|
|
74
|
+
@Arg.param('clientName', z.string().optional()) clientName?: IAuthenticateOptions<IAuthProviderRecord[T]>['clientName'],
|
|
75
|
+
@Arg.query('redirect', v.optional()) redirect?: string,
|
|
76
|
+
): Promise<DtoPassportJwt> {
|
|
77
|
+
const jwt = await this.bean.auth.authenticate(`${module}:${providerName}` as T, {
|
|
78
|
+
state: { intention: 'migrate', redirect },
|
|
79
|
+
clientName,
|
|
80
|
+
});
|
|
81
|
+
return this._combineDtoPassportJwt(jwt);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Web.post('refreshAuthToken')
|
|
85
|
+
@Passport.public()
|
|
86
|
+
@Api.body(v.object(DtoJwtToken))
|
|
87
|
+
async refreshAuthToken(@Arg.body('refreshToken') refreshToken: string): Promise<DtoJwtToken> {
|
|
88
|
+
return await this.bean.passport.refreshAuthToken(refreshToken);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Web.post('createPassportJwtFromOauthCode')
|
|
92
|
+
@Passport.public()
|
|
93
|
+
@Api.body(v.object(DtoPassportJwt))
|
|
94
|
+
async createPassportJwtFromOauthCode(@Arg.body('code') code: string): Promise<DtoPassportJwt> {
|
|
95
|
+
const jwt = await this.bean.passport.createAuthTokenFromOauthCode(code);
|
|
96
|
+
return this._combineDtoPassportJwt(jwt);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private _combineDtoPassportJwt(jwt?: IJwtToken): DtoPassportJwt {
|
|
100
|
+
if (!jwt) this.app.throw(403);
|
|
101
|
+
return {
|
|
102
|
+
passport: this._combineDtoPassport()!,
|
|
103
|
+
jwt: jwt as DtoJwtToken,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private _combineDtoPassport(): DtoPassport | undefined {
|
|
108
|
+
const passport = this.bean.passport.getCurrent();
|
|
109
|
+
if (!passport) return;
|
|
110
|
+
return {
|
|
111
|
+
user: passport.user as EntityUser,
|
|
112
|
+
auth: { id: passport.auth!.id },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
2
|
+
import type { IAuthBase } from 'vona-module-a-user';
|
|
3
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
4
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
5
|
+
import { Dto } from 'vona-module-a-web';
|
|
6
|
+
|
|
7
|
+
export interface IDtoOptionsAuth extends IDecoratorDtoOptions {}
|
|
8
|
+
|
|
9
|
+
@Dto<IDtoOptionsAuth>()
|
|
10
|
+
export class DtoAuth implements IAuthBase {
|
|
11
|
+
@Api.field(v.tableIdentity())
|
|
12
|
+
id: TableIdentity;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { Api } from 'vona-module-a-openapi';
|
|
3
|
+
import { Dto } from 'vona-module-a-web';
|
|
4
|
+
import { EntityUser } from '../entity/user.ts';
|
|
5
|
+
import { DtoAuth } from './auth.ts';
|
|
6
|
+
|
|
7
|
+
export interface IDtoOptionsPassport extends IDecoratorDtoOptions {}
|
|
8
|
+
|
|
9
|
+
@Dto<IDtoOptionsPassport>()
|
|
10
|
+
export class DtoPassport {
|
|
11
|
+
@Api.field()
|
|
12
|
+
user: EntityUser;
|
|
13
|
+
|
|
14
|
+
@Api.field()
|
|
15
|
+
auth: DtoAuth;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { DtoJwtToken } from 'vona-module-a-jwt';
|
|
3
|
+
import { Api } from 'vona-module-a-openapi';
|
|
4
|
+
import { Dto } from 'vona-module-a-web';
|
|
5
|
+
import { DtoPassport } from './passport.ts';
|
|
6
|
+
|
|
7
|
+
export interface IDtoOptionsPassportJwt extends IDecoratorDtoOptions {}
|
|
8
|
+
|
|
9
|
+
@Dto<IDtoOptionsPassportJwt>()
|
|
10
|
+
export class DtoPassportJwt {
|
|
11
|
+
@Api.field()
|
|
12
|
+
passport: DtoPassport;
|
|
13
|
+
|
|
14
|
+
@Api.field()
|
|
15
|
+
jwt: DtoJwtToken;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ILocaleInfos } from 'vona';
|
|
2
|
+
import type { IDecoratorEntityOptions } from 'vona-module-a-database';
|
|
3
|
+
import { Entity, EntityBase } from 'vona-module-a-database';
|
|
4
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
export interface IEntityOptionsUser extends IDecoratorEntityOptions {}
|
|
8
|
+
|
|
9
|
+
@Entity<IEntityOptionsUser>('homeUser')
|
|
10
|
+
export class EntityUser extends EntityBase {
|
|
11
|
+
@Api.field()
|
|
12
|
+
name: string;
|
|
13
|
+
|
|
14
|
+
@Api.field(v.optional())
|
|
15
|
+
avatar?: string;
|
|
16
|
+
|
|
17
|
+
@Api.field(z.string().optional())
|
|
18
|
+
locale?: keyof ILocaleInfos | undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
2
|
+
import type { IAuthBase } from 'vona-module-a-user';
|
|
3
|
+
import type { IAuth } from '../types/auth.ts';
|
|
4
|
+
import { cast } from 'vona';
|
|
5
|
+
import { setAuthAdapter } from 'vona-module-a-user';
|
|
6
|
+
|
|
7
|
+
setAuthAdapter({ getAuthId });
|
|
8
|
+
|
|
9
|
+
function getAuthId(auth: IAuthBase): TableIdentity {
|
|
10
|
+
return cast<IAuth>(auth).id;
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ILocaleInfos } from 'vona';
|
|
2
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
3
|
+
import type { IUserBase } from 'vona-module-a-user';
|
|
4
|
+
import type { IUser } from '../types/user.ts';
|
|
5
|
+
import { cast } from 'vona';
|
|
6
|
+
import { setUserAdapter } from 'vona-module-a-user';
|
|
7
|
+
|
|
8
|
+
setUserAdapter({ getUserId, getUserName, getUserAvatar, getUserLocale, getUserAnonymous });
|
|
9
|
+
|
|
10
|
+
function getUserId(user: IUserBase): TableIdentity {
|
|
11
|
+
return cast<IUser>(user).id;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getUserName(user: IUserBase): string {
|
|
15
|
+
return cast<IUser>(user).name;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getUserAvatar(user: IUserBase): string | undefined {
|
|
19
|
+
return cast<IUser>(user).avatar;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getUserLocale(user: IUserBase): keyof ILocaleInfos | undefined {
|
|
23
|
+
return cast<IUser>(user).locale;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getUserAnonymous(user: IUserBase): boolean {
|
|
27
|
+
return cast<IUser>(user).id === -1;
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IAuthBase, IAuthInnerAdapter } from 'vona-module-a-user';
|
|
2
|
+
import type { IAuth } from '../types/auth.ts';
|
|
3
|
+
import { BeanBase, beanFullNameFromOnionName } from 'vona';
|
|
4
|
+
import { Service } from 'vona-module-a-web';
|
|
5
|
+
|
|
6
|
+
@Service()
|
|
7
|
+
export class ServiceAuthInnerAdapter extends BeanBase implements IAuthInnerAdapter {
|
|
8
|
+
async get(auth: Partial<IAuth>): Promise<IAuthBase | undefined> {
|
|
9
|
+
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.authInner, 'service');
|
|
10
|
+
const beanAuth = this.bean._getBean<IAuthInnerAdapter>(beanFullName as never);
|
|
11
|
+
if (beanAuth) return await beanAuth.get(auth);
|
|
12
|
+
return auth as unknown as IAuthBase | undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IAuthTokenAdapter, IUserBase } from 'vona-module-a-user';
|
|
2
|
+
import type { IPayloadData } from '../types/passport.ts';
|
|
3
|
+
import { BeanBase, createHash, uuidv4 } from 'vona';
|
|
4
|
+
import { Service } from 'vona-module-a-web';
|
|
5
|
+
|
|
6
|
+
@Service()
|
|
7
|
+
export class ServiceAuthTokenAdapter extends BeanBase implements IAuthTokenAdapter {
|
|
8
|
+
async create(payloadData: IPayloadData): Promise<IPayloadData> {
|
|
9
|
+
const token = (payloadData.authId.toString() === '-1') ? createHash(payloadData.authId.toString()) : uuidv4();
|
|
10
|
+
const payloadDataNew = Object.assign({}, payloadData, { token });
|
|
11
|
+
await this.scope.service.redisToken.create(payloadDataNew);
|
|
12
|
+
return payloadDataNew;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async retrieve(payloadData: IPayloadData): Promise<IPayloadData | undefined> {
|
|
16
|
+
return await this.scope.service.redisToken.retrieve(payloadData);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async verify(payloadData: IPayloadData): Promise<boolean> {
|
|
20
|
+
return await this.scope.service.redisToken.verify(payloadData);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async refresh(payloadData: IPayloadData): Promise<void> {
|
|
24
|
+
await this.scope.service.redisToken.refresh(payloadData);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async remove(payloadData: IPayloadData): Promise<void> {
|
|
28
|
+
await this.scope.service.redisToken.remove(payloadData);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async removeAll(user: IUserBase): Promise<void> {
|
|
32
|
+
await this.scope.service.redisToken.removeAll(user);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IPassportAdapter, IPassportBase } from 'vona-module-a-user';
|
|
2
|
+
import type { IPassport, IPayloadData } from '../types/passport.ts';
|
|
3
|
+
import type { IUser } from '../types/user.ts';
|
|
4
|
+
import { BeanBase } from 'vona';
|
|
5
|
+
import { Service } from 'vona-module-a-web';
|
|
6
|
+
|
|
7
|
+
@Service()
|
|
8
|
+
export class ServicePassportAdapter extends BeanBase implements IPassportAdapter {
|
|
9
|
+
async isAdmin(user: IUser): Promise<boolean> {
|
|
10
|
+
return user.name === 'admin';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async setCurrent(passport: IPassport | undefined): Promise<IPassport | undefined> {
|
|
14
|
+
return passport;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async serialize(passport: IPassportBase): Promise<IPayloadData> {
|
|
18
|
+
const userId = passport.user!.id;
|
|
19
|
+
const authId = passport.auth!.id;
|
|
20
|
+
return { userId, authId };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async deserialize(payloadData: IPayloadData): Promise<IPassportBase | undefined> {
|
|
24
|
+
const user = await this.bean.userInner.get({ id: payloadData.userId });
|
|
25
|
+
if (!user) return;
|
|
26
|
+
const auth = await this.bean.authInner.get({ id: payloadData.authId });
|
|
27
|
+
if (!auth) return;
|
|
28
|
+
return { user, auth };
|
|
29
|
+
}
|
|
30
|
+
}
|