@creator.co/wapi 1.2.1-beta6 → 1.2.2

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 (127) hide show
  1. package/.github/workflows/npmpublish.yml +11 -19
  2. package/.github/workflows/prs.yml +13 -0
  3. package/jest.config.ts +39 -0
  4. package/package.json +15 -4
  5. package/src/API/Request.ts +120 -10
  6. package/src/API/Response.ts +236 -8
  7. package/src/API/Utils.ts +56 -1
  8. package/src/BaseEvent/EventProcessor.ts +84 -11
  9. package/src/BaseEvent/Process.ts +62 -1
  10. package/src/BaseEvent/Transaction.ts +5 -8
  11. package/src/Config/Configuration.ts +111 -5
  12. package/src/Config/EnvironmentVar.ts +90 -1
  13. package/src/Crypto/Crypto.ts +77 -18
  14. package/src/Crypto/JWT.ts +49 -3
  15. package/src/Globals.ts +141 -3
  16. package/src/Logger/Logger.ts +173 -19
  17. package/src/Mailer/Mailer.ts +95 -0
  18. package/src/Publisher/Publisher.ts +50 -4
  19. package/src/Server/RouteResolver.ts +142 -0
  20. package/src/Server/Router.ts +77 -0
  21. package/src/Server/lib/ContainerServer.ts +48 -1
  22. package/src/Server/lib/Server.ts +78 -38
  23. package/src/Server/lib/container/GenericHandler.ts +7 -5
  24. package/src/Server/lib/container/GenericHandlerEvent.ts +59 -17
  25. package/src/Server/lib/container/HealthHandler.ts +1 -1
  26. package/src/Server/lib/container/Proxy.ts +92 -11
  27. package/src/Server/lib/container/Utils.ts +16 -25
  28. package/src/Validation/Validator.ts +18 -2
  29. package/tests/API/Request.test.ts +263 -0
  30. package/tests/API/Response.test.ts +372 -0
  31. package/tests/API/Utils.test.ts +157 -0
  32. package/tests/BaseEvent/EventProcessor.test.ts +278 -0
  33. package/tests/BaseEvent/Process.test.ts +49 -0
  34. package/tests/BaseEvent/Transaction.test.ts +231 -0
  35. package/tests/Config/Config.test.ts +193 -0
  36. package/tests/Config/EnvironmentVar.test.ts +223 -0
  37. package/tests/Crypto/Crypto.test.ts +90 -0
  38. package/tests/Crypto/JWT.test.ts +92 -0
  39. package/tests/Logger/Logger.test.ts +108 -0
  40. package/tests/Mailer/Mailer.test.ts +67 -0
  41. package/tests/Publisher/Publisher.test.ts +60 -0
  42. package/tests/Server/RouteResolver.test.ts +106 -0
  43. package/tests/Server/Router.test.ts +38 -0
  44. package/tests/Server/lib/ContainerServer.test.ts +329 -0
  45. package/tests/Server/lib/Server.test.ts +12 -0
  46. package/tests/Server/lib/container/GenericHandler.test.ts +141 -0
  47. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  48. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  49. package/tests/Server/lib/container/Proxy.test.ts +278 -0
  50. package/tests/Server/lib/container/Utils.test.ts +48 -0
  51. package/tests/Test.utils.ts +95 -0
  52. package/tests/Validation/Validator.test.ts +88 -0
  53. package/tests/main.test.ts +15 -0
  54. package/tsconfig.json +1 -0
  55. package/dist/index.d.ts +0 -11
  56. package/dist/index.js +0 -24
  57. package/dist/index.js.map +0 -1
  58. package/dist/package.json +0 -53
  59. package/dist/src/API/Request.d.ts +0 -21
  60. package/dist/src/API/Request.js +0 -86
  61. package/dist/src/API/Request.js.map +0 -1
  62. package/dist/src/API/Response.d.ts +0 -39
  63. package/dist/src/API/Response.js +0 -232
  64. package/dist/src/API/Response.js.map +0 -1
  65. package/dist/src/API/Utils.d.ts +0 -8
  66. package/dist/src/API/Utils.js +0 -49
  67. package/dist/src/API/Utils.js.map +0 -1
  68. package/dist/src/BaseEvent/EventProcessor.d.ts +0 -13
  69. package/dist/src/BaseEvent/EventProcessor.js +0 -151
  70. package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
  71. package/dist/src/BaseEvent/Process.d.ts +0 -12
  72. package/dist/src/BaseEvent/Process.js +0 -114
  73. package/dist/src/BaseEvent/Process.js.map +0 -1
  74. package/dist/src/BaseEvent/Transaction.d.ts +0 -29
  75. package/dist/src/BaseEvent/Transaction.js +0 -248
  76. package/dist/src/BaseEvent/Transaction.js.map +0 -1
  77. package/dist/src/Config/Configuration.d.ts +0 -34
  78. package/dist/src/Config/Configuration.js +0 -93
  79. package/dist/src/Config/Configuration.js.map +0 -1
  80. package/dist/src/Config/EnvironmentVar.d.ts +0 -17
  81. package/dist/src/Config/EnvironmentVar.js +0 -152
  82. package/dist/src/Config/EnvironmentVar.js.map +0 -1
  83. package/dist/src/Crypto/Crypto.d.ts +0 -8
  84. package/dist/src/Crypto/Crypto.js +0 -84
  85. package/dist/src/Crypto/Crypto.js.map +0 -1
  86. package/dist/src/Crypto/JWT.d.ts +0 -16
  87. package/dist/src/Crypto/JWT.js +0 -49
  88. package/dist/src/Crypto/JWT.js.map +0 -1
  89. package/dist/src/Globals.d.ts +0 -21
  90. package/dist/src/Globals.js +0 -35
  91. package/dist/src/Globals.js.map +0 -1
  92. package/dist/src/Logger/Logger.d.ts +0 -34
  93. package/dist/src/Logger/Logger.js +0 -345
  94. package/dist/src/Logger/Logger.js.map +0 -1
  95. package/dist/src/Mailer/Mailer.d.ts +0 -12
  96. package/dist/src/Mailer/Mailer.js +0 -234
  97. package/dist/src/Mailer/Mailer.js.map +0 -1
  98. package/dist/src/Publisher/Publisher.d.ts +0 -10
  99. package/dist/src/Publisher/Publisher.js +0 -109
  100. package/dist/src/Publisher/Publisher.js.map +0 -1
  101. package/dist/src/Server/Router.d.ts +0 -27
  102. package/dist/src/Server/Router.js +0 -22
  103. package/dist/src/Server/Router.js.map +0 -1
  104. package/dist/src/Server/lib/ContainerServer.d.ts +0 -11
  105. package/dist/src/Server/lib/ContainerServer.js +0 -103
  106. package/dist/src/Server/lib/ContainerServer.js.map +0 -1
  107. package/dist/src/Server/lib/Server.d.ts +0 -9
  108. package/dist/src/Server/lib/Server.js +0 -141
  109. package/dist/src/Server/lib/Server.js.map +0 -1
  110. package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -4
  111. package/dist/src/Server/lib/container/GenericHandler.js +0 -136
  112. package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
  113. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -14
  114. package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -164
  115. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
  116. package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -3
  117. package/dist/src/Server/lib/container/HealthHandler.js +0 -44
  118. package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
  119. package/dist/src/Server/lib/container/Proxy.d.ts +0 -15
  120. package/dist/src/Server/lib/container/Proxy.js +0 -157
  121. package/dist/src/Server/lib/container/Proxy.js.map +0 -1
  122. package/dist/src/Server/lib/container/Utils.d.ts +0 -6
  123. package/dist/src/Server/lib/container/Utils.js +0 -109
  124. package/dist/src/Server/lib/container/Utils.js.map +0 -1
  125. package/dist/src/Validation/Validator.d.ts +0 -5
  126. package/dist/src/Validation/Validator.js +0 -31
  127. package/dist/src/Validation/Validator.js.map +0 -1
@@ -1,22 +1,14 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
1
+ name: NPM Publish
6
2
  on:
7
- release:
8
- types: [created]
3
+ push:
4
+ branches: [ "main" ]
9
5
 
10
6
  jobs:
11
- publish-npm:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: actions/setup-node@v3
16
- with:
17
- node-version: 16
18
- registry-url: https://registry.npmjs.org/
19
- - run: npm ci
20
- - run: npm publish --access='public'
21
- env:
22
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
7
+ Publish:
8
+ uses: Creator-co/tool-github-workflows/.github/workflows/npmpublish.yml@main2
9
+ secrets: inherit
10
+ with:
11
+ disablieSASTFailure: false
12
+ disableLintFailure: false
13
+ disableUTestFailure: false
14
+ NODE_VERSION: "16.x"
@@ -0,0 +1,13 @@
1
+ name: PR Checks
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - master
6
+ - main
7
+
8
+ jobs:
9
+ Checks:
10
+ uses: Creator-co/tool-github-workflows/.github/workflows/prs-check.yml@main2
11
+ secrets: inherit
12
+ with:
13
+ NODE_VERSION: "16.x"
package/jest.config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { Config } from "@jest/types"
2
+ /* eslint-env node */
3
+ const config: Config.InitialOptions = {
4
+ preset: "ts-jest",
5
+ testEnvironment: "node",
6
+ reporters: [
7
+ "default",
8
+ [
9
+ "jest-junit",
10
+ {
11
+ outputDirectory: "coverage",
12
+ outputName: "jest-junit.xml",
13
+ ancestorSeparator: " › ",
14
+ uniqueOutputName: "false",
15
+ suiteNameTemplate: "{filepath}",
16
+ classNameTemplate: "{classname}",
17
+ titleTemplate: "{title}",
18
+ },
19
+ ],
20
+ ],
21
+ coverageReporters: [
22
+ "clover",
23
+ "json",
24
+ "lcov",
25
+ "text",
26
+ ["text", { file: "coverage.txt" }],
27
+ "json-summary",
28
+ ],
29
+ collectCoverageFrom: ["src/**/*.(t|j)s"],
30
+ coverageThreshold: {
31
+ global: {
32
+ branches: 80,
33
+ functions: 80,
34
+ lines: 80,
35
+ statements: 80,
36
+ },
37
+ },
38
+ }
39
+ export default config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.1-beta6",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,10 @@
8
8
  "scripts": {
9
9
  "build": "npm run lint && tsc --build",
10
10
  "clean": "tsc --build --clean",
11
- "lint": "eslint . --ext .ts --fix"
11
+ "lint-fix": "eslint . --ext .ts --fix",
12
+ "lint": "eslint . --ext .ts",
13
+ "test": "jest --coverage --silent --runInBand",
14
+ "test-dev": "jest --coverage --runInBand"
12
15
  },
13
16
  "author": "",
14
17
  "license": "ISC",
@@ -33,21 +36,29 @@
33
36
  "parse-duration": "^1.1.0",
34
37
  "sha1": "^1.1.1",
35
38
  "stack-trace": "0.0.10",
36
- "unflatten": "^1.0.4",
37
39
  "zod": "^3.22.4"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@types/aws-lambda": "^8.10.119",
41
43
  "@types/express": "^4.17.19",
44
+ "@types/jest": "^29.5.6",
42
45
  "@types/jsonwebtoken": "^9.0.3",
43
46
  "@types/node": "^20.5.7",
44
47
  "@typescript-eslint/eslint-plugin": "^6.5.0",
45
48
  "@typescript-eslint/parser": "^6.5.0",
46
49
  "aws-lambda": "^1.0.7",
50
+ "aws-sdk-client-mock": "^3.0.0",
51
+ "chai": "^4.3.10",
47
52
  "eslint": "^8.48.0",
48
53
  "eslint-config-prettier": "^9.0.0",
49
54
  "eslint-plugin-import": "^2.28.1",
50
55
  "eslint-plugin-prettier": "^5.0.0",
51
- "prettier": "^3.0.3"
56
+ "jest": "^29.7.0",
57
+ "jest-junit": "^16.0.0",
58
+ "prettier": "^3.0.3",
59
+ "supertest": "^6.3.3",
60
+ "ts-jest": "^29.1.1",
61
+ "ts-node": "^10.9.1",
62
+ "typescript": "^5.2.2"
52
63
  }
53
64
  }
@@ -2,28 +2,74 @@ import type { Context, APIGatewayEvent } from "aws-lambda"
2
2
 
3
3
  import Utils from "./Utils"
4
4
  import Logger from "../Logger/Logger"
5
- //
5
+ /**
6
+ * ${1:Description placeholder}
7
+ *
8
+ * @export
9
+ * @class Request
10
+ * @typedef {Request}
11
+ * @template InputType
12
+ */
6
13
  export default class Request<InputType> {
14
+ /**
15
+ * ${1:Description placeholder}
16
+ *
17
+ * @private
18
+ * @type {APIGatewayEvent}
19
+ */
7
20
  private requestEvent: APIGatewayEvent
21
+ /**
22
+ * ${1:Description placeholder}
23
+ *
24
+ * @private
25
+ * @type {Context}
26
+ */
8
27
  private context: Context
28
+ /**
29
+ * Creates an instance of Request.
30
+ *
31
+ * @constructor
32
+ * @param {APIGatewayEvent} requestEvent
33
+ * @param {Context} context
34
+ * @param {Logger} logger
35
+ */
9
36
  constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
10
37
  this.requestEvent = requestEvent
11
38
  this.context = context
12
39
  logger.debug("Request info:", JSON.stringify(requestEvent))
13
40
  logger.debug("Request context:", JSON.stringify(context))
14
41
  }
15
- //query
42
+ /**
43
+ * ${1:Description placeholder}
44
+ *
45
+ * @public
46
+ * @param {string} paramName
47
+ * @returns {boolean}
48
+ */
16
49
  public containsQueryParam(paramName: string): boolean {
17
50
  const val = this.getQueryParam(paramName)
18
51
  return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
19
52
  }
53
+ /**
54
+ * ${1:Description placeholder}
55
+ *
56
+ * @public
57
+ * @param {string} paramName
58
+ * @returns {(string | null)}
59
+ */
20
60
  public getQueryParam(paramName: string): string | null {
21
61
  return Utils.caseInsensitiveObjectForKey(
22
62
  this.requestEvent.queryStringParameters,
23
63
  paramName,
24
64
  )
25
65
  }
26
- //header
66
+ /**
67
+ * ${1:Description placeholder}
68
+ *
69
+ * @public
70
+ * @param {string} headerName
71
+ * @returns {(string | null)}
72
+ */
27
73
  public getHeader(headerName: string): string | null {
28
74
  return Utils.caseInsensitiveObjectForKey(
29
75
  this.requestEvent.headers,
@@ -31,24 +77,49 @@ export default class Request<InputType> {
31
77
  )
32
78
  }
33
79
  //context params
80
+ /**
81
+ * ${1:Description placeholder}
82
+ *
83
+ * @public
84
+ * @param {string} cxtParam
85
+ * @returns {(any | null)}
86
+ */
34
87
  public getContextParam(cxtParam: string): any | null {
35
88
  return Utils.caseInsensitiveObjectForKey(
36
89
  this.requestEvent.requestContext,
37
90
  cxtParam,
38
91
  )
39
92
  }
40
- //path param
93
+ /**
94
+ * ${1:Description placeholder}
95
+ *
96
+ * @public
97
+ * @param {string} paramName
98
+ * @returns {boolean}
99
+ */
41
100
  public containsPathParam(paramName: string): boolean {
42
101
  const val = this.getPathParam(paramName)
43
102
  return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
44
103
  }
104
+ /**
105
+ * ${1:Description placeholder}
106
+ *
107
+ * @public
108
+ * @param {string} paramName
109
+ * @returns {(string | null)}
110
+ */
45
111
  public getPathParam(paramName: string): string | null {
46
112
  return Utils.caseInsensitiveObjectForKey(
47
113
  this.requestEvent.pathParameters,
48
114
  paramName,
49
115
  )
50
116
  }
51
- //body
117
+ /**
118
+ * ${1:Description placeholder}
119
+ *
120
+ * @public
121
+ * @returns {InputType}
122
+ */
52
123
  public getBody(): InputType {
53
124
  let b: any = null
54
125
  try {
@@ -60,33 +131,72 @@ export default class Request<InputType> {
60
131
  }
61
132
  return b
62
133
  }
134
+ /**
135
+ * ${1:Description placeholder}
136
+ *
137
+ * @public
138
+ * @returns {string}
139
+ */
63
140
  public getPath(): string {
64
141
  return this.requestEvent.path
65
142
  }
143
+ /**
144
+ * ${1:Description placeholder}
145
+ *
146
+ * @public
147
+ * @returns {string}
148
+ */
66
149
  public getMethod(): string {
67
150
  return this.requestEvent.httpMethod
68
151
  }
152
+ /**
153
+ * ${1:Description placeholder}
154
+ *
155
+ * @public
156
+ * @returns {(object | null)}
157
+ */
69
158
  public getPathParams(): object | null {
70
159
  return this.requestEvent.pathParameters
71
160
  }
72
-
73
- //Shortcuts
161
+ /**
162
+ * ${1:Description placeholder}
163
+ *
164
+ * @public
165
+ * @returns {(string | null)}
166
+ */
74
167
  public getAuthorizationHeader(): string | null {
75
168
  return this.getHeader("Authorization")
76
169
  }
170
+ /**
171
+ * ${1:Description placeholder}
172
+ *
173
+ * @public
174
+ * @returns {string}
175
+ */
77
176
  public getRequestID(): string {
78
177
  if (this.context.awsRequestId) return this.context.awsRequestId
79
178
  return this.requestEvent.requestContext
80
179
  ? this.requestEvent.requestContext.requestId
81
180
  : "unknown"
82
181
  }
182
+ /**
183
+ * ${1:Description placeholder}
184
+ *
185
+ * @public
186
+ * @returns {string}
187
+ */
83
188
  public getOriginIP(): string {
84
189
  const origin = this.getContextParam("identity")?.sourceIp
85
190
  const hOrigin = this.getHeader("X-Forwarded-For")
86
- return origin ? origin : hOrigin ? hOrigin : "unknow"
191
+ return origin ? origin : hOrigin ? hOrigin : "unknown"
87
192
  }
88
-
89
- //ugly fix
193
+ /**
194
+ * ${1:Description placeholder}
195
+ *
196
+ * @public
197
+ * @param {any[]} keys
198
+ * @param {any[]} result
199
+ */
90
200
  public setFixedPathParams(keys: any[], result: any[]): void {
91
201
  this.requestEvent.pathParameters = {}
92
202
  keys.forEach(
@@ -3,29 +3,121 @@ import type { Context } from "aws-lambda"
3
3
  import Transaction from "../BaseEvent/Transaction"
4
4
  import Globals from "../Globals"
5
5
  //
6
+ /**
7
+ * ${1:Description placeholder}
8
+ *
9
+ * @class CustomError
10
+ * @typedef {CustomError}
11
+ * @extends {Error}
12
+ */
6
13
  class CustomError extends Error {
14
+ /**
15
+ * Creates an instance of CustomError.
16
+ *
17
+ * @constructor
18
+ * @param {*} body
19
+ */
7
20
  constructor(body: any) {
8
- const msg = body && body.message ? body.message : "Unknown error!"
9
- super(msg)
10
- this.name = body && body.error ? body.error : "UnknownError"
21
+ super(body.message || "Unknown error!")
22
+ this.name = body.error || "UnknownError"
11
23
  }
12
24
  }
13
25
  //
26
+ /**
27
+ * ${1:Description placeholder}
28
+ *
29
+ * @export
30
+ * @typedef {ResponseErrorType}
31
+ */
14
32
  export type ResponseErrorType = {
15
33
  err: string
16
34
  errCode?: string
17
35
  }
18
36
  //
37
+ /**
38
+ * ${1:Description placeholder}
39
+ *
40
+ * @export
41
+ * @class Response
42
+ * @typedef {Response}
43
+ * @template [BodyType=null]
44
+ */
19
45
  export default class Response<BodyType = null> {
46
+ /**
47
+ * ${1:Description placeholder}
48
+ *
49
+ * @private
50
+ * @type {number}
51
+ */
20
52
  private _statusCode: number
53
+ /**
54
+ * ${1:Description placeholder}
55
+ *
56
+ * @private
57
+ * @type {*}
58
+ */
21
59
  private _body: any
60
+ /**
61
+ * ${1:Description placeholder}
62
+ *
63
+ * @private
64
+ * @type {boolean}
65
+ */
22
66
  private _isPipingOut: boolean
67
+ /**
68
+ * ${1:Description placeholder}
69
+ *
70
+ * @private
71
+ * @type {object}
72
+ */
23
73
  private _headers: object
74
+ /**
75
+ * ${1:Description placeholder}
76
+ *
77
+ * @public
78
+ * @readonly
79
+ * @type {boolean}
80
+ */
24
81
  public readonly shouldStream: boolean
82
+ /**
83
+ * ${1:Description placeholder}
84
+ *
85
+ * @public
86
+ * @readonly
87
+ * @type {boolean}
88
+ */
25
89
  public readonly rawBody: boolean
90
+ /**
91
+ * ${1:Description placeholder}
92
+ *
93
+ * @public
94
+ * @readonly
95
+ * @type {boolean}
96
+ */
26
97
  public readonly throwOnErrors: boolean
98
+ /**
99
+ * ${1:Description placeholder}
100
+ *
101
+ * @public
102
+ * @readonly
103
+ * @type {boolean}
104
+ */
27
105
  public readonly disableTransactionID: boolean
28
106
  //
107
+ /**
108
+ * Creates an instance of Response.
109
+ *
110
+ * @constructor
111
+ * @param {number} statusCode
112
+ * @param {BodyType} body
113
+ * @param {?(| {
114
+ * shouldStream?: boolean
115
+ * rawBody?: boolean
116
+ * throwOnErrors?: boolean
117
+ * disableTransactionID?: boolean
118
+ * }
119
+ * | undefined)\} [optBehaviour]
120
+ */
29
121
  constructor(
30
122
  statusCode: number,
31
123
  body: BodyType,
@@ -54,18 +146,54 @@ export default class Response<BodyType = null> {
54
146
  this.throwOnErrors = !!optBehaviour?.throwOnErrors
55
147
  this.disableTransactionID = !!optBehaviour?.disableTransactionID
56
148
  }
149
+ /**
150
+ * ${1:Description placeholder}
151
+ *
152
+ * @public
153
+ * @returns {number}
154
+ */
57
155
  public getCode(): number {
58
156
  return this._statusCode
59
157
  }
158
+ /**
159
+ * ${1:Description placeholder}
160
+ *
161
+ * @public
162
+ * @returns {BodyType}
163
+ */
60
164
  public getBody(): BodyType {
61
165
  return this._body
62
166
  }
167
+ /**
168
+ * ${1:Description placeholder}
169
+ *
170
+ * @public
171
+ * @param {string} key
172
+ * @param {*} value
173
+ */
63
174
  public appendIntoBody(key: string, value: any): void {
64
175
  this._body[key] = value
65
176
  }
177
+ /**
178
+ * ${1:Description placeholder}
179
+ *
180
+ * @public
181
+ * @param {string} key
182
+ * @param {*} value
183
+ */
66
184
  public appendHeader(key: string, value: any): void {
67
185
  this._headers[key] = value
68
186
  }
187
+ /**
188
+ * ${1:Description placeholder}
189
+ *
190
+ * @public
191
+ * @async
192
+ * @param {Context} context
193
+ * @param {Transaction<any, any, any>} transaction
194
+ * @param {boolean} _optDoNotCallContext
195
+ * @returns {Promise<void>}
196
+ */
69
197
  public async build(
70
198
  context: Context,
71
199
  transaction: Transaction<any, any, any>,
@@ -98,9 +226,14 @@ export default class Response<BodyType = null> {
98
226
  //Batch does not succeed directly just on upper transaction (which will should be a batch)
99
227
  if (!_optDoNotCallContext) context.succeed(b)
100
228
  }
229
+ /**
230
+ * ${1:Description placeholder}
231
+ *
232
+ * @private
233
+ * @param {Context} context
234
+ */
101
235
  private _pipe(context: Context): void {
102
236
  //Check if not streaming
103
- if (this._isPipingOut) return
104
237
  this._isPipingOut = true
105
238
  //build response
106
239
  const b = {
@@ -111,6 +244,13 @@ export default class Response<BodyType = null> {
111
244
  //log response and respond to context
112
245
  context.succeed(b)
113
246
  }
247
+ /**
248
+ * ${1:Description placeholder}
249
+ *
250
+ * @private
251
+ * @param {Context} context
252
+ * @param {Transaction<null, BodyType>} transaction
253
+ */
114
254
  private _rawContext(
115
255
  context: Context,
116
256
  transaction: Transaction<null, BodyType>,
@@ -126,6 +266,14 @@ export default class Response<BodyType = null> {
126
266
  }
127
267
 
128
268
  /* Shortcuts */
269
+ /**
270
+ * ${1:Description placeholder}
271
+ *
272
+ * @public
273
+ * @static
274
+ * @param {string} paramName
275
+ * @returns {Response<ResponseErrorType>}
276
+ */
129
277
  public static MissingParamResponse(
130
278
  paramName: string,
131
279
  ): Response<ResponseErrorType> {
@@ -135,6 +283,14 @@ export default class Response<BodyType = null> {
135
283
  errCode: Globals.ErrorCode_MissingParam,
136
284
  })
137
285
  }
286
+ /**
287
+ * ${1:Description placeholder}
288
+ *
289
+ * @public
290
+ * @static
291
+ * @param {string} paramName
292
+ * @returns {Response<ResponseErrorType>}
293
+ */
138
294
  public static MissingQueryResponse(
139
295
  paramName: string,
140
296
  ): Response<ResponseErrorType> {
@@ -144,6 +300,16 @@ export default class Response<BodyType = null> {
144
300
  errCode: Globals.ErrorCode_MissingParam,
145
301
  })
146
302
  }
303
+ /**
304
+ * ${1:Description placeholder}
305
+ *
306
+ * @public
307
+ * @static
308
+ * @param {?string} [msg]
309
+ * @param {?string} [errCode]
310
+ * @param {?*} [optBody]
311
+ * @returns {Response<ResponseErrorType>}
312
+ */
147
313
  public static BadRequestResponse(
148
314
  msg?: string,
149
315
  errCode?: string,
@@ -156,9 +322,19 @@ export default class Response<BodyType = null> {
156
322
  ...(optBody || {}),
157
323
  })
158
324
  }
325
+ /**
326
+ * ${1:Description placeholder}
327
+ *
328
+ * @public
329
+ * @static
330
+ * @param {string} msg
331
+ * @param {?string} [errCode]
332
+ * @param {?*} [optBody]
333
+ * @returns {Response<ResponseErrorType>}
334
+ */
159
335
  public static BadRequestResponseWithRollback(
160
336
  msg: string,
161
- errCode: string,
337
+ errCode?: string,
162
338
  optBody?: any,
163
339
  ): Response<ResponseErrorType> {
164
340
  console.warn(`Bad request - ${msg}`)
@@ -169,9 +345,18 @@ export default class Response<BodyType = null> {
169
345
  ...(optBody || {}),
170
346
  })
171
347
  }
348
+ /**
349
+ * ${1:Description placeholder}
350
+ *
351
+ * @public
352
+ * @static
353
+ * @param {string} msg
354
+ * @param {?string} [errCode]
355
+ * @returns {Response<ResponseErrorType>}
356
+ */
172
357
  public static UnauthorizedResponse(
173
358
  msg: string,
174
- errCode: string,
359
+ errCode?: string,
175
360
  ): Response<ResponseErrorType> {
176
361
  console.warn(`Denying request - ${msg}`)
177
362
  return new Response<ResponseErrorType>(401, {
@@ -179,28 +364,71 @@ export default class Response<BodyType = null> {
179
364
  ...(errCode ? { errCode: errCode } : {}),
180
365
  })
181
366
  }
367
+ /**
368
+ * ${1:Description placeholder}
369
+ *
370
+ * @public
371
+ * @static
372
+ * @template BodyType
373
+ * @param {BodyType} body
374
+ * @returns {Response<BodyType>}
375
+ */
182
376
  public static SuccessResponse<BodyType>(body: BodyType): Response<BodyType> {
183
377
  return new Response<BodyType>(200, (body ? body : {}) as BodyType)
184
378
  }
379
+ /**
380
+ * ${1:Description placeholder}
381
+ *
382
+ * @public
383
+ * @static
384
+ * @param {string} url
385
+ * @returns {Response<null>}
386
+ */
185
387
  public static RedirectResponse(url: string): Response<null> {
186
388
  const resp = new Response<null>(302, null)
187
389
  resp.appendHeader("Location", url)
188
390
  return resp
189
391
  }
392
+ /**
393
+ * ${1:Description placeholder}
394
+ *
395
+ * @public
396
+ * @static
397
+ * @returns {Response<null>}
398
+ */
190
399
  public static SuccessNoContentResponse(): Response<null> {
191
400
  return new Response<null>(204, null)
192
401
  }
402
+ /**
403
+ * ${1:Description placeholder}
404
+ *
405
+ * @public
406
+ * @static
407
+ * @param {*} stream
408
+ * @param {string} contentType
409
+ * @returns {Response}
410
+ */
193
411
  public static SuccessStreamResponse(
194
412
  stream: any,
195
413
  contentType: string,
196
414
  ): Response {
197
- const resp = new Response(200, stream ? stream : {}, {
415
+ const resp = new Response(200, stream, {
198
416
  shouldStream: true,
199
417
  })
200
418
  resp.appendHeader("Connection", "keep-alive")
201
- if (contentType) resp.appendHeader("Content-type", contentType)
419
+ if (contentType) resp.appendHeader("Content-Type", contentType)
202
420
  return resp
203
421
  }
422
+ /**
423
+ * ${1:Description placeholder}
424
+ *
425
+ * @public
426
+ * @static
427
+ * @template BodyType
428
+ * @param {BodyType} body
429
+ * @param {?number} [optionalCode]
430
+ * @returns {Response<BodyType>}
431
+ */
204
432
  public static SimpleResponse<BodyType>(
205
433
  body: BodyType,
206
434
  optionalCode?: number,