@smartsoft001/auth-shell-nestjs 2.76.0 → 2.81.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/index.js +454 -0
- package/package.json +1 -1
- package/src/lib/controllers/token/token.controller.d.ts +8 -0
- package/src/lib/nestjs.module.d.ts +12 -0
- package/.eslintrc.json +0 -26
- package/jest.config.ts +0 -26
- package/project.json +0 -37
- package/src/lib/controllers/token/token.controller.ts +0 -18
- package/src/lib/nestjs.module.ts +0 -74
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -20
- /package/src/{index.ts → index.d.ts} +0 -0
- /package/{test-setup.ts → test-setup.d.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
13
|
+
|
|
14
|
+
// packages/auth/shell/nestjs/src/lib/controllers/token/token.controller.ts
|
|
15
|
+
import { Body, Controller, Post, Req } from "@nestjs/common";
|
|
16
|
+
var TokenController = class {
|
|
17
|
+
constructor(service) {
|
|
18
|
+
this.service = service;
|
|
19
|
+
}
|
|
20
|
+
create(req, httpReq) {
|
|
21
|
+
return this.service.create(req, httpReq);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
__decorateClass([
|
|
25
|
+
Post(),
|
|
26
|
+
__decorateParam(0, Body()),
|
|
27
|
+
__decorateParam(1, Req())
|
|
28
|
+
], TokenController.prototype, "create", 1);
|
|
29
|
+
TokenController = __decorateClass([
|
|
30
|
+
Controller("token")
|
|
31
|
+
], TokenController);
|
|
32
|
+
|
|
33
|
+
// packages/auth/shell/nestjs/src/lib/nestjs.module.ts
|
|
34
|
+
import { HttpModule } from "@nestjs/axios";
|
|
35
|
+
import { Module } from "@nestjs/common";
|
|
36
|
+
import { JwtModule } from "@nestjs/jwt";
|
|
37
|
+
import { PassportModule } from "@nestjs/passport";
|
|
38
|
+
import { TypeOrmModule } from "@nestjs/typeorm";
|
|
39
|
+
|
|
40
|
+
// packages/auth/domain/src/lib/entities/user.entity.ts
|
|
41
|
+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
42
|
+
var User = class {
|
|
43
|
+
};
|
|
44
|
+
__decorateClass([
|
|
45
|
+
PrimaryGeneratedColumn()
|
|
46
|
+
], User.prototype, "id", 2);
|
|
47
|
+
__decorateClass([
|
|
48
|
+
Column("permissions")
|
|
49
|
+
], User.prototype, "permissions", 2);
|
|
50
|
+
__decorateClass([
|
|
51
|
+
Column("username")
|
|
52
|
+
], User.prototype, "username", 2);
|
|
53
|
+
__decorateClass([
|
|
54
|
+
Column("password")
|
|
55
|
+
], User.prototype, "password", 2);
|
|
56
|
+
__decorateClass([
|
|
57
|
+
Column("disabled")
|
|
58
|
+
], User.prototype, "disabled", 2);
|
|
59
|
+
__decorateClass([
|
|
60
|
+
Column("lastLoginDate")
|
|
61
|
+
], User.prototype, "lastLoginDate", 2);
|
|
62
|
+
__decorateClass([
|
|
63
|
+
Column("authRefreshToken")
|
|
64
|
+
], User.prototype, "authRefreshToken", 2);
|
|
65
|
+
__decorateClass([
|
|
66
|
+
Column("facebookUserId")
|
|
67
|
+
], User.prototype, "facebookUserId", 2);
|
|
68
|
+
__decorateClass([
|
|
69
|
+
Column("googleUserId")
|
|
70
|
+
], User.prototype, "googleUserId", 2);
|
|
71
|
+
User = __decorateClass([
|
|
72
|
+
Entity("users")
|
|
73
|
+
], User);
|
|
74
|
+
|
|
75
|
+
// packages/auth/domain/src/lib/feature-create-token/token.factory.ts
|
|
76
|
+
import { Injectable } from "@nestjs/common";
|
|
77
|
+
import { InjectRepository } from "@nestjs/typeorm";
|
|
78
|
+
import { Guid as Guid2 } from "guid-typescript";
|
|
79
|
+
|
|
80
|
+
// packages/shared/models/src/lib/symbols.ts
|
|
81
|
+
var SYMBOL_MODEL = Symbol.for("smartsoft:model");
|
|
82
|
+
var SYMBOL_FIELD = Symbol.for("smartsoft:field");
|
|
83
|
+
|
|
84
|
+
// packages/shared/models/src/lib/decorators/model/model.decorator.ts
|
|
85
|
+
import "reflect-metadata";
|
|
86
|
+
|
|
87
|
+
// packages/shared/models/src/lib/decorators/field/field.decorator.ts
|
|
88
|
+
import "reflect-metadata";
|
|
89
|
+
|
|
90
|
+
// packages/shared/utils/src/lib/services/password/password.service.ts
|
|
91
|
+
import * as md5_ from "md5";
|
|
92
|
+
var md5 = md5_;
|
|
93
|
+
var PasswordService = class _PasswordService {
|
|
94
|
+
/**
|
|
95
|
+
* Hash password text
|
|
96
|
+
* @param p {string} - text
|
|
97
|
+
* @return - hashed text
|
|
98
|
+
*/
|
|
99
|
+
static hash(p) {
|
|
100
|
+
return Promise.resolve(md5(p));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compare password text with hashed text
|
|
104
|
+
* @param p {string} - password text
|
|
105
|
+
* @param h {string} - hashed text
|
|
106
|
+
*/
|
|
107
|
+
static async compare(p, h) {
|
|
108
|
+
const hp = await _PasswordService.hash(p);
|
|
109
|
+
return hp === h;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// packages/shared/utils/src/lib/services/object/object.service.ts
|
|
114
|
+
import { stringify } from "flatted";
|
|
115
|
+
|
|
116
|
+
// packages/shared/utils/src/lib/services/guid/guid.service.ts
|
|
117
|
+
import { Guid } from "guid-typescript";
|
|
118
|
+
|
|
119
|
+
// packages/shared/utils/src/lib/services/array/array.service.ts
|
|
120
|
+
import * as _ from "lodash";
|
|
121
|
+
|
|
122
|
+
// packages/shared/domain-core/src/lib/errors.ts
|
|
123
|
+
var DomainValidationError = class _DomainValidationError extends Error {
|
|
124
|
+
constructor(msg) {
|
|
125
|
+
super(msg);
|
|
126
|
+
this.type = _DomainValidationError;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// packages/auth/domain/src/lib/feature-create-token/token.factory.ts
|
|
131
|
+
var TokenFactory = class {
|
|
132
|
+
constructor(config, repository, jwtService, fbService, googleService) {
|
|
133
|
+
this.config = config;
|
|
134
|
+
this.repository = repository;
|
|
135
|
+
this.jwtService = jwtService;
|
|
136
|
+
this.fbService = fbService;
|
|
137
|
+
this.googleService = googleService;
|
|
138
|
+
this._invalidUsernameOrPasswordMessage = "Invalid username or password";
|
|
139
|
+
}
|
|
140
|
+
static getQuery(config, customProvider = false) {
|
|
141
|
+
switch (config.grant_type) {
|
|
142
|
+
case "fb":
|
|
143
|
+
return { facebookUserId: config.fb_user_id };
|
|
144
|
+
case "google":
|
|
145
|
+
return { googleUserId: config.google_user_id };
|
|
146
|
+
case "password":
|
|
147
|
+
return { username: config.username };
|
|
148
|
+
case "refresh_token":
|
|
149
|
+
return { authRefreshToken: config.refresh_token };
|
|
150
|
+
default:
|
|
151
|
+
if (!customProvider) {
|
|
152
|
+
throw new DomainValidationError("Invalid grand type");
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
static checkDisabled(user) {
|
|
158
|
+
if (user.disabled)
|
|
159
|
+
throw new DomainValidationError("user disabled");
|
|
160
|
+
}
|
|
161
|
+
async create(options) {
|
|
162
|
+
if (options.request.grant_type === "fb") {
|
|
163
|
+
options.request.fb_user_id = await this.fbService.getUserId(
|
|
164
|
+
options.request.fb_token
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (options.request.grant_type === "google") {
|
|
168
|
+
options.request.google_user_id = await this.googleService.getUserId(
|
|
169
|
+
options.request.google_token
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
this.valid(options.request);
|
|
173
|
+
const query = TokenFactory.getQuery(
|
|
174
|
+
options.request,
|
|
175
|
+
!!options.userProvider
|
|
176
|
+
);
|
|
177
|
+
const user = options.userProvider ? await options.userProvider.get(query, options.request, options.httpReq) : await this.repository.findOne(query);
|
|
178
|
+
if (!options.validationProvider || !options.validationProvider.replace) {
|
|
179
|
+
this.checkUser(options.request, user);
|
|
180
|
+
TokenFactory.checkDisabled(user);
|
|
181
|
+
await this.checkPassword(options.request, user);
|
|
182
|
+
}
|
|
183
|
+
if (options.validationProvider) {
|
|
184
|
+
await options.validationProvider.check({
|
|
185
|
+
request: options.request,
|
|
186
|
+
user
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const refreshToken = Guid2.raw();
|
|
190
|
+
await this.repository.update(
|
|
191
|
+
{
|
|
192
|
+
...query,
|
|
193
|
+
disabled: { $ne: true }
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
lastLoginDate: /* @__PURE__ */ new Date(),
|
|
197
|
+
authRefreshToken: refreshToken
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
const payload = {
|
|
201
|
+
permissions: user.permissions,
|
|
202
|
+
scope: options.request.scope
|
|
203
|
+
};
|
|
204
|
+
if (options.payloadProvider) {
|
|
205
|
+
await options.payloadProvider.change(payload, {
|
|
206
|
+
user,
|
|
207
|
+
request: options.request,
|
|
208
|
+
httpReq: options.httpReq
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
expired_in: this.config.expiredIn,
|
|
213
|
+
token_type: "bearer",
|
|
214
|
+
access_token: this.jwtService.sign(payload, {
|
|
215
|
+
expiresIn: this.config.expiredIn,
|
|
216
|
+
subject: user.username
|
|
217
|
+
}),
|
|
218
|
+
refresh_token: refreshToken,
|
|
219
|
+
username: user.username
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
checkUser(config, user) {
|
|
223
|
+
if (!user)
|
|
224
|
+
throw new DomainValidationError(
|
|
225
|
+
config.grant_type === "password" ? this._invalidUsernameOrPasswordMessage : "Invalid token"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
async checkPassword(config, user) {
|
|
229
|
+
if (config.grant_type === "password" && !await PasswordService.compare(config.password, user.password))
|
|
230
|
+
throw new DomainValidationError(this._invalidUsernameOrPasswordMessage);
|
|
231
|
+
}
|
|
232
|
+
valid(req) {
|
|
233
|
+
if (!req)
|
|
234
|
+
throw new DomainValidationError("config is empty");
|
|
235
|
+
if (!req.grant_type)
|
|
236
|
+
throw new DomainValidationError("grant_type is empty");
|
|
237
|
+
if (req.grant_type === "password") {
|
|
238
|
+
if (!req.username)
|
|
239
|
+
throw new DomainValidationError("username is empty");
|
|
240
|
+
if (!req.password)
|
|
241
|
+
throw new DomainValidationError("password is empty");
|
|
242
|
+
if (!req.client_id)
|
|
243
|
+
throw new DomainValidationError("client_id is empty");
|
|
244
|
+
if (!this.config.clients.some((c) => c === req.client_id))
|
|
245
|
+
throw new DomainValidationError("client_id is incorrect");
|
|
246
|
+
} else if (req.grant_type === "refresh_token") {
|
|
247
|
+
if (!req.refresh_token)
|
|
248
|
+
throw new DomainValidationError("refresh_token is empty");
|
|
249
|
+
} else if (req.grant_type === "fb") {
|
|
250
|
+
if (!req.fb_token)
|
|
251
|
+
throw new DomainValidationError("fb_token is empty");
|
|
252
|
+
if (!req.fb_user_id)
|
|
253
|
+
throw new DomainValidationError("fb_user_id is empty");
|
|
254
|
+
} else if (req.grant_type === "google") {
|
|
255
|
+
if (!req.google_token)
|
|
256
|
+
throw new DomainValidationError("google_token is empty");
|
|
257
|
+
if (!req.google_user_id)
|
|
258
|
+
throw new DomainValidationError("google_user_id is empty");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
TokenFactory = __decorateClass([
|
|
263
|
+
Injectable(),
|
|
264
|
+
__decorateParam(1, InjectRepository(User))
|
|
265
|
+
], TokenFactory);
|
|
266
|
+
|
|
267
|
+
// packages/auth/domain/src/lib/feature-create-token/token.config.ts
|
|
268
|
+
import { Injectable as Injectable2 } from "@nestjs/common";
|
|
269
|
+
var TokenConfig = class {
|
|
270
|
+
constructor() {
|
|
271
|
+
this.clients = [];
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
TokenConfig = __decorateClass([
|
|
275
|
+
Injectable2()
|
|
276
|
+
], TokenConfig);
|
|
277
|
+
|
|
278
|
+
// packages/auth/domain/src/lib/feature-create-token/token-payload.provider.ts
|
|
279
|
+
var AUTH_TOKEN_PAYLOAD_PROVIDER = "AUTH_TOKEN_PAYLOAD_PROVIDER";
|
|
280
|
+
|
|
281
|
+
// packages/auth/domain/src/lib/feature-create-token/token-validation.provider.ts
|
|
282
|
+
var AUTH_TOKEN_VALIDATION_PROVIDER = "AUTH_TOKEN_VALIDATION_PROVIDER";
|
|
283
|
+
|
|
284
|
+
// packages/auth/domain/src/lib/feature-create-token/token-user.provider.ts
|
|
285
|
+
var AUTH_TOKEN_USER_PROVIDER = "AUTH_TOKEN_USER_PROVIDER";
|
|
286
|
+
|
|
287
|
+
// packages/auth/domain/src/index.ts
|
|
288
|
+
var DOMAIN_SERVICES = [TokenFactory];
|
|
289
|
+
var ENTITIES = [User];
|
|
290
|
+
|
|
291
|
+
// packages/auth/shell/app-services/src/lib/services/auth/auth.service.ts
|
|
292
|
+
import { Injectable as Injectable3, Logger } from "@nestjs/common";
|
|
293
|
+
var AuthService = class {
|
|
294
|
+
constructor(factory, moduleRef) {
|
|
295
|
+
this.factory = factory;
|
|
296
|
+
this.moduleRef = moduleRef;
|
|
297
|
+
}
|
|
298
|
+
create(req, httpReq) {
|
|
299
|
+
return this.factory.create({
|
|
300
|
+
httpReq,
|
|
301
|
+
request: req,
|
|
302
|
+
payloadProvider: this.getPayloadProvider(),
|
|
303
|
+
validationProvider: this.getValidationProvider(),
|
|
304
|
+
userProvider: this.getUserProvider()
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
getPayloadProvider() {
|
|
308
|
+
try {
|
|
309
|
+
return this.moduleRef.get(AUTH_TOKEN_PAYLOAD_PROVIDER, {
|
|
310
|
+
strict: false
|
|
311
|
+
});
|
|
312
|
+
} catch (e) {
|
|
313
|
+
Logger.debug(e.message, AuthService.name);
|
|
314
|
+
}
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
getValidationProvider() {
|
|
318
|
+
try {
|
|
319
|
+
return this.moduleRef.get(AUTH_TOKEN_VALIDATION_PROVIDER, {
|
|
320
|
+
strict: false
|
|
321
|
+
});
|
|
322
|
+
} catch (e) {
|
|
323
|
+
Logger.debug(e.message, AuthService.name);
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
getUserProvider() {
|
|
328
|
+
try {
|
|
329
|
+
return this.moduleRef.get(AUTH_TOKEN_USER_PROVIDER, {
|
|
330
|
+
strict: false
|
|
331
|
+
});
|
|
332
|
+
} catch (e) {
|
|
333
|
+
Logger.debug(e.message, AuthService.name);
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
AuthService = __decorateClass([
|
|
339
|
+
Injectable3()
|
|
340
|
+
], AuthService);
|
|
341
|
+
|
|
342
|
+
// packages/shared/fb/src/lib/fb.service.ts
|
|
343
|
+
import { Injectable as Injectable4 } from "@nestjs/common";
|
|
344
|
+
var FbService = class {
|
|
345
|
+
constructor(http) {
|
|
346
|
+
this.http = http;
|
|
347
|
+
}
|
|
348
|
+
async getUserId(token) {
|
|
349
|
+
const { data } = await this.http.get("https://graph.facebook.com/me?access_token=" + token).toPromise();
|
|
350
|
+
return data.id;
|
|
351
|
+
}
|
|
352
|
+
async getData(token) {
|
|
353
|
+
const { data } = await this.http.get(
|
|
354
|
+
"https://graph.facebook.com/me?fields=email,id&access_token=" + token
|
|
355
|
+
).toPromise();
|
|
356
|
+
return data;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
FbService = __decorateClass([
|
|
360
|
+
Injectable4()
|
|
361
|
+
], FbService);
|
|
362
|
+
|
|
363
|
+
// packages/shared/google/src/lib/google.service.ts
|
|
364
|
+
import { Injectable as Injectable5 } from "@nestjs/common";
|
|
365
|
+
var GoogleService = class {
|
|
366
|
+
constructor(http) {
|
|
367
|
+
this.http = http;
|
|
368
|
+
}
|
|
369
|
+
async getUserId(token) {
|
|
370
|
+
const { data } = await this.http.get(
|
|
371
|
+
"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + token
|
|
372
|
+
).toPromise();
|
|
373
|
+
return data.user_id;
|
|
374
|
+
}
|
|
375
|
+
async getData(token) {
|
|
376
|
+
const { data } = await this.http.get(
|
|
377
|
+
"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + token
|
|
378
|
+
).toPromise();
|
|
379
|
+
return {
|
|
380
|
+
id: data.user_id,
|
|
381
|
+
email: data.email
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
GoogleService = __decorateClass([
|
|
386
|
+
Injectable5()
|
|
387
|
+
], GoogleService);
|
|
388
|
+
|
|
389
|
+
// packages/auth/shell/nestjs/src/lib/nestjs.module.ts
|
|
390
|
+
var AuthShellNestjsModule = class {
|
|
391
|
+
static forRoot(options) {
|
|
392
|
+
return {
|
|
393
|
+
module: AuthShellNestjsModule,
|
|
394
|
+
controllers: [TokenController],
|
|
395
|
+
providers: [
|
|
396
|
+
{ provide: TokenConfig, useValue: options.tokenConfig },
|
|
397
|
+
AuthService,
|
|
398
|
+
FbService,
|
|
399
|
+
GoogleService,
|
|
400
|
+
...DOMAIN_SERVICES
|
|
401
|
+
],
|
|
402
|
+
imports: [
|
|
403
|
+
HttpModule,
|
|
404
|
+
TypeOrmModule.forFeature(ENTITIES),
|
|
405
|
+
PassportModule.register({ defaultStrategy: "jwt", session: false }),
|
|
406
|
+
JwtModule.register({
|
|
407
|
+
secret: options.tokenConfig.secretOrPrivateKey,
|
|
408
|
+
signOptions: {
|
|
409
|
+
expiresIn: options.tokenConfig.expiredIn
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
],
|
|
413
|
+
exports: [FbService, GoogleService]
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
AuthShellNestjsModule = __decorateClass([
|
|
418
|
+
Module({})
|
|
419
|
+
], AuthShellNestjsModule);
|
|
420
|
+
var AuthShellNestjsCoreModule = class {
|
|
421
|
+
static forRoot(options) {
|
|
422
|
+
return {
|
|
423
|
+
module: AuthShellNestjsModule,
|
|
424
|
+
providers: [
|
|
425
|
+
{ provide: TokenConfig, useValue: options.tokenConfig },
|
|
426
|
+
AuthService,
|
|
427
|
+
...DOMAIN_SERVICES
|
|
428
|
+
],
|
|
429
|
+
exports: [
|
|
430
|
+
AuthService,
|
|
431
|
+
...DOMAIN_SERVICES,
|
|
432
|
+
{ provide: TokenConfig, useValue: options.tokenConfig }
|
|
433
|
+
],
|
|
434
|
+
imports: [
|
|
435
|
+
TypeOrmModule.forFeature(ENTITIES),
|
|
436
|
+
PassportModule.register({ defaultStrategy: "jwt", session: false }),
|
|
437
|
+
JwtModule.register({
|
|
438
|
+
secret: options.tokenConfig.secretOrPrivateKey,
|
|
439
|
+
signOptions: {
|
|
440
|
+
expiresIn: options.tokenConfig.expiredIn
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
]
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
AuthShellNestjsCoreModule = __decorateClass([
|
|
448
|
+
Module({})
|
|
449
|
+
], AuthShellNestjsCoreModule);
|
|
450
|
+
export {
|
|
451
|
+
AuthShellNestjsCoreModule,
|
|
452
|
+
AuthShellNestjsModule,
|
|
453
|
+
TokenController
|
|
454
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { IAuthToken, IAuthTokenRequest } from '@smartsoft001/auth-domain';
|
|
3
|
+
import { AuthService } from '@smartsoft001/auth-shell-app-services';
|
|
4
|
+
export declare class TokenController {
|
|
5
|
+
private readonly service;
|
|
6
|
+
constructor(service: AuthService);
|
|
7
|
+
create(req: IAuthTokenRequest, httpReq: Request): Promise<IAuthToken>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { TokenConfig } from '@smartsoft001/auth-domain';
|
|
3
|
+
export declare class AuthShellNestjsModule {
|
|
4
|
+
static forRoot(options: {
|
|
5
|
+
tokenConfig: TokenConfig;
|
|
6
|
+
}): DynamicModule;
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthShellNestjsCoreModule {
|
|
9
|
+
static forRoot(options: {
|
|
10
|
+
tokenConfig: TokenConfig;
|
|
11
|
+
}): DynamicModule;
|
|
12
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"rules": {
|
|
5
|
-
"import/order": "off"
|
|
6
|
-
},
|
|
7
|
-
"overrides": [
|
|
8
|
-
{
|
|
9
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
10
|
-
"rules": {}
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"files": ["*.ts", "*.tsx"],
|
|
14
|
-
"rules": {}
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"files": ["*.js", "*.jsx"],
|
|
18
|
-
"rules": {}
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"files": "package.json",
|
|
22
|
-
"parser": "jsonc-eslint-parser",
|
|
23
|
-
"rules": {}
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
export default {
|
|
3
|
-
displayName: 'auth-shell-nestjs',
|
|
4
|
-
preset: '../../../../jest.preset.js',
|
|
5
|
-
testEnvironment: 'node',
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]sx?$': [
|
|
8
|
-
'ts-jest',
|
|
9
|
-
{
|
|
10
|
-
tsConfig: '<rootDir>/tsconfig.spec.json',
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
|
15
|
-
coverageDirectory: '../../../../coverage/packages/auth/shell/nestjs',
|
|
16
|
-
/* TODO: Update to latest Jest snapshotFormat
|
|
17
|
-
* By default Nx has kept the older style of Jest Snapshot formats
|
|
18
|
-
* to prevent breaking of any existing tests with snapshots.
|
|
19
|
-
* It's recommend you update to the latest format.
|
|
20
|
-
* You can do this by removing snapshotFormat property
|
|
21
|
-
* and running tests with --update-snapshot flag.
|
|
22
|
-
* Example: From within the project directory, run "nx test --update-snapshot"
|
|
23
|
-
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
24
|
-
*/
|
|
25
|
-
snapshotFormat: { escapeString: true, printBasicPrototype: true },
|
|
26
|
-
};
|
package/project.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "auth-shell-nestjs",
|
|
3
|
-
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/auth/shell/nestjs/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": ["scope:auth", "type:shell"],
|
|
7
|
-
"targets": {
|
|
8
|
-
"lint": {
|
|
9
|
-
"executor": "@nx/eslint:lint",
|
|
10
|
-
"outputs": ["{options.outputFile}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"lintFilePatterns": [
|
|
13
|
-
"packages/auth/shell/nestjs/**/*.{ts,tsx,js,jsx}",
|
|
14
|
-
"packages/auth/shell/nestjs/package.json"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"test": {
|
|
19
|
-
"executor": "@nx/jest:jest",
|
|
20
|
-
"outputs": ["{workspaceRoot}/coverage/packages/auth/shell/nestjs"],
|
|
21
|
-
"options": {
|
|
22
|
-
"jestConfig": "packages/auth/shell/nestjs/jest.config.ts"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"build": {
|
|
26
|
-
"executor": "@nx/esbuild:esbuild",
|
|
27
|
-
"outputs": ["{options.outputPath}"],
|
|
28
|
-
"options": {
|
|
29
|
-
"outputPath": "dist/packages/auth/shell/nestjs",
|
|
30
|
-
"tsConfig": "packages/auth/shell/nestjs/tsconfig.lib.json",
|
|
31
|
-
"packageJson": "packages/auth/shell/nestjs/package.json",
|
|
32
|
-
"main": "packages/auth/shell/nestjs/src/index.ts",
|
|
33
|
-
"assets": ["packages/auth/shell/nestjs/*.md"]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Body, Controller, Post, Req } from '@nestjs/common';
|
|
2
|
-
import { Request } from 'express';
|
|
3
|
-
|
|
4
|
-
import { IAuthToken, IAuthTokenRequest } from '@smartsoft001/auth-domain';
|
|
5
|
-
import { AuthService } from '@smartsoft001/auth-shell-app-services';
|
|
6
|
-
|
|
7
|
-
@Controller('token')
|
|
8
|
-
export class TokenController {
|
|
9
|
-
constructor(private readonly service: AuthService) {}
|
|
10
|
-
|
|
11
|
-
@Post()
|
|
12
|
-
create(
|
|
13
|
-
@Body() req: IAuthTokenRequest,
|
|
14
|
-
@Req() httpReq: Request,
|
|
15
|
-
): Promise<IAuthToken> {
|
|
16
|
-
return this.service.create(req, httpReq);
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/lib/nestjs.module.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { HttpModule } from '@nestjs/axios';
|
|
2
|
-
import { DynamicModule, Module } from '@nestjs/common';
|
|
3
|
-
import { JwtModule } from '@nestjs/jwt';
|
|
4
|
-
import { PassportModule } from '@nestjs/passport';
|
|
5
|
-
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
DOMAIN_SERVICES,
|
|
9
|
-
ENTITIES,
|
|
10
|
-
TokenConfig,
|
|
11
|
-
} from '@smartsoft001/auth-domain';
|
|
12
|
-
import { AuthService } from '@smartsoft001/auth-shell-app-services';
|
|
13
|
-
import { FbService } from '@smartsoft001/fb';
|
|
14
|
-
import { GoogleService } from '@smartsoft001/google';
|
|
15
|
-
|
|
16
|
-
import { TokenController } from './controllers/token/token.controller';
|
|
17
|
-
|
|
18
|
-
@Module({})
|
|
19
|
-
export class AuthShellNestjsModule {
|
|
20
|
-
static forRoot(options: { tokenConfig: TokenConfig }): DynamicModule {
|
|
21
|
-
return {
|
|
22
|
-
module: AuthShellNestjsModule,
|
|
23
|
-
controllers: [TokenController],
|
|
24
|
-
providers: [
|
|
25
|
-
{ provide: TokenConfig, useValue: options.tokenConfig },
|
|
26
|
-
AuthService,
|
|
27
|
-
FbService,
|
|
28
|
-
GoogleService,
|
|
29
|
-
...DOMAIN_SERVICES,
|
|
30
|
-
],
|
|
31
|
-
imports: [
|
|
32
|
-
HttpModule,
|
|
33
|
-
TypeOrmModule.forFeature(ENTITIES),
|
|
34
|
-
PassportModule.register({ defaultStrategy: 'jwt', session: false }),
|
|
35
|
-
JwtModule.register({
|
|
36
|
-
secret: options.tokenConfig.secretOrPrivateKey,
|
|
37
|
-
signOptions: {
|
|
38
|
-
expiresIn: options.tokenConfig.expiredIn,
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
exports: [FbService, GoogleService],
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@Module({})
|
|
48
|
-
export class AuthShellNestjsCoreModule {
|
|
49
|
-
static forRoot(options: { tokenConfig: TokenConfig }): DynamicModule {
|
|
50
|
-
return {
|
|
51
|
-
module: AuthShellNestjsModule,
|
|
52
|
-
providers: [
|
|
53
|
-
{ provide: TokenConfig, useValue: options.tokenConfig },
|
|
54
|
-
AuthService,
|
|
55
|
-
...DOMAIN_SERVICES,
|
|
56
|
-
],
|
|
57
|
-
exports: [
|
|
58
|
-
AuthService,
|
|
59
|
-
...DOMAIN_SERVICES,
|
|
60
|
-
{ provide: TokenConfig, useValue: options.tokenConfig },
|
|
61
|
-
],
|
|
62
|
-
imports: [
|
|
63
|
-
TypeOrmModule.forFeature(ENTITIES),
|
|
64
|
-
PassportModule.register({ defaultStrategy: 'jwt', session: false }),
|
|
65
|
-
JwtModule.register({
|
|
66
|
-
secret: options.tokenConfig.secretOrPrivateKey,
|
|
67
|
-
signOptions: {
|
|
68
|
-
expiresIn: options.tokenConfig.expiredIn,
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"outDir": "../../../../dist/out-tsc",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"types": ["node"]
|
|
8
|
-
},
|
|
9
|
-
"exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
|
|
10
|
-
"include": ["**/*.ts"]
|
|
11
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"types": ["jest", "node"]
|
|
7
|
-
},
|
|
8
|
-
"include": [
|
|
9
|
-
"**/*.spec.ts",
|
|
10
|
-
"**/*.test.ts",
|
|
11
|
-
"**/*.spec.tsx",
|
|
12
|
-
"**/*.test.tsx",
|
|
13
|
-
"**/*.spec.js",
|
|
14
|
-
"**/*.test.js",
|
|
15
|
-
"**/*.spec.jsx",
|
|
16
|
-
"**/*.test.jsx",
|
|
17
|
-
"**/*.d.ts",
|
|
18
|
-
"jest.config.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
File without changes
|
|
File without changes
|