@breautek/storm 9.3.1 → 9.5.0
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/CHANGELOG.md +15 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Application.html +17 -17
- package/docs/classes/Command.html +90 -90
- package/docs/classes/ConfigLoader.html +3 -3
- package/docs/classes/Database.html +2 -2
- package/docs/classes/DatabaseCastObject.html +2 -2
- package/docs/classes/DatabaseConnection.html +21 -21
- package/docs/classes/DatabaseQueryError.html +6 -6
- package/docs/classes/DeadLockError.html +6 -6
- package/docs/classes/DiskSpaceError.html +5 -5
- package/docs/classes/DropTemporaryTableQuery.html +7 -7
- package/docs/classes/DuplicateEntryError.html +5 -5
- package/docs/classes/EntityNotFoundError.html +5 -5
- package/docs/classes/ExpiredTokenError.html +5 -5
- package/docs/classes/ForbiddenError.html +5 -5
- package/docs/classes/GetMySQLVersion.html +7 -7
- package/docs/classes/Handler.html +4 -2
- package/docs/classes/IllegalStateError.html +5 -5
- package/docs/classes/InternalError.html +5 -5
- package/docs/classes/InvalidCredentialsError.html +5 -5
- package/docs/classes/InvalidValueError.html +5 -5
- package/docs/classes/LineString.html +2 -2
- package/docs/classes/LockWaitTimeoutError.html +6 -6
- package/docs/classes/ManagedDatabaseConnection.html +5 -5
- package/docs/classes/MetricStore.html +2 -2
- package/docs/classes/Middleware.html +2 -2
- package/docs/classes/MissingConfigError.html +5 -5
- package/docs/classes/MissingParameterError.html +5 -5
- package/docs/classes/MySQLConnection.html +25 -25
- package/docs/classes/MySQLDatabase.html +2 -2
- package/docs/classes/NotImplementedError.html +5 -5
- package/docs/classes/Point.html +2 -2
- package/docs/classes/Polygon.html +2 -2
- package/docs/classes/Query.html +7 -7
- package/docs/classes/RawError.html +5 -5
- package/docs/classes/RawQuery.html +7 -7
- package/docs/classes/Request.html +10 -3
- package/docs/classes/Response.html +2 -2
- package/docs/classes/ResponseData.html +3 -3
- package/docs/classes/ServiceProvider.html +2 -2
- package/docs/classes/ServiceResponse.html +2 -2
- package/docs/classes/SetSessionVariableQuery.html +7 -7
- package/docs/classes/StormError.html +5 -5
- package/docs/classes/TemporaryTableQuery.html +7 -7
- package/docs/classes/TimeoutError.html +5 -5
- package/docs/classes/Token.html +2 -2
- package/docs/classes/TokenManager.html +5 -2
- package/docs/classes/Transaction.html +2 -2
- package/docs/classes/UnauthorizedAccessError.html +5 -5
- package/docs/enums/ErrorCode.html +2 -2
- package/docs/enums/ExitCode.html +2 -2
- package/docs/enums/HTTPMethod.html +2 -2
- package/docs/enums/IsolationLevel.html +2 -2
- package/docs/enums/JWTError.html +2 -2
- package/docs/enums/StatusCode.html +2 -2
- package/docs/enums/TransactionAccessLevel.html +2 -2
- package/docs/functions/getInstance.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/IAdditionalErrorDetails.html +1 -1
- package/docs/interfaces/ICloudwatchConfig.html +2 -2
- package/docs/interfaces/ICloudwatchCredentials.html +2 -2
- package/docs/interfaces/ICloudwatchStreamConfig.html +2 -2
- package/docs/interfaces/IConfig.html +3 -3
- package/docs/interfaces/IDatabaseConfig.html +2 -2
- package/docs/interfaces/IDatabaseConnection.html +5 -5
- package/docs/interfaces/IDatabasePosition.html +2 -2
- package/docs/interfaces/IErrorResponse.html +2 -2
- package/docs/interfaces/IFormData.html +2 -2
- package/docs/interfaces/IGetMySQLVersionResult.html +2 -2
- package/docs/interfaces/IGetMySQLVersionRow.html +2 -2
- package/docs/interfaces/IInsertQueryResult.html +2 -2
- package/docs/interfaces/IJWTVerifyOptions.html +2 -2
- package/docs/interfaces/IOKPacket.html +2 -2
- package/docs/interfaces/IParameterMap.html +1 -1
- package/docs/interfaces/IQueryable.html +2 -2
- package/docs/interfaces/IRequestResponse.html +2 -2
- package/docs/interfaces/ISetSessionVariableQueryInput.html +2 -2
- package/docs/interfaces/IStormCLIArgs.html +2 -2
- package/docs/interfaces/ITemporaryTableQueryInput.html +2 -2
- package/docs/interfaces/IUpdateQueryResult.html +2 -2
- package/docs/interfaces/formidable.EmitData.html +2 -2
- package/docs/interfaces/formidable.EventData.html +2 -2
- package/docs/interfaces/formidable.File.html +9 -9
- package/docs/interfaces/formidable.FileJSON.html +7 -7
- package/docs/interfaces/formidable.Options.html +16 -16
- package/docs/interfaces/formidable.Part.html +2 -2
- package/docs/types/IDeleteQueryResult.html +1 -1
- package/docs/types/IStoredProcedureResult.html +1 -1
- package/docs/types/TCoordinate.html +1 -1
- package/docs/types/TExpiresIn.html +1 -1
- package/docs/types/TSerializableResponse.html +1 -1
- package/docs/types/TSupportedResponsePrimitives.html +1 -1
- package/docs/types/TSupportedResponseTypes.html +1 -1
- package/docs/types/formidable.BufferEncoding.html +1 -1
- package/docs/types/formidable.DefaultOptions.html +1 -1
- package/docs/types/formidable.EnabledPlugins.html +1 -1
- package/docs/types/formidable.EventNames.html +1 -1
- package/docs/types/formidable.Fields.html +1 -1
- package/docs/types/formidable.Files.html +1 -1
- package/docs/types/formidable.MappedParsers.html +1 -1
- package/docs/types/formidable.Plugin.html +1 -1
- package/docs/types/formidable.PluginFunction.html +1 -1
- package/docs/types/formidable.Plugins.html +1 -1
- package/docs/variables/formidable.html +1 -1
- package/lib/Handler.d.ts +2 -0
- package/lib/Handler.js +18 -4
- package/lib/Handler.js.map +1 -1
- package/lib/Request.d.ts +17 -3
- package/lib/Request.js +27 -0
- package/lib/Request.js.map +1 -1
- package/lib/TokenManager.d.ts +13 -0
- package/lib/TokenManager.js +15 -0
- package/lib/TokenManager.js.map +1 -1
- package/package.json +9 -9
- package/src/Handler.ts +24 -4
- package/src/Request.ts +38 -3
- package/src/TokenManager.ts +16 -0
package/src/Handler.ts
CHANGED
|
@@ -138,8 +138,17 @@ export class Handler<
|
|
|
138
138
|
response.error(error);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
protected _logRequestStart(request: Request<unknown>): void {
|
|
142
142
|
this.getApplication().getLogger().info(TAG, `${request.getForwardedIP()} (${request.getIP()}) - ${request.getMethod()} ${request.getURL()} - UA(${request.getHeader('user-agent')})`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected _logRequestEnd(request: Request<unknown>, response: Response<any>, elapsed: number): void {
|
|
146
|
+
this.$app.getLogger().info(TAG, `API ${request.getURL()} (${response.getStatus()}) responded in ${elapsed}ms`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public async get(request: Request<TGetRequest>, response: Response<TGetResponse>): Promise<void> {
|
|
150
|
+
let startTime: Date = new Date();
|
|
151
|
+
this._logRequestStart(request);
|
|
143
152
|
|
|
144
153
|
try {
|
|
145
154
|
let result: IRequestResponse<TGetRequest, TGetResponse> = await this.$executeMiddlewares(request, response);
|
|
@@ -149,10 +158,13 @@ export class Handler<
|
|
|
149
158
|
catch (ex) {
|
|
150
159
|
this.$handleResponseError(response as Response<StormError>, ex);
|
|
151
160
|
}
|
|
161
|
+
|
|
162
|
+
this._logRequestEnd(request, response, new Date().getTime() - startTime.getTime());
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
public async put(request: Request<TPutRequest>, response: Response<TPutResponse>): Promise<void> {
|
|
155
|
-
|
|
166
|
+
let startTime: Date = new Date();
|
|
167
|
+
this._logRequestStart(request);
|
|
156
168
|
|
|
157
169
|
try {
|
|
158
170
|
let result: IRequestResponse<TPutRequest, TPutResponse> = await this.$executeMiddlewares(request, response);
|
|
@@ -162,10 +174,13 @@ export class Handler<
|
|
|
162
174
|
catch (ex) {
|
|
163
175
|
this.$handleResponseError(response as Response<StormError>, ex);
|
|
164
176
|
}
|
|
177
|
+
|
|
178
|
+
this._logRequestEnd(request, response, new Date().getTime() - startTime.getTime());
|
|
165
179
|
}
|
|
166
180
|
|
|
167
181
|
public async post(request: Request<TPostRequest>, response: Response<TPostResponse>): Promise<void> {
|
|
168
|
-
|
|
182
|
+
let startTime: Date = new Date();
|
|
183
|
+
this._logRequestStart(request);
|
|
169
184
|
|
|
170
185
|
try {
|
|
171
186
|
let result: IRequestResponse<TPostRequest, TPostResponse> = await this.$executeMiddlewares(request, response);
|
|
@@ -175,10 +190,13 @@ export class Handler<
|
|
|
175
190
|
catch (ex) {
|
|
176
191
|
this.$handleResponseError(response as Response<StormError>, ex);
|
|
177
192
|
}
|
|
193
|
+
|
|
194
|
+
this._logRequestEnd(request, response, new Date().getTime() - startTime.getTime());
|
|
178
195
|
}
|
|
179
196
|
|
|
180
197
|
public async delete(request: Request<TDeleteRequest>, response: Response<TDeleteResponse>): Promise<void> {
|
|
181
|
-
|
|
198
|
+
let startTime: Date = new Date();
|
|
199
|
+
this._logRequestStart(request);
|
|
182
200
|
|
|
183
201
|
try {
|
|
184
202
|
let result: IRequestResponse<TDeleteRequest, TDeleteResponse> = await this.$executeMiddlewares(request, response);
|
|
@@ -188,6 +206,8 @@ export class Handler<
|
|
|
188
206
|
catch (ex) {
|
|
189
207
|
this.$handleResponseError(response as Response<StormError>, ex);
|
|
190
208
|
}
|
|
209
|
+
|
|
210
|
+
this._logRequestEnd(request, response, new Date().getTime() - startTime.getTime());
|
|
191
211
|
}
|
|
192
212
|
|
|
193
213
|
protected async _get(request: Request<TGetRequest>): Promise<TGetResponse | ResponseData<TGetResponse>> {
|
package/src/Request.ts
CHANGED
|
@@ -34,8 +34,12 @@ import { InternalError } from './InternalError';
|
|
|
34
34
|
import IncomingForm = require('formidable/Formidable');
|
|
35
35
|
import { IDatabasePosition } from './IDatabasePosition';
|
|
36
36
|
|
|
37
|
+
export interface IQueryParams {
|
|
38
|
+
[key: string]: undefined | string | IQueryParams | (string | IQueryParams)[];
|
|
39
|
+
}
|
|
40
|
+
|
|
37
41
|
export interface IParameterMap {
|
|
38
|
-
[key: string]: string;
|
|
42
|
+
[key: string]: string | string[];
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export class Request<TBody = any, TAuthToken extends IAuthTokenData = IAuthTokenData> {
|
|
@@ -83,7 +87,7 @@ export class Request<TBody = any, TAuthToken extends IAuthTokenData = IAuthToken
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
public getQueryVariables():
|
|
90
|
+
public getQueryVariables(): IQueryParams {
|
|
87
91
|
return this.$request.query;
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -91,10 +95,41 @@ export class Request<TBody = any, TAuthToken extends IAuthTokenData = IAuthToken
|
|
|
91
95
|
return this.$request.params;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
public getParam(name: string): string {
|
|
98
|
+
public getParam(name: string): string | string[] {
|
|
95
99
|
return this.$request.params[name];
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Gets a URL parameter as string. If the value is multiple
|
|
104
|
+
* then only the first value is returned.
|
|
105
|
+
* This is a convenience method over `getParam` which returns a union.
|
|
106
|
+
*/
|
|
107
|
+
public getURLSingleParam(name: string): string {
|
|
108
|
+
let v: string | string[] = this.getParam(name);
|
|
109
|
+
|
|
110
|
+
if (typeof v === 'string') {
|
|
111
|
+
return v;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return v[0];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Gets a URL parameter as string[].
|
|
120
|
+
* This is a convenience method over `getParam` which returns a union.
|
|
121
|
+
*/
|
|
122
|
+
public getURLMultiParam(name: string): string[] {
|
|
123
|
+
let v: string | string[] = this.getParam(name);
|
|
124
|
+
|
|
125
|
+
if (typeof v === 'string') {
|
|
126
|
+
return [v];
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return v;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
98
133
|
public getIP(): string {
|
|
99
134
|
return this.$request.ip;
|
|
100
135
|
}
|
package/src/TokenManager.ts
CHANGED
|
@@ -78,6 +78,22 @@ export class TokenManager<TAuthToken extends IAuthTokenData = IAuthTokenData> {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Decodes the token. Use this method only on verified tokens as this does not verify against tampering
|
|
83
|
+
*
|
|
84
|
+
* @param token
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
public decodeSync(token: Token): TAuthToken {
|
|
88
|
+
return jwt.decode(token.getSignature()) as TAuthToken;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Decodes the token. Use this method only on verified tokens as this does not verify against tampering
|
|
93
|
+
*
|
|
94
|
+
* @param token
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
81
97
|
public decode(token: Token): Promise<TAuthToken> {
|
|
82
98
|
return new Promise<any>((resolve, reject) => {
|
|
83
99
|
try {
|