@creator.co/wapi 1.1.8 → 1.2.0-alpha2
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/.eslintrc.cjs +22 -22
- package/README.md +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +50 -0
- package/dist/src/API/Request.d.ts +4 -5
- package/dist/src/API/Request.js +3 -4
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +1 -1
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +0 -1
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +4 -7
- package/dist/src/BaseEvent/Process.js +1 -2
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +6 -6
- package/dist/src/BaseEvent/Transaction.js +2 -4
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +28 -0
- package/dist/src/Config/Configuration.js +93 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +17 -0
- package/dist/src/Config/EnvironmentVar.js +155 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Globals.d.ts +11 -0
- package/dist/src/Globals.js +12 -0
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +42 -11
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.js +50 -24
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Server/Router.d.ts +30 -0
- package/dist/src/Server/Router.js +21 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +11 -0
- package/dist/src/Server/lib/ContainerServer.js +100 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +9 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +14 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +164 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +44 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +15 -0
- package/dist/src/Server/lib/container/Proxy.js +153 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +6 -0
- package/dist/src/Server/lib/container/Utils.js +109 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +5 -0
- package/dist/src/Validation/Validator.js +39 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/index.ts +8 -6
- package/package.json +14 -3
- package/src/API/Request.ts +6 -12
- package/src/API/Response.ts +1 -1
- package/src/BaseEvent/EventProcessor.ts +3 -2
- package/src/BaseEvent/Process.ts +11 -10
- package/src/BaseEvent/Transaction.ts +24 -16
- package/src/Config/Configuration.ts +83 -0
- package/src/Config/EnvironmentVar.ts +94 -0
- package/src/Globals.ts +15 -0
- package/src/Server/Router.ts +51 -0
- package/src/Server/lib/ContainerServer.ts +27 -0
- package/src/Server/lib/Server.ts +66 -0
- package/src/Server/lib/container/GenericHandler.ts +63 -0
- package/src/Server/lib/container/GenericHandlerEvent.ts +133 -0
- package/src/Server/lib/container/HealthHandler.ts +5 -0
- package/src/Server/lib/container/Proxy.ts +107 -0
- package/src/Server/lib/container/Utils.ts +45 -0
- package/src/Validation/Validator.ts +35 -0
- package/tsconfig.json +2 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import unflatten from "unflatten"
|
|
2
|
+
// https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
|
|
3
|
+
// (rawHeaders: Array<string>): { [string]: Array<string> }
|
|
4
|
+
export function parseMultiValueHeaders(rawHeaders) {
|
|
5
|
+
if (rawHeaders.length === 0) return null
|
|
6
|
+
//
|
|
7
|
+
const map = new Map()
|
|
8
|
+
const unflattened = unflatten(rawHeaders, 2)
|
|
9
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
10
|
+
for (const key of Object.keys(unflattened)) {
|
|
11
|
+
const item = map.get(key)
|
|
12
|
+
if (item) item.push(unflattened[key])
|
|
13
|
+
else map.set(key, [unflattened[key]])
|
|
14
|
+
}
|
|
15
|
+
return Object.fromEntries(map)
|
|
16
|
+
}
|
|
17
|
+
// https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
|
|
18
|
+
// [ [ 'petType', 'dog' ], [ 'petType', 'fish' ] ]
|
|
19
|
+
// => { petType: [ 'dog', 'fish' ] },
|
|
20
|
+
export function parseMultiValueQueryStringParameters(url) {
|
|
21
|
+
// dummy placeholder url for the WHATWG URL constructor
|
|
22
|
+
// https://github.com/nodejs/node/issues/12682
|
|
23
|
+
const { searchParams } = new URL(url, "http://example")
|
|
24
|
+
//
|
|
25
|
+
if (Array.from(searchParams).length === 0) return null
|
|
26
|
+
const map = new Map()
|
|
27
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
28
|
+
for (const [key, value] of searchParams) {
|
|
29
|
+
const item = map.get(key)
|
|
30
|
+
if (item) item.push(value)
|
|
31
|
+
else map.set(key, [value])
|
|
32
|
+
}
|
|
33
|
+
return Object.fromEntries(map)
|
|
34
|
+
}
|
|
35
|
+
export function parseQueryStringParameters(url) {
|
|
36
|
+
// dummy placeholder url for the WHATWG URL constructor
|
|
37
|
+
// https://github.com/nodejs/node/issues/12682
|
|
38
|
+
const { searchParams } = new URL(url, "http://example")
|
|
39
|
+
if (Array.from(searchParams).length === 0) return null
|
|
40
|
+
return Object.fromEntries(searchParams)
|
|
41
|
+
}
|
|
42
|
+
//
|
|
43
|
+
export function nullIfEmpty(obj) {
|
|
44
|
+
return obj && (Object.keys(obj).length > 0 ? obj : null)
|
|
45
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
import Response from "../API/Response"
|
|
4
|
+
import Globals from "../Globals"
|
|
5
|
+
|
|
6
|
+
export default class Validator {
|
|
7
|
+
public static validateSchema(
|
|
8
|
+
data: any,
|
|
9
|
+
schema: z.ZodObject<any>,
|
|
10
|
+
): boolean | Response {
|
|
11
|
+
let error, validatedInput
|
|
12
|
+
// Validate body against known zod schema
|
|
13
|
+
try {
|
|
14
|
+
validatedInput = schema.parse(data) as typeof schema
|
|
15
|
+
} catch (err: z.ZodError | any) {
|
|
16
|
+
if (err instanceof z.ZodError) {
|
|
17
|
+
error = err.issues
|
|
18
|
+
.map((v) => {
|
|
19
|
+
return `${v.code} - ${v.message} ${v.path}`
|
|
20
|
+
})
|
|
21
|
+
.join(", ")
|
|
22
|
+
} else if (err.message) error = err.message
|
|
23
|
+
else error = "Unknown validation error!"
|
|
24
|
+
}
|
|
25
|
+
// Error validation
|
|
26
|
+
if (!validatedInput || error) {
|
|
27
|
+
return Response.BadRequestResponse(
|
|
28
|
+
Globals.ErrorResponseValidationFail,
|
|
29
|
+
Globals.ErrorCode_InvalidInput,
|
|
30
|
+
)
|
|
31
|
+
} else {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|