@spytecgps/lambda-utils 2.3.15 → 2.3.16

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 CHANGED
@@ -166,6 +166,35 @@ const SpytecJoi = Joi__namespace.extend((joi) => ({
166
166
  },
167
167
  }));
168
168
 
169
+ const getAuthorizerValidator = (params = {}) => {
170
+ return Joi__namespace.object({
171
+ clientId: Joi__namespace.number(),
172
+ resources: json.object({}),
173
+ scope: Joi__namespace.string().optional(),
174
+ // .error(() => new UnauthorizedError(`missing scope ${scope}`))
175
+ type: Joi__namespace.string().optional(),
176
+ // .error(() => new UnauthorizedError(`missing user type ${type}`))
177
+ enterprise: Joi__namespace.boolean().default(false),
178
+ maintenanceModule: Joi__namespace.boolean().default(false),
179
+ billingMethod: Joi__namespace.string().optional(),
180
+ customerSegment: Joi__namespace.string().optional(),
181
+ securityGroupTagId: Joi__namespace.number().optional().allow(null),
182
+ securityRole: Joi__namespace.string().optional().allow(null),
183
+ ...params,
184
+ });
185
+ };
186
+ /**
187
+ * @deprecated
188
+ */
189
+ const requestContextValidator = Joi__namespace.object({
190
+ authorizer: getAuthorizerValidator(),
191
+ });
192
+ const getRequestContextValidator = (params = {}) => {
193
+ return Joi__namespace.object({
194
+ authorizer: getAuthorizerValidator(params),
195
+ });
196
+ };
197
+
169
198
  class HttpError extends Error {
170
199
  }
171
200
 
@@ -204,40 +233,6 @@ class UnauthorizedError extends HttpError {
204
233
  name = 'UnauthorizedError';
205
234
  }
206
235
 
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
236
  const validateEvent = (event, schema, validateOptions) => {
242
237
  if (!schema) {
243
238
  sdkLogger.logger.warn(`skipping validation`);
@@ -1,11 +1,8 @@
1
1
  import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
2
2
  import * as Joi from 'joi';
3
- import { AuthClass, SpytecAuthContext } from '../types';
4
- interface GetAuthorizerValidatorParams {
5
- scope?: string;
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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/lambda-utils",
3
- "version": "2.3.15",
3
+ "version": "2.3.16",
4
4
  "description": "Lambda Utils",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",