How to use @plumier/core - 10 common examples

To help you get started, we’ve selected a few @plumier/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plumier / plumier / packages / serve-static / src / index.ts View on Github external
if (!isFile)
            throw new HttpStatusError(HttpStatus.NotFound)
        ctx.type = extname(this.body)
        const sendFile = ctx.config.sendFile || ((path: string, opt?: ServeStaticOptions) => send(ctx, path, opt))
        await sendFile(this.body, this.opt)
    }
}

// --------------------------------------------------------------------- //
// ----------------------------- DECORATORS ---------------------------- //
// --------------------------------------------------------------------- //


response.file = (path: string, opt?: ServeStaticOptions) => new FileActionResult(path, opt)

route.historyApiFallback = () => {
    return decorateMethod({ type: "HistoryApiFallback" })
}


// --------------------------------------------------------------------- //
// ---------------------------- MIDDLEWARES ---------------------------- //
// --------------------------------------------------------------------- //

export class ServeStaticMiddleware implements Middleware {
    constructor(public option: ServeStaticOptions) { }

    async execute(invocation: Readonly): Promise {
        if(this.option.rootPath && !this.option.rootPath.startsWith("/"))
            this.option.rootPath = "/" + this.option.rootPath
        const rootPath = this.option.rootPath || ""
        //no route = no controller = possibly static file request
github plumier / plumier / packages / social-login / src / provider / google.ts View on Github external
client_id=618103802046-48c83lio7h0fl4spoqbb6if1g2ol94i4.apps.googleusercontent.com

SERVER SIDE INFO
https://developers.google.com/identity/protocols/OAuth2WebServer


Get Client ID :
goto https://console.developers.google.com  -> select project 
goto credential. Crete credential -> OAuth Client ID 

Playground 
https://developers.google.com/oauthplayground

*/

@domain()
export class GoogleProfile {
    constructor(
        public id: string,
        public family_name: string,
        public given_name: string,
        public locale: string,
        public name: string,
        public picture: string,
    ) { }
}

@domain()
export class GoogleLoginStatus implements SocialLoginStatus {
    constructor(
        public status: "Success" | "Failed",
        @val.optional()
github plumier / plumier / packages / serve-static / src / index.ts View on Github external
async execute(ctx: Context) {
        await super.execute(ctx)
        const isFile = !!mime.lookup(this.body)
        if (!isFile)
            throw new HttpStatusError(HttpStatus.NotFound)
        ctx.type = extname(this.body)
        const sendFile = ctx.config.sendFile || ((path: string, opt?: ServeStaticOptions) => send(ctx, path, opt))
        await sendFile(this.body, this.opt)
    }
}
github plumier / plumier / packages / multipart / src / index.ts View on Github external
            .on("filesLimit", () => reject(new HttpStatusError(422, errorMessage.NumberOfFilesExceeded)))
            .on("finish", async () => {
github plumier / plumier / packages / multipart / src / index.ts View on Github external
async save(subDirectory?: string): Promise {
        const result: FileUploadInfo[] = []
        const temps = await asyncBusboy(this.context, this.option)
        const invalid = temps.filter(x => !x.validSize)
        if (invalid.length > 0)
            throw new HttpStatusError(422, errorMessage.FileSizeExceeded.format(invalid.map(x => x.originalName).join(",")))
        for (const temp of temps) {
            const baseName = basename(temp.fileName)
            const dir = join(this.option.uploadPath, subDirectory || "")
            const destFile = join(dir, baseName)
            await checkDirectory(dir)
            await copy(temp.fileName, destFile)
            const { validSize, fileName, ...info } = temp;
            result.push({ ...info, fileName: join(subDirectory || "", baseName) })
        }
        return result;
    }
}
github plumier / plumier / packages / kernel / src / converter.ts View on Github external
function createConversionError(value: any, typ: Function, path: string[]) {
    const type = (typ as Class).name
    return new ConversionError({ path: path, messages: [errorMessage.UnableToConvertValue.format(value, type)] })
}
github plumier / plumier / packages / social-login / src / provider / google.ts View on Github external
*/

@domain()
export class GoogleProfile {
    constructor(
        public id: string,
        public family_name: string,
        public given_name: string,
        public locale: string,
        public name: string,
        public picture: string,
    ) { }
}

@domain()
export class GoogleLoginStatus implements SocialLoginStatus {
    constructor(
        public status: "Success" | "Failed",
        @val.optional()
        public error?: any,
        @val.optional()
        public data?: GoogleProfile
    ) { }
}

export class GoogleProvider implements SocialAuthProvider {
    tokenEndPoint = "https://www.googleapis.com/oauth2/v4/token"
    profileEndPoint = "https://www.googleapis.com/oauth2/v2/userinfo"

    constructor(
        public clientId: string,
github plumier / plumier / packages / social-login / src / index.ts View on Github external
export function oAuthCallback(option: SocialAuthProvider) {
    return middleware.use(new OAuthCallbackMiddleware(option))
}
github plumier / plumier / packages / social-login / src / index.ts View on Github external
export function oAuthDialogEndPoint(option:DialogProvider){
    return middleware.use(new OAuthDialogEndPointMiddleware(option))
}
github plumier / plumier / packages / swagger / src / index.ts View on Github external
async execute(invocation: Readonly): Promise {
        const uiPath = this.opt.endpoint.toLowerCase() + "/index"
        if (invocation.context.path.toLowerCase() === "/swagger.json")
            return response.json(this.spec)
        if (invocation.context.path.toLowerCase() === this.opt.endpoint.toLowerCase())
            return response.redirect(uiPath)
        if (invocation.context.path.toLowerCase() === uiPath)
            return response.file(join(dist.getAbsoluteFSPath(), "index.html"))
        else
            return invocation.proceed()
    }
}