Skip to content

Commit

Permalink
Merge pull request #248 from Adapcon/develop
Browse files Browse the repository at this point in the history
Integrate Chages
  • Loading branch information
Viserion77 authored Apr 9, 2024
2 parents 85057a0 + 88abb1a commit e42c5be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapcon-utils-js",
"version": "1.3.2",
"version": "1.3.3",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
7 changes: 5 additions & 2 deletions src/lambda/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ export type CrudInputParams = {
}
export type DocfySettings = {
label: string
description?: string
required?: boolean
translate?: string
default?: any
}

export type Docfy = {
type: 'screen' | 'integration' | 'public' | 'session' | 'hybrid'
description: string
pathParameters?: { [key: string]: DocfySettings }
queryStringParameters: { [key: string]: DocfySettings }
pathParameters?: { [key: string]: Omit<DocfySettings, 'required'> }
queryStringParameters?: { [key: string]: DocfySettings }
headers?: { [key: string]: DocfySettings }
body?: { [key: string]: DocfySettings }
requestContext?: { [key: string]: DocfySettings }
fromEvent?: { [key: string]: DocfySettings }
}
16 changes: 13 additions & 3 deletions src/lambda/lambdaGetParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ const extractParams = (docfy: Docfy, parameter: string, evt: APIGatewayEvent) =>

for (const [key, value] of Object.entries(docfy[parameter] ?? {}) as Array<[key: string, value: DocfySettings]>) {
const identity = value.translate ?? key
const param = get(evt, `${parameter}.${key}`)

if (value.required && !param) { errs[key] = `Missing(${parameter}) ${value.label}` } else if (param !== 'undefined') params[identity] = param
const param = get(evt, `${parameter}.${key}`) ?? value.default

const alreadyExist = value.translate && !params[value.translate]
const isRequired = value.required ?? parameter === 'pathParameters'
if (isRequired && !param && alreadyExist) {
errs[key] = `Missing(${parameter}) ${value.label}`
} else if (param !== 'undefined' && !params[identity]) {
params[identity] = param
}
}
return { params, errs }
}
Expand Down Expand Up @@ -90,6 +96,10 @@ export const lambdaSettingsGetParameters = <T>(docfy: Docfy, evt: APIGatewayEven
Object.assign(parameters, requestContext.params)
Object.assign(errs, requestContext.errs)

const fromEvent = extractParams(docfy, 'fromEvent', { ...evt })
Object.assign(parameters, fromEvent.params)
Object.assign(errs, fromEvent.errs)

if (docfy.body) {
try {
const evtObj = {
Expand Down

0 comments on commit e42c5be

Please sign in to comment.