@spytecgps/lambda-utils 3.0.4 → 3.0.6-rc.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.
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var merge = require('deepmerge');
4
+
5
+ const getEnvKey = () => {
6
+ if (process.env.NODE_ENV === 'test') {
7
+ return 'test';
8
+ }
9
+ if (isOffline() && process.env.STAGE === 'dev') {
10
+ return 'local';
11
+ }
12
+ return (process.env.STAGE ?? process.env.NODE_ENV ?? 'dev');
13
+ };
14
+ const isOffline = () => !!process.env.IS_OFFLINE;
15
+ const isLocal = () => getEnvKey() === 'local';
16
+ const isTest = () => getEnvKey() === 'test';
17
+ const isDev = () => getEnvKey() === 'dev';
18
+ const isProduction = () => getEnvKey() === 'prod';
19
+ const setupEnvConfig = (envConfigs) => {
20
+ const baseConfig = envConfigs['base'];
21
+ const envConfig = envConfigs[getEnvKey()] ?? {};
22
+ return merge(baseConfig, envConfig);
23
+ };
24
+
25
+ exports.getEnvKey = getEnvKey;
26
+ exports.isDev = isDev;
27
+ exports.isLocal = isLocal;
28
+ exports.isOffline = isOffline;
29
+ exports.isProduction = isProduction;
30
+ exports.isTest = isTest;
31
+ exports.setupEnvConfig = setupEnvConfig;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class BadRequestError extends HttpError.default {
8
+ code = 400;
9
+ statusCode = 400;
10
+ name = 'BadRequestError';
11
+ }
12
+
13
+ exports.default = BadRequestError;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ class BaseError extends Error {
6
+ code;
7
+ statusCode;
8
+ }
9
+
10
+ exports.default = BaseError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class ConflictError extends HttpError.default {
8
+ code = 409;
9
+ statusCode = 409;
10
+ name = 'ConflictError';
11
+ }
12
+
13
+ exports.default = ConflictError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class ForbiddenError extends HttpError.default {
8
+ code = 403;
9
+ statusCode = 403;
10
+ name = 'ForbiddenError';
11
+ }
12
+
13
+ exports.default = ForbiddenError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class GoneError extends HttpError.default {
8
+ code = 410;
9
+ statusCode = 410;
10
+ name = 'GoneError';
11
+ }
12
+
13
+ exports.default = GoneError;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ class HttpError extends Error {
6
+ }
7
+
8
+ exports.default = HttpError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class NotFoundError extends HttpError.default {
8
+ code = 404;
9
+ statusCode = 404;
10
+ name = 'NotFoundError';
11
+ }
12
+
13
+ exports.default = NotFoundError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HttpError = require('./HttpError.js');
6
+
7
+ class UnauthorizedError extends HttpError.default {
8
+ code = 401;
9
+ statusCode = 401;
10
+ name = 'UnauthorizedError';
11
+ }
12
+
13
+ exports.default = UnauthorizedError;