Options
All
  • Public
  • Public/Protected
  • All
Menu

Module express-utils

@dvelop-sdk/express-utils

npm (scoped) npm bundle size (scoped) GitHub license

This package contains util-functions for the express-framework and d.velop app-building.

Explore the docs »
Install via npm »
Check us out on GitHub »

Index

Middleware Functions

  • authenticationMiddleware(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction): Promise<void>
  • contextMiddleware(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, _: Response<any, Record<string, any>>, next: NextFunction): void
  • Sets a DvelopContext to the express-request-object. Accessable via the req.dvelopContext-property.

    import { contextMiddleware } from "@dvelop-sdk/express-utils";

    app.use(contextMiddleware);

    app.use((req: Request, _: Response, next: NextFunction) => {
    console.log(req.dvelopContext);
    next();
    });

    Parameters

    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
    • _: Response<any, Record<string, any>>
    • next: NextFunction

    Returns void

  • validateCloudCenterEventSignatureMiddlewareFactory(appSecret: string): (request: Request, response: Response, next: NextFunction) => void
  • validateCloudCenterEventSignatureMiddlewareFactory(appSecret: string, validateCloudCenterEventSignature: (appSecret: string, params: ValidateCloudCenterEventSignatureParams) => void): (request: Request, response: Response, next: NextFunction) => void
  • Validate the cloud-center-event signature against your appSecret.

    The cloud-center-event signature should be validated for every request when recieving events from the d.velop cloud-center. Refer to the d.velop cloud center API for more information.

    import { validateCloudCenterEventSignatureMiddlewareFactory } from "@dvelop-sdk/express-utils";

    app.use("/some/route/dvelop-cloud-lifecycle-event", validateCloudCenterEventSignatureMiddlewareFactory(process.env.APP_SECRET));

    Parameters

    • appSecret: string

    Returns (request: Request, response: Response, next: NextFunction) => void

      • (request: Request, response: Response, next: NextFunction): void
      • Validate the cloud-center-event signature against your appSecret.

        The cloud-center-event signature should be validated for every request when recieving events from the d.velop cloud-center. Refer to the d.velop cloud center API for more information.

        import { validateCloudCenterEventSignatureMiddlewareFactory } from "@dvelop-sdk/express-utils";

        app.use("/some/route/dvelop-cloud-lifecycle-event", validateCloudCenterEventSignatureMiddlewareFactory(process.env.APP_SECRET));
        category

        Middleware

        Parameters

        • request: Request
        • response: Response
        • next: NextFunction

        Returns void

  • Validate the cloud-center-event signature against your appSecret. You can supply a custom validate-function.

    internal

    Parameters

    • appSecret: string
    • validateCloudCenterEventSignature: (appSecret: string, params: ValidateCloudCenterEventSignatureParams) => void
        • (appSecret: string, params: ValidateCloudCenterEventSignatureParams): void
        • Parameters

          • appSecret: string
          • params: ValidateCloudCenterEventSignatureParams

          Returns void

    Returns (request: Request, response: Response, next: NextFunction) => void

      • (request: Request, response: Response, next: NextFunction): void
      • Validate the cloud-center-event signature against your appSecret. You can supply a custom validate-function.

        internal
        category

        Middleware

        Parameters

        • request: Request
        • response: Response
        • next: NextFunction

        Returns void

  • validateSignatureMiddlewareFactory(appSecret: string): (request: Request, response: Response, next: NextFunction) => void
  • validateSignatureMiddlewareFactory(appSecret: string, validateDvelopContext: (appSecret: string, context: DvelopContext) => void): (request: Request, response: Response, next: NextFunction) => void
  • Validate the requestSignature against the requestData your appSecret. Requires the dvelopContext-propertiy to be set. See {@link dvelopContextMiddleware}.

    The requestSignature should be validated for every request when recieving calls from the d.velop cloud. Refer to the d.velop basics tenant header section for more information.

    import { validateSignatureMiddlewareFactory } from "@dvelop-sdk/express-utils";

    app.use(validateSignatureMiddlewareFactory(process.env.APP_SECRET));

    Parameters

    • appSecret: string

    Returns (request: Request, response: Response, next: NextFunction) => void

      • (request: Request, response: Response, next: NextFunction): void
      • Validate the requestSignature against the requestData your appSecret. Requires the dvelopContext-propertiy to be set. See {@link dvelopContextMiddleware}.

        The requestSignature should be validated for every request when recieving calls from the d.velop cloud. Refer to the d.velop basics tenant header section for more information.

        import { validateSignatureMiddlewareFactory } from "@dvelop-sdk/express-utils";

        app.use(validateSignatureMiddlewareFactory(process.env.APP_SECRET));
        category

        Middleware

        Parameters

        • request: Request
        • response: Response
        • next: NextFunction

        Returns void

  • Validate the requestSignature against the requestData your appSecret. You can supply a custom validate-function.

    internal

    Parameters

    • appSecret: string
    • validateDvelopContext: (appSecret: string, context: DvelopContext) => void

    Returns (request: Request, response: Response, next: NextFunction) => void

      • (request: Request, response: Response, next: NextFunction): void
      • Validate the requestSignature against the requestData your appSecret. You can supply a custom validate-function.

        internal
        category

        Middleware

        Parameters

        • request: Request
        • response: Response
        • next: NextFunction

        Returns void

Other Functions

  • redirectToLoginPage(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>): void
  • Redirect a request to the login page provided by the Identityprovider-App.

    import { redirectToLoginPage, UnauthorizedError } from "@dvelop-sdk/express-utils";

    app.use((err, req, res, next) => {
    if (err instanceof UnauthorizedError && req.accepts("text/html")) {
    redirectToLoginPage(req, res);
    } else {
    res.status(401).send("Unauhtorized") // For Content-Types such as JSON return a 401 - Unauthorized
    }
    });

    Parameters

    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
    • res: Response<any, Record<string, any>>

    Returns void

Generated using TypeDoc