@tsed/cli-plugin-passport 6.6.3 → 7.0.0-alpha.2
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/lib/esm/CliPluginPassportModule.js +4 -30
- package/lib/esm/index.js +1 -2
- package/lib/esm/services/PassportClient.js +32 -12
- package/lib/esm/templates/generic.protocol.template.js +34 -0
- package/lib/esm/templates/index.js +7 -0
- package/lib/esm/templates/passport.discord.protocol.template.js +39 -0
- package/lib/esm/templates/passport.facebook.protocol.template.js +37 -0
- package/lib/esm/templates/passport.http.protocol.template.js +33 -0
- package/lib/esm/templates/passport.jwt.protocol.template.js +33 -0
- package/{templates/passport-local.protocol.hbs → lib/esm/templates/passport.local.protocol.template.js} +16 -3
- package/lib/esm/templates/protocol.template.js +66 -0
- package/lib/types/CliPluginPassportModule.d.ts +0 -3
- package/lib/types/index.d.ts +1 -2
- package/lib/types/services/PassportClient.d.ts +14 -1
- package/lib/types/templates/generic.protocol.template.d.ts +2 -0
- package/lib/types/templates/index.d.ts +7 -0
- package/lib/types/templates/passport.discord.protocol.template.d.ts +2 -0
- package/lib/types/templates/passport.facebook.protocol.template.d.ts +2 -0
- package/lib/types/templates/passport.http.protocol.template.d.ts +2 -0
- package/lib/types/templates/passport.jwt.protocol.template.d.ts +2 -0
- package/lib/types/templates/passport.local.protocol.template.d.ts +2 -0
- package/lib/types/templates/protocol.template.d.ts +12 -0
- package/package.json +8 -5
- package/lib/esm/hooks/PassportGenerateHook.js +0 -95
- package/lib/esm/utils/templateDir.js +0 -2
- package/lib/types/hooks/PassportGenerateHook.d.ts +0 -28
- package/lib/types/utils/templateDir.d.ts +0 -1
- package/templates/generic.protocol.hbs +0 -20
- package/templates/passport-http.protocol.hbs +0 -20
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let CliPluginPassportModule = class CliPluginPassportModule {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.packageJson = inject(ProjectPackageJson);
|
|
8
|
-
}
|
|
9
|
-
install() {
|
|
10
|
-
this.packageJson.addDependencies({
|
|
11
|
-
"@tsed/passport": this.packageJson.dependencies["@tsed/platform-http"],
|
|
12
|
-
passport: "latest"
|
|
13
|
-
});
|
|
14
|
-
this.packageJson.addDevDependencies({
|
|
15
|
-
"@types/passport": "latest"
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
__decorate([
|
|
20
|
-
OnAdd("@tsed/cli-plugin-passport"),
|
|
21
|
-
__metadata("design:type", Function),
|
|
22
|
-
__metadata("design:paramtypes", []),
|
|
23
|
-
__metadata("design:returntype", void 0)
|
|
24
|
-
], CliPluginPassportModule.prototype, "install", null);
|
|
25
|
-
CliPluginPassportModule = __decorate([
|
|
26
|
-
Module({
|
|
27
|
-
imports: [PassportGenerateHook]
|
|
28
|
-
})
|
|
29
|
-
], CliPluginPassportModule);
|
|
30
|
-
export { CliPluginPassportModule };
|
|
1
|
+
import { injectable } from "@tsed/di";
|
|
2
|
+
export class CliPluginPassportModule {
|
|
3
|
+
}
|
|
4
|
+
injectable(CliPluginPassportModule);
|
package/lib/esm/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import "./templates/index.js";
|
|
1
2
|
import { CliPluginPassportModule } from "./CliPluginPassportModule.js";
|
|
2
|
-
export * from "./hooks/PassportGenerateHook.js";
|
|
3
3
|
export * from "./services/PassportClient.js";
|
|
4
|
-
export * from "./utils/templateDir.js";
|
|
5
4
|
export default CliPluginPassportModule;
|
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
const HOST = "
|
|
4
|
-
|
|
1
|
+
import { CliHttpClient, inject } from "@tsed/cli-core";
|
|
2
|
+
import { injectable } from "@tsed/di";
|
|
3
|
+
const HOST = "https://www.passportjs.org/packages";
|
|
4
|
+
export class PassportClient {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.httpClient = inject(CliHttpClient);
|
|
7
7
|
}
|
|
8
8
|
async getPackages() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!this.cache) {
|
|
10
|
+
const result = await this.httpClient.get(`${HOST}/-/all.json`, {});
|
|
11
|
+
this.cache = Object.values(result).filter((o) => {
|
|
12
|
+
return o.name?.startsWith("passport-");
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return this.cache;
|
|
16
|
+
}
|
|
17
|
+
async getPackage(name) {
|
|
18
|
+
const packages = await this.getPackages();
|
|
19
|
+
return packages.find((pkg) => pkg.name === name);
|
|
20
|
+
}
|
|
21
|
+
async getPackageVersion(name) {
|
|
22
|
+
let pkg = await this.getPackage(name);
|
|
23
|
+
return pkg?.["dist-tags"]?.latest || "latest";
|
|
24
|
+
}
|
|
25
|
+
async getChoices(input) {
|
|
26
|
+
const choices = (await this.getPackages()).map((item) => {
|
|
27
|
+
return {
|
|
28
|
+
name: `${item.name} - ${item.description}`,
|
|
29
|
+
value: item.name
|
|
30
|
+
};
|
|
12
31
|
});
|
|
32
|
+
if (input) {
|
|
33
|
+
return choices.filter((item) => item.name.toLowerCase().includes(input.toLowerCase()));
|
|
34
|
+
}
|
|
35
|
+
return choices;
|
|
13
36
|
}
|
|
14
|
-
}
|
|
15
|
-
PassportClient
|
|
16
|
-
Injectable()
|
|
17
|
-
], PassportClient);
|
|
18
|
-
export { PassportClient };
|
|
37
|
+
}
|
|
38
|
+
injectable(PassportClient);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.generic",
|
|
5
|
+
label: "Passport Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
const { passportPackage } = data;
|
|
12
|
+
return `import {Req} from "@tsed/platform-http";
|
|
13
|
+
import {BodyParams} from "@tsed/platform-params";
|
|
14
|
+
import {OnInstall, OnVerify, Protocol, Args} from "@tsed/passport";
|
|
15
|
+
import {Strategy} from "${passportPackage}";
|
|
16
|
+
|
|
17
|
+
@Protocol({
|
|
18
|
+
name: "${protocolName}",
|
|
19
|
+
useStrategy: Strategy,
|
|
20
|
+
settings: {}
|
|
21
|
+
})
|
|
22
|
+
export class ${symbolName} implements OnVerify, OnInstall {
|
|
23
|
+
async $onVerify(@Req() request: Req, @Args() args: any[]) {
|
|
24
|
+
const [] = args;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$onInstall(strategy: Strategy): void {
|
|
29
|
+
// intercept the strategy instance to adding extra configuration
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./protocol.template.js";
|
|
2
|
+
import "./passport.http.protocol.template.js";
|
|
3
|
+
import "./passport.local.protocol.template.js";
|
|
4
|
+
import "./passport.jwt.protocol.template.js";
|
|
5
|
+
import "./passport.discord.protocol.template.js";
|
|
6
|
+
import "./passport.facebook.protocol.template.js";
|
|
7
|
+
import "./generic.protocol.template.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.passport-discord",
|
|
5
|
+
label: "Passport Discord Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
return `import {Args, OnInstall, OnVerify, Protocol} from "@tsed/passport";
|
|
12
|
+
import {Req} from "@tsed/platform-http";
|
|
13
|
+
import {Strategy, StrategyOptions} from "passport-discord";
|
|
14
|
+
import * as refresh from "passport-oauth2-refresh";
|
|
15
|
+
|
|
16
|
+
@Protocol<StrategyOptions>({
|
|
17
|
+
name: "${protocolName}",
|
|
18
|
+
useStrategy: Strategy,
|
|
19
|
+
settings: {
|
|
20
|
+
clientID: "id",
|
|
21
|
+
clientSecret: "secret",
|
|
22
|
+
callbackURL: "callbackURL"
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
export class ${symbolName} implements OnVerify, OnInstall {
|
|
26
|
+
async $onVerify(@Req() req: Req, @Args() [accessToken, refreshToken, profile]: any) {
|
|
27
|
+
profile.refreshToken = refreshToken;
|
|
28
|
+
|
|
29
|
+
// const user = await this.authService.findOne({discordId: profile.id});
|
|
30
|
+
|
|
31
|
+
// return user ? user : false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async $onInstall(strategy: Strategy) {
|
|
35
|
+
refresh.use(strategy);
|
|
36
|
+
}
|
|
37
|
+
}`;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.passport-facebook",
|
|
5
|
+
label: "Passport Facebook Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
return `import {Args, OnInstall, OnVerify, Protocol} from "@tsed/passport";
|
|
12
|
+
import {Req} from "@tsed/platform-http";
|
|
13
|
+
import {Strategy, StrategyOptions} from "passport-facebook";
|
|
14
|
+
|
|
15
|
+
import {AuthService} from "../services/auth/AuthService";
|
|
16
|
+
|
|
17
|
+
@Protocol<StrategyOptions>({
|
|
18
|
+
name: "${protocolName}",
|
|
19
|
+
useStrategy: Strategy,
|
|
20
|
+
settings: {
|
|
21
|
+
clientID: "FACEBOOK_APP_ID",
|
|
22
|
+
clientSecret: "FACEBOOK_APP_SECRET",
|
|
23
|
+
callbackURL: "http://www.example.com/auth/facebook/callback",
|
|
24
|
+
profileFields: ["id", "emails", "name"]
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
export class ${symbolName} implements OnVerify, OnInstall {
|
|
28
|
+
async $onVerify(@Req() req: Req, @Args() [accessToken, refreshToken, profile]: any) {
|
|
29
|
+
profile.refreshToken = refreshToken;
|
|
30
|
+
|
|
31
|
+
// const user = await this.authService.findOne({facebookId: profile.id});
|
|
32
|
+
|
|
33
|
+
// return user ? user : false;
|
|
34
|
+
}
|
|
35
|
+
}`;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.passport-http",
|
|
5
|
+
label: "Passport HTTP Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
return `import {Req} from "@tsed/platform-http";
|
|
12
|
+
import {BodyParams} from "@tsed/platform-params";
|
|
13
|
+
import {OnInstall, OnVerify, Protocol} from "@tsed/passport";
|
|
14
|
+
import {BasicStrategy} from "passport-http";
|
|
15
|
+
|
|
16
|
+
@Protocol({
|
|
17
|
+
name: "${protocolName}",
|
|
18
|
+
useStrategy: BasicStrategy,
|
|
19
|
+
settings: {}
|
|
20
|
+
})
|
|
21
|
+
export class ${symbolName} implements OnVerify, OnInstall {
|
|
22
|
+
async $onVerify(@Req() request: Req, @BodyParams() credentials: any) {
|
|
23
|
+
const {username, password} = credentials;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$onInstall(strategy: Strategy): void {
|
|
28
|
+
// intercept the strategy instance to adding extra configuration
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.passport-jwt",
|
|
5
|
+
label: "Passport JWT Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
return `import {Arg, OnVerify, Protocol} from "@tsed/passport";
|
|
12
|
+
import {Req} from "@tsed/platform-http";
|
|
13
|
+
import {ExtractJwt, Strategy, StrategyOptions} from "passport-jwt";
|
|
14
|
+
|
|
15
|
+
@Protocol<StrategyOptions>({
|
|
16
|
+
name: "${protocolName}",
|
|
17
|
+
useStrategy: Strategy,
|
|
18
|
+
settings: {
|
|
19
|
+
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
20
|
+
secretOrKey: "secret",
|
|
21
|
+
issuer: "accounts.examplesoft.com",
|
|
22
|
+
audience: "yoursite.net"
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
export class ${symbolName} implements OnVerify {
|
|
26
|
+
async $onVerify(@Req() req: Req, @Arg(0) jwtPayload: {sub: string}) {
|
|
27
|
+
const token = jwtPayload.sub;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { kebabCase } from "change-case";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "protocol.passport-local",
|
|
5
|
+
label: "Passport local Protocol",
|
|
6
|
+
fileName: "{{symbolName}}.protocol",
|
|
7
|
+
outputDir: "{{srcDir}}/protocols",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const protocolName = kebabCase(data.name);
|
|
11
|
+
return `import {Req} from "@tsed/platform-http";
|
|
2
12
|
import {BodyParams} from "@tsed/platform-params";
|
|
3
13
|
import {OnInstall, OnVerify, Protocol} from "@tsed/passport";
|
|
4
14
|
import {IStrategyOptions, Strategy} from "passport-local";
|
|
5
15
|
|
|
6
16
|
@Protocol<IStrategyOptions>({
|
|
7
|
-
name: "{
|
|
17
|
+
name: "${protocolName}",
|
|
8
18
|
useStrategy: Strategy,
|
|
9
19
|
settings: {
|
|
10
20
|
usernameField: "email",
|
|
11
21
|
passwordField: "password"
|
|
12
22
|
}
|
|
13
23
|
})
|
|
14
|
-
export class {
|
|
24
|
+
export class ${symbolName} implements OnVerify, OnInstall {
|
|
15
25
|
async $onVerify(@Req() request: Req, @BodyParams() credentials: any) {
|
|
16
26
|
const {email, password} = credentials;
|
|
17
27
|
|
|
@@ -21,3 +31,6 @@ export class {{symbolName}} implements OnVerify, OnInstall {
|
|
|
21
31
|
// intercept the strategy instance to adding extra configuration
|
|
22
32
|
}
|
|
23
33
|
}
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { defineTemplate, ProjectClient, render } from "@tsed/cli";
|
|
2
|
+
import { inject } from "@tsed/di";
|
|
3
|
+
import { PassportClient } from "../services/PassportClient.js";
|
|
4
|
+
import { ProjectPackageJson } from "@tsed/cli-core";
|
|
5
|
+
export default defineTemplate({
|
|
6
|
+
id: "protocol",
|
|
7
|
+
label: "Passport Protocol",
|
|
8
|
+
fileName: "{{symbolName}}.protocol",
|
|
9
|
+
outputDir: "{{srcDir}}/protocols",
|
|
10
|
+
prompts() {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
type: "autocomplete",
|
|
14
|
+
name: "passportPackage",
|
|
15
|
+
message: "Which passport package ?",
|
|
16
|
+
when(state) {
|
|
17
|
+
return ["protocol"].includes(state.type);
|
|
18
|
+
},
|
|
19
|
+
source(_, input) {
|
|
20
|
+
return inject(PassportClient).getChoices(input);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
},
|
|
25
|
+
async render(_, data) {
|
|
26
|
+
const result = await render("protocol." + data.passportPackage, data);
|
|
27
|
+
return result || render("protocol.generic", data);
|
|
28
|
+
},
|
|
29
|
+
hooks: {
|
|
30
|
+
$alterProjectFiles(_, project, data) {
|
|
31
|
+
const sourceFile = project.serverSourceFile;
|
|
32
|
+
if (data.passport) {
|
|
33
|
+
sourceFile.addImportDeclaration({
|
|
34
|
+
moduleSpecifier: "@tsed/passport"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return project;
|
|
38
|
+
},
|
|
39
|
+
async $alterPackageJson(_, packageJson, data) {
|
|
40
|
+
if (data.passport) {
|
|
41
|
+
packageJson.addDependencies({
|
|
42
|
+
"@tsed/passport": packageJson.dependencies["@tsed/platform-http"],
|
|
43
|
+
passport: "latest"
|
|
44
|
+
});
|
|
45
|
+
packageJson.addDevDependencies({
|
|
46
|
+
"@types/passport": "latest"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return packageJson;
|
|
50
|
+
},
|
|
51
|
+
async $alterGenerateTasks(_, tasks, data) {
|
|
52
|
+
if (data.passportPackage) {
|
|
53
|
+
const packageJson = inject(ProjectPackageJson);
|
|
54
|
+
const passportClient = inject(PassportClient);
|
|
55
|
+
packageJson.addDependency(data.passportPackage, await passportClient.getPackageVersion(data.passportPackage));
|
|
56
|
+
if (!packageJson.devDependencies["@types/passport"]) {
|
|
57
|
+
packageJson.addDevDependency("@types/passport", "latest");
|
|
58
|
+
}
|
|
59
|
+
if (!packageJson.dependencies["passport"]) {
|
|
60
|
+
packageJson.addDevDependency("passport", "latest");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return tasks;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import "./templates/index.js";
|
|
1
2
|
import { CliPluginPassportModule } from "./CliPluginPassportModule.js";
|
|
2
|
-
export * from "./hooks/PassportGenerateHook.js";
|
|
3
3
|
export * from "./services/PassportClient.js";
|
|
4
|
-
export * from "./utils/templateDir.js";
|
|
5
4
|
export default CliPluginPassportModule;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { CliHttpClient } from "@tsed/cli-core";
|
|
2
|
+
type PassportPackage = {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
"dist-tags": Record<string, string>;
|
|
6
|
+
};
|
|
2
7
|
export declare class PassportClient {
|
|
3
8
|
protected httpClient: CliHttpClient;
|
|
4
|
-
|
|
9
|
+
private cache;
|
|
10
|
+
getPackages(): Promise<PassportPackage[]>;
|
|
11
|
+
getPackage(name: string): Promise<PassportPackage | undefined>;
|
|
12
|
+
getPackageVersion(name: string): Promise<string>;
|
|
13
|
+
getChoices(input?: string): Promise<{
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}[]>;
|
|
5
17
|
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./protocol.template.js";
|
|
2
|
+
import "./passport.http.protocol.template.js";
|
|
3
|
+
import "./passport.local.protocol.template.js";
|
|
4
|
+
import "./passport.jwt.protocol.template.js";
|
|
5
|
+
import "./passport.discord.protocol.template.js";
|
|
6
|
+
import "./passport.facebook.protocol.template.js";
|
|
7
|
+
import "./generic.protocol.template.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace TsED {
|
|
3
|
+
interface GenerateOptions {
|
|
4
|
+
passportPackage: string;
|
|
5
|
+
}
|
|
6
|
+
interface RenderDataContext {
|
|
7
|
+
passport?: boolean;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare const _default: import("@tsed/cli").DefineTemplateOptions;
|
|
12
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-plugin-passport",
|
|
3
3
|
"description": "Ts.ED CLI plugin. Add Passport.js support",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-alpha.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"tslib": "2.7.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@tsed/cli": "
|
|
30
|
-
"@tsed/cli-core": "
|
|
31
|
-
"@tsed/typescript": "
|
|
29
|
+
"@tsed/cli": "7.0.0-alpha.2",
|
|
30
|
+
"@tsed/cli-core": "7.0.0-alpha.2",
|
|
31
|
+
"@tsed/typescript": "7.0.0-alpha.2",
|
|
32
32
|
"@types/change-case": "^2.3.1",
|
|
33
33
|
"cross-env": "7.0.3",
|
|
34
34
|
"typescript": "5.6.2",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-passport",
|
|
43
43
|
"author": "Romain Lenzotti",
|
|
44
|
-
"license": "MIT"
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"tag": "alpha"
|
|
47
|
+
}
|
|
45
48
|
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
var PassportGenerateHook_1;
|
|
2
|
-
import { __decorate, __metadata } from "tslib";
|
|
3
|
-
import { ProvidersInfoService, SrcRendererService } from "@tsed/cli";
|
|
4
|
-
import { inject, OnExec, OnPrompt, ProjectPackageJson } from "@tsed/cli-core";
|
|
5
|
-
import { Injectable } from "@tsed/di";
|
|
6
|
-
import { kebabCase } from "change-case";
|
|
7
|
-
import { PassportClient } from "../services/PassportClient.js";
|
|
8
|
-
import { TEMPLATE_DIR } from "../utils/templateDir.js";
|
|
9
|
-
let PassportGenerateHook = PassportGenerateHook_1 = class PassportGenerateHook {
|
|
10
|
-
constructor(providersInfoService) {
|
|
11
|
-
this.providersInfoService = providersInfoService;
|
|
12
|
-
this.projectPackageJson = inject(ProjectPackageJson);
|
|
13
|
-
this.srcRenderService = inject(SrcRendererService);
|
|
14
|
-
this.passportClient = inject(PassportClient);
|
|
15
|
-
providersInfoService.add({
|
|
16
|
-
name: "Protocol",
|
|
17
|
-
value: "protocol",
|
|
18
|
-
model: "{{symbolName}}.protocol"
|
|
19
|
-
}, PassportGenerateHook_1);
|
|
20
|
-
}
|
|
21
|
-
async onGeneratePrompt() {
|
|
22
|
-
this.packages = await this.passportClient.getPackages();
|
|
23
|
-
const list = this.packages.map((item) => {
|
|
24
|
-
return {
|
|
25
|
-
name: `${item.name} - ${item.description}`,
|
|
26
|
-
value: item.name
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
type: "autocomplete",
|
|
32
|
-
name: "passportPackage",
|
|
33
|
-
message: "Which passport package ?",
|
|
34
|
-
when(state) {
|
|
35
|
-
return ["protocol"].includes(state.type);
|
|
36
|
-
},
|
|
37
|
-
source: (state, keyword) => {
|
|
38
|
-
if (keyword) {
|
|
39
|
-
return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
|
|
40
|
-
}
|
|
41
|
-
return list;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
onGenerateExec(ctx) {
|
|
47
|
-
if (this.providersInfoService.isMyProvider(ctx.type, PassportGenerateHook_1)) {
|
|
48
|
-
ctx = this.mapOptions(ctx);
|
|
49
|
-
const { passportPackage, symbolPath } = ctx;
|
|
50
|
-
this.projectPackageJson.addDependency(ctx.passportPackage, this.getPassportPackageVersion(passportPackage));
|
|
51
|
-
return [
|
|
52
|
-
{
|
|
53
|
-
title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
|
|
54
|
-
task: () => this.srcRenderService.render(this.getTemplate(passportPackage), ctx, {
|
|
55
|
-
output: `${symbolPath}.ts`,
|
|
56
|
-
templateDir: TEMPLATE_DIR
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
mapOptions(options) {
|
|
64
|
-
return {
|
|
65
|
-
...options,
|
|
66
|
-
protocolName: kebabCase(options.name),
|
|
67
|
-
passportPackage: options.passportPackage
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
getTemplate(passportPackage) {
|
|
71
|
-
const template = `${passportPackage}.protocol.hbs`;
|
|
72
|
-
return this.srcRenderService.templateExists(template, { templateDir: TEMPLATE_DIR }) ? template : "generic.protocol.hbs";
|
|
73
|
-
}
|
|
74
|
-
getPassportPackageVersion(passportPackage) {
|
|
75
|
-
const passportPkgDetails = this.packages.find((pkg) => pkg.name === passportPackage);
|
|
76
|
-
return passportPkgDetails ? passportPkgDetails["dist-tags"]?.latest : undefined;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
__decorate([
|
|
80
|
-
OnPrompt("generate"),
|
|
81
|
-
__metadata("design:type", Function),
|
|
82
|
-
__metadata("design:paramtypes", []),
|
|
83
|
-
__metadata("design:returntype", Promise)
|
|
84
|
-
], PassportGenerateHook.prototype, "onGeneratePrompt", null);
|
|
85
|
-
__decorate([
|
|
86
|
-
OnExec("generate"),
|
|
87
|
-
__metadata("design:type", Function),
|
|
88
|
-
__metadata("design:paramtypes", [Object]),
|
|
89
|
-
__metadata("design:returntype", Array)
|
|
90
|
-
], PassportGenerateHook.prototype, "onGenerateExec", null);
|
|
91
|
-
PassportGenerateHook = PassportGenerateHook_1 = __decorate([
|
|
92
|
-
Injectable(),
|
|
93
|
-
__metadata("design:paramtypes", [ProvidersInfoService])
|
|
94
|
-
], PassportGenerateHook);
|
|
95
|
-
export { PassportGenerateHook };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type GenerateCmdContext, ProvidersInfoService, SrcRendererService } from "@tsed/cli";
|
|
2
|
-
import { ProjectPackageJson, type Tasks } from "@tsed/cli-core";
|
|
3
|
-
import { PassportClient } from "../services/PassportClient.js";
|
|
4
|
-
export interface PassportGenerateOptions extends GenerateCmdContext {
|
|
5
|
-
passportPackage: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class PassportGenerateHook {
|
|
8
|
-
private providersInfoService;
|
|
9
|
-
protected projectPackageJson: ProjectPackageJson;
|
|
10
|
-
protected srcRenderService: SrcRendererService;
|
|
11
|
-
protected passportClient: PassportClient;
|
|
12
|
-
protected packages: any[];
|
|
13
|
-
constructor(providersInfoService: ProvidersInfoService);
|
|
14
|
-
onGeneratePrompt(): Promise<{
|
|
15
|
-
type: string;
|
|
16
|
-
name: string;
|
|
17
|
-
message: string;
|
|
18
|
-
when(state: any): boolean;
|
|
19
|
-
source: (state: any, keyword: string) => {
|
|
20
|
-
name: string;
|
|
21
|
-
value: any;
|
|
22
|
-
}[];
|
|
23
|
-
}[]>;
|
|
24
|
-
onGenerateExec(ctx: PassportGenerateOptions): Tasks;
|
|
25
|
-
private mapOptions;
|
|
26
|
-
private getTemplate;
|
|
27
|
-
private getPassportPackageVersion;
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const TEMPLATE_DIR: string;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {Req} from "@tsed/platform-http";
|
|
2
|
-
import {BodyParams} from "@tsed/platform-params";
|
|
3
|
-
import {OnInstall, OnVerify, Protocol, Args} from "@tsed/passport";
|
|
4
|
-
import {Strategy} from "{{passportPackage}}";
|
|
5
|
-
|
|
6
|
-
@Protocol({
|
|
7
|
-
name: "{{protocolName}}",
|
|
8
|
-
useStrategy: Strategy,
|
|
9
|
-
settings: {}
|
|
10
|
-
})
|
|
11
|
-
export class {{symbolName}} implements OnVerify, OnInstall {
|
|
12
|
-
async $onVerify(@Req() request: Req, @Args() args: any[]) {
|
|
13
|
-
const [] = args;
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
$onInstall(strategy: Strategy): void {
|
|
18
|
-
// intercept the strategy instance to adding extra configuration
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {Req} from "@tsed/platform-http";
|
|
2
|
-
import {BodyParams} from "@tsed/platform-params";
|
|
3
|
-
import {OnInstall, OnVerify, Protocol} from "@tsed/passport";
|
|
4
|
-
import {BasicStrategy} from "passport-http";
|
|
5
|
-
|
|
6
|
-
@Protocol({
|
|
7
|
-
name: "{{protocolName}}",
|
|
8
|
-
useStrategy: BasicStrategy,
|
|
9
|
-
settings: {}
|
|
10
|
-
})
|
|
11
|
-
export class {{symbolName}} implements OnVerify, OnInstall {
|
|
12
|
-
async $onVerify(@Req() request: Req, @BodyParams() credentials: any) {
|
|
13
|
-
const {username, password} = credentials;
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
$onInstall(strategy: Strategy): void {
|
|
18
|
-
// intercept the strategy instance to adding extra configuration
|
|
19
|
-
}
|
|
20
|
-
}
|