my-q-format-response-aws-lambda 1.0.26 → 1.0.28
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/index.js +21 -3
- package/index.ts +28 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.StatusResult = StatusResult;
|
|
|
7
7
|
StatusResult.ok = 'Ok';
|
|
8
8
|
StatusResult.error = 'Error';
|
|
9
9
|
StatusResult.notFound = 'NotFound';
|
|
10
|
+
StatusResult.unauthorized = 'Unauthorized';
|
|
10
11
|
class StatusCode {
|
|
11
12
|
}
|
|
12
13
|
exports.StatusCode = StatusCode;
|
|
@@ -189,6 +190,23 @@ class CreateResponse {
|
|
|
189
190
|
});
|
|
190
191
|
return result.bodyToString();
|
|
191
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Unauthorized
|
|
195
|
+
* @param error
|
|
196
|
+
* @param statusCode
|
|
197
|
+
* @param message
|
|
198
|
+
* @param bodyWrap
|
|
199
|
+
*/
|
|
200
|
+
static unauthorized({ error = null, statusCode = StatusCode.Unauthorized, message = 'Unauthorized', bodyWrap = true, }) {
|
|
201
|
+
const result = new Result({
|
|
202
|
+
statusCode,
|
|
203
|
+
statusResult: StatusResult.unauthorized,
|
|
204
|
+
error,
|
|
205
|
+
message,
|
|
206
|
+
bodyWrap,
|
|
207
|
+
});
|
|
208
|
+
return result.bodyToString();
|
|
209
|
+
}
|
|
192
210
|
/**
|
|
193
211
|
* Custom
|
|
194
212
|
* @param statusCode
|
|
@@ -277,9 +295,9 @@ const messagesREST = (prefix, suffix = '') => {
|
|
|
277
295
|
USER_LOGOUT: `${prefix}_USER_LOGOUT${suffix}`,
|
|
278
296
|
NOT_USER_LOGOUT: `${prefix}_NOT_USER_LOGOUT${suffix}`,
|
|
279
297
|
ERROR_USER_LOGOUT: `${prefix}_ERROR_USER_LOGOUT${suffix}`,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
298
|
+
USER_AUTHENTICATION_REFRESH: `${prefix}_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
299
|
+
NOT_USER_AUTHENTICATION_REFRESH: `${prefix}_NOT_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
300
|
+
ERROR_USER_AUTHENTICATION_REFRESH: `${prefix}_ERROR_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
283
301
|
};
|
|
284
302
|
};
|
|
285
303
|
exports.messagesREST = messagesREST;
|
package/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export class StatusResult {
|
|
|
2
2
|
static ok = 'Ok';
|
|
3
3
|
static error = 'Error';
|
|
4
4
|
static notFound = 'NotFound';
|
|
5
|
+
static unauthorized = 'Unauthorized';
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export class StatusCode {
|
|
@@ -271,6 +272,30 @@ export class CreateResponse {
|
|
|
271
272
|
return result.bodyToString();
|
|
272
273
|
}
|
|
273
274
|
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Unauthorized
|
|
278
|
+
* @param error
|
|
279
|
+
* @param statusCode
|
|
280
|
+
* @param message
|
|
281
|
+
* @param bodyWrap
|
|
282
|
+
*/
|
|
283
|
+
static unauthorized({
|
|
284
|
+
error = null,
|
|
285
|
+
statusCode = StatusCode.Unauthorized,
|
|
286
|
+
message = 'Unauthorized',
|
|
287
|
+
bodyWrap = true,
|
|
288
|
+
}: TFuncParams): ResponseVoAWS {
|
|
289
|
+
const result = new Result({
|
|
290
|
+
statusCode,
|
|
291
|
+
statusResult: StatusResult.unauthorized,
|
|
292
|
+
error,
|
|
293
|
+
message,
|
|
294
|
+
bodyWrap,
|
|
295
|
+
});
|
|
296
|
+
return result.bodyToString();
|
|
297
|
+
}
|
|
298
|
+
|
|
274
299
|
/**
|
|
275
300
|
* Custom
|
|
276
301
|
* @param statusCode
|
|
@@ -389,9 +414,9 @@ export const messagesREST = (prefix: string, suffix: string = '') => {
|
|
|
389
414
|
NOT_USER_LOGOUT: `${prefix}_NOT_USER_LOGOUT${suffix}`,
|
|
390
415
|
ERROR_USER_LOGOUT: `${prefix}_ERROR_USER_LOGOUT${suffix}`,
|
|
391
416
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
417
|
+
USER_AUTHENTICATION_REFRESH: `${prefix}_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
418
|
+
NOT_USER_AUTHENTICATION_REFRESH: `${prefix}_NOT_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
419
|
+
ERROR_USER_AUTHENTICATION_REFRESH: `${prefix}_ERROR_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
395
420
|
};
|
|
396
421
|
};
|
|
397
422
|
|
package/package.json
CHANGED