@spytecgps/lambda-utils 0.0.2 → 0.0.5

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.
@@ -1,12 +1,8 @@
1
- export declare const apiResponse: <T>(code: number, message: string, data?: T) => {
1
+ import { HandlerResponse } from './types';
2
+ import { APIGatewayProxyResult } from 'aws-lambda';
3
+ export declare const buildResponseBody: <T>(statusCode: number, message: string, data?: T) => {
2
4
  success: boolean;
3
5
  message: string;
4
6
  result: T;
5
7
  };
6
- export declare const buildResponse: (code: number, message: string, data?: any) => {
7
- headers: {
8
- 'Content-Type': string;
9
- };
10
- statusCode: number;
11
- body: string;
12
- };
8
+ export declare const buildProxyResult: <R>({ statusCode, message, data, headers, }: HandlerResponse<R>) => APIGatewayProxyResult;
package/dist/types.d.ts CHANGED
@@ -1,18 +1,26 @@
1
1
  import { APIGatewayProxyWithLambdaAuthorizerEvent } from 'aws-lambda';
2
- import { ObjectSchema, ValidationResult } from 'joi';
2
+ import { ObjectSchema } from 'joi';
3
+ export interface SpytecAuthorizedResources {
4
+ devices: string[];
5
+ }
3
6
  export interface SpytecAuthContext {
4
7
  type: 'user' | 'client';
5
8
  userId?: string;
6
9
  clientId: number;
7
- resources: {
8
- devices: string[];
9
- };
10
+ resources: SpytecAuthorizedResources;
10
11
  }
11
- export interface WrapperArgs<T, R> {
12
- event: APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext>;
13
- schema: ObjectSchema<T>;
14
- handler: (event: T) => Promise<R>;
12
+ export declare type BaseEvent = APIGatewayProxyWithLambdaAuthorizerEvent<SpytecAuthContext>;
13
+ export interface WrapperArgs<E, R> {
14
+ event: BaseEvent;
15
+ schema?: ObjectSchema<E>;
16
+ handler: (event: E) => Promise<HandlerResponse<R>>;
15
17
  }
16
- export interface FullValidationResult<T> extends Omit<ValidationResult, 'value'> {
17
- value: T;
18
+ export interface HandlerResponse<R> {
19
+ statusCode?: number;
20
+ headers?: {
21
+ [header: string]: boolean | number | string;
22
+ };
23
+ isBase64Encoded?: boolean;
24
+ message?: string;
25
+ data?: R;
18
26
  }
@@ -0,0 +1,4 @@
1
+ import * as Joi from 'joi';
2
+ export declare const json: any;
3
+ export declare const urlEncoded: any;
4
+ export declare const requestContext: Joi.ObjectSchema<any>;
@@ -0,0 +1,3 @@
1
+ import validateEvent from './validateEvent';
2
+ export { validateEvent };
3
+ export * from './custom';
@@ -0,0 +1,3 @@
1
+ import { ObjectSchema } from 'joi';
2
+ declare const validateEvent: <T>(event: any, schema?: ObjectSchema<T>) => T;
3
+ export default validateEvent;
@@ -0,0 +1,4 @@
1
+ import { APIGatewayProxyResult } from 'aws-lambda';
2
+ import { WrapperArgs } from '../types';
3
+ declare const apiGwWrapper: <E, R>({ event, schema, handler }: WrapperArgs<E, R>) => Promise<APIGatewayProxyResult>;
4
+ export default apiGwWrapper;
@@ -0,0 +1,3 @@
1
+ import apiGwWrapper from './apiGwWrapper';
2
+ export { apiGwWrapper };
3
+ export * from './response';
@@ -0,0 +1,8 @@
1
+ import { APIGatewayProxyResult } from 'aws-lambda';
2
+ import { HandlerResponse } from '../types';
3
+ export declare const buildResponseBody: <T>(statusCode: number, message: string, data?: T) => {
4
+ success: boolean;
5
+ message: string;
6
+ result: T;
7
+ };
8
+ export declare const buildProxyResult: <R>({ statusCode, message, data, headers, }: HandlerResponse<R>) => APIGatewayProxyResult;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@spytecgps/lambda-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "Lambda Utils",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {
8
8
  "version": "npm run format && git add -A src",
9
+ "preversion": "npm test",
9
10
  "postversion": "git push && git push --tags",
10
11
  "prepublishOnly": "npm test && npm run lint",
11
12
  "prepare": "npm run build",
@@ -27,7 +28,8 @@
27
28
  },
28
29
  "homepage": "https://github.com/spytecgps/lambda-utils#readme",
29
30
  "dependencies": {
30
- "joi": "^17.4.0"
31
+ "joi": "^17.4.0",
32
+ "qs": "^6.10.1"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@types/aws-lambda": "^8.10.76",