@spytecgps/lambda-utils 2.3.15 → 2.3.17
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.
- package/dist/index.js +43 -39
- package/dist/types.d.ts +3 -0
- package/dist/validation/requestContext.d.ts +3 -6
- package/dist/wrappers/response.d.ts +1 -1
- package/package.json +2 -2
- package/dist/logger/index.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ var dayjs = require('dayjs');
|
|
|
5
5
|
var timezone = require('dayjs/plugin/timezone');
|
|
6
6
|
var utc = require('dayjs/plugin/utc');
|
|
7
7
|
var Joi = require('joi');
|
|
8
|
-
var qs = require('qs');
|
|
9
8
|
var rawMiddy = require('@middy/core');
|
|
10
9
|
var httpErrorHandler = require('@middy/http-error-handler');
|
|
11
10
|
var httpResponseSerializer = require('@middy/http-response-serializer');
|
|
@@ -32,7 +31,16 @@ function _interopNamespaceDefault(e) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
var Joi__namespace = /*#__PURE__*/_interopNamespaceDefault(Joi);
|
|
35
|
-
|
|
34
|
+
|
|
35
|
+
var stringify = require('./stringify');
|
|
36
|
+
var parse = require('./parse');
|
|
37
|
+
var formats = require('./formats');
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
formats: formats,
|
|
41
|
+
parse: parse,
|
|
42
|
+
stringify: stringify
|
|
43
|
+
};
|
|
36
44
|
|
|
37
45
|
dayjs.extend(utc);
|
|
38
46
|
dayjs.extend(timezone);
|
|
@@ -64,7 +72,7 @@ const urlEncoded = Joi__namespace.extend((joi) => {
|
|
|
64
72
|
type: 'object',
|
|
65
73
|
base: joi.object(),
|
|
66
74
|
coerce(value) {
|
|
67
|
-
return { value:
|
|
75
|
+
return { value: undefined(value) };
|
|
68
76
|
},
|
|
69
77
|
};
|
|
70
78
|
});
|
|
@@ -86,7 +94,7 @@ const SpytecJoi = Joi__namespace.extend((joi) => ({
|
|
|
86
94
|
type: 'urlEncodedObject',
|
|
87
95
|
base: joi.object(),
|
|
88
96
|
coerce(value) {
|
|
89
|
-
return { value:
|
|
97
|
+
return { value: undefined(value) };
|
|
90
98
|
},
|
|
91
99
|
}), (joi) => ({
|
|
92
100
|
type: 'jsonObject',
|
|
@@ -166,6 +174,35 @@ const SpytecJoi = Joi__namespace.extend((joi) => ({
|
|
|
166
174
|
},
|
|
167
175
|
}));
|
|
168
176
|
|
|
177
|
+
const getAuthorizerValidator = (params = {}) => {
|
|
178
|
+
return Joi__namespace.object({
|
|
179
|
+
clientId: Joi__namespace.number(),
|
|
180
|
+
resources: json.object({}),
|
|
181
|
+
scope: Joi__namespace.string().optional(),
|
|
182
|
+
// .error(() => new UnauthorizedError(`missing scope ${scope}`))
|
|
183
|
+
type: Joi__namespace.string().optional(),
|
|
184
|
+
// .error(() => new UnauthorizedError(`missing user type ${type}`))
|
|
185
|
+
enterprise: Joi__namespace.boolean().default(false),
|
|
186
|
+
maintenanceModule: Joi__namespace.boolean().default(false),
|
|
187
|
+
billingMethod: Joi__namespace.string().optional(),
|
|
188
|
+
customerSegment: Joi__namespace.string().optional(),
|
|
189
|
+
securityGroupTagId: Joi__namespace.number().optional().allow(null),
|
|
190
|
+
securityRole: Joi__namespace.string().optional().allow(null),
|
|
191
|
+
...params,
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* @deprecated
|
|
196
|
+
*/
|
|
197
|
+
const requestContextValidator = Joi__namespace.object({
|
|
198
|
+
authorizer: getAuthorizerValidator(),
|
|
199
|
+
});
|
|
200
|
+
const getRequestContextValidator = (params = {}) => {
|
|
201
|
+
return Joi__namespace.object({
|
|
202
|
+
authorizer: getAuthorizerValidator(params),
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
169
206
|
class HttpError extends Error {
|
|
170
207
|
}
|
|
171
208
|
|
|
@@ -204,40 +241,6 @@ class UnauthorizedError extends HttpError {
|
|
|
204
241
|
name = 'UnauthorizedError';
|
|
205
242
|
}
|
|
206
243
|
|
|
207
|
-
const getAuthorizerValidator = ({ scope, type } = {}) => {
|
|
208
|
-
return Joi__namespace.object({
|
|
209
|
-
clientId: Joi__namespace.number(),
|
|
210
|
-
resources: json.object({}),
|
|
211
|
-
scope: scope
|
|
212
|
-
? Joi__namespace.string()
|
|
213
|
-
.pattern(new RegExp(`${scope}`))
|
|
214
|
-
.error(() => new UnauthorizedError(`missing scope ${scope}`))
|
|
215
|
-
: Joi__namespace.optional(),
|
|
216
|
-
type: type
|
|
217
|
-
? Joi__namespace.any()
|
|
218
|
-
.valid(type)
|
|
219
|
-
.error(() => new UnauthorizedError(`missing user type ${type}`))
|
|
220
|
-
: Joi__namespace.optional(),
|
|
221
|
-
enterprise: Joi__namespace.boolean().default(false),
|
|
222
|
-
maintenanceModule: Joi__namespace.boolean().default(false),
|
|
223
|
-
billingMethod: Joi__namespace.string().optional(),
|
|
224
|
-
customerSegment: Joi__namespace.string().optional(),
|
|
225
|
-
securityGroupTagId: Joi__namespace.number().optional().allow(null),
|
|
226
|
-
securityRole: Joi__namespace.string().optional().allow(null),
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* @deprecated
|
|
231
|
-
*/
|
|
232
|
-
const requestContextValidator = Joi__namespace.object({
|
|
233
|
-
authorizer: getAuthorizerValidator(),
|
|
234
|
-
});
|
|
235
|
-
const getRequestContextValidator = (params = {}) => {
|
|
236
|
-
return Joi__namespace.object({
|
|
237
|
-
authorizer: getAuthorizerValidator(params),
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
244
|
const validateEvent = (event, schema, validateOptions) => {
|
|
242
245
|
if (!schema) {
|
|
243
246
|
sdkLogger.logger.warn(`skipping validation`);
|
|
@@ -275,11 +278,12 @@ const buildResponseBody = (statusCode, message, data) => {
|
|
|
275
278
|
result: typeof data !== 'undefined' ? data : undefined,
|
|
276
279
|
};
|
|
277
280
|
};
|
|
278
|
-
const buildProxyResult = ({ statusCode = 200, message = 'ok', data, headers = {}, rawResult = false, stringifyBody = true, }) => {
|
|
281
|
+
const buildProxyResult = ({ statusCode = 200, message = 'ok', data, headers = {}, multiValueHeaders = {}, rawResult = false, stringifyBody = true, }) => {
|
|
279
282
|
const resp = rawResult ? data : buildResponseBody(statusCode, message, data);
|
|
280
283
|
const body = stringifyBody ? resp && JSON.stringify(resp) : data;
|
|
281
284
|
return {
|
|
282
285
|
headers: { ...baseHeaders, ...headers },
|
|
286
|
+
multiValueHeaders,
|
|
283
287
|
statusCode,
|
|
284
288
|
body,
|
|
285
289
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
|
|
2
2
|
import * as Joi from 'joi';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type?: AuthClass;
|
|
7
|
-
}
|
|
8
|
-
export declare const getAuthorizerValidator: ({ scope, type }?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
|
|
3
|
+
import { SpytecAuthContext } from '../types';
|
|
4
|
+
type GetAuthorizerValidatorParams = Partial<Record<keyof SpytecAuthContext, Joi.AnySchema>>;
|
|
5
|
+
export declare const getAuthorizerValidator: (params?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
|
|
9
6
|
/**
|
|
10
7
|
* @deprecated
|
|
11
8
|
*/
|
|
@@ -5,4 +5,4 @@ export declare const buildResponseBody: <T>(statusCode: number, message: string,
|
|
|
5
5
|
message: string;
|
|
6
6
|
result: T | undefined;
|
|
7
7
|
};
|
|
8
|
-
export declare const buildProxyResult: <R>({ statusCode, message, data, headers, rawResult, stringifyBody, }: HandlerResponse<R>) => APIGatewayProxyResult;
|
|
8
|
+
export declare const buildProxyResult: <R>({ statusCode, message, data, headers, multiValueHeaders, rawResult, stringifyBody, }: HandlerResponse<R>) => APIGatewayProxyResult;
|
package/package.json
CHANGED
package/dist/logger/index.d.ts
DELETED