@tsed/passport 7.79.3 → 7.80.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.
@@ -0,0 +1,19 @@
1
+ import { BeforeRoutesInit, OnInit, PlatformApplication, Logger } from "@tsed/common";
2
+ import { PassportSerializerService } from "./services/PassportSerializerService.js";
3
+ import { ProtocolsService } from "./services/ProtocolsService.js";
4
+ /**
5
+ * @ignore
6
+ */
7
+ export declare class PassportModule implements OnInit, BeforeRoutesInit {
8
+ private app;
9
+ private protocolsService;
10
+ private passportSerializer;
11
+ userProperty: string;
12
+ pauseStream: boolean;
13
+ disableSession: boolean;
14
+ platformName: string;
15
+ logger: Logger;
16
+ constructor(app: PlatformApplication, protocolsService: ProtocolsService, passportSerializer: PassportSerializerService);
17
+ $onInit(): Promise<any>;
18
+ $beforeRoutesInit(): void | Promise<any>;
19
+ }
@@ -0,0 +1 @@
1
+ export declare const PROVIDER_TYPE_PROTOCOL = "protocol";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Inject args resolve by the passport strategy on verify method.
3
+ * @decorator
4
+ */
5
+ export declare function Args(): any;
6
+ export declare function Arg(index: number): any;
@@ -0,0 +1,6 @@
1
+ import { AuthenticateOptions as PassportAuthenticateOptions } from "passport";
2
+ export interface AuthenticateOptions extends PassportAuthenticateOptions {
3
+ security?: Record<string, string[]>;
4
+ originalUrl?: boolean;
5
+ }
6
+ export declare function Authenticate(protocol?: string | string[], options?: AuthenticateOptions): Function;
@@ -0,0 +1,6 @@
1
+ import { AuthenticateOptions } from "passport";
2
+ export interface AuthorizeOptions extends AuthenticateOptions {
3
+ security?: Record<string, string[]>;
4
+ originalUrl?: boolean;
5
+ }
6
+ export declare function Authorize(protocol?: string | string[], options?: AuthorizeOptions): Function;
@@ -0,0 +1,11 @@
1
+ import { ProtocolOptions } from "../interfaces/ProtocolOptions.js";
2
+ /**
3
+ * Declare a new Protocol base on a Passport Strategy
4
+ *
5
+ * @decorator
6
+ * @class
7
+ */
8
+ export declare function Protocol<T = any>(options: ProtocolOptionsDecorator<T>): any;
9
+ export type ProtocolOptionsDecorator<T = any> = {
10
+ name: string;
11
+ } & Partial<ProtocolOptions<T>>;
@@ -0,0 +1,5 @@
1
+ export declare class UserInfo {
2
+ id: string;
3
+ email: string;
4
+ password: string;
5
+ }
@@ -0,0 +1,4 @@
1
+ import { Exception } from "@tsed/exceptions";
2
+ export declare class PassportException extends Exception {
3
+ constructor(error: any);
4
+ }
@@ -0,0 +1,5 @@
1
+ import { Unauthorized } from "@tsed/exceptions";
2
+ export declare class PassportMessage extends Unauthorized {
3
+ opts: Record<string, unknown>;
4
+ constructor(message: string, opts?: Record<string, unknown>);
5
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./contants/constants.js";
5
+ export * from "./decorators/args.js";
6
+ export * from "./decorators/authenticate.js";
7
+ export * from "./decorators/authorize.js";
8
+ export * from "./decorators/protocol.js";
9
+ export * from "./domain/UserInfo.js";
10
+ export * from "./errors/PassportException.js";
11
+ export * from "./errors/PassportMessage.js";
12
+ export * from "./interfaces/BeforeInstall.js";
13
+ export * from "./interfaces/interfaces.js";
14
+ export * from "./interfaces/OnInstall.js";
15
+ export * from "./interfaces/OnVerify.js";
16
+ export * from "./interfaces/ProtocolMethods.js";
17
+ export * from "./interfaces/ProtocolOptions.js";
18
+ export * from "./middlewares/PassportMiddleware.js";
19
+ export * from "./PassportModule.js";
20
+ export * from "./services/PassportSerializerService.js";
21
+ export * from "./services/ProtocolsService.js";
22
+ export * from "./utils/getProtocolsFromRequest.js";
@@ -0,0 +1,3 @@
1
+ export interface BeforeInstall<Settings = any> {
2
+ $beforeInstall(setting: Settings): Promise<Settings> | Settings | void;
3
+ }
@@ -0,0 +1,4 @@
1
+ import { Strategy } from "passport";
2
+ export interface OnInstall {
3
+ $onInstall(strategy: Strategy): void | Promise<void>;
4
+ }
@@ -0,0 +1,3 @@
1
+ export interface OnVerify {
2
+ $onVerify(...args: any[]): Promise<any | any[]> | any | any[];
3
+ }
@@ -0,0 +1,5 @@
1
+ import { OnInstall } from "./OnInstall.js";
2
+ import { OnVerify } from "./OnVerify.js";
3
+ import { BeforeInstall } from "./BeforeInstall.js";
4
+ export interface ProtocolMethods<Settings = any> extends OnVerify, OnInstall, BeforeInstall<Settings> {
5
+ }
@@ -0,0 +1,7 @@
1
+ import { Type } from "@tsed/core";
2
+ import { Strategy } from "passport";
3
+ export interface ProtocolOptions<Settings = any> {
4
+ name: string;
5
+ useStrategy: Type<Strategy>;
6
+ settings: Settings;
7
+ }
@@ -0,0 +1,19 @@
1
+ import { Type } from "@tsed/core";
2
+ import { PassportStatic } from "passport";
3
+ import { ProtocolOptions } from "./ProtocolOptions.js";
4
+ declare global {
5
+ namespace TsED {
6
+ interface Configuration {
7
+ passport: {
8
+ userProperty?: string;
9
+ pauseStream?: string;
10
+ disableSession?: boolean;
11
+ userInfoModel?: Type<any> | false;
12
+ module?: PassportStatic;
13
+ protocols?: {
14
+ [protocolName: string]: Partial<ProtocolOptions>;
15
+ };
16
+ };
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ import { Context } from "@tsed/common";
2
+ import { ProtocolsService } from "../services/ProtocolsService.js";
3
+ export declare class PassportMiddleware {
4
+ protocolsService: ProtocolsService;
5
+ shouldSkip(ctx: Context): any;
6
+ use(ctx: Context): Promise<void>;
7
+ }
@@ -0,0 +1,9 @@
1
+ import { UserInfo } from "../domain/UserInfo.js";
2
+ /**
3
+ * @ignore
4
+ */
5
+ export declare class PassportSerializerService {
6
+ private model;
7
+ serialize(user: UserInfo, done: any): void;
8
+ deserialize(obj: any, done: any): void;
9
+ }
@@ -0,0 +1,54 @@
1
+ import { PlatformContext, PlatformHandler } from "@tsed/common";
2
+ import { Provider } from "@tsed/di";
3
+ import { Strategy } from "passport";
4
+ import type { ProtocolMethods } from "../interfaces/ProtocolMethods.js";
5
+ /**
6
+ * @ignore
7
+ */
8
+ export declare class ProtocolsService {
9
+ readonly strategies: Map<string, Strategy>;
10
+ protected platformHandler: PlatformHandler;
11
+ private injector;
12
+ getProtocols(): Provider[];
13
+ getProtocolsNames(): string[];
14
+ /**
15
+ * Invoke provider and bind it to passport.
16
+ * @param provider
17
+ */
18
+ invoke(provider: Provider): Promise<ProtocolMethods<any> & Record<string, any>>;
19
+ /**
20
+ * Call authenticate passport method.
21
+ * @param protocols
22
+ * @param options
23
+ * @param ctx
24
+ */
25
+ authenticate(protocols: string | string[], options: Record<string, any>, ctx: PlatformContext): Promise<void>;
26
+ /**
27
+ * Call authorize passport method.
28
+ * @param protocols
29
+ * @param options
30
+ * @param ctx
31
+ */
32
+ authorize(protocols: string | string[], options: Record<string, any>, ctx: PlatformContext): Promise<void>;
33
+ /**
34
+ * Call passport authenticate or authorize depending on the chosen method.
35
+ * @param method
36
+ * @param protocols
37
+ * @param options
38
+ * @param ctx
39
+ * @private
40
+ */
41
+ private call;
42
+ /**
43
+ * Create strategy options based on decorator metadata and global configuration
44
+ * @param provider
45
+ * @private
46
+ */
47
+ private getOptions;
48
+ /**
49
+ * Create the verifier handler for passport
50
+ * @param provider
51
+ * @private
52
+ */
53
+ private createHandler;
54
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @ignore
3
+ */
4
+ export declare function getProtocolsFromRequest(req: any, protocol: string | string[], defaultProtocols: string[]): string[];
package/package.json CHANGED
@@ -1,48 +1,52 @@
1
1
  {
2
2
  "name": "@tsed/passport",
3
- "version": "7.79.3",
4
3
  "description": "Passport package for Ts.ED framework",
4
+ "type": "commonjs",
5
+ "version": "7.80.0",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./lib/cjs/index.js",
7
8
  "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
- "types": "./lib/types/index.d.ts",
11
- "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js",
13
- "default": "./lib/esm/index.js"
11
+ ".": {
12
+ "types": "./lib/types/index.d.ts",
13
+ "import": "./lib/esm/index.js",
14
+ "default": "./lib/cjs/index.js"
15
+ }
14
16
  },
15
17
  "scripts": {
16
18
  "clean": "rm -rf lib",
17
19
  "build": "yarn clean && yarn barrels && yarn build:ts",
18
20
  "barrels": "barrels",
19
- "test": "jest --max-workers=2 && jest-coverage-thresholds-bumper",
21
+ "test": "vitest run",
20
22
  "start": "ts-node src/index.ts",
21
- "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
23
+ "build:ts": "tsc --build tsconfig.json",
24
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
22
25
  },
23
26
  "dependencies": {
24
27
  "tslib": "2.6.1"
25
28
  },
26
29
  "devDependencies": {
27
- "@tsed/barrels": "7.79.3",
28
- "@tsed/common": "7.79.3",
29
- "@tsed/core": "7.79.3",
30
- "@tsed/di": "7.79.3",
31
- "@tsed/platform-router": "7.79.3",
32
- "@tsed/typescript": "7.79.3",
30
+ "@tsed/barrels": "7.80.0",
31
+ "@tsed/common": "7.80.0",
32
+ "@tsed/core": "7.80.0",
33
+ "@tsed/di": "7.80.0",
34
+ "@tsed/platform-router": "7.80.0",
35
+ "@tsed/typescript": "7.80.0",
33
36
  "@types/passport": "1.0.16",
34
37
  "@types/passport-http": "0.3.11",
35
38
  "@types/passport-local": "1.0.38",
36
39
  "@types/passport-strategy": "0.2.38",
37
40
  "eslint": "^8.57.0",
38
- "jest": "^29.7.0",
39
41
  "passport": "0.7.0",
40
42
  "passport-http": "0.3.0",
41
43
  "passport-local": "1.0.0",
42
- "passport-strategy": "1.0.0"
44
+ "passport-strategy": "1.0.0",
45
+ "typescript": "4.9.5",
46
+ "vitest": "2.0.4"
43
47
  },
44
48
  "peerDependencies": {
45
- "@tsed/common": "7.79.3",
49
+ "@tsed/common": "7.80.0",
46
50
  "passport": ">=0.4.1"
47
51
  },
48
52
  "peerDependenciesMeta": {
@@ -0,0 +1,21 @@
1
+ // @ts-ignore
2
+ import {presets} from "@tsed/vitest/presets";
3
+ import {defineConfig} from "vitest/config";
4
+
5
+ export default defineConfig(
6
+ {
7
+ ...presets,
8
+ test: {
9
+ ...presets.test,
10
+ coverage: {
11
+ ...presets.test.coverage,
12
+ thresholds: {
13
+ statements: 0,
14
+ branches: 0,
15
+ functions: 0,
16
+ lines: 0
17
+ }
18
+ }
19
+ }
20
+ }
21
+ );
package/jest.config.js DELETED
@@ -1,20 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
- const config = require("@tsed/jest-config");
4
-
5
- module.exports = {
6
- ...config,
7
- roots: ["<rootDir>/src", "<rootDir>/test"],
8
- moduleNameMapper: {
9
- ...config.moduleNameMapper,
10
- "@tsed/passport": "<rootDir>/src/index.ts"
11
- },
12
- coverageThreshold: {
13
- global: {
14
- statements: 0,
15
- branches: 0,
16
- functions: 0,
17
- lines: 0
18
- }
19
- }
20
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/tsconfig.esm.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "extends": "@tsed/typescript/tsconfig.node.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types",
10
- "composite": true,
11
- "noEmit": false
12
- },
13
- "include": ["src", "src/**/*.json"],
14
- "exclude": [
15
- "node_modules",
16
- "test",
17
- "lib",
18
- "benchmark",
19
- "coverage",
20
- "spec",
21
- "**/*.benchmark.ts",
22
- "**/*.spec.ts",
23
- "keys",
24
- "jest.config.js",
25
- "**/__mock__/**",
26
- "webpack.config.js"
27
- ],
28
- "references": [
29
- {
30
- "path": "../../platform/common"
31
- },
32
- {
33
- "path": "../../core"
34
- },
35
- {
36
- "path": "../../di"
37
- },
38
- {
39
- "path": "../../platform/platform-router"
40
- }
41
- ]
42
- }