1.0.0 • Published 5 years ago

@diy-kitchens/aws-utils v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

Ultima AWS Utils

AdminAction

Utility action to decode and validate Ultima admin information from the header.

Construct a new AdminAction passing the event, context, claims, and secret used to sign the JWT token.

The execute method will call the provided function if the authorisation is valid.

The function will be called with a parameter object with queryString, body (parsed to an object) and adminInfo. AdminInfo is defined as follows:

export interface AdminInfo {
    id: string;
    clockNumber: string;
    email: string;
    firstName: string;
    lastName: string;
    claims: string[];
}

The output from the provided function will be returned in the response body with appropriate status code and CORS headers.

An example of using the action can be found in the order-admin-api.

service.getBaskets(...) will only execute if the calling user has the claims defined in [config.claims.list]

    const action = new AdminAction(event, context, [config.claims.list], config.auth.adminSecret);
    return await action.execute(params => service.getBaskets(params.queryString.email, params.queryString.orderId));

UserAction

Utility action to decode and validate Ultima user information from the header.

Construct a new UserAction passing the event, context, and secret used to sign the JWT token.

The function will be called with a parameter object with queryString, body (parsed to an object) and userInfo. UserInfo is defined as follows:

export interface UserInfo {
    id: number;
    email: string;
    firstName: string;
    lastName: string;
}

The output from the provided function will be returned in the response body with appropriate status code and CORS headers.

An example of using the action can be found in the order-admin-api.

    const action = new UserAction(event, context, config.auth.secret);
    return await action.execute(async params => service.getOrders(params.userInfo.email));