@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.
Files changed (79) hide show
  1. package/.eslintrc.cjs +22 -22
  2. package/README.md +1 -0
  3. package/dist/index.d.ts +3 -2
  4. package/dist/index.js +5 -3
  5. package/dist/index.js.map +1 -1
  6. package/dist/package.json +50 -0
  7. package/dist/src/API/Request.d.ts +4 -5
  8. package/dist/src/API/Request.js +3 -4
  9. package/dist/src/API/Request.js.map +1 -1
  10. package/dist/src/API/Response.d.ts +1 -1
  11. package/dist/src/API/Response.js.map +1 -1
  12. package/dist/src/BaseEvent/EventProcessor.js +0 -1
  13. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  14. package/dist/src/BaseEvent/Process.d.ts +4 -7
  15. package/dist/src/BaseEvent/Process.js +1 -2
  16. package/dist/src/BaseEvent/Process.js.map +1 -1
  17. package/dist/src/BaseEvent/Transaction.d.ts +6 -6
  18. package/dist/src/BaseEvent/Transaction.js +2 -4
  19. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  20. package/dist/src/Config/Configuration.d.ts +28 -0
  21. package/dist/src/Config/Configuration.js +93 -0
  22. package/dist/src/Config/Configuration.js.map +1 -0
  23. package/dist/src/Config/EnvironmentVar.d.ts +17 -0
  24. package/dist/src/Config/EnvironmentVar.js +155 -0
  25. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  26. package/dist/src/Globals.d.ts +11 -0
  27. package/dist/src/Globals.js +12 -0
  28. package/dist/src/Globals.js.map +1 -1
  29. package/dist/src/Logger/Logger.js +42 -11
  30. package/dist/src/Logger/Logger.js.map +1 -1
  31. package/dist/src/Mailer/Mailer.js +50 -24
  32. package/dist/src/Mailer/Mailer.js.map +1 -1
  33. package/dist/src/Server/Router.d.ts +30 -0
  34. package/dist/src/Server/Router.js +21 -0
  35. package/dist/src/Server/Router.js.map +1 -0
  36. package/dist/src/Server/lib/ContainerServer.d.ts +11 -0
  37. package/dist/src/Server/lib/ContainerServer.js +100 -0
  38. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  39. package/dist/src/Server/lib/Server.d.ts +9 -0
  40. package/dist/src/Server/lib/Server.js +137 -0
  41. package/dist/src/Server/lib/Server.js.map +1 -0
  42. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  43. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  44. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  45. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +14 -0
  46. package/dist/src/Server/lib/container/GenericHandlerEvent.js +164 -0
  47. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  48. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  49. package/dist/src/Server/lib/container/HealthHandler.js +44 -0
  50. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  51. package/dist/src/Server/lib/container/Proxy.d.ts +15 -0
  52. package/dist/src/Server/lib/container/Proxy.js +153 -0
  53. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  54. package/dist/src/Server/lib/container/Utils.d.ts +6 -0
  55. package/dist/src/Server/lib/container/Utils.js +109 -0
  56. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  57. package/dist/src/Validation/Validator.d.ts +5 -0
  58. package/dist/src/Validation/Validator.js +39 -0
  59. package/dist/src/Validation/Validator.js.map +1 -0
  60. package/index.ts +8 -6
  61. package/package.json +14 -3
  62. package/src/API/Request.ts +6 -12
  63. package/src/API/Response.ts +1 -1
  64. package/src/BaseEvent/EventProcessor.ts +3 -2
  65. package/src/BaseEvent/Process.ts +11 -10
  66. package/src/BaseEvent/Transaction.ts +24 -16
  67. package/src/Config/Configuration.ts +83 -0
  68. package/src/Config/EnvironmentVar.ts +94 -0
  69. package/src/Globals.ts +15 -0
  70. package/src/Server/Router.ts +51 -0
  71. package/src/Server/lib/ContainerServer.ts +27 -0
  72. package/src/Server/lib/Server.ts +66 -0
  73. package/src/Server/lib/container/GenericHandler.ts +63 -0
  74. package/src/Server/lib/container/GenericHandlerEvent.ts +133 -0
  75. package/src/Server/lib/container/HealthHandler.ts +5 -0
  76. package/src/Server/lib/container/Proxy.ts +107 -0
  77. package/src/Server/lib/container/Utils.ts +45 -0
  78. package/src/Validation/Validator.ts +35 -0
  79. 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
+ }
package/tsconfig.json CHANGED
@@ -3,6 +3,8 @@
3
3
  "noImplicitAny": false,
4
4
  "noEmitOnError": true,
5
5
  "removeComments": false,
6
+ "downlevelIteration": true,
7
+ "resolveJsonModule": true,
6
8
  "sourceMap": true,
7
9
  "target": "es5",
8
10
  "outDir": "dist",